Bookmarks for September 17th through September 23rd

  • MODx Content Management System | Home - "MODx is an open source PHP Application Framework that helps you take control of your online content. It empowers developers and advanced users to give as much control as desired to whomever they desire for day-to-day website content maintenance chores."
  • SilverStripe CMS - "SilverStripe is an intuitive content management system atop a powerful programming framework.
    We've rethought how content editors, developers, and designers should build and manage websites. We've arrived at a unique combination that empowers all three to get their jobs done more quickly and with more flexibility."
  • Midgard CMS: Midgard Project: Midgard - New user experience - "Midgard CMS is an Open Source Content Management System built on top of the Linux, Apache, MySQL and PHP (LAMP) platform. It provides a reliable, powerful and internationalized set of tools for building web sites and networked applications. "
  • Zarafa - Open Source Exchange Server - "Nowadays, e-mail is one of the mission critical applications of a company. Zarafa combines the usabillity of Outlook with the stability and flexibility of a Linux server. Not only Outlook is supported natively, but users can use also the web 2.0 Outlook "Look & Feel" webaccess and all ActiveSync compatible mobile devices."
  • How-To: Covering Brand Bases on Twitter - MarketingVOX - "The young adults that use the service [Twitter] present a significant marketing opportunity for retail brands."

Related posts

Tagged with: , , , , , , , , , , , , , ,

Vacation Learning - PHP and Smarty Templates

I’m on vacation this week and next week. Since I rarely have time to learn anything technical (or blog for that matter anymore), I thought I would take some time during my time off to learn something new around development.

We have a system at work that is essentially a small portal. The core of it was written by me to learn PHP about 8 years ago and has been augmented by me and one other guy at workKeith and I over the years. Over that time, as we added new functionality to it, I used it to experiment with other languages as I was learning it. Other pieces were written in Java out of convenience. In total, we have pieces written in PHP, Java, Python, and PERL.

As I usually use this system to learn new things, I figured it would be a good candidate to use to learn how to use the Smarty templating system for PHP. I became interested in this templating system after working with Eventum over the last few weeks and figured that if I am going to do further work with Eventum, it would be helpful to understand the templating framework it uses.

So I’ve started using the system to take our 8 year old PHP code base and separate some of the presentation logic out. Smarty is pretty flexible and easy to use at a high level (I haven’t gotten into any of the really advanced stuff yet).

Here’s an example of how nicely the use of a templating system simplifies your code. Take this example, which enumerated entries from our internal wiki via an RSS feed into a section on the home page:


function getWikiEntries($url) {
   $theHTML = "";

   $rss = fetch_rss($url);

   $theHTML .=  "<table cellpadding="0" cellspacing="0" align="center"><tr>";
   $theHTML .=  "<th CLASS="header-title" colspan="2">";

   # get the channel title and link properties off of the rss object
   #
   $title = "Recent Wiki Entries";
   $link = $rss->channel['link'];

   #$theHTML .= "<a href=$link>$title</a>";
   $theHTML .= "$title&nbsp;&nbsp;&nbsp;<a href="$url"><img border="0" src="" . APP_URL . "/images/rss.png"/></a>";
   $theHTML .=  "</th></tr><tr><td colspan="2" class="modifications-sectionheader">&nbsp;</td></tr>";
   
   # foreach over each item in the array.
   # displaying simple links

   $rowCount = 0;
   $className = "modifications-evenrow";
   
   foreach ($rss->items as $item ) {

      if (($rowCount % 2) == 0) {
        $theHTML .= "<tr CLASS="$className">";
      }
      $theHTML .= "<td CLASS="modifications-data">";
      $theHTML .= "<a href="$item[link]" title="" . $item['title'] . "">";

        # truncate item title to 28 characters 
        $myTitle = $item['title'];

        if (strlen($myTitle) > 28 ) {
            $myTitle = substr($myTitle, 0, 28) . " ...";
       }

      $theHTML .= $myTitle;
      if (($rowCount % 2) == 0) {
          $theHTML .= "</a>&nbsp;&nbsp;</td>";
      } else {
          $theHTML .= "</tr>";
      }
      $rowCount++;
   
      if ($rowCount == 20):
         break;
      endif;
   }
   
   $theHTML .= "</table>";
   
   return($theHTML);
}

I’m sure you can appreciate how hard this would be to maintain, and all of the cruft that has accumulated over the years …

Now take the simplified version (sans error checking), written today in about 10 minutes:



