<?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>Garrett St. John &#187; CodeIgniter</title>
	<atom:link href="http://garrettstjohn.com/topics/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://garrettstjohn.com</link>
	<description>I am a web developer and partner at Bold. This is where I share my thoughts, discoveries and other random bits.</description>
	<lastBuildDate>Thu, 17 May 2012 18:12:49 +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>Loading environment-specific configuration files in CodeIgniter</title>
		<link>http://garrettstjohn.com/entry/loading-environment-specific-configuration-files-codeigniter/</link>
		<comments>http://garrettstjohn.com/entry/loading-environment-specific-configuration-files-codeigniter/#comments</comments>
		<pubDate>Thu, 17 May 2012 18:12:49 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=588</guid>
		<description><![CDATA[About a year ago, CodeIgniter got the addition of an ENVIRONMENT constant which saved me a lot of headaches with managing difference between my various environments (development, staging, production). // Conditional I add to index.php to self-determine the environment if ($_SERVER['SERVER_NAME'] == 'mysite.dev') { define('ENVIRONMENT', 'development'); } else { define('ENVIRONMENT', 'production'); } if (defined('ENVIRONMENT')) { [<a href="http://garrettstjohn.com/entry/loading-environment-specific-configuration-files-codeigniter/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>About a year ago, CodeIgniter got the addition of an <code>ENVIRONMENT</code> constant which saved me a lot of headaches with managing difference between my various environments (development, staging, production).</p>
<pre class="brush: php">
// Conditional I add to index.php to self-determine the environment
if ($_SERVER['SERVER_NAME'] == 'mysite.dev')
{
	define('ENVIRONMENT', 'development');
}
else
{
	define('ENVIRONMENT', 'production');
}

if (defined('ENVIRONMENT'))
{
	switch (ENVIRONMENT)
	{
		case 'development':
			error_reporting(-1);
		break;
		case 'testing':
		case 'production':
			error_reporting(0);
		break;
		default:
			exit('The application environment is not set correctly.');
	}
}
</pre>
<p>Not only is it great for setting up server configurations like error reporting, it&#8217;s perfect for use in config files as well.</p>
<pre class="brush: php">
// Cloud asset bucket
switch (ENVIRONMENT) {
case 'development':
	$config['s3_bucket'] = 'mybucket_develop';
break;

case 'staging':
	$config['s3_bucket'] = 'mybucket_staging';
break;

case 'production':
default:
	$config['s3_bucket'] = 'mybucket_production';
break;
}
</pre>
<p>Instead of having to ignore configuration files in Git to handle the differences in production vs. development, now all that is necessary is a conditional to handle the variations.</p>
<p>Fast-forward a year, all the way to yesterday, and I happened upon another great little feature: &#8220;Environment-specific configuration files.&#8221; It was really by accident that I stumbled on it and only did because I was searching for <code>ENVIRONMENT</code> in my full CI project.</p>
<pre class="brush: php">
// Is the config file in the environment folder?
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
	$file_path = APPPATH.'config/config.php';
}
</pre>
<p>What! So basically this is telling me that I can have a &#8216;development&#8217; and &#8216;production&#8217; folder inside of my &#8216;application/config&#8217; folder and it will precede the main config.php file. Better yet, it works for all the config files (hooks, constants, routes and even libraries).</p>
<p>I headed to the CI docs and found one paragraph about environment-specific configuration files in the <a href="http://codeigniter.com/user_guide/libraries/config.html#environments">Config class docs</a>. Not exactly prime real estate if you want to get noticed&#8230;</p>
<p>Since this was such a surprise to me, I figured it might be helpful to someone else as well. No more conditionals, no more Git ignores. Nice!</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/loading-environment-specific-configuration-files-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Startup Script</title>
		<link>http://garrettstjohn.com/entry/codeigniter-startup-script/</link>
		<comments>http://garrettstjohn.com/entry/codeigniter-startup-script/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 22:49:36 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=533</guid>
		<description><![CDATA[Ever since CodeIgniter moved over to GitHub I&#8217;ve been interested in figuring out a way to use the EllisLab repository code inline with our specific project code to simplify updates but haven&#8217;t found a great way to go about it. Fairly recently I came across CodeIgniter Starter which is a step in the right directoin: A [<a href="http://garrettstjohn.com/entry/codeigniter-startup-script/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>Ever since CodeIgniter moved over to GitHub I&#8217;ve been interested in figuring out a way to use the EllisLab repository code inline with our specific project code to simplify updates but haven&#8217;t found a great way to go about it.</p>
<p>Fairly recently I came across <a href="https://github.com/sangar82/CodeIgniter-Starter">CodeIgniter Starter</a> which is a step in the right directoin: A GitHub repo that has some configuration and project setup in place. I didn&#8217;t love that it comes with certain Sparks pre-installed and at Bold we run our system files outside of the webroot. Still left me with a decent amount of configuration to get up and running.</p>
<p>I use <a href="http://www.sublimetext.com/2">Sublime Text 2</a> for coding (you probably should be using it too) and recently there was a great Package built by NetTuts called <a href="http://net.tutsplus.com/articles/news/introducing-nettuts-fetch/">NetTuts+ Fetch</a>. It simplifies the retrieval of remote files and packages by downloading them from a preset source and &#8220;injecting&#8221; them into a project. It got my juices flowing again about automating CodeIgniter project setups.</p>
<p>Enter Bash scripting. I&#8217;ve always loved Bash scripts and realized that this was the perfect use case. Let&#8217;s automate all of the steps and configuration that happens on every new CI project with a short command line operation.</p>
<p>As I mentioned, at Bold we run CI system files outside of the webroot. This script retrieves the latest CI version, automates the clean up of the folder structure, installs placeholder asset files, and optionally sets up the Sparks installer (no actual Sparks are installed), adds the project to a local Git repo, pushes the initial commit to a remote Repo, and installs Git Flow. Lots of stuff going on there, but now deploying a new CI project takes about 10-15 seconds from start to finish. Pretty great!</p>
<p><strong>Check out the code and full docs on GitHub at: <a href="https://github.com/bold/codeigniter-startup-script">https://github.com/bold/codeigniter-startup-script</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/codeigniter-startup-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Spark for SendGrid&#8217;s Newsletter API</title>
		<link>http://garrettstjohn.com/entry/codeigniter-spark-sendgrid-newsletter-api/</link>
		<comments>http://garrettstjohn.com/entry/codeigniter-spark-sendgrid-newsletter-api/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 23:28:21 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[SendGrid]]></category>
		<category><![CDATA[Spark]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=513</guid>
		<description><![CDATA[I&#8217;ve submitted my first CodeIgniter library to GetSparks.org in an effort to start giving back to the community that has provided us with so many great tools. This library is a wrapper to the SendGrid Newsletter API and supports all of their provided methods. What is SendGrid? SendGrid is a easy-to-use email delivery service similar to Postmark or Amazon&#8217;s SES. [<a href="http://garrettstjohn.com/entry/codeigniter-spark-sendgrid-newsletter-api/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve submitted my first CodeIgniter library to <a href="http://getsparks.org/">GetSparks.org</a> in an effort to start giving back to the community that has provided us with so many great tools. This library is a wrapper to the <a href="http://docs.sendgrid.com/documentation/api/newsletter-api/">SendGrid Newsletter API</a> and supports all of their provided methods.</p>
<h4>What is SendGrid?</h4>
<p><a href="http://sendgrid.com/">SendGrid</a> is a easy-to-use email delivery service similar to <a href="http://postmarkapp.com/" rel="nofollow">Postmark</a> or Amazon&#8217;s <a href="http://aws.amazon.com/ses/" rel="nofollow">SES</a>. They provide a great way to <a href="http://docs.sendgrid.com/documentation/get-started/integrate/examples/codeigniter-example-using-smtp/">send transactional emails</a> using CodeIgniter&#8217;s core email library and SMTP. However, they also offer a newsletter service at no additional cost which supports recipient lists and send scheduling.</p>
<h4>Where Can I Get It?</h4>
<p>Go grab the library on <a href="http://getsparks.org/packages/sendgrid-newsletter/show">GetSparks</a> or download it on <a href="https://github.com/bold/codeigniter-sendgrid-newsletter">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/codeigniter-spark-sendgrid-newsletter-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing CodeIgniter Packages with Git Submodules</title>
		<link>http://garrettstjohn.com/entry/managing-codeigniter-packages-with-git-submodules/</link>
		<comments>http://garrettstjohn.com/entry/managing-codeigniter-packages-with-git-submodules/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 18:57:05 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=503</guid>
		<description><![CDATA[Link: http://philsturgeon.co.uk/blog/2011/09/managing-codeigniter-packages-with-git-submodules Great post on how to include Git projects within other Git projects as submodules. I&#8217;ve been wanting to do this for a long time!]]></description>
			<content:encoded><![CDATA[<p>Link: <a href="http://philsturgeon.co.uk/blog/2011/09/managing-codeigniter-packages-with-git-submodules">http://philsturgeon.co.uk/blog/2011/09/managing-codeigniter-packages-with-git-submodules</a></p>
<p>Great post on how to include Git projects within other Git projects as submodules. I&#8217;ve been wanting to do this for a long time!</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/managing-codeigniter-packages-with-git-submodules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter US State Helper</title>
		<link>http://garrettstjohn.com/entry/codeigniter-state-helper/</link>
		<comments>http://garrettstjohn.com/entry/codeigniter-state-helper/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 21:45:58 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=449</guid>
		<description><![CDATA[I&#8217;m working on a project today and building a credit card checkout form for what seems like the 1,000th time. It occurred to me that a US State Helper would save me from having to 1)  look up all of the states every time, and 2) dump them into an array and build out functions [<a href="http://garrettstjohn.com/entry/codeigniter-state-helper/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project today and building a credit card checkout form for what seems like the 1,000th time. It occurred to me that a US State Helper would save me from having to 1)  look up all of the states every time, and 2) dump them into an array and build out functions for easy conversions and validation. I figure this may help some people out there, so enjoy!</p>
<h4>Download</h4>
<p>Offered for free and without support: <a href="http://getsparks.org/packages/state-helper/show">Spark</a> or <a href="https://github.com/bold/codeigniter-state-helper">GitHub</a></p>
<h4>Documentation</h4>
<p><strong>Installation</strong></p>
<p>If you are using the Spark, install as usual. Otherwise, the helper file (helpers/state_helper.php) will need to be moved into your &#8216;application/helpers&#8217; project directory.</p>
<p><strong>Configuration</strong></p>
<p>No configuration involved. Just load the helper as your would any other helper.</p>
<pre class="brush: php">&lt;?php
    // Spark
    $this-&gt;load-&gt;spark('state-helper/1.0.0');

    // Or, Helper file
    $this-&gt;load-&gt;helper('state');
?&gt;</pre>
<p><strong>Usage</strong></p>
<p>There are currently four helper functions available to simplify dealing with US states in CodeIgniter.</p>
<ul>
<li><strong>state_array()</strong> — Returns an array of US state names where the array&#8217;s keys are the corresponding two-letter abbreviation.</li>
<li><strong>state_dropdown($name [, $selected [, $id [, $class]]])</strong> — Returns the HTML for a &lt;select&gt; dropdown where the &lt;option&gt; values are the states&#8217; two-letter abbreviations and the displayed values are the full state names.
<ul>
<li><em>$name</em> — The name to be placed on the &lt;select&gt; element.</li>
<li><em>$selected</em> (optional) — The particular state&#8217;s two-letter abbreviation to be set as the default.</li>
<li><em>$id</em> (optional) — ID attribute to be placed in the &lt;select&gt; tag.</li>
<li><em>$class</em> (optional) — Class attribute to be placed in the &lt;select&gt; tag.</li>
</ul>
</li>
<li><strong>abbr_to_name()</strong> — Converts state&#8217;s two-letter abbreviations into their full state name.</li>
<li><strong>name_to_abbr()</strong> — Converts full state names into their respective two-letter abbreviations.</li>
<li><strong>is_valid_state()</strong> — Checking function to see that the provided full state name OR two-letter abbreviation is valid. Returns boolean TRUE or FALSE.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/codeigniter-state-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting Attachments From Emails With PHP</title>
		<link>http://garrettstjohn.com/entry/extracting-attachments-from-emails-with-php/</link>
		<comments>http://garrettstjohn.com/entry/extracting-attachments-from-emails-with-php/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 16:12:50 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=299</guid>
		<description><![CDATA[Yesterday I wrote about how to read emails with PHP, but I want to dig a bit deeper and discuss another part of the My Slow Low project that needed tackling: Extracting attachments from emails with PHP. For the purposes of this post, I will be specifically discussing file attachments, not HTML inline attached files. [<a href="http://garrettstjohn.com/entry/extracting-attachments-from-emails-with-php/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I wrote about how to <a href="http://garrettstjohn.com/entry/reading-emails-with-php-my-slow-low/">read emails with PHP</a>, but I want to dig a bit deeper and discuss another part of the <a href="http://myslowlow.com">My Slow Low</a> project that needed tackling: Extracting attachments from emails with PHP. For the purposes of this post, I will be specifically discussing file attachments, not HTML inline attached files.</p>
<p>This project was executed with <a href="http://www.codeigniter.com">CodeIgniter 2.0</a> so there are a few libraries and helper functions used that will not be available in other frameworks or with straight PHP, however, their functionality can be pretty easily replicated.</p>
<pre class="brush:php">function email_pull() {
	// load the Email_reader library from previous post
	$this-&gt;load-&gt;library('email_reader');

	// load the meals_model to store meal information
	$this-&gt;load-&gt;model('meals_model');

	// this method is run on a cronjob and should process all emails in the inbox
	while (1) {
		// get an email
		$email = $this-&gt;email_reader-&gt;get();

		// if there are no emails, jump out
		if (count($email) &lt;= 0) {
			break;
		}

		$attachments = array();
		// check for attachments
		if (isset($email['structure']-&gt;parts) &amp;&amp; count($email['structure']-&gt;parts)) {
			// loop through all attachments
			for ($i = 0; $i &lt; count($email['structure']-&gt;parts); $i++) {
				// set up an empty attachment
				$attachments[$i] = array(
					'is_attachment' =&gt; FALSE,
					'filename'      =&gt; '',
					'name'          =&gt; '',
					'attachment'    =&gt; ''
				);

				// if this attachment has idfparameters, then proceed
				if ($email['structure']-&gt;parts[$i]-&gt;ifdparameters) {
					foreach ($email['structure']-&gt;parts[$i]-&gt;dparameters as $object) {
						// if this attachment is a file, mark the attachment and filename
						if (strtolower($object-&gt;attribute) == 'filename') {
							$attachments[$i]['is_attachment'] = TRUE;
							$attachments[$i]['filename']      = $object-&gt;value;
						}
					}
				}

				// if this attachment has ifparameters, then proceed as above
				if ($email['structure']-&gt;parts[$i]-&gt;ifparameters) {
					foreach ($email['structure']-&gt;parts[$i]-&gt;parameters as $object) {
						if (strtolower($object-&gt;attribute) == 'name') {
							$attachments[$i]['is_attachment'] = TRUE;
							$attachments[$i]['name']          = $object-&gt;value;
						}
					}
				}

				// if we found a valid attachment for this 'part' of the email, process the attachment
				if ($attachments[$i]['is_attachment']) {
					// get the content of the attachment
					$attachments[$i]['attachment'] = imap_fetchbody($this-&gt;email_reader-&gt;conn, $email['index'], $i+1);

					// check if this is base64 encoding
					if ($email['structure']-&gt;parts[$i]-&gt;encoding == 3) { // 3 = BASE64
						$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
					}
					// otherwise, check if this is "quoted-printable" format
					elseif ($email['structure']-&gt;parts[$i]-&gt;encoding == 4) { // 4 = QUOTED-PRINTABLE
						$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
					}
				}
			}
		}

		// for My Slow Low, check if I found an image attachment
		$found_img = FALSE;
		foreach ($attachments as $a) {
			if ($a['is_attachment'] == 1) {
				// get information on the file
				$finfo = pathinfo($a['filename']);

				// check if the file is a jpg, png, or gif
				if (preg_match('/(jpg|gif|png)/i', $finfo['extension'], $n)) {
					$found_img = TRUE;
					// process the image (save, resize, crop, etc.)
					$fname = $this-&gt;_process_img($a['attachment'], $n[1]);

					break;
				}
			}
		}

		// if there was no image, move the email to the Rejected folder on the server
		if ( ! $found_img) {
			$this-&gt;email_reader-&gt;move($email['index'], 'INBOX.Rejected');
			continue;
		}

		// get content from the email that I want to store
		$addr   = $email['header']-&gt;from[0]-&gt;mailbox."@".$email['header']-&gt;from[0]-&gt;host;
		$sender = $email['header']-&gt;from[0]-&gt;mailbox;
		$text   = ( ! empty($email['header']-&gt;subject) ? $email['header']-&gt;subject : '');

		// move the email to Processed folder on the server
		$this-&gt;email_reader-&gt;move($email['index'], 'INBOX.Processed');

		// add the data to the database
		$this-&gt;meals_model-&gt;add(array(
			'username'    =&gt; $sender,
			'email'       =&gt; $addr,
			'photo'       =&gt; $fname,
			'description' =&gt; ($text == '' ? NULL : $text)
		));

		// don't slam the server
		sleep(1);
	}

	// close the connection to the IMAP server
	$this-&gt;email_reader-&gt;close();
}
</pre>
<p>I tried to comment the code above as best as possible to convey what it is I am doing with the information. This code is a method within a Controller, but I&#8217;ve only included the attachment extraction method of the class for this post.</p>
<p>For more information and to credit those I&#8217;ve learned from, please check out David Walsh&#8217;s post on <a href="http://davidwalsh.name/gmail-php-imap">Retriev[ing] Your Gmail Emails with PHP and IMAP</a> as well as Chris Hope&#8217;s post on <a href="http://www.electrictoolbox.com/extract-attachments-email-php-imap/">Extracting attachments from an email message using PHP IMAP functions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/extracting-attachments-from-emails-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Migrations</title>
		<link>http://garrettstjohn.com/entry/codeigniter-migrations/</link>
		<comments>http://garrettstjohn.com/entry/codeigniter-migrations/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 02:52:51 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=132</guid>
		<description><![CDATA[Link: CodeIgniter Migrations esbueno: An open source utility for Codeigniter inspired by Ruby on Rails. The one thing Ruby on Rails has that Codeigniter does not have built in is database migrations. That function to keep track of database chages (versions) and migrate your database to what ever version you need. Migrate up or migrate [<a href="http://garrettstjohn.com/entry/codeigniter-migrations/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>Link: <a href="http://github.com/philsturgeon/codeigniter-migrations">CodeIgniter Migrations</a></p>
<p><a href="http://esbueno.noahstokes.com/post/1258198528/codeigniter-migrations">esbueno</a>:</p>
<blockquote><p>An open source utility for Codeigniter inspired by Ruby on Rails.</p>
<p>The one thing Ruby on Rails has that Codeigniter does not have built in is database migrations. That function to keep track of database chages (versions) and migrate your database to what ever version you need. Migrate up or migrate down. With this library you can now do this.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/codeigniter-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExpressionEngine Documentation Quick Search with Alfred</title>
		<link>http://garrettstjohn.com/entry/expressionengine-documentation-quick-search-alfred/</link>
		<comments>http://garrettstjohn.com/entry/expressionengine-documentation-quick-search-alfred/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 19:31:20 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[ExpressionEngine]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=118</guid>
		<description><![CDATA[Link: ExpressionEngine Documentation Quick Search with Alfred Use the power of Alfred to quickly and easily search ExpressionEngine documentation. Works great for CodeIgniter as well!]]></description>
			<content:encoded><![CDATA[<p>Link: <a href="http://www.tonygeer.com/2010/09/24/expressionengine-documentation-quick-search-with-alfred/">ExpressionEngine Documentation Quick Search with Alfred</a></p>
<p>Use the power of <a href="http://www.alfredapp.com/">Alfred</a> to quickly and easily search ExpressionEngine documentation. Works great for CodeIgniter as well!</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/expressionengine-documentation-quick-search-alfred/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Credit Card Helper</title>
		<link>http://garrettstjohn.com/entry/codeigniter-credit-card-helper/</link>
		<comments>http://garrettstjohn.com/entry/codeigniter-credit-card-helper/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 19:07:36 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=73</guid>
		<description><![CDATA[Jim O’Halloran has put together a stellar Credit Card Helper for CodeIgniter which includes the following highly useful functions: Card Number Truncation &#8211; Removes all but the first four and last three digits of a credit card and replaces them with X’s. Card Number Cleaning &#8211; Removes all non-numeric characters from the credit card number [<a href="http://garrettstjohn.com/entry/codeigniter-credit-card-helper/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>Jim O’Halloran has put together a stellar <a href="http://codeigniter.com/wiki/Credit_Card_Helper/">Credit Card Helper</a> for CodeIgniter which includes the following highly useful functions:</p>
<ul>
<li><strong>Card Number Truncation</strong> &#8211; Removes all but the first four and last three digits of a credit card and replaces them with X’s.</li>
<li><strong>Card Number Cleaning</strong> &#8211; Removes all non-numeric characters from the credit card number (spaces, dashes, etc.)</li>
<li><strong>Card Number Validation</strong> &#8211; Uses the Luhn algorithm to execute basic validation of a credit card number.</li>
<li><strong>Card Expiry Date</strong> &#8211; Tests if the card is still active based on its expiration date.</li>
</ul>
<p>I’ll definitely be putting this into my future ecommerce and online sales projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/codeigniter-credit-card-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FTP Download with the CodeIgniter FTP Library</title>
		<link>http://garrettstjohn.com/entry/ftp-download-codeigniter-library/</link>
		<comments>http://garrettstjohn.com/entry/ftp-download-codeigniter-library/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 16:00:46 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[text]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[FTP]]></category>

		<guid isPermaLink="false">http://garrettstjohn.com/?p=42</guid>
		<description><![CDATA[I was recently working on a project that involved FTP and I thought it would be a great chance to get away from the built-in PHP functionality and use the CodeIgniter FTP library instead. I was pretty surprised to find that there was no download functionality in the base FTP library as of CI 1.7.2. [<a href="http://garrettstjohn.com/entry/ftp-download-codeigniter-library/">Keep Reading&#8230;</a>]]]></description>
			<content:encoded><![CDATA[<p>I was recently working on a project that involved FTP and I thought it would be a great chance to get away from the <a href="http://php.net/manual/en/book.ftp.php">built-in PHP functionality</a> and use the <a href="http://codeigniter.com/user_guide/libraries/ftp.html">CodeIgniter FTP library</a> instead.</p>
<p>I was pretty surprised to find that there was no download functionality in the base FTP library  as of CI 1.7.2.  I&#8217;ve extended the library to incorporate file download and will share that here.</p>
<pre class="brush: php">&lt;?php
// This codes goes in the 'application/libraries' folder with a
// file name of MY_Ftp.php

class MY_Ftp extends CI_Ftp {

	/**
	 * Constructor
	 **/
	function MY_Ftp() {
		parent::CI_Ftp();
	}

	/**
	 * Download a file from a FTP server
	 * @param	&lt;string&gt;	$rem_path	Remote path of the file to download
	 * @param	&lt;string&gt;	$loc_path	Local path destination for download
	 * @param	&lt;string&gt;	$mode		Transfer mode, defaults to auto
	 **/
	function download($rem_path, $loc_path, $mode='auto') {
		// check for an active connection
		if ( ! $this-&gt;_is_conn()) {
			return FALSE;
		}

		// get remote folder/filename
		$rem_folder   = dirname($rem_path);
		$rem_filename = basename($rem_path);

		// if a local directory was passed handle differently.
		// Otherwise, treat same as remote.
		if (@is_dir($loc_path)) {
			$loc_folder   = rtrim($loc_path, '/');
			$loc_filename = $rem_filename;
		}
		else {
			$loc_folder   = dirname($loc_path);
			$loc_filename = basename($loc_path);
		}

		// check that the loc path exists
		if ( $loc_folder != '.'  &amp;&amp; ! @is_dir($loc_folder)) {
			$this-&gt;_error('ftp_bad_loc_path');
			return FALSE;
		}
		// check that loc path and file are writable
		elseif ( ! @is_writable($loc_folder) OR (file_exists($loc_folder.'/'.$loc_filename) &amp;&amp; ! @is_writable($loc_folder.'/'.$loc_filename))) {
			$this-&gt;_error('ftp_loc_not_write');
			return FALSE;
		}

		// store old paths
		$old_rem_path = @ftp_pwd($this-&gt;conn_id);
		$old_loc_path = getcwd();

		// move to the local path
		if ( ! @chdir($loc_folder)) {
			$this-&gt;_error('ftp_bad_loc_path');
			return FALSE;
		}

		// move to the remote path
		if ( $rem_folder != '.' &amp;&amp; ! $this-&gt;changedir($rem_folder)) {
			$this-&gt;_error('ftp_bad_rem_path');
			return FALSE;
		}

		// check that the file exists remotely
		$found_file = FALSE;
		$files = $this-&gt;list_files();
		if (count($files) &gt; 0) {
			foreach ($files as $f) {
				if ($f == $rem_filename) {
					$found_file = TRUE;
					break;
				}
			}
		}

		if ( ! $found_file) {
			$this-&gt;_error('ftp_bad_rem_file');
			@chdir($old_loc_path);
			return FALSE;
		}

		// Set the mode if not specified
		if ($mode == 'auto') {
			// Get the file extension so we can set the upload type
			$ext = $this-&gt;_getext($rem_path);
			$mode = $this-&gt;_settype($ext);
		}

		$mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;

		// download the file
		$result = @ftp_get($this-&gt;conn_id, $loc_folder.'/'.$loc_filename, $rem_filename, $mode);

		if ($result === FALSE) {
			if ($this-&gt;debug == TRUE)
				$this-&gt;_error('ftp_unable_to_download');

			return FALSE;
		}

		// move back to the root path
		$this-&gt;changedir($old_rem_path);
		@chdir($old_loc_path);

		return TRUE;
	}

}

?&gt;</pre>
<p>As a side note, you will need to tweak your language file to include all of the message codes (e.g., ftp_bad_loc_path) passed to _error() for proper error display in your app.</p>
]]></content:encoded>
			<wfw:commentRss>http://garrettstjohn.com/entry/ftp-download-codeigniter-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

