Contact Us

If you are interested in our services leave your contact details below and our sales representatives will contact you.

The organization which you represent
Email address we will use to contact you
Longer contact form…
 
  • About

    mFabrik Blog is about mobile and web software development, open source and Linux. We tell exciting tales where business, technology, web and mobile convergence.

    Creative Commons License
    This work is licensed under a Creative Commons Attribution 3.0 Unported License.

domgen – Creating HTML with Javascript without DOM API



Tired of using Javascript DOM API for generating HTML dynamically? Meet domgen. domgen is a tool for easy dynamic content generation via Javascript. It generates DOM elements from dictionary specification similar to HTML and eliminates the need for cumbersome DOM Javascript API.

domgen uses a simple specification to generate the HTML. In some cases it’s more reliable to use DOM API to generate HTML instead of using innerHTML. We have had problems especially with iPhone when using innerHTML.
See for example http://pastebin.com/LLk3J0iH or google “iPhone innerHTML” for more info. In fact, innerHTML is not even part of the HTML standard even though it exists on every browser.

So if you want to add dynamic HTML properly, you should use the Javascript DOM API. Consider the following short HTML where the contents inside body had to be generated:

<body>
    <div id="mydiv">my div</div>
</body>

Using Javascript DOM API:

// Get the body tag
var body = document.getElementsByTagName("body")[0];
// Create 'div' element
var mydiv = document.createElement("div");
mydiv.setAttribute("id", "mydiv");
mydiv.innerText = "my div";
// Attach the div to body
body.appendChild(mydiv);

And using domgen:

var spec = [
    'div',
    {
        id : 'mydiv',
        _innerText : 'my div'
    }
];
domgen.generate( domgen.get("body")[0], spec);
// or with jQuery
domgen.generate( $("body")[0], spec);

To me, domgen seems a lot easier to read and work with. Get code and more examples here: https://bitbucket.org/mfabrik/domgen

How people perceive Plone outside Plone community



Our company does business with multiple CMS systems, like Joomla, Plone and Drupal.  They all have their advantages, they all have their disadvantages. We do not want to make CMS a religion. It’s a tool. You can argue with the client which tool is a right job for a task. Joomla is lightweight solution for non-critical systems, Plone is good with lots of content, editors and workflows flying around. etc. etc.

I had this curious piece on conversation on #joomla channel on freenode. Though it is an individual case, I hope it will bring some light to the fact how people perceive Plone outside Plone community and what Plone should to do fix it.

I think it would be beneficial for Plone to finally close mailman for the site administration / user support and move to real web forums / Google Groups / whatever which would be usable.

Also, there is an example how unprofessionalism is not good for the community.