function getWikiEntries($url) {
   $rss = fetch_rss($url);

   $template = new TemplateEngine();
   
   $firstComµçVÖâÒ'&•÷6Æ–6R‚G'72Óæ—FV×2“°Ð¢G6V6öæD6öÇVÖãÒ'&•÷6Æ–6R‚G'72Óæ—FV×2“°Ð¢ТGFVׯFRÓæ76–vâ‚&f—'7D6öÇVÖâ"ÂFf—'7D6öÇVÖ⓰ТGFVׯFRÓæ76–vâ‚'6V6öæD6öÛ^umn", $secondColumn);
   $template->assign("link", $rss->channel['link']);
   
   return($template->renderString("wikiEntries.tpl"));   
}

… along with its corresponding Smarty template:


<table width="80%" cellpadding="0" cellspacing="0" align="center">
<tr><th class="header-title" colspan="2">Recent Wiki Entries&nbsp;&nbsp; 
       <a href="{$link}"><img border="0"  src="{$applicationURL}/images/rss.png"/></a></th>
</tr>
<tr><td colspan="2" class="modifications-sectionheader">&nbsp;</td></tr>

{section name="entries" loop="$firstColumn"}
    <tr>
    <td class="modifications-data">
    <a href="{$firstComµçVÖå¶VçG&–W5ÒæÆ–æ·Ò"F—FÆSÒ'²Ff—'7D6öÇVÖå¶VçG&–W5ÒçF—FÆWÒ#ç²Ff—'7D6öÇVÖå¶VçG&–W5ÒçF—FÆWÇG'Væ6FS£#ƒ¢"âââ'ÓÂöâfæ'7²fæ'7°Ð¢Â÷FCàТÇFB6Æ73Ò&ÖöF–f–6F–öç2ÖFF#àТÆ‡&VcÒ'²G6V6öæD6öÇVÖå¶VçG&–W5ÒæÆ–æ·Ò"F—FÆSÒ'²G6V6öæD6öÛ^umn[entries].title}">{$secondColumn[entries].title}</a>
    </td></tr>
{/section}
</table>

I don’t know about you, but I think thats quite a difference in maintainability. I’d much rather modify the html in the template than in the original function. Not only that, but the code is actually code, not a bunch of code with a lot of simply horrid markup stuck in the middle of everything.

I’m pretty impressed with how much I’ve been able to use in a short amount of time this week. The libraries are obviously thought out and ramp up time for me was really minimal. I like libraries like that. It also addresses something that has annoyed me for a long time. Embedded HTML is a pain to maintain and I’ve dreaded going into this over the years just because of that.

At some point, I’ll investigate what it takes to write custom plugins, a functionality that the libraries also support.

I think I’ve been able to get a really good start at getting something maintainable. My goal over the next few of weeks is to templatize the whole system, then start taking the non-PHP pieces of the system and rewrite them in PHP. I’ll also add the ability to change configuration in one place, so that we can cut some of the pain that we have in keeping things maintained down - and perhaps be able to install the application in other places.

Should be fun. I’m definitely feeling productive over the past few days. I’ve always liked working in PHP over other languages. I definitely have to do work like this more often.

Related posts

Tagged with: , , ,

  • Ever wonder what Flickr’s architecture looks like? Niall Kennedy has a post about it that refers to a Powerpoint presentation on Flickr’s site and states some brief statistics. The presentation is pretty interesting. It’s amazing what you can do with MySQL and a little (okay, a lot of) PHP … Comments Off

IBM Backs PHP Programming Language

I found an article hidden away on slashdot talking about how IBM has entered into a partnership with Zend Technologies, a leading provider of PHP development tools, in order to "help make PHP work better with corporate databases and web service technologies".

I have used PHP quite a bit over the years both on the work and home fronts. Almost every incarnation of this web site has been written in PHP, including this one (Wordpress is written entirely in PHP). At work, I’ve used PHP to help manage data related to development and deployment processes that has been running for over three years with very little modification over the time its been in production. It’s very easy to write pretty solid code in an abbreviated amount of time using PHP.

PHP is a very powerful language, and it is very easy to get a highly interactive web site up very quickly. While I’ve never used the Zend development tools in order to perform any of this development, I’ve had very good experiences with the tool in general and I’m glad to see that it is finally going to get some backing from a pretty large corporate entity.

For one, it does something to validate the tool as valid corporate tool. Secondly, and probably more important to me, it validates the technology choice I made three years ago in order to get solid results as quickly as possible.

This should be a very interesting time for the PHP community. While they’ve had huge support from the Open Source community over the years, I’m interested to see how many companies start finding the PHP language a valid technology due to IBM’s backing.

Related Articles:

Related posts

Tagged with: ,