Showing posts with label technology. Show all posts
Showing posts with label technology. Show all posts

Saturday, 20 June 2009

Making Drupal Your Bitch

I suspect no-one will read this post entirely unless they get here from some random Google search looking for help with Drupal. A shame, to be sure, but not unlike the thousands of lines of beautiful code poetry I've written no one will look at. Probably not unlike the rest of these post either. Still, I'mma gonna write it and call it the first page of my Drupal tutorials.

Now it's no secret that I'm building a CMS from scratch. Heck, some of you are even using the first production version of it! Well, clients have demanded feature sets faster than I can build them in the normal course of development, so in an effort to work smarter, not harder, for those few clients who wanted the moon for cheese, I turned to an off-the-shelf CMS, Drupal. IMHO, it's the best thing out there, but it's still incredibly bloated and needlessly complicated. It pains me to use Drupal for those reasons, but that said, it's still the best thing out there - for now.

So once you get Drupal installed you'll need to enable the modules you want. Don't bother configuring your site yet; we're not done installing. Most of the core modules are useful, but only enable the ones you are actually using - the more you have, the slower your site is. With today's technology even. Warned you the code was bloated and inefficient!

Now you'll need to install a whole host of 3rd party add-on modules (and a template if you're not going to build one). Right, there's a lot that Drupal needs it don't come with. Everyone has their own list of must-have modules. My essential list (based on extensive meddling) looks like:
  • Administration menu 6.x-1.4
    You want this dropdown menu; should be core.
  • Image 6.x-1.0-alpha4
    Can't upload or otherwise use images without this.
  • ImageAPI 6.x-1.6 ImageAPI supporting multiple toolkits.
    Ditto
  • FCKeditor 6.x-1.3
    A WYSIWYG editor instead of plain text fields.
  • Image Browser 6.x-1.0-beta1
    An image browser/manager for use with FCK
  • Meta tags 6.x-1.0
    Why aren't keywords core?
  • Views 6.x-2.6
    Haven't used this powerful module yet, but modules above require it.
Getting all these modules installed is not that difficult, but FCK and the image browser are a bit tricky. Go to their homepages and read carefully. FCK requires two downloads/installs! Right, the one you get from Drupal.org is only 1/2 of it.

Oh yeah, if you're going to have clients (and not just you using the system) you'll definitely want to configure Drupal to serve multiple sites from one install directory. Read the manual carefully; it's not hard. In fact, creating a new site is one of the nicest features about Drupal, even though it still requires a command-line interface and a few Unix commands. I felt a wave of smugness pass over me since my system is all web-based. I let it go, Smug is one of the leading sources of air pollution.

Time to setup your CSS. To do this, you need to create what Drupal calls a theme. You'll find no end of schizophrenic (manual) pages about how best to do this. Take my advice. Use the blank slate template I wrote. It's simplified beyond Stark. However, if you're HTML-based instead of PHP-based you can use the Stark theme; it's just got a bit more divs than it ought to have, but it's no big deal; just copy it, and then edit as you wish.

Okay, so now you got a CMS enabled with (most of) the features you want/need. Now what?

Well one would hope that the entire CMS is customisable via an online interface to control not only what modules are active, but what data each module outputs along with the accompanying CSS to handle the layout. Unfortunately, this process only works for the simplest of modules, and it's never a customizable as you'll want. Breadcrumbs are a great example. You can't just click a checkbox and tell Drupal not to print the darn things. Instead, you have to edit code. Don't even get me started on the User Login box.

But since we don't want to edit the actual Drupal source (cause we'll lose it on system updates/upgrades) we instead have to copy the php file (called a template) that Drupal uses to figure out what to display. Hmm... we might have to redo changes anyway when the new templates change from the old. You'll find in my template a file called "page.tpl.php" which gets called on every page draw. If you were to make it blank, all your pages would be blank. Seems easy peasy, but finding the module's source code can be a pain until you get intimate with Drupal.

Now the templating scheme is fairly clever - you can be as specific or as general as you want, and Drupal follows rules for which template files it uses based on the content. It would be nice if each module had a template, but alas, that would make too much sense (and too much facism).

To override some types of Drupal output, you need to figure out which PHP funciton in the Drupal source code is outputting the content, and then override that function and figure out where to put it. Not an easy task at first, especially since all you want to do at this point is to build your website. This was supposed to be easy, right?

