Articles for Tag: php

My State of Textpattern

Drew McClellan has just posted The State of Textpattern over on his site. Drew is not a core TXP developer, but a long time user who has seen the product change and change hands over its life. His concerns are no surprise to me, as we’ve often gone back and forth over IM trying to ease each other’s frustration with the state of the project.

I think Drew has covered most of my frustrations in his State of Textpattern address. I’ve been using it since the Place Name Here redesign in late 2004, and evaluated it for other projects before and used it since. In that time there are some enhancements to the sites I’ve done via other’s plugins, plugins written myself after I’ve seen a need, times when I’ve done things simply to participate in the community and make it look like it had some life [like the theme contest and been in the code enough to know how it works and make a fair amount of my own customizations.

But as time has passed, like Drew, I find myself both concerned and hesitant about continuing to contribute in any way, or keeping it in future plans for my own sites.

I don’t use the product in my typical day to day web development duties [projects are bigger, using other often custom frameworks or languages besides PHP] but I occasionally find myself with time outside of work that I could offer to the project if the motivation was there.

When motivation and time align – the occasional contributor

The times in the past when both motivation and time have aligned and I’ve made contributions like the microformat plugin. The times more recently when that has been the case, were time and motivation to revise my plugins or look for other things to enhance [hAtom templates or OpenID as examples], I haven’t had enough confidence in the project to justify the effort. “Big” changes that have been talked about forever like admin side redesigning or the decision to include [or not] a particular JS library would have a big impact on how I should approach my code and what features I think are a priority. With no development roadmap in sight [again not a timeline, just a commitment to features or general development direction] and no assurances that what has been done in the so called experimental branch will be there next week I find it impossible to plan my own contributions.

And that’s my own biggest area of frustration for the last few months. My investment in any particular product on my own blogs is light. I could jump to WP or EE or some other solution in a weekend and be done with TXP and onto plotting how to address my peeves with the new platform. The investment in a product that others might be downloading and using is a bit more difficult for me to abandon.

The wrong things take work

As much as the direction [or lack there of] is a concern, its only the latest symptom of a something that has always plagued textpattern.

The way product development has been handled since it was opened up to a larger, more open team, has always been difficult to follow. It is a chore to cover the forums, blogs and mailing lists on a regular basis. That their use by the core team go in spurts and ultimately most of the insight into the product comes in the form of replies to inquiries on the forums or individual code checkins only makes it more difficult. Unless it is your job to do so and you’re building sites with TXP on a day to day basis, the commitment that needs to be made before one can just jump in and be a productive contributor has been too great.

Its nice that a core team has formed over time and they’re now looking for ways to sustain themselves, but I agree 100% that its the the lack of open direction, and the occational feeling from some contributors that direction doesn’t need to be or is somehow in a state of development where it cannot be stated that has me concerned and questioning continued use and support of textpattern.

Released: Textpattern Microformat Plugin v1.2

I’ve just updated my microformat plugin for the textpattern CMS and blogging tool. This update is a maintenance fix to add support for Textpattern v1.0.4 and some changes made in the way tag helpers are built. Users of older versions of TXP should stick with the 1.0 version of the plugin.

Future updates to the plugin are planned to add additional microformats support, expand the flexibility of the tag helpers and to streamline the underlying PHP code. If you’re using this plugin — or have chosen not to — please help by posting a comment letting me know how well you think it fits into your writing style.

Redesign: The New Place Name Here

Hey look, I did it!

After roughly six months of sitting on a design I was happy with I’ve found both the time and ambition to finish building an update to Place Name Here. Not quite sure what version of the site this is, but 6 seemed like a good number when I started.

Like with all previous versions of the site the new layout is fairly simple, and doesn’t use a lot of images or tricks to play things up. This site always proves to be difficult to rebuild in a uniform way because of the patchwork of different side projects, and technical demos that have been posted since the site first launched in late 1998. The new design and slightly rearranged navigation will hopefully help give a better perspective of what is hiding on the site.

Though not glitzy, there are a few tricks hiding in the new design which I’ll cover in detail in a future post. One element in particular is the code used to create a “liquid” like layout via JavaScript. If you are reading this and seeing a two column layout the left column is made of content that has been pulled out of the main column and repositioned to fill the gap on the left. This is similar to using floats where content will stack if there isn’t enough room to go side by side, but in this method I can pull content from anywhere in the flow of the main column depending on the given page — introduction content from the top, extra content from the bottom, or something I’d like to highlight from the middle.

Another new site feature is the beginning of better integration with the aggregated content on Place Name Where?. This can be seen in the combined tag searches found on pages such as the PHP tag page. This was really what I build the mechanics behind PNW for, but hadn’t gotten to any implementation before this redesign.

More about the guts of the site can be found in the updated colophon. Please take the new look for a spin and let me know what you think in the comments.

Bitten By A String Change

Just getting around to some much needed maintenance on some of the projects around here and had to chase down something that was plaguing Place Name Where? for a few weeks now. Though I looked at it when it first came up I just didn’t see the cause of the “Node no longer exists in…” messages that PHP5’s SimpleXML was throwing.

Turns out the cause was as simple (pardon the pun) as a string change in Flickr’s RSS feed

The media namespace URL was changed from “http://search.yahoo.com/mrss” to “http://search.yahoo.com/mrss/” (note the new trailing slash) which meant that my application was no longer addressing those elements properly, manifesting in it not loading the Image and Thumbnail urls properly. GRRRRR.

Always the little things I guess. All better now!

Feeds For All With hAtom -- Part 2: The Code

Recently I introduced the idea of adding an Atom feed to any document you want by using hAtom along with a local ‘proxy’ script to generate feeds to pages on your site that otherwise wouldn’t have them. The post seemed well received, but it didn’t feel complete to me without some code to allow people to quickly try it for themselves. So here’s the inevitable followup with an example PHP5 script to show how you can make the hAtom to Atom conversion transparent to a site visitor and add feeds to static pages or pages that otherwise don’t have a more typical Atom feed.

This certainly isn’t a robust script—it doesn’t account for the use of Tidy to manage non-valid or non-XHTML documents, multiple domains or different request methods. It works for my purposes and I left it at that. But the core idea is simple enough that it shouldn’t take long to re-write it for your needs or in your language of choice if they’re different then mine.

The PHP Proxy Script


<?php
ini_set('display_errors', '0');
header('Content-type: application/atom+xml');
//
// configuration
$h2axsl = '/home/user/app/hAtom2Atom.xsl'; // path to hatom2atom.xsl
$domain = 'example.com'; // domain with the hatom content
$permalink_stub = 'hatom2atom.php';// public path to this file
//
// parse request
$requested = $_SERVER['REQUEST_URI'];
$requested = substr_replace($requested,'',0,strlen($permalink_stub)+2);
$requested = urldecode($requested); // deal with encoded #
$docurl = 'http://'.$domain.'/'.$requested;
//
// grab file contents
if (function_exists('curl_init')){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $docurl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
$file_contents = curl_exec($ch);
curl_close($ch);
} else {
$file_contents= file_get_contents($docurl);
}
//
// pass the file through the transform and send it out
$xsl = new DomDocument();
$xsl->load($h2axsl);
$inputdom = new DomDocument();
if ($inputdom->loadXML($file_contents)) {
$proc = new XsltProcessor();
$proc->importStylesheet($xsl);
$proc->setParameter('', 'source-uri', $docurl);
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
}
?>

The script can be broken down into the following parts:

  1. Configuration of paths for support files and requests.
  2. Extracting the location of the desired XHTML document that contains the hAtom content. This script is written so that requests made to hatom2atom.php/some/page would output the Atom feed for the document at http://example.com/some/page.
  3. Grabbing the contents of that XHTML document. In my case I’m making an http request to make sure the file is properly built/parsed, though if your files are static without includes you may want to use local file access methods instead.
  4. Performing the XSL transform and outputting the results.

You can copy and paste the above script, or download it as a .zip.

The XSL Transform

All the magic really happens via XSL and the trusty hatom2atom transform. So download both hAtom2Atom.xsl and uri.xsl and put them into the same directory somewhere on your server. When you do update the following line in the configuration portion of the script to the actual location of hAtom2Atom.xsl:

$h2axsl = '/home/user/app/hAtom2Atom.xsl'; // path to hatom2atom.xsl

Usage & The hAtom Document

Now that the proxy script is in place you should expose the feed to your visitors by including it in the head of the document or as links in the content. For example, if you have some hAtom content in http://example.com/page_with_hatom.html you can add the following link element in the head of that document:

<link rel="alternate" href="/hatom2atom.php/page_with_hatom.html" type="application/atom+xml" title="This Page's Atom feed" />

And any visitor with a browser that picks up on the link element would then identify the page as having a feed. If you want to be more specific about the location of the feed on the page, or you’re dealing with a document with multiple hAtom feeds and you want to specify the fragment ID for the root of the feed you’d do like so:

<link rel="alternate" href="/hatom2atom.php/page_with_hatom.html%23some_fragment" type="application/atom+xml" title="This Page's Atom feed" />

Notice I url encoded the # (as %23) when using a fragment id, this was because many user agents do not send the fragment ID as part of the request so I encoded it to make sure that the information was there for the proxy to manage and then had the script manage things from there.

Prettying up the Request

There are lots of ways to manage requests on your server – from MVC like dispatchers to mod_rewrite to nothing at all, in the case of this script I’ve just used the following rewrite rule that I added to the list of a number of rules I already had allowing me to pretty the url up a bit – and make it a bit more universal or future proof.

RewriteRule ^hatom2atom/(.*)$ hatom2atom.php/$1 [L]

But remember, if you do change the location of the proxy script to change the configuration line or url extraction methods in the script appropriately.

The Results

With the script installed and the feed linked up for users to find you now have Atom feeds for your readers to subscribe to that are generated from hAtom markup in a way that’s totally transparent to them. You can see this method in action in pages like:

Introducing: Place Name Where?

A week or two ago I posted some comments about working with CakePHP for an upcoming project. Well, I’m happy to announce that that project—Place Name Where?—is up.

Place Name Where? is a personal information aggregator that tries to reverse the trend of decentralized content contributions that seems to be one of the core features of “Web 2.0” sites.

Web 2.0 is great, but at a certain point one can feel too distributed. You’ve got news stories here, pictures of your pet dust bunnies over there, and in the cellar you keep your favorite wines. Each service is kind enough to provide ways to include the content you added to their site back into your own site, but typically this is limited to a presentation that doesn’t go further then “hey, look at the last 10 things I did on this other site”.

The site works by regularly grabbing several feeds associated with my accounts on the selected services and then permanently storing a copy of the data on my end. Once I’m free of the restrictions of RSS feeds, APIs or JavaScript embedding techniques I can build much more elaborate views on the data like displaying recent activity across all services or looking up all things tagged with nhl regardless of the type of thing it is. I dubbed it a “Web of Web Things” after the discussions of similar tagging and aggregation of real world Web, or Internet of Things (call them spimes, blogjects, or whatever you’d like) by Bruce Sterling, Adam Greenfield, and others.

This aggregator isn’t intended to be a stand alone site forever—though it does work fairly well as such. I need to find some time to spend working on design and integration issues, but I hope it won’t be too long until the ideas behind Place Name Where? are integrated into this site and appear both in place of the current “link” lists as well as integrated into tag lookups and maybe search results.