Archive for the ‘Uncategorized’ Category
Quick and dirty christmas list – a Joomla! Recipe
Right around Thanksgiving, my mother will usually email asking for a list of Christmas gifts. This previously presented a messy problem: we would have to sit down, come up with a list, send it to Mom, then she would have to circulate the list and coordinate who was buying what. Instead of doing that this year, I told Mom to wait a week. Ten days later, I managed to scrounge up enough time to dash off a Joomla!-based system to handle all of this. Joomla! took care of the basic interface and user management tasks, leaving me to finish off the rest as an MVC component.
First, I installed a standard copy of Joomla! 1.5 with no sample content. I adjusted the parameters of the default rhuk_milkyway template so that it would have green links and headers (Color Variation) with a solid red background (Background Variation). I could have ditched the Joomla! logo in the header, but was lazy and just left it in.
Next, I added an instance of the Login module and unpublished the main menu. Although the main menu was unpublished, I left it in the system as a holding place for the default menu item. I also set Joomla! to disallow account self-registration: only seven specific people would ever be logging into this site and I didn’t want any passers-by creating accounts. I created an additional menu and set the access level to registered users only; no need to show the world any piece of our application. This menu included a link to the User Form Layout which I titled “Change my password” (even though you can do more than change your password from this form).
Finally, I cobbled together a custom MVC component to handle the lists. Before writing a lot of code, I created a menu link pointing to the component on the main menu, then adjusted the login module to redirect to this menu item after authenticating. This makes the login process seamless: you don’t see any parts of or links to the list component before you are logged in. Your only options are to either log in, retrieve your username, or retrieve your password. Once you’ve successfully logged in, you’re immediately taken to the component.
After configuring the login module, I continued to build the component. Before calling the controller, I used this code to make sure the user is logged in before continuing:
if (!$user->id) {
global $mainframe;
$mainframe->redirect('index.php',
'No peeking! You have to log in first.');
}
Next, I have controller sets the default view to ‘mylist’. This view lists all of your requested items and provides a form for entering more. To set the default view, I overrode the display() function for the controller like this:
function display()
{
$view = JRequest::getVar('view', '');
if ($view == '') {
JRequest::setVar('view', 'mylist');
}
parent::display();
}
This way, if ‘task’ in the request is empty, the component automatically calls display(), finds that ‘view’ is also empty, then sets it to ‘mylist’. Now, while the ‘mylist’ view lists all of our requests, it does not display the purchase status of those gifts. In addition to the ‘mylist’ view, there is an ‘item’ view providing a form where you can edit gifts you’ve already added. Links to the ‘item’ view are provided from the ‘mylist’ view.
In contrast to ‘mylist’, the ‘otherlists’ view displays all of the gift requests from all the other users, while listing gift purchases. It also has links you can click to mark yourself as having bought a specific gift. This way, people know not to buy something you’ve already purchasing. The code also makes it possible to mark multiple people as chipping in on a gift.
While the ‘item’ view simply loads a single row from the database, the ‘mylist’ and ‘otherlist’ views have their own data models. The data model for ‘mylist’ is very simple and has only one function, but the ‘otherlists’ model has functions for getting a list of all users, getting the buyers for each item, and getting all of the items listed by everyone else.
While there is more code I would like to add (such as gift suggestions for people who are slow about building their wishlist), following the MVC pattern now will make it easy to do that later. In the meantime, here’s a link to the code as it stands today (NOTE: this is not an installable Joomla! package. Drop com_christmaslist into the frontend components folder, run the .sql, then make an entry into jos_components if you want).
Using MooTools and jQuery Together in Joomla!
Framework conflicts are a common problem people run into when using jQuery. While jQuery provides some tricks you can use to get around this, you may still run into issues when Joomla! generates MooTools effects. While writing the second edition of Learning Joomla! Extension Development, I decided to do a chapter on JavaScript and look into this problem a little bit more closely. It turns out you have to make sure MooTools loads before jQuery, then use one of the tricks detailed on jquery.com.
Fortunately, this can be done in Joomla! consistenly, so I documented it. Packt decided to release the entire JavaScript chapter as the sample PDF for my book, so you can read everything you need to know about implementing this technique for free!
Textmate Bundle for Joomla!
I’ve been an avid Textmate user for a while now. It’s a text editor for Mac OS X that allows you to automate a lot of common text tasks. The editor has the concept of bundles, where you can group similar code snippets and macros together; selectively using each depending on the type of file you’re editing. Textmate also allows you to edit the core bundles that ship, as well as create custom bundles for your own projects.
To help with my Joomla! programming, I’ve developed a bundle of snippets for commonly used code. You can download it here. Unzip the package, then double click on the bundle to install it in Textmate. I’ve been slowly collecting snippets for a while now, so there’s some Joomla! 1.0 snippets as well as Joomla! 1.5, but it’s mostly 1.5 now. I’ll probably clean this up someday and add more functionality, but for now, here it is. No warranties, all the usual legal stuff, etc… enjoy!
Longest line I’ve ever been in for voting
Have a look. Fortunately, I was able to finish voting within an hour. And I used a paper ballot, thank you very much.
Bigger, better, and updated – Learning Joomla! 1.5 Extension Development
It’s official: preorders are being taken for the second edition of Learning Joomla! 1.5 Extension Development! Thanks goes out to everyone who bought the first edition and offered their praise as well as critiques. I’ve incorporated a lot of the suggestions and the book is better for it. Here are some of the additions to the new book:
- Fuller coverage of the model-view-controller design pattern. This is now introduced much earlier in the book and is used much more thoroughly.
- Use of the MooTools JavaScript framework.
- More of the extras: elements generated by JHTML, pagination, and internationalization among other features.
Keep up with official Joomla! security updates
While helping people get the Podcast Suite up and running, I’m noticing that a lot of people are running vulnerable, outdated copies of Joomla! 1.5.x. Keeping your Joomla! site running with the latest patches is a MUST. The Joomla! core team, working groups, security team, and bug squad all jump in and help write a patch whenver a vulnerability is discovered. However, these patches do no good if they are not applied to your site.
So how do you stay on top of Joomla! security issues and releases? The download page for Joomla! now has a handy form where you can sign up for email alerts. If you prefer RSS, use this feed link. (BTW: the current version as of this writing is 1.5.7, with a 1.5.8 maintenance release around the corner.)
PHP Appalachia Wrap-up
Earlier this week, I attended PHP Appalachia in Pigeon Forge, TN. We rented this ginormous cabin (scroll all the way down) just to hang out and talk about PHP. I finally met several people who I’ve missed in my failure to show up for Zendcon all these years.
As far as presentations went, Ben Ramsey started with his “frankenstein talk” on REST, focusing on how REST is an architecture for the web itself. Brian DeShong showed us how to rickroll people on any phone using WURFL, PHP, and ffmpeg. Matthew Turland talked about the PHP-based IRC bot named Phergie and corrected me on the pronounciation of my last name (he’s correct, it’s Luh-blon instead of Luh-blon-k).
Brandon Savage led a roundtable discussion (although we were actually seated in the living room on couches) about creating a PHP clone of Trac. Brian Moon talked about the process he uses to load all of the world’s products into the dealnews database. Rob Peck talked about using PHP with Asterisk through the Asterisk Gateway Interface. Finally, Paul Reinheimer gave a presentation on Magento and how to let your open-source contributors know they’re appreciated.
Aside from the talks, we soaked in a hot tub, watched movies, played pool, quizzed each other on PHP trivia, and ate some delicious chicken and sausage gumbo made by Matthew’s wife Whitney. The only thing we didn’t do was spend hours on Internet thanks to satellite connectivity. We talked to each other instead
Listen to The Joomla Podcast
Mike Brogan has started a podcast about Joomla! simply called The Joomla Podcast. He’s been regularly releasing episodes over the past couple of months and is now up to #6. The show is a good balance between project news, component reviews, tips, and Mike’s own two cents. Anyone who’s a fan of Joomla will get something out of the podcast.
I’m getting caught up on it as I write this blog post
.
Joomla! vs. Drupal vs. WordPress
Lynda.com now has videos available on the most popular open-source programs for publishing content. There’s the one on Joomla! I recorded, one on WordPress by Maria Langer, and now one on Drupal by Tom Geller. So which one is right for your next site? Sign up for an Online Training Library account today and find out!
For $25, you get a month-long subscription where you can watch all of our videos in their entirety and as many times as you wish. You will also have access to the rest of the video library which covers topics like Flash, HTML, Photoshop, CS3, and Search Engine Optimization. Use Lynda.com to learn everything you need to know for launching your next site!
UPDATE: As Maria pointed out in the comments, you can watch the first few videos of each Lynda.com title for free. This will give you a general feel for each system.
