Working with Content plugins in Joomla 1.5

Earlier this week, I made my debut on HowToJoomla.net with an article on How to Fix Joomla Content Plugins. If you’ve used Joomla since the 1.0 days, you may recall that content plugins acted on both articles and Custom HTML modules. In 1.5, this behavior changed so that Content plugins only act on articles from the Article Manager. Fortunately, there are several options for regaining and controlling this functionality, which I outline in the post. Head over and let me know what you think!

Joomla 1.5 Development Cookbook

When I originally received my copy of the Joomla! 1.5 Development Cookbook, I was in the middle of a large client project. The book sat over on my shelf for a few days waiting to be read. While working on my code, I came to a point where I wanted to add some custom markup to the portion of the HTML document. Although I usually whip out my Joomla Textmate bundle to pull up the right snippet, this wasn’t something I already had preprogrammed and ready to go.

If I learned something, you’ll learn something

I was about to do a Google search, but suddenly remembered that James’ book was in arm’s reach and might have the answer. After turning to the index and finding the topic, I quickly located the exact code I needed to move on. Despite having written a book on Joomla myself, this one came to my rescue at just the right time!

While it took me a while to read all 130 recipes (including time on airplanes, buses, and sitting in my living room), the practical tips and methods were worth it. James covers a wide breadth of Joomla programming topics, matched only by his Joomla Framework reference. Most passages are 2-3 pages long and include relevant information that’s quickly applicable to any Joomla project you’re working on.

Essential information

Two chapters in this book really make it a must-purchase for any Joomla developer. The Multilingual Recipes chapter gives more in-depth information on internationalization and character encodings than any other Joomla reference I’ve seen. Even if you’re only creating a website in one language, it’s imperative that you understand how character encodings work. Current versions of PHP have some shortcomings with handling UTF-8 strings, but Joomla’s special libraries will help you handle them correctly.

Character encodings aside, Keeping it Extensible and Modular is the most useful chapter in the entire book. This chapter is devoted to helping you work with Joomla’s different extension types and getting around some of the shortcomings in 1.5. For instance, James shows you how to create installable libraries by creating a custom type of plugin.

Also, this chapter has a recipe for using the component installation process to install additional extensions. This method allows you to include your modules and plugins inside of your component package; installing multiple extensions in one click. I plan on using it as soon as I get a chance to work on the Podcast Suite!

While the content in this book is very strong, it does have a couple of drawbacks. While most of the recipes have readily usable code that’s straightforward, a few of them don’t make a strong case for why you would use the described method. For instance, there’s a recipe on creating and raising a custom error level. It goes into how you want to avoid conflicting with Joomla and PHP error codes, but it doesn’t explain why you would want to create a custom error level in the first place. Fortunately, most of the recipes have more context.

I’m willing to read more than two pages… seriously.

The biggest disappointment of this book is in the execution of the cookbook format. Having read other “programming cookbooks” in the past, I know that the goal of these kinds of books is to help you find relevant information on specific topics quickly. However, Packt seems to have decided that providing “quick information” means catering to readers with severe cases of attention deficit disorder.

If you try to read entire chapters of this book at a time, you’ll notice that some recipes are almost identical. In Chapter 7, there are individual recipes on setting the HTML document generator, description, and metadata. These add up to less than three pages, but all include the same introduction at the beginning of each. Additionally, all three of these include “See also” references to each other. These would have worked much better as a combined recipe, including a reasonable scenario where you would want to set these things. In its current form, almost half of your reading consists of headers and duplicated information.

I get the feeling that Packt was trying to break all of the topics up into the tiniest pieces possible. This way, they’re able to slap “130 simple but incredibly useful recipes” on the cover and advertise a page count of over 300. This is really taking a short view of things, as James did a wonderful job with the topics he covered. While some marketer is probably pushing for a specific length, I’ve found that the length of a book is not proportional to its usefulness. For instance, I learned far more in 145 pages of Javascript: The Good Parts than I did in nearly 800 pages of Programming Ruby.

Hidden Joomla treasures

