Ramblings On A Multi-Site Textpattern Install

A while back, after running Textpattern on Place Name Here I got the bright idea to duplicate or syndicate (or whatever you want to call it) the web tech related postings over at the more focused ChunkySoup.net as a way to freshen that place up a bit. Sure, I could have just parsed the Atom feed from the originating site and then drop the results on the homepage of the other one, but what fun would that be… and it wouldn’t be particularly friendly either.

And thus began the Textpattern hacking.

The goal – to get two sites sharing the same articles, comments and feeds with different restrictions and presentations and with no manual work to keep in sync on a dat to day basis.

Now I’ve gone through the hacking process a few times, most recently to update the site to run off the 4.0 (and then before I could get it done the 4.01) codebase, and I’ve refined things to the point where they’re easy enough to explain. (clearly I hope). I won’t post code here, because specifics have changed a bit with different TXP versions, but I’ll try and outline what has to be done and where.

There’s really two changes at work here, first is to get 2 different sites with two different appearances, locations and configurations working from the same centralized content repository, and the second is to get one of those sites to only present a portion of that content (in this case, anything posted in the “web” category.

To get the two sites working off the same content, but looking differently we need to get them both access to the same database, and define some shared tables and some site specific tables. Those that each site needed on its own are as follows, the rest are shared:

  • txp_css
  • txp_form
  • txp_log
  • txp_log_mention
  • txp_page
  • txp_plugin
  • txp_prefs

For each of these tables I duplicated them for the second install (using a postfix, as the is already a prefix facility in the code), added a method in txplib_db.php to clean up the table name generation and add the postfix found in the config.php file if the table called is in the subset defined above, and off we were. Almost. Duplicating the tables isn’t enough, for the second site we at least need to update the domain of the site in the prefs file so we can go in and manage the rest of the preference and template changes via the admin interface of each site.

Ah, but there’s a hitch! For the most part the textpattern data layout is clean and the separation of the data above for one site or the other went flawlessly – except for one field stored in the prefs table – last modified date. Somehow, probably for lack of a clearly better place, this value that got stuck as an entry in the site preference table. To work with this, it was necessary to add code in 3 or 4 places where that field may be updated to update it for both sites (txp_article.php, txp_link.php, comment.php). [note to texpattern maintainers: I suggest either storing this value someplace that is more representative of its association with the content, or alternatively writing a utility function to manage all updates to this field from a central place instead of having it scattered about .]

At this point, I’ll drop the modified files in the textpattern folder for both sites and, after editing their preferences, they should be up and running with their own looks, but with the same content, shared comments and seeing new articles and links as added.

The second part of the process took a little more knowledge of the code and tags behind TXP templates. It be wonderful if there was a way to restrict every article related tag (from article display, to next article, etc.) by category and have the work done for me, but it just wasn’t that easy. The standard method of including articles (the apt named article tag) is just too smart and relies too much on context to do it, and the alternatives (other tags, or plugins) though they may allow restriction by category just didn’t seem to offer the flexibility that the article tag does when dealing with article lists, pagination, viewing single articles and whatever other magic it works.

So off to modify a few queries. And when I say a few I really mean it. It was only necessary to modify queries in publish.php, and the files that generate the feeds (atom.php & rss.php) to only pull articles or references where either one of the categories matched the one I wanted to restrict the site to (“web”).

And thats it. As I noted above, TXP has matured enough, and a lot that recently, that the code is fairly clean and well organized and aside from the last modified date issue (which can just be turned off in the prefs anyway).

And one last note on version updates should you kids choose to try this at home, I still use PNH as the “primary” install (including not adding a postfix to the tables) so that I can run the stock update scripts if they change the database structure and then migrate those changes over to the other install. Have to then in and reapply my changes in the code, and I’m done and ready for testing in a few minutes.

This entry was posted in meta, web. Bookmark the permalink.

4 Responses to Ramblings On A Multi-Site Textpattern Install

  1. You’ve accidently written the storage provider of the Textpattern theming engine, I suppose. Separating presentation from content, that is.

    Add a method of changing those presentational tables on the fly and preload them with contents: Voila, themes.

  2. chris says:

    Interesting take Robert, but on first glance I think it would take a bit more separation both in the admin side and data tables side to reall get that break clean… particularly on the prefs side.

    In my 2 site build I separated the prefs tables completely.. in a theme scenario I’d think you’d have to be much more picky about what was theme specific and what was site/install specific. I’m sure you’re follwing the theme discussions elsewhere but things like:

    * site name

    * time zone

    * clean urls

    * who to ping

    …are all install specific, but things in the same UI and data table that would have to be cloned for each theme include:

    * attaching comment forms automatically

    * date display formats

    * comments as list items or not

    … etc. etc. And then what about plugins? That might not be an issue, but from the looks of it some existing theme authors are looking for ways to require or bundle plugins. How do you manage what is theme specific and what you want installed no matter what?

    Not trying to shoot the idea down. most of the issues I mention need to be resolved regardless of how themes are managed (and I’ve said so elsewhere). Just saying that I don’t think its as easy as claiming what I’ve done here is all the work that’s needed on the DB end.

  3. Ah, the finer details… Sure you’re right. But what struck me most with your approach was the simplicity of how you extended the existing Textpattern code to provide a large portion of stress relief. Alex’ initial post at Textbook lists some requirements, one of them being:

    Install and uninstall should be easy and non-destructive, no unrecoverable data should be lost or overwritten

    All suggestions I have seen up to now are somehow based around folders and files (mimicking WordPress’ behaviour), so your table based approach looks to me like an Egg of Columbus, at least as a starting point.

  4. Ziami says:

    hmm, i test now Textpattern and will create subpages and posts witch defferent themes. @ Chris – thanks for tutorial, must test it :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>