<?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>Anorgan's blog about stuff &#187; Web</title>
	<atom:link href="http://blog.anorgan.com/tag/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.anorgan.com</link>
	<description>...hmm</description>
	<lastBuildDate>Sun, 07 Feb 2010 00:39:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP and template engines (and some other stuff)</title>
		<link>http://blog.anorgan.com/2008/06/28/php-and-template-engines-and-some-other-stuff/</link>
		<comments>http://blog.anorgan.com/2008/06/28/php-and-template-engines-and-some-other-stuff/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 15:19:52 +0000</pubDate>
		<dc:creator>Anorgan</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.anorgan.com/blog/?p=23</guid>
		<description><![CDATA[I’m developing web sites for quite some time now, started when i was… Young? Yellow? Well, started a long time a go in a galaxy… AARGH! Can’t get Star Wars out of my life! Anyway. In the beginning i was using the good old php mess approach: echo '&#60;ul&#62;'; foreach($array as $item) { echo '&#60;li&#62;Some [...]]]></description>
			<content:encoded><![CDATA[<p>I’m developing web sites for quite some time now, started when i was… Young? Yellow? Well, started a long time a go in a galaxy… AARGH! Can’t get Star Wars out of my life! Anyway. In the beginning i was using the good old php mess approach:</p>
<p><code>echo '&lt;ul&gt;';<br />
 foreach($array as $item) {<br />
 echo '&lt;li&gt;Some $item here&lt;/li&gt;';<br />
 }<br />
 echo '&lt;ul&gt;';<br />
 </code></p>
<p>And so on. For onepagers this was enough. So i stumbled accross <a href="http://mambo-foundation.org/" target="_blank">mambo</a> (former <a href="http://www.joomla.org/" target="_blank">Joomla</a>) and saw the raw power of cms and, well for me, good coding. K, let&#8217;s make ourselves a content management system. But how? What do we need? The neccesary ingridients where these:</p>
<ul>
<li><a href="http://www.apache.org/" target="_blank">Apache</a> with <a href="http://www.php.net/" target="_blank">php</a> (obvious)</li>
<li><a href="http://www.mysql.com/" target="_blank">MySQL</a> database (oh, what&#8217;s this database thing for?)</li>
<li>foresight</li>
</ul>
<p>What’s the most important? No, wrong, not coffee. Foresight! Without analyzing and planning the outcome can’t be good. I started to code. Heavily. Took a good number of different approaches, all ended bit dull and like they couldn’t take on serious tasks.</p>
<p><span id="more-23"></span></p>
<p>Why this intro? So you can better relate to me. I AM one of you, coders. We all started like this. One learns trough he’s own mistakes. What have I learned? Let’s take this a bit further. There is no good CMS without know-how, so these are the things one has to be familiar with:</p>
<ul>
<li>apache web server and its .htaccess or http.conf files and configurations. Hence the readable links, good caching, security…</li>
<li><a href="http://www.ubuntu.com/" target="_blank">Linux</a>, yes, you need a bit of knowledge of that OS and it&#8217;s abilities. Good start is to install it on an empty partition or run it virtualized with <a href="http://www.vmware.com/" target="_blank">VMWare</a>. When you get to know it, you can do marvels like putting a cache directory into system memory with tmpfs, and so on</li>
<li>php programming language, with good knowledge of object oriented programming (OOP). This just simplifies things, realy. </li>
<li> usage of a template engine (oh, we&#8217;re getting on to a topic here, let&#8217;s have a beer!). I prefer <a href="http://www.smarty.net/" target="_blank">Smarty</a>, some say it&#8217;s too big, too complicated, too **insert your reason here**. I found that I can do my sites faster with it, so i use it</li>
<li>mysql database. This could be the hardest and most time consuming, but it&#8217;s well worth it. It includes database designing and SQL programming</li>
<li>benchmarking and debugging is also a part of the process. I use bit of <a href="http://xdebug.org/" target="_blank">xdebug</a>, <a href="http://www.zend.com/" target="_blank">zend platform</a>, smarty debug console, my own debug console for page creation time and sql execution times</li>
</ul>
<p>Ok, this is a handful, but any of the above items should be tackled at some point of the learning curve. If we are trying to code and produce scalable sites that can do the task right, we should be familiar with the MVC architecture. It comes down to having a database to store our data, php code to process that data and template to show that data. The upper code with all this in mind would be:</p>
<h2>DATABASE:</h2>
<p>1. item 1<br />
 2. item 2<br />
 3. item 3<br />
 4. &#8230;</p>
<h2>PHP and SQL:</h2>
<p><code>$data = $db-&gt;fetch('SELECT item FROM table');<br />
 $t-&gt;assign('data', $data);</code></p>
<h2>TEMPLATE:</h2>
<p><code>&lt;h1&gt;Our items&lt;/h1&gt;&lt;ul&gt;<br />
 {section name=item loop=$data}&lt;li&gt;{$data[item]}&lt;/li&gt;<br />
 {/section}&lt;/ul&gt;</code></p>
<p>Here we use a database abstraction layer class ($db) and are free of repeating the same change accross our code should we change database, etc. The template is free for editing by the designer, and the coder can still work on his code. Now we have everything separated, and one process can be changed regardless of the other.</p>
<p>One question pops up when we see {section}. It’s smarties way of saying “loop array $data and present data in the following way”. So, why should our designer be bothered with foreaches and if-then-elses? Answer lies in the following lines:</p>
<p><code>{section name=item loop=$data}<br />
 &lt;li {if $smarty.section.item.first}class="first"{/if}&gt;{$data[item]|upper}&lt;/li&gt;<br />
 {/section}</code></p>
<p>Designer just realized that the data presented is not right. Items should be uppercase and the first &lt;li&gt; should have class=”first”. Instead of yelling to the programmer “give me uppercased items!!!”, the designer has the power to modify, mold the data. Php guy is working on the control segment as we speak, he is half through the form processing code, which takes the order or whatnot, and the designer is at liberty to change the appearance of the data. He will choose to truncate long text, format date to display only day and month, maybe put {sectionelse} No data to display {/section} if $data array is empty, and he will never need to bother the programmer for those tasks.</p>
<p>If the caching is turned on, the php code and database calls will never even be executed, because the content is already rendered in some static file (which resides in our cache directory happily mounted to memory with tmpfs)</p>
<p>As we can see, this architecture helps alot, but it can be moved further. What if you need to present this data a couple of times across your site? It would be good if we could somehow include this block anytime we need it. And so we can, with {include file=”items.tpl”}. Anywhere we need this data (on the homepage, in the cart…) we just include this bit of a line. Saves time, eh? Now for the bad part.</p>
<h1>Drawbacks</h1>
<p>Template engines are good things to have, but they slow execution of the page. Smarty renders php code out of the template, and for that needs some processing time. He renders only once, and the rendered template benefits from the usage of some opcode cache module like <a href="http://eaccelerator.net/" target="_blank">eAccellerator</a>, <a href="http://www.zend.com/en/products/guard/optimizer/" target="_blank">Zend Optimizer</a> and such.</p>
<p>There is also the need to learn new language, smarty’s template language. It’s not that hard, and there is a lot of <a href="http://www.smarty.net/manual/en/" target="_blank">documentation</a> on the net for it. When you get accustomed to your template engines language, and start coding, the html starts to look really ugly. That’s really up to you to decide weather you want to have all the foreaches and if/then/elses in the php, parse them, and send them to the template. There is also <a href="http://phptal.motion-twin.com/" target="_blank">PHPTal</a> template engine, whose code is really simple and intuitive.</p>
<h1>Conclusion</h1>
<p>Once you take the MVC road, there is no turning back. You will never go back to having all the code and html in one file. Your next stop is maybe using some frameworks to get the job done even faster (<a href="http://www.symfony-project.org/" target="_blank">symfony</a>, <a href="http://www.akelos.org/" target="_blank">akelos</a>, <a href="http://framework.zend.com/" target="_blank">zend framework</a>&#8230;), or building your own classes for your application.</p>
<p>Keep coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorgan.com/2008/06/28/php-and-template-engines-and-some-other-stuff/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress SVN upgrade</title>
		<link>http://blog.anorgan.com/2008/06/08/wordpress-svn-upgrade/</link>
		<comments>http://blog.anorgan.com/2008/06/08/wordpress-svn-upgrade/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 16:28:46 +0000</pubDate>
		<dc:creator>Anorgan</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.blog.local/?p=5</guid>
		<description><![CDATA[Usually when the new version of WordPress is out, you have to download the latest zip (or tar.gz), unpack it, upload everything, and run upgrade. You can help yourself with uploading the zip file to the server and unpack it there, but you have to have shell account and know a bit of console commands. [...]]]></description>
			<content:encoded><![CDATA[<p>Usually when the new version of WordPress is out, you have to download the latest zip (or tar.gz), unpack it, upload everything, and run upgrade. You can help yourself with uploading the zip file to the server and unpack it there, but you have to have shell account and know a bit of console commands.</p>
<p>There is another way of upgrading to the latest version, and that involves usage of <a title="Subversion" href="http://subversion.tigris.org/" target="_blank">Subversion</a>. This gets the latest of files but you still need the console. The command is:</p>
<p><code>svn co http://svn.automattic.com/wordpress/trunk/</code></p>
<p>So, to help with the upgrading process, I&#8217;ve developed the SVN upgrade plug-in. It uses the phpSVNclient and some other classes by <a href="http://www.sixdegrees.com.br" target="_blank">Cesar</a>, who posted it on <a href="http://www.phpclasses.org/" target="_blank">PHP Classes</a>. I took it and made the plug-in firstly for my CMS, and it works great. Than I saw that the WordPress can be obtained via Subversion, so I decided to make svn upgrade available to all.</p>
<p>SVN upgrade uses database (wp_svn table) in which it stores the latest repository revision. If a new revision is out, you can do the upgrade, otherwise it will tell you that it is on the latest version.</p>
<p>Oh, and I have just tested it, again. 8061 is out! Bleeding edge! wp-login.php just got debugged, or something, and i have it! With just one click! Great!</p>
<p><span id="more-6"></span></p>
<p>Anyway, the plug-in can be downloaded here:<a href="/wp-content/uploads/2008/06/wp-svn.zip"> SVN upgrade plug-in</a></p>
<p>Installation is easy as always:</p>
<ol>
<li>Unpack and upload to wp-content/plugins</li>
<li>Install via admin console (plugins page)</li>
<li>If necessary update the repository in settings section</li>
<li>Go to the SVN upgrade page (link in main menu) and click SVN upgrade</li>
</ol>
<p>That&#8217;s it. Happy upgrading!</p>
<blockquote><p>Update: no need for this plugin anymore, the new WordPress handles updates on his own <img src='http://blog.anorgan.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  .</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorgan.com/2008/06/08/wordpress-svn-upgrade/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
