<?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>Steve&#039;s Blog &#187; PHP</title>
	<atom:link href="http://crindigo.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://crindigo.com/blog</link>
	<description>Escapades of a web programmer</description>
	<lastBuildDate>Thu, 24 Jun 2010 00:33:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Ancient Image Class</title>
		<link>http://crindigo.com/blog/2010/06/ancient-image-class/</link>
		<comments>http://crindigo.com/blog/2010/06/ancient-image-class/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 01:33:19 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=81</guid>
		<description><![CDATA[This is a really old image library/class thing I wrote back in Summer 2006 while working with Jeremy and his company. I believe it was originally written in PHP4 and updated to PHP5 a month or two after the original &#8230; <a href="http://crindigo.com/blog/2010/06/ancient-image-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a really old image library/class thing I wrote back in Summer 2006 while working with <a href="http://jeremyprivett.com/">Jeremy</a> and his company. I believe it was originally written in PHP4 and updated to PHP5 a month or two after the original was written. There are some features, like drawing rotated images/ellipses, that were commented away due to them not working on PHP4, but may work now if someone dares to try. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  The comments are fairly plentiful, and I&#8217;m feeling lazy, so it shouldn&#8217;t need a manual to get started (besides, I haven&#8217;t used it in years either).</p>
<p>The code is located at <a href="http://gist.github.com/429474">http://gist.github.com/429474</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/06/ancient-image-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wildfire Log Adapter for Solar</title>
		<link>http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/</link>
		<comments>http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/#comments</comments>
		<pubDate>Sat, 29 May 2010 05:25:59 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[crindigan]]></category>
		<category><![CDATA[solar]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=74</guid>
		<description><![CDATA[While doing some more development for Crindigan, I figured I should be looking for a better way to show debug information than putting it in the page footer, so I looked at FirePHP. Unfortunately the Firephp log adapter in Solar &#8230; <a href="http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While doing some more development for Crindigan, I figured I should be looking for a better way to show debug information than putting it in the page footer, so I looked at FirePHP. Unfortunately the Firephp log adapter in <a href="http://solarphp.com/">Solar</a> was out of date, so I wrote a quick adapter that uses the newer Wildfire protocol.</p>
<pre class="brush: php;">
/**
 * Log adapter that works with the latest FirePHP version
 * (probably not FireConsole though, whenever it's released).
 *
 * @package Crindigan
 * @author Steven Harris
 * @license http://opensource.org/licenses/bsd-license.php BSD
 * @version $Id$
 */
class Rpg_Log_Adapter_Wildfire extends Solar_Log_Adapter {

    /**
     * Default configuration values.
     *
     * @config string|array events The event types this instance
     *   should recognize; a comma-separated string of events, or
     *   a sequential array.  Default is all events ('*').
     *
     * @config dependency response A Solar_Http_Response dependency injection.
     *
     * @var array
     *
     */
    protected $_Rpg_Log_Adapter_Wildfire = array(
        'events'   =&gt; '*',
        'response' =&gt; 'response',
    );

    /**
     * The Solar_Http_Response where headers will be sent.
     *
     * @var Solar_Http_Response
     */
    protected $_response;

    /**
     * The Solar_Json instance used to encode JSON for Wildfire.
     *
     * @var Solar_Json
     */
    protected $_json;

    /**
     * Wildfire header index to keep headers in sequential order.
     *
     * @var int
     */
    protected $_index = 0;

    /**
     * Post-construction tasks. Sets up the response, JSON, and default Wildfire headers.
     */
    protected function _postConstruct() {
        parent::_postConstruct();

        $this-&gt;_response = Solar::dependency('Solar_Http_Response', $this-&gt;_config['response']);

        $this-&gt;_json = Solar::factory('Solar_Json');

		$this-&gt;_response-&gt;setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
        $this-&gt;_response-&gt;setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
        $this-&gt;_response-&gt;setHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
    }

    /**
     * Writes the log message to FirePHP.
     *
     * @param  string $class Class name.
     * @param  string $event Event name.
     * @param  mixed  $descr Log data. Any data type should work, assuming it can be encoded as JSON.
     * @return bool Always true.
     */
    protected function _save($class, $event, $descr) {
    	$meta = array();
    	$meta['Type']  = 'LOG';
    	$meta['Label'] = &quot;$class-$event&quot;;

    	$data = $this-&gt;_json-&gt;encode(array($meta, $descr));
    	$len  = strlen($data);

		if ( strlen($data) &lt;= 4990 ) {
			$this-&gt;_index++;
			$this-&gt;_response-&gt;setHeader(&quot;X-Wf-1-1-1-{$this-&gt;_index}&quot;, &quot;$len|$data|&quot;);
		} else {
			$chunks = chunk_split($data, 4990, &quot;\n&quot;);
			$parts = explode(&quot;\n&quot;, $chunks);
            $num_parts = count($parts);
            for ( $i = 0; $i &lt; $num_parts; $i++ ) {
				$this-&gt;_index++;
				$this-&gt;_response-&gt;setHeader(&quot;X-Wf-1-1-1-{$this-&gt;_index}&quot;,
					($i == 0 ? $len : '') . &quot;|{$parts[$i]}|&quot; . (($i == $num_parts - 1) ? '' : '\\'));
            }
        }

        return true;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pwiff Update</title>
		<link>http://crindigo.com/blog/2010/02/pwiff-update/</link>
		<comments>http://crindigo.com/blog/2010/02/pwiff-update/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 05:36:36 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pwiff]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=69</guid>
		<description><![CDATA[I just committed a simple Movie and Encoder class, so making a blank movie is now far easier to understand. At least now you don&#8217;t have to calculate the file length by hand. $env = new Pwiff_Environment; $env-&#62;setSwfVersion(10); $movie = &#8230; <a href="http://crindigo.com/blog/2010/02/pwiff-update/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just committed a simple Movie and Encoder class, so making a blank movie is now far easier to understand. At least now you don&#8217;t have to calculate the file length by hand. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<pre class="brush: php;">
$env = new Pwiff_Environment;
$env-&gt;setSwfVersion(10);

$movie = new Pwiff_Movie($env);
$movie-&gt;setFrameSize(100, 100);
$movie-&gt;setFrameRate(0);

$enc = new Pwiff_Encoder($movie, new Pwiff_Output_File('test.swf'));
$enc-&gt;encode();
</pre>
<p>The first step is to define an environment, which creates a context for encoding (and later decoding). By setting the version, certain tags or tag attributes could be ignored when reading or writing, if they are in a higher version than what you set. Then, you define a movie object, and set some of its properties, like the frame size and frame rate. After that, you would do more fancy things (when they get written, though you can addTag() with it right now). Finally, set up an encoder, passing the movie and output objects, and call encode(), which will write it with the given output instance (in this case, to the file test.swf).</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/pwiff-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pwiff Source Released</title>
		<link>http://crindigo.com/blog/2010/02/pwiff-source-released/</link>
		<comments>http://crindigo.com/blog/2010/02/pwiff-source-released/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 04:28:05 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pwiff]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=66</guid>
		<description><![CDATA[Today, I was able to get Pwiff to create a &#8220;blank&#8221; SWF file, meaning a header, a FileAttributes tag, and an End tag. As a result, I decided to start a Google Code project for it, and host the files &#8230; <a href="http://crindigo.com/blog/2010/02/pwiff-source-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today, I was able to get Pwiff to create a &#8220;blank&#8221; SWF file, meaning a header, a FileAttributes tag, and an End tag. As a result, I decided to start a Google Code project for it, and host the files there instead of my private subversion location. It&#8217;s very bare bones right now, as you can see from the following example that created the 25-byte file:</p>
<pre class="brush: php;">
$env = new Pwiff_Environment;
$env-&gt;setSwfVersion(10);

$out = new Pwiff_Output_File('test.swf');

$h = new Pwiff_Record_Header(false, 10, 25, new Pwiff_Record_Rect(0, 100, 0, 100), 0, 0);
$f = new Pwiff_Tag_FileAttributes($env);
$e = new Pwiff_Tag_End($env);

$h-&gt;write($out);
$f-&gt;write($out);
$e-&gt;write($out);
</pre>
<p>So yeah, it definitely needs some helper classes to be easier to use. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' />  Right now it&#8217;s pretty much just raw record/tag classes. The resulting SWF file is located <a href="/stuff/test.swf">here</a>.</p>
<p><a href="http://code.google.com/p/pwiff/">Pwiff @ Google Code</a><br />
<a href="http://ohloh.net/p/pwiff">Pwiff @ Ohloh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/pwiff-source-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NextShout is now Free</title>
		<link>http://crindigo.com/blog/2010/02/nextshout-is-now-free/</link>
		<comments>http://crindigo.com/blog/2010/02/nextshout-is-now-free/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 04:00:03 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[nextshout]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=63</guid>
		<description><![CDATA[NextShout was a commercial shoutbox product I released two or three years ago, for the vBulletin forum software. Its bandwidth consumption is far lower than any competing products, due to its use of efficient JSON and only sending information deltas, &#8230; <a href="http://crindigo.com/blog/2010/02/nextshout-is-now-free/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>NextShout was a commercial shoutbox product I released two or three years ago, for the vBulletin forum software. Its bandwidth consumption is far lower than any competing products, due to its use of efficient JSON and only sending information deltas, rather than completely refreshing entire blocks of HTML. Other features include a modular command system, multiple channels, automatic pruning and logging (configurable per channel), and new post/thread notices. It requires PHP 5.1.4, and at least vBulletin 3.6.9 (currently unavailable for 4.x).</p>
<p>Find more information and the download <a href="/nextshout/">at its website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/nextshout-is-now-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Pwiff</title>
		<link>http://crindigo.com/blog/2010/02/introducing-pwiff/</link>
		<comments>http://crindigo.com/blog/2010/02/introducing-pwiff/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 05:36:32 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pwiff]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=59</guid>
		<description><![CDATA[Considering I&#8217;ve reached a small milestone in the project, I figured I would write a post explaining what I&#8217;ve been up to. My previous entry relates to this, as at the time I was experimenting with writing a class to &#8230; <a href="http://crindigo.com/blog/2010/02/introducing-pwiff/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Considering I&#8217;ve reached a small milestone in the project, I figured I would write a post explaining what I&#8217;ve been up to. My previous entry relates to this, as at the time I was experimenting with writing a class to encode binary data into a stream of bits. Float information was important, as the class needed to support half-precision floating point numbers, which standard PHP cannot do.</p>
<p>If the name of the project didn&#8217;t give it away, I am writing an SWF output (possibly input, later) library using only PHP, without the need for something like ext/ming or swflib. The name seems pretty unoriginal &#8211; SWF is pronounced <i>swiff</i>, so I put a P in there for PHP <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> . The last project which attempted this, <a href="http://sf.net/projects/freemovie/">FreeMovie</a>, has not been updated in more than five years, was written in PHP4, and crammed into a few large files. This one is written using the PHP5 object model, and will hopefully be modular enough to extend upon as the SWF specification continues to grow.</p>
<p>Currently, there is a class for writing out the raw datatypes, and a set of classes for the current SWF records (RGB, RGBA, ARGB, LanguageCode, Matrix, Rect, CXForm, and CXFormWithAlpha). I have other issues/work occupying my time at the moment, but after I get back into this, I plan on starting a Google Code project for it once it can actually encode a full SWF file.</p>
<p>Until next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/introducing-pwiff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting Information from Floats</title>
		<link>http://crindigo.com/blog/2010/01/extracting-information-from-floats/</link>
		<comments>http://crindigo.com/blog/2010/01/extracting-information-from-floats/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 03:34:58 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=54</guid>
		<description><![CDATA[I was tinkering around with working in binary again, for a project I may or may not follow through on &#8211; still deciding. Along the way I was dealing with floating point numbers, and how to work with their individual &#8230; <a href="http://crindigo.com/blog/2010/01/extracting-information-from-floats/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was tinkering around with working in binary again, for a project I may or may not follow through on &#8211; still deciding. Along the way I was dealing with floating point numbers, and how to work with their individual bits in PHP. It&#8217;s definitely not as nice as in C, where you can just typecast into the raw binary representation. Unless there&#8217;s a better way I haven&#8217;t seen, you have to pack() a float, then unpack() it as an unsigned int, before you can use bitwise operators on it to pick out information.</p>
<pre class="brush: php;">
/**
 * Takes a single-precision floating point number, and returns it as a
 * sequence of bits in the form of an unsigned integer.
 *
 * @param  float $float
 * @return int
 */
function floatToIntBits($float)
{
	$s = unpack('Vval', pack('f', $float));
	return $s['val'];
}

/**
 * Takes a sequence of bits representing a float in the form of an unsigned
 * integer, and returns an associative array of information about the float.
 *
 * The returned array has the keys:
 * - sign: 0 if positive, 1 if negative
 * - exp:  exponent, with 127 exponent bias applied
 * - mant: decoded mantissa
 *
 * Using these you can reconstruct the float with (1 - 2*sign) * mant * 2^exp
 *
 * @param  int $bits
 * @return array
 */
function floatInfo($bits)
{
	$exponent = ($bits &amp; 0x7f800000) &gt;&gt; 23;
	$mantissa = $bits &amp; 0x7fffff;

	// if the exponent is nonzero, the mantissa gets a leading bit
	if ($exponent !== 0) {
		$mantissa |= 1 &lt;&lt; 23;
	}

	// decode the mantissa
	// bit 23 = 1.0
	// bit 22 = 0.5
	// bit 21 = 0.25
	// etc
	$decoded = 0;
	for ($i = 23; $i &gt;= 0; $i--) {
		if (($mantissa &gt;&gt; $i) &amp; 1) {
			$decoded += pow(2, $i - 23);
		}
	}

	return array(
		// sign would otherwise be -1 on 32bit systems
		'sign' =&gt; abs(($bits &amp; 0x80000000) &gt;&gt; 31),
		'exp'  =&gt; $exponent - 127,
		'mant' =&gt; $decoded,
	);
}

$bits = floatToIntBits(25.0);
var_dump(floatInfo($bits));
// array(3) {
//   [&quot;sign&quot;]=&gt;
//   int(0)
//   [&quot;exp&quot;]=&gt;
//   int(4)
//   [&quot;mant&quot;]=&gt;
//   float(1.5625)
// }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/01/extracting-information-from-floats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crindigan: An Introduction</title>
		<link>http://crindigo.com/blog/2009/12/crindigan-an-introduction/</link>
		<comments>http://crindigo.com/blog/2009/12/crindigan-an-introduction/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 01:12:36 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[crindigan]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=48</guid>
		<description><![CDATA[This entry is meant to quickly describe what Crindigan is, and what led to its creation. As the description on Google Code states, it is basically a web-based role playing game, played through a user&#8217;s browser using standard technologies like &#8230; <a href="http://crindigo.com/blog/2009/12/crindigan-an-introduction/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This entry is meant to quickly describe what Crindigan is, and what led to its creation.</p>
<p>As the description on Google Code states, it is basically a web-based role playing game, played through a user&#8217;s browser using standard technologies like AJAX to enhance the experience. You create your first character, then spend artificial money to purchase new recruits, items, and equipment. You can organize the characters into multiple squads, then use those squads to explore the game world and fight enemies/other parties.</p>
<p>Crindigan is actually my third attempt at creating a web application like this. My first attempt started in the Fall of 2005, maybe six months after starting to learn PHP. Back then, I really had no knowledge of proper application design, and so it was a sloppy jumble of code based on the &#8220;RPG Creator System&#8221; program badly ported to an object-oriented architecture. It eventually died off after a few months, as it was a pain to look at.</p>
<p>My second attempt started a year after the first, in Fall 2006. This one lasted for over two years, with the last change happening in December 2008. It only worked with the vBulletin forum software, and in fact had portions of its architecture based on it, such as session and input handling. The RPG started out in PHP4, and went through some small rewrites and design changes, but nothing drastic. In the end, I had a 17,000 line codebase written with PHP5 features, that also included a couple thousand lines of JavaScript for fancy battle, equipment, and skill learning screens. Why did I abandon it? It was still running on the architecture I made in 2006, with a few hacks added on top of it for things like fancy URLs. There was no clear separation between the model and the view, and new features were becoming harder and more clumsy to add. At this point, I had two choices: continue adding hacks to the existing codebase, or rewrite it from scratch. Since I now had almost four years of programming experience, I opted for the rewrite, mainly as a test to see how far I progressed and whether or not I could finally make something maintainable.</p>
<p>And that&#8217;s how the Crindigan project came to fruition. Of course, it didn&#8217;t really have a name until this summer. Development has been slower than I would like, but at least I&#8217;m now feeling proud about the code I&#8217;m writing. From the start, I declared that PHP 5.2 would be a requirement, and I would force myself to follow the MVC design pattern, which has really helped to keep my code clean. Most of the work I&#8217;ve done has been on the framework rather than the application itself, though things like logging in were written, along with parts of the style. My next task is to rethink how I&#8217;m handling updates and inserts through the Model, such as making it a bit smarter but without overdoing it, as I&#8217;m not particularly interested in coding a full-blown ORM. After that comes a forms library, then finally I can get to the application itself.</p>
<p>See you next article!</p>
<p><a href="http://code.google.com/p/crindigan/">Crindigan @ Google Code</a><br />
<a href="http://www.ohloh.net/p/crindigan">Crindigan @ Ohloh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/crindigan-an-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mariph</title>
		<link>http://crindigo.com/blog/2009/12/mariph/</link>
		<comments>http://crindigo.com/blog/2009/12/mariph/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 00:44:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[mariph]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=42</guid>
		<description><![CDATA[Mariph is a collection of a few classes that can read a subset of Ruby&#8217;s Marshal format. I wrote it back when I worked with RPG Maker XP, and wanted to convert the marshalled data from that program into something &#8230; <a href="http://crindigo.com/blog/2009/12/mariph/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://crindigo.com/code/php/Mariph.phps">Mariph</a> is a collection of a few classes that can read a subset of Ruby&#8217;s <a href="http://ruby-doc.org/core/classes/Marshal.html">Marshal</a> format. I wrote it back when I worked with RPG Maker XP, and wanted to convert the marshalled data from that program into something I could read. In order to do it in Ruby, I would have had to recreate most of the module and class structure defined in RPG Maker, so I instead opted to write a reader in the language most familiar to me &#8211; PHP.</p>
<p>It does not support every feature built in to the marshal format, only the ones that I required at the time. This includes: nil, true, false, int, float, string, symbol, regexp (string), array, hash, object, and user. Hash types are returned as a Mariph_Hash, which is a simple representation of a hash table with arbitrary data for keys. Objects are returned as stdClass, with the property __mariphName set to the name of its Ruby counterpart class. User types look for a PHP class defined with the same name as the Ruby class, with any double colon replaced by a double underscore. It then statically calls the class&#8217;s rubyLoad() method, which should accept the raw data string as its only parameter, and return an instance of the class. See the Table class in the file for an example.</p>
<p>The simplest way to parse in the data is by calling the mariph_load() shortcut function, which saves you the trouble of initializing both the tokenizer and interpreter classes. Each top-level element in the marshalled string becomes an element of the returned array.</p>
<pre class="brush: php; light: true;">$data = mariph_load($marshalString);</pre>
<p>The Mariph_Hash class has your standard get() and set() methods, along with a few convenience methods such as iterate(), count() (implementing Countable), each(), and reset().</p>
<pre class="brush: php;">
$hash = new Mariph_Hash(array('initial' =&gt; 'data'));
$hash-&gt;set(1, 'one');
$hash-&gt;set(2.5, 'two point five');
$hash-&gt;set('str', 'string');
$hash-&gt;set(array(1, 2, 3), 'one two three');

echo $hash-&gt;get(2.5); // &quot;two point five&quot;

// should work in PHP 5.3
$hash-&gt;iterate(function($value, $key) {
    echo 'Key: ';
    var_dump($key);
    echo 'Value: ';
    var_dump($value);
});

// Alternatively iterate with each()
while (list($key, $value) = $hash-&gt;each()) {
    // do whatever
}

// reset iteration position after using each()
$hash-&gt;reset();
</pre>
<p>I&#8217;m sure there&#8217;s much better ways for designing a custom hash class than what I wrote, but for me it gets the job done. Hopefully this small library can prove useful to some people. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/mariph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obfuscated Cake</title>
		<link>http://crindigo.com/blog/2009/12/obfuscated-cake/</link>
		<comments>http://crindigo.com/blog/2009/12/obfuscated-cake/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 03:52:25 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>
		<category><![CDATA[obfuscated]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=32</guid>
		<description><![CDATA[Almost forgot about this one. I wrote it back in June 2008 for Jeremy&#8217;s birthday since he was having a rough day. Like the heart, this is code in the shape of a birthday cake (well, as long as you &#8230; <a href="http://crindigo.com/blog/2009/12/obfuscated-cake/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Almost forgot about this one. I wrote it back in June 2008 for <a href="http://www.jeremyprivett.com/">Jeremy&#8217;s</a> birthday since he was having a rough day. Like the heart, this is code in the shape of a birthday cake (well, as long as you use some imagination <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> ) that draws a birthday cake. A chocolate one.</p>
<p>The code first draws the main cake rectangle. After that, it loops three times to draw the rectangles for the candlesticks, polygons for the flames, then orange circles with an alpha channel for the light. It finishes off with a series of lines whose lengths are determined by the sine function, used for the frosting.</p>
<p><a href="http://crindigo.com/birthday.php">Here&#8217;s the output.</a></p>
<pre class="brush: php;">
&lt;?php               header             ('Content'.
'-type:'.          'image/png'         );$f = 'im'.
'agecre'.          'atetrueco'.        'lor';$im=$f
(250,250);         $g='imagef'.        'illedrect'.
'angle';$g         ($im,10,120,        240,240,(630*
10000)+ 37         *100+44);for        ($i=0;$i&lt;3;$i
++){$x=60+         $i*60;$g($im        ,$x+2,50,$x+8,
120,0xeeeeee);$h=str_rot13('vzntrsvyyrqcbyltba');$h(
$im,array($x,50,$x+5,30,$x+10,50),3,0xc00000);$h($im,
array($x+2,50,$x+ 5,40,$x+8,50),3, 0xff8000);$h ($im,
array($x+3,50,$x+5,45,$x+7,50),3,0x0000ff);$el='ima'.
'gefilledellipse';$el($im,$x+5,40,40,40,0x48ffa000);}
$l='i'.'m'.'a'. 'g'.'e'.'l'.'in'.'e';$c=0xd0d0ff; for
($i=10;$i&lt;=240;$i++){$y=130+3* sin(($i-10)/2);$l($im,
$i,120,$i,$y,$c);}$p=strrev('egami').'png';$d='imag';
$d.='ede';$de='str';$d.=$de;$d.='oy';$p($im);$d($im);
</pre>
<p>Unobfuscated version:</p>
<pre class="brush: php;">
&lt;?php

header('Content-type: image/png');
$img = imageCreateTrueColor(250, 250);
imageFilledRectangle($img, 10, 120, 240, 240, 0x603000);

// loop through the 3 candles
for ($i = 0; $i &lt; 3; $i++) {
	$x = 60 + $i * 60;
	// candlestick, red flame, orange flame, blue flame, light
	imageFilledRectangle($img, $x + 2, 50, $x + 8, 120, 0xEEEEEE);
	imageFilledPolygon($img, array($x, 50, $x + 5, 30, $x + 10, 50), 3, 0xC00000);
	imageFilledPolygon($img, array($x + 2, 50, $x + 5, 40, $x + 8, 50), 3, 0xFF8000);
	imageFilledPolygon($img, array($x + 3, 50, $x + 5, 45, $x + 7, 50), 3, 0x0000FF);
	imageFilledEllipse($img, $x + 5, 40, 40, 40, 0x48FFA000);
}

// frosting
for ($i = 10; $i &lt;= 240; $i++) {
	$y = 130 + 3 * sin(($i - 10) / 2);
	imageLine($img, $i, 120, $i, $y, 0xD0D0FF);
}

imagePNG($img);
imageDestroy($img);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/obfuscated-cake/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
