New Year, New Theme

2 January 2012 : code, new year, php, programming, wordpress

Today, I relaunched my blog design. As regular readers of this blog will note, I probably spend more time writing about reprogramming my blog than actually writing it. I’m hoping to change that in 2012 but allow me for a minute to discuss the story behind the latest incarnation of RasheqRahman.com.

The impetus began this past summer when Twitter announced its new CSS framework called Twitter bootstrap. As I read more about the theme and downloaded the v1.0 source code, the simple, clean design tugged at me as if begging me to use it in a project. I had looked for years for a simple theme that was mainly white for the text part but had a fixed top navigation bar that could pull together my different interests (photography, writing, web development) but in a compartmentalized way so that the output of each activity could be cleanly displayed in a format that highlighted its unique characteristics. Bootstrap provides such a lattice upon which build such websites. As always, WordPress is the brains behind this project because, like the dependable friend that it is, I can connect it to my front end HTML and CSS almost immediately and know that the key files will be in the right place and easily customizable.

I vowed for this project to use as few WordPress plugins as possible, relying more on code snippets and design patterns to customize my website so I truly understood what was “under the hood.” As I hope to share in coming posts in the code category, I did this in order to improve my PHP skills and to gain a better understanding of WordPress theming. Having now completed this site and several others this year I am excited to declare that I intend to “hand roll” my own themes from here on out, i.e. using only HTML templates and adding in the WordPress code myself. If you are at the point of having configured a few existing off the shelf WordPress sites yourself and are looking to really grow as a WordPress developer, I highly recommend the “roll your own” approach.

Overall the process took some four months, with a two month long break in the middle and several pauses in the middle while I thought about the design and how I wanted everything to fit together. I decided to launch it today to kick start the New Year knowing full well that both content and design need some continued tweaking.

Look for the aforementioned coding posts in the coming weeks and please feel free to comment below. I look forward to your thoughts and questions.


Ipodder Opml Class

25 May 2005 : code, opml, php, podcast, programming

<?php

/*************************************************************************************
* ipodder.opml.class.php
* ---------
* Author: Rasheq Rahman (rasheq.rahman@gmail.com)
* Copyright: (c) 2005 Rasheq Rahman
* Release Version: 1.0.0
* Date Started: 2005/05/20

* ipodder.opml.class.php is a PHP class to convert an Ipodder (http://www.ipodder.org) OPML file into a simple HTML table that can be inserted into a web page. More complete documentation can be found at http://www.rasheqrahman.com/.
*
* The orginial code for this class was written by Joe Grossberg. See http://www.joegrossberg.com/archives/001966.html for details.
*
*************************************************************************************
*
*
* ipodder.opml.class.php is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This class is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ipodder.opml.class.php; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
************************************************************************************/

class OPMLtoHTML
{
  var $index;
  var $vals;
  var $html = '';
  
  /* Set the color scheme for alternating podcasts and alternating categories
In the ipodder hierarchy, podcasts are organized into categories. A category might have one, two, etc. podcasts. To make the tables easier to read, I have implemented logic that sets different color schemes for alternating categories and alternating podcasts. You can use Hexadecimal colors or CSS color names. A good list is provided by the W3 Consortium at http://www.w3schools.com/css/css_colornames.asp
*/
  
  var $oddcategory_oddpodcast_color = "#D1CEF2"; // ex: category #1, podcast #1
  var $oddcategory_evenpodcast_color = "#E3E1F7"; // ex: category #1, podcast #2
  var $evencategory_oddpodcast_color = "#D8EDAF"; //ex: category #2, podcast #1
  var $evencategory_evenpodcast_color = "#EEF7DD"; //ex: category #2, podcast #2
  


  function OPMLtoHTML ($file)
  {
    $this->parse_opml($file);
    $this->generate_table();
  }

  function parse_opml ($file)
  {
    $fp = fopen($file, 'r');
    if (!$fp) return;
    $xml = fread($fp, filesize($file));
    fclose($fp);

    $parser = xml_parser_create('');
    $status = xml_parse_into_struct($parser, $xml, $this->vals, $this->index);
    xml_parser_free($parser);
    if (!$status) return;

    return true;
  }