But you're a superstar, you've gotten this far, the rest is a cakewalk right? We just edit the template to layout our <divs> and then edit our custom CSS to take care of the display. In theory. You're going to need to be quite the expert if you expect to do any serious CSS. Why? Cause Drupal litters the CSS heirarchy with all kinds of unnecessary definitions that are hidden, until you're wondering why for example, your <li> elements, which you've explicitly and clearly marked up in the CSS to not have bullets, shows bullets anyway (but only on non-IE browsers). Oh yeah, don't forget to override the background with "background:transparent" or you're going to get weird images appearing in your lists too. See what I mean? Oh yeah, be sure to have a "border: 0px;" command for any tables you want unless you like having borders. Who does that? Ya gotta be familiar with just about all of CSS2 and even then, CSS that works in isolation will often fail when inside Drupal and you'll have to figure out exactly what (and where) Drupal is mucking up the CSS with non-standard or extra inherited definitions (which IE doesn't seem to respect).

Are we having fun yet?

Well don't forget, Drupal 5 did all of this differently from Drupal 6, as no doubt Drupal 7 does too, so just because you become an expert, don't worry about the joy of learning... you'll have to do all this over again when/if you upgrade/downgrade! Whoopee!!!

PS - about the cover image: if that kind of thing excites you, try starting here.

Wednesday, 17 June 2009

Slime, Stunts, and Source (code)

Felt a little down today. Been doing an awful lot of work for little or no reward and though I try not to feel the stress of rent and phone payments, still, it is there. I did get $100 for a day's work, so Burger king wages for PhD work. Sigh...

I met with a guy who wanted a photo in response to my ad seeking a roommate. He wasn't too slimy, but my presence obviously made him and his friend uncomfortable. I didn't mind. :) We had a business meeting regarding poker. When I had spoken to him earlier, I mentioned the reason I was in Vegas (and why I wanted to stay close to the Strip - he wants a house in BFE). He mentioned that we would consider staking me for a world series event. Turns out, all he really wanted was an excuse to see me again. He wasn't serious about the offer, but figured I could be bought. I declined.

Oh, in good news, I did meet some teenagers yesterday. They were doing bike tricks out in the parking lot as slimy brought me home (car still in shop) and I was a receptive audience, so they did tricks for me! Later, I saw the same one (who has both ears pierced and has pretty big black spacers in his ears) sitting in a car with a girl and they were jamming out to some heavy metal sounding music. I zipped around the corner on rollerblades and when he saw me, his eyes lit up and he smiled wide at me, much to the chagrin of the girl with him in the car. Teehee. Once I got to the top of the stairs, where they could see me through the trees, they gave a glance upwards seemingly as if they expected me to express disapproval at the loud music. I held my middle and ring fingers pressed down with my thumb and gave them an encouraging few head bangs. They loved it! Tee hee. If they are out again, I might go out and do rollerblade tricks with them (yes, I'll get some protective gear! ... eventually)

Other than that, there has been little contact with humans, but that's fine, I'm preoccupied with (quickly) becoming an expert in Drupal. Yeehaw!

Monday, 15 June 2009

Muscle Memory

Unix aficionados, especially back in the day, fell into one of two camps, depending on which text editor they preferred: vi or emacs. Emacs was fancier in that it was programmable and customizable, while vi was simply a very powerful, but tersely obfuscated (or so I thought at the time), editor. I was a vi fan; never used emacs.

As I'm installing drupal, I find myself back in the Unix command line and I'm amazed at how quickly the fingers remember what's what.

I start the editor and view a large document file. Instantly, my fingers go to CTRL-d for page down (CTRL-U is page up). The fingers also remember h, j, k, and l, the commands to move the cursor left, up, down, and right respectively.

O inserts a line under the current line, $ moves me to the end of the current line, a appends at the current spot, and A appends at the end of the current line.

It's both bizarre and a testament to how efficiently vi's interface was that one can just re-remember these long forgotten commands. I was surprised to find it was just like riding a bike. VI was one of the hardest programs I learned how to use because it required you to become an expert user - or keep with you a list of VI commands like the one below.

By the way, if you're wondering the significance of the dog cartoon... that cartoon (from the New Yorker) was hanging on the door of the Unix system administrator's office during my tenure as an undergraduate at Ball State. I didn't search for it, it just came up, so there must be some cosmic relationship between it and VI.