<?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>Witheringtree</title>
	<atom:link href="http://www.witheringtree.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.witheringtree.com</link>
	<description>If a tree falls in the forest and no one is around to hear it fall… yeah, it still makes a sound.</description>
	<lastBuildDate>Sat, 05 May 2012 15:15:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Disable .MobileBackup on Lion</title>
		<link>http://www.witheringtree.com/2012/03/disable-mobilebackup-on-lion/</link>
		<comments>http://www.witheringtree.com/2012/03/disable-mobilebackup-on-lion/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 04:05:27 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=976</guid>
		<description><![CDATA[For the last week I&#8217;ve been without the Internet. Let me tell you, it&#8217;s killing me. Blah blah blah. Suddenly, the amount of free space I have on my hard drive went from about 200Gb to 24Gb. Turns out it is Time Machine on Lion. If Time Machine is enabled but it can&#8217;t back up &#8230; <a href="http://www.witheringtree.com/2012/03/disable-mobilebackup-on-lion/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For the last week I&#8217;ve been without the Internet. Let me tell you, it&#8217;s killing me. Blah blah blah. Suddenly, the amount of free space I have on my hard drive went from about 200Gb to 24Gb. Turns out it is Time Machine on Lion. If Time Machine is enabled but it can&#8217;t back up the the Time Machine drive, it will still back it up to your internal hard drive under a hidden .MobileBackups directory in the root of your drive. This feature is only active for laptops. It is also available for desktops, though it must be enabled.</p>
<p>For me, this is a bad thing since I won&#8217;t have internet for another week. This feature can be disabled. Open Terminal and type (or copy/paste) the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sudo tmutil disablelocal</pre></div></div>

<p>A reboot is going to be required before this take effect.</p>
<p>If you ever want to re-enable it, you would open Terminal again and type:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sudo tmutil enablelocal</pre></div></div>

<p>Once again, a reboot is going to be re</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2012/03/disable-mobilebackup-on-lion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Overloading Codeigniter DB Driver</title>
		<link>http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/</link>
		<comments>http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 16:53:03 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=972</guid>
		<description><![CDATA[Working with Microsoft SQL Server and PHP isn&#8217;t always the easiest thing to do. There are always like quarks you have to work around and even big problems that have to be fixed before anything else can be done. One of the most annoying things I have found is that MSSQL doesn&#8217;t have an offset &#8230; <a href="http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Working with Microsoft SQL Server and PHP isn&#8217;t always the easiest thing to do. There are always like quarks you have to work around and even big problems that have to be fixed before anything else can be done.</p>
<p>One of the most annoying things I have found is that MSSQL doesn&#8217;t have an offset like MySQL does. Offsets are great for pagination. If you have 1000 records and you want to pull 200 records at at time, you would limit the number of records to 200 (TOP 200). But how do you get to page two? That&#8217;s where offset comes in. Let&#8217;s says you want to get the top X records, but offset by Y records. Without offset, the only decent way I could think of to do pagination was to pull the top 400 and in the PHP code I split off the first 200 records that I don&#8217;t need. That gets pretty ugly if there are 10k records and you are displaying 10 records at a time. By the last page, your query is taking way to long to return results when you aren&#8217;t using 99% of them.</p>
<p>All that being said, I am working on a project built with Codeigniter that connects to a MSSQL database. Codeigniter has some pretty good DB libraries so most things work just fine. My two big problems are offset and batch insert and batch update (more on batch in a later post). We don&#8217;t want to go into the Codeigniter system directory and start changing things as we see fit. If we dod that, we can never update Codeigniter at a later date. The answer is to overload, or extend, the Codeigniter database driver. What we have to do is extend a function in the system/core/Loader.php file. To do this, in application/core/ create a file named MY_Loader.php. Just to reiterate, this file goes in application/core/ NOT application/libraries/ If you have changed the subclass_prefix config value to something other than MY_ then you will need to rename the file accordingly. Next, copy/paste the code below into the file you just created.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MY_Loader <span style="color: #000000; font-weight: bold;">extends</span> CI_Loader <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> database<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span> <span style="color: #000088;">$active_record</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Grab the super object</span>
		<span style="color: #000088;">$CI</span> <span style="color: #339933;">=&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Do we even need to load the database class?</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CI_DB'</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$return</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span> AND <span style="color: #000088;">$active_record</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">NULL</span> AND <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #009900;">&#41;</span> AND <span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'database/DB.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> DB<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #000088;">$active_record</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Load extended DB driver</span>
		<span style="color: #000088;">$custom_db_driver</span> <span style="color: #339933;">=</span> config_item<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'subclass_prefix'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'DB_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbdriver</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_driver'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$custom_db_driver_file</span> <span style="color: #339933;">=</span> APPPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'core/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$custom_db_driver</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$custom_db_driver_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$custom_db_driver_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$custom_db_driver</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Return DB instance</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Initialize the db variable. Needed to prevent reference errors with some configurations</span>
		<span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above code is pretty much the same thing found in system/core/Loader.php with some changes to make it look in application/core/ for your extensions to the database drivers. If there aren&#8217;t any database extensions, no big deal. It will continue on like normal.</p>
<p>So the next thing we have to do is create a file named MY_DB_mssql_driver.php in application/core/ Again, this file goes in application/core/ NOT application/libraries/ and if you have changed the subclass_prefix config value to something other than MY_ then you will need to rename the file accordingly. In my case, I am extending the MSSQL database driver so my file is named MY_DB_mssql_driver.php. If you are extending the MySQL driver, then you would name it MY_DB_mysql_driver.php. Next, copy/paste the following code into the MY_DB_mssql_driver.php file you just created</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MY_DB_mssql_driver <span style="color: #000000; font-weight: bold;">extends</span> CI_DB_mssql_driver <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Limit string
	 *
	 * Generates a platform-specific LIMIT clause
	 *
	 * @param	string	the sql query string
	 * @param	integer	the number of rows to limit the query to
	 * @param	integer	the offset value
	 * @return	string
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> _limit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(^\SELECT (DISTINCT)?)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'\\1 TOP '</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_orderby</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$ordeR_by</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ORDER BY &quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$ordeR_by</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_orderby</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_order</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$ordeR_by</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ar_order</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' DESC'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">' ASC'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(\\'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$ordeR_by</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'\n?)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(^\SELECT (DISTINCT)?)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'\\1 row_number() OVER ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$ordeR_by</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') AS rownum, '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;SELECT * <span style="color: #000099; font-weight: bold;">\n</span>FROM (<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;) AS A <span style="color: #000099; font-weight: bold;">\n</span>WHERE A.rownum BETWEEN (&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) AND (&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Query must have an order_by clause in order to be offset.'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above code is a direct copy/paste from the code <a href="http://codeigniter.com/forums/member/88927/" target="_blank">Kyle Johnson</a> on is <a href="http://codeigniter.com/forums/viewthread/160626/#959597" target="_blank">Codeigniter forum post</a>. All it does is check if an offset is being passed. If there is, then it builds a subquery to create the offset. If the offset is not defined or is 0, then it does the normal function does.</p>
<p>The only thing you have to do now is run your application. There shouldn&#8217;t be any additional changes to any libraries or to your SQL calls.</p>
<p>Again, the files for this post have been committed to <a href="https://github.com/dfreerksen/ci-overload-db" target="_blank">Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2012/02/overloading-codeigniter-db-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorry</title>
		<link>http://www.witheringtree.com/2012/02/sorry/</link>
		<comments>http://www.witheringtree.com/2012/02/sorry/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 15:55:30 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Self]]></category>
		<category><![CDATA[Website]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=968</guid>
		<description><![CDATA[I&#8217;ve been horrible with making posts. I keep forgetting or I tell myself I&#8217;ll do it tomorrow. I&#8217;ll try to do better from now on. Soon to come though, at some point I want to switch away from WordPress and build this site on PyroCMS. PyroCMS is build on Codeigniter, which I love and know &#8230; <a href="http://www.witheringtree.com/2012/02/sorry/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been horrible with making posts. I keep forgetting or I tell myself I&#8217;ll do it tomorrow. I&#8217;ll try to do better from now on.</p>
<p>Soon to come though, at some point I want to switch away from WordPress and build this site on PyroCMS. PyroCMS is build on Codeigniter, which I love and know try well. So maybe I can build some plugins for it after I switch over. I&#8217;m also learning Backbone.js and Node.js so that should be interesting. Eventually I&#8217;ll post code also.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2012/02/sorry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#8217;t Argue With That Logic</title>
		<link>http://www.witheringtree.com/2012/01/cant-argue-with-that-logic/</link>
		<comments>http://www.witheringtree.com/2012/01/cant-argue-with-that-logic/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 02:07:39 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Self]]></category>
		<category><![CDATA[Cool]]></category>
		<category><![CDATA[Funny]]></category>
		<category><![CDATA[Me]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=964</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.witheringtree.com/wp-content/uploads/2012/01/logic.png" rel="shadowbox[sbpost-964];player=img;"><img class="alignnone size-medium wp-image-965" title="Can't Argue With That Logic" src="http://www.witheringtree.com/wp-content/uploads/2012/01/logic-300x277.png" alt="" width="300" height="277" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2012/01/cant-argue-with-that-logic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Dream Team</title>
		<link>http://www.witheringtree.com/2011/12/the-dream-team/</link>
		<comments>http://www.witheringtree.com/2011/12/the-dream-team/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 05:35:04 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=960</guid>
		<description><![CDATA[Torus Marketing]]></description>
			<content:encoded><![CDATA[<p>Torus Marketing<br />
<a href="http://www.witheringtree.com/wp-content/uploads/2011/12/390532_312310245456265_170819309605360_1007615_2090785016_n.jpg" rel="shadowbox[sbpost-960];player=img;"><img src="http://www.witheringtree.com/wp-content/uploads/2011/12/390532_312310245456265_170819309605360_1007615_2090785016_n-300x214.jpg" alt="" title="Torus Marketing" width="300" height="214" class="alignnone size-medium wp-image-961" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/12/the-dream-team/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add a digital signature to a PDF using Preview</title>
		<link>http://www.witheringtree.com/2011/11/add-a-digital-signature-to-a-pdf-using-preview/</link>
		<comments>http://www.witheringtree.com/2011/11/add-a-digital-signature-to-a-pdf-using-preview/#comments</comments>
		<pubDate>Sun, 06 Nov 2011 16:07:01 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Apple Software]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=954</guid>
		<description><![CDATA[Apple always builds all kinds of hidden things into their stuff. Today I had to sign a contract. The contract was sent over as a PDF. I really didn’t want to print it, sign it, and mail or fax it back or rescan it and email it back. I don’t have a scanner and I &#8230; <a href="http://www.witheringtree.com/2011/11/add-a-digital-signature-to-a-pdf-using-preview/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Apple always builds all kinds of hidden things into their stuff. Today I had to sign a contract. The contract was sent over as a PDF. I really didn’t want to print it, sign it, and mail or fax it back or rescan it and email it back. I don’t have a scanner and I don’t have a printer. I started playing with Preview and it turns out, it’s built in now. This is available in Lion.</p>
<ol>
<li>Open the PDF that needs a signature with Preview.</li>
<li>Click the <strong>Annotate</strong> tab to display the annotate toolbar.</li>
<li>Select the <strong>Signature</strong> button.</li>
<li>If you do not have a signature loaded already, click <strong>Create Signature from Built-In iSight&#8230;</strong>. If you already have one loaded, skip to step 7<br /><a href="http://www.witheringtree.com/wp-content/uploads/2011/11/signature_annotate.png" rel="shadowbox[sbpost-954];player=img;"><img src="http://www.witheringtree.com/wp-content/uploads/2011/11/signature_annotate-300x80.png" alt="" title="signature_annotate" width="300" height="80" class="alignnone size-medium wp-image-956" /></a></li>
<li>In the <strong>Signatures</strong> tab, click <strong>Create Signature&#8230;</strong></li>
<li>Sign your name to a white piece of paper and hold it up to your iSight camera.</li>
<li>Click <strong>Accept</strong> when your signature is positioned correctly inside the preview area.<br /><a href="http://www.witheringtree.com/wp-content/uploads/2011/11/signature_capture.png" rel="shadowbox[sbpost-954];player=img;"><img src="http://www.witheringtree.com/wp-content/uploads/2011/11/signature_capture-300x146.png" alt="" title="signature_capture" width="300" height="146" class="alignnone size-medium wp-image-957" /></a></li>
<li>With the Signature button selected (it should be blue), click and drag where you want to place your signature.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/11/add-a-digital-signature-to-a-pdf-using-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Now I&#8217;m Confused</title>
		<link>http://www.witheringtree.com/2011/09/now-im-confused/</link>
		<comments>http://www.witheringtree.com/2011/09/now-im-confused/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 03:24:32 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Funny]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=950</guid>
		<description><![CDATA[I&#8217;m working on a Magento module and I got an error message saying &#8220;An error occurred while saving the page.&#8221; Right under it I gut a success message saying &#8220;The page has been saved.&#8221;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a Magento module and I got an error message saying &#8220;An error occurred while saving the page.&#8221; Right under it I gut a success message saying &#8220;The page has been saved.&#8221;</p>
<p><a href="http://www.witheringtree.com/wp-content/uploads/2011/09/fail_but_save.png" rel="shadowbox[sbpost-950];player=img;"><img class="alignnone size-medium wp-image-951" title="fail_but_save" src="http://www.witheringtree.com/wp-content/uploads/2011/09/fail_but_save-300x234.png" alt="" width="300" height="234" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/now-im-confused/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom CodeIgniter Validation Methods</title>
		<link>http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/</link>
		<comments>http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 21:12:05 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=944</guid>
		<description><![CDATA[CodeIgniter&#8217;s Form Validation library isn&#8217;t bad. It takes a little getting use to but it can be very powerful. Most of the validation that comes with CodeIgniter are pretty much the only ones you will ever need. Every now and then you will need something else. Extending CodeIgniter libraries is very easy. These are some &#8230; <a href="http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter&#8217;s <a href="http://codeigniter.com/user_guide/libraries/form_validation.html" title="CodeIgniter Form Validation" target="_blank">Form Validation</a> library isn&#8217;t bad. It takes a little getting use to but it can be very powerful. Most of the validation that comes with CodeIgniter are pretty much the only ones you will ever need. Every now and then you will need something else. <a href="http://codeigniter.com/user_guide/general/creating_libraries.html" title="Creating and Extending CodeIgniter Libraries" target="_blank">Extending CodeIgniter libraries</a> is very easy. These are some of the custom form validation I&#8217;ve had to do in previous projects</p>
<p>First of all, you have to create a library that will extend CodeIgniter&#8217;s library. Create a new file named MY_Form_validation.php and put it in the application/libraries/ directory. Here is what that library will look 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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MY_Form_validation <span style="color: #000000; font-weight: bold;">extends</span> CI_Form_validation <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$CI</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span> <span style="color: #339933;">=&amp;</span> get_instance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The first validation method I used for a project where the user would enter a fraction and I didn&#8217;t really want to convert a decimal to a fraction. So I just created a validation method.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Fraction
 *
 * @access  public
 * @param   string  $str
 * @return  bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fraction<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fraction'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s field must be a valid fraction.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^(\d++(?! */))? *-? *(?:(\d+) */ *(\d+))?.*$/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'screen_size'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Screen Size'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fraction'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This was a fun validation to make. When a user signs up or is changing their password, their password must be <a href="http://www.pcicomplianceguide.org/" title="PCI Compliance" target="_blank">PCI compliant</a>. For a password to be PCI compliant, it must meet the following:<br />
1) Must be between 6 and 99 characters in length<br />
2) Must not contain two consecutively repeating characters<br />
3) Must contain at least one upper-case letter<br />
4) Must contain at least one lower-case letter<br />
5) Must contain at least one number<br />
6) Must contain at least one special character</p>
<p>Please note that the validation message is really long. You may want to simplify it a little before using it</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * PCI compliance password
 *
 * @access  public
 * @param   $str
 * @return  bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pci_password<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$special</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'!@#$%*-_=+.'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pci_password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'For PCI compliance, %s must be between 6 and 99 characters in length, must not contain two consecutively repeating characters, contain at least one upper-case letter, at least one lower-case letter, at least one number, and at least one special character ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$special</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^(?=^.{6,99}$)(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*['</span><span style="color: #339933;">.</span><span style="color: #000088;">$special</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'])(?!.*?(.)\1{1,})^.*$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">TRUE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pci_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>CodeIgniter already has a validation method for <em>required</em>. But I needed one to be required if a different field had a value. A couple weeks later I needed to have method to make a field required if another field had a certain value.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Required if another field has a value (related fields) or if a field has a certain value
 *
 * @access  public
 * @param   string  $str
 * @param   string  $field
 * @return  bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> required_if<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fld</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required_if'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s field is required.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// $fld is filled out</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$fld</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Must have specific value</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Not the specific value we are looking for</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$fld</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$val</span> AND <span style="color: #339933;">!</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required_if[foo]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// required if field 'foo' has a value</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foobar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Foo Bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required_if[foo,bar]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// required if field 'foo' has a value of 'bar'</span></pre></div></div>

<p>There are a lot of examples of this validation floating around. It requires that a value being passed has a unique value in the database. This one also takes into account the database prefix.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Unique
 *
 * @access	public
 * @param	string
 * @param	field
 * @return	bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> unique<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'unique'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s that you requested is already in use.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<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;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) AS dupe FROM {<span style="color: #006699; font-weight: bold;">$this-&gt;CI</span>-&gt;db-&gt;dbprefix(<span style="color: #006699; font-weight: bold;">$table</span>)} WHERE <span style="color: #006699; font-weight: bold;">{$column}</span> = '<span style="color: #006699; font-weight: bold;">{$str}</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dupe</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unique[DBTABLE,DBFIELD]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// DBTABLE is the database table and DBFIELD is the database field to validation against</span></pre></div></div>

<p>I took the previous validation a step further so that the field value must be unique in the database EXCEPT for a certain record ID. This one is really good for if you have an existing user in the system and they are updating their profile. You want to make sure that their email address is unique. If you run the previous <em>unique</em> validation it will fail because the email address is already in use by the user currently being edited. So we need to exclude that users ID from the validation. This one also takes into account the database prefix.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Unique except. Check if a specific value is in use except when the value is attached to a specific row ID
 *
 * @param	string
 * @param	field
 * @return	bool
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> unique_exclude<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$column</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fld</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'unique_exclude'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The %s that you requested is already in use.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<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;">CI</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) AS dupe FROM {<span style="color: #006699; font-weight: bold;">$this-&gt;CI</span>-&gt;db-&gt;dbprefix(<span style="color: #006699; font-weight: bold;">$table</span>)} WHERE <span style="color: #006699; font-weight: bold;">{$column}</span> = '<span style="color: #006699; font-weight: bold;">$str</span>' AND <span style="color: #006699; font-weight: bold;">{$fld}</span> &lt;&gt; <span style="color: #006699; font-weight: bold;">{$id}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dupe</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unique[DBTABLE,DBFIELD,IDFIELD,ID]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// DBTABLE is the database table, DBFIELD is the database field, IDFIELD is the primary key for the table, and ID is the unique ID for the user</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/custom-codeigniter-validation-methods/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross Browser Support for inline-block in CSS</title>
		<link>http://www.witheringtree.com/2011/09/cross-browser-support-for-inline-block-in-css/</link>
		<comments>http://www.witheringtree.com/2011/09/cross-browser-support-for-inline-block-in-css/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 00:44:17 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=940</guid>
		<description><![CDATA[I&#8217;ve been using this method for cross browser inline-block displays for a while and thought everyone else knew about it too. One of my co-workers was shocked to find out they had been doing it wrong for so long. So I thought I would share it in case someone else didn&#8217;t know about it. Inline-block &#8230; <a href="http://www.witheringtree.com/2011/09/cross-browser-support-for-inline-block-in-css/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using this method for cross browser inline-block displays for a while and thought everyone else knew about it too. One of my co-workers was shocked to find out they had been doing it wrong for so long. So I thought I would share it in case someone else didn&#8217;t know about it. </p>
<p>Inline-block is very powerful. It is very useful for horizontal lists and even makes vertical alignment work properly. Unfortunately, it’s supported pretty poorly. *cough*Internet Explorer*cough*</p>
<p>Older versions of Firefox support inline-block with a special &#8220;-moz&#8221; tag. But not the one you think. It uses &#8216;-moz-inline-stack&#8217; instead of &#8216;-moz-inline-block&#8217;. And when I say older versions I mean anything before version 4 I believe. So really, you don&#8217;t have to add it if you don&#8217;t want to. I don&#8217;t. But if you keep it, make sure &#8216;display:-moz-inline-stack&#8217; comes BEFORE &#8216;display:inline-block&#8217; so newer versions of Firefox can use the standard style.</p>
<p>IE supports inline-block, but only for elements that are natively inline, such as span and strong. When &#8216;zoom: 1&#8242; is set, it triggers hasLayout and magically IE supports inline-block. The *property is an IE hack that does not get run for non-IE browsers.</p>
<p>So, without further adieus, cross-browser inline-block support:</p>
<pre>
.myStyle {
	display: -moz-inline-stack;  /* optional */
	display: inline-block;
	zoom: 1;  /* triggers hasLayout for IE */
	*display: inline;  /* target IE7 only */
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/cross-browser-support-for-inline-block-in-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocks in Magento</title>
		<link>http://www.witheringtree.com/2011/09/blocks-in-magento/</link>
		<comments>http://www.witheringtree.com/2011/09/blocks-in-magento/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 00:41:11 +0000</pubDate>
		<dc:creator>David Freerksen</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.witheringtree.com/?p=937</guid>
		<description><![CDATA[One of the things Magento got right is blocks. It&#8217;s one of the few things I am continually impressed by. There are a lot of ways to add a static block to the page. XML is probably the most common place to add a static block. You find whatever block you want to add your &#8230; <a href="http://www.witheringtree.com/2011/09/blocks-in-magento/" title="Continue reading">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the things Magento got right is blocks. It&#8217;s one of the few things I am continually impressed by. There are a lot of ways to add a static block to the page.</p>
<p><strong>XML</strong> is probably the most common place to add a static block. You find whatever block you want to add your static block into and you add something like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;block</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;cms/block&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOUR_BLOCK_ID&quot;</span> <span style="color: #000066;">before</span>=<span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;setBlockId&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>YOUR_BLOCK_ID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Adding a static clock through <strong>layout XML</strong> can be very useful if you need to add a static block to a sidebar on a single page for example instead of all pages.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;left&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;block</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;cms/block&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOUR_BLOCK_ID&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;setBlockId&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>YOUR_BLOCK_ID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block_id<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/reference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Adding you static block through <strong>PHP</strong> may be the least common way. This, however, can be very useful if you want to define areas in your theme where a menu or a widgets could go. To add a static block in PHP you would use:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cms/block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBlockId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'YOUR_BLOCK_ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toHtml</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Adding a static block through a short code is very powerful. It allows you to add a static block into a CMS page or even your products.</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #D36900;">&#123;</span>block type<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;cms/block&quot;</span> block_id<span style="color: #D36900;">=</span><span style="color: #ff0000;">&quot;YOUR_BLOCK_ID&quot;</span><span style="color: #D36900;">&#125;</span>}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.witheringtree.com/2011/09/blocks-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