  function generate_table () // creates table from parsed OPML file
  {
    $expand = $this->vals[$this->index['EXPANSIONSTATE'][0]]['value'];
    $expand = array_flip(preg_split('/,\s*/', $expand));
    
    $category_count = 1; // counter to track category # for color formatting
    
    $count = 0; // Not sure what this is used for but it was in joe's original script

    foreach ($this->index['OUTLINE'] as $i)
    {
      $type = $this->vals[$i]['type'];
      if ($type == 'cdata' or $i < $this->index['BODY'][0])
        continue; //skips over header informaition in OMPL file
        
       // code below is optional. You can use it create "indents" in the final HTML output so that code is nicely formatted
       
      if (empty($first_depth))
        $first_depth = $this->vals[$i]['level'] - 1;

      $depth = $this->vals[$i]['level'] - $first_depth;
      $indent = str_repeat(' ', $depth);

// when the last podcast is reached in each category, an extra row is added to provide a buffer for the next category.

      if ($type == 'close')
      {
        $category_count++;
     
        $this->html .= "<tr>\n<td height=".'"20px"'."></td>\n<td></td></tr>\n";
        continue;
      }
      
      $count++;

/*
the text (podcast name or category name) and $feed (rss/xml feed for podcast as parsed from the OPML file
*/

      $text = htmlentities($this->vals[$i]['attributes']['TEXT']);
      $feed = htmlentities($this->vals[$i]['attributes']['URL']);

      
            
      if ($type == 'complete')
     
      {
/*
skip over the first entry which is just a link to add a new podcast to the category. This is hardcoded in HTML already.
*/
        if ( preg_match("/\bClick to add your show to this listing\b/i", $text, $match))
        {
        continue;
        }
        
/*
identifies whether a category # is even/odd and the podcast # is even/odd. Apply appropriate formatting based on class variables defined above.
*/

        if ($category_count % 2)
         ($podcast_count % 2) ? $bgcolor = $this->oddcategory_oddpodcast_color : $bgcolor = $this->oddcategory_evenpodcast_color;
        else
         ($podcast_count % 2) ? $bgcolor = $this->evencategory_oddpodcast_color : $bgcolor = $this->evencategory_evenpodcast_color;

//formatting for podcast feed

        if ($feed)
        {
         $this->html .= "<tr> \n";
         $this->html .= $indent . $indent . '<td width="50px" align="center" bgcolor ="'. $bgcolor. '"><a href="' . $feed . '"><img alt="Click to select feed" src="http://www.scripting.com/images/xmlIcon2.gif" border="0" height="14" width="36"></a></td>'."\n";
        
//formatting for podcast name/description

        if ($text)
          $this->html .= $indent . $indent . '<td width="650px" align="left" bgcolor="' . $bgcolor. '" cellpadding="3"><B>'. $text . '</B>';
          $podcast_count++;
          
        }
        $this->html .= "</td>\n</tr>\n";
      }
      
//formatting for category name

      if ($type == 'open') // This for the section headers
       {
        $this->html .= '<tr><td colspan="2"><h3 align="left"><b>'. $text . "</b></h3></td></tr>\n";
        $podcast_count = 1; // counter to track podcast # for color formatting
       }
    }
  }
}

?>


The author speaks

18 April 2005 : code, php, programming

I wrote a few weeks ago about learning php. Well today I got stumped by a php problem so I took the brave step of contacting the author of my php book, Jason Gilmore, to see if he could shed some light on my problem. I was surprised to see an answer from him by the time I had finished dinner and he even dropped a nice comment on my blog.

For a beginner like me, it’s nice to know that great help is out there.


Scuttle

10 April 2005 : code, php, programming

I’ve been using del.icio.us for the past few months and I’ve been really pleased with how easy it is to maintain and access my bookmarks anywhere. However, I’ve often wished that there was a privacy feature in del.icio.us so that I could make some links publicly viewable and the rest would be private. Well this morning I was reading a few blogs and came across a link to Scuttle as an personalized version of del.icio.us. I played around with the test site a little and realized this is exactly what I was looking for. Marcus Campbell, the creator of scuttle has recreated del.icio.us in PHP and MYSQL allowing anyone with a webserver to store their bookmarks on their localhost. He’s also done a great job of using css to make the links easy to read. Best of all he’s tweaked the category creation logic so that you can have a category link “Cool Links” instead of having to smash it together with underscore characters (i.e. Cool_Links). I’ll let you install Scuttle to figure out how he accomplishes this.