Despite the sometimes choppy format, the Joomla! 1.5 Development Cookbook organizes a lot of how-tos missing from Joomla’s online documentation. Anyone coding anything more than the simplest module can benefit from the recipes in this book. James demonstrates expert programming knowledge and delivers it in a very accessible format. The time you’ll save by having this information at hand will offset the cost of purchasing it within the first week. If you’re writing code for Joomla, you need this book.

UPDATE: you can also read a PDF sample of Chapter 2 from Packt’s website.

SEO is a tiebreaker, nothing more

I’ve always been a skeptic of SEO “best practices.” A website that reminds me of this is titled “The Japan FAQ: know before you go.” Several years ago, I was marginally interested in what it would take to teach English in Japan. So I found this extensive website and read up. It’s one of those sites that someone started writing and just kept going at, with minimal navigation and loooooong pages. You get lost in the content, but you keep reading because it’s is full of anecdotes.

For some reason, I wanted to look up this page again, so I Googled “japan faq”. Lo and behold, it was the top hit. A peek at the source reveals this site follows almost none of the oft-quoted SEO practices necessary to get to the top. Some of the pages have two <h1> tags, some have none. The HTML doesn’t validate. There are multiple unclosed <body> tags. Some of the tags are capitalized, some pages don’t have any <meta> tags. There are <font> tags all over the place. It’s 1997-era tag soup at its finest.

This made me wonder about the quality of top-ranked pages for other search terms. So I began typing in terms at random:

  • japan
  • breast cancer
  • garlic
  • beethoven’s 5th
  • war of 1812
  • supernova
  • heroes
  • michael jordan
  • kung pao chicken
  • gardening

For each of these terms, I ran the top hit that wasn’t a Wikipedia page* through the W3C validator. Each and every page failed HTML validation. A few had clean CSS/tableless layouts, but most didn’t. Several pages had mysterious whitespace at the top. Many had inline styles and JavaScript. The top hit for Japan is a Flash animation with precious little content surrounding it. Several were missing DOCTYPE tags. When <h1>’s were present, they were cluttered with tags inside of them. Amongst these sites, practically every SEO “rule” was broken.

Yet they all rank very well in Google. This leads me to believe that SEO is nothing more than a tie-breaker in edge cases. It could be that your site is simply swimming amongst other edge case websites. However, sometimes it seems that for all of the effort people put into SEO, they would yield comparable results by getting people to talk about their website. Both interesting content and good old-fashioned interpersonal networking can help with that.

Valid markup can’t hurt though.

(* I’m excluding Wikipedia from the top pages as it’s the exception that proves my point: wikipedia.org’s overall pagerank is absurdly high because Wikipedia is ridiculously popular. The markup Wikipedia uses is largely irrelevant.)

Book Review: Joomla 1.5 Template Design

Packt Publishing recently sent me a review copy of Joomla 1.5 Template Design by Tessa Blakeley Silver. Since I read most of it away from my computer, I wasn’t able to work through the examples. While I can’t speak to how well the code examples matched the actual process of building the template, I did enjoy reading the book. Coming in at 259 pages before the index, this book has enough content to cover everything you need to know while not wearing out its welcome.

The strongest part shines in Chapter 2, where Tessa introduces her “Rapid Design Comping” technique. This markup-centric approach helps you get your typography and HTML right first, then goes back and creates accompanying graphics. By getting your basic HTML and CSS out of the way up front, you don’t run into issues where you’ve designed a layout in PhotoShop that doesn’t translate to the web. Her coverage of this method is easily worth the price of the whole book.

Another plus is that Tessa incorporates HTML and CSS validation as a part of your template design workflow. Although having valid markup does not guarantee that your design will display properly in all browsers, it does help you avoid many such inconsistencies from the outset. She also covers common browser hacks (mostly to accommodate Internet Explorer 6) and how to use them as sparingly as possible. Finally, she also dives into avoiding quirks mode rendering and how to handle inconsistent renderings of the box model.

Coverage of Joomla-specific code and techniques is extensive, including custom module chrome and template parameters. She includes a complete reference for all <jdoc:include /> tags, as well as CSS selectors output by the Joomla core. Joomla template-specific PHP is also explained, but without going too deep into code that might confuse people without a programming background.

