Dented Reality

All posts tagged 'php'

Import DokuWiki pages into WordPress

I used to maintain a wiki full of personal ideas using DokuWiki, but at some point just gave up with wiki syntax entirely. A few months ago when I was moving all of my sites and content over to a new server and trying to consolidate things as much as possible, I decided to import all of that old content into a WordPress install (which was actually a single site within the same Multi-site install that runs Dented Reality). I ended up writing the following super-rough script to just scrape the contents of the pages and throw them into WordPress. Scraping the pages meant that I could get the actual output of all plugins etc, and also get full links between pages.

Read the rest of this post…

My Development Setup/Flow

Developers seem to love to hear about how other developers work, so I thought I’d try to capture my entire environment, from end to end, in a single post. This will change (has changed) over time and depending on the project/company/whatever, but this is how things are for me right now. A couple of points up front:

  • I work for Automattic, so a lot of this is influenced by our internal policies/security/workflow.
  • I don’t always use all components of this “system”. I’ll try to detail when I do/don’t use certain parts of it as I go.

OK, here goes.

Note: This turned into a little bit of a summary of how we work internally at Automattic as well. Oh well, maybe it’ll provide some inspiration, I think we do some pretty cool things.

Read the rest of this post…

BackPress, Your New Best Friend

If you’ve spent some time poking around in the code for either WordPress or bbPress, you may have come across comments that mention “BackPress”. You may have wondered what this BackPress thing was, well, wonder no more.

In the last few days, I’ve put together a quick site to try to help introduce people to the BackPress project. From the site:

BackPress is a PHP library of core functionality for web applications. It grew out of the immensely popular WordPress project, and is also the core of the bbPress and GlotPress sister-projects.

So effectively, BackPress takes all of the best core functionality (on a code level) from WordPress and bbPress, and makes it available to you and your next PHP-based web application/project. By using BackPress in your projects, you are then able to use most of the code you’ve come to rely on while working on WordPress-based projects, such as $wpdb, trailingslashit(), make_clickable(), __(), wp_remote_fopen() and more. The site includes some details on how to use BackPress in your project, and has the beginnings of a collection of documentation covering the main parts of the code library.

I’m personally really excited about this because I think BackPress has huge potential as a library for other folks and other projects. It allows them to benefit from the lessons learned through years (and thousands of “man-hours” worth of development) on the WordPress and bbPress projects. I’m using it as the core of my HTFS project (not released yet), and I know that some other projects are starting to use it as well. As a developer who has spent a lot of time in “WordPress land”, it makes life so much easier to be able to continue using a lot of the design patterns and techniques that I’ve become accustomed to.

Check it out, and please let me know what else we could get on the site, what needs more documentation etc!

LDAP (very) Basics

Getting started with LDAP can be quite daunting. In the space of a weekend, I took myself on a bit of a crash course to learn about LDAP so that I could work on a project that needed LDAP to access an address book. Here are some of the things I learned along the way:

Read the rest of this post…

New Project: ListML

If you’re anything like me, you write a lot of lists. I use lists for pretty much everything — note taking, planning my day, managing projects, shopping, organization, etc etc etc. I have lists of lists. It’s a bit out of control. Over the years, I’ve coalesced on a simple, basic format, where I write things using indented (tabbed) lists of plain text (in TextMate). I kept finding myself converting some of these lists to HTML, so I’ve written something up that will take a plain text list and reformat it as HTML, given a simple set of formatting rules.

That project is available for download now, under the name ListML. Check it out, I use it all the time, so will probably continue developing it. At the moment it’s just a simple script that you drop into a directory, then drop other TXT files in there to view them as HTML. We’ll see where it ends up. If you’ve got any suggestions or find any bugs, feel free to post them as a comment here and I’ll fix things up. I already have some ideas on new features:

  • Ability to load external files (from URL)
  • List files in the current directory if none specified
  • Cut out the parsing engine properly to make it more portable
  • Make the HTML view (optionally) into a lightweight editor as well
  • Quick UI for grabbing the HTML snippet of just the list (sans CSS/extras)

Slinky, a PHP class for URL shortening/lengthening

A few weeks ago, I tweeted that I was writing a PHP library for shortening/lengthening URLs using some of the common/popular services. I said it was going to be called Slinky, and that it’d support a bunch of different services. Well, it’s now available for download and I think it’s pretty cool, even if I do say so myself ;)