[20:23:29] x: Biggest problem so far is finding competent ("I will deliver on this schedule) joomla consulting experts. Second biggest problem is security, our site has been hacked 3 times in the past 6 months
[20:25:18] me: have you considered any alternative CMS with better security track record?
[20:25:50] x: moo: we moved from Plone to Joomla. 3 years on Plone with no hacks.
[20:26:04] x: Problem with plone is no forums with email support
[20:26:21] me: you pay for support
[20:26:30] z: did you do basic joomla security guidelines?
[20:26:39] me: also check http://plone.org/support
[20:26:40]  Title: Support options for Plone — Plone CMS: Open Source Content Management (at plone.org)
[20:26:51] x: moo: I'm fine with paying for support. We're paying SiteGround $200-$300/month on average when you add the support costs.
[20:26:58] z: ie using a key to access admin, changing default sql prefix
[20:27:01] AngryPerson: who cares about plone
[20:27:10] AngryPerson: its an ancient cms thats clearly past its time
[20:27:20] AngryPerson: its only privately supported with little community support
[20:28:34] AngryPerson: Moo^_^: why are you even in here?
[20:28:40] AngryPerson: you just want to piss on joomla?
[20:28:43] me: we do business on drupal, joomla and plone
[20:28:48] me: different tool for different job
[20:28:51] -*- y shrugs
[20:29:01] AngryPerson: just seems to me like you want to push ppl away from joomla
[20:29:11] x: z: After 6 months I'm still a Joomla noob. I need a consulting services company that will do the security patching, maintenance, service on the site, and host it.
[20:29:25] me: not true
[20:29:36] AngryPerson: Moo^_^: well regardless of what you say, tahts how it seems to me
[20:29:54] z: actually I've had good luck just following a few blog posts
[20:30:10] me: I don't defend myself, as I don't want to engage such a conversation with you
[20:30:22] AngryPerson: thats good, why dont you fuck off too
[20:30:22] <-* jools has kicked y from #joomla (Please watch your language) [20:30:22] --> y (dgdf@unaffiliated/anti-mttr/x-9384728) has joined #joomla
[20:30:27] z: nothing is impervious, but you drastically reduce your attractiveness to hackers by a few simple steps
[20:30:32] AngryPerson: stop giving ppl your shitty advice

Read our blog  Subscribe mFabrik blog in a reader Follow us on Twitter Mikko Ohtamaa on LinkedIn

Why people hate Adobe (and have now headache with sports-tracker.com)?



sportstracker.nokia.com was a GPS based sports tracking service for Nokia phones. Around a year ago it spun off as independent company, which was a good move if you really want to develop your service business. Now sports-tracker.com has launched a new website. You can upload your runs and photos there and share your sports results through social media.

It was delightful to see the new site opened and having the features been missing so long time ago. However, I was not totally happy with what I saw.

The whole new site is built on top of Adobe Flash run-time technologies. There are no traditional web pages per se.

The problem is that full page Flash is resource hog. In the picture above you see that opening this web site in my Safari web browser spikes CPU to 100% usage – and it actually stays there indefinitely (note: on front page, see remarks below). This means that my computer is working to barely survive under the stress caused by this one web site – and my computer is powerful iMac. This means that if I have this site open background in my web browser my laptop battery would die very very fast. This means that all programs I try to simultaneously use on my computer become sluggish.

I assume that when sports-tracker.com was spun off from Nokia they contracted some digital advertisiment agency to built the new site for them. Digital advertisement agencies are often, not always, companies focused on the brand and visual appearance. They love to work with Flash because it gives good authoring tools to build nice looking, bling bling filled, animations.  Flash is a great tool for animations. Flash is a great tool for building browser based games. However, it is not good for building the whole web site where the user experience criteria could include 1) the site actually to responds to clicks 2) the site does not bring down to the whole computer. The decision makers probably drink cool-aid “hey let’s built the site with the Adobe’s latest tools – have you seen the demos how coooooool they look like”.

The thing is, I want to just see my sports tracking results. I don’t care whether the diagrams have blurred drop shadows with state of the art Web 3.0 mouse over effects. Now I can enjoy the effects, points for the artistic leader for that, but doing the actual task, accessing my sports results, have become irritating task to do. Things respond sloooow – that’s the main reason. In-flash scrolls bars have noticeable lag.

There exists an uncanny valley how normal web sites behave and how 100% Flash site behave. My right click does not work. I cannot right click a link and open it in new tab. I cannot right click a link to copy it to my friend. I cannot access the site on my N900 web browser (which even has Flash). I coudn’t even send feedback to sports-tracker.com team without first installing a desktop email client, as the email address cannot be copied from Flash to web mail. Text boxes are little different.

I cannot hold my horses to see Adobe conquering mobile phones with Flash and doing the same thing for mobile browsing experience it has now done for sports-tracker.com.

The site is not bad. Usability guidelines have been followed carefully when building the site. The developers seem to have gone into great details to make the operations smooth as possible. For example, URL fragment identifies are used to make sure bookmarking works even though Flash is present on the site. Social media features, not present in old sport tracker, are finally there. The results of design decision to built the whole site on Flash, instead of using Flash for some components only, might not have been seen by the time this decision was taken.

When Nokia Sports Tracker was first introduced 3-4 years ago with the first Series 60 GPS phones it was ahead of the competition. Wow effect had no limits – can you really do that with your mobile phone – in real-time and live?

It is funny how time passes.

It is definitely possible to build a sports tracking site, which looks cool, but does not have issues mentioned here.