Despite a strong foundation in the fundamentals of Joomla templating and HTML/CSS, the book does have faults. There are some places where Tessa states something pensively (for instance, date formatting in XML manifests on page 138) which makes you wonder whether or not she’s confident about what she’s describing. Conversely, her description of the Model-View-Controller design pattern is very confidently stated, but slightly inaccurate. Fortunately, she describes the relevant details of View overrides correctly. That said, a more consistent voice would make the book easier to read.

Less forgivable is the introduction of the jQuery JavaScript library in Chapter 8. While she does a good job of showing jQuery’s power and simplicity, not once does she mention that Joomla already includes MooTools. Worse, readers are not alerted to the fact that jQuery will clash with MooTools if you don’t add the proper workarounds. While I love jQuery as much as Tessa does (and perhaps more), I was quite shocked by the omission. It’s quite possible that Tessa hasn’t run into this conflict, but it does happen frequently.

Despite a few missteps, this book is a solid introduction to the ins and outs of building a template in Joomla. All of the standard syntax is covered, along with a practical overview of how to structure your HTML and CSS for optimal browser compatibility. Advanced topics are also tackled head on, making this book the most complete reference for building Joomla templates that I know of. If you need to build a template or are curious about the process, this book should definitely be on your shelf.

You can read a sample of the book from Packt’s website [PDF], or purchase the book there as well.

Attention Podcast Suite Lovers

Throughout the life of the Podcast Suite, many of you have asked if you could make donations for the work I’ve put into it. Every time, I’ve redirected your kindness by suggesting a donation towards the Joomla project instead. I do this as the effort I put into the Suite is small when compared to the enormous effort put into Joomla itself. Without Joomla, the Podcast Suite would not exist.

However, if you have used the Podcast Suite and would still like to donate money, there is a current opportunity for you to make a tax-deductible donation that would help me greatly. At the last week of October, I will be flying with 12 other people from my church to Iloilo City, Philippines; we will be spending two weeks there to run a summer camp for street children. Each of us need to raise $2,300 for our trip expenses. You can read more about it in this (PDF) letter and make a donation here.

Any funds raised in excess of my $2,300 goal will go towards the goals of my other team members. Although I would be honored to receive money towards this goal from Suite users, do not feel any obligation to contribute towards this trip. I’m always thrilled to hear about the Suite being used. I want all Joomla users to be able to publish their own podcasts without knowing programming or RSS. When you publish a podcast with the Suite, you help me achieve that goal!

The way NOT to do JavaScript in Joomla!

While doing a little Sunday afternoon browsing of Twitter, I noticed Amy Stephen warning about a bad technique for using Joomla! with AJAX-style requests. I followed the link (WARNING: don’t use this code!) and found security vulnerabilities right away. Since the blog in question doesn’t support comments, I’m forced to respond here.

First, as Amy pointed out, the technique creates another entry point into Joomla. While this can be used effectively if you know what you’re doing, it’s totally unnecessary for a casual application of asynchronous JavaScript. Next, class, who can tell me what’s wrong with this piece of code?

cExt( $_POST['func'] );

That’s right, we’re passing data straight from our HTTP request (which can come from anywhere in the WORLD) into our application’s logic. Once we get into the the cExt function, the variable is used to execute code with no filtering whatsoever:

function cExt($func = ”){
$cext = null;
if(!empty($GLOBALS['cExt']))
$cext = $GLOBALS['cExt'];
else{
$GLOBALS['cExt'] = new plgCommunityExt();
$cext = $GLOBALS['cExt'];
}
if(empty($func))
return $cext;
else{
if($GLOBALS['ajax'] == true)
$cext->$func();
else
return $cext->$func();
}
}
function cExt($func = ''){

    $cext = null;

    if(!empty($GLOBALS['cExt']))

        $cext = $GLOBALS['cExt'];

    else{

        $GLOBALS['cExt'] = new plgCommunityExt();

        $cext = $GLOBALS['cExt'];

    }

    if(empty($func))

        return $cext;

    else{

        if($GLOBALS['ajax'] == true)

            $cext->$func();

        else

            return $cext->$func();

    }

}

