<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>... coding (the life) &#187; job</title>
	<atom:link href="http://www.marvinmarcelo.com/category/job/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marvinmarcelo.com</link>
	<description>Anything about programming, and a little about me.</description>
	<lastBuildDate>Thu, 22 Jul 2010 06:27:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using Smarty&#8217;s count_words and count_characters in design</title>
		<link>http://www.marvinmarcelo.com/using-smartys-count_words-and-count_characters-in-design/</link>
		<comments>http://www.marvinmarcelo.com/using-smartys-count_words-and-count_characters-in-design/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 05:47:07 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[work related]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1590</guid>
		<description><![CDATA[This product page inspired me to write this post. It was launched around February last year (uh oh time flies!) and the first successful order was made around that time too. By then, there were only about 20 products or less, and really short attributes i.e. volumes in 8, 12 or 16 oz. strength like [...]]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://tr.im/MCz1">product page</a> inspired me to write this post. It was launched around February last year (uh oh time flies!) and the first successful order was made around that time too. By then, there were only about 20 products or less, and really short attributes i.e. volumes in 8, 12 or 16 oz. strength like mild, regular, etc. Last monday, new products came in for addition to the site and they have quite longer attributes. It could have had a liquid width on the attribute and cart buttons but they had a really good design advisers and wanted to follow the design to the pixel.</p>
<p><img src="http://www.marvinmarcelo.com/wp-content/uploads/2010/02/Screenshot.png" alt="" title="Screenshot" width="319" height="111" class="alignnone size-full wp-image-1602" /></p>
<p>Initially, this html code composes the product attribute and cart button, notice that <tt>&lt;span class="c"&gt;Cherry&lt;/span&gt;</tt> is a one word attribute for <tt>scent</tt></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cartbutton&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;background-image: url(images/button-long-add-to-bag.gif);&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c&quot;</span>&gt;</span>Cherry<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c&quot;</span>&gt;</span>8 oz.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c&quot;</span>&gt;</span>$5.99<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;e&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cart.php?product=5|33404&amp;amp;as=5&quot;</span>&gt;</span>Add to bag<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;e&quot;</span>&gt;</span>» ITEM: 33404<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>And the new ones came with the colors &#8220;Casino Red&#8221;, &#8220;Golden Chestnut&#8221; and &#8220;Orchid Black&#8221; &#8211; long attributes, and two others &#8220;Copper&#8221; and &#8220;Spice&#8221; &#8211; short and manageable, as the column width will fit the entire word. </p>
<p>I was really planning to rewrite the whole attribute and cart button section, but I didn&#8217;t had much time. I figured I can make the font smaller and paddings or margins can go smaller than the regular so that two lines would fit in the box if the attribute value is a word longer. But I cannot be in PHP, its not really the way to go. So, if I can add another class that would override existing font-size and parent margin/padding, that would work. Here, I thought, word count doesn&#8217;t really need be in the PHP side and since I&#8217;m using <a href="http://www.smarty.net/">Smarty</a>, I found in it a variable modifier that can print the <a href="http://www.smarty.net/manual/en/language.modifier.count.words.php">number of words</a> in a variable, and that&#8217;s it. I can add another class in the column span like <tt>words-10</tt> or <tt>countwords-3</tt> in my template by the number of words that is present in the variable. Below is the generated code</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cartbutton&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;background-image: url('images/button-long-add-to-bag.gif');&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c col-color words-2&quot;</span>&gt;</span>Casino Red<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>  	  	  	  	  	  	
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c col-volume&quot;</span>&gt;</span>8 oz.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>  	  	
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c&quot;</span>&gt;</span>$11.39<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cart.php?product=28|33825&amp;amp;as=14&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;e&quot;</span>&gt;</span>Add to bag<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;e&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;raquo;</span> ITEM: 33825<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>CSS rules</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* default rules */</span>
<span style="color: #6666ff;">.cartbutton</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">23px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'/images/button-add-to-bag.gif'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.cartbutton</span> span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.cartbutton</span> span<span style="color: #6666ff;">.c</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">45px</span><span style="color: #00AA00;">;</span>  <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.cartbutton</span> span<span style="color: #6666ff;">.d</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.cartbutton</span> span<span style="color: #6666ff;">.d</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.cartbutton</span> span<span style="color: #6666ff;">.e</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* special rule for two word attribute */</span>
span<span style="color: #6666ff;">.words-2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">98</span>%</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><img src="http://www.marvinmarcelo.com/wp-content/uploads/2010/02/Screenshot1.png" alt="" title="Screenshot" width="348" height="222" class="alignnone size-full wp-image-1610" /></p>
<p>And this is how it is setup in the template.</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #009000;">&lt;div class=&quot;cartbutton&quot; style=&quot;background-image: url('images/button-long-add-to-bag.gif');&quot;&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">color</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #009000;">&lt;span class=&quot;c col-color words-{$attr[at].color|count_words}&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">color</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">strength</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #009000;">&lt;span class=&quot;c col-strength words-{$attr[at].strength|count_words}&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">strength</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">scent</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #009000;">&lt;span class=&quot;c col-scent&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">scent</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">volume</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #009000;">&lt;span class=&quot;c col-volume&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">volume</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;span class=&quot;c&quot;&gt;</span>
  $ <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #D36900;">!</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">amount</span><span style="color: #D36900;">&#125;</span> <span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$results</span><span style="color: #D36900;">&#91;</span>r<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">amount</span><span style="color: #D36900;">&#125;</span> <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">else</span><span style="color: #D36900;">&#125;</span> <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">math</span> equation<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;x&quot;</span> x<span style="color: #D36900;">=</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">amount</span> format<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;%.2f&quot;</span><span style="color: #D36900;">&#125;</span> <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #009000;">&lt;span class=&quot;d&quot;&gt;</span>
  <span style="color: #009000;">&lt;a href=&quot;cart.php?product={$results[r].id}|{if $results[r].sku &amp;&amp; !$attr[at].sku}{$results[r].sku}{elseif $attr[at].sku}{$attr[at].sku}{/if}&amp;amp;as={$attr[at].pas_id}&quot; class=&quot;e&quot;&gt;</span>Add to bag<span style="color: #009000;">&lt;/a&gt;</span>
<span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #009000;">&lt;span class=&quot;e&quot;&gt;</span>&amp;raquo; ITEM: <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$results</span><span style="color: #D36900;">&#91;</span>r<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">sku</span> &amp;&amp; <span style="color: #D36900;">!</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">sku</span><span style="color: #D36900;">&#125;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$results</span><span style="color: #D36900;">&#91;</span>r<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">sku</span><span style="color: #D36900;">&#125;</span><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">elseif</span> <span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">sku</span><span style="color: #D36900;">&#125;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$attr</span><span style="color: #D36900;">&#91;</span>at<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">sku</span><span style="color: #D36900;">&#125;</span><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/span&gt;</span>
<span style="color: #009000;">&lt;/div&gt;</span></pre></div></div>

<p>Those extra class names like <tt>col-volume</tt>, <tt>col-scent</tt> and <tt>col-strength</tt> are only for future use, who knows what other formatting and adjustments on the data and theme will happen. Its really fun working with MVC model. Hope it helps <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/using-smartys-count_words-and-count_characters-in-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quickie Visitors Country WP Plugin</title>
		<link>http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/</link>
		<comments>http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 02:14:54 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1382</guid>
		<description><![CDATA[This plugin is dependent on WP/GeoTrack by Johannes Lietz, this is NOT a stand-alone plugin, it won&#8217;t work if WP/GeoTrack is not installed anyway, so it&#8217;s safe. And don&#8217;t look for it in WP Plugins repo, you won&#8217;t find it there 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [...]]]></description>
			<content:encoded><![CDATA[<p>This plugin is dependent on <a title="Visit plugin site" href="http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin">WP/GeoTrack</a> by <a title="Visit author homepage" href="http://dadabase.de/">Johannes Lietz</a>, this is NOT a stand-alone plugin, it won&#8217;t work if <a title="Visit plugin site" href="http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin">WP/GeoTrack</a> is not installed anyway, so it&#8217;s safe.</p>
<p>And don&#8217;t look for it in <a href="http://wordpress.org/extend/plugins/">WP Plugins</a> repo, you won&#8217;t find it there <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Plugin Name: Top Visitors Flag
Plugin URI: http://www.marvinmarcelo.com/
Description: This plugin displays visitors on sidebar as widget dependent on &lt;a href=&quot;http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin&quot;&gt;WP/GEO-Track plugin&lt;/a&gt;.
Author: Marvin Marcelo
Author URI: http://www.marvinmarcelo.com/
Version: 1.0.0
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> tvf_get_topvisits<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_prefix</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select count(*) as `rows` , `country` , `flagname` from `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$table_prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;geotrack` group by `country` order by `rows` desc limit 0 , 12&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$flagstats</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;li id='top-country-flags'&gt;&lt;h2&gt;Top Visiting Countries&lt;/h2&gt;&lt;div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/*  id string */</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$flagstats</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cf</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rows</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span> GEOTRACK_URL <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;flags/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cf</span><span style="color: #339933;">-/&gt;</span>flagname <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.png<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span>Flag of <span style="color: #006699; font-weight: bold;">$cf-&gt;country</span> with <span style="color: #006699; font-weight: bold;">$cf-&gt;rows</span> visits<span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$cf-&gt;country</span> with <span style="color: #006699; font-weight: bold;">$cf-&gt;rows</span> visits<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> init_tvf_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	register_sidebar_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Top Visitors Flags&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tvf_get_topvisits&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GT_NOT_INSTALLED'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;!-- You need <span style="color: #000099; font-weight: bold;">\&quot;</span>http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin<span style="color: #000099; font-weight: bold;">\&quot;</span> installed first--&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
  add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;plugins_loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;init_tvf_init&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Also, you have to forgive the function, constants, and variables names, we all struggle for a better and sensible one <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/quickie-visitors-country-wp-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Login without password</title>
		<link>http://www.marvinmarcelo.com/ssh-login-without-password/</link>
		<comments>http://www.marvinmarcelo.com/ssh-login-without-password/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 02:01:37 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[work related]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1346</guid>
		<description><![CDATA[This is actually a repost from the tutorial I often ran onto when working with servers. Lately, the sys-ad I was working with changed users home directory and also changed their passwords, but gave me the root pass. However, I don&#8217;t want to bother him for new passwords, and I guess he setup new ones [...]]]></description>
			<content:encoded><![CDATA[<p>This is actually a repost from the tutorial I often ran onto when working with servers. Lately, the sys-ad I was working with changed users home directory and also changed their passwords, but gave me the root pass. However, I don&#8217;t want to bother him for new passwords, and I guess he setup new ones from password generator apps/scripts, which are of course, really really recommended nowadays. Since I have the root pass, and I don&#8217;t want to go back to chmod-chown each and every files/folders I created via root, I thought I can automate logging in with each account I need to work &#8216;as&#8217; their respective users. Or I can use <tt>cat /etc/passwd</tt> to know their home directories.</p>
<p>First log in on A as user a and generate a pair of authentication keys.  Do not enter a passphrase:</p>
<pre>a@A:~&gt; ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A</pre>
<p>Now use <tt>ssh</tt> to create a directory <tt>~/.ssh</tt> as user b on B. (The directory may already exist, which is fine):</p>
<pre>a@A:~&gt; ssh b@B mkdir -p .ssh
b@B's password:</pre>
<p>Finally append a&#8217;s new public key to <tt>b@B:.ssh/authorized_keys</tt> and enter b&#8217;s password one last time:</p>
<pre>a@A:~&gt; cat .ssh/id_rsa.pub | ssh b@B 'cat &gt;&gt; .ssh/authorized_keys'
b@B's password:</pre>
<p>Now I can work as &#8216;owner&#8217; and &#8216;user&#8217; within each user home directory.</p>
<pre>a@A:~&gt; ssh b@B hostname
B</pre>
<p>Some notes, depending on your version of SSH you might also have to do the following changes:</p>
<ul>
<li>Put the public key in <tt>.ssh/authorized_keys2</tt></li>
<li>Change the permissions of <tt>.ssh</tt> to <tt>700</tt></li>
<li>Change the permissions of <tt>.ssh/authorized_keys2</tt> to <tt>640</tt></li>
</ul>
<p>Source: <a href="http://linuxproblem.org/art_9.html">http://linuxproblem.org/art_9.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/ssh-login-without-password/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP code block &#8211; bringing order to chaos</title>
		<link>http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/</link>
		<comments>http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 02:00:48 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[basic programming]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[ezsql]]></category>
		<category><![CDATA[grumble]]></category>
		<category><![CDATA[month-year]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1282</guid>
		<description><![CDATA[I had to come up with this post because I&#8217;ve been working on an old CMS about 3 years old (or even more) and I had been wondering why the calendar links cuts off from 2001 to 2003. Task: List a year/month links from the present to the oldest published image sets. Sounds easy, and [...]]]></description>
			<content:encoded><![CDATA[<p>I had to come up with this post because I&#8217;ve been working on an old CMS about 3 years old (or even more) and I had been wondering why the calendar links cuts off from 2001 to 2003.</p>
<p>Task: List a year/month links from the present to the oldest published image sets.</p>
<p>Sounds easy, and I believe it is.</p>
<p>But when I checked on the existing script, this is what I got.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$month_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'January'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'February'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'March'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'April'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;5&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'May'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'June'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'July'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;8&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'August'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;9&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'September'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'October'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;11&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'November'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;12&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'December'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'y2day'</span><span style="color: #339933;">,</span><span style="color: #000088;">$y2day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">'2000'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$m2day</span> <span style="color: #339933;">==</span><span style="color: #000088;">$q</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span>  <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'2007'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>month<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span>
&nbsp;
		  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$m2day</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tmp_cal_month_now_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$q</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$date_month_now_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_month_now_array</span><span style="color: #339933;">;</span>	 <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//for</span>
&nbsp;
	 <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_now_month'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_month_now_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>	<span style="color: #000088;">$c_yeartoday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//echo $c_yeartoday;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span><span style="color: #000088;">$c_yeartoday</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$q</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//echo $tmp;</span>
&nbsp;
		 <span style="color: #000088;">$tmp_cal_date_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					  <span style="color: #0000ff;">'year'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$tmp</span>
&nbsp;
				 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #000088;">$date_year_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_date_array</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">//for</span>
&nbsp;
	<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_year'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_year_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>month<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$tmp_cal_month_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$q</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$date_month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_month_array</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//for</span>
	 <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_month'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_month_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #000088;">$y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$month_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'2000'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>month<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$w_string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$week_string</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$tmp_cal_month_old_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
					<span style="color: #0000ff;">'month'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$w_string</span><span style="color: #339933;">,</span>
					<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$q</span>
					<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$date_month_old_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$tmp_cal_month_old_array</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//for</span>
	 <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar_month_old'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date_month_old_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-1282"></span></p>
<p>Looking at the above script, it looks like they were grouped in to 4 sections, deriving the values of <code>$date_month_now_array</code>, <code>$date_year_array</code>, <code>$date_month_array</code> and <code>$date_month_old_array</code>. And the hardcoded values &#8217;2000&#8242; and &#8217;2007&#8242; will definitely set limit and obviously introduce bug, and so it did. Honestly, I would have coded it this way when I was moving into PHP 3 years ago, and perhaps even now if I&#8217;d have been coding for a whole day confronted with bugs.</p>
<p>Anyway, the main problem with the above code is, there was always a reference for dates and the original programmer didn&#8217;t use it, the date column in the content&#8217;s table. Instead, I&#8217;m guessing, he setup a start &#8216;year&#8217; which is probably he asked someone about the oldest possible year a content was published &#8211; there he arrived at using &#8217;2000&#8242; in the code. And if I&#8217;m not mistaken, this code was written in 2007, LOL, so there was a condition on year set to 2007.</p>
<p>Here&#8217;s how I modified it, optimized it as much (well I hope). The date column had a unix timestamp values, so it&#8217;s not in typical date format.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Calendar modification
 * @author marvin marcelo
 * @uses ez_sql
 * @link http://www.phpclasses.org/browse/package/790.html
 */</span>
<span style="color: #666666; font-style: italic;">/* present */</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y n j&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select distinct(from_unixtime(updateStartDate, '%Y')) year
          from series_table where updateStartDate &gt; 0 order by updateStartDate desc&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* ezSql stuff */</span>
<span style="color: #000088;">$years</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$months</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$endofmonth</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$years</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>year<span style="color: #0000ff;">&quot;]}-<span style="color: #006699; font-weight: bold;">$j</span>-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* future year-month */</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">/* this day in this month of this year is also future, use current date instead */</span>
      <span style="color: #000088;">$endofmonth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ts0</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$years</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>year<span style="color: #0000ff;">&quot;]}-<span style="color: #006699; font-weight: bold;">$j</span>-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* unix timestamp start of month */</span>
    <span style="color: #000088;">$ts1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$years</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>year<span style="color: #0000ff;">&quot;]}-<span style="color: #006699; font-weight: bold;">$j</span>-<span style="color: #006699; font-weight: bold;">$endofmonth</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* unix timestamp last day or today of month */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from series_table where updateStartDate &gt; <span style="color: #006699; font-weight: bold;">$ts0</span> and updateStartDate &lt; = <span style="color: #006699; font-weight: bold;">$ts1</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$month</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$months</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;active&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;j&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;F&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ts0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$months</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;j&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;F&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ts0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$months</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;months&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$months</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* template */</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'calendar'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$years</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * Calendar modification end block
 */</span></pre></div></div>

<p>The process I did &#8230;</p>
<ol>
<li>Select distinct years from all published content by converting unix timestamp to readable year value, then iterate on them</li>
<li>Do a for loop from 12 (december) to 1 (january) to generate a unix timestamp for use in the next query</li>
<li>Query the table for a matching timestamp of the first day and the last day of month-year pair; Use current day of month if iterating year and month matches the present</li>
<li>Show the month link for the year in iteration if a match is found</li>
</ol>
<p>Couple of notes though, I didn&#8217;t name the table as &#8216;series_table&#8217; <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  , it&#8217;s been there years since. I also named my variables when referring to start and end as <code>$x0</code> and <code>$x1</code>, <code>$ts0</code> and <code>$ts1</code>. I got used to this when college years in physics &#8211; the start and end of a distance, I don&#8217;t know, I just like the thought <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .</p>
<p>Hope it didn&#8217;t went order to chaos at all!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/php-code-block-bringing-order-to-chaos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPAnywhere &#8211; edit PHP from browser</title>
		<link>http://www.marvinmarcelo.com/phpanywhere-edit-php-from-browser/</link>
		<comments>http://www.marvinmarcelo.com/phpanywhere-edit-php-from-browser/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 05:37:55 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[work related]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1224</guid>
		<description><![CDATA[Found this post from Smash!ng Apps PHPanywhere is a new online service that&#8217;s changing the way people develop on the web. They enable users to develop and maintain their php/html projects online using any standard web browser. This is a web based free Integrated Development Environment or IDE for the PHP language, in other words [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Found this post from <a href="http://tr.im/xLMy">Smash!ng Apps</a></p></blockquote>
<p><a href="http://phpanywhere.net/">PHPanywhere</a> is a new online service that&#8217;s changing the way people develop on the web. They enable users to develop and maintain their php/html projects online using any standard web browser.</p>
<p>This is a web based free Integrated Development Environment or IDE for the PHP language, in other words it is an application that gives developers all the code editing capabilities they need to develop PHP applications online. It includes a real-time syntax code editor with support for all web formats and a powerful FTP editor.</p>
<p><img class="alignnone" src="http://www.smashingapps.com/wp-content/uploads/2009/09/phpanywhere.jpg" alt="" width="500" height="360" /></p>
<p>Because it works in a browser you can start coding right away, no need for installing anything and best of all you can work from anywhere, all you need is an internet connection and a web browser and you&#8217;re ready to go.</p>
<p>You can develop and maintain multiple projects with ease using PHPanywhere, because as soon as you log in all your projects (FTP servers) are immediately accessible. PHPanywhere even remembers what files you were working on and reopens them as well.</p>
<p><strong>Real-time syntax code editor</strong></p>
<p>The real-time syntax code editor is really what PHPanywhere is all about, so here is a list of just some of the things it does:</p>
<ul type="disc">
<li>Syntax highlighting</li>
<li>Smart indentation for each language</li>
<li>Code folding</li>
<li>Full internationalization</li>
<li>Unlimited undo/redo (now handled on client (browser) side, no more waiting for server response)</li>
<li>Unlimited tabs</li>
<li>Find and replace feature (New Feature)</li>
<li>Displays line numbers (New Feature)</li>
<li>Code auto completion, snippets (New Feature)</li>
<li>Displays line numbers (New Feature)</li>
<li>Code indention  (TAB key) (New Feature)</li>
</ul>
<p><span id="more-1224"></span><br />
<strong>Projects (New Feature)</strong></p>
<p>Create and use projects to group files you commonly use together, so you can easily open them next time you need to work on the project.</p>
<p><strong>File permissions (New Feature)</strong></p>
<p>Change your file and folder permissions using PHPanywhere&#8217;s ftp explorer.</p>
<p><strong>Messages Window (New Feature)</strong></p>
<p>Your every action is now logged in the window at bottom of the screen, so you can now easily track changes you made using PHPanywhere.</p>
<p><strong>Skins (New Feature)</strong></p>
<p>Choose from different skins to change the look and feel of PHPanywhere.</p>
<p><strong>Welcome Screen (New Feature)</strong></p>
<p>Besides giving you a nice and warm welcome <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , it also displays shortcuts to your most common commands, and recently opened files and projects.</p>
<p><strong>Powerfull FTP explorer</strong></p>
<p>This is a full-blown FTP explorer. You can add as many servers as you like, edit files, create/delete files or folders and you can even edit the permissions on folders. It will definitely satisfy all you FTP needs.</p>
<p><strong>Work without restrictions</strong></p>
<p>PHPanywhere doesn&#8217;t install anything on your computer, so you can use it without asking your IT administrator for permission. Also since it isn&#8217;t on your computer, it works even if your corporate firewall is blocking the FTP port.</p>
<p><strong>Share your work</strong></p>
<p>Because all your projects are on our servers you can easily allow others to work on your project, without duplicating you files. Also PHPanywhere enables real-time document collaboration (**) which makes it the ideal work environment.</p>
<p>PHPanywhere can be comfortably run on Opera 9+ and Gecko-based browsers (Firefox, Camino, Seamonkey, &#8230;) on any OS. Support for IE and Safari/Chrome coming soon.</p>
<p>Source: <a href="http://tr.im/xLMy">http://www.smashingapps.com/2009/09/01/now-use-phpanywhere-to-code-directly-from-your-browser.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/phpanywhere-edit-php-from-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Smarty Gravatar plugin</title>
		<link>http://www.marvinmarcelo.com/smarty-gravatar-plugin/</link>
		<comments>http://www.marvinmarcelo.com/smarty-gravatar-plugin/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 03:33:40 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[gravatar]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1213</guid>
		<description><![CDATA[I realize the need for this when working on an MVC based CMS especially with Smarty engine in it. Oh and in case you&#8217;re wondering why its sounds like the upcoming movie Avatar by James Cameron, I don&#8217;t know. What it has to do with internet term &#8216;avatar&#8216;? I really don&#8217;t know. But in &#8216;www&#8217;, [...]]]></description>
			<content:encoded><![CDATA[<p>I realize the need for this when working on an MVC based CMS especially with <a href="http://www.smarty.net">Smarty</a> engine in it.</p>
<p>Oh and in case you&#8217;re wondering why its sounds like the upcoming movie <a href="http://www.imdb.com/title/tt0499549/">Avatar</a> by <a href="http://www.imdb.com/name/nm0000116/">James Cameron</a>, I don&#8217;t know. What it has to do with internet term &#8216;<a href="http://en.wikipedia.org/wiki/Avatar_(computing)">avatar</a>&#8216;? I really don&#8217;t know. But in &#8216;www&#8217;, <a href="http://en.gravatar.com/">Gravatar</a> is a short term for &#8220;Globally Recognized Avatar&#8221; assigned by a user as his/her default avatar in every places of the internet, same people behind <a href="http://wordpress.com">WordPress</a>. There are other similar services too.</p>
<p>So, this plugin is based from its <a href="http://en.gravatar.com/site/implement">documentation</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Gravatar
 *
 * @link http://www.marvinmarcelo.com
 *
 * @param array $params
 * @param Smarty $smarty
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> smarty_function_gravatar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$smarty</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * constant $gravatar_host
   */</span>
  <span style="color: #000088;">$gravatar_host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.gravatar.com/avatar/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;gravatar: email parameter not set&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">eregi</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;gravatar: <span style="color: #006699; font-weight: bold;">{$params['email']}</span> is not a valid email.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009933; font-style: italic;">/**
   * @link http://en.gravatar.com/site/implement/url
   */</span>
  <span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gravatar_host</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hash</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.jpg?&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span><span style="color: #cc66cc;">512</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$src</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;s={<span style="color: #006699; font-weight: bold;">$params</span>[&quot;</span>size<span style="color: #0000ff;">&quot;]}&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;default&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;default&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;identicon&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$src</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;d={<span style="color: #006699; font-weight: bold;">$params</span>[&quot;</span><span style="color: #b1b100;">default</span><span style="color: #0000ff;">&quot;]}&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;rating&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;rating&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;G&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$src</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;r={<span style="color: #006699; font-weight: bold;">$params</span>[&quot;</span>rating<span style="color: #0000ff;">&quot;]}&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$extras</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;class&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$extras</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; class=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$params</span>[&quot;</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$extras</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; id=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$params</span>[&quot;</span>id<span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009933; font-style: italic;">/**
   * @example http://www.gravatar.com/avatar/7023218434f12aee57f4b03454dadcaa?s=32&amp;d=identicon&amp;r=G
   */</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$src</span><span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$params</span>[&quot;</span>alt<span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$extras</span> /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Simply extract <a href='http://www.marvinmarcelo.com/wp-content/uploads/2009/08/function.gravatar.zip'>function.gravatar.zip</a> into your Smarty plugin directory. And use it in your template file like this</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span>gravatar email<span style="color: #D36900;">=</span><span style="color: #ff0000;">'someemail@domain.com'</span><span style="color: #D36900;">&#125;</span></pre></div></div>

<p>You&#8217;re done!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/smarty-gravatar-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix unresponsive browser when serving files via PHP</title>
		<link>http://www.marvinmarcelo.com/fix-unresponsive-browser-when-serving-files-via-php/</link>
		<comments>http://www.marvinmarcelo.com/fix-unresponsive-browser-when-serving-files-via-php/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 01:00:30 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[work related]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1162</guid>
		<description><![CDATA[After an hour long reading his frustrations over IM, I began google&#8217;ing on files served thru PHP but locks clicks in a client&#8217;s browser until download is finished. It is unresponsive until the download is complete. // add this function before a readfile() or chunked with fopen() session_write_close&#40;&#41;; // header goes here, content-type, filename, etc [...]]]></description>
			<content:encoded><![CDATA[<p>After an hour long reading <abbr title="my client">his</abbr> frustrations over IM, I began google&#8217;ing on files served thru PHP but locks clicks in a client&#8217;s browser until download is finished. It is unresponsive until the download is complete.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// add this function before a readfile() or chunked with fopen()</span>
<span style="color: #990000;">session_write_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// header goes here, content-type, filename, etc</span>
<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And, also, I found <a href="http://phpclasses.sgboards.com/browse/file/9051.html">this class</a> to support downloading using a download manager.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/fix-unresponsive-browser-when-serving-files-via-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smarty template for generating cascaded UL based menu</title>
		<link>http://www.marvinmarcelo.com/smarty-template-for-generating-cascaded-ul-based-menu/</link>
		<comments>http://www.marvinmarcelo.com/smarty-template-for-generating-cascaded-ul-based-menu/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 00:30:52 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[me stuff]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=1060</guid>
		<description><![CDATA[So far, I&#8217;ve been happy how this template behaves when I pass a parent/child links into it. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 &#60; {$parent_tag&#124;default:'ul'}{if $menu_id} id=&#34;{$menu_id}&#34;{/if}{if $parent_class} class=&#34;{$parent_class}&#34;{/if}&#62;{* ul tag opens here *} &#123;foreach from=$links item=link&#125; &#123;if $link.class_active &#38;&#38; $link.href == $current_uri&#125; [...]]]></description>
			<content:encoded><![CDATA[<p>So far, I&#8217;ve been happy how this template behaves when I pass a parent/child links into it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #009000;">&lt; {$parent_tag|default:'ul'}{if $menu_id} id=&quot;{$menu_id}&quot;{/if}{if $parent_class} class=&quot;{$parent_class}&quot;{/if}&gt;</span><span style="color: #008080; font-style: italic;">{* ul tag opens here *}</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">foreach</span> <span style="color: #6A0A0A;">from</span><span style="color: #D36900;">=</span><span style="color: #00aaff;">$links</span> <span style="color: #6A0A0A;">item</span><span style="color: #D36900;">=</span>link<span style="color: #D36900;">&#125;</span>
  <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$link</span>.<span style="color: #006600;">class_active</span> &amp;&amp; <span style="color: #00aaff;">$link</span>.<span style="color: #006600;">href</span> <span style="color: #D36900;">==</span> <span style="color: #00aaff;">$current_uri</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$link</span>.<span style="color: #006600;">class</span><span style="color: #D36900;">&#125;</span>
      <span style="color: #D36900;">&#123;</span><span style="color: #008000;">assign</span> var<span style="color: #D36900;">=</span>class <span style="color: #6A0A0A;">value</span><span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;`$link.class` `$link.class_active`&quot;</span><span style="color: #D36900;">&#125;</span>      
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">else</span><span style="color: #D36900;">&#125;</span>
      <span style="color: #D36900;">&#123;</span><span style="color: #008000;">assign</span> var<span style="color: #D36900;">=</span>class <span style="color: #6A0A0A;">value</span><span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;`$link.class_active`&quot;</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">else</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #008000;">assign</span> var<span style="color: #D36900;">=</span>class <span style="color: #6A0A0A;">value</span><span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;`$link.class`&quot;</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #009000;">&lt; {$child_tag|default:'li'}{if $class} class=&quot;{$class}&quot;{/if}{if $link.id} id=&quot;link_{$link.id}&quot;{/if}&gt;</span>
    <span style="color: #009000;">&lt;a href=&quot;{$link.href}&quot;{if $link.target} target=&quot;{$link.target}&quot;{/if}&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$link</span>.<span style="color: #006600;">text</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/a&gt;</span>
  <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$link</span>.<span style="color: #006600;">children</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">include</span> <span style="color: #6A0A0A;">file</span><span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;links.html&quot;</span> links<span style="color: #D36900;">=</span><span style="color: #00aaff;">$link</span>.<span style="color: #006600;">children</span> parent_class<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #D36900;">&#125;</span>
  <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">foreach</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt; /{$parent_tag|default:'ul'}&gt;</span></pre></td></tr></table></div>

<p>Does something like this when rendered</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sf-menu&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.swerteka.com/index.php&quot;</span>&gt;</span>Home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.swerteka.com/PostItem&quot;</span>&gt;</span>Post Item<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.swerteka.com&quot;</span>&gt;</span>Blog<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.swerteka.com/BlogComments/do/viewrecent&quot;</span>&gt;</span>Comments<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.swerteka.com/Content/name/about&quot;</span>&gt;</span>About<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.swerteka.com/Content/name/contact&quot;</span>&gt;</span>Contact Us<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/smarty-template-for-generating-cascaded-ul-based-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OOP 101: No logic in template, as much as possible</title>
		<link>http://www.marvinmarcelo.com/oop-101-no-logic-in-template-as-much-as-possible/</link>
		<comments>http://www.marvinmarcelo.com/oop-101-no-logic-in-template-as-much-as-possible/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 02:15:25 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[work related]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=916</guid>
		<description><![CDATA[If you have a repeating region in your template and it doesn&#8217;t need a wrapper around it, simply use section 1 2 3 &#123;section name=s loop=$images&#125; &#60;div id=&#34;image_{$images[s].id}&#34;&#62;&#60;img src=&#34;{$images[s].src}&#34; alt=&#34;&#34; /&#62;&#60;/div&#62; &#123;/section&#125; Cases where you need html wrap tags is like this 1 2 3 4 5 6 7 8 9 &#123;if $navlinks&#125; &#60;ul&#62; &#123;section [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a repeating region in your template and it doesn&#8217;t need a wrapper around it, simply use <code>section</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span>s <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span><span style="color: #00aaff;">$images</span><span style="color: #D36900;">&#125;</span>
   <span style="color: #009000;">&lt;div id=&quot;image_{$images[s].id}&quot;&gt;&lt;img src=&quot;{$images[s].src}&quot; alt=&quot;&quot; /&gt;&lt;/div&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span></pre></td></tr></table></div>

<p>Cases where you need html wrap tags is like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$navlinks</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;ul&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span>s <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span><span style="color: #00aaff;">$navlinks</span><span style="color: #D36900;">&#125;</span>
   <span style="color: #009000;">&lt;li id=&quot;navitem_{$navlinks[s].id}&quot;&gt;</span>
     <span style="color: #009000;">&lt;a href=&quot;{$navlinks[s].href}&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$navlinks</span><span style="color: #D36900;">&#91;</span>s<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">text</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/a&gt;</span>
   <span style="color: #009000;">&lt;/li&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;/ul&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span></pre></td></tr></table></div>

<p>This avoids the <code>&lt;ul&gt;</code> being rendered if <code>$navlinks</code> don&#8217;t have a return record. Another way is to access Smarty properties</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span>s <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span><span style="color: #00aaff;">$navlinks</span><span style="color: #D36900;">&#125;</span>
   <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$smarty</span>.<span style="color: #0600FF;">section</span>.<span style="color: #006600;">s</span>.<span style="color: #006600;">first</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;ul&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
   <span style="color: #009000;">&lt;li id=&quot;navitem_{$navlinks[s].id}&quot;&gt;</span>
     <span style="color: #009000;">&lt;a href=&quot;{$navlinks[s].href}&quot;&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$navlinks</span><span style="color: #D36900;">&#91;</span>s<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">text</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/a&gt;</span>
   <span style="color: #009000;">&lt;/li&gt;</span>
   <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #00aaff;">$smarty</span>.<span style="color: #0600FF;">section</span>.<span style="color: #006600;">s</span>.<span style="color: #006600;">last</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/ul&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span></pre></td></tr></table></div>

<p>But still, this adds an <code>if</code> in the template. As this post title goes, you should avoid them, that&#8217;s the basics of OOP system and MVC frameworks, separate logic from code <img src='http://www.marvinmarcelo.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>What made me write this post? Template Designers sometimes <em>hate</em> seeing <code>if</code> statements. In my case, my boss transforms into savvy Designer as well, at times! Bummer</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/oop-101-no-logic-in-template-as-much-as-possible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first project for open-source release</title>
		<link>http://www.marvinmarcelo.com/my-first-project-for-open-source-release/</link>
		<comments>http://www.marvinmarcelo.com/my-first-project-for-open-source-release/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 03:54:09 +0000</pubDate>
		<dc:creator>Marvin</dc:creator>
				<category><![CDATA[job]]></category>
		<category><![CDATA[work related]]></category>

		<guid isPermaLink="false">http://www.marvinmarcelo.com/?p=781</guid>
		<description><![CDATA[Welcome to SourceForge.net! The following project has been approved for hosting: Descriptive Name: ****** Unix Name: ****** By using the SourceForge.net site, you agree to be bound by the terms and conditions of the SourceForge.net Terms of Use Agreement. SourceForge.net project hosting is available solely to Open Source software development projects. If you are not [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Welcome to SourceForge.net!</p>
<p>The following project has been approved for hosting:</p>
<p>Descriptive Name:  ******<br />
Unix Name:         ******</p>
<p>By using the SourceForge.net site, you agree to be bound by the<br />
terms and conditions of the SourceForge.net Terms of Use Agreement.</p>
<p>SourceForge.net project hosting is available solely to Open Source<br />
software development projects.  If you are not releasing your project<br />
under an Open Source license, please contact SourceForge.net staff for<br />
assistance (see &#8220;Support&#8221;, below).</p>
<p>Project Administration:</p>
<p>To manage your project, login and go to:</p>
<p>https://sourceforge.net/project/admin/?group_id=******</p>
<p>For help in getting started with your new project:</p>
<p>http://p.sf.net/sourceforge/getstarted</p>
<p>Support:</p>
<p>SourceForge.net maintains a full-time support team; we are ready to<br />
assist you with any questions you have about your new project.</p>
<p>We can be contacted by submitting a ticket at:</p>
<p>http://p.sf.net/sourceforge/submitticket</p>
<p>We may also be reached directly during business hours via IRC:</p>
<p>http://p.sf.net/sourceforge/irc</p>
<p>&#8211; the SourceForge.net crew</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.marvinmarcelo.com/my-first-project-for-open-source-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
