<?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>visual77 &#187; php</title>
	<atom:link href="http://visual77.com/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://visual77.com</link>
	<description>Ramblings from Steve Phillips</description>
	<lastBuildDate>Sat, 10 Sep 2011 21:19:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Drupal migration</title>
		<link>http://visual77.com/blog/2011/08/drupal-migration/</link>
		<comments>http://visual77.com/blog/2011/08/drupal-migration/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 19:08:33 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://visual77.com/?p=704</guid>
		<description><![CDATA[In the past 6 months, I&#8217;ve been using Drupal quite a bit and have made the decision to migrate my site from WordPress to Drupal. I&#8217;m more familiar with Drupal 6.x than Drupal 7.x right now, but I can easily change that. The decision to migrate really came to a head when I made my last [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>In the past 6 months, I&#8217;ve been using Drupal quite a bit and have made the decision to migrate my site from WordPress to Drupal. I&#8217;m more familiar with Drupal 6.x than Drupal 7.x right now, but I can easily change that. The decision to migrate really came to a head when I made my last post about the <a title="Drupal Statepicker Module" href="http://visual77.com/blog/2011/08/drupal-statepicker-module/">statepicker module</a> and realized I have no ability to show off this module on my own site. Not only is this site running software that isn&#8217;t Drupal, but WordPress is a platform that I don&#8217;t foresee myself spending much time in its development community.</p>
<p>My time with Drupal has really changed my opinion of it from &#8216;meh&#8217; to semi-awestruck. The main point that I keep thinking about is that I have yet needed to hack in any changes to Drupal. Every module I&#8217;ve written and every customization I&#8217;ve done has been neatly tucked into the sites folder, where custom content is intended to be handled. Unlike the other platforms I&#8217;ve used (mostly Kohana and WordPress), I have not needed to go edit things I shouldn&#8217;t be editing to reach my desired result.</p>
<p>I&#8217;ll be doing the migration over the next month or so. As of right now, I just have a blank Drupal 7.7 install floating in a git repository. I have a lot of work before it&#8217;s suitable to replace this WordPress build.</p>
<div class="shr-publisher-704"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2011/08/drupal-migration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drupal Statepicker Module</title>
		<link>http://visual77.com/blog/2011/08/drupal-statepicker-module/</link>
		<comments>http://visual77.com/blog/2011/08/drupal-statepicker-module/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 21:57:49 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[statepicker]]></category>

		<guid isPermaLink="false">http://visual77.com/?p=701</guid>
		<description><![CDATA[I&#8217;ve spent the past few months working heavily with Drupal, rebuilding my company&#8217;s primary site on it. While doing this, I came to an interesting issue that involved creating a module that I think the Drupal community at large could use &#8211; a new form item type for choose a state, with a full country [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>I&#8217;ve spent the past few months working heavily with Drupal, rebuilding my company&#8217;s primary site on it. While doing this, I came to an interesting issue that involved creating a module that I think the Drupal community at large could use &#8211; a new form item type for choose a state, with a full country list as well. To solve this issue, I created the statepicker module, which is currently hosted on Drupal.org as a sandbox project, but I hope to have it upgraded to full project status shortly.</p>
<p>Statepicker creates a new field type, called &#8216;statepicker&#8217;, that creates a pair of dropdown menus in the form &#8211; a state dropdown and a country dropdown. When the country dropdown is changed, an AJAX call refreshes the state list to show the states from the current country. I&#8217;ve also created an administration panel that lets an admin edit the state list.</p>
<p>You can download the module from the Drupal.org site, currently only through the repository viewer.</p>
<p>http://drupal.org/sandbox/visual77/1258930</p>
<div class="shr-publisher-701"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2011/08/drupal-statepicker-module/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Kohana 2.x kotidy &#8211; Using the Tidy library to clean up Kohana&#8217;s HTML output</title>
		<link>http://visual77.com/blog/2010/09/kohana-2-x-kotidy-using-the-tidy-library-to-clean-up-kohanas-html-output/</link>
		<comments>http://visual77.com/blog/2010/09/kohana-2-x-kotidy-using-the-tidy-library-to-clean-up-kohanas-html-output/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 19:11:17 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[visual77]]></category>
		<category><![CDATA[ko23]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=643</guid>
		<description><![CDATA[In a quick followup to yesterday&#8217;s building and releasing autoasset, I&#8217;ve created another module to do something simple and portable for Kohana 2.x. This module, kotidy, uses the PHP Tidy library to clean up the HTML output immediately prior to display. Even though the HTML is not seen by the end user, I find myself [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>In a quick followup to <a href="http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/">yesterday&#8217;s building and releasing autoasset</a>, I&#8217;ve created another module to do something simple and portable for <a href="http://visual77.com/blog/tag/kohana">Kohana</a> 2.x. This module, kotidy, uses the <a href="http://php.net/tidy">PHP Tidy</a> library to clean up the HTML output immediately prior to display. Even though the HTML is not seen by the end user, I find myself OCD about this kind of stuff and want to know that my source code is clean, even if most people will never see it.</p>
<p>Just like autoasset, kotidy uses the Event system to hook a basic function in place to use the tidy library to clean up the output. Other than adding this module to your module list in the main config file, no work is required on your part, unless you want to customize the config data being sent to Tidy::parseString(), of course.</p>
<p><a href="http://visual77.com/blog/wp-content/uploads/2010/09/kotidy.zip">Download Kohana 2.x &#8211; kotidy</a></p>
<div class="shr-publisher-643"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/09/kohana-2-x-kotidy-using-the-tidy-library-to-clean-up-kohanas-html-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana 2.x Autoasset &#8211; Automatically include relevant javascript, css and more</title>
		<link>http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/</link>
		<comments>http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 06:00:25 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[visual77]]></category>
		<category><![CDATA[ko23]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=638</guid>
		<description><![CDATA[I&#8217;ve set up about a half dozen Kohana 2.x sites now, and one problem that I constantly run into is including javascript / css based on the controller and method for the current page. For instance, if you go to &#8220;/user/view/1&#8243; on a Kohana site, I would like to automatically include &#8220;/javascript/user.js&#8221; or &#8220;/javascript/user/view.js&#8221;, if [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>I&#8217;ve set up about a half dozen <a href="http://visual77.com/blog/tags/kohana">Kohana</a> 2.x sites now, and one problem that I constantly run into is including javascript / css based on the controller and method for the current page. For instance, if you go to &#8220;/user/view/1&#8243; on a Kohana site, I would like to automatically include &#8220;/javascript/user.js&#8221; or &#8220;/javascript/user/view.js&#8221;, if the files exist.</p>
<p>To solve this problem, I created an autoasset module for Kohana 2.x. It will not work on Kohana 3.x due to the removal of events and hooks. To use autoasset, simply load it like you would any other module, and then go into the config file and specify which kinds of assets to load. Just input the directory that these assets are stored in, the file extension, and a callback to use when rendering. I put in example entries for javascript and css as a demonstration. You can then render the autoloaded assets by calling autoasset::render(); where you want to include the assets, such as the html head tag.</p>
<p>On a similar note, modules like this are one of the main reasons why I am launching <a href="http://visual77.com/blog/tags/ko23">ko23.net</a>. I think Kohana 2.x is a fantastic framework, and if a large community arose to provide modules that are just generally useful, then Kohana 2.x could really shine.</p>
<p><a href="http://visual77.com/blog/wp-content/uploads/2010/09/autoasset.zip">Download Kohana 2.x Autoasset</a></p>
<div class="shr-publisher-638"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/09/kohana-2-x-autoasset-automatically-include-relevant-javascript-css-and-more/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Kohana 2.3 community</title>
		<link>http://visual77.com/blog/2010/09/kohana-2-x-community/</link>
		<comments>http://visual77.com/blog/2010/09/kohana-2-x-community/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 16:03:00 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[visual77]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=634</guid>
		<description><![CDATA[I&#8217;ve been a Kohana user for about a year now, and every major update pleases me less than the last. I&#8217;m considering starting a community dedicated to Kohana 2.3, built around maintaining documentation (since the official site already pulled the Doxygen docs, how long until they pull the documentation wiki?), creating new modules and generally [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>I&#8217;ve been a Kohana user for about a year now, and every major update pleases me less than the last. I&#8217;m considering starting a community dedicated to Kohana 2.3, built around maintaining documentation (since the official site already pulled the Doxygen docs, how long until they pull the documentation wiki?), creating new modules and generally working on preserving the Kohana 2.3 legacy. Would anyone be interested in being a part of this community?</p>
<p>I&#8217;d like to stress that I am in no way trying to insult the developers and maintainers of Kohana through this project. Their work has been absolutely amazing, but just as they forked from CodeIgnitor when they felt it was no longer serving their needs as developers, so now am I feeling that Kohana no longer serves my needs as a developer.</p>
<p>I&#8217;m setting the project up at <a title="Ko23 - Kohana 2.3 Community" href="http://ko23.net/">ko23.net</a>. I&#8217;ll begin adding some functionality such as forums and module hosting / rating.</p>
<div class="shr-publisher-634"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/09/kohana-2-x-community/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Iterative Development for Economy Calculator</title>
		<link>http://visual77.com/blog/2010/05/iterative-development-for-economy-calculator/</link>
		<comments>http://visual77.com/blog/2010/05/iterative-development-for-economy-calculator/#comments</comments>
		<pubDate>Wed, 19 May 2010 17:45:13 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[gaming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sc2build]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=605</guid>
		<description><![CDATA[This iterative build was to test the economy calculator at different time intervals. I created an array to store information on 5 basic protoss units &#8211; Nexus, Pylon, Gateway, Probe and Zealot. I then wrote some quick calculators to accept a time, in seconds, and return the amount of minerals available at that time. The [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>This <a href="http://sc2build.com/id/process/20100519-1/">iterative build</a> was to test the economy calculator at different time intervals. I created an array to store information on 5 basic protoss units &#8211; Nexus, Pylon, Gateway, Probe and Zealot. I then wrote some quick calculators to accept a time, in seconds, and return the amount of minerals available at that time. The display is fairly minimal, just showing economy, but various units and builds were constructed at certain times.</p>
<p>The calculation is based on finding out how many probes exist at this time, how long they have existed, and multiplying that by 5/6. 5/6 is the number of minerals gathered per second per harvester (before saturation, at least). Once I have found the total minerals gathered, I get a list of all units that have begun construction at that time and subtract it from the total and return it.</p>
<p>The formula for calculating wealth seems okay, but the initial array contained far more data than I ended up using and the formulas were a bit too hard coded. Things like MULE and Chrono Boost are not being accounted for, and supply count is ignored as well.</p>
<p>I like the idea of a function being passed a time value and returning a snapshot of the build status at that time, and the array storing the build information also containing when each item was started. This system would fairly easily allow new commands to be inserted mid way through the build.</p>
<p>I definitely need to make the calclations more dynamic, though. I&#8217;m also still unsure of how to handle the starting Nexus and 5 Probes. This system puts the build time at -100 and -17, respectively, and always adds 700 minerals to the mineral count.</p>
<p>All in all, this iteration did show some interesting ideas, particularly with where to store data on all of the units. I ended up sliding it in as an array inside the build class, but that seems impractical. I should probably set a race as a class, units as a class, buildings as a class and special abilities as a class. My next experimentation will involve testing those methods for viability.</p>
<div class="shr-publisher-605"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/05/iterative-development-for-economy-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StarCraft II Build Order Calculator</title>
		<link>http://visual77.com/blog/2010/05/starcraft-ii-build-order-calculator/</link>
		<comments>http://visual77.com/blog/2010/05/starcraft-ii-build-order-calculator/#comments</comments>
		<pubDate>Wed, 19 May 2010 04:27:08 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[gaming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sc2build]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[starcraft]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=602</guid>
		<description><![CDATA[I&#8217;ve recently begun work on a new project that should see the light of day in time for StarCraft II to launch on July 27. The project, being hosted over at http://sc2build.com, is the StarCraft II Build Order Calculator. The project aims to take the ease of use and share-friendly nature of World of Warcraft [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>I&#8217;ve recently begun work on a new project that should see the light of day in time for StarCraft II to launch on July 27. The project, being hosted over at http://sc2build.com, is the StarCraft II Build Order Calculator. The project aims to take the ease of use and share-friendly nature of World of Warcraft talent calculators and apply it to StarCraft II build orders.</p>
<p>The project is just beginning the iterative development phase, with some small scale tests of single aspects of the system. I began writing my notes on the site in plain text, but it quickly became apparent that I will have enough notes to require a full fledged blog.</p>
<p>Expect to see a flood of posts in the coming days as I think aloud on how to build this system and test various methods of implementation. I will be building it through iterative development, and as such there will be many micro tests in the coming weeks of single aspects of the system.</p>
<p>The first test that has already been pondered upon and attempted once is how to store the build order data in a URI without that URI becoming ungainly in length. You can see my <a href="http://sc2build.com/id/parse/20100518-1.php">notes on that test</a> and see a <a href="http://sc2build.com/id/parse/20100518-1a.php?build=PZZZZ1ZZZ3">sample of this one attempt</a> in the iterative development section of that site.</p>
<div class="shr-publisher-602"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/05/starcraft-ii-build-order-calculator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up dynamic themes on Kohana</title>
		<link>http://visual77.com/blog/2010/04/kohana-dynamic-theme/</link>
		<comments>http://visual77.com/blog/2010/04/kohana-dynamic-theme/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 18:43:22 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=584</guid>
		<description><![CDATA[It&#8217;s been a little over six months since I first began to use Kohana framework for all PHP development, and I thoroughly love the system. The only issue I&#8217;ve had with Kohana is the lack of built in, intuitive support for dynamic themes. I was unable to find an easy method to set up a [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>It&#8217;s been a little over six months since I first began to use <a href="http://visual77.com/blog/tag/kohana">Kohana</a> framework for all <a href="http://visual77.com/blog/tag/php">PHP</a> development, and I thoroughly love the system. The only issue I&#8217;ve had with Kohana is the lack of built in, intuitive support for dynamic themes. I was unable to find an easy method to set up a theme that automatically wraps itself around all pages, while remaining dynamic enough to change certain elements on a page to page basis.</p>
<p>Over the past few days, I have been exploring methods to do this, with the following requirements:</p>
<ul>
<li>Keep <em>all </em>theme files separate from the application</li>
<li>Require <em>no</em> changes to existing controllers and views to implement or change a theme</li>
<li>Allow multiple applications on the same Kohana build to use the same theme</li>
<li>Provide support for cascading themes</li>
</ul>
<p>After a few failed attempts, I have <a href="http://visual77.com/blog/tag/tutorial">found a solution</a> that covers all four requirements and is pretty easy to implement. Of course, it is easier to implement this from the start, but if you have an existing Kohana site, it shouldn&#8217;t be too difficult to integrate this theming setup into the site. <strong>The concept of the theme is simple: create a theme as a module and then  use hooks to implement the theme elements as appropriate.</strong></p>
<p><span id="more-584"></span></p>
<h3>Step 1 &#8211; Enable hooks</h3>
<p>Without hooks, this theming set up won&#8217;t be able to execute at the proper time, and timing is essential. In order to enable hooks, <strong>open up application/config/config.php and change $config['enable_hooks'] to TRUE</strong>. With hooks enabled, all files within a hooks directory are included. This will be the starting point for inserting the theme content around the template.</p>
<h3>Step 2 &#8211; Create a theme folder</h3>
<p>One of my stated goals for the theme was to keep all theme files inside a single folder. This encapsulation allows for very easy modification, copying and replacing of themes. <strong>Make a folder called themes, and a subfolder named after the theme.</strong> This theme folder will operate just like a module folder, containing config, controllers, hooks, views, etc. My directory tree now looks like this:</p>
<pre>/httpdocs
    /application
    /modules
    /system
    /themes
        /visual77
            /config
            /controllers
            /css
            /hooks
            /images
            /views
    /index.php
</pre>
<h3>Step 3 &#8211; Add the theme folder to the list of enabled modules</h3>
<p>In order to use the theme folder just as a module folder, you need to register the folder in the list of modules being used by your application.<strong> Open up application/config/config.php and add the theme folder to your list of modules at the end.</strong> This lets Kohana make full use of the directory.</p>
<pre class="brush:php">$config['modules'] = array
(
    DOCROOT.'themes/visual77',
);</pre>
<h3><strong> </strong><strong>Step 4 &#8211; Create a hook for adding theme content</strong></h3>
<p>The most important step is creating a hook to add your theme content around your template content. You want to let your template proceed as normal, and after completion, add your theme data.</p>
<p>To create hooks in Kohana, just create a file inside your hooks directory. All files in that directory will be loaded automatically. For instance, <strong>make a file called theme.php inside themes/&lt;theme-name&gt;/hooks.</strong></p>
<p>In order to do the theming, the ideal hook to use is <em>system.post_controller</em>. The previous hook, <em>system.post_controller_constructor</em>, is before the controller has executed; the following hook, <em>system</em>.<em>send_headers</em>, is after <em>system.execute</em>, and therefore can&#8217;t manipulate the controller.</p>
<p>The goal is then to create a hook on <em>system.post_controller</em> and manipulate the controller to take the template data and move it within the overall theme. To access the controller, call Kohana::$instance and begin manipulating. My hook file looks like this:</p>
<pre class="brush:php">&lt;?php defined('SYSPATH') or die('No direct access allowed');

// set my hook up to execute at the appropriate time
event::add('system.post_controller', 'visual77_theme');

function visual77_theme() {
    // grab the controller
    $controller = Kohana::$instance;

    // pull the original template aside
    $temp = $controller-&gt;template;
    // replace the template with my theme template
    $controller-&gt;template = new View('visual77/index');
    // put the original template into the content section of my theme
    $controller-&gt;template-&gt;content = $temp;
    // free up some memory by unsetting the temp variable
    unset($temp);
}
</pre>
<h3><strong>Step 5 &#8211; Begin building the theme</strong></h3>
<p>Now that the hook is in place, the only thing left to do is build your theme. In my example, <strong>create an index.php file in themes/&lt;theme-name&gt;/views/&lt;theme-name&gt;</strong>. This index file will contain the wrapper HTML for your theme, leaving the original template to drop neatly inside the content section that you define. When you begin adding css and images, you can keep it inside the theme directory. The usual .htaccess restriction on modules only applies to the module directory, which is why I put the themes outside of the module folder.</p>
<p>While building, remember to keep all theme related content, such as views and controllers, inside the theme directory. This makes the theme ultra portable and easily removed. To change themes, just change the name of the theme from Step 3 to the new theme directory.</p>
<p>In a system like this, you can even cascade themes. One great example of cascading themes is including barebones files like CSS resets and jQuery files. On a current project, I have to build an internal client administration and an external company website. Both use certain shared libraries and both need a CSS reset and jQuery files. Using cascading themes and module sharing, I can blend these two sites very neatly. The file structure for this project looks like this:</p>
<pre>/httpdocs
    /internal_application
    /external_application
    /modules
        /shared_libraries
    /system
    /themes
        /internal_theme
        /external_theme
        /default
    /index.php
</pre>
<p>Both internal and external applications include modules/shared_libraries and themes/default. However, internal_application also includes themes/internal_theme and external_application includes themes/external_theme. A switch statement in index.php dynamically switches the application based on the hostname. In the end, I  have two sites running smoothly in parallel on a single Kohana build.</p>
<h3>Final Thoughts</h3>
<p>Kohana is a fantastic system, but really needs better support for dynamic theming. In my build process for this theming pattern, I tried to emulate the wordpress theme convention, where all theme files are kept clustered and are easily swapped out for a new theme.</p>
<p>To see a full theme example, you can<strong> <a href="http://visual77.com/blog/wp-content/uploads/2010/04/visual77.zip">download my Sample Kohana Theme</a></strong> and then modify it to fit your needs. Just remember to enable hooks and include this theme as a module!</p>
<div class="shr-publisher-584"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/04/kohana-dynamic-theme/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to flatten an array in PHP</title>
		<link>http://visual77.com/blog/2010/03/php-flatten-array/</link>
		<comments>http://visual77.com/blog/2010/03/php-flatten-array/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 23:57:18 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://visual77.com/blog/?p=577</guid>
		<description><![CDATA[In a recent Kohana project, I came across a somewhat odd PHP scenario &#8211; I had a multidimensional array that I needed to compress to a single dimensional array, but retaining all of the non array values. Basically, I need to make this change: Array ( to =&#62; Array ( 0 =&#62; stevep 1 =&#62; [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>In a recent <a title="Kohana articles" href="http://visual77.com/blog/tag/kohana">Kohana</a> project, I came across a somewhat odd <a title="PHP articles" href="http://visual77.com/blog/tag/php">PHP</a> scenario &#8211; I had a multidimensional array that I needed to compress to a single dimensional array, but retaining all of the non array values. Basically, I need to make this change:</p>
<pre>Array
    (
        to =&gt; Array
            (
                0 =&gt; stevep
                1 =&gt; bobw
            )
        bcc =&gt; Array
            (
                0 =&gt; paulj
            )
    )

Array
    (
        0 =&gt; stevep
        1 =&gt; bobw
        2 =&gt; paulj
    )
</pre>
<p>I looked around a bit for an existing PHP snippet to do just this, but they were all overly complex and used recursive callback functions. I had a feeling I could pull this off in a much more clean fashion. I toyed around a bit with the <a title="PHP:Array Functions" href="http://www.php.net/manual/en/ref.array.php" target="_blank">array functions</a> and the <a title="PHP:ArrayObject" href="http://www.php.net/manual/en/class.arrayobject.php" target="_blank">ArrayObject</a> library, and this is <a title="Tutorials written by Steve Phillips" href="http://visual77.com/blog/tag/tutorial">what I settled with</a>:</p>
<pre class="brush:php">$new_array = new ArrayObject();
array_walk_recursive($old_array, array($new_array, 'offsetSet'));
$flattened_array = array_keys($new_array-&gt;getArrayCopy());
</pre>
<p>The big drawback is the way <a title="PHP:ArrayObject::OffsetSet" href="http://www.php.net/manual/en/arrayobject.offsetset.php" target="_blank">ArrayObect::offsetSet()</a> accepts its parameters, compared to how <a title="PHP:array_walk_recursive" href="http://php.net/manual/en/function.array-walk-recursive.php" target="_blank">array_walk_recursive()</a> sends the callback parameters; they are reversed.  This causes the values to become keys, which has the effect of canceling out duplicate values. If your script needs duplicate values to remain intact, then this solution won&#8217;t work for you. Otherwise, it should work out just fine.</p>
<div class="shr-publisher-577"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/03/php-flatten-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with PHP and character encoding</title>
		<link>http://visual77.com/blog/2010/02/dealing-with-php-and-character-encoding/</link>
		<comments>http://visual77.com/blog/2010/02/dealing-with-php-and-character-encoding/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 04:05:56 +0000</pubDate>
		<dc:creator>visual77</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.visual77.com/blog/?p=567</guid>
		<description><![CDATA[How many times have you been presented with a character encoding glitch on a PHP site that you thought was working properly? You finished the site months ago with no issues, but now you are being told some weird character is showing up on that page? Chances are, that character is either Ã, Â or [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><p>How many times have you been presented with a character encoding glitch on a <a title="More PHP related articles" href="http://visual77.com/blog/tag/php">PHP</a> site that you thought was working properly? You finished the site months ago with no issues, but now you are being told some weird character is showing up on that page? Chances are, that character is either Ã, Â or Ä, possibly followed by some other random character. If I&#8217;m right, keep reading. If not, I offer my deepest condolences, for you are knee deep in a character encoding issue that I cannot help you with.</p>
<p>So what is it that causes that Ã to show up? In short &#8211; you have UTF-8 encoded data set to display as ISO-8859-1. But the more important question is how to prevent this from happening in the future. The easy answer to that &#8211; store all data in the same format as the final display. Convert the encoding as soon as you receive the data, either through an input field, reading a file or any other method. Don&#8217;t put anything in your <a title="MySQL related articles" href="http://visual77.com/blog/tag/mysql">database</a> unless you are sure it is in the right format.</p>
<p>First, an introduction to the three important character encodings that you are likely to deal with &#8211; ASCII, UTF-8 and ISO-8859-1. Character encoding is, in a nutshell, the exact method that characters are stored and displayed by a computer. Since computers only deal in binary, there must be some way to convert from binary into a character. Character encodings come in two flavors (at least, two flavors I&#8217;ll be discussing) &#8211; single byte and multi byte encodings. Single byte encodings, such as ASCII and ISO-8859-1, use a single byte to represent a character. For instance, the letter &#8220;M&#8221; in ASCII is represented as 0x4D, whereas the number 4 is 0&#215;34.</p>
<p>A single byte is limited to only 256 possible values, which rapidly becomes a limitation when you want to use characters not typically seen in English, such as &#8220;ç&#8221; or &#8220;ß&#8221;, and when you begin thinking about Asian languages, you can quickly see there simply isn&#8217;t room for all characters. Multi byte encodings use one or more bytes to represent a character. Each byte still only has 256 possibilities, but 2 bytes have 65,536 possibilities. But, what if there is confusion as to whether or not you are using single or multi byte encoding? Is that short string &#8220;0x3C 0xA5&#8243; supposed to be the UTF-8 character å or the ISO-8859-1 string ÃÑ? And there we are &#8211; a sudden bug has shown up.</p>
<p>ASCII is the oldest of the three and the most basic. The ASCII character set started out as just 128 characters, and very English-centric. You can see that the basic <a title="ASCII table" href="http://www.asciitable.com/">ASCII table</a> is very restricted to the English speaking world. The extended ASCII table goes off into some weird directions and is rarely used. The full ASCII table is only 256 characters, and thus fits neatly into a single byte, and so it is a single byte encoding.</p>
<p><a title="ISO-8859-1 character listing" href="http://www.pemberley.com/janeinfo/latin1.html">ISO-8859-1</a> is also a single byte encoding, but you can see that it is a bit better in the extended range to support many Latin based languages. Unlike ASCII, ISO-8859-1 can handle the majority of Latin based languages without too much issue. It fails when you go outside of the Latin based languages, however.</p>
<p>The third character encoding is <a title="UTF-8 character table" href="http://www.utf8-chartable.de/unicode-utf8-table.pl">UTF-8</a>, which is designed to support over 1.1 million characters, more than enough for all existing languages (and a few dead ones). Unlike ASCII and ISO-8859-1, UTF-8 is not limited to a single byte, but can vary between 1 and 4 bytes, depending on the character being used.</p>
<p>One thing to take note of is that the first 128 characters of all three encodings are identical. This is why a character encoding issue on an English website can take so long to spot. You can go months not knowing that you have a character encoding issue because the only characters you used were the same in all 3 encodings &#8211; 0x4D is an M in ASCII, UTF-8 and ISO-8859-1.</p>
<p><strong>On to the meat of this article &#8211; dealing with character encodings in PHP. Namely, how to detect and convert encodings.</strong></p>
<p>The magic bullet of dealing with character encodings in PHP can be summed up in three functions &#8211; <a title="PHP documentation" href="http://php.net/mb_detect_encoding" target="_blank">mb_detect_encoding()</a>, <a title="PHP documentation" href="http://php.net/mb_detect_order" target="_blank">mb_detect_order()</a> and <a title="PHP documentation" href="http://php.net/iconv" target="_blank">iconv()</a>. The mb libraries are designed for working with multibyte languages and iconv is a function to convert from one encoding type to another. One nonobvious restriction to the multibyte languages is the lack of native support for ISO-8859-1, since that is a single byte language. mb_detect_order() can be used to specify the order of encodings to scan when attempting to detect an encoding on a string.</p>
<p>The basics of dealing with character encoding conversion in PHP is a simple three step process:</p>
<ol>
<li>Set the encoding types to scan (ASCII, UTF-8, ISO-8859-1). Luckily, this only has to be done once.</li>
<li>Identify the encoding of the string to convert.</li>
<li>Convert to the desired encoding type (I prefer UTF-8).</li>
</ol>
<p>But, let&#8217;s cut to the crap. Sample code!</p>
<pre class="brush:php">// tell the multibyte library which encodings to use
mb_detect_order('ASCII, UTF-8, ISO-8859-1');

// tell the browser that we are using UTF-8
header('content-type: text/plain; charset=UTF-8');

$string = "Fün wîth èñcøding!";

// UTF string displays properly
echo $string . "\r\n";

// convert to ISO-8859-1, which will confuse the browser
$string = iconv(
    mb_detect_encoding($string),
    'ISO-8859-1',
    $string
);
echo $string . "\r\n";

// convert back to UTF-8, which the browser understands
$string = iconv(
    mb_detect_encoding($string),
    'UTF-8',
    $string
);
echo $string . "\r\n";
</pre>
<div class="shr-publisher-567"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://visual77.com/blog/2010/02/dealing-with-php-and-character-encoding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