Please, regardless of whether or not you use Joomla, don’t do this! It is a totally insecure way of writing code. Instead, if you are using Joomla, you can at least filter this variable using the following code:

$func = JRequest::getCmd('func', '');

This code will filter the func variable from the request and make sure it only includes numbers, letters, or underscores. Additionally, you should filter $func to make sure a corresponding public function in the plgCommunityExt class exists before attempting to use it to actually execute that function.

As a side note, $GLOBALS is being used an awful lot here. While this isn’t a security risk in and of itself, it is a bad practice that can lead to insecure coding. If the register_globals setting in PHP (going away in PHP 6) is turned on, this becomes a huge security risk as anyone in the world can set the value of cExt to anything.

The post ends with this quick jibe:

That was pretty easy wasn’t it, in order to get quick results you just have to find these shortcuts which will spare you the time and pain of having to read some Joomla-, or pick your favorite, CMS book.

I’d argue that the author of this blog post would not only benefit from reading a book about CMS development, but one on basic PHP security. The technique he describes is insecure in any PHP-based framework or CMS.

Fortunately, you don’t even have to run to the bookstore to find examples of the correct way of doing these things. Louis Landry has a quick example of how to return JSON formatted data simply and securely on this thread, without having to create a special component view. If you do want to use a view, this blog post will show you how to do it.

Finally, if you do want to learn how to add AJAX-style requests to Joomla (without necessarily using JSON), I’ll shamelessly plug my own book. But you don’t even have to buy it, because the sample chapter is indeed the one on JavaScript and Joomla (start on page 168 if you already know Joomla! MVC).

Basic HTML/CSS Invoices

Yesterday, one of my clients requested an invoice for my services. This is not an unreasonable request by any means, but it is oddly one that doesn’t happen very often. I initially fired up OpenOffice.org and started writing one, but had difficulty getting the layout I wanted. After OpenOffice crashed (I had an older version), I posted a message to Twitter. Suddenly I had friends suggesting FreshBooks, Zoho Invoice, Billable, and some homebrew solution. Many of these were good suggestions, but I was really just looking for a nice clean invoice template; I already have my own system for tracking hours and payments.

Unfortunately, I have a very bad case of NIH and decided to roll my own using HTML and CSS. Fortunately, it only actually took an hour and I’m quite pleased with the results. So pleased, that I’m now sharing the results for all of the Internet to plunder. Have a look. It is released under a Creative Commons Attribution-Share Alike 3.0 license, so feel free to modify it and use it for invoicing your clients. If you redistribute this in HTML form, please maintain the copyright notice in the comments. If the final medium is a PDF export for printing or emailing to a client, you do not have to maintain the copyright notice.

I created a PDF of this using my Mac’s “Save as PDF” function under “Print…” on Firefox 3.5 and it worked perfectly. Safari wanted to print headers and footers with the source URL and didn’t pick up my backgrounds. I have not tested this in Internet Explorer.

Enjoy!

Creative Commons License
Basic HTML/CSS Invoice by Joseph LeBlanc is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

Podcast Suite 1.5 Stable Released

I released a stable copy of Podcast Suite 1.5 today, go get it. On the forums, we managed to find bugs regarding the MIME type being set in the HTTP headers. We also fixed a bug where languages other than English would not get their code in the RSS feed. A few other fixes and enhancements made it in. Thanks goes out to everyone who’s reported bugs on the forum and even offered solutions!

Spring ‘09 Conference Roundup

It seems as though the tech conference season starts off every year with SXSW in Austin, comes to a peak in May, then takes a vacation until September. So far, this year has been no different. I recently had the opportunity to attend three conferences within four weeks of each other. A small taste of each follows…

JSConf

Back in February, I began seeing tweets for JSConf on April 24th-25th: the first conference for JavaScript developers. I recently began digging into JavaScript for more than simple effects in jQuery so this sounded interesting. The venue was a mere two metro stops away from my apartment, so I knew I would be kicking myself if I didn’t go.