Note: With little more research it seems that CPU usage stays 100% is specific to front page only and it has issues of not winding down action when you move away from your browser. However, rendering of other pages still uses vast amount of CPU, causing lag you do not see when opening web pages. The background CPU consumption on sports-tracker.com page is aroud 8% per tab when should be 0%.

Note 2: I am using the latest 10.1  Flash Player.

Read our blog  Subscribe mFabrik blog in a reader Follow us on Twitter Mikko Ohtamaa on LinkedIn

.gitignore for Python developers



If you are using Git for version control for your Python egg and buildout development below are is a sample which you might want to put into your .gitignore file.

*.mo
*.egg-info
*.egg
*.EGG
*.EGG-INFO
bin
build
develop-eggs
downloads
eggs
fake-eggs
parts
dist
.installed.cfg
.mr.developer.cfg
.hg
.bzr
.svn
*.pyc
*.pyo
*.tmp*

Suggestions for new ignores are welcome.

Read our blog  Subscribe mFabrik blog in a reader Follow us on Twitter Mikko Ohtamaa on LinkedIn

Looking for free icons?



Check out this Smashing Magazine article with 50 free icons set.

Then there is 14 free mobile application icon set by Speckyboy design magazine.

Ps. Please if you have any good free icon set tips share them in the comments

Read our blog  Subscribe mFabrik blog in a reader Follow us on Twitter Mikko Ohtamaa on LinkedIn

Plone Go Mobile – preparing a release



Enter the mobile world with Plone! Go mobile for Plone add-on is now “feature complete” and we are preparing a release.

For Easter holidays we bring you a trunk release instructions. Note: you might want to change checkout protocol from “https” to “http” in the buildout cfg. The most able and most inpatient might want to test this now when it is hot.

There exists three production site where you can see the product in action

See the feature set which will beat crap out of other mobile CMSs.

What’s missing for the real release is

  • packaging it as a eggs
  • making microsite
  • clean up documentation (YES. It has documentation since day 0)

It has not been tested on Plone 4.

Thanks Karl Horak for bringing up the issue.

Meet mFabrik @ Internet Expo 2010 Helsinki



If you can’t see the video above, please go to mfabrik.fi.

mFabrik will participate in INTERNET EXPO which is the biggest “Internet fair event” in Finland. Topics include e.g. social media, sematic web and IT security. Many major Internet companies and their products will be present.

Our expo representatives, as in the video above, will gladly help you to tell about mobile and CMS solutions.

You can get free tickets using the code provided on mfabrik.fi page.

Now hiring (Developer, Helsinki)



We are looking for a new developer to join our production team in Helsinki, Finland. Check out the details at our web site:

http://mfabrik.com/about-us/jobs/developer-helsinki

Integrating and theming WordPress with your CMS site using XDV



Introduction

XDV is an external HTML theming engine, a.k.a. theming proxy, which allows you to mix and match HTML and CSS from internal and external sites by using simple XML rules. It separates the theme development from the site development, so that people with little HTML and CSS knowledge can create themes without need to know underlying Python, PHP or whatever. It also enables integration of different services and sites to one, unified, user experience. For example, XDV is used by plone.org <http://plone.org> to integrate Plone CMS and Trac issue tracker. XDV compiles theming rules to XSL templates, which has been a standard XML based templates language since 1999. XSL has good support in every programming language and web server out there. Example backends to perform XSL transformation include

  • Python and lxml library
  • Apache’s mod_transform
  • nginx web server
  • All XSL capable Java and .NET software out there

XDV theming can be used together with Plone where enhanced support is provided by collective.xdv package package. Technically, collective.xdv adds Plone settings panel and does XSL transformation in Zope’s post-publication hook using lxml library. XDV can be used standalone with XDV package to theme any web site, let it be WordPress, Joomla, Drupal or custom in-house PHP solution from year 2000. XDV is based on Deliverance specification The difference between XDV and Deliverance reference implementation is that XDV internally compiles themes to XSL templates, when Deliverance relies on processing HTML in Python. Currently XDV approach seems to be working better, as we had many problems trying to apply Deliverance for WordPress site (redirects didn’t work, HTTP posts didn’t work, etc.).

