<?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>Morgan Davison</title>
	<atom:link href="http://morgandavison.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://morgandavison.com</link>
	<description></description>
	<lastBuildDate>Mon, 15 Aug 2011 17:21:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WordPress Plugin Skeleton</title>
		<link>http://morgandavison.com/2011/08/wordpress-plugin-skeleton/</link>
		<comments>http://morgandavison.com/2011/08/wordpress-plugin-skeleton/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 16:27:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://morgandavison.com/?p=108</guid>
		<description><![CDATA[Here&#8217;s a foundation for writing a WordPress plugin, based on version 3.2. This would go in the main my-plugin-name.php file. /** * Plugin Name: Plugin Name * Plugin URI: http://authorname.com/plugin/ * Description: Description of Plugin * Author: Author Name * &#8230; <a href="http://morgandavison.com/2011/08/wordpress-plugin-skeleton/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a foundation for writing a WordPress plugin, based on version 3.2. This would go in the main my-plugin-name.php file.<span id="more-108"></span></p>
<pre class="brush: php">/**
 * Plugin Name: Plugin Name
 * Plugin URI: http://authorname.com/plugin/
 * Description: Description of Plugin
 * Author: Author Name
 * Version: 1.0
 * Author URI: http://www.authorname.com
 */

/**
 * Copyright 2011 Author Name
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

define('MYPLUGIN_VERSION', '1.0');
define('MYPLUGIN_PLUGIN_URL', plugin_dir_url( __FILE__ ));

/* for plugin Settings in Admin */
function myplugin_admin() {
	include('myplugin-admin.php');
}

add_action('init', 'myplugin_init');
add_action('plugins_loaded', 'myplugin_do_something');
add_action('admin_menu', 'myplugin_admin_actions');
add_action('update_option_mypluginoption', 'myplugin_do_something_else');

function myplugin_admin_actions() {
     // add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');
     add_options_page("My Plugin", "My Plugin", "manage_options", "My Plugin", "myplugin_admin");
}

function potd_init() {
	if (is_admin()) {
		wp_register_script('myplugin.js', MYPLUGIN_PLUGIN_URL . 'myplugin.js', array('jquery'));
		wp_enqueue_script('myplugin.js');
	}
}

function myplugin_install() {
	global $wpdb;

	// Create default options if needed
	add_option('myplugin_option', 'the option');

        // Create a table if necessary (only if can't use options or postmeta tables)
	$table_name = $wpdb-&gt;prefix . "myplugin";

	// Create myplugin table if not existing
	if ($wpdb-&gt;get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

		$sql = "
			CREATE TABLE IF NOT EXISTS `" . $table_name . "` (
				`id` BIGINT(20) NOT NULL AUTO_INCREMENT  PRIMARY KEY,
				`field_one` VARCHAR(255) NOT NULL
			);";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);

		// Initial insert
		$rows_affected = $wpdb-&gt;insert(
			$table_name,
			array(
				'field_one' =&gt; 'a string'
			)
		);
	}
}

function myplugin_do_something() {
     // something to do when plugins are loaded
}

function myplugin_do_something_else() {
     // do something when options are updated
}

/**
 * Replaces shortcode "[myplugin]" with plugin stuff
 * Can be called anywhere in template with
 * &lt;?php echo do_shortcode('[myplugin]'); ?&gt;
 * @param array $atts
 * @param string $content
 * @param string $code
 */
function myplugin_shortcode($atts = array(), $content=null, $code="") {
     // have to return, not echo
     return 'something to replace shortcode';
}

/**
* Drops the table and deletes the options
* when user clicks "delete plugin"
*/
function potd_uninstall() {
	global $wpdb;
	$table_name = $wpdb-&gt;prefix . "myplugin";

	if ($wpdb-&gt;get_var("SHOW TABLES LIKE '$table_name'") === $table_name) {
		$qry = "
			DROP TABLE `{$table_name}`
		";
		$wpdb-&gt;query($qry);
	}

	delete_option('myplugin_option');
}

register_activation_hook( __FILE__, 'myplugin_install' );
add_shortcode( 'myplugin', 'myplugin_shortcode' );
register_uninstall_hook( __FILE__, 'myplugin_uninstall' );</pre>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/08/wordpress-plugin-skeleton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Escaping shortcodes in WordPress Posts</title>
		<link>http://morgandavison.com/2011/08/escaping-shortcodes-in-wordpress-posts/</link>
		<comments>http://morgandavison.com/2011/08/escaping-shortcodes-in-wordpress-posts/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 19:22:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://morgandavison.com/?p=69</guid>
		<description><![CDATA[If you want to display the shortcode literally in a post (like so: &#91;shortcode&#93;), just use double brackets like this: &#8220;[[shortcode]]&#8221;. You can also use the html entities &#38;#91; for &#8220;[" and &#38;#93; for "]&#8221; (which you&#8217;ll need to use &#8230; <a href="http://morgandavison.com/2011/08/escaping-shortcodes-in-wordpress-posts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to display the shortcode literally in a post (like so: &#91;shortcode&#93;), just use double brackets like this: &#8220;[[shortcode]]&#8221;. You can also use the html entities &amp;#91; for &#8220;[" and &amp;#93; for "]&#8221; (which you&#8217;ll need to use if your shortcode doesn&#8217;t exist and therefore doesn&#8217;t run through the parser).</p>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/08/escaping-shortcodes-in-wordpress-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Up a Virtual Host on WAMP</title>
		<link>http://morgandavison.com/2011/06/setting-up-a-virtual-host-on-wamp/</link>
		<comments>http://morgandavison.com/2011/06/setting-up-a-virtual-host-on-wamp/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 20:16:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WAMP]]></category>

		<guid isPermaLink="false">http://morgandavison.com/?p=44</guid>
		<description><![CDATA[One of the biggest pains about developing on a local server setup like WAMP is that the root filepaths are different when you go live. To get around this I always set up a virtual host so that my development &#8230; <a href="http://morgandavison.com/2011/06/setting-up-a-virtual-host-on-wamp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the biggest pains about developing on a local server setup like WAMP is that the root filepaths are different when you go live. To get around this I always set up a virtual host so that my development url can be something like, http://myapplication.localhost/. It&#8217;s really easy to set up. <span id="more-44"></span></p>
<p>First, go into the WAMP menu under the Apache section, open up httpd.conf. Go all the way to the bottom and put in this:</p>
<pre class="brush: plain">

&lt;VirtualHost *:80&gt;
ServerName myapplication.localhost
DocumentRoot c:/wamp/www/myapplication/

&lt;Directory c:/wamp/www/myapplication/&gt;
DirectoryIndex index.php
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
&lt;/Directory&gt;
&lt;/VirtualHost&gt;
</pre>
<p>Changing &#8220;myapplication&#8221; to the name of the directory of your project, of course. Next, open up your hosts file (I create a shortcut on my desktop because I can&#8217;t ever remember where it is.) On my machine (Windows 7) it&#8217;s in C:\Windows\System32\drivers\etc. Add this line to the end:</p>
<pre class="brush: plain">

127.0.0.1 myapplication.localhost
</pre>
<p>Restart WAMP and you should now be able to access it at http://myapplication.localhost.</p>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/06/setting-up-a-virtual-host-on-wamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Temporary Tables in Zend Framework</title>
		<link>http://morgandavison.com/2011/06/temporary-tables-in-zend-framework/</link>
		<comments>http://morgandavison.com/2011/06/temporary-tables-in-zend-framework/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 01:15:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://morgandavison.com/?p=25</guid>
		<description><![CDATA[Use temporary tables when your sql queries are starting to do gymnastics. The following would go in your model: $config = $this-&#62;getAdapter()-&#62;getConfig(); $db = Zend_Db::factory('PDO_MYSQL', $config); $sql = "CREATE TEMPORARY TABLE tmp_datasets ("; $sql .= "`id` INT(11) NOT NULL AUTO_INCREMENT, &#8230; <a href="http://morgandavison.com/2011/06/temporary-tables-in-zend-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Use temporary tables when your sql queries are starting to do gymnastics. The following would go in your model:</p>
<p><span id="more-25"></span></p>
<pre class="brush: php">
$config = $this-&gt;getAdapter()-&gt;getConfig();
$db = Zend_Db::factory('PDO_MYSQL', $config);
$sql = "CREATE TEMPORARY TABLE tmp_datasets (";
$sql .= "`id` INT(11) NOT NULL AUTO_INCREMENT, ";
$sql .= "`primary_date` DATE, ";

$fieldArray = array(0 =&gt; 'primary_date');
// looping through existing table dataset to get column names for temp table
foreach ($dataFields as $field) {
// format the field label to use as the column name
// needs to be lowercase and no spaces/spec char
$pattern = '[^a-z0-9]';
$label = strtolower($field-&gt;label);
// replace anything that's not a letter or number with an underscore
$label = preg_replace($pattern, '_', $label);
// if label is 'id' or 'primary_date', rename it since we're already using those
if ($label === 'id') {
$label = 'id_1';
}
if ($label === 'primary_date') {
$label = 'primary_date_1';
}

// build the columns
switch ($field-&gt;db_type) {
case 'date':
$type = 'DATE';
break;
case 'varchar(50)':
$type = 'VARCHAR(50)';
break;
case 'int(10)':
$type = 'INT(10)';
break;
case 'decimal(10,2)':
$type = 'DECIMAL(10,2)';
break;
default:
$type = 'VARCHAR(255)';
break;
}

$null = 'NOT NULL'; // either NULL or NOT NULL
$sql .= "`{$label}` {$type} {$null}, ";
$fieldArray[$field-&gt;id] = $label;

}

$sql .= " PRIMARY KEY (`id`) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8"
$executed = $db-&gt;query($sql);
ksort($fieldArray); // need to keep everything in the right order
$fieldString = implode('`,`', $fieldArray);

// need to get a string with the same number of '?' as items in $fieldArray -
// seems like an awkward way to do this but couldn't find a php function
// that would do it...
$fieldVariablesArray = array();
foreach ($fieldArray as $fieldItem) {
$fieldVariablesArray[] = '?';
}
$fieldVariables = implode(',', $fieldVariablesArray);

$stmt = $db-&gt;prepare("INSERT INTO tmp_datasets (`{$fieldString}`) VALUES ({$fieldVariables})");
</pre>
<p>At this point we should have the table set up but there&#8217;s nothing in it yet. Query your existing table(s) to get the data you want to store.</p>
<pre class="brush: php">
// get the values
// $fieldIdArray came from data that was passed into the method
$datasetEntries = $this-&gt;_datasetEntry-&gt;getAllForFields($fieldIdArray);

// Loop through your datasets to build a new array of values to insert into
// the temp table
$valuesArray = array();
foreach ($datasetEntries as $key =&gt; $value) {
$valuesArray[$key] = $value-&gt;value;
}
ksort($valuesArray); // again, keep things in the right order
// have to remove keys for some reason or it won't execute
$valuesArray = array_values($valuesArray);
$stmt-&gt;execute($valuesArray);
unset($stmt);
</pre>
<p>Now we should have data in our table that we can query as usual.</p>
<pre class="brush: php">
$select = $db-&gt;select();
$select-&gt;from('tmp_datasets');
$select-&gt;where("primary_date IN ('{$dateString}')"); // or whatever your where clause should be
$select-&gt;order(array("primary_date ASC"));
$tmpDatasets = $db-&gt;fetchAll($select);
</pre>
<p>You might also want to check out <a href="http://blog.brianhartsock.com/2009/02/04/using-mysql-temporary-tables-to-save-your-brain/">this post</a>, which does a much better job of explaining temporary tables than me.</p>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/06/temporary-tables-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Function Skeleton</title>
		<link>http://morgandavison.com/2011/06/javascript-function-skeleton/</link>
		<comments>http://morgandavison.com/2011/06/javascript-function-skeleton/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 00:38:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://morgandavison.com/?p=32</guid>
		<description><![CDATA[(function(){ var functionName = function(){ this.init(); }; functionName.prototype = { init : function() { this.setFunction(); }, setFunction : function() { // do stuff here } }; new functionName(); })();]]></description>
			<content:encoded><![CDATA[<pre class="brush: js">
(function(){
	var functionName = function(){
			this.init();
		};

	functionName.prototype = {
		init : function() {
	 		this.setFunction();
	 	},	

	 	setFunction : function() {
	 		// do stuff here
	 	}
	};

	new functionName();
})();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/06/javascript-function-skeleton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Focus First Input Field</title>
		<link>http://morgandavison.com/2011/06/focus-first-input-field/</link>
		<comments>http://morgandavison.com/2011/06/focus-first-input-field/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 00:43:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://morgandavison2.localhost/?p=18</guid>
		<description><![CDATA[Here&#8217;s a handy little snippet to automatically put the cursor in the first input field on the page. You can override it by adding a class of &#8220;nofocus&#8221; to any element and/or list the elements in the array. Nice for &#8230; <a href="http://morgandavison.com/2011/06/focus-first-input-field/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a handy little snippet to automatically put the cursor in the first input field on the page. You can override it by adding a class of &#8220;nofocus&#8221; to any element and/or list the elements in the array. Nice for login pages.</p>
<pre class="brush: js">

if( !$(':input:visible:enabled:first').hasClass('nofocus') &#038;&#038;
		$.inArray( $(':input:visible:enabled:first').attr('id'),
				  ['element_to_exclude', 'another_element_to_exclude']
		        ) == -1
  ){
	$(':input:visible:enabled:first').focus();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/06/focus-first-input-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Excerpt</title>
		<link>http://morgandavison.com/2011/05/generate-excerpt/</link>
		<comments>http://morgandavison.com/2011/05/generate-excerpt/#comments</comments>
		<pubDate>Mon, 30 May 2011 23:42:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://morgandavison2.localhost/?p=1</guid>
		<description><![CDATA[Here&#8217;s a little snippet for generating an excerpt without breaking up a word: function excerpt($string='', $maxChar=50, $uri='#') { $length = strlen($string); if ($length &#60; $maxChar) { return $string; } $trimmedString = substr($string, 0, $maxChar); $choppedString = substr($trimmedString, 0, strrpos($trimmedString, strrchr($trimmedString, &#8230; <a href="http://morgandavison.com/2011/05/generate-excerpt/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little snippet for generating an excerpt without breaking up a word:</p>
<pre class="brush: php">
function excerpt($string='', $maxChar=50, $uri='#') {
     $length = strlen($string);
     if ($length &lt; $maxChar) {
          return $string;
     }
     $trimmedString = substr($string, 0, $maxChar);
     $choppedString = substr($trimmedString, 0, strrpos($trimmedString, strrchr($trimmedString, ' ')));
     $newString = $choppedString . ' &lt;a href="' . $uri . '"&gt;more&lt;/a&gt;';
     return $newString;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://morgandavison.com/2011/05/generate-excerpt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