Because Scuttle is open-source and very cleanly written, its very easy to customize. It’s also gotten me thinking about a project I’d like to work on. I’ve been meaning to write a bookmarklet which parses the ISBN number of an Amazon link and creates a boomark in my Scuttle list. I’ve wanted a good way to keep track of books that friends recommend without relying only on the Amazon wishlist system. I’ve done some poking around the scuttle file structure and I think this could be done easily. If anyone reading this has some ideas about how to go about doing this, drop me a line at projects@rasheqrahman.com. Hopefully I can give back to the open source community.


Learning PHP

30 March 2005 : code, php, programming

Now that I have my own domain and access to a server, I’ve been poking around with some cool open source apps. One of the first applications I installed was Wikka (formerly known as Wakka). Wikka is an Wiki written in PHP with some great features:

  • PHP and MYSQL make it lightweight and fast. (Okay so that’s propaganda from the website but it really is great.)
  • Page level security so you can determine which pages can be viewed and edited by others.
  • Like other Wikis it uses the CamelCase syntax for links to other pages but it also has some neat tricks for creating elements like lists, horizontal bars, etc.
  • Its functionality can be extended using plugins called actions. People have written actions to display rss feeds and calendars among others.

This last feature really got my creative juices flowing. As I examined the actions that others had written and p0ked around the actions folder in the Wikka installation, I saw that people were doing some pretty powerful things using pretty simple code. One project in particular to make Wikka into a Personal Information Manager really excited me as I wanted to use the Wiki as a my online dossier for ideas, programming projects, etc. Seeing different implementations of to-do-lists, calendars and schedules made me want to build my own.

My first step was to start learning PHP and MYSQL. Since I do a lot of work with SQL in my day job on Wall Street, I knew I would have no trouble writing the queries I would need for my event calendar. Being a semi-pro VB developer I thought PHP as a sister programming language would be pretty straightforward as well. I picked up J.W Gilmore’s Beginning PHP5 and MYSQL: From Novice to Professional. The book is great for beginners, easy to read especially if you are familiar with basic programming concepts but not so basic that you feel the author is treating you like a novice. After the first sixty pages and a few examples, I felt confident enough to poke around myself and I printed out some of the Wikka action code to see if I could pull it apart.

With the help of the book and some specific searches of the PHP.net website, I was able to write a simple date action which would allow me to enter “{{date}}” on a Wikka page and it would print out a formatted version of the current date. Emboldened by the simple success, I jumped way ahead of my skill set to the end of Gilmore’s book and peeked at the code for connecting mysql to PHP. Here I was bested by the most humble of creatures: the semicolon.

I began my quest to connect a simple Contacts table in MYSQL to a small routine which would print out the results of a dynamic query into Wikka via a “{{contacts}}” action. I found some simple code on the About.com website and modified it with the login details from my own server. However, everytime I would load the sample.php file I would get a blank page. Coming from the VB background, I’m used to having Excel or Access shout at me via a dialog box with a cryptic error message which I would have to decipher using the posts of others on VB programming bulleting boards. By contrast this silent refusal to execute my commands was at first puzzling but soon became frustrating. I thought at first my php code didn’t like the MYSQL user name and password that I had set up for my test database. So I changed the user password several times. Then, I commented out the whole program and just concentrated on getting the connection to the database to work and print out “Database connected.” Once I got that working, I slowly started uncommenting my program line by line until the point where I would get the blank screen again. By the end of about two hours I had unraveled about half of the code and gotten it to work. My wife called me away for dinner sensing that I need some fuel. Nurished, I return to the joust. However as I was reviewing one line of code, I noticed that I was missing a semicolon at the end of the line. After adding it in and checking the remaining commented code for missing semicolons, I took a huge step and uncommented all of the code. With baited breath, I clicked the refresh button on my browser and to my joy, the formatted output of my query appeared in its proper place on my wiki.

My advice to young programmers who may find this post among the annals of history: remember your semi-colons.