<?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>blog.rhp.org</title>
	<atom:link href="http://blog.rhp.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rhp.org</link>
	<description>Programming, Geek Stuff, Trivia</description>
	<lastBuildDate>Sat, 26 Mar 2011 15:23:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Disabling TextMate&#8217;s auto-open of previous projects</title>
		<link>http://blog.rhp.org/2011/03/26/disabling-textmates-auto-open-of-previous-projects/</link>
		<comments>http://blog.rhp.org/2011/03/26/disabling-textmates-auto-open-of-previous-projects/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 15:21:09 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=86</guid>
		<description><![CDATA[defaults write -app TextMate OakDisableSessionRestore 1]]></description>
			<content:encoded><![CDATA[<p>defaults write -app TextMate OakDisableSessionRestore 1</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2011/03/26/disabling-textmates-auto-open-of-previous-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickie: Running a Controller action from a script in LightVC</title>
		<link>http://blog.rhp.org/2010/09/29/quickie-running-a-controller-action-from-a-script-in-lightvc/</link>
		<comments>http://blog.rhp.org/2010/09/29/quickie-running-a-controller-action-from-a-script-in-lightvc/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 22:10:45 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[shell scripts]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=84</guid>
		<description><![CDATA[Create scripts/test_action.php in your LVC app: http://pastie.org/1190014 Excitin&#8217;. Just be aware you&#8217;re running things from the command line, and the usual caveats with respect to running PHP CLI apply (superglobals, etc).]]></description>
			<content:encoded><![CDATA[<p>Create scripts/test_action.php in your LVC app:<br />
<a href="http://pastie.org/1190014">http://pastie.org/1190014</a></p>
<p>Excitin&#8217;.</p>
<p>Just be aware you&#8217;re running things from the command line, and the usual caveats with respect to running PHP CLI apply (superglobals, etc).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2010/09/29/quickie-running-a-controller-action-from-a-script-in-lightvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mass-op plugin for Colloquy</title>
		<link>http://blog.rhp.org/2010/08/29/mass-op-plugin-for-colloquy/</link>
		<comments>http://blog.rhp.org/2010/08/29/mass-op-plugin-for-colloquy/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 22:24:09 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=80</guid>
		<description><![CDATA[There&#8217;s no massop command in Colloquy, so here&#8217;s a javascript plugin that does it. Copy/paste the following as whatever.js in your ~/Application Support/Colloquy/PlugIns/ directory: function opNick&#40;nick, connection, view&#41; &#123; connection.sendRawMessage&#40;&#34;MODE &#34; + view.target&#40;&#41; + &#34; +o &#34; + nick&#41;; &#125; &#160; function massOp&#40;connection, view&#41; &#123; var members = view.chatMembers&#40;&#41;; var len = members.length; &#160; for [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s no massop command in Colloquy, so here&#8217;s a javascript plugin that does it.</p>
<p>Copy/paste the following as whatever.js in your ~/Application Support/Colloquy/PlugIns/ directory:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> opNick<span style="color: #009900;">&#40;</span>nick<span style="color: #339933;">,</span> connection<span style="color: #339933;">,</span> view<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	connection.<span style="color: #660066;">sendRawMessage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;MODE &quot;</span> <span style="color: #339933;">+</span> view.<span style="color: #660066;">target</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; +o &quot;</span> <span style="color: #339933;">+</span> nick<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> massOp<span style="color: #009900;">&#40;</span>connection<span style="color: #339933;">,</span> view<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> members <span style="color: #339933;">=</span> view.<span style="color: #660066;">chatMembers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> len <span style="color: #339933;">=</span> members.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>members<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">operator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			opNick<span style="color: #009900;">&#40;</span>members<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nickname</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> connection<span style="color: #339933;">,</span> view<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: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// process the command and return true if you handle it or false to pass on to another plugin</span>
<span style="color: #003366; font-weight: bold;">function</span> processUserCommand<span style="color: #009900;">&#40;</span> command<span style="color: #339933;">,</span> arguments<span style="color: #339933;">,</span> connection<span style="color: #339933;">,</span> view <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// return true if the command was handled or to prevent other plugins or Colloquy from handling it</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>command <span style="color: #339933;">==</span> <span style="color: #3366CC;">'mop'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		massOp<span style="color: #009900;">&#40;</span>connection<span style="color: #339933;">,</span> view<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2010/08/29/mass-op-plugin-for-colloquy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mysqli driver, prepared statements and geometry types</title>
		<link>http://blog.rhp.org/2010/08/23/mysqli-driver-prepared-statements-and-geometry-types/</link>
		<comments>http://blog.rhp.org/2010/08/23/mysqli-driver-prepared-statements-and-geometry-types/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 18:36:49 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=72</guid>
		<description><![CDATA[FYI: PHP Warning: mysqli_stmt_bind_result(): Server returned unknown type 255. Probably your client library is incompatible with the server version you use! Probably means you&#8217;re selecting a geometry type without calling AsText on it. Instead of SELECT place.location_point FROM place WHERE place.place_id = ? do: SELECT AsText&#40;place.location_point&#41; FROM place WHERE place.place_id Supposedly this is fixed in [...]]]></description>
			<content:encoded><![CDATA[<p>FYI:<br />
<code><br />
PHP Warning:  mysqli_stmt_bind_result(): Server returned unknown type 255. Probably your client library is incompatible with the server version you use!<br />
</code><br />
<br/><br />
Probably means you&#8217;re selecting a geometry type without calling AsText on it.<br />
Instead of</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
	place<span style="color: #66cc66;">.</span>location_point
<span style="color: #993333; font-weight: bold;">FROM</span>
	place
<span style="color: #993333; font-weight: bold;">WHERE</span>
	place<span style="color: #66cc66;">.</span>place_id <span style="color: #66cc66;">=</span> ?</pre></div></div>

<p>do:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
	AsText<span style="color: #66cc66;">&#40;</span>place<span style="color: #66cc66;">.</span>location_point<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
	place
<span style="color: #993333; font-weight: bold;">WHERE</span>
	place<span style="color: #66cc66;">.</span>place_id</pre></div></div>

<p>Supposedly this is fixed in PHP 5.3. That isn&#8217;t really useful information, nor is the snotty svn commit message to use mysqlnd.</p>
<p>See: <a href="http://www.mail-archive.com/php-bugs@lists.php.net/msg127837.html">http://www.mail-archive.com/php-bugs@lists.php.net/msg127837.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2010/08/23/mysqli-driver-prepared-statements-and-geometry-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A little TextMate black magic</title>
		<link>http://blog.rhp.org/2010/08/19/a-little-textmate-black-magic/</link>
		<comments>http://blog.rhp.org/2010/08/19/a-little-textmate-black-magic/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 01:47:09 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[shell scripts]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=66</guid>
		<description><![CDATA[I do most of my code editing in TextMate in OSX. However my current code environment consists of a CentOS VM running under parallels. I have my linux home directory mounted via SMB in OSX, but I like to do a lot of poking around on the files from the shell on the VM. So, [...]]]></description>
			<content:encoded><![CDATA[<p>I do most of my code editing in TextMate in OSX.</p>
<p>However my current code environment consists of a CentOS VM running under parallels. </p>
<p>I have my linux home directory mounted via SMB in OSX, but I like to do a lot of poking around on the files from the shell on the VM.</p>
<p>So, here&#8217;s a shell script to let me open files in TextMate from the VM:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/tcsh</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">f</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`pwd`</span>/$*&quot;</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">f</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$f</span>:s./home/pistole./Volumes/pistole/.&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> wrath open <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>TextMate.app <span style="color: #ff0000;">&quot;<span style="color: #007800;">$f</span>&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2010/08/19/a-little-textmate-black-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Controllers and Actions in LightVC</title>
		<link>http://blog.rhp.org/2009/08/25/tutorial-controllers-and-actions-in-lightvc/</link>
		<comments>http://blog.rhp.org/2009/08/25/tutorial-controllers-and-actions-in-lightvc/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 18:15:23 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[coughphp]]></category>
		<category><![CDATA[lightvc]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=41</guid>
		<description><![CDATA[In this tutorial, we continue to create an MVC application using the bare LightVC and CoughPHP distributions, focusing on Controllers and Views in LighVC. For this tutorial, you will need to have the skeleton application created in the previous article on combining CoughPHP and LightVC, as well as our database table and generated CoughPHP code. [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we continue to create an MVC application using the bare LightVC and CoughPHP distributions, focusing on Controllers and Views in LighVC.</p>
<p>For this tutorial, you will need to have the skeleton application created in the previous article <a href="http://blog.rhp.org/2009/04/10/creating-cough-models-for-our-coughphplightvc-application/">on combining CoughPHP and LightVC</a>, as well as our database table and generated CoughPHP code.<br />
<span id="more-41"></span></p>
<p>Step 1: Creating a new controller and action in LightVC.</p>
<p>Create a new file in controllers/ called post.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> PostController <span style="color: #000000; font-weight: bold;">extends</span> AppController
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> actionIndex<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>	
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This creates a new controller, page and a the default index action.</p>
<p>Now we need to create a view corresponding to the action.<br />
Create a folder in the views/ folder called post.<br />
Create a file in views/post/ called index.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>(Notice how the name for the folder corresponds to the lowercase name of the controller, and the name of the view corresponds to the lowercase name of the action)</p>
<p>Now if you&#8217;ve been following along the tutorial, navigate to <a href="http://cms.rhp.org/post/">http://cms.rhp.org/post/</a> and you should see the result of your work:<br />
<div id="attachment_42" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.rhp.org/wp-content/uploads/2009/08/2009-08-25_1208.png"><img src="http://blog.rhp.org/wp-content/uploads/2009/08/2009-08-25_1208-300x113.png" alt="New Action" title="New Action" width="300" height="113" class="size-medium wp-image-42" /></a><p class="wp-caption-text">New Action</p></div></p>
<p>This page is composited from several different parts.<br />
The outer shell comes from views/layouts/default.php<br />
The inner content comes from the view we just edited views/post/index.php<br />
The css resides in webroot/css/master.css</p>
<p>Let&#8217;s edit the layout to remove the congratulations messages:</p>

<div class="wp_syntax"><div class="code"><pre class="pre" style="font-family:monospace;">&lt;body&gt;
&nbsp;
	&lt;div id=&quot;header&quot;&gt;
		Welcome to cms.rhp.org
	&lt;/div&gt;
&nbsp;
	&lt;div id=&quot;content&quot;&gt;
		&lt;?php echo $layoutContent ?&gt;
	&lt;/div&gt;
&nbsp;
&lt;/body&gt;</pre></div></div>

<p>Reload the page, and see the changes.</p>
<p>Now let&#8217;s put that action we created to some use by listing all the posts we&#8217;ve got in the system.</p>
<p>Step 2: Listing Posts</p>
<p>The first thing we need to do is create a method on Post_Collection to load all the non-deleted posts:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadActive<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'
		SELECT
			*
		FROM
			post
		WHERE
			is_deleted = 0
		ORDER BY
			post.name
	'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadBySql</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: #009900;">&#125;</span></pre></div></div>

<p>This is pretty straightforward, some SQL to fetch all the posts which we then pass to the loadBySql method that Post_Collection inherits from CoughCollection. This will populate the collection with all the posts. Note that the order in which the rows are retrieved will be the order they are in in the collection (unless we sort the collection after the fact), so we set an ORDER BY in the SQL statement.</p>
<p>Now to use it:</p>
<p>Edit the actionIndex method to create an instance of Post_Collection, and populate it, and then pass it to the view:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> actionIndex<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>	
	<span style="color: #000088;">$posts</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Post_Collection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$posts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadActive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$posts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Again, a note on conventions the same way we&#8217;re going to be using the singular for table names and objects representing individual rows in the table, we&#8217;re going to use the plural for aggregates.</p>
<p>Now edit views/post/index.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;ul&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$posts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;li&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;</pre></div></div>

<p>Note that we call htmlentities on display to prevent any bad data in the db from messing up our page display.</p>
<p>Reload your index page, and if you&#8217;ve been following the tutorial, you should see the following:</p>
<p><a href="http://blog.rhp.org/wp-content/uploads/2009/08/2009-08-25_1238.png"><img src="http://blog.rhp.org/wp-content/uploads/2009/08/2009-08-25_1238-300x71.png" alt="Finished Page" title="Finished Page" width="300" height="71" class="alignnone size-medium wp-image-43" /></a></p>
<p>Congratulations, you are dynamically reading data out of the db and displaying it on your page!</p>
<p>Next time: viewing and editing posts! Creating new posts!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2009/08/25/tutorial-controllers-and-actions-in-lightvc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Hashing Axapta 3 compatible passwords from PHP</title>
		<link>http://blog.rhp.org/2009/08/21/hashing-axapta-3-compatible-passwords-from-php/</link>
		<comments>http://blog.rhp.org/2009/08/21/hashing-axapta-3-compatible-passwords-from-php/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 17:01:18 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[axapta]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=32</guid>
		<description><![CDATA[As an interlude from the CoughPHP, I present the following: The downside of working with legacy systems is that sometimes you find it necessary to work with existing data in ways that are completely arbitrary. The worst of all of these is password hashing. It is often the case that you have to maintain compatibility [...]]]></description>
			<content:encoded><![CDATA[<p>As an interlude from the CoughPHP, I present the following:<br />
<br/><br />
The downside of working with legacy systems is that sometimes you find it necessary to work with existing data in ways that are completely arbitrary. The worst of all of these is password hashing.<br />
<br/><br />
<span id="more-32"></span></p>
<p>It is often the case that you have to maintain compatibility with legacy passwords, and while you can replace the old algorithms going forward with a sensible schema, you still have to be able to validate against passwords stored in the old way.<br />
<br/><br />
So I present to you a way to hash passwords compatible with Axapta 3:<br />
<br/></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;PHP_INT_SIZE: &quot;</span> <span style="color: #339933;">.</span> PHP_INT_SIZE <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> str2int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0x015A4E35&quot;</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;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmpChar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_init</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0xff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0xFFFFFFFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_add</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_mul</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;8192&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0x0FFFFE000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_div_q</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;524288&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0x000001FFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_xor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_mul</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpChar</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;32&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0x01FE0&quot;</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;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_add</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_xor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmpChar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0xFFFFFFFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> int2code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$intCode</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$intCode</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">&quot;0xFFFFFFFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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;">$code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmpByte</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_intval</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_mod</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0x24&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;">$tmpByte</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$tmpByte</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$code</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;">$code</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$tmpByte</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_div_q</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_mul</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0x38E38E39&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_div_q</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0xFFFFFFFF00000000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;4294967296&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> cryptUserPass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$userName</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$tmpConst</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0xA59C29F1&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_xor</span><span style="color: #009900;">&#40;</span>str2Int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userName</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmpConst</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> int2Code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tmpConst</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_and</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">gmp_add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0x928379A1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmpCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0xFFFFFFFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">gmp_xor</span><span style="color: #009900;">&#40;</span>str2Int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmpConst</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$code</span> <span style="color: #339933;">.</span> Int2Code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span>cryptUserPass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hello'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jw02'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'0OYMDGB17QNP49'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Or if you have a 64-bit PHP binary:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;PHP_INT_SIZE: &quot;</span> <span style="color: #339933;">.</span> PHP_INT_SIZE <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> str2int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x015A4E35</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;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmpChar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xff</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x0FFFFE000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">19</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x000001FFF</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmpCode</span> ^ <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpChar</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x01FE0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span> ^ <span style="color: #000088;">$tmpChar</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> int2code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$intCode</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$intCode</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF</span><span style="color: #339933;">;</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;">$code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmpByte</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">%</span> <span style="color: #208080;">0x24</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpByte</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$tmpByte</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$code</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;">$code</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$tmpByte</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">*</span> <span style="color: #208080;">0x38E38E39</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF00000000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> cryptUserPass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$userName</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$tmpConst</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0xA59C29F1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> str2Int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userName</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> ^ <span style="color: #000088;">$tmpConst</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> int2Code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tmpConst</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #208080;">0x928379A1</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$tmpCode</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFFFFFFFF</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tmpCode</span> <span style="color: #339933;">=</span> str2Int<span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> ^ <span style="color: #000088;">$tmpConst</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$code</span> <span style="color: #339933;">.</span> Int2Code<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span>cryptUserPass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hello'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jw02'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'0OYMDGB17QNP49'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You probably don&#8217;t need this, but if you do, it&#8217;s a lifesaver.<br />
<br/><br />
Originally found <a href="http://axforum.info/forums/showthread.php?t=6684">in delphi</a>. In Russian.<br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2009/08/21/hashing-axapta-3-compatible-passwords-from-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Cough models for our CoughPHP/LightVC application</title>
		<link>http://blog.rhp.org/2009/04/10/creating-cough-models-for-our-coughphplightvc-application/</link>
		<comments>http://blog.rhp.org/2009/04/10/creating-cough-models-for-our-coughphplightvc-application/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 17:27:29 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[coughphp]]></category>
		<category><![CDATA[lightvc]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=18</guid>
		<description><![CDATA[In this tutorial, we continue to create an MVC application using the bare LightVC and CoughPHP distributions, focusing on creating working cough model classes and using them in the application, as well as best practices for different deployment environment files for LightVC applications, CoughPHP generation config, and suggested db schema patterns. For this tutorial, you [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we continue to create an MVC application using the bare LightVC and CoughPHP distributions, focusing on creating working cough model classes and using them in the application, as well as best practices for different deployment environment files for LightVC applications, CoughPHP generation config, and suggested db schema patterns.</p>
<p>For this tutorial, you will need to have the skeleton application created in the previous article <a href="http://blog.rhp.org/2009/02/16/combining-coughphp-and-lightvc/">on combining CoughPHP and LightVC</a>, as well as a working installation of MySQL. Installing and configuring MySQL is outside the scope of this tutorial, but there are many <a href="http://dev.mysql.com/downloads/">pre-packaged versions available</a>.<br />
<span id="more-18"></span></p>
<p>Step 1: Create our Post table<br />
	Actually step 0 is to create the database in mysql. For the purposes of this tutorial, we&#8217;re going to be using a database called &#8216;cms&#8217;, with a user also called &#8216;cms&#8217;. Note that unlike many ORMs, CoughPHP has no trouble with cross-database object relationships, so at a later point we may be using multiple databases for the purpose of organization.</p>
<pre>
		CREATE DATABASE IF NOT EXISTS `cms` ;
		GRANT ALL PRIVILEGES ON `cms` . * TO 'cms'@'localhost';
	</pre>
<p>	Now we&#8217;re going to create our sample Post table:</p>
<pre>
		CREATE TABLE `cms`.`post` (
		`post_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`name` VARCHAR( 255 ) NULL DEFAULT NULL ,
		`body` TEXT NULL DEFAULT NULL ,
		`is_deleted` TINYINT( 1 ) NOT NULL DEFAULT '0',
		`date_created` DATETIME NULL DEFAULT NULL ,
		`date_modified` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NULL DEFAULT NULL
		) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
	</pre>
<p>	A few notes on some of the conventions we will be using here:<br />
		* Singular table names:<br />
			Cough generates its objects names based on the table names and it would be confusing if the class representing a single row in the &#8216;posts&#8217; table was called Posts, and your aggregate object was called Posts_Collection.<br />
		* is_deleted column: in general, it is a common idea to do logical deletes rather than actually deleting data from the db, and an is_deleted flag is one of the simpler paradigms. In future articles we will go into more detail about logical deletions, the reasonings behind them and how CoughPHP can work with them most effectively.<br />
		* c_style_naming: This is just convention, deal with it.<br />
		* table_name_id primary key:  CoughPHP by default will look for joins to other tables by looking for columns named<br />
<table_name>_id. This can be configured, and joins can be manually specified, but we will take use the default for now.</p>
<p>Step 2: Create models directory, set up generate script, set up generator config:<br />
	Now that we have created a table to generate our objects from, we need to set up the CoughPHP generator to point at the right database, put the objects where we went them, etc.</p>
<p>	First, create a directory in the cms project to hold our generated classes:<br />
	<code><br />
		mkdir models<br />
	</code><br />
	Next, we&#8217;ll create a shell script that will generate the classes:<br />
	edit config/generate:</p>
<pre>
		#!/bin/sh
		../modules/coughphp/scripts/cough -g generator_config $@
	</pre>
<p>	and make it executable&#8221;<br />
	<code><br />
		chmod +x config/generate<br />
	</code><br />
	And create our base generator configs:<br />
	<code><br />
		mkdir config/generator_config<br />
		cp ../modules/coughphp/config_examples/default/*.php generator_config/<br />
	</code><br />
	Now to actually set up the generator configs. We&#8217;re going to tell it to put the generated classes into the models/ directory we just created.</p>
<p>	edit config/generator_config/cough_generator.inc.php and add the following line:</p>
<pre>
		$generated = dirname(dirname(dirname(__FILE__))) . '/models/';
	</pre>
<p>	Now we need to tell the generator the connection information we&#8217;ll be using, as well as which databases to generate objects for.<br />
	Edit config/generator_config/database_schema_generator.inc.php and change the $config array:</p>
<pre>
		$config = array(
			'dsn' => array(
				'host' => 'localhost',
				'user' => 'cms',
				'pass' => 'mypassword',
				'port' => 3306,
				'driver' => 'mysql'
			),

			'database_settings' => array(
				'include_databases_matching_regex' => '/cms/x',
				'exclude_databases_matching_regex' => '/(_bak$)|(^bak_)|(^temp_)/',
			),
		);
	</pre>
<p>Step 3: Generate<br />
	To generate the Cough objects:<br />
	<code><br />
		cd config<br />
		./generate<br />
	</code><br />
	You should get output similar to the following:</p>
<pre>
		Generating for ../config/generator_config
		=========================================
		Success writing 4 classes (220 lines) with 0 one-to-one relationships and 0 one-to-many relationships!
	</pre>
<p>	Now we only have 1 table, why is did it generating 4 classes?<br />
	For each table, Cough generates classes of two forms, a single and an aggregate. For each of these forms, it generates a base-class and if it doesn&#8217;t already exist, a sub-class.<br />
	This latter distinction is important. For a table called post, it will generate a Post_Generated class, which contains all the getters/setters/base CRUD logic/etc. It will also create an empty Post class for the developer to add functionality to. Similarly for the aggregate collections, it will create a Post_Colllection_Generated class and a Post_Collection class. Each time you re-run the generator, the *_Generated classes will be overwritten by the generator, but if the Post/Post_Collection classes already exist, they will be left untouched.</p>
<p>Step 4: App changes<br />
	Now that we have the models generated, we&#8217;ll need to modify the autoloader setClassPaths in config/application.php:</p>
<pre>
		Autoloader::setClassPaths(array(
			APP_PATH . 'classes/',
			APP_PATH . 'models/',
		));
	</pre>
<p>	Next we need to set up the application to include our database credentials. However, we might want to change database credentials between say the development and production versions of the application, so we&#8217;ll create a separate file with the credentials and include a symlink to it from inside application.php. That way when we deploy to production, we can just change the symlink.</p>
<p>	<code><br />
		mkdir config/environment<br />
	</code><br />
	Create a file config/environment/dev.php:</p>
<pre>
		&lt;?php
		// Setup database config
		CoughDatabaseFactory::addConfig(array(
			'adapter' => 'as',
			'driver' => 'mysql',
			'host' => '127.0.0.1',
			'user' => 'cms',
			'pass' => 'mypassword',
			'aliases' => array('cms'),
		));
		?&gt;
	</pre>
<p>	Now symlink the file:<br />
	<code><br />
		cd config/<br />
		ln -s environment/dev.php environment.php<br />
	</code></p>
<p>	Edit config/application.php and add the following lines before the line about loading routes:</p>
<pre>
	// Include env specific confs
	include('environment.php');
	</pre>
<p>Step 5: Test Cough<br />
	Congratulations, you&#8217;ve successfully set up CoughPHP! Let&#8217;s test it out:<br />
	We&#8217;re going to add some code to the view action in the page controller, just to create a Post object, set some fields on it and then save it to the db. Next time we&#8217;ll talk about pulling it back out, and really doing something with it, with collections and actually using the View/Controller parts of the MVC paradigm.</p>
<p>	For now, edit controllers/page.php and add the following to the actionPage method:</p>
<pre>
		$post = new Post();
		$post->setName('Test Post');
		$post->setBody('This is a test post.');
		$post->setDateCreated(date("Y-m-d H:i:s",time()));

		$post->save();
	</pre>
<p>	Now hit your http://cms.rhp.org or equivalent URL. If you get any error messages, make sure that all the CoughPHP classes are accessible by your apache user, make sure your config/application.php has the following lines in it:</p>
<pre>
		include(APP_PATH . 'modules/coughphp/load.inc.php');
		include(APP_PATH . 'modules/coughphp/as_database/load.inc.php');
	</pre>
<p>	And make sure your database is readable/writable by the user specified in your db configuration above.</p>
<p>	Given a lack of errors, check your database. You should see a row in the post table!</p>
<p>Next Time:<br />
	We&#8217;ll create a simple list of all posts in the db, create/edit/view actions, and more!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2009/04/10/creating-cough-models-for-our-coughphplightvc-application/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Combining CoughPHP and LightVC</title>
		<link>http://blog.rhp.org/2009/02/16/combining-coughphp-and-lightvc/</link>
		<comments>http://blog.rhp.org/2009/02/16/combining-coughphp-and-lightvc/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 10:15:30 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[coughphp]]></category>
		<category><![CDATA[lightvc]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=9</guid>
		<description><![CDATA[In this tutorial, we will be creating an MVC application using the bare LightVC and CoughPHP distributions. For the purposes of this tutorial, I will be working on my Macbook, with Apache 2. You may need to consult your documentation on your webserver to set up the server configs correctly. Step 1: Download the LightVC [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we will be creating an MVC application using the bare LightVC and CoughPHP distributions.<br />
<span id="more-9"></span><br />
For the purposes of this tutorial, I will be working on my Macbook, with Apache 2. You may need to consult your documentation on your webserver to set up the server configs correctly.</p>
<p>Step 1:<br />
	Download the <a href="http://lightvc.org">LightVC</a> and <a href="http://coughphp.com">CoughPHP</a> distribution files. </p>
<p>	I am using CoughPHP version 1.3.5 and LightVC 1.0.4 for this tutorial.</p>
<p>Step 2:<br />
	Unpack the LightVC and CoughPHP distributions.<br />
	I used the following command to unpack LightVC:<br />
	<code><br />
		cd ~/Documents/<br />
		mkdir Source<br />
		cd Source<br />
		unzip -d cms.rhp.org ~/Downloads/lightvc-1.0.4.zip<br />
	</code><br />
	And CoughPHP:<br />
	<code><br />
		cd ~/Documents/Source/cms.rhp.org<br />
		cd modules<br />
		tar -xzvf ~/Downloads/coughphp-1.3.5.tgz<br />
		mv coughphp-1.3.5 coughphp<br />
	</code></p>
<p>Step 3:<br />
	Prepare LightVC.<br />
	Upon unpacking the LightVC distribution, I noticed that unzip set the permissions wrong, so I had to do the following:<br />
	<code><br />
		cd ~/Documents/Source/cms.rhp.org<br />
		chmod -R a+r .<br />
		chmod a+x * webroot/* views/* modules/coughphp modules/coughphp/*<br />
	</code><br />
	In addition the autoloader will need a world writable tmp directory:<br />
	<code><br />
		cd ~/Documents/Source/cms.rhp.org<br />
		mkdir tmp<br />
		chmod 777 tmp<br />
	</code><br />
Step 4:<br />
	Edit your /etc/hosts file:<br />
	<code><br />
		sudo nano /etc/hosts<br />
	</code><br />
	(you will be prompted for your password)<br />
	Change the 127.0.0.1 line to look like</p>
<pre>
		127.0.0.1	localhost cms.rhp.org
	</pre>
<p>Step 5:<br />
	Edit your apache conf files and (re)start apache<br />
	<code><br />
		sudo nano /etc/apache2/httpd.conf<br />
	</code><br />
	Add the lines:</p>
<pre>
		&lt;Directory "/Users/pistole/Documents/Source/cms.rhp.org/webroot"&gt;
		    Options Indexes FollowSymLinks MultiViews

		    AllowOverride All

		    Order allow,deny
		    Allow from all

		&lt;/Directory&gt;
	</pre>
<p>	Replacing /Users/pistole/Documents/Source/cms.rhp.org/ with the path you installed LightVC into.<br />
	Then run<br />
	<code><br />
		sudo nano /etc/apache2/extra/httpd-vhosts.conf<br />
	</code><br />
	Add the lines:</p>
<pre>
		&lt;VirtualHost *:80&gt;
		    ServerAdmin pistole@rhp.org
		    DocumentRoot "/Users/pistole/Documents/Source/cms.rhp.org/webroot"
		    ServerName cms.rhp.org
		    ErrorLog "/private/var/log/apache2/www-error_log"
		    CustomLog "/private/var/log/apache2/www-access_log" common
		    AddType application/x-httpd-php .php .html
		&lt;/VirtualHost&gt;
	</pre>
<p>	Again, setting the right path. Also set the ServerAdmin to your email address.<br />
	Now start apache:<br />
	<code><br />
		sudo /usr/sbin/apachectl start<br />
	</code><br />
	If that doesn&#8217;t work, try:<br />
	<code><br />
		sudo /usr/sbin/apachectl restart<br />
	</code><br />
Step 6:<br />
	Configure the Autoloader<br />
	edit cms.rhp.org/config/application.php and replace the following lines:</p>
<pre>
		// Lvc doesn't autoload the AppController, so we have to do it: (this also means we can put it anywhere)
		include(APP_PATH . 'classes/AppController.class.php');
		include(APP_PATH . 'classes/AppView.class.php');
	</pre>
<p>	with:</p>
<pre>
		include(APP_PATH . 'modules/coughphp/extras/Autoloader.class.php');
		Autoloader::setCacheFilePath(APP_PATH . 'tmp/class_path_cache.txt');
		Autoloader::excludeFolderNamesMatchingRegex('/^CVS|\..*$/');
		Autoloader::setClassPaths(array(
			APP_PATH . 'classes/',
		));
		spl_autoload_register(array('Autoloader', 'loadClass'));
	</pre>
<p>	This will load any classes named *.class.php in your cms.rhp.org/classes/ directory automagically, including the aforementioned AppController and AppView classes.<br />
Step 7:<br />
	Load the base CoughPHP include:<br />
	Once again edit cms.rhp.org/config/application.php and add the following below the autoloader block:</p>
<pre>
		include(APP_PATH . 'modules/coughphp/load.inc.php');
		include(APP_PATH . 'modules/coughphp/as_database/load.inc.php');
	</pre>
<p>Step 8:<br />
	You&#8217;re done!<br />
	You have successfully created a LightVC application that loads the CoughPHP framework! go to <a href="http://cms.rhp.org">http://cms.rhp.org</a> in your browser to see your handywork!<br />
	In the next part of our tutorial, we will set up CoughPHP to talk to the database, generate some models and use them in the application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2009/02/16/combining-coughphp-and-lightvc/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Welcome to blog.rhp.org</title>
		<link>http://blog.rhp.org/2009/02/15/welcome-to-blogrhporg/</link>
		<comments>http://blog.rhp.org/2009/02/15/welcome-to-blogrhporg/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 00:14:25 +0000</pubDate>
		<dc:creator>Richard Pistole</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[coughphp]]></category>
		<category><![CDATA[lightvc]]></category>

		<guid isPermaLink="false">http://blog.rhp.org/?p=3</guid>
		<description><![CDATA[Welcome to my personal blog, blog.rhp.org. This blog will be kept updated with my musings on technology, programming tutorials and other randomness. First up will be a series of articles detailing how to make a simple content management system in PHP using LightVC and CoughPHP, lightweight VC and ORM frameworks the combine to create a [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to my personal blog, <a href="blog.rhp.org">blog.rhp.org</a>. This blog will be kept updated with my musings on technology, programming tutorials and other randomness.</p>
<p>First up will be a series of articles detailing how to make a simple content management system in PHP using <a href="http://lightvc.org">LightVC</a> and <a href="http://coughphp.com">CoughPHP</a>, lightweight VC and ORM frameworks the combine to create a simple and powerful MVC solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rhp.org/2009/02/15/welcome-to-blogrhporg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 3.566 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-22 21:11:10 -->
<!-- Compression = gzip -->