JSConf absolutely blew me away. The sessions were not simple “here’s how to use jQuery for form validation in your next project” talks. These were the first presentations I saw of JavaScript being used for backend programming as well as frontend. There were speakers representing Objective-J/Cappuccino, Dojo, jQuery, YUI, CouchDB, Titanium, and many other projects. This was also the first I had seen a formal presentation on BOSH and XMPP.

Although there were the presentations about using JavaScript in the backend, the current mainstream use is in the front. Consequently, most of the attendees had expertise in languages other than JavaScript. JSConf managed to get Ruby, PHP, Python, .NET, and other developers in the same room. This really made the conference for me: we were forced to talk about our tools without hiding behind fanboyism.

Another highlight of JSConf was running into Chad Auld and Ozgur Cem Sen from the MiaCMS project. MiaCMS is a fork of the Mambo codebase that has some promising features developing. The JavaScript for the entire codebase has been rewritten in YUI. MiaCMS also sports a REST-style interface you can use to do things like update your site from an iPhone.

Aside from the incredible technical content, the accomodations and after parties were fantastic. Chris and Laura poured a lot of effort into putting this and thought of all the details. They made sure that outlets and wifi were plentiful. The venue they picked was just the right size for shuffling between sessions, uncon talks, hallway tracks, and break room hacking. They even organized a “significant other” track where spouses and children were able to tour DC and Old Town together.

There may be some who would say that this was great for a first year conference; I thought it was amazing for a second or third year conference. I know first hand how difficult it can be to pull off a tech conference, but Chris and Larua passed with flying colors. The sponsors were also incredibly generous and helped the event shine. Looking forward to JSConf 2010!

WordCamp Mid-Atlantic

While people may know me as “the Joomla! guy” in the DC tech community, I’m currently happily using WordPress to power this blog. WordPress is the best tool for doing a stand-alone blog, which is what Design vs. Develop has become. So I felt this was as good an excuse as any to show up for WordCamp Mid-Atlantic on May 18th. (On the other hand, Keith has never used WordPress and simply attended to steal ideas.)