Please grab a copy, try it out and let me know what you think. It hasn’t actually been used for anything useful yet, so I’m also interested to hear what you’re using it for!

Quick PHP Tip

If you’re coding in PHP and checking variables to see if they have a strlen() == 0, or isset() or a variety of other possibilities, you might consider using empty() instead. It’s quite versatile and is nice because it doesn’t trigger any warnings or notices if you use it on a variable which hasn’t been set yet. Here are some examples to show you what it will match against:

<?php

$zero_string  = '0';
$zero_int     = 0;
$false        = false;
$empty_string = '';
$array        = array();
$obj          = new stdClass();

echo empty( $zero_string ) ? "'0' = empty\n" : '';
echo empty( $zero_int ) ? "0 = empty\n" : '';
echo empty( $false ) ? "false = empty\n" : '';
echo empty( $empty_string ) ? "'' = empty\n" : '';
echo empty( $array ) ? "array() = empty\n" : '';
echo empty( $obj ) ? "stdClass() = empty\n" : '';
echo empty( $foo ) ? "foo is empty (and the variable was never set)\n" : '';

The All-New LiveJournal Importer for WordPress

Over the past few weeks, I have been working on a new importer for people who use LiveJournal, but would like to switch over to WordPress. With LiveJournal laying off a bunch of employees, it seemed like some people might prefer to move to a platform where they had a bit more control over their own content, rather than relying on another company to handle it for them. I decided that my measure of success would be that it needed to be capable of importing Guav’s entire journal — comments and all, without error.

As it turns out, it’s been quite a project. LiveJournal’s API is, shall we say, “challenging” to work with, and the sheer size of Guav’s journal (over 3,700 posts and nearly 200,000 comments) meant that I kept running into time, memory and database limits that would crash the importer. After a lot of back and forth with Guav though, I’m happy to present the new importer (find it under Tools > Import > LiveJournal), sporting the following features:

  • Just enter your LiveJournal username and password and you’re ready to go
  • Via the API, it connects directly to LiveJournal and imports all of your posts,
    • Posts marked as “Friends Only” are assigned a password within WordPress,
    • Posts marked as “Private (you only)” are marked as Private within WordPress, which means that only authors on your new blog can read them,
    • lj-cut tags are converted to the WordPress equivalent, the <! — more — > tag,
    • lj-user tags are converted to normal links, and have class=”lj-user” attached to them to make it easier to style them if you like,
    • Tags are imported properly,
    • If you closed the comments on a post in LiveJournal, then they’ll be closed in WordPress as well,
    • Lots of the “meta” information related to posts is also imported using WordPress’ Custom Fields feature. You could then use these values to reproduce some of LiveJournal’s functionality within your new theme if you like. The fields imported are:
      • If your post contains adult content (lj_adult_content),
      • Your current co-ordinates and location (lj_current_coords and lj_current_location),
      • Your current mood (lj_current_mood),
      • Current music (lj_current_music),
      • Your userpic keyword (lj_picture_keyword)
  • Next up, all of your comments are also imported,
    • Threading is preserved, so replies to other comments show up successfully (provided you enable that feature in WordPress),
    • The “subject” of each comment is included as the first line of the comment itself, because WordPress doesn’t have a comment title/subject value,
    • LiveJournal users get links back to their LiveJournals,
    • Your own comments are linked to your WordPress account, and are linked back to your new WordPress blog,
    • Anonymous users are labeled as “Anonymous”,
    • “Screened” comments on LiveJournal are imported as “Unapproved” within WordPress, so you can decide what to do with them

So there you have it, a brand new, shiny LiveJournal importer. This should be bundled with the 2.8 release of WordPress (it’s available right now on WordPress.com), and will be available for everyone. As I mentioned, it’s been tested with one single, very large blog (and a few smaller test ones), but if you find anything wrong with it, please file a bug on the WordPress Trac!

Huge thanks again to Guav for helping with the testing of this thing (maybe now he can migrate over to WordPress as well)!

FeedGrowler – get Growl notifications from your feeds

On a whim, I whipped up this quick project today. Basically it just gives you a Growl notification when a feed you’re monitoring gets a new post (or technically, when the most recent post in the feed changes content).

Check out FeedGrowler’s project page »

Ruby is the new PHP

Don’t know if this has dawned on anyone else yet…

PHP was the new Perl, written for the web

Ruby (+ Rails) is the new PHP, written for web 2.0

I guess that means I’d better get on the bandwagon and figure it out!