1. More SimpleXML to display OPML

    jake on 2010.04.22 at 05:28 pm

    Matt Katz recently sent in an email regarding the code we use to display our OPML lists. He needed a second pair of eyes to go over his new class. Turned out the bug wasn’t in his display function but the once over highlighted some other issues with ours.

    The pages here are now updated but we can’t keep this all to ourselves. Here’s the updated code for traversing an OPML file.

    function displayChildrenRecursive($xmlObj,$depth=1) {
    	$outPut = "";
    	if (count($xmlObj->children()) > 0) { $outPut .= str_repeat("\t",$depth).'<ul class="opmlGroup">'."\n"; }
    	foreach($xmlObj->children() as $child) {
    		if (isset($child['htmlUrl']) || isset($child['xmlUrl'])) 
    			$outPut .= str_repeat("\t",$depth).'<li>';
    			if (isset($child['htmlUrl']))
    				$outPut .= '<a href="'.htmlentities($child['htmlUrl']).'"';
    				$outPut .= (isset($child['description'])) ? ' title="'.htmlentities($child['description']).'"' : '';
    				$outPut .= '>'.$child['text'].'</a>';
    				$outPut .= $child['text'];
    			$outPut .= (isset($child['xmlUrl'])) ? ' [<a href="'.htmlentities($child['xmlUrl']).'">XML Feed</a>]' : '';
    			$outPut .= '</li>'."\n";
    		elseif (isset($child['text']) &amp;&amp; !isset($child['xmlUrl'])) 
    			$outPut .= str_repeat("\t",$depth).'<li><h'.($depth+1).'>'.$child['text'].'</h'.($depth+1).'>'."\n";
    		$outPut .= displayChildrenRecursive($child,$depth+1);
    	if (count($xmlObj->children()) > 0) { $outPut .= str_repeat("\t",$depth).'</ul>'."\n"; 
    		if ($depth > 1) { $outPut .= str_repeat("\t",$depth-1).'</li>'."\n"; }
    	return $outPut;

    Posted in: Programming · Web

    Talk Bubble 0 Comments

  2. Fixing a launchd and svnserve problem on Leopard

    jake on 2008.06.12 at 12:12 am

    It’s not too difficult to configure the basics of Subversion (Leopard includes it). But it’s not a huge leap to want the server component running perpetually in the background. That’s not as straight forward. Instructions exist but a few snags with launchctl means you cannot automate svnserve’s launch. It didn’t work on the first try for me.

    But after that hurdle an issue arose where my machine starts the service, and then restarts it, again and again. A little digging reveals the console reporting “Exited with exit code: 1” and if you look at the launchctl list the status is also set to 1. Google isn’t much help so it’s time for trial and error. After pulling a few commands from the .plist file there’s still a successful launch and the restart problem goes away.

    The following are the superfluous properties (it’s possible there are more you can remove).


    Happy editing!

    Posted in: Apple · Programming

    Talk Bubble 1 Comments

  3. HTML5 Doesn't Like You Citing People

    jake on 2008.02.21 at 12:01 am

    Yesterday Mark Pilgrim pointed out something odd in the HTML5 draft spec. In the reference for the cite element (including a snarky comment) the author has declared that people cannot be cited. At least not with the cite element (neither can ships, but they only really offer wisdom in cartoons). As we push for more semantics this draft pulls them away.

    A person’s name is not the title of a work — even if people call that person a piece of work — and the element must therefore not be used to mark up people’s names.

    Read More

    Posted in: Programming · Rant · Web

    Talk Bubble 0 Comments

  4. Textpattern Plugin Preferences With set_pref

    jake on 2008.01.23 at 05:57 pm

    To insert preferences into the Textpattern database you use a function called set_pref. There is one area of the command that generated confusion while I was working on my latest plugin.

    set_pref($name, $val, $event, $type)

    Most of the information you pass to set_pref is straightforward. The $name and $val are simply the name of the variable for the database and the value of that variable. $event is what the preference is associated with, in this case the name of my plugin. But it’s harder to surmise the effect of $type. And a search through Google and the Textpattern forums returns no explanation.

    Originally I copied another developer and set this value to 0. While this works it also adds all the settings alphabetically to the main preferences tab. Because I already have a separate tab for my plugin (and this option adds clutter) having all the settings duplicated and unformatted is not ideal.

    Setting the $type variable to 2 creates a hidden preference. No more list in the main preferences yet I can access the information. This is how my plugin is now set up.

    I have not made attempts to set the value to 1 nor do I know if there are other possibilities. Please leave a comment if you can explain this further and help other developers.


    Thanks to Mary we now have clarification on the $type setting. If you go into Admin->Preferences you’ll see Basic and Advanced tabs. The 0 and 1 are to place preferences on these respective pages. The Basic tab is primarily for system settings. But the advanced can be used for a few, relevant options.In most circumstances managing the preferences on another page and using the 2 (hidden) setting makes the most sense.

    Posted in: Programming · Web

    Talk Bubble 2 Comments

  5. Plugin To Import Tumblr Posts Into A Textpattern Site

    jake on 2007.12.30 at 07:50 pm

    Jess, a friend of Brian and I, has had a blog for a few years. And similar to me (and many authors out there) she can be sporadic at times and not post for weeks at a time (Hopefully this has nothing to do with the site needing a refresh).

    Supplementing her blog she’s been posting with Tumblr. Her Tumblog works great for short posts that don’t require a great deal of forethought. Each site handles a different style. Too bad they’re separate.

    To remedy the lack of continuity Brian suggested I build a plugin for her Textpattern site to pull in Tumblr posts. After working on it a couple weekends and going through some testing I’m ready to release my plugin to the masses.

    It is named vag_tumblr_import and now Jess has both sites meshed together. Regardless of where she posts the content is displayed on her primary site.

    More Information…

    Posted in: Programming · Web

    Talk Bubble 0 Comments

  6. Leopard's Input Buttons Can Have Color?

    jake on 2007.10.30 at 02:09 am

    Back in college Brian used to randomly proclaim things he was reading online if he thought I’d be interested. He reenacted this over the weekend while I was visiting Boston. He stumbled upon some information involving Leopard’s rendering of submit buttons. Setting a background color removes Safari’s default aqua buttons and produces flat buttons with the declared background color.

    Mr Dominey’s solution of setting a class or removing the styles all together works for restoring the default visuals. But it makes more sense to simply change them from input type="button|submit" to button type="submit". Using button instead of input reaps similar benefits when it comes to inheritance in non Safari browsers too.

    Screenshot of the form test in Safari Beta for Windows Update: I spoke a little hastily last night. Brian thought it best that I test out my theory before mentioning it. Since I don’t have Leopard installed I had to use the Safari beta on Windows. It actually confirmed my hypothesis. Though in the beta Dominey’s solution actually failed. Can anyone take a look in Leopard?

    I also rediscovered that Safari 2 does not handle buttons the same when using the button element. Not too mention IE6’s issues with buttons. They’re still usable but can require a little hacking… but then again what in IE6 doesn’t require a little hacking? ;)

    Posted in: Design · Programming · Standards · Web

    Talk Bubble 0 Comments

  7. Using PHP's SimpleXML to display OPML

    jake on 2007.05.19 at 06:25 pm

    We like sharing OPML files listing the feeds Brian and I read. Originally we used a simple script that just spit out a long unordered list without much structure. Over time the file it was based on disappeared and the code became muddled. It was time to start fresh.

    After some searching I found the Optimal OPML Browser which looked to be a good replacement with minimal effort. But after it failed to work I discovered that our host does not have all the requirements installed.

    What to do?

    In a recent article Tim Koschuetzki wrote about parsing, the more general, XML with PHP 5’s new SimpleXML. Using SimpleXML and a recursive function I could now sift through the OPML and write out some XHTML compliant code.

    First a recursive function modified from Tim’s simple indented text display.

    function displayChildrenRecursive($xmlObj,$depth=1) {
    	if (count($xmlObj->children()) > 0) { echo str_repeat("\t",$depth).''<ul class="opmlGroup">'."\n"; }
    	foreach($xmlObj->children() as $child) {
    		if (isset($child['htmlUrl'])) {
    			echo str_repeat("t",$depth).'<li><a href="'.htmlentities($child['htmlUrl']).'" title="'.htmlentities($child['description']).'">'.htmlentities($child['text']).'</a> [<a href="'.htmlentities($child['xmlUrl']).'">XML Feed</a>]</li>'."n";
    		} elseif (isset($child['text']) && !isset($child['htmlUrl'])) {
    			echo str_repeat("\t",$depth).'<li><h'.($depth+1).'>'.htmlentities($child['text']).'</h'.($depth+1).'>'."n";
    	if (count($xmlObj->children()) > 0) { 
    		echo str_repeat("\t",$depth).'</ul>'."\n"; 
    		if ($depth > 1) { echo str_repeat("\t",$depth-1).'</li>'."\n"; }

    The first thing you see is an if statement to check for children. When children are found it creates a new unordered list to wrap them in. It then loops through all of said children looking for new possible groups and any actual feeds. Notice the function being called within itself to spit out children’s children. And finally a check again to close out that depth’s list.

    Now that we have the function to parse through the file we need to create a new instance of the SimpleXML object and call the function.

    $opmlFile = new SimpleXMLElement("path to OPML file",null,true);

    One thing you may notice is that instead of referencing the entire object I target only the body with $opmlFile->body. This gives us the list of feeds instead of the entire file.

    Again we have a functional method for listing OPML files. And this more robust method leaves things open for future modifications. Please let me know if you have any questions about the above method.

    Posted in: Programming · Web

    Talk Bubble 1 Comments

  8. Clean Archives in Wordpress

    jake on 2007.05.12 at 04:33 pm

    While working on Kate’s site recently I stumbled upon an issue with the SRG Clean Archives plugin I installed last year. When the plugin is displaying the archive it makes a lot of extra calls to the database. This slows down the page a lot just to display the number of comments a post has. And the more posts you have the slower it gets.

    My solution is to simply add a join to the second query so that it grabs the comment count for each post in one call. To implement this fix you replace the second query with the following (currently line 32).

     $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status, count(".$wpdb->comments.".comment_id) as comments_count FROM " . $wpdb->posts . " LEFT JOIN ".$wpdb->comments." ON ".$wpdb->posts.".id=".$wpdb->comments.".comment_post_ID AND (".$wpdb->comments.".comment_approved='1') WHERE post_date LIKE '$thisyear-$thismonth-%' AND $current_posts AND post_status='publish' AND post_password='' group by ID ORDER BY post_date DESC");

    Now you get comments_count almost (using $arcresult2->comments_count) just like before with the single call. The final step to showing the count is to uncomment the code toward the bottom, remember you only need the if statement and not the extra queries, and replace $comments_count with $arcresult2->comments_count.

    I sent these code updates to the original author Shawn Grimes. He has passed the plugin’s maintenance to another Sean so I thought sharing would be nice for both the new author and the general public. Please let me know if I let any bugs through or if anything is unclear. Thanks to Shawn and Sean for building this plugin in the first place.

    Posted in: Programming · Web

    Talk Bubble 1 Comments

by date

« May 2020 »
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30