WordCamp Mid-Atlantic (with the rather long Twitter hashtag #wordcampmidatl) was a nice mix between sessions about writing, marketing, and coding. A couple of big announcements from SixApart and the WordPress core team hit that day (TypePad Connect and WP 2.8 beta respectively). The venue was accessible and well-suited for formal talks as well as hallway tracks.

I applaud Aaron’s decision to move the event from DC to Baltimore and refocusing it as a regional conference instead of a city-centric event. DC’s tech community is now much more firmly established than 3-4 years ago. While it would have personally been more convenient to have something located in DC, we’re definitely at a point where we need to connect talent regionally as well as locally.

While the vast majority of the people attending were WordPress users, many were also proficient in Drupal, Joomla!, and other PHP-based systems. The recurring conversation seemed to be that we like using WordPress for straight-up blogs and simple sites, then reach for something else when we want something more involved. Although WordPress is billing itself as a publishing platform as well as a blog, I think we’ll continue to see people using different platforms for different sites. It’s gotten to the point where most are using WordPress for very simple sites (just pages with content), but using something else when integrated shopping carts and forums are wanted.

php|tek

Finally, I flew out to Chicago for php|tek ‘09. The guys over at MTA are seasoned conference organizers, with this event being no exception. There was a wide variety of talks: from using XMLReader, to alternative databases, Zend Framework hacks, and even an unconference session on PHP-GTK. As many have commented, php|tek is a nice blend between the PHP developer community and business community.

We had a hackathon where people were writing PHP tests for TestFest, but somehow I was convinced to write patches for Phergie instead. Ok, so I was sitting at the table and was curious more than anything. Phergie is an IRC bot maintained by Matthew Turland that hangs around #phpc on Freenode. It’s quite a non-traditional use of PHP: you have a long-running process that essentially sits in one big loop. It was nice to sit down and write some code purely for fun :)

Aside from the hackathon, you can read about the events and what I thought of them on joind.in. I didn’t get around to rating all of the sessions I went to, but most of the sessions seem to have been ranked by at least one person.

Unfortunately, the wifi was a bit of a wash. I ended up paying for the hotel’s package the first day as I had some side work that needed to go out ASAP. The other days I was usually able to connect, but had difficulty during the hackathon and in the back rooms. However, I think most of the issue with wifi at conferences is the sheer number of heavy Internet users all hitting the same access points at once. As I’ve been telling everyone I meet, Apple should pioneer “conference mode” where you tell your laptop to stop doing backups, software updates, and any other non-crucial network activities.

The biggest announcement at the conference was that php|works, usually held in the fall, will be revamped as CodeWorks 2009 and held in 7 cities (not all at the same time!). It will be an affordable, two-day conference held on a two-week, cross-country tour. I’m planning on going to the one here in the DC area.

In addition to MTA’s CodeWorks, StackOverflow DevDay will be held later that month. More tickets have been opened, so it’s not too late to register!

concrete5 – first impressions

I downloaded the concrete5 CMS a couple of weeks ago and intended to write a critique earlier, but am only now getting around to doing so. Since then, this article was released on CMS Wire and Joomla! fans on Twitter began talking.

What’s good

One common pitfall of CMSes is to abstract away the concept of a page. concrete5 avoids this and very much embraces pages. A+ in my book. While it’s true that some layer of abstraction can be helpful in certain cases (usually when you’re building an application inside of your CMS), it adds extra work for most webmasters.

Editing pages is also very straightforward. Once you’re in edit mode, all of the blocks (similar to Joomla! modules) appear with dotted borders. Clicking on one gives you several options for editing the block, including dragging and dropping the block to a new position. Very nicely done.

The features built around content5 are thoughtful. Versioning is built in and outputs diff-style coloring when comparing revisions. There are also extensions to help you embed videos, Google Maps, slide shows, and RSS feeds.

About 70% of the functionality you’ll need on a regular basis is contained in the toolbar that appears as you’re editing individual pages. For the rest, there’s a specific “dashboard” backend where you can go to manage themes and files, get reports, and perform other administrative tasks.

Theming is okay

The theming system is reasonable. Like Joomla!, you can add specific themes to specific pages. Closer to Drupal, your theme can define several different page types, which might eliminate the need for separate themes. However, concrete5 requires theme designers to instantiate objects within their markup, then call member functions of those objects to display output. This bothers me. It seems like static function calls or embedded tokens would handle this more elegantly.

Also, the greensalad example theme uses the “header.php at the top, footer.php at the bottom” style of breaking up the markup—I loathe this. There’s no reason to use this error-prone method for theming: you end up with tags that are opened in one file and closed in another.

What’s annoying

While the simplicity of editing individual pages is definitely something I prefer, concrete5 has sacrificed some features to get there. I was not able to find any kind of feature to create a blog-style index of content made up of blurbs from other pages. Add-ons are scarce: if you’re looking for a forum or shopping cart, you might be in for a wait until they attract more developers to the platform.

I ran into a few speed bumps when installing concrete5 locally. After downloading it and going to the installation screen, there was a checklist of PHP configuration settings necessary to run concrete5 (not unlike Joomla!’s). Most of them were good to go after tweaking folder permissions, but I did not have the GD library setup on my self-compiled version of PHP. I was a little surprised that the system would not let me continue installation. While I’m sure there are features in concrete5 that use server-side image processing, this doesn’t strike me as something so vital as to halt installation. (I was able to successfully install both GD and concrete5 on my spare Ubuntu machine.)

Although the GD dependency was annoying, the halted installation uncovers something even more so. If the installer detects even the slightest issue with your configuration, an advertisement for professional installation is displayed. Quite tacky; they could have at least provided a link to their installation forum.

Which brings us to community. This company oozes a know-it-all attitude. In sharp contrast to the websites of other CMSes, their official About page openly bashes Joomla!, Drupal, and Wordpress; painting all three in rather broad strokes. This is very disappointing, unnecessary, and ultimately counter-productive. I’m all for making bold statements, but they’re driving away the very people who could help their platform grow quickly.

Final word

concrete5 is a very promising CMS that does the basics very well. The interface is picked up quickly and things are easy to find. However, if they’re earnest about building a community around their code, they might want to tone down the self-worship a smidge. And is content management really a human right?