<?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>Made of Everything You&#039;re Not &#187; php</title>
	<atom:link href="http://blog.ericlamb.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Thu, 27 Oct 2011 01:29:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Stand Alone ExpressionEngine Authentication</title>
		<link>http://blog.ericlamb.net/2011/08/stand-alone-expressionengine-authentication/</link>
		<comments>http://blog.ericlamb.net/2011/08/stand-alone-expressionengine-authentication/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 09:25:14 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3746</guid>
		<description><![CDATA[I had a small task come to me recently wherein a site needed to allow for verification of ExpressionEngine credentials but couldn&#8217;t use the normal controllers for access. The challenge was in how ExpressionEngine encrypts the passwords and replicating that behavior. Taking a look at the Login controllers made things very clear though; as usual [...]]]></description>
			<content:encoded><![CDATA[<p>I had a small task come to me recently wherein a site needed to allow for verification of ExpressionEngine credentials but couldn&#8217;t use the normal controllers for access. The challenge was in how ExpressionEngine encrypts the passwords and replicating that behavior. Taking a look at the Login controllers made things very clear though; as usual ExpressionEngine was very well written. </p>
<p>Here&#8217;s an example of how to do it (note that this will only work within the CP):</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: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'members.password, members.unique_id, members.member_id, members.group_id, member_groups.can_access_cp'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'member_groups.site_id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'site_id'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'members.group_id = '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbprefix</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'member_groups.group_id'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #000;">&#40;</span><span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'members'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'member_groups'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_rows</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> do_hash<span style="color: #000;">&#40;</span><span style="color: #000088;">$pass</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$password</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//good user credentials :)</span>
	<span style="color: #000;">&#125;</span>
	<span style="color: #22f;">else</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//bad password/good username</span>
	<span style="color: #000;">&#125;</span>			
<span style="color: #000;">&#125;</span>
<span style="color: #22f;">else</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//bad username</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>According to the site admin who passed this my way the above won&#8217;t work outside the CP. He was kind enough to send along an example that worked fine for their situation:</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'auth'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadfile</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$authorized</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate_username</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">EE</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$authorized</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	set_status_header<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #000;">&#40;</span>lang<span style="color: #000;">&#40;</span><span style="color: #0000ff;">'unauthorized_request'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2011/08/stand-alone-expressionengine-authentication/' addthis:title='Stand Alone ExpressionEngine Authentication '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2011/08/stand-alone-expressionengine-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importing Legacy Users Into ExpressionEngine</title>
		<link>http://blog.ericlamb.net/2011/07/importing-legacy-users-into-expressionengine/</link>
		<comments>http://blog.ericlamb.net/2011/07/importing-legacy-users-into-expressionengine/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 12:17:11 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3753</guid>
		<description><![CDATA[Fuck. We spent all this time convincing one of the oldest clients with the agency into upgrading their old and kludgy, PHP 3 era, nightmare website into a snazzy ExpressionEngine 2.2 gem of modern technology. But, like the assholes we are, we didn&#8217;t quite think through the fact that they have a complicated data structure [...]]]></description>
			<content:encoded><![CDATA[<p>Fuck. We spent all this time convincing one of the oldest clients with the agency into upgrading their old and kludgy, PHP 3 era, nightmare website into a snazzy ExpressionEngine 2.2 gem of modern technology. But, like the assholes we are, we didn&#8217;t quite think through the fact that they have a complicated data structure (having been built when PHP <em>really</em> sucked) that we&#8217;d have to import into ExpressionEngine. So, you know, fuck&#8230;</p>
<p>But then, after the pants come on and a moment to reflect is had and the obviousness of the overreaction becomes clear. This is ExpressionEngine after all; there&#8217;s bound to be some utility available to handle this with the least amount of pain possible. And there is: the <a title="ExpressionEngine Member Import Utility" href="http://expressionengine.com/user_guide/cp/tools/utilities/member_import/index.html" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Fuser_guide%2Fcp%2Ftools%2Futilities%2Fmember_import%2Findex.html','ExpressionEngine+Member+Import+Utility')" target="_blank">Member Import Utility</a> and, even better, it&#8217;s included into the core of ExpressionEngine so it&#8217;s already there.</p>
<p>And in traditional ExpressionEngine fashion its built in much the same and logical way most would design an import system. There are two different modes to work with: one to <a title="Import from XML" href="http://expressionengine.com/user_guide/cp/tools/utilities/member_import/import_from_xml.html" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Fuser_guide%2Fcp%2Ftools%2Futilities%2Fmember_import%2Fimport_from_xml.html','Import+from+XML')" target="_blank">import an ExpressionEngine Member XML file</a> and another to create said file from a <a title="Convert Delimited Data to XML" href="http://expressionengine.com/user_guide/cp/tools/utilities/member_import/convert_to_xml.html" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Fuser_guide%2Fcp%2Ftools%2Futilities%2Fmember_import%2Fconvert_to_xml.html','Convert+Delimited+Data+to+XML')" target="_blank">CSV formatted file</a>.</p>
<p>The CSV format conversion wasn&#8217;t really all that for the purposes of this project (mostly due to conditional rewriting of specific column entries) but it does have it&#8217;s uses. For instance, with smaller, self contained, exports it should be a snap to easily hand over the export straight from phpMyAdmin and convert it into an <a title="Member XML Format" href="http://expressionengine.com/user_guide/cp/tools/utilities/member_import/member_xml_format.html" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Fuser_guide%2Fcp%2Ftools%2Futilities%2Fmember_import%2Fmember_xml_format.html','Member+XML+Format')" target="_blank">ExpressionEngine Member XML</a> file. One big drawback though is that the CSV import doesn&#8217;t appear to create new custom member fields on import so manual mapping is required per import.</p>
<p>The flip side of the CSV format convertor is the straight ExpressionEngine Member XML import utility. The big drag with this, and only if you don&#8217;t use the CSV convertor, is that a script has to be written to handle the conversion. Not too big a deal but, considering most installations will vary, this is going to require manual intervention every time a new system is imported. But, unlike the CSV convertor, the Member XML importer does actually create missing custom fields so updating the system shouldn&#8217;t be too big  a drag.</p>
<p>For my purposes I wrote a dirty little script to create the XML file for me so it was simply a matter of importing. I&#8217;m lazy, in the long term, so keeping as much of this as simple as possible is always a priority for me. But, since it&#8217;s a throw away thing cleanliness and best practices is less important than getting me more time to do real work. A word of caution though; the XML parser within ExpressionEngine isn&#8217;t very helpful when it comes to error messages and telling you what went wrong. You will curse.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM users&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #22f;">echo</span> <span style="color: #990000;">mysql_error</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
<span style="color: #000088;">$ee</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;members&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #22f;">while</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;member&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;username&gt;&lt;![CDATA[&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'last_name'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;]]&gt;&lt;/username&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;screen_name&gt;&lt;![CDATA[&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'last_name'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;]]&gt;&lt;/screen_name&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;legacy_subscriber_id&gt;&lt;![CDATA[&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'subscriber_id'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;]]&gt;&lt;/legacy_subscriber_id&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">foreach</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #22f;">AS</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #000;">&#41;</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #22f;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span>
		<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;&lt;![CDATA[&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;]]&gt;&lt;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
	<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;/member&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #000088;">$ee</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/members&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #22f;">echo</span> <span style="color: #000088;">$ee</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The above code is fine if your existing database is cool but, and this is weird, ExpressionEngine goes full retard when it encounters anything it doesn&#8217;t like in the XML and won&#8217;t let you proceed. It&#8217;s really quite stunning. The XML importer knows that duplicate email addresses are bad in the database but instead of, say, allowing you to skip or force things the importer will just die and scream about a duplicate leaving you the only option of then manually pruning your data. Why they couldn&#8217;t be bothered with a checkbox or something allowing you to skip bad entries is beyond me but it makes the experience really, <em>really</em>, painful if your data sucks. </p>
<p>Still though, if your data is good to begin with the importer is a nice touch.</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2011/07/importing-legacy-users-into-expressionengine/' addthis:title='Importing Legacy Users Into ExpressionEngine '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2011/07/importing-legacy-users-into-expressionengine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CartThrob 2.0 Beta Fun</title>
		<link>http://blog.ericlamb.net/2011/05/cartthrob-2-0-beta-fun/</link>
		<comments>http://blog.ericlamb.net/2011/05/cartthrob-2-0-beta-fun/#comments</comments>
		<pubDate>Thu, 26 May 2011 22:00:58 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[CartThrob]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3668</guid>
		<description><![CDATA[About a year ago I reviewed various shopping cart platforms for what was to be an &#8220;upcoming&#8221; project. After numerous delays and client hand holding (with the requisite back and forth) one year later that project finally began. And, as has lately become a trend in my professional life, the client&#8217;s spec combined with a [...]]]></description>
			<content:encoded><![CDATA[<p>About a year ago I reviewed various <a title="Should We Use Prestashop" href="http://blog.ericlamb.net/2010/05/should-we-use-prestashop/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fshould-we-use-prestashop%2F','Should+We+Use+Prestashop')">shopping</a> <a title="Should We Use OpenCart" href="http://blog.ericlamb.net/2010/05/should-we-use-opencart/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fshould-we-use-opencart%2F','Should+We+Use+OpenCart%3F')" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fshould-we-use-opencart%2F','Should+We+Use+OpenCart')">cart</a> <a title="A Closer Look At Avactis" href="http://blog.ericlamb.net/2010/05/a-closer-look-at-avactis/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fa-closer-look-at-avactis%2F','A+Closer+Look+At+Avactis')" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fa-closer-look-at-avactis%2F','A+Closer+Look+At+Avactis')">platforms</a> for what was to be an &#8220;upcoming&#8221; project. After numerous delays and client hand holding (with the requisite back and forth) one <em>year </em>later that project finally began. And, as has lately become a trend in my professional life, the client&#8217;s spec combined with a drastically shortened and accelerated deadline forced us to go with something completely unknown and with only cursory inspection; the 3rd party e-commerce <a title="ExpressionEngine" href="http://expressionengine.com/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2F','ExpressionEngine')" target="_blank">ExpressionEngine</a> module <a title="CartThrob" href="http://cartthrob.com/" onclick="return TrackClick('http%3A%2F%2Fcartthrob.com%2F','CartThrob+Logo')" onclick="return TrackClick('http%3A%2F%2Fcartthrob.com%2F','CartThrob')" target="_blank">CartThrob 2.0</a> (beta at the time of this review BTW).</p>
<div id="attachment_3689" class="wp-caption aligncenter" style="width: 342px"><a title="CartThrob Logo" href="http://cartthrob.com/" onclick="return TrackClick('http%3A%2F%2Fcartthrob.com%2F','CartThrob+Logo')" onclick="return TrackClick('http%3A%2F%2Fcartthrob.com%2F','CartThrob')" target="_blank"><img class="size-full wp-image-3689" title="CartThrob" src="http://blog.ericlamb.net/wp-content/uploads/2011/05/cartthrob_logo.png" alt="CartThrob" width="332" height="117" /></a><p class="wp-caption-text">CartThrob</p></div>
<p>Of course this presented the problem of actually using an unknown  package to build a site with. Thankfully though, while CartThrob has a  steep learning curve and is most certainly missing key functionality,  it&#8217;s an overall nice package that allowed us to do what we needed. Sure, there&#8217;s pain involved (lots of configuration, testing and set up) but with a little elbow grease it all worked out.</p>
<p>As mentioned, CartThrob is an ExpressionEngine module for managing an online store. It&#8217;s available for both ExpressionEngine branches (1.x and 2.x) and was voted <a href="http://devot-ee.com/academee-awards/2010/" onclick="return TrackClick('http%3A%2F%2Fdevot-ee.com%2Facademee-awards%2F2010%2F','Module+of+the+Year+by+Devot%3Aee+in+2010')" target="_blank">Module of the Year by Devot:ee in 2010</a> (for the 1.x version only). This being an ExpressionEngine project CartThrob would, in theory, be a nice fit.</p>
<p>One of the really nice things about using CartThrob is that it uses the ExpressionEngine admin panel for managing your store. This meant there wouldn&#8217;t be a second administration site that the client would have to learn. (Personally, I always found dual admins to be janky at best and sloppy/lazy at worst so this was a definite bonus in favor CartThrob.)</p>
<p>But this is also double edged because, well, pretty much everything about your store is saved into the entries system within ExpressionEngine. This, of course, causes your Entries panel to become an eye sore whenever you have to do anything there. Instead of having a dedicated section to manage products you use the Entries section. Instead of a dedicated section to manage your orders you use the Entries section. Instead of a dedicated section to manage&#8230; well, you get the idea; everything is managed through the entries. This makes sense for the product management but when you have to dig through entries to find orders and coupons and discounts (etc) things get a little jarring for some people (even internally with my team) so it&#8217;s a concern.</p>
<p>Still, <em>single freaking admin</em> so it was kind of a lesser evil compromise.</p>
<p>The unusual thing though is that, for how thoroughly the management of items was punted (though, to be fair, it looks to be a feature versus bug debate more than &#8220;punting&#8221;), CartThrob has an extremely deep configuration section where you can customize CartThrob to function just right. CartThrob has all the basic customization functionality one would expect from any modern shopping cart platform (tax, shipping, payments with lots of merchant options, etc) plus a bunch of settings just to get CartThrob working (CartThrob is NOT an out of the box solution). It&#8217;s all presented in an easy to use interface that&#8217;s designed to mesh with the ExpressionEngine administration panel design which makes for an easier experience.</p>
<p>As far as merchant accounts go (for accepting payments through your site) there&#8217;s the usual suspects of <a title="Authorize.net" href="http://www.authorize.net/" onclick="return TrackClick('http%3A%2F%2Fwww.authorize.net%2F','Authorize.net')" target="_blank">Authorize.net</a>, <a title="Paypal" href="http://www.paypal.com/" onclick="return TrackClick('http%3A%2F%2Fwww.paypal.com%2F','Paypal')" target="_blank">Paypal</a> and <a title="SagePay" href="http://www.sagepay.com/" onclick="return TrackClick('http%3A%2F%2Fwww.sagepay.com%2F','SagePay')" target="_blank">SagePay</a> built right in but also some offline solutions for pay by check and credit accounts. For this project we used Authorize.net which went smooth for the most part but I can&#8217;t speak for the other options though if they&#8217;re anything like the Authorize.net one they&#8217;re probably cool. CartThrob also includes some extensions and hooks so writing your own payment gateway is possible if you need.</p>
<p>CartThrob can also hook into the ExpressionEngine member module so your customers can be registered internally. Like pretty much everything else with CartThrob there&#8217;s a bit of configuration involved to get it up and working though. Unfortunately though, there&#8217;s not really any out of the box functionality for your members to take advantage of. For example, there isn&#8217;t any way for your customers to view their past orders when logged in and when using the control panel and viewing a member&#8217;s profile there&#8217;s no relationship with CartThrob. You&#8217;re gonna have to write all that stuff yourself but, and I don&#8217;t know why, but CartThrob doesn&#8217;t store any relationships between ExpressionEngine members and it&#8217;s customers so expect a challenge.</p>
<p>In terms of the user side, the actual storefront, everything is done using ExpressionEngine templates and <a href="http://cartthrob.com/docs/tags/" onclick="return TrackClick('http%3A%2F%2Fcartthrob.com%2Fdocs%2Ftags%2F','CartThrob+Template+Tags')" title="CartThrob Template Tags" target="_blank">template tags</a>. There are lots of module methods available and even though it&#8217;s far from a complete package of the expected functionality. In fact, on our team, we got into a habit of thinking of CartThrob as a Lego set for <em>creating</em> what we want instead of <em>having</em> what we want already.</p>
<p>For example, to view the details about a users cart you&#8217;d use the template code below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000;">&#123;</span><span style="color: #990000;">exp</span><span style="color: #339933;">:</span>cartthrob<span style="color: #339933;">:</span>cart_info<span style="color: #000;">&#125;</span>
	<span style="color: #000;">&#123;</span>total_items<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>total_unique_items<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>cart_entry_ids<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>cart_shipping<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>cart_tax_rate<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>cart_tax<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>cart_subtotal<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
	<span style="color: #000;">&#123;</span>cart_total<span style="color: #000;">&#125;</span> <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #000;">&#123;</span><span style="color: #339933;">/</span><span style="color: #990000;">exp</span><span style="color: #339933;">:</span>cartthrob<span style="color: #339933;">:</span>cart_info<span style="color: #000;">&#125;</span></pre></div></div>

<p>On the surface this appears to be nice because it keeps things within the core ExpressionEngine development process. And it would be except, well, CartThrob isn&#8217;t abstract enough. Too many times I would try to do something that seemed obvious, like <a href="http://cartthrob.com/forums/viewthread/2391/" onclick="return TrackClick('http%3A%2F%2Fcartthrob.com%2Fforums%2Fviewthread%2F2391%2F','How+to+build+a+logical+checkout+process')" title="How to build a logical checkout process" target="_blank">checking for shippable items within a users cart</a>, and would come up short; that functionality doesn&#8217;t exist. </p>
<p>Still though, don&#8217;t get me wrong. Yes, some of the above sucks. Absolutely. But CartThrob is still under development. Plus, since it&#8217;s a commercial script ($99) there&#8217;s financial incentive to improve it. And, truth be told, for as painful as certain points were it&#8217;s still way more fun to build a site with CartThrob than most of the other options I&#8217;ve used or reviewed like <a href="http://blog.ericlamb.net/2010/05/should-we-use-opencart/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fshould-we-use-opencart%2F','Should+We+Use+OpenCart%3F')" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fshould-we-use-opencart%2F','Should+We+Use+OpenCart')" title="Should We Use OpenCart?">OpenCart</a> or <a href="http://blog.ericlamb.net/2010/05/a-closer-look-at-avactis/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fa-closer-look-at-avactis%2F','A+Closer+Look+At+Avactis')" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F05%2Fa-closer-look-at-avactis%2F','A+Closer+Look+At+Avactis')" title="A Closer Look At Avactis">Avactis</a>. </p>
<p>Plus, again, <em>single freaking admin</em>!</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2011/05/cartthrob-2-0-beta-fun/' addthis:title='CartThrob 2.0 Beta Fun '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2011/05/cartthrob-2-0-beta-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExpressionEngine and the Mystery of M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr</title>
		<link>http://blog.ericlamb.net/2011/05/expressionengine-and-the-mystery-of-m00o93h7pq09l8x1t49chy01z5j4tt91fgfr/</link>
		<comments>http://blog.ericlamb.net/2011/05/expressionengine-and-the-mystery-of-m00o93h7pq09l8x1t49chy01z5j4tt91fgfr/#comments</comments>
		<pubDate>Tue, 03 May 2011 11:53:21 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3651</guid>
		<description><![CDATA[Recently, I came across a weird issue while developing an ExpressionEngine 2.0 module. The issue was that, for some reason, my module would output a random string instead of the intended content. For example, instead of displaying the HTML, that the module created, the module would display the string M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr instead. Tracking down this issue [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I came across a weird issue while developing an <a title="ExpressionEngine" href="http://expressionengine.com/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2F','ExpressionEngine')" target="_blank">ExpressionEngine</a> 2.0 module. The issue was that, for some reason, my module would output a random string instead of the intended content. For example, instead of displaying the HTML, that the module created, the module would display the string M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr instead. Tracking down this issue was symptomatic of the proverbial needle in a haystack but I learned a lot about how ExpressionEngine&#8217;s internals work and was once again reminded to be pragmatic about my development strategies.</p>
<div id="attachment_3655" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flickr.com/photos/rafaelm/145958282/" onclick="return TrackClick('http%3A%2F%2Fwww.flickr.com%2Fphotos%2Frafaelm%2F145958282%2F','random%2C+the+lion')"><img class="size-medium wp-image-3655" title="random, the lion" src="http://blog.ericlamb.net/wp-content/uploads/2011/05/random_the_lion-300x225.jpg" alt="random, the lion" width="300" height="225" /></a><p class="wp-caption-text">random, the lion</p></div>
<p>My first and automatic reaction when coming up against some random and meaningless output string is to just Google it and see what happens. Unfortunately though, this particular search, at the time at least, returned around 35,000 sites that were outputting the string and only 1 that had a <a title="Out from plugin getting over-written by EE?" href="http://expressionengine.com/archived_forums/viewthread/123475/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Farchived_forums%2Fviewthread%2F123475%2F','Out+from+plugin+getting+over-written+by+EE%3F')" target="_blank">reference to the issue with a possible explanation</a>. All of a a sudden this became an actual thing.</p>
<p>Putting aside the fact that there are around 35,000 sites with the string within Google for the moment (and that&#8217;s really a problem to be discussed) it took a bunch of digging but I finally found a few things:</p>
<p>First, this is an issue that has been within ExpressionEngine for <em>years.</em> Doing a <a title="ExpressionEngine Forum Search" href="http://expressionengine.com/archived_forums/search/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Farchived_forums%2Fsearch%2F','ExpressionEngine+Forum+Search')" target="_blank">search</a> on the ExpressionEngine site lists the first entry of this string at <a title="EE1.6 upgrade - Hash values apppearing throughout site" href="http://expressionengine.com/archived_forums/viewthread/54903/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Farchived_forums%2Fviewthread%2F54903%2F','EE1.6+upgrade+-+Hash+values+apppearing+throughout+site')" target="_blank">2007</a> (sorry for the lack of a link; ExpressionEngine search is cached so old search URLs don&#8217;t work sometimes). My initial reaction was that this was kind of sloppy; EllisLab updated ExpressionEngine to 2.0 recently, from the ground up to use <a title="CodeIgniter" href="http://codeigniter.com/" onclick="return TrackClick('http%3A%2F%2Fcodeigniter.com%2F','CodeIgniter')" target="_blank">CodeIgniter</a> I believe, yet this issue got ported over?</p>
<p>After doing further research though, I came to believe the above is more to do with the design of ExpressionEngine than anything else like copying code. Turns out, there&#8217;s some logic to that random and oblique string.</p>
<p>Basically, that string (M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr) is a template holder for the content you want to output. It&#8217;s a little complicated in how it works but thanks to <a title="Explanation of EE Template Parsing" href="http://expressionengine.com/archived_forums/viewthread/85160/#j1" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Farchived_forums%2Fviewthread%2F85160%2F%23j1','Explanation+of+EE+Template+Parsing')" target="_blank">Derek Jones over at the ExpressionEngine forums</a> there&#8217;s a succinct, though still a little complicated but less complicated than I could explain it, explanation of what&#8217;s going on.</p>
<blockquote><p>
&#8230;</p>
<p>The template parser is an extremely complex gizmo, so let me try to explain it stripped of what techno mumbo jumbo I can. This will still be long, so bear with me.</p>
<p>The template parser intelligently saves on resources by only processing a given tag once, no matter how many times it occurs on the template.  This means that if your tag is exactly the same, including its tagdata, EE only execute’s that modules code once, and replaces all copies of that tag with the output.</p>
<p>So first, when the template parser goes through the template finding tags, it replaces them all with temporary markers (the gibberish), and adds each tag to a list of tags to be parsed, in the order they are encountered on the template, top down.  Each marker starts with the letter “M” followed by the number (starting at 0) that tag is sitting in on The List.</p>
<p>Second, the parser goes down its list of tags.  It parses tag #0, and then replaces all of #0’s marker with that tag’s output.</p>
<p>——————-</p>
<p>Ok that’s the setup.  Here’s why it affected you, and why this side effect is not a problem (and also extremely, extremely rare). Remember, top down, tags will be assigned 0, 1, 2, etc.  So I’m abstracting it out to show the nesting and the positioning only.  Just focus on the numbers.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{exp:tag0}foo{/exp:tag0}
{exp:tag1}
    bar
    {exp:tag0}foo{/exp:tag0}
{/exp:tag1}</pre></div></div>

<p>Step 1, the tags are grabbed and replaced with markers.  The first tag encountered is replaced first.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">M0
{exp:tag1}
    bar
    M0
{/exp:tag1}</pre></div></div>

<p>And then the next tag:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">M0
M1</pre></div></div>

<p>All tags have been collected and put on The List, so step 2, the parser goes down The List, and parses tag #0:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">foo
M1</pre></div></div>

<p>See the problem?  The second M0 is sitting protected inside the marker for tag #1, so it doesn’t get replaced.  Then tag #1 gets parsed.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">foo
    bar
    M0</pre></div></div>

<p>And the marker is left in the output.  EE doesn’t go back and parse tag #0 again, it’s already done that once, and will not do it again.</p>
<p>So the circumstances required for this problem to exist each are uncommon, and combined, very very rare:</p>
<p>1) Multiple exact copies of a given tag<br />
2) One or more copies nested inside another tag (tag nesting itself is also rare, and usually not recommended)<br />
3) The tag of which there are copies must sit at a position in the template above any occurrences of it being nested in another tag.
</p></blockquote>
<p>From the above it was easy to conclude that the template parsing stuff was breaking down in my module. Why, I had no idea, but at least I had a known starting point. While it was easy to conclude that my issue lay with the template parsing though, it was 100% off point for my particular issue which had to do with, of all things, the case of the module name. But, I digress. </p>
<p>The point is that for years now, and through multiple versions and rewrites, ExpressionEngine has consistently carried the same &#8220;issue&#8221;. Understanding the intent of the design for the template parsing helps put some perspective on things: it&#8217;s definitely a side effect of the particular approach. It bugged, and surprised, me that ExpressionEngine would have such oblique and useless output on such a widespread basis (35,000 site&#8217;s with that string within Google is a bit much in my opinion) but the more I thought about it the more I came to understand the complexity of what was involved in being helpful when the issue cropped up. Aside from abandoning the approach what could really be done?</p>
<p>It&#8217;s a nice reminder that development is often a balancing act between getting what you want and dealing with a counter issue. The ExpressionEngine team developed a strategy to enable them to effectively and efficiently meet their requirements but there&#8217;s sometimes an issue; a random string gets output instead of the template data. Plus, since the cause could be for anything from bad module installation data (as I had) to an issue within a template there&#8217;s no real way to provide helpful error messages when the template parsing does fail. But, on the other hand, the template parser does exactly what it was designed to do (and it does it well). </p>
<p>Which would you choose?</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2011/05/expressionengine-and-the-mystery-of-m00o93h7pq09l8x1t49chy01z5j4tt91fgfr/' addthis:title='ExpressionEngine and the Mystery of M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2011/05/expressionengine-and-the-mystery-of-m00o93h7pq09l8x1t49chy01z5j4tt91fgfr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom Routes With Zend Framework</title>
		<link>http://blog.ericlamb.net/2011/04/custom-routes-with-zend-framework/</link>
		<comments>http://blog.ericlamb.net/2011/04/custom-routes-with-zend-framework/#comments</comments>
		<pubDate>Fri, 08 Apr 2011 18:43:58 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[routes]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3609</guid>
		<description><![CDATA[When I first started using the Zend Framework I didn&#8217;t give much thought into the way it handles routing URLs to the controllers/action combo. Honestly, while I had become used to so called search engine friendly, or pretty, URLs, I grew up on query strings where the idea of URLs was more about function than [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started using the <a href="http://framework.zend.com/" onclick="return TrackClick('http%3A%2F%2Fframework.zend.com%2F','Zend+Framework')" title="Zend Framework" target="_blank">Zend Framework</a> I didn&#8217;t give much thought into the way it handles routing URLs to the controllers/action combo. Honestly, while I had become used to so called search engine friendly, or pretty, URLs, I grew up on query strings where the idea of URLs was more about function than form. So when I moved over to Zend Framework as a framework I didn&#8217;t give a damn how the URLs were parsed and routed to which controller/action. I just accepted the natural order of things. </p>
<div id="attachment_3627" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flickr.com/photos/orudge/5602610471/lightbox/#/photos/orudge/5602610471/" onclick="return TrackClick('http%3A%2F%2Fwww.flickr.com%2Fphotos%2Forudge%2F5602610471%2Flightbox%2F%23%2Fphotos%2Forudge%2F5602610471%2F','Road+Signs')" target="_blank"><img class="size-medium wp-image-3627" title="Road Signs" src="http://blog.ericlamb.net/wp-content/uploads/2011/04/routes-300x199.jpg" alt="Road Signs by orudge" width="300" height="199" /></a><p class="wp-caption-text">Road Signs by orudge</p></div>
<p>Recently though, I took on a project to build a sort of quick and dirty CMS with a couple unique requirements:</p>
<ol>
<li>It had to use the Zend Framework</li>
<li>URLs would be broken down into a /category/page/subpage scheme.</li>
</ol>
<p>This was the first time I&#8217;ve ever had a client demand a project use the Zend Framework. Pretty cool. But, this presented a problem because, as mentioned above, by default the Zend Framework has URL schemes based on the controller and action you&#8217;re looking to access like /controller/action/. This just wouldn&#8217;t work.</p>
<p>Since the clients URLs would mostly be based on user generated strings, what we were calling URL slugs, the default routing scheme just wouldn&#8217;t do. I say mostly because there were other areas of the project that would use the normal scheme for a couple modules. Either way, thankfully, using <a href="http://framework.zend.com/manual/1.11/en/zend.controller.router.html#zend.controller.router.routes.standard" onclick="return TrackClick('http%3A%2F%2Fframework.zend.com%2Fmanual%2F1.11%2Fen%2Fzend.controller.router.html%23zend.controller.router.routes.standard','Zend_Controller_Router_Route')" title="Zend_Controller_Router_Route" target="_blank">Zend_Controller_Router_Route</a> made this pretty much a snap (a little head bashing but not too much).</p>
<p>First though, a little background. Because of the above requirement from the client on URL schemes, I was thinking the best thing to do was to route all user generated URLs to to a single controller and handle the rest from there. I looked but there didn&#8217;t seem to be any easy way to route all URLs <em>except</em> the specific modules I wanted to exclude which meant I had to pull out the categories and iterate over them to create each route individually. (If anyone knows of a way to reverse the design and create a route for everything but certain strings let me know.)</p>
<p>To do this, in my bootstrap class I just created a new _init function like the below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//bootstrap</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _initRoutes<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$url_data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCategoryUrls</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$frontController</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$router</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$frontController</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouter</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">foreach</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$url_data</span> <span style="color: #22f;">AS</span> <span style="color: #000088;">$url</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route <span style="color: #000;">&#40;</span>
			<span style="color: #000088;">$url</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'url_slug'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/*'</span><span style="color: #339933;">,</span>
			<span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pages'</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #000;">&#41;</span>
		<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'url_slug'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$route</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> 
<span style="color: #000;">&#125;</span></pre></td></tr></table></div>

<p>In a nutshell, all the above is doing is looping over an array of category URL slugs and adding a custom route for each category that sends all requests to the Pages controller and the Index action. From there I parse the URL and proceed accordingly for the rest of the module. </p>
<p>For this example I&#8217;m doing a couple thing; using the Zend_Controller_Router_Route class and using wild cards (*). The Zend_Controller_Router_Route class takes two parameters, the first being the route and the second being an array of options (I&#8217;m only passing the controller and action but it&#8217;s possible to send others). For the route, and because it&#8217;s using the wildcard (*), I&#8217;m basically saying take any requests for the &#8220;url_slug&#8221; and anything after it and use the controller &#8220;Pages&#8221; and the &#8220;Index&#8221; action to handle everything. </p>
<p>After passing the Zend_Controller_Router_Route object to the $router, passing the unique name for the route as the first parameter, I was good to go. </p>
<p>That said, there&#8217;s a lot more that can be done with the custom routing stuff within the Zend Framework above what&#8217;s outlined above. There&#8217;s a pretty good article by <a href="http://www.wdvl.com/Authoring/PHP/Zend_Routes/Jason_Gilmore04282010.html" onclick="return TrackClick('http%3A%2F%2Fwww.wdvl.com%2FAuthoring%2FPHP%2FZend_Routes%2FJason_Gilmore04282010.html','Creating+Custom+Routes+with+the+Zend+Framework')" title="Creating Custom Routes with the Zend Framework" target="_blank">Jason Gilmore</a> that goes into some detail into how to create default URL parameters to make the URLs look even prettier. Definitely worth checking out. </p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2011/04/custom-routes-with-zend-framework/' addthis:title='Custom Routes With Zend Framework '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2011/04/custom-routes-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Practical PHP Reflection</title>
		<link>http://blog.ericlamb.net/2011/03/practical-php-reflection/</link>
		<comments>http://blog.ericlamb.net/2011/03/practical-php-reflection/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 08:00:12 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[reflection api]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3401</guid>
		<description><![CDATA[The Reflection API in PHP is one of those language features that can kind of creep up on you; it&#8217;s just not needed for a vast majority of projects. In fact, I&#8217;d wager there are a bunch of professional developers who have never had to make use of the Reflection API. Hell, I spent 8 [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="Reflection API in PHP" href="http://us.php.net/manual/en/book.reflection.php" onclick="return TrackClick('http%3A%2F%2Fus.php.net%2Fmanual%2Fen%2Fbook.reflection.php','Reflection+API+in+PHP')" target="_blank">Reflection API in PHP</a> is one of those language features that can kind of creep up on you; it&#8217;s just not needed for a vast majority of projects. In fact, I&#8217;d wager there are a bunch of professional developers who have never had to make use of the Reflection API. Hell, I spent 8 years writing code professionally before I ever had to use it (though, because of some unrelated .NET research I was peripherally aware of it). It&#8217;s just not something that really comes up all that often in the day to day coding tasks. </p>
<p>Then, one day, out of nowhere, it comes up. The perfect problem where the Reflection API appears to be the perfect solution. For me this came up a couple months ago while I was working on a European zip code radius project that had to be built using one of those obfuscated and ill documented 3rd party commercial programs (nothing worse than when the platform is forced on you). So, I had to use this program that was intentionally encoded to prevent me from doing what I wanted to do. I couldn&#8217;t even look at the code; it was completely obfuscated.</p>
<p>Before getting into things it should be noted that the Reflection API is capable above and beyond what I&#8217;m outlining; usually for the kind of high level stuff like core <a title="PHP 5's Reflection API" href="http://weierophinney.net/matthew/archives/125-PHP-5s-Reflection-API.html" onclick="return TrackClick('http%3A%2F%2Fweierophinney.net%2Fmatthew%2Farchives%2F125-PHP-5s-Reflection-API.html','PHP+5')" target="_blank">Zend Framework components</a> and anything you&#8217;d want <em>way</em> abstracted. </p>
<p>So, yeah, weird problem.</p>
<p>This is where reflection comes in for me. It was made for problems like the above; according to the manual:</p>
<blockquote><p>
PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions, methods and extensions. Additionally, the reflection API offers ways to retrieve doc comments for functions, classes and methods.
</p></blockquote>
<p>So, the theory was that I could use the Reflection API to look into the obfuscated code and get some insight into what was going on and what I had to work with. I figured that, at the least, if I could see what methods, properties and comments the code had; maybe I&#8217;d get some clue about what the code was about. Using, for example, the internal PHP class &#8220;SimpleXMLElement&#8221; it&#8217;s real simple to get a nice map of the class by calling the class <a title="ReflectionClass" href="http://us.php.net/manual/en/class.reflectionclass.php" onclick="return TrackClick('http%3A%2F%2Fus.php.net%2Fmanual%2Fen%2Fclass.reflectionclass.php','ReflectionClass')" target="_blank">ReflectionClass</a> and passing the name of the class you want to get details on as a parameter like the below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$reflector</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;SimpleXMLElement&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #22f;">echo</span> <span style="color: #000088;">$reflector</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The above outputs an eye gouging but verbose class map:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Class</span> <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>iterateable<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleXMLElement implements Traversable <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
&nbsp;
  <span style="color: #339933;">-</span> Constants <span style="color: #000;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
  <span style="color: #000;">&#125;</span>
&nbsp;
  <span style="color: #339933;">-</span> Static properties <span style="color: #000;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
  <span style="color: #000;">&#125;</span>
&nbsp;
  <span style="color: #339933;">-</span> Static methods <span style="color: #000;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
  <span style="color: #000;">&#125;</span>
&nbsp;
  <span style="color: #339933;">-</span> Properties <span style="color: #000;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
  <span style="color: #000;">&#125;</span>
&nbsp;
  <span style="color: #339933;">-</span> Methods <span style="color: #000;">&#91;</span><span style="color: #cc66cc;">14</span><span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">,</span> ctor<span style="color: #339933;">&gt;</span> final <span style="color: #000000; font-weight: bold;">public</span> method __construct <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method asXML <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method saveXML <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method xpath <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method registerXPathNamespace <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method attributes <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method children <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method getNamespaces <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method getDocNamespaces <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method getName <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method addChild <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method addAttribute <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method __toString <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
&nbsp;
    Method <span style="color: #000;">&#91;</span> <span style="color: #339933;">&lt;</span>internal<span style="color: #339933;">:</span>SimpleXML<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">public</span> method <span style="color: #990000;">count</span> <span style="color: #000;">&#93;</span> <span style="color: #000;">&#123;</span>
    <span style="color: #000;">&#125;</span>
  <span style="color: #000;">&#125;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>As you can see, the above lists every property, method and constant about a class along with any parent classes and interfaces. If there were any variables the methods accepted it would also list those as well but SimpleXMLElement doesn&#8217;t have any. </p>
<p>It&#8217;s also possible to get the individual elements on a one by one basis while using the ReflectionClass object; for example the below methods returns the class name, any comments (if they&#8217;re in docblock format), the constants, parent class, constructor and default properties for the class DateTime.</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: #000088;">$reflector</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;DateTime&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">&quot;Class name: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</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>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">&quot;Doc Comment:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">var_dump</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDocComment</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</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>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">&quot;Contants: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">var_dump</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConstants</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</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>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">&quot;Parent Class: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">var_dump</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParentClass</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</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>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">&quot;Constructor: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">var_dump</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConstructor</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</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>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">&quot;Default Properties: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">var_dump</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDefaultProperties</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</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>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Outputs</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Class</span> name<span style="color: #339933;">:</span> DateTime
Doc Comment<span style="color: #339933;">:</span> bool<span style="color: #000;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #000;">&#41;</span>
Contants<span style="color: #339933;">:</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;ATOM&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;Y-m-d<span style="color: #000099; font-weight: bold;">\T</span>H:i:sP&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;COOKIE&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;l, d-M-y H:i:s T&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;ISO8601&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;Y-m-d<span style="color: #000099; font-weight: bold;">\T</span>H:i:sO&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RFC822&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;D, d M y H:i:s O&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RFC850&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;l, d-M-y H:i:s T&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RFC1036&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;D, d M y H:i:s O&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RFC1123&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;D, d M Y H:i:s O&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RFC2822&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;D, d M Y H:i:s O&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RFC3339&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;Y-m-d<span style="color: #000099; font-weight: bold;">\T</span>H:i:sP&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;RSS&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;D, d M Y H:i:s O&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;W3C&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;Y-m-d<span style="color: #000099; font-weight: bold;">\T</span>H:i:sP&quot;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
Parent <span style="color: #000000; font-weight: bold;">Class</span><span style="color: #339933;">:</span> bool<span style="color: #000;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #000;">&#41;</span>
Constructor<span style="color: #339933;">:</span> object<span style="color: #000;">&#40;</span>ReflectionMethod<span style="color: #000;">&#41;</span><span style="color: #666666; font-style: italic;">#2 (2) {
</span>  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;__construct&quot;</span>
  <span style="color: #000;">&#91;</span><span style="color: #0000ff;">&quot;class&quot;</span><span style="color: #000;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #000;">&#41;</span> <span style="color: #0000ff;">&quot;DateTime&quot;</span>
<span style="color: #000;">&#125;</span>
<span style="color: #22f;">Default</span> Properties<span style="color: #339933;">:</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>Check out the documentation; there are a bunch of other details you can get from other methods. </p>
<p>This is really just the tip of the iceberg though. There are other classes that allow even deeper insight into <a title="ReflectionFunction" href="http://us.php.net/manual/en/class.reflectionfunction.php" onclick="return TrackClick('http%3A%2F%2Fus.php.net%2Fmanual%2Fen%2Fclass.reflectionfunction.php','ReflectionFunction')" target="_blank">functions</a>, <a title="ReflectionMethod" href="http://us.php.net/manual/en/class.reflectionmethod.php" onclick="return TrackClick('http%3A%2F%2Fus.php.net%2Fmanual%2Fen%2Fclass.reflectionmethod.php','ReflectionMethod')" target="_blank">methods</a>,  <a title="ReflectionExtension" href="http://us.php.net/manual/en/class.reflectionextension.php" onclick="return TrackClick('http%3A%2F%2Fus.php.net%2Fmanual%2Fen%2Fclass.reflectionextension.php','ReflectionExtension')" target="_blank">extensions</a> and much more. Definitely worth checking out. </p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2011/03/practical-php-reflection/' addthis:title='Practical PHP Reflection '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2011/03/practical-php-reflection/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Care About What Matters</title>
		<link>http://blog.ericlamb.net/2010/10/care-about-what-matters/</link>
		<comments>http://blog.ericlamb.net/2010/10/care-about-what-matters/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 21:03:52 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3405</guid>
		<description><![CDATA[It&#8217;d been a while since I&#8217;ve had the free time to write something and I really didn&#8217;t think it&#8217;d be a bitch post but it is and here we are. But, as I sit here at midnight browsing Reddit, and, yes, a little drunk, I find myself raging about the idea of the dumb stuff [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;d been a while since I&#8217;ve had the free time to write something and I really didn&#8217;t think it&#8217;d be a bitch post but it is and here we are. But, as I sit here at midnight browsing Reddit, and, yes, a little drunk, I find myself raging about the idea of the dumb stuff we care about and why we probably shouldn&#8217;t.</p>
<p>Case in point, an article called &#8220;<a href="http://arin.me/blog/php-require-vs-include-vs-require_once-vs-include_once-performance-test" onclick="return TrackClick('http%3A%2F%2Farin.me%2Fblog%2Fphp-require-vs-include-vs-require_once-vs-include_once-performance-test','PHP+require+vs.+include+vs.+require_once+vs.+include_once+Performance+Test')" target="_blank">PHP require vs. include vs. require_once vs. include_once Performance Test</a>&#8221; written by <a href="http://arin.me" onclick="return TrackClick('http%3A%2F%2Farin.me','Arin+Sarkissian')" target="_blank">Arin Sarkissian</a> way back in 2007. Forgiving the obscenely long and verbose title, Arin goes over the process and code he created to test which of 4 statements (require, include, require_once, includes_once) was the most efficient in terms of performance. It&#8217;s definitely a good read if for no other reason than the insight into how to test and benchmark code but I think there&#8217;s more to the article than that.</p>
<p>That said, the article left me unsettled for a couple reasons. First, with the amazement and appreciation that someone had taken the initiative to <em>test</em> a theory instead of just drawing conclusions (something that&#8217;s pretty rare in my experience). Second though, well the second thing bothered me because of the other more applicable and meaningful question I couldn&#8217;t shake. Why do we care about this nonsense?</p>
<p>For years I&#8217;ve read articles about how best to handle certain circumstances to improve performance. Some are good. Things like how to use the dir() function to iterate over directories or how to properly write SQL are great and definitely worthwhile reads. On the other hand though, there are tons of articles talking about the advantages of using single quotes over double quotes or, as Arin wrote, which function is better suited for file inclusion; scenarios that matter so minimally that the effort in thinking about the issue is far greater than the gains of switching techniques.</p>
<p>As my friend Caroline would say, &#8220;Rubbish; all of it.&#8221; (she&#8217;s British).</p>
<p>Care about your SQL. Care about your file system interaction, your loops and your math. Care about your logic. And, because it&#8217;s so important it demands repeating, care about your SQL.</p>
<p>I promise you, there are zero circumstances where whether you used include_once over require_once is going to be the bottleneck. It will never matter one bit if you concatenate with single quotes rather than use double quotes with nested variables. Hand to fucking god; it will not matter nearly enough to spend any time debating which approach is better.</p>
<p>So before you start spending all your time wondering what is the best technique or method for a specific scenario as yourself how much does it matter.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 51px; width: 1px; height: 1px; overflow: hidden;">SQL</div>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2010/10/care-about-what-matters/' addthis:title='Care About What Matters '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/10/care-about-what-matters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing ExpressionEngine 1.6x Extensions</title>
		<link>http://blog.ericlamb.net/2010/09/developing-expressionengine-1-6x-extensions/</link>
		<comments>http://blog.ericlamb.net/2010/09/developing-expressionengine-1-6x-extensions/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 23:32:34 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[ExpressionEngine Extension]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3344</guid>
		<description><![CDATA[I recently had a project come up that could have gone one of two ways from a  strategic design stand point; either as a straight up script custom built for the occasion or, time warranting, I could build an extension for ExpressionEngine. As I&#8217;d already looked into writing an ExpressionEngine plugin the idea of writing [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a project come up that could have gone one of two ways from a  strategic design stand point; either as a straight up script custom built for the occasion or, time warranting, I could build an extension for ExpressionEngine. As I&#8217;d already looked into writing an ExpressionEngine plugin the idea of writing an extension was pretty enticing regardless of the added time costs I would have to swallow (can&#8217;t bill the client for my fun now can I?).</p>
<div id="attachment_3352" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2010/08/ee-extension.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2010%2F08%2Fee-extension.jpg','Developing+ExpressionEngine+1.6x+Extensions')"><img class="size-medium wp-image-3352" title="Developing ExpressionEngine 1.6x Extensions" src="http://blog.ericlamb.net/wp-content/uploads/2010/08/ee-extension-300x225.jpg" alt="Developing ExpressionEngine 1.6x Extensions" width="300" height="225" /></a><p class="wp-caption-text">Developing ExpressionEngine 1.6x Extensions</p></div>
<p>The only problem is that the project in question was built on ExpressionEngine 1.6.7 and ExpressionEngine, having recently released 2.0 with all new bells and whistles and ways of doing things, updated their documentation as well. I couldn&#8217;t find any documentation for writing extensions for 1.6x though there&#8217;s a really nice help center for 2.0. A little advice third party developers; don&#8217;t just remove documentation and replace it with the new stuff because, as shocking as this may sound, people still use the old stuff. </p>
<p>To ExpressionEngine an extension is a script built to modify how ExpressionEngine <em>works</em> as opposed to adding additional functionality like a plugin would do. For example, a plugin would be good for adding a drop in template tag while an extension would be good for changing how ExpressionEngine parses all template tags. If you&#8217;re used to the WordPress development paradigm think of extensions as hook filters in WordPress plugins.</p>
<p>Those aren&#8217;t the only distinction though; extensions can also have a settings section, language files and database tables too so you&#8217;re really going  to need at least an extension for any deep functionality or customizations (there are also <a title="What is the difference between modules plugins extensions and expansions " href="http://expressionengine.com/wiki/What_is_the_difference_between_modules_plugins_extensions_and_expansions/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Fwiki%2FWhat_is_the_difference_between_modules_plugins_extensions_and_expansions%2F','What+is+the+difference+between+modules+plugins+extensions+and+expansions')" target="_blank">ExpressionEngine modules and expansions</a> but that&#8217;s for another day).</p>
<p>Codewise, ExpressionEngine extensions are pretty similar to plugins insofar as structure and elements. At the core an extension is a PHP class that follows the same naming structure for both the class and the file as a plugin except the prefix changes and where you store the file. ExpressionEngine extensions should be named with a prefix of &#8220;ext.&#8221; and the class name, include a couple class variables for information about the extension, a couple methods to activate, deactivate and remove the extension and, ideally, a method to be called when the &#8220;hook&#8221; is executed. </p>
<p>As an example let&#8217;s put together an extension stub for a demonstration of how things should be setup</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Pissoff_client
<span style="color: #000;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Name of the extension
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Enrage The Client'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Version of the extension
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$version</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * The description of the extension
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Replaces every instance of one word with another from all entries'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Flag for whether this extension has settings 
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$settings_exist</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'n'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * URL to the documentation for the extension
	 * @var stirng
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$docs_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://url_to_documentation.com'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * The available settings for the extension
	 * @var array
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Constructor
	 *
	 * @param 	mixed	Settings array or empty string if none exist.
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> Pissoff_client<span style="color: #000;">&#40;</span><span style="color: #000088;">$settings</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$settings</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Activate Extension
	 *
	 * This function enters the extension into the exp_extensions table
	 *
	 * @see http://codeigniter.com/user_guide/database/index.html for
	 * more information on the db class.
	 *
	 * @return void
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> activate_extension<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$DB</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// default settings</span>
		<span style="color: #000088;">$settings</span> <span style="color: #339933;">=</span>	<span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$hook</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span>
				<span style="color: #0000ff;">'extension_id'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'class'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'method'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'run'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'hook'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hook_to_process_extension_on'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'settings'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #990000;">serialize</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$settings</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'priority'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'version'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">version</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'enabled'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'y'</span>
		<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert_string</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'exp_extensions'</span><span style="color: #339933;">,</span>	<span style="color: #000088;">$hook</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Update Extension
	 *
	 * This function performs any necessary db updates when the extension
	 * page is visited
	 *
	 * @return 	mixed	void on update / false if none
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> update_extension<span style="color: #000;">&#40;</span><span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$DB</span><span style="color: #339933;">,</span> <span style="color: #000088;">$EXT</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$current</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">version</span><span style="color: #000;">&#41;</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;SELECT settings FROM exp_extensions WHERE class = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape_str</span><span style="color: #000;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #000;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'settings'</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update_string</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'exp_extensions'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'settings'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">serialize</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'version'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">version</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span>
&nbsp;
		<span style="color: #22f;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Disable Extension
	 *
	 * This method removes information from the exp_extensions table
	 *
	 * @return void
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> disable_extension<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$DB</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$DB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM exp_extensions WHERE class = '&quot;</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Method to execute when hook is called
	 * @param mixed $data
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #000;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//process</span>
	<span style="color: #000;">&#125;</span>
<span style="color: #000;">&#125;</span></pre></td></tr></table></div>

<p>Most of the above should be self explanatory but just in case what&#8217;s going on is that most of the class variables are used for extension details and there are 3 methods for activating, deactivating and removing the extension. The methods for activation management are important, especially the activation method &#8220;activate_extension&#8221; which contains the details about the extension including the hook to execute on along with the method name to execute when the hook is called. In the above example, the extension will execute the method &#8220;run&#8221; when the hook &#8220;hook_to_process_extension_on&#8221; is called. Thankfully, ExpressionEngine hasn&#8217;t done away with the <a href="http://expressionengine.com/developers/extension_hooks/" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Fdevelopers%2Fextension_hooks%2F','All+Extension+Hooks')" title="All Extension Hooks" target="_blank">list of hooks available in the 1.x</a> branch.</p>
<p>Obviously, the above extension is pretty useless, what with not <em>doing</em> anything, but that&#8217;s all you&#8217;re gonna need to have the extension listed in the Extension Manager. To further personalize and customize (huh&#8230; I&#8217;m a poet) the details of your extension you can add settings and, if you want people to have the ability to change those settings, you can add a settings page by.</p>
<p>To add a settings page to your extension things get a little complicated at first but it&#8217;s not so bad. All you have to do is set the class variable $settings_exist to &#8220;y&#8221;, create a new method called &#8220;settings()&#8221; that EE uses and modify your extension language file (should be created inside the &#8220;lang&#8221; directory using the convention of &#8220;lang.extension_name&#8221;). The settings() function should contain an associative array with the key being the name of the setting and any default value for that setting like the below:</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: #000000; font-weight: bold;">function</span> settings<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$settings</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'pissoff_find'</span><span style="color: #000;">&#93;</span>		<span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$settings</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'pissoff_replace'</span><span style="color: #000;">&#93;</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'this is the default value'</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">return</span> <span style="color: #000088;">$settings</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>Using the above will simply display a form with 2 text boxes for input. If no value is provided for the second item then there&#8217;ll be a default used. Simple. But, if you want to use, say, radio buttons or select boxes you have to make a couple modifications like the below:</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: #000000; font-weight: bold;">function</span> settings<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$settings</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'pissoff_find'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'t'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Default!!'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$settings</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'pissoff_replace'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'nothing'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Nothing&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'something'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Something&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'something'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">return</span> <span style="color: #000088;">$settings</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>The above will create a new setting form with a textarea for the first option and a radio fieldgroup for the second. Make sure you add the radio option text to your language file though; it won&#8217;t do that automatically. Also, you&#8217;re not locked into just radio and textareas; you can also have select boxes (s) and multi-select boxes (ms) by updating the relevant array key. </p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2010/09/developing-expressionengine-1-6x-extensions/' addthis:title='Developing ExpressionEngine 1.6x Extensions '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/09/developing-expressionengine-1-6x-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP-Click-Track 0.7.2 Released</title>
		<link>http://blog.ericlamb.net/2010/08/wp-click-track-0-7-2-released/</link>
		<comments>http://blog.ericlamb.net/2010/08/wp-click-track-0-7-2-released/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 21:07:03 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wp-click-track]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3371</guid>
		<description><![CDATA[Today I finally found the time to release an update to wp-click-track with a few bugs that some users have been encountering. This release is purely a bug fix release so there won&#8217;t be any new bells or whistles but if you run IIS 6 or want to clear out some links or reset your [...]]]></description>
			<content:encoded><![CDATA[<p>Today I finally found the time to release an update to wp-click-track with a few bugs that some users have been encountering. This release is purely a bug fix release so there won&#8217;t be any new bells or whistles but if you run IIS 6 or want to clear out some links or reset your system you&#8217;re in luck. The only &#8220;interesting&#8221; bug that was fixed was the IIS6 HTTPS issue.</p>
<div id="attachment_3374" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2010/08/microsoft-logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2010%2F08%2Fmicrosoft-logo.png','WP-Click-Track+0.7.2+Released')"><img src="http://blog.ericlamb.net/wp-content/uploads/2010/08/microsoft-logo-300x220.png" alt="WP-Click-Track 0.7.2 Released" title="WP-Click-Track 0.7.2 Released" width="300" height="220" class="size-medium wp-image-3374" /></a><p class="wp-caption-text">WP-Click-Track 0.7.2 Released</p></div>
<p>Because of how IIS6 and PHP populate the $_SERVER['HTTPS'] value some users were experiencing issues with their stats page. Turns out that <a href="http://php.net/manual/en/reserved.variables.server.php" onclick="return TrackClick('http%3A%2F%2Fphp.net%2Fmanual%2Fen%2Freserved.variables.server.php','IIS6+will+return+a+value+of+off')" title="IIS6 will return a value of off" target="_blank">IIS6 will return a value of &#8220;off&#8221;</a> if the request wasn&#8217;t made through HTTPS instead of the default behavior of returning a boolean. So, while the below code will work with Apache and newer versions of IIS, IIS6 creates a bit of a false positive:</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: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTPS'</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//server has HTTPS but IIS6 will always think it's on</span>
<span style="color: #000;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Instead, it&#8217;s better to check the value along with the existance check like:</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: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTPS'</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTPS'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'off'</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//server has HTTPS and IIS6 is being account for</span>
<span style="color: #000;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Go Microsoft <img src='http://blog.ericlamb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2010/08/wp-click-track-0-7-2-released/' addthis:title='WP-Click-Track 0.7.2 Released '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/08/wp-click-track-0-7-2-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ExpressionEngine White Screen Fix</title>
		<link>http://blog.ericlamb.net/2010/07/expressionengine-white-screen/</link>
		<comments>http://blog.ericlamb.net/2010/07/expressionengine-white-screen/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 07:00:32 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=3326</guid>
		<description><![CDATA[The more I work with ExpressionEngine the more I keep running into the same issues. ExpressionEngine hides most error messages, especially those related to configuration, probably for security, but this doesn&#8217;t make debugging any easier. To be fair, I don&#8217;t know if this is how ExpressionEngine works out of the box or if this is [...]]]></description>
			<content:encoded><![CDATA[<p>The more I work with <a href="http://expressionengine.com" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com','ExpressionEngine')" target="_blank" title="ExpressionEngine">ExpressionEngine</a> the more I keep running into the same issues. ExpressionEngine hides most error messages, especially those related to configuration, probably for security, but this doesn&#8217;t make debugging any easier. To be fair, I don&#8217;t know if this is how ExpressionEngine works out of the box or if this is a configuration setup done by the projects original developers but it does make fixing the issue that much harder.</p>
<div id="attachment_3333" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2010/07/whitescreen.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2010%2F07%2Fwhitescreen.jpg','Expression+Engine+White+Screen')"><img class="size-medium wp-image-3333" title="Expression Engine White Screen" src="http://blog.ericlamb.net/wp-content/uploads/2010/07/whitescreen-300x300.jpg" alt="ExpressionEngine White Screen" width="300" height="300" /></a><p class="wp-caption-text">ExpressionEngine White Screen</p></div>
<h3>Admin White Screen</h3>
<p>I&#8217;ve only come across the administration area throwing a white screen when using ExpressionEngine 1.67 on a PHP 5.3 server and only if extensions are enabled. I&#8217;m not sure if the newer versions of the 1.x branch have this fixed so this might not work for you.</p>
<p>The issue has to do with how the variables are being passed and called; PHP 5.3 changed how references were handled so the method ExpressionEngine 1.67 uses no longer works. To fix you have to modify &#8220;/system/core/core.extensions.php&#8221; with the below changes that are on the <a href="http://expressionengine.com/archived_forums/viewthread/121802/#603928" onclick="return TrackClick('http%3A%2F%2Fexpressionengine.com%2Farchived_forums%2Fviewthread%2F121802%2F%23603928','ExpressionEngine+forums')" target="_blank" title="ExpressionEngine forums">ExpressionEngine forums</a>:</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: #666666; font-style: italic;">//system/core/core.extensions.php around line 115 modify:</span>
<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #990000;">sizeof</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
    <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$which</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #990000;">version_compare</span><span style="color: #000;">&#40;</span><span style="color: #009900; font-weight: bold;">PHP_VERSION</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'5.3'</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
    <span style="color: #22f;">foreach</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #22f;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #000;">&#41;</span>
    <span style="color: #000;">&#123;</span>
        <span style="color: #000088;">$args</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$args</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000;">&#125;</span>            
<span style="color: #000;">&#125;</span>  
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//and likewise around line 174 modify:</span>
<span style="color: #000;">&#123;</span>
    <span style="color: #000088;">$php4_object</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #000;">&#40;</span><span style="color: #990000;">func_get_args</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #990000;">version_compare</span><span style="color: #000;">&#40;</span><span style="color: #009900; font-weight: bold;">PHP_VERSION</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'5.3'</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
    <span style="color: #22f;">foreach</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #22f;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #000;">&#41;</span>
    <span style="color: #000;">&#123;</span>
        <span style="color: #000088;">$args</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$args</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000;">&#125;</span>            
<span style="color: #000;">&#125;</span>  
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Front End White Screen</h3>
<p>Then there&#8217;s the front end white screen; so far I&#8217;ve encountered this type of white screen in both the 1.6 and 2.0 branches of ExpressionEngine. Luckily, whenever I&#8217;ve ran into a white screen on the front site it&#8217;s always due to various path configurations which is easily fixed by over riding the configuration file. </p>
<p>Expression Engine is <a href="http://blog.ericlamb.net/2010/07/portability-is-a-good-thing/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2010%2F07%2Fportability-is-a-good-thing%2F','Portability+Is+A+Good+Goal')" title="Portability Is A Good Goal">one of those programs</a> that stores as much as possible in the database including file and path directory paths. To get around this permanently I&#8217;ve gotten in the habit of using a default config.php file for all any Expression Engine site I work on; it&#8217;s the first thing I do before anything else.</p>
<p>This new configuration file uses the $_SERVER super global to dynamically determine the paths and makes allowances for development, staging and production environments.</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: #22f;">if</span> <span style="color: #000;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'EXT'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#123;</span>
	<span style="color: #990000;">exit</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'Invalid file request'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'app_version'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;167&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'license_number'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'debug'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'install_lock'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_hostname'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_username'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_password'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_name'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'dev.site.com'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_hostname'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_username'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_password'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_name'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
<span style="color: #22f;">elseif</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'stage.site.com'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span>
<span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_hostname'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_username'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_password'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_name'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>	
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'avatar_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/avatars/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'avatar_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/avatars/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'photo_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/member_photos/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'photo_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/member_photos/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'sig_img_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/signature_attachments/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'sig_img_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/signature_attachments/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'prv_msg_upload_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/pm_attachments/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'theme_folder_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/themes/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'site_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'captcha_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/captchas/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'captcha_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/captchas/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'emoticon_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/images/smileys/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'theme_folder_path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/themes/&quot;</span><span style="color: #339933;">;</span>	
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_type'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_prefix'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;exp&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'db_conntype'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'system_folder'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;system&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'cp_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'system_folder'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/index.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'doc_url'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://expressionengine.com/docs/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'cookie_prefix'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'is_system_on'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'allow_extensions'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conf</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'multiple_sites_enabled'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;n&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The above config is for the 1.x branch though most values should work for the 2.x branch with the addition of $config['tmpl_file_basepath'].</p>
<p>Hopefully, this should take care of those white screens.</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2010/07/expressionengine-white-screen/' addthis:title='ExpressionEngine White Screen Fix '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/07/expressionengine-white-screen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

