<?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>Clifton Griffin&#187; clifgriffin</title>
	<atom:link href="http://clifgriffin.com/author/clifgriffin/feed/" rel="self" type="application/rss+xml" />
	<link>http://clifgriffin.com</link>
	<description>I develop simple solutions to complex problems.</description>
	<lastBuildDate>Sat, 30 Mar 2013 16:04:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Switching WordPress Databases and Git Branches Simultaneously</title>
		<link>http://clifgriffin.com/2011/12/15/switching-wordpress-database-and-git-branches-simultaneously/</link>
		<comments>http://clifgriffin.com/2011/12/15/switching-wordpress-database-and-git-branches-simultaneously/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 14:55:08 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1366</guid>
		<description><![CDATA[I&#8217;ve recently switched to a rather rad workflow involving a local copy of our website run through MAMP using a git repository. We&#8217;ve recently started working on a bigger set of changes that require a feature branch. But, these changes also will require WordPress to be upgraded to 3.3, requiring database changes.  Making it impossible [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve recently switched to a rather rad workflow involving a local copy of our website run through MAMP using a git repository.</p>
<p>We&#8217;ve recently started working on a bigger set of changes that require a feature branch. But, these changes also will require WordPress to be upgraded to 3.3, requiring database changes.  Making it impossible to use the same database.</p>
<p>I was able to come up with this nifty technique for determining which DB to use.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$stringfromfile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.git/HEAD'</span><span style="color: #339933;">,</span> FILE_USE_INCLUDE_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stringfromfile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stringfromfile</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get the string from the array</span>
<span style="color: #000088;">$explodedstring</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stringfromfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//separate out by the &quot;/&quot; in the string</span>
<span style="color: #000088;">$branchname</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$explodedstring</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get the one that is always the branch name</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ** MySQL settings - You can get this info from your web host ** //</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$branchname</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;master&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/** The name of the database for WordPress */</span>
	<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wordpress_local'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wordpress_new'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s all there is to it. It works flawlessly.</p>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/12/15/switching-wordpress-database-and-git-branches-simultaneously/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding Autocomplete Search To Shopp</title>
		<link>http://clifgriffin.com/2011/10/11/adding-autocomplete-search-to-shopp/</link>
		<comments>http://clifgriffin.com/2011/10/11/adding-autocomplete-search-to-shopp/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 16:35:22 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1360</guid>
		<description><![CDATA[This week I tackled another long term todo: autocomplete. It was a fun project with the right amount of difficulties and surprises along the way. To make this possible, I used jQuery Marco Polo, a very nice autocomplete plugin available here: https://github.com/jstayton/jquery-marcopolo I had to modify it to make it work exactly how I wanted, [...]]]></description>
				<content:encoded><![CDATA[<p>This week I tackled another long term todo: autocomplete. It was a fun project with the right amount of difficulties and surprises along the way.</p>
<p>To make this possible, I used jQuery Marco Polo, a very nice autocomplete plugin available here: <a href="https://github.com/jstayton/jquery-marcopolo">https://github.com/jstayton/jquery-marcopolo</a></p>
<p>I had to modify it to make it work exactly how I wanted, but it does the job.</p>
<p>Basically, jQuery Marco Polo takes input into a search field and runs it against a URL in realtime using AJAX.  It expects a JSON response from this URL.  It has many options on how to display items and what to do when items are clicked.</p>
<p>The first challenge was getting the results into JSON. To do this, I created a function to intercept requests that match a certain format: /q=?somesearchterm&#038;ajax=true</p>
<p>Pretty basic.  Here is the function:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ajax_autocomplete_search'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ajax_autocomplete_search<span style="color: #009900;">&#40;</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ajax'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ajax'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;true&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</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: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'search-products'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;load=true&amp;search=<span style="color: #006699; font-weight: bold;">$q</span>&quot;</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>shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'has-products'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$Shopp</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$filter_cat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$used_products</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'products'</span><span style="color: #009900;">&#41;</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: #000088;">$count</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000088;">$product_id</span> <span style="color: #339933;">=</span> shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'return=true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;id=<span style="color: #006699; font-weight: bold;">$product_id</span>&amp;load=true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span>TEMPLATEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'/name-vars.php'</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: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$used_products</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$used_products</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$first_name</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'coverimage'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'width=60&amp;height=60'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$image_tag</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000088;">$summary</span> <span style="color: #339933;">=</span> shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'summary'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'return=true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$slug</span> <span style="color: #339933;">=</span> shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'slug'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'return=true'</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: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$summary</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$summary</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$summary</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$summary</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</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>
					<span style="color: #b1b100;">else</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$summary</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$summary</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>shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'in-category'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;name=<span style="color: #006699; font-weight: bold;">$filter_cat</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filter_cat</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$filter_cat</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;Everything&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$first_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$summary</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$image_tag</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$slug</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
				<span style="color: #009900;">&#125;</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;">$Shopp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Category</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">products</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'See All Search Results'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'search'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'s'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'category'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#93;</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;">$results</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: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">die</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now, you&#8217;re going to notice right away that there are a lot of specific things going on here that cater to the specific way I implemented this.  For instance, I only show the first 3 results with a &#8220;See All Results&#8221; footer.  This also assumes that you, like me, have implemented a category filtered search <a href="http://clifgriffin.com/2011/10/07/search-by-category-in-shopp/">as described here.</a>  There is also some custom stuff in there based on the way we name things. (that&#8217;s the name-vars.php and $first_name stuff&#8230;I won&#8217;t go into that)</p>
<p>No matter.  You should be able to see what I&#8217;m doing and modify it as necessary.</p>
<p>So that, with some modification, should throw some nice JSON responses out.</p>
<p>Other than that, I just used the following JavaScript:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#category-dropdown&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input.search'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">marcoPolo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/?wp-minify-off=1&amp;category='</span> <span style="color: #339933;">+</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#category-dropdown&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;x=0&amp;y=0&amp;ajax=true'</span><span style="color: #339933;">,</span>
				  param<span style="color: #339933;">:</span> <span style="color: #3366CC;">'q'</span><span style="color: #339933;">,</span>
				  formatItem<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> $item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				  	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">name</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;footer&quot;</span><span style="color: #009900;">&#41;</span>
				  	<span style="color: #009900;">&#123;</span>
				   		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;h2&gt;'</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/h2&gt;'</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">image</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;'</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">summary</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
				   	<span style="color: #009900;">&#125;</span>
				   	<span style="color: #000066; font-weight: bold;">else</span>
				   	<span style="color: #009900;">&#123;</span>
				   		$item.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				   		<span style="color: #000066; font-weight: bold;">return</span> data.<span style="color: #660066;">summary</span><span style="color: #339933;">;</span>
				   	<span style="color: #009900;">&#125;</span>
				  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
				  onSelect<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> $item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				  	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">name</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;footer&quot;</span><span style="color: #009900;">&#41;</span>
				  	<span style="color: #009900;">&#123;</span>
				    	window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/shop/'</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">slug</span><span style="color: #339933;">;</span>
				    <span style="color: #009900;">&#125;</span>
				    <span style="color: #000066; font-weight: bold;">else</span>
				    <span style="color: #009900;">&#123;</span>
				    	window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/?s='</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">search</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;category='</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">category</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;catalog=true'</span><span style="color: #339933;">;</span>
				    <span style="color: #009900;">&#125;</span>
				  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
				  formatNoResults<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>q<span style="color: #339933;">,</span> $item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				  	$item.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mp_selectable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				  	$item.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				  		window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/?s='</span> <span style="color: #339933;">+</span> q <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;category=Everything&amp;catalog=true'</span><span style="color: #339933;">;</span>
				  	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				  	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;em&gt;No results for &lt;strong&gt;'</span> <span style="color: #339933;">+</span> q <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/strong&gt; in '</span> <span style="color: #339933;">+</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#category-dropdown&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.&lt;br /&gt;&lt;br /&gt; Try your search again in Everything?&lt;/em&gt;'</span><span style="color: #339933;">;</span>
				  <span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#category-dropdown&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Again, not the briefest example. It&#8217;s either show all or show nothing. You&#8217;re going to have to work around my particular usage of all of these things.  I instantiate Marco Polo when the dropdown is changed because the search URL depends on the drop down selection.</p>
<p>I modified Marco Polo to get rid of it&#8217;s hijacking of the ENTER key, etc.  I just removed all of the key binding because it didn&#8217;t support the way I wanted to use it.</p>
<p>You can see this fully working here: <a href="http://www.mooreandgiles.com">Moore and Giles, Inc.</a></p>
<p>Type in Brompton, for example.</p>
<p>That&#8217;s it.  Feel free to ask questions.<br />
Clif</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/10/11/adding-autocomplete-search-to-shopp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Search by Category in Shopp</title>
		<link>http://clifgriffin.com/2011/10/07/search-by-category-in-shopp/</link>
		<comments>http://clifgriffin.com/2011/10/07/search-by-category-in-shopp/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 20:56:17 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1357</guid>
		<description><![CDATA[Today I saw a thread on the Shopp forums asking how to limit a search to a particular category. As this was on my big list, I decided to tackle it. It turns out to not be very difficult, once you understand the way Shopp handles searches. The trick is that the category template (i.e., [...]]]></description>
				<content:encoded><![CDATA[<p>Today I saw a thread on the Shopp forums asking how to limit a search to a particular category.  As this was on my big list, I decided to tackle it.</p>
<p>It turns out to not be very difficult, once you understand the way Shopp handles searches.</p>
<p>The trick is that the category template (i.e., theme/shopp/category.php) is used to display searches.  This allows you to easily jump in and decide how it is displayed, based on your own criteria.</p>
<p>So, you will want to create a copy of your category.php file named something like category-default.php.  Then create a separate file named category-search.php. The former file will handle the default category page functionality.  The second will handle searches only.</p>
<p>In category.php,  do something like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><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;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'s'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'catalog'</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: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category-search.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category-default.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Basically, if the URL parameters for a search exist, use the search template, otherwise, stick to the normal game plan.</p>
<p>Then in category-search.php, you&#8217;re going to want to use your own loop to exclude every category but the one you&#8217;re interested in:</p>

<div class="wp_syntax"><table><tr><td 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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</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: #000088;">$category</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'has-products'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'products'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	 	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>shopp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'in-category'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;name=<span style="color: #006699; font-weight: bold;">$category</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$category</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$category</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;Everything&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		// your code to display in your own html using the product tags (model it after the default category template, for example)
&nbsp;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Lastly, you&#8217;ll want to render the search form yourself instead of using the default widget. For example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">			&lt;form id=&quot;search&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;get&quot; accept-charset=&quot;utf-8&quot;&gt;
				&lt;div class=&quot;search-perimeter&quot;&gt;
					&lt;input autocomplete=&quot;off&quot; class=&quot;search&quot; type=&quot;text&quot; name=&quot;s&quot; value=&quot;&quot; id=&quot;find&quot; /&gt;
					&lt;select size=1 name=&quot;category&quot; id=&quot;category-dropdown&quot; title=&quot;Search in&quot;&gt;
						&lt;option value=&quot;Category 1 Name&quot;&gt;Category 1 Name&lt;/option&gt;
						&lt;option value=&quot;Category 2 Name&quot;&gt;Category 2 Name&lt;/option&gt;
						&lt;option value=&quot;Everything&quot;&gt;Everything&lt;/option&gt;
					&lt;/select&gt;
					&lt;input type=&quot;image&quot; class=&quot;search-button&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'template_url'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/search.png&quot; /&gt;
				&lt;/div&gt;
				&lt;input type=&quot;hidden&quot; name=&quot;catalog&quot; value=&quot;true&quot; id=&quot;catalog&quot; /&gt;
			&lt;/form&gt;</pre></td></tr></table></div>

<p>That&#8217;s about all there is to it. You&#8217;ll have to get in deep with the templates, but I think you&#8217;ll agree this is conceptually pretty simple.</p>
<p>Lastly, you should note: Category names seem to be case sensitive. &#8220;Bags&#8221; != &#8220;bags&#8221;</p>
<p>Good luck,<br />
Clif</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/10/07/search-by-category-in-shopp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Improve HTML E-mails from WordPress, automagically</title>
		<link>http://clifgriffin.com/2011/10/07/improve-html-e-mails-from-wordpress-automagically/</link>
		<comments>http://clifgriffin.com/2011/10/07/improve-html-e-mails-from-wordpress-automagically/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 13:27:36 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1353</guid>
		<description><![CDATA[HTML e-mails are like wild stallions.  They are really hard to tame. I have been frustrated by the vastly different ways e-mails from my company&#8217;s site (http://www.mooreandgiles.com) render in different clients.  After some research, I decided the trick to fix this would be inlining all CSS styles, as various clients will haphazardly abort style blocks you [...]]]></description>
				<content:encoded><![CDATA[<p>HTML e-mails are like wild stallions.  They are really hard to tame.</p>
<p>I have been frustrated by the vastly different ways e-mails from my company&#8217;s site (http://www.mooreandgiles.com) render in different clients.  After some research, I decided the trick to fix this would be inlining all CSS styles, as various clients will haphazardly abort style blocks you include in your e-mails.</p>
<p>Being lazy and wanting to the greatest flexibility for modifying templates in the future, I came up with a way to automatically process e-mails and inline their styles as they leave.   As this hooks into wp_mail, it should work with most plugins that send HTML e-mails.  Some may go around WordPress and use PHP mail&#8230;I can&#8217;t help you there.</p>
<p>In your theme functions file, add this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_mail'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'html_email_prep'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> html_email_prep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</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: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'headers'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;html&quot;</span><span style="color: #009900;">&#41;</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;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Grab CSS block</span>
		<span style="color: #b1b100;">require_once</span> TEMPLATEPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'/css_to_inline_styles.php'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$cssConverter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CSSToInlineStyles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cssConverter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCleanup</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cssConverter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHTML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cssConverter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUseInlineStylesBlock</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$new_html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cssConverter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">convert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$email</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$new_html</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And, simply dropp css_to_inline_styles.php in your theme folder.   You may download it here: <a href="http://blog.verkoyen.eu/blog/p/detail/convert-css-to-inline-styles-with-php">http://blog.verkoyen.eu/blog/p/detail/convert-css-to-inline-styles-with-php</a></p>
<p>With this in place, it will automatically parse outgoing e-mail messages.  It will find the style block and inline each style, automagically. This instantly fixed most of the rendering problems I was having in various clients.</p>
<p>It automatically excludes e-mails that don&#8217;t have HTML.  I have seen the class bork up one HTML template, but making a minor change to the markup avoided the problem easily.  Make sure you test. </p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/10/07/improve-html-e-mails-from-wordpress-automagically/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Thoughts On Steve Jobs</title>
		<link>http://clifgriffin.com/2011/10/06/thoughts-on-steve-jobs/</link>
		<comments>http://clifgriffin.com/2011/10/06/thoughts-on-steve-jobs/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 23:48:47 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/2011/10/06/thoughts-on-steve-jobs/</guid>
		<description><![CDATA[Like most, I was shocked at the passing of Steve Jobs last evening. I believe there is something in all of us that wants to believe that genius and resources will spare us death. But I doesn&#8217;t. He is dead, but what a remarkable legacy he has left behind. It occurs to me that the [...]]]></description>
				<content:encoded><![CDATA[<p>Like most, I was shocked at the passing of Steve Jobs last evening. I believe there is something in all of us that wants to believe that genius and resources will spare us death. But I doesn&#8217;t. He is dead, but what a remarkable legacy he has left behind.</p>
<p>It occurs to me that the greatest tribute to Jobs is his work on the iPhone. In four years he revolutionized the way we think about, use, and what we expect from smartphones.</p>
<p>In 2007, the smartphone industry was a horror show of ugly, slow hardware with archaic input. Each phone seemed to have a larger keyboard, antenna, and battery. This was progress. Then came the first iPhone. Critics scoffed at it. No one would want a touch screen only device. It was too expensive. You couldn&#8217;t multitask. It didn&#8217;t had GPS or 3G. It was laughably expensive. It would fail miserably.</p>
<p>In 2008, the iPhone 3G was too slow. The screen too small. Too low resolution. Android was going to win because it was open.</p>
<p>2009 brought the too minorly improved 3GS. Apple was poised to be left behind, their massive lead would be quickly absorbed.</p>
<p>Then came the iPhone 4. Within a year of its release, my dad bought one. So did 4 of my non-techie friends. Most people I know that don&#8217;t have one, no longer say they never will get one.  Android has grown, but the iPhone continues to dominate and define the technology.</p>
<p>I scoffed with the scoffers until 2009. Since then, I have converted from full Windows to full Mac. I bought an iPad. Great products create their own demand.</p>
<p>So that&#8217;s Steve&#8217;s legacy to me. In four years, he made the smartphone a household device. In four years he took a device from a toy for fanatics and nerds, to a cultural phenomenon. And all around the world, salesmen are pitching the competitions&#8217; products as &#8220;Just like an iPhone.&#8221;</p>
<p>My friend Jeremy noted it should be called the iPhone 4Steve. I think he has a point. There&#8217;s no greater tribute to him than his last revolution.</p>
<p>Clif</p>
<p>Sent from my iPad</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/10/06/thoughts-on-steve-jobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Imagick and WP-Minify</title>
		<link>http://clifgriffin.com/2011/08/12/imagick-and-wp-minify/</link>
		<comments>http://clifgriffin.com/2011/08/12/imagick-and-wp-minify/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 15:05:37 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1334</guid>
		<description><![CDATA[This morning I attempted to migrate a fully working script from our test site to our production site.  To my dismay, it stopped working on our production site. The script used Imagick to composite two images together on the fly.  It used WordPress for database connectivity by including wp-load.php. Strangely,  Firefox reported the image to [...]]]></description>
				<content:encoded><![CDATA[<p>This morning I attempted to migrate a fully working script from our test site to our production site.  To my dismay, it stopped working on our production site.</p>
<p>The script used <span style="color: #000000;"><strong>Imagick</strong></span> to composite two images together on the fly.  It used WordPress for database connectivity by including <span style="color: #000000;"><strong>wp-load.php</strong></span>.</p>
<p>Strangely,  Firefox reported the image to be corrupt.  I downloaded the image being generated and ran Imagick&#8217;s &#8220;identify&#8221; command against it via SSH.   The tool reported the file had &#8220;two SOI markers&#8221; and &#8220;extraneous bytes before marker&#8221;.  Exciting stuff.</p>
<p>After wracking my brain and starting the process of opening a StackOverflow post,  a thought occurred to me:  What if the problem is coming from WordPress.  I threw together a quick proof of concept using <span style="color: #000000;"><strong>Imagick</strong></span> and tested it.  Worked fine.  I then included <span style="color: #000000;"><strong>wp-load.php</strong></span> at the beginning&#8230;corrupt image again.</p>
<p>At this point, I knew the problem was most likely a plugin. I realized that the only plugin difference between our test and production site was a plugin called <a href="http://wordpress.org/extend/plugins/wp-minify/">WP-Minify</a> that handles JS/CSS/HTML minification.  I tried disabling it and magically the script worked again.</p>
<p>Unwilling to sacrifice the advantages of WP-Minify, I looked through the code.  It turns out you can pass in <span style="color: #000000;"><strong>wp-minify-off=1</strong></span> as a URL parameter to any page to prevent it from processing.  A very easy solution.</p>
<p>So there you go. That&#8217;s my story.   If ImageMagick / Imagick is outputting a corrupt JPEG, and you are using WP-Minify,  now you know how to solve it.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/08/12/imagick-and-wp-minify/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another Guide To Optimizing WordPress</title>
		<link>http://clifgriffin.com/2011/05/26/another-guide-to-optimizing-wordpress/</link>
		<comments>http://clifgriffin.com/2011/05/26/another-guide-to-optimizing-wordpress/#comments</comments>
		<pubDate>Thu, 26 May 2011 02:37:51 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1323</guid>
		<description><![CDATA[A word of warning: I haven&#8217;t implemented hardly any of the tips I&#8217;m about to share on this site. So don&#8217;t hate, participate. This blog is just for fun and I have no incentive to spend hours making it faster.   MooreAndGiles.com is a good example of a site where I have implemented many of [...]]]></description>
				<content:encoded><![CDATA[<p><em>A word of warning:  I haven&#8217;t implemented hardly any of the tips I&#8217;m about to share on this site.  So don&#8217;t hate, participate.  This blog is just for fun and I have no incentive to spend hours making it faster.   <a href="http://www.mooreandgiles.com">MooreAndGiles.com</a> is a good example of a site where I have implemented many of these techniques. </em></p>
<p>Today, Media Temple <a href="https://twitter.com/#!/mediatemple/status/73480318304264192">tweeted</a> about <a href="http://www.noupe.com/how-tos/speeding-up-wordpress.html">an article</a> on optimizing WordPress.  While it makes some good points, I feel like there were some omissions that are worthy of sharing.  So, that&#8217;s what I intend to do.</p>
<p><strong>A word about caching.</strong><br />
No article on optimizing WordPress is worth anything if it neglects to mention the world of caching plugins.  Such plugins are relied upon by millions and are a great way to achieve large performance increases in just a few steps.   In fact, I have used such plugins to fix constant crashing on high traffic websites. The two I am most familiar with are <a href="http://wordpress.org/extend/plugins/wp-super-cache/">WP Super Cache</a> and <a href="http://wordpress.org/extend/plugins/w3-total-cache/">W3 Total Cache</a>.</p>
<p>While these have their place,  there are a couple of reasons I tend to avoid them:  mainly they can break things,  and they try to do everything.</p>
<p>Now, I&#8217;m sure I just offended a few people.  You can certainly work around the occasional (and often minor breaks).  And more features isn&#8217;t always bad.</p>
<p>My hangup is that when they do break things, it is often difficult to troubleshoot because of the sheer volume of moving parts.  There are so many nuances to the settings and it can be extremely difficult to find the right balance simply because it can be impossible to understand everything the plugin is trying to do on your behalf.</p>
<p>There are also many plugins that simply do not work with caching plugins. So some don&#8217;t even have a choice.</p>
<p>The goal here is to provide a list of things that nearly everyone should consider.  These approaches are specific enough to be understood and minimalist enough to implement on a site that&#8217;s already established.</p>
<p><strong>Out of control JavaScript (and CSS)</strong><br />
It happens to everyone.   You build a theme or buy one.  You install it. You customize it.  You install some plugins.  And soon, you find that your site is loading 20 complete JavaScript libraries on every single page load.  NextGen Gallery has hijacked your home page.  Contact Form 7 is running it&#8217;s validation scripts on your About Us page.</p>
<p>All of this is costly in terms of page load times.   Your goal should be to never load a JavaScript file on a page where it isn&#8217;t being used. Ever.</p>
<p>So, open your site in your favorite browser and start going through these files one by one.   I found it helpful to use the <a href="http://developer.yahoo.com/yslow/">YSlow</a> add-on for <a href="http://getfirebug.com/">Firebug</a> in Firefox for this.  Once you do a scan, you can view the components in a list and sort by size.   This can give you a great way to prioritize what scripts you are going to tackle first.</p>
<p>If you are loading a script in header.php that is only used on one page, consider moving that include to a page template or wrap it in a conditional:</p>
<pre>&lt;?php if(is_page('your-awesome-page-slug')): ?&gt;
&lt;script src="evilscript.js" type="text/javascript"&gt;
&lt;?php endif; ?&gt;</pre>
<p>Some will be more challenging.  If you have plugins adding scripts, you&#8217;ll have to figure out how to prevent the script from being included where it isn&#8217;t wanted.  Often a quick Google search will show other people who have tackled the same issue.  I was able to disable the javascript/css components of several plugins in just a few minutes, relying on other&#8217;s expertise.</p>
<p>It is much faster for PHP to selectively unregister a script in functions.php than for your browser to download and process it.</p>
<p>You should notice immediate, tangible improvement as you work down the list.</p>
<p><strong>Combine and minify</strong><br />
Once you have your JavaScript and CSS running at a bare minimum, it&#8217;s time to combine and minify.  The more files your browser has to touch while loading a page, the slower.  The goal of combining is to reduce several requests into one.  The goal of minifying is to reduce the total size of a download by removing comments, line breaks, etc.</p>
<p>Now, I know what some of you are thinking &#8220;But you can do this with caching plugins!&#8221; Which is true.  But, as we&#8217;ve already mentioned we&#8217;re trying to take a minimalistic approach.</p>
<p>While there are plenty of online services you can submit your CSS and JavaScript files to for minification, this is often highly inconvenient.  It forces you to maintain development and production versions of your files (which may not make sense for the size of your operation), and it can be difficult to troubleshoot if you don&#8217;t have a working test environment.</p>
<p>Enter <a href="http://wordpress.org/extend/plugins/wp-minify/">WP Minify</a>.</p>
<p>WP-Minify has the magic ability to do all of this on the fly.   Install. Activate.  Done.  It even minifies your HTML output.</p>
<p>Now, with anything like this, there can be issues so you&#8217;ll want to do full regression testing on anything that requires JavaScript once you&#8217;re done.  You&#8217;ll also want to pay close attention to styling as it can have an inadvertent effect on the order styles are loaded. (That whole &#8220;cascading&#8221; part of CSS)</p>
<p>If you have a problem with a script (as I did), the easiest thing to do is just add it to the list of exclusions.  This allows you to reap 90% of the benefits while not changing your whole site to fit an optimization technique.</p>
<p>It also does some other little things for you like setting far future expiration dates and enabling gzip. (More on that later)</p>
<p><strong>Alternative PHP Cache</strong><br />
This next tip only applies if you have a dedicated (virtual or physical) server with root access.   PHP, while having many awesome qualities, is not known for being the fastest language in the world.   This is mainly because it compiles and recompiles each script every time it is requested.  Large operations like Facebook get around this by converting their PHP to C before publishing, but that isn&#8217;t a very practical solution for most people.</p>
<p>The most reliable way to improve PHP&#8217;s processing time is to use an opcode optimizer.  This allows PHP to cache the compiled version of a page and rerun it from RAM on subsequent requests.  This is tons faster than pulling from disk and recompiling! While there are several options in this realm, I think Alternative PHP Cache is the best choice for two simple reasons: 1) It is made by the PHP guys 2) it&#8217;s going to be built into PHP 6</p>
<p>Those are pretty strong reasons to get on board in my book.</p>
<p>Installing APC is relatively easy depending on your server config.  There are many guides, often specific to the hosting service so I recommend you do a quick search before you get started.</p>
<p>Tweaking the settings can have a learning curve.  I recommend you accept the defaults and then tweak once you have a chance to watch how it performs.   The basic concept is this:  you have a certain amount of dedicated cache where pages are compiled and stored.  If this cache fills up frequently, it forces APC to flush the cache.  If this happens often, you get what&#8217;s called cache churn which can actually hinder performance.   Your goal is to have a large enough cache with a good expiration interval that allows the cache to stay relatively full without actually running out of space.</p>
<p>The nice thing about APC is that just installing it gives you a performance boost.  But, since this is about WordPress, I recommend you install <a href="http://wordpress.org/extend/plugins/apc/">APC Object Cache Backend</a>.  This allows WordPress&#8217;s built in caching engine to fully leverage APC&#8217;s features.   Read the instructions carefully&#8230;this isn&#8217;t installed like a normal plugin.  The file actually goes in wp-content/ directly.  Weird, I know.</p>
<p><strong>Optimize those images</strong><br />
In addition to the above, images are often the slowest component of a page.   Make sure you use JPEGs wherever appropriate and stick with PNGs only where lossless is absolutely necessary or where transparency is desired.</p>
<p>For JPEGs, pick a quality level that will satisfy your level of pixel OCD.  The smaller the files, the faster they&#8217;ll load.</p>
<p>Once you&#8217;re done with that,  you should use a tool that can losslessly optimize your images.  I chose <a href="http://freshmeat.net/projects/jpegoptim/">jpegoptim</a> for this.  Because I&#8217;m a nerd, I installed this on my server and setup a cron to run it against my images (of which I have many thousands on the install I&#8217;m referencing) weekly.</p>
<p>It&#8217;s easy to install and easy to run.</p>
<p>Just run this via SSH:</p>
<pre>jpegoptim --strip-all /your/awesome/path/*</pre>
<p>This will optimize each image, skipping any that will result in a larger size or no change.</p>
<p>(A word of caution, I found that this altered the permissions of my images&#8230;so double check the permissions after you&#8217;re done.)</p>
<p>In total, I was able to cut down my images sizes 10% with no loss of quality.  That&#8217;s pretty cool.</p>
<p><strong>Expiration and Gzip</strong><br />
The fewer times a browser refreshes your static files from cache, the faster your load times will be.  Because of this it&#8217;s desirable to have a lengthy expiration date on your JavaScript, CSS, and image files.   This is most easily accomplished with the Apache module mod_expire.  Your server probably already has it installed *crosses fingers* and turning it on/configuring it is <a href="http://www.google.com/search?sourceid=chrome&amp;ie=UTF-8&amp;q=setting+up+mod_expire">rather easy</a>.</p>
<p>Similarly, mod_deflate for Apache can gzip plain text files for faster delivery.  The small cost of server overhead is well worth the advantages of smaller downloads.  Processing time is cheaper than bandwidth (at least in this case).</p>
<p>To set this up, <a href="http://www.brighterlamp.com/2010/10/how-to-enable-mod_deflate-on-apache-to-optimize-page-speed/">I suggest you look at this guide.</a></p>
<p><a href="http://www.brighterlamp.com/2010/10/how-to-enable-mod_deflate-on-apache-to-optimize-page-speed/"></a></p>
<p><strong>Et Cetera</strong><br />
Beyond this, there are many other things you can do, but I&#8217;ve tried to cover only the things I think go most unnoticed and apply to nearly every install. I highly recommend you use the aforementioned YSlow plugin and Google&#8217;s Page Speed feature (available in Chrome and Firefox) for more performance tips. (And many of these were inspired by such tools).</p>
<p>In addition to what I&#8217;ve recommended, there are literally hundreds (if not thousands) of techniques out there:</p>
<ol>
<li>You can enable a conservative caching plugin like Hypercache (which hopefully plays nicely with the above plugins).</li>
<li>You can optimize your MySQL tables (to reclaim free space).</li>
<li>You can limit how many revisions WordPress keeps for each post by modifying wp-config.php.</li>
<li>You can offload commenting to services like Disqus.</li>
<li>You can change your scripts to run asynchronously.</li>
<li>Etc. Ad infinitum.</li>
</ol>
<p>As you can see, it would be fairly easy to <em>waste*</em> a lot of time here. (I once saw this called the &#8220;Holy Grail of micro-performance optimizations&#8221;) But, that being said, it&#8217;s worth diving into these things at least once.   Your users will like it.  Google&#8217;s page ranking will like it.  And you&#8217;ll like it.  You may even be amazed by the results.  (I know I was!)</p>
<p><em>*If you see anyone telling you to get rid of references to get_bloginfo() in your templates in favor of hardcoded paths, tell &#8216;em to take a hike.  That&#8217;s a truly pointless change and you won&#8217;t see any real performance gains&#8230;WordPress is smart enough to handle that stuff inexpensively.</em></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/05/26/another-guide-to-optimizing-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Twitch for Blinksale</title>
		<link>http://clifgriffin.com/2011/04/15/twitch-for-blinksale/</link>
		<comments>http://clifgriffin.com/2011/04/15/twitch-for-blinksale/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 01:40:06 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1295</guid>
		<description><![CDATA[After many late nights, long weekends, and a couple of months I am finally finished with version 1.0 of Twitch for Blinksale. Twitch for Blinksale is the first native iPhone/iOS client for the popular invoicing service Blinksale. With Twitch, you can manage all of your invoicing needs right from your iPhone. Its clean, professional design [...]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-1315" style="clear: both;" title="Twitch for Blinksale" src="http://clifgriffin/wp-content/uploads/2011/04/twitch_rounded.png" alt="Twitch for Blinksale - An iPhone app for Blinksale" width="191" height="190" />After many late nights, long weekends, and a couple of months I am finally finished with version 1.0 of Twitch for Blinksale.</p>
<p>Twitch for Blinksale is the first native iPhone/iOS client for the popular invoicing service Blinksale.  With Twitch, you can manage all of your invoicing needs right from your iPhone.</p>
<p>Its clean, professional design highlights the information you need. Updating invoices on-the-go has never been easier.</p>
<p>Invoices Features:</p>
<ul>
<li>View, add, update invoices.</li>
<li>Send invoices to clients with or without payment link.</li>
<li>Receive payment for invoices.</li>
</ul>
<p>Client Features:</p>
<ul>
<li>View and add clients.</li>
<li>Add people to clients.</li>
<li>Contact clients directly from phone (using the iPhone&#8217;s phone and mail apps)</li>
</ul>
<p>More:</p>
<ul>
<li>Convenient, &#8220;Pull To Refresh&#8221; design on invoice and client views makes reloading data a cinch.</li>
<li>Tested on multiple iPhone devices and OS versions.</li>
<li>Very stable.</li>
<li>Secure credential storage in keychain.</li>
</ul>
<p>Screenshots:</p>
<p><a href="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-58-50-PM.jpg"><img class="alignnone size-medium wp-image-1297" title="Invoice Detail View" src="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-58-50-PM-200x300.jpg" alt="" width="200" height="300" /></a><a href="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-03-PM.jpg"><img class="alignnone size-medium wp-image-1298" title="Invoice Detail View" src="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-03-PM-200x300.jpg" alt="" width="200" height="300" /></a><a href="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-13-PM.jpg"><img class="alignnone size-medium wp-image-1299" title="Invoice Action menu.  Lots of options." src="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-13-PM-200x300.jpg" alt="" width="200" height="300" /></a><br/><img class="alignnone size-medium wp-image-1300" title="Invoice Creation View" src="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-22-PM-200x300.jpg" alt="" width="200" height="300" /><img class="alignnone size-medium wp-image-1301" title="Client List View" src="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-31-PM-200x300.jpg" alt="" width="200" height="300" /><img class="alignnone size-medium wp-image-1302" title="Client Detail View" src="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-40-PM-200x300.jpg" alt="" width="200" height="300" /></p>
<p>&nbsp;</p>
<p><a href="http://clifgriffin/wp-content/uploads/2011/04/Photo-Apr-09-3-59-31-PM.jpg"></a></p>
<p>Twitch for Blinksale is <a href="itunes.apple.com/us/app/twitch-for-blinksale/id431491955?mt=8&amp;ls=1">available for purchase in the App Store</a>.</p>
<p><a href="itunes.apple.com/us/app/twitch-for-blinksale/id431491955?mt=8&amp;ls=1"><img class="alignnone size-full wp-image-1317" title="Twitch for Blinksale" src="http://clifgriffin/wp-content/uploads/2011/04/available_on_appstore_11.png" alt="Available in the iPhone app store" width="150" height="50" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/04/15/twitch-for-blinksale/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Bulk Updating Image Sizes in @ShopPlugin</title>
		<link>http://clifgriffin.com/2011/03/30/bulk-updating-image-sizes-in-shopplugin/</link>
		<comments>http://clifgriffin.com/2011/03/30/bulk-updating-image-sizes-in-shopplugin/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 19:01:37 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1291</guid>
		<description><![CDATA[This will be two helper scripts I&#8217;ve written in a row for Shopp. We found a situation recently where we had images with different sizes in Shopp, making uniform usage difficult at times. To compensate for this, we exported the images again. Since we use a consistent naming scheme, we didn&#8217;t have to worry about [...]]]></description>
				<content:encoded><![CDATA[<p>This will be two helper scripts I&#8217;ve written in a row for Shopp.</p>
<p>We found a situation recently where we had images with different sizes in Shopp, making uniform usage difficult at times.  To compensate for this, we exported the images again.  Since we use a consistent naming scheme, we didn&#8217;t have to worry about names.</p>
<p>We then uploaded these new images over the existing images in the /wp-content/uploads/shopp folder.</p>
<p>In a perfect world, this would be all there was to it, but unfortunately Shopp stores width and height information about an image in the database.  This meant each table entry had to be updated.  Enter this script.</p>
<p>It automatically scans your uploads directory and looks for images that have a different size than is stored in the database.  It then updates the size.</p>
<p><strong><span style="color: #ff0000;">WARNING: This script is DESTRUCTIVE.  It can potentially screw up your database so PLEASE make sure you have a full backup.  This is provided without any warranty whatsoever. I have only tested this on Shopp 1.1.17 and have no idea how it will work/not work on other versions.</span></strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//Adjust to point to root from where this script is located</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'../wp-load.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Edit this path</span>
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/var/www/vhosts/domain/httpdocs/wp-content/uploads/shopp'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// END EDITS. You shouldn't have to edit below this line.</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;auto_detect_line_endings&quot;</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: #000088;">$dir_handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</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: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$csv_data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir_handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;..&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$width_regex</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/((?&lt;=width\&quot;;i:)[0-9]{1,4})|((?&lt;=width=\&quot;)[0-9]{1,4})/'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$height_regex</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/((?&lt;=height\&quot;;i:)[0-9]{1,4})|((?&lt;=height=\&quot;)[0-9]{1,4})/'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select value from wp_shopp_meta where value LIKE '%&quot;</span><span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$file</span>.&quot;</span><span style="color: #0000ff;">&quot;%'&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$existing_properties</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</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: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$existing_properties</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$new_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$info</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$new_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$info</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_regex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$existing_properties</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height_regex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$existing_properties</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_width</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$old_width</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$new_height</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$old_height</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$old_width</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$old_height</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Updating <span style="color: #006699; font-weight: bold;">$file</span>. Old width/height: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$old_width</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$old_height</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; New width/height: <span style="color: #006699; font-weight: bold;">$new_width</span>/<span style="color: #006699; font-weight: bold;">$new_height</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000088;">$new_properties</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_regex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$existing_properties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$new_properties</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height_regex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_properties</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: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_properties</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$query_update</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update wp_shopp_meta set value = '&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_properties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' where value LIKE '%&quot;</span><span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$file</span>.&quot;</span><span style="color: #0000ff;">&quot;%'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #666666; font-style: italic;">//echo &quot;Query update: &quot;.$query_update.&quot;n&quot;;</span>
&nbsp;
					<span style="color: #000088;">$update</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_update</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;">$update</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; --- FAILED. No rows changed. Didn't update.n&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$update</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; --- POSSIBLE FAILURE. Updated too many rows.(<span style="color: #006699; font-weight: bold;">$update</span>)n&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">else</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; --- SUCCESSn&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;--- FAILED. New properties string suspiciously short.&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Hope it helps.  Let me know if there are questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/03/30/bulk-updating-image-sizes-in-shopplugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting Shopp&#039;s Image Storage From Database to File System</title>
		<link>http://clifgriffin.com/2011/03/21/converting-shopps-image-storage-from-database-to-file-system/</link>
		<comments>http://clifgriffin.com/2011/03/21/converting-shopps-image-storage-from-database-to-file-system/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 18:34:43 +0000</pubDate>
		<dc:creator>clifgriffin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://clifgriffin.com/?p=1283</guid>
		<description><![CDATA[I have been searching for a little while for an easy way to convert a Shopp install from using the database for image storage to using the file system. The advantages for this are obvious, especially when you have 3000 images and your database has bloomed to several hundred MB. Failing to find one, I [...]]]></description>
				<content:encoded><![CDATA[<p>I have been searching for a little while for an easy way to convert a Shopp install from using the database for image storage to using the file system.</p>
<p>The advantages for this are obvious, especially when you have 3000 images and your database has bloomed to several hundred MB.</p>
<p>Failing to find one, I decided to write my own.  Shopp&#8217;s image store rules (at least in 1.0.14) seem to follow this model:</p>
<ul>
<li>Check wp_shopp_asset table to see if an image has been stored in the data column.</li>
<li>If it isn&#8217;t there, assume it&#8217;s in the filesystem path.</li>
</ul>
<p>After about an hour, I came up with this solution (<strong><span style="color: #ff0000;">WARNING: This script is DESTRUCTIVE.  It will delete all of your images from the database so PLEASE make sure you have a full backup.  This is provided without any warranty whatsoever. I have only tested this on Shopp 1.0.14 and have no idea how it will work/not work on other versions.</span></strong>):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Copyright 2011, Clifton H. Griffin II</span>
<span style="color: #666666; font-style: italic;">// This script is DESTRUCTIVE.  It will delete all images in your database!</span>
<span style="color: #666666; font-style: italic;">// Run at your own risk. It is provided with NO WARRANTY WHATSOEVER.</span>
<span style="color: #666666; font-style: italic;">// Please read carefully and do a full backup before using!</span>
<span style="color: #666666; font-style: italic;">// Test with Shopp 1.0.14</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//EDIT THIS LINE (this directory must be writeable)</span>
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/var/www/vhosts/domain.com/httpdocs/wp-content/uploads/shopp&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Load WP data objects</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'wp-load.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Get list of rows from shopp</span>
<span style="color: #000088;">$sql</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT id FROM wp_shopp_asset&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ARRAY_A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Loop through them, grabbing images</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$therow</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_row</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT name, data FROM wp_shopp_asset WHERE id = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ARRAY_A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$therow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;data&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$therow</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File name: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$name</span> &lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$name</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Clear image from DB</span>
	<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE wp_shopp_asset SET data = null WHERE id = <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: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//Optimize the table to clear unused space</span>
<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OPTIMIZE TABLE wp_shopp_asset&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>It should be fairly self-explanatory.   Use at your own risk.  I create a public github repository to host the file, on the off chance others want to add to it: <a href="https://github.com/clifgriffin/Shopp-Image-Export">https://github.com/clifgriffin/Shopp-Image-Export</a></p>
<p>Let me know if it helps you out. </p>
]]></content:encoded>
			<wfw:commentRss>http://clifgriffin.com/2011/03/21/converting-shopps-image-storage-from-database-to-file-system/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