Setting up XDV development tools

XDV tools are deployed as Python eggs. You can use tools like buildout <http://www.buildout.org/> configuration and assembly tool or easy_install to get XDV on your development computer and the server. If you are working with Plone you can integrate XDV to your site existing buildout. If you are not working with Plone, XDV home page has instructions how to deploy XDV command standalone.

XDV Rules

Rules (rules.xml) will tell how to fit content from external source to your theme HTML. It provides straightforward XML based syntax to manipulate HTML easily

  • Append, replace and drop HTML pieces
  • Insert HTML snippets
  • CSS or XPath selectors can be used to identify HTML parts
  • It is possible to mix and match content from more than two sites
  • etc.

Rules XML syntax is documented at XDV homepage. Rules will be compiled to XSL template (theme.xsl) by xdvcompiler command. The actual theming is done by one of the XSL backends listed above, by taking HTML as input and applying XSL transformations on it. Note that currently rules without matching selectors are silently ignored and there is no bullet-proof way to debug what happens inside XSL transformation, except by looking into compiled theme.xsl.

Using XDV to theme and integrate a WordPress site

Below are instructions how to integrate a WordPress site to your CMS. In this example CMS is Plone, but it could be any other system. We will create XDV theme which will theme WordPress site to match our CMS site in the fly.

WordPress theme using built with XDV and using a live Plone web page as a theme template. This way WordPress theme inherits “live data” from Plone site, like top tabs (portal sections), footer, CSS and other stuff which can be changed in-the-fly and reflecting changes to two separaet theming products would be cumbersome. Benefits using WordPress for blogging instead of main CMS

  • WordPress post and comment management is easy
  • WordPress does not need to be touched: the old public WordPress instance can keep happily running wherever it is during the whole process
  • You do not need to migrate legacy WordPress installations to your CMS’s internal blogging tool
  • WordPress comes with extensive blog spam filtering tools. We get 11000 spam comments a month.
  • WordPress is designed for blogging and the user interface is good for that
  • WordPress integrates well with blog pingback support services
  • WordPress supports Gravatars and other blogging plug-ins
  • ..and so on…

Benefits of using XDV theming instead of creating native WordPress theme are

  • You need to maintain only one theming add-on product e.g. one for your main CMS and WordPress receives updates to this site and theme automatically
  • WordPress does not need to be touched
  • You can host your WordPress on a different server, even wordpress.com, and still integrate it to your main CMS
  • The theme can be recycled not only for WordPress, but also other external services: Bugzilla, Trac, Webmail, phpBB, you-name-it
  • Even though WordPress has slick UI, it is a well known fact that it is a can of worms internally. My developers do not like the idea of PHP development and would spit on my face if I ask them to go a develop a WordPress theme for us

Theme elements

The theme will consist of following pieces

  • Deliverance rules XML file which defines how to combine Plone and WordPress HTML (rules.xml)
  • Additional CSS definitions active only for WordPress (wordpress.css). Dependency to this CSS in injected to the <head> by rules XML
  • Special Plone page template which will provide slots where WordPress can drop in the content (wordpress_listing.pt)
  • A helper script which makes it easy for repeatable perform theming actions, like recompiling the theme (xdv.py)

CMS page template

This explains how to create a Plone page template where WordPress content will be dropped in. This step is not necessary, as we could do this without touching the Plone. However, it makes things more straightforward and explicit when we known that WordPress theme uses a certain template and we explicitly define slots for WordPress content there. Example:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="here/main_template/macros/master"
      i18n:domain="plone">

<body>

    <div metal:fill-slot="content">

        <div id="wordpress-content">
                <!-- Your WordPress "left column" will go there -->
        </div>

    </div>

</body>
</html>

Theming rules

Following are XDV rules (rules.xml) how we will fit WordPress site to Plone frame. It will integrate

  • Content from WordPress
  • Metadata from WordPress
  • CSS from Plone
  • Page basic structrure from Plone

rules.xml:

<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://namespaces.plone.org/xdv"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:css="http://namespaces.plone.org/xdv+css">

    <!-- Remove WordPress CSS by filtering out <style> tags-->
    <drop css:content="style" />

    <!-- Make sure that WordPress metadata is present in <head> section -->
    <append css:content="head link" css:theme="head" />

    <!-- note: replace does not seem to handle multiple meta tags very well -->
    <drop css:theme="meta" />
    <append css:content="head meta" css:theme="head" />

    <!-- Use blog title instead of Plone page title -->
    <replace css:content="title" css:theme="title" />

    <!-- Put WordPress sidebar to Plone's portlets section -->
    <append css:content="#r_sidebar" css:theme="#portal-column-one .visualPadding" />

    <!-- Place wordpress content into our theme content area -->
    <copy css:content="#contentleft" css:theme="#wordpress-content" />

    <!-- This mixes in WordPress specific CSS sheet which is applied for pages
         served from WordPress only and does not concern Plone CMS.
         This stylesheet will theme WordPress specific tags,
         like blog posts and comment fields.
         We keep this file in Plone, but this could be served from elsewhere. -->
    <append css:theme="head">
        <style type="text/css">
           @import url(http://mfabrik.com/++resource++plonetheme.mfabrik/wordpress.css);
        </style>
    </append>

    <!-- This stylesheet is used by special spam protection plug-in NoSpamNX -->
    <append css:theme="head">
        <link rel="stylesheet" href="http://blog.mfabrik.com/wp-content/plugins/nospamnx/nospamnx.css" type="text/css" />
    </append>

    <!-- Remove Google Analytics script used for CMS site -->
    <drop css:theme="#page-bottom script" />

    <!-- Rebuild our Google Analytics code, using a different tracker id this time
         which is a specific to our blog.
      -->
    <append css:theme="#page-bottom">

        <script type="text/javascript">
                var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
                document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
        </script>

        <script type="text/javascript">
                try {
                       var pageTracker = _gat._getTracker("UA-8819100-2");
                       pageTracker._trackPageview();
                } catch(err) {
                }
        </script>
    </append>

</rules>

WordPress specific CSS

This CSS has styles which are applied only to WordPress pages. They are mainly corner case fixes where WordPress and CMS styles must match. The CSS file is loaded when rules.xml injects it to <head> section. wordpress.css:

/* Font and block style fixes */

#wordpress-content h1 {
        border: 0;
}

#wordpress-content .post-end {
        margin-bottom: 60px;
}

#wordpress-content pre {
        width: 600px;
        overflow: auto;
        background: white;
        border: 1px solid #888;
}

#wordpress-content ul {
        margin-left: 20px;
}

#wordpress-content .post-info-date,
#wordpress-content .post-info-categories,
#wordpress-content .post-info-tags {
        font-size: 80%;
        color: #888;
}

/* Make sure that posts and comments look sane in our theme */

#wordpress-content .post {
        margin-top: 15px;
}

#wordpress-content .commentlist li {
        margin: 20px;
        background: white;
        padding: 10px;
}

#wordpress-content .commentlist li img {
        float: left;
        margin-right: 20px;
        margin-bottom: 20px;
}

#wordpress-content #commentform {
        margin: 20px;
}

#wordpress-content {
        margin-left: 20px;
        margin-right: 20px;
}

/* Make WordPress "sidebaar" look like Plone "portlets */

.template-wordpress_listing #portal-column-one ul {
        list-style: none;
        margin-bottom: 40px;
}

.template-wordpress_listing #portal-column-one ul#Recent li {
        margin-bottom: 8px;
}

.template-wordpress_listing #portal-column-one ul#Categories a {
        line-height: 120%;
}

.template-wordpress_listing #portal-column-one h2 {
        background: transparent;
        border: 0;
        font-weight:normal;
        line-height:1.6em;
        padding:0;
        text-transform:none;
        font-size: 16px;
        color: #9b9b9b;
        border-bottom:4px solid #CDCDCD;
}

Helper script

The following Python script (xdv.py) makes it easy for us

  • Recompile the theme
  • Test the theme applied on the site
  • Preview the theme in our browser
It is basically wrapped with default file locations around
bin/xdvcompiler and bin/xdvrun commands with some webbrowser opening magic.

xdv.py:

"""

 This command line Python script compiles your rules.xml to XDV XSL

 Modify it for your own needs.

 It assumes your buildout.cfg has xdv section and generated XDV
 commands under bin/

 To compile, execute in the buildout folder::

     python src/plonetheme.mfabrik/xdv.py

 To build test HTML::

     python src/plonetheme.mfabrik/xdv.py --test

 To build test HTML and preview it in browser, execute in buildout folder::

     python src/plonetheme.mfabrik/xdv.py --preview

"""

import getopt, sys
import os
import webbrowser

# rules XML for theming
RULES_XML = "src/plonetheme.mfabrik/deliverance/etc/rules.xml"

# Which XSL file to generate for compiled XDV
OUTPUT_FILE = "theme.xsl"

# Which file to generate applied theme test runs
TEST_HTML_FILE = "test.html"

# Our "theme.html" is a remote template served for each request.
# Because we are doing live integrattion, this is a HTTP resource,
# not a local file.
THEME="http://mfabrik.com/news/wordpress_listing/"

#
# External site you are theming.
# Note: must have ending slash (lxm cannot handle redirects)
#
SITE="http://blog.twinapex.fi/"

try:
    opts, args = getopt.getopt(sys.argv[1:], "pt", ["preview", "test"])
except getopt.GetoptError, err:
    # print help information and exit:
    print str(err) # will print something like "option -a not recognized"

# Convert options to simple list
opts = [ opt for opt, value in opts ]

print "Compiling transformation"
value = os.system("bin/xdvcompiler -o " + OUTPUT_FILE + " " + RULES_XML +" " + THEME)
if value != 0:
    print "Compilation failed"
    sys.exit(1)

if "-p" in opts or "--preview" in opts or "-t" in opts or "--test" in opts:
      print "Generating test HTML page"
      value = os.system("bin/xdvrun -o " + TEST_HTML_FILE + " " + OUTPUT_FILE + " " + SITE)
      if value != 0:
          print "Page transformation failed"
          sys.exit(1)

if "-p" in opts or "--preview" in opts:
    # Preview the result in a browser
    # NOTE: OSX needs Python >= 2.5 to make this work

    # Make sure test run succeeded
    url = "file://" + os.path.abspath(TEST_HTML_FILE)
    print "Opening:" + url

    # We prefer Firefox for preview for its superious
    # Firebug HTML debugger and XPath rule generator
    try:
        browser = webbrowser.get("firefox")
    except webbrowser.Error:
        # No FF on the system, or OSX which can't find its browsers
        browser = webbrowser.get()

    browser.open_new_tab(url)

Compiling the theme

This will generate XSL templates to do theming transform. It will compile rules XML with some boilerplate XSL. Running our compile script:

python src/plonetheme.mfabrik/xdv.py

Since Plone usually does not use any relative paths or relative resources in HTML, we do not give the parameter “Absolute prefix” to the compilation stage. In Plone, everything is mapped through a virtual hosting aware resource locator: portal_url and VirtualHostMonster. For more information see

Testing the theme

The following command will apply theme for an example external page:

bin/xdvrun -o theme.html theme.xsl http://blog.twinapex.fi
firefox theme.xhtml

… or we can use shortcut provided by our script …

python src/plonetheme.mfabrik/xdv.py --preview

Applying the theme in Apache production environment

These steps tell how to apply the integration theme for WordPress when WordPress is running under Apache virtualhost.

Installing dependencies

We use Apache and mod_transform. Instructions how to set up modules for Apache are available on XDV homepage. Some hand-build modules must be used, but instructions to set them up for Ubuntu / Debian are available. Apache 2 supports filter chains which allow you to perform magic on HTTP response before sending it out. This corresponds Python’s WSGI middleware. We’ll use special built of mod_transform and mod_depends which are known to working. These modules were forked from their orignal creations to make them XDV compatible, as the orignal has not been updated since 2004 (here you can nicely see how open source guarantees “won’t run out of support” freedom).

Example:

sudo -i
apt-get install libxslt1-dev libapache2-mod-apreq2 libapreq2-dev apache2-threaded-dev
wget http://html-xslt.googlecode.com/files/mod-transform-html-xslt.tgz
wget http://html-xslt.googlecode.com/files/mod-depends-html-xslt.tgz
tar -xzf mod-transform-html-xslt.tgz
tar -xzf mod-depends-html-xslt.tgz
cd mod-depends-html-xslt ; ./configure ; make ; make install ; cd ..
cd mod-transform-html-xslt ; ./configure ; make ; make install ; cd ..

Enable built-in Apache modules:

a2enmod filter
a2enmod ext_filter

For modules depends and transform you need to manually add them to the end of Apache configuration, as they do not provide a2enmod stubs for Debian. Edit /etc/apache2/apache.conf:

LoadModule depends_module /usr/lib/apache2/modules/mod_depends.so
LoadModule transform_module /usr/lib/apache2/modules/mod_transform.so

You need to hard reset Apache to make the new modules effective:

/etc/init.d/apache2 force-reload

Virtual host configuration

Below is our virtualhost configuration which runs WordPress and PHP. Transformation filter chain has been added in. /etc/apache/sites-enabled/blog.mfabrik.com:

<VirtualHost *>

    ServerName blog.mfabrik.com
    ServerAdmin info@mfabrik.com

    LogFormat       combined
    TransferLog     /var/log/apache2/blog.mfabrik.com.log

    # Basic WordPress setup

    Options +Indexes FollowSymLinks +ExecCGI

    DocumentRoot /srv/www/wordpress

    <Directory /srv/www/wordpress>
        Options FollowSymlinks
        AllowOverride All
    </Directory>

    AddType application/x-httpd-php .php .php3 .php4 .php5
    AddType application/x-httpd-php-source .phps

    # Theming set-up

    # This chain is used for public web pages
    FilterDeclare THEME
    FilterProvider THEME XSLT resp=Content-Type $text/html

    TransformOptions +ApacheFS +HTML
    # This is the location of compiled XSL theme transform
    TransformSet /theme.xsl

    # This will make Apache not to reload transformation every time
    # it is performed. Instead, a compiled version is hold in the
    # virtual URL declared above.
    TransformCache /theme.xsl /srv/plone/twinapex.fi/theme.xsl

    # We want to apply theme only for
    # 1. public pages (otherwise WordPress administrative interface stops working)
    <Location "/">
        FilterChain THEME
    </Location>

    # 2. Admin interface and feeds should not receive any kind of theming
    <LocationMatch "(wp-login|wp-admin|wp-includes)">
        # The following resets the filter chain
        # http://httpd.apache.org/docs/2.2/mod/mod_filter.html#filterchain
        FilterChain !
    </LocationMatch>

</VirtualHost>

Running it

After Apache has all modules enabled and your virtualhost configuration is ok, you should see WordPress through your new theme by visiting at the site served through Apache:

Automatically reflecting CMS changes back to XDV theme

The theme should be recompiled every time

  • Plone is restarted: CSS references change in <head> as CSS cache is rebuilt
  • CSS is modified: CSS references change in <head> as CSS cache is rebuilt
  • Plone content is changed and changes reflect back to WordPress theme (e.g. a new top level site section is being added)

This is because the compilation will hard-link resources and template snippets to resulting the theme.xsl file. If hard-linked resources change on the Plone site, the transformation XSL file does not automatically reflect back the changes. It could be possible to use Plone events automatically to rerun theme compilation when concerned resources change. However, the would be quite complex. For now, we are satisfied with a scheduled task which will recompile the theme now and then. Alternatively, mod_transforms could be run in non-cached mode with some performance implications. Here is a shell script, update-wordpress-theme.sh, which will perform the recompilation and make Apache’s transformation cache aware of changes:

#!/bin/sh
#
# Periodically update WordPress theme to reflect changes on CMS site
#

# Recompile theme
sudo -H -u twinapex /bin/sh -c cd /srv/plone/twinapex.fi ; python src/plonetheme.mfabrik/xdv.py

# Make Apache aware of theme changes
sudo apache2ctl graceful

Then we call it periodically in cron job, every 15 minutes in /etc/cron.d/update-wordpress:

# Make WordPress XDV theme to reflect changes on CMS
0,15,30,45 * * * * /srv/plone/twinapex.fi/update-wordpress-theme.sh

Updating WordPress settings

No changes on WordPress needed if the domain name is not changed in the theme transformation process.

Site URL

Unlike Plone, WordPress does not have decent virtual hosting machinery. It knowns only one URL which is uses to refer to the site in the external context (e.g. RSS feeds). This setting can be overridden in

  • WordPress administrative interface
  • wp-config.php

Here is an example how we override this in our wp-config.php:

// http://codex.wordpress.org/Editing_wp-config.php#WordPress_address_.28URL.29
define('WP_HOME','http://blog.mfabrik.com');
define('WP_SITEURL','http://blog.mfabrik.com');

HTTP 404 Not Found special case

Http 404 Not Found responses are not themed by Apache filter chain. This is not possible due to order of pipeline in Apache. As a workaround you can set up a custom HTTP 404 page in WordPress which does not expose the old theme.

  • Go to WordPress admin interface, Theme editor
  • Edit 404.php and modify it so that it does not pull in the WordPress theme:
    <html>
    <head>
    <title>Not found</title>
    </head>
    <body>
    
            <h1>Not Found, Error 404</h1>
            <p>Aaaaw, snap! The page you are looking for no longer exists. It must be our hamster who ate it.</p>
    
            <a href="<?php bloginfo('url'); ?>">Go to blog homepage</a>
    
            <a href="http://mfabrik.com">mFabrik business site</a>
    </body>
    </html>
    

For more information see

Roll-out checklist

Below is a checklist you need to go to through to confirm that the theme integration works on your production site

  • WordPress public pages are loaded with the new theme
  • WordPress login works
  • WordPress administrative interface works
  • RSS feed from WordPress works and contain correct URLs
  • HTTP 404 not found is handled correctly
  • HTTP 302 redirect is handled correctly (i.e. missing / at the end of blog post URL)
  • Changes on CMS site are reflected to WordPress theme within the update delay
  • Old blog site is redirected to new site using HTTP 301 (if applies)

MooTools setOptions() nullifies object references



I bumped up into a problem where the object references where resolved as object copies when I passed them to class instances. That might sound easy to resolve, but unfortunately I was already deep in code and it was difficult to see this. Therefore, here’s a little explanation for those who are facing the same frustrating issue.

Say, you have variable ‘a’ and you want to pass it to a MooTools class B instance during creation. In the easiest case you’d use new B({ myReference: a}) and trust on MooTools’ Class.setOptions() to minify the need of code lines. This is what you should do… well at least that’s what I did and in this case it was a mistake.

It turns out that Class.setOptions() merges it’s arguments to this.options and then takes copy of them via $merge(). That means that any variable references you pass to setOptions() will get copied to this.options and.. well, that’s it. See lines 1170-1173 in uncompressed version of MooTools 1.2:

var Options = new Class({
    setOptions: function(){
        this.options = $merge.run([this.options].extend(arguments));

That effectively nullifies the benefits of Class.setOptions() if you want to pass in variable references..

Here’s a longer example to clarify (use Firebug):

  // The most basic MooTools class that implements options
  // ref is a variable meant for pointing at given object
  // (won't do that, however)
  var B = new Class({
    Implements: Options,
    options: {
      ref: null
    },
    initialize: function(options) {
      this.setOptions(options);
    }
  });

  // Ok let's create an instance that we can pass to B
  // It's similar with all sorts of variables
  var A = new Class({
    initialize: function() {
      this.somevar = 'untouched';
    }
  });
  var a = new A();

  // Create an instance of B and give it somevar as reference
  var b = new B({ ref: a });

  // prints out "untouched" as should
  console.log(b.options.ref.somevar);

  // Let's change the variable (direct access, bad)
  a.somevar = "changed";

  // b's reference should still point to a, right?
  // In that case the following should print "changed",
  // but because our reference object was copied instead
  // of retaining reference to it, we just get "untouched"
  console.log(b.options.ref.somevar);

I don’t know why MooTools wants to make a copy of arguments in setOptions() – propably for performance reasons.