<?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>Illuminati Karate, Inc. &#187; Web Development</title>
	<atom:link href="http://illuminatikarate.com/blog/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://illuminatikarate.com</link>
	<description>creative web design, development and marketing</description>
	<lastBuildDate>Fri, 03 Feb 2012 20:13:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How To Add A Lightbox To A WordPress Gallery</title>
		<link>http://illuminatikarate.com/blog/wordpress-how-to-add-a-lightbox-to-a-wordpress-gallery/</link>
		<comments>http://illuminatikarate.com/blog/wordpress-how-to-add-a-lightbox-to-a-wordpress-gallery/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 14:39:25 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[prettyphoto]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=532</guid>
		<description><![CDATA[I wanted to setup a simple lightbox photo gallery on a WordPress site (v3.2.1) and, to avoid installing a slew of plugins, I put together a little gallery shortcode function using the built-in WordPress gallery shortcode as my starting point. I&#8217;m a big fan of PrettyPhoto, so I modified [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to setup a simple lightbox photo gallery on a WordPress site (v3.2.1) and, to avoid installing a slew of plugins, I put together a little gallery shortcode function using the built-in WordPress gallery shortcode as my starting point. I&#8217;m a big fan of <a title="PrettyPhoto" href="http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/" target="_blank">PrettyPhoto</a>, so I modified the output of the gallery shortcode to include the needed rel= attribute for PrettyPhoto galleries.<span id="more-532"></span></p>
<p>I grabbed the standard WordPress gallery shortcode from line ~758 in wp-includes/media.php and pasted it into my_theme/functions.php for modification.  For the more adventurous folks you can override the default WordPress gallery shortcode and then galleries you&#8217;ve inserted using the Media Gallery will be lightboxed.</p>
<p>Here&#8217;s the code I ended up with in functions.php <em>(shortened for readability, you&#8217;ll need to C&#038;P the entire shortcode function from wp-includes/media.php)</em>:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5325"><td class="code" id="p532code5"><pre class="php" style="font-family:monospace;">add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_gallery_shortcode'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_gallery_shortcode_function'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_gallery_shortcode_function<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</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;">$post</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_locale</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">...</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">'file'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span> ? wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//add rel=&quot;prettyPhoto[pp_gal]&quot;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&gt;&lt;img'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rel=&quot;prettyPhoto[pp_gal]&quot; &gt;&lt;img'</span><span style="color: #339933;">,</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$itemtag}</span> class='gallery-item'&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;<span style="color: #006699; font-weight: bold;">{$icontag}</span> class='gallery-icon'&gt;
				<span style="color: #006699; font-weight: bold;">$link</span>
			&lt;/<span style="color: #006699; font-weight: bold;">{$icontag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$captiontag</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
				&lt;<span style="color: #006699; font-weight: bold;">{$captiontag}</span> class='wp-caption-text gallery-caption'&gt;
				&quot;</span> <span style="color: #339933;">.</span> wptexturize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;
				&lt;/<span style="color: #006699; font-weight: bold;">{$captiontag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/<span style="color: #006699; font-weight: bold;">{$itemtag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;br style=&quot;clear: both&quot; /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;br style='clear: both;' /&gt;
		&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>My edit was small, I added <code>$link=str_replace('&gt;&lt;img','rel="prettyPhoto[pp_gal]" &gt;&lt;img',$link);</code> to the gallery output so that PrettyPhoto can do it&#8217;s thing.</p>
<p>Now that you have that all you need to do is be sure you&#8217;re including the necessary files:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5326"><td class="code" id="p532code6"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> media<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;all&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=bloginfo('template_directory');?&gt;/prettyPhoto/css/prettyPhoto.css&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=bloginfo('template_directory');?&gt;/prettyPhoto/js/jquery.prettyPhoto.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>And be sure to call PrettyPhoto:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code7'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5327"><td class="code" id="p532code7"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[rel^='prettyPhoto']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prettyPhoto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Now all you need to do is upload photos to your gallery and use this shortcode on your page:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code8'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5328"><td class="code" id="p532code8"><pre class="html" style="font-family:monospace;">[my_gallery_shortcode link=&quot;file&quot;]</pre></td></tr></table></div>

<p>And that&#8217;s it!  A quick solution to adding a lightbox to your WordPress gallery.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wordpress-how-to-add-a-lightbox-to-a-wordpress-gallery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: How To Change Comment Excerpt Length</title>
		<link>http://illuminatikarate.com/blog/wordpress-how-to-change-comment-excerpt-length/</link>
		<comments>http://illuminatikarate.com/blog/wordpress-how-to-change-comment-excerpt-length/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 18:17:17 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=493</guid>
		<description><![CDATA[I recently needed to output a list of comments and bumped into a little trouble trying to output the comment excerpt. Usually I would use the built-in comment_excerpt() function but I only needed 10 words instead of the 20 that is hard-coded. I put together a little function that [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to output a list of comments and bumped into a little trouble trying to output the comment excerpt.  Usually I would use the built-in comment_excerpt() function but I only needed 10 words instead of the 20 that is hard-coded.  I put together a little function that I found helpful and thought I would share.</p>
<p>  <span id="more-493"></span></p>
<p>I started with get_comment_excerpt() from line ~407 of wp-includes/comment-template.php and pasted it into my_name/functions.php to be modified.</p>
<p>Here&#8217;s what I ended up with:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p493code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49311"><td class="code" id="p493code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_get_comment_excerpt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_ID</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num_words</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$comment</span> <span style="color: #339933;">=</span> get_comment<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$comment_ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$comment_text</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blah</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blah</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$num_words</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$num_words</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$use_dotdotdot</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</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;">$k</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blah</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$use_dotdotdot</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$excerpt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$k</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$excerpt</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$blah</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$excerpt</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$use_dotdotdot</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'...'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_comment_excerpt'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$excerpt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><br/></p>
<p>And here&#8217;s a little code to output a list of comments using this function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p493code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49312"><td class="code" id="p493code12"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
	<span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> get_comments<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo get_permalink(<span style="color: #006699; font-weight: bold;">$c-&gt;comment_post_ID</span>); ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/* output 10 words of comment */</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> my_get_comment_excerpt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_ID</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>		
		<span style="color: #339933;">&lt;</span>span<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_author</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>span<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m/j/Y&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_date</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: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Feel free to ask questions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wordpress-how-to-change-comment-excerpt-length/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP e-Commerce Category Product List Shortcode</title>
		<link>http://illuminatikarate.com/blog/wp-e-commerce-category-product-list-shortcode/</link>
		<comments>http://illuminatikarate.com/blog/wp-e-commerce-category-product-list-shortcode/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 17:35:59 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[WP E-Commerce]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=570</guid>
		<description><![CDATA[While setting up a store using WP e-Commerce (v3.8.5 at the time of development) I noticed that the Category Product List Shortcode was no longer working for me. I cooked up a quick shortcode function using some of their product list code that will query the products by the [...]]]></description>
			<content:encoded><![CDATA[<p>While setting up a store using <a href="http://www.instinct.co.nz/e-commerce/" target="_blank" title="WP E-Commerce">WP e-Commerce</a> <em>(v3.8.5 at the time of development)</em> I noticed that the <a href="http://www.instinct.co.nz/e-commerce/integration/" target="_blank">Category Product List Shortcode</a> was no longer working for me.  </p>
<p>I cooked up a quick shortcode function using some of their product list code that will query the products by the passed category and output them using the product template.<span id="more-570"></span></p>
<p>First, place the following code in my_theme/functions.php:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p570code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57014"><td class="code" id="p570code14"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_wpsc_products_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$number_per_page</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'use_pagination'</span><span style="color: #009900;">&#41;</span> ? get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpsc_products_per_page'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> shortcode_atts<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'category_id'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$atts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'limit_of_items'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'sort_order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'number_per_page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$number_per_page</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> wpsc_display_products_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_wpsc_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_wpsc_products_shortcode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once that&#8217;s done you&#8217;ll be able to use <code>[my_wpsc_category cat=6 /]</code>, where 6 is the integer ID of the category, on whichever page you want the products displayed on.  </p>
<p>This list will be output using the wpsc-single_product.php template or the wpsc-products_page.php template, depending on whether you have multiple products in the category.</p>
<p>Feel free to ask questions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wp-e-commerce-category-product-list-shortcode/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Finding the Carrier of a Cell Phone Number in PHP</title>
		<link>http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/</link>
		<comments>http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 03:47:37 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[cell phones]]></category>
		<category><![CDATA[cellular]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=470</guid>
		<description><![CDATA[Often web apps need to send SMS messages to their users (for example: balance alerts, reminders, notifications). To send these text messages from within your app, you basically have 2 options: 1) Pay Twilio and Tropo for the use of their APIs, for roughly a penny per message. 2) [...]]]></description>
			<content:encoded><![CDATA[<p>Often web apps need to send SMS messages to their users (for example: balance alerts, reminders, notifications). To send these text messages from within your app, you basically have 2 options:</p>
<p>1) Pay <a title="Twilio" href="http://twilio.com">Twilio</a> and <a title="Tropo" href="http://tropo.com">Tropo</a> for the use of their APIs, for roughly a penny per message.</p>
<p>2) Send an email directly to their carrier&#8217;s mail-to-SMS gateway &#8211; a free service most carriers provide, which will translate your email into an SMS sent to their subscribers&#8217; phone</p>
<p>Twilio and Tropo are about as easy as it gets to integrate (REST-like APIs that return <a href="http://json.org">JSON</a>/<a href="http://en.wikipedia.org/wiki/Plain_Old_XML">POX</a>), but you pay for every single message and that can add up quickly. So #2 (mail-to-SMS gateways) starts to look pretty good.</p>
<p>But there&#8217;s some problems with mail-to-SMS gateways:<span id="more-470"></span></p>
<p>1) Each carrier has their own format. For example, T-Mobile&#8217;s gateway is <em>number</em>@tmomail.net (for the US), AT&amp;T&#8217;s is <em>number</em>@txt.att.net (for most of their customers), and Verizon is <em>number</em>@vtext.net (unless you used to be with Alltel &#8211; then its <em>number</em>@message.alltel.com). A big <a href="http://en.wikipedia.org/wiki/List_of_SMS_gateways">list of mail-to-SMS-gateways</a> is available on Wikipedia.</p>
<p>Bonus:some carriers want the international code prepended (the 1 in front of  the number, for the US), some carriers don&#8217;t. (e.g., T-Mobile does,  AT&amp;T doesn&#8217;t)</p>
<p>2) Some carriers require authentication (Sprint) or don&#8217;t have a mail-to-SMS gateway at all (Google Voice).</p>
<p>3) If the user ports their number to a different carrier you&#8217;ll have to detect it and react accordingly.</p>
<p>So you&#8217;ll have to figure out what carrier they&#8217;re using in order to direct the email and meet whatever requirements &#8211; which usually means asking the user to choose their carrier from a list.</p>
<p><strong>There is a better way!</strong> What if we could detect the carrier automatically?</p>
<p>It turns out you can. The lovely folks at <a href="http://cloudvox.com">CloudVox </a>made an API that does exactly that &#8211; you give it a phone number, and it tells you the carrier and if its a cell-phone or landline. Its 100% free, with no API keys/credentials required. </p>
<p>Its hosted at <a href="http://digits.cloudvox.com">digits.cloudvox.com</a>, along with example calls/responses (<a href="http://help.cloudvox.com/kb/digits/digits-phone-number-location-lookup-api">full docs are here</a>). It speaks JSON over HTTP.</p>
<p>This gives us a much better user experience:</p>
<p>1) User inputs their number, no carrier dropdown needed</p>
<p>2) We use CloudVox&#8217;s API to determine their carrier</p>
<p>3) Try to send them an SMS, and have them confirm ownership in the normal way (i.e., enter a confirmation code)</p>
<p>This will cover most people, and is free outside of the development time. If there was an error (i.e., we couldn&#8217;t find the number with CloudVox&#8217;s API, or we did but the carrier doesn&#8217;t support mail-to-SMS), we can fall back to Twilio or Tropo. We&#8217;re still paying a few cents here and there, but the default case is free.</p>
<p>Here&#8217;s some example code in PHP, for querying CloudVox&#8217;s API:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47016"><td class="code" id="p470code16"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">/* Finds the carrier for the given phone number using CloudVox's API. Returns the carrier name as a string on success, or false if the carrier couldn't be determined */</span>
	<span style="color: #000000; font-weight: bold;">function</span> findCarrier<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$carrier</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will contain the carriers name as a string if we are able to look it up</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// attempt to lookup the number with the CloudVox API</span>
		<span style="color: #000088;">$requestUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://digits.cloudvox.com/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$phoneNumber</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.json'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$apiResponse</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$requestUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Note: needs code to handle the error case of file_get_contents</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$apiResponse</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$responseJson</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/json_decode"><span style="color: #990000;">json_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$apiResponse</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseJson</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allocation</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseJson</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allocation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">carrier_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$carrier</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$responseJson</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allocation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">carrier_name</span><span style="color: #339933;">;</span>			
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$carrier</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will be false or the name of the carrier</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phoneNumber'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// user has submitted a form via GET, containing a field called phoneNumber</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// collect the phoneNumber and remove any non-numeric chars</span>
		<span style="color: #000088;">$phoneNumber</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#[^0-9]#'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phoneNumber'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$carrier</span> <span style="color: #339933;">=</span> findCarrier<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</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;">$carrier</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><a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$carrier</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'verizon'</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>
				sendWithVerizon<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$carrier</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'at&amp;t'</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>
				sendWithATT<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</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: #666666; font-style: italic;">// other carrier. you'd really want to fall back to Twilio/Tropo here, and/or log the carrier so you can add it later</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Unknown Carrier: <span style="color: #006699; font-weight: bold;">{$carrier}</span>&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: #666666; font-style: italic;">// send SMS via Twilio or Tropo instead</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: #666666; font-style: italic;">// show the form</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;form&gt;'</span> <span style="color: #339933;">.</span> 
			 <span style="color: #0000ff;">'&lt;label for=&quot;phoneNumber&quot;&gt;Phone Number&lt;/label&gt;'</span> <span style="color: #339933;">.</span>
			 <span style="color: #0000ff;">'&lt;input type=&quot;text&quot; name=&quot;phoneNumber&quot; /&gt;'</span> <span style="color: #339933;">.</span>
			 <span style="color: #0000ff;">'&lt;/form&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Facebook Graph API requires Access Token for Feed Access</title>
		<link>http://illuminatikarate.com/blog/facebook-graph-api-requires-access-token-for-feed-access/</link>
		<comments>http://illuminatikarate.com/blog/facebook-graph-api-requires-access-token-for-feed-access/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 18:49:58 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=442</guid>
		<description><![CDATA[On June 3rd, Facebook updated the Graph API to require an access token to pull wall post data from public Facebook pages. This change can cause scripts to stop working, so here is a quick solution to pull wall post data from public Facebook pages with an access token. [...]]]></description>
			<content:encoded><![CDATA[<p>On June 3rd, Facebook <a href="http://developers.facebook.com/blog/post/510/">updated the Graph API</a> to require an access token to pull wall post data from public Facebook pages.  This change can cause scripts to stop working, so here is a quick solution to pull wall post data from public Facebook pages with an access token.<span id="more-442"></span></p>
<p>Consider the following code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p442code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44220"><td class="code" id="p442code20"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_init"><span style="color: #990000;">curl_init</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_close"><span style="color: #990000;">curl_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p442code21'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44221"><td class="code" id="p442code21"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$profile_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1234567890&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'feed_data'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://graph.facebook.com/<span style="color: #006699; font-weight: bold;">{$profile_id}</span>/feed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Before the recent changes, this was all you needed to load a Facebook page&#8217;s feed.  You could load a public page&#8217;s feed by simply pulling from graph.facebook.com/{profile_id}/feed.  With the recent changes you just have to make a small modification and you&#8217;re good to go.</p>
<p>Here is the updated code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p442code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44222"><td class="code" id="p442code22"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$profile_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1234567890&quot;</span><span style="color: #339933;">;</span>		
&nbsp;
<span style="color: #666666; font-style: italic;">//App Info, needed for Auth</span>
<span style="color: #000088;">$app_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0001234567890&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$app_secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abc123ebf123f3g5g6j&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//retrieve auth token</span>
<span style="color: #000088;">$authToken</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://graph.facebook.com/oauth/access_token?type=client_cred&amp;client_id=<span style="color: #006699; font-weight: bold;">{$app_id}</span>&amp;client_secret=<span style="color: #006699; font-weight: bold;">{$app_secret}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'feed_data'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://graph.facebook.com/<span style="color: #006699; font-weight: bold;">{$profile_id}</span>/feed?<span style="color: #006699; font-weight: bold;">{$authToken}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Be sure to use https instead of http, needed for OAuth.  You&#8217;ll also need to <a href="http://developers.facebook.com">create a simple Facebook app</a> to get an App ID and Secret key.  Once done, just swap out the variables in the above script for the proper values and you&#8217;re off to the races!</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/facebook-graph-api-requires-access-token-for-feed-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Submitting a Contact Form via AJAX From Your Facebook Page</title>
		<link>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/</link>
		<comments>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 03:57:08 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[FBJS]]></category>
		<category><![CDATA[FBML]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=297</guid>
		<description><![CDATA[We recently created a contact submission form on a client&#8217;s Facebook page, and were not satisfied with the default user experience. For starters, the form opened a new window, and there was no way to redirect the user back to a confirmation message on the Facebook page. We decided [...]]]></description>
			<content:encoded><![CDATA[<p>We recently created a contact submission form on a client&#8217;s Facebook page, and were not satisfied with the default user experience. For starters, the form opened a new window, and there was no way to redirect the user back to a confirmation message on the Facebook page. </p>
<p>We decided to submit the form via AJAX instead, and show the confirmation message directly on the Facebook page. This way the user would not have to leave the Facebook page, resulting in a smoother user experience. We couldn&#8217;t find a good explanation of how to do this on Google, so after figuring it out I decided to go ahead and write it up. </p>
<p>The following example will show you how to submit a basic contact form using AJAX from within your Facebook page. All HTML and Javascript that follows should be pasted directly into the &#8220;Edit FBML&#8221; screen on Facebook.</p>
<p><span id="more-297"></span>Here&#8217;s the example form HTML we&#8217;ll use for the rest of this article. It&#8217;s just two text fields (name and email) and a submit button:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code26'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29726"><td class="code" id="p297code26"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;http://mywebsite.com/form_submit.php&quot; method=&quot;post&quot;&gt;
     &lt;p&gt;
          &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt;
     &lt;/p&gt;
     &lt;p&gt;
          &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; /&gt;
     &lt;/p&gt;
     &lt;button type=&quot;submit&quot; onclick=&quot;return submitAjaxForm();&quot;&gt;Submit&lt;/button&gt;
     &lt;p id=&quot;ajaxMessage&quot;&gt;&lt;/p&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>There&#8217;s three things you should take note of:</p>
<ol>
<li>The form&#8217;s <b>action</b> attribute is set to a page on mywebsite.com, not facebook.com (replace mywebsite.com with your own domain)</li>
<li>The submit button has an onSubmit event that calls a function submitAjaxForm, which we&#8217;ll define shortly</li>
<li>At the end of the form is an empty paragraph tag. We&#8217;ll use this space to display messages to the user.</li>
</ol>
<p>On our server, form_submit.php is a simple PHP script that logs the submissions, and sends back a message for the user letting them know the submission was successful. It might look something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29727"><td class="code" id="p297code27"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
     log_submission<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Thank you for your submission!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Of course, your script will be more sophisticated than this one, and doesn&#8217;t have to be written in PHP. Its on your server, so you can handle logging the submission however you like. Just make sure the output is valid <a href="http://wiki.developers.facebook.com/index.php/FBML">FBML</a>.</p>
<p>With the form HTML added to your Facebook page and the logging script in place, the only thing left is adding the Javascript to submit the form via AJAX and show the confirmation message.</p>
<p class="note"><b>Note:</b> Facebook does not allow you to use any Javascript function you like, for security purposes. Instead they&#8217;ve created a library of Javascript functions for accessing the DOM, AJAX, and event binding called <a href="http://wiki.developers.facebook.com/index.php/FBJS">FBJS</a>. These functions are used in the example below.</p>
<p>We&#8217;ll now define the submitAjaxForm() function we referenced earlier in our submit button&#8217;s onSubmit event:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code28'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29728"><td class="code" id="p297code28"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;&lt;!--</span>
<span style="color: #003366; font-weight: bold;">function</span> submitAjaxForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
	<span style="color: #006600; font-style: italic;">// declare a new FBJS AJAX object</span>
	<span style="color: #003366; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	ajax.<span style="color: #660066;">responseType</span> <span style="color: #339933;">=</span> Ajax.<span style="color: #660066;">FBML</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// define a callback to handle the response from the server</span>
	ajax.<span style="color: #660066;">ondone</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajaxMessage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setInnerFBML</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// let the user know we're sending the data	</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajaxMessage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setInnerXHTML</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Submitting your information, please wait...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// collect field values</span>
	<span style="color: #003366; font-weight: bold;">var</span> queryParams <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'name'</span> <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'email'</span> <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	ajax.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://mywebsite.com/form_submit.php'</span><span style="color: #339933;">,</span> queryParams<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span></pre></td></tr></table></div>

<p><em>Note: The opening and closing HTML comments embedded in the Javascript are important, so leave them intact.</em></p>
<p>The example is fairly self explanatory, but here&#8217;s what&#8217;s happening:</p>
<ol>
<li>Declare a new Ajax object, which is one of the FBJS classes. We then set its response type to FBML (Ajax.RAW and Ajax.JSON are also accepted).</li>
<li>Define a callback function to handle the response from the server. In this case, our function simply takes the response from the server and displays it in the #ajaxMessage paragraph we defined earlier.</li>
<li>Update the user to let them know their data is being submitted using FBJS&#8217;s setInnerFBML function.</li>
<li>Collect the form field&#8217;s values into an array named queryParams, using FBJS&#8217;s getElementById and getValue functions. Although getElementById is similar to the standard Javascript function, it accounts for the random slugs Facebook injects into div id&#8217;s for security (View Source on a Facebook page and look at the div ID&#8217;s to see this in action).</li>
<li>Send the AJAX request, using FBJS&#8217; Ajax.post function. The second argument is optional, and should be an array containing the query parameters.</li>
<li>&#8220;return false;&#8221; prevents the form&#8217;s normal submit behavior</li>
</ol>
<p>That&#8217;s all there is to it! If you have any questions or if I should clarify a section, let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Free Webservice to Geocode IP Addresses Saves The Day</title>
		<link>http://illuminatikarate.com/blog/free-webservice-to-geocode-ip-addresses-saves-the-day/</link>
		<comments>http://illuminatikarate.com/blog/free-webservice-to-geocode-ip-addresses-saves-the-day/#comments</comments>
		<pubDate>Sat, 23 May 2009 06:03:06 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Webservices]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=265</guid>
		<description><![CDATA[At Illuminati Karate we love a challenge. So when our client called needing two lists of 1500 IP addresses geocoded as quickly as possible, we rose to the occasion. With the help of PHP and a freely available web service we were able to complete the task in just [...]]]></description>
			<content:encoded><![CDATA[<p>At Illuminati Karate we love a challenge. So when our client called needing two lists of 1500 IP addresses geocoded as quickly as possible, we rose to the occasion. With the help of PHP and a freely available web service we were able to complete the task in just under an hour. Here&#8217;s how we did it.</p>
<p><span id="more-265"></span><br />
<h4>The Challenge</h4>
<p>Given 2 text files, each containing approximately 1500 anonymous IP addresses, we were to determine how many resolved to each US state. Separate counts were to be maintained for each list. The data was needed for a time sensitive report, and the clock was ticking.</p>
<h4>The Tools</h4>
<p>There are several freely available SQL databases which correlate IP addresses to their geographic location, such as <a href="http://www.iplocationtools.com/sql_database.php">this one</a> maintained by iplocationtools.com. If we&#8217;d been building a web app setting up a local instance would have made sense, but at 4.1 million rows it was going to take too long to get a local instance running.</p>
<p>What we needed was a web service to do the lookups for us. In the past, we&#8217;d been unable to find a free web service to fulfill this role, as most will not provide data beyond a country level. But today we were lucky, and Google quickly turned up the perfect solution: a free REST web service running the very same database from <a href="http://www.iplocationtools.com">iplocationtools.com</a>. Its exactly what it says on the tin: <a href="http://freegeoip.appspot.com/">a free IP geolocation webservice</a>. It gave us even more accuracy than we needed (cities and zipcodes!), and even better it was running on <a href="http://www.appspot.com" rel="nofollow">Google&#8217;s App Engine</a>, so we knew it could handle a heavy load.</p>
<p>With the primary problem solved, the only thing needed was a simple PHP script to read in the input files, query the web service for each IP, parse the JSON results, and maintain a total for each state.</p>
<h4>The Solution</h4>
<p>Thanks to PHP5&#8242;s excellent JSON support, the script to interact with the web service was trivial. I won&#8217;t bore you with the file I/O and tallying, but here&#8217;s the function which converts the IP address to its state.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p265code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p26530"><td class="code" id="p265code30"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000000; font-weight: bold;">function</span> getStateFromIp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$resp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/json_decode"><span style="color: #990000;">json_decode</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://freegeoip.appspot.com/json/'</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$resp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// lookup failed</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$resp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">regioncode</span><span style="color: #339933;">;</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>Take note of the the <a href="http://php.net/json_decode">json_decode</a> function. If you&#8217;re not already familiar with it I&#8217;d highly recommend taking a few minutes to familiarize yourself with <a href="http://php.net/manual/en/ref.json.php">PHP5&#8242;s JSON functions</a>. JSON is becoming a de facto standard for web services, so being able to painlessly convert to and from JSON in PHP is critical.</p>
<p>Finally, we simply used <a href="http://php.net/manual/en/function.print-r.php">print_r</a> to dump the array containing the per state totals, and used <a href="http://www.datawatch.com/_products/monarch_pro.php">Monarch</a> to pull the data into an Excel file which we then delivered to the customer. (<em>Note: under normal circumstances we would have reached a more elegant solution, but given the time constraints brute force was the name of the game.</em>)</p>
<h4>Conclusion</h4>
<p><a href="http://illuminatikarate.com/web-services/">On-demand web services</a> are fundamentally changing the way we interact with data. Projects which were formerly large, slow, and expensive can now be completed in a matter of hours or days for a fraction of the cost. Perhaps most importantly, anyone can get involved.</p>
<p>Its an exciting time, and we&#8217;re happy to be a part of it all. Thanks for reading!</p>
<p class="note"><em>If your company needs help with a custom dataset <a href="http://illuminatikarate.com/contact-us/" rel="nofollow">contact us</a> today. Even if you&#8217;re not sure exactly what to ask for, we can help fill in the blanks.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/free-webservice-to-geocode-ip-addresses-saves-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Javascript Tricks for Better Forms</title>
		<link>http://illuminatikarate.com/blog/10-javascript-tricks-for-better-forms/</link>
		<comments>http://illuminatikarate.com/blog/10-javascript-tricks-for-better-forms/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 17:53:56 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[combo box]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[progress bars]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=4</guid>
		<description><![CDATA[Nothing exposes the gap between web apps and desktop applications more than plain HTML forms. Fortunately, by leveraging Javascript we can start to close this gap while maintaining a consistent experience for users using screen readers and old browsers. We&#8217;ve identified 10 ways in which normal HTML forms fall [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing exposes the gap between web apps and desktop applications more than plain HTML forms. Fortunately, by leveraging Javascript we can start to close this gap while maintaining a consistent experience for users using screen readers and old browsers.</p>
<p>We&#8217;ve identified 10 ways in which normal HTML forms fall short, and dug up the Javascript and CSS code you&#8217;ll need to fix them. Although the best enhancements are so intuitive as to be unnoticed, rest assured your visitors would thank you if they knew.</p>
<p class="note"><em>Note: Many of the solutions in this list depend on <a href="http://jquery.com">jQuery</a>, our javascript framework of choice.</em></p>
<p><span id="more-369"></span></p>
<h4>Combo Boxes</h4>
<p>For those unfamiliar, a Combo Box is a combination of a text box and a list box. It allows the user the option of selecting from a list of predefined items, or entering a new item of their choice. Your browser&#8217;s address bar is a perfect example.</p>
<p>Its an elegant solution to a common problem, yet the combo box was somehow left out of HTML&#8217;s form elements.</p>
<p>Enter <strong><a href="http://code.google.com/p/sexy-combo/">Sexy Combo</a></strong>, a jQuery plugin which provides a seamless solution. Users without javascript will simply encounter a normal select element.</p>
<h4>Progress Bars For Uploads</h4>
<p>The standard file input frustrates users with its awkwardness and lack of information. Furthermore, not being able to upload asynchronously results in a lot of wasted time.</p>
<p>To be fair, providing information on an ongoing upload is trickier than it might sound. Thankfully, <strong><a href="http://swfupload.org">SWFUpload</a></strong> provides a very clean solution that will convert your standard file inputs into a very flexible and asynchronous file uploader complete with a progress bar.</p>
<p class="note"><em>Note: As the name implies, SWFUpload uses an invisible Flash movie to actually perform the upload. As such, your users will need Flash as well as javascript enabled to take advantage.</em></p>
<h4>Date Selection</h4>
<p>Using a standard text input for a date leads to all manner of formatting issues, and using 3 select boxes is cumbersome. Desktop apps have a great solution &#8211; the date picker, which is to say a pop-up calendar.</p>
<p><a href="http://ui.jquery.com/demos/datepicker"><strong>jQuery UI&#8217;s Datepicker plugin</strong></a> is a perfect solution.</p>
<p class="note"><em>Note: The download page is for the entire jQuery UI library, but will allow you to download only what you want. I&#8217;d recommend only downloading the Datepicker with Packed compression, as the library is quite large.</em></p>
<h4>Time Selection</h4>
<p>Time selection in a normal HTML form has the same problems as date selection, but it lacks a uniform solution. We&#8217;ve provided 2 implementations, so that you can decide which is more appropriate for your audience.</p>
<p><strong><a href="http://keith-wood.name/timeEntry.html">Time Entry</a></strong> is a jQuery plugin that is simple and very customizable. Its normal behavior is to provide a text box where the user can use the arrow keys to quickly set the hour, minute, and am/pm settings. Its similar to how you set the time in Windows, so it should be intuitive for most visitors.</p>
<p><a href="http://www.oakcitygraphics.com/jquery/clockpick/trunk/ClockPick.cfm"><strong>ClockPick</strong></a> is a more creative, but less traditional solution. If you&#8217;re generally comfortable with creative inputs, its a fantastic interface.</p>
<h4>Color Selection</h4>
<p>Color selection might not apply to every app, but when you need it the native options leave you out in the cold. There&#8217;s only a handful of visitors who would know what a hex code is, and even fewer who have their favorites memorized.</p>
<p><a href="http://www.eyecon.ro/colorpicker/"><strong>ColorPicker</strong></a> is a very nice solution, which provides a color picker similar to that in Adobe Photoshop.</p>
<h4>Input Masking / Validation</h4>
<p>Input masking is when a text box has static characters already included, and the cursor moves intelligently. For example, a text box for a social security number should already have the dashes, and after you enter the first three numbers the cursor should move past the first dash. Furthermore, it shouldn&#8217;t allow anything but numbers to be entered.</p>
<p>Input validation is checking to see if the value the user entered falls within the boundaries. In our social security number example, if the number entered isn&#8217;t exactly 9 digits, its not valid.</p>
<p class="note"><em>Note: Client-side validation can be easily overridden by a malicious visitor, so you&#8217;ll need to sanitize and validate your data server-side as well.</em></p>
<p>The <strong><a href="http://digitalbush.com/projects/masked-input-plugin/">Masked Input jQuery plugin</a></strong> can implement both of these features for us. It will let you define any custom mask, and you can use its &#8220;completed&#8221; callback function to flag the inputs as valid.</p>
<h4>Better Support for Defaults</h4>
<p>HTML inputs do allow for default values, but its nice to have them disappear when the input gains focus, and reappear on blur if the user hasn&#8217;t entered anything.</p>
<p>The aptly named <strong><a href="http://plugins.jquery.com/project/defaultvalue">Default Values plugin</a></strong> does exactly that.</p>
<h4>AJAX Form Submission</h4>
<p>Submitting forms can be a great use of AJAX, particularly if you have a series of forms which are affected by the user entered values (i.e. a wizard). Its also a nice way to break a long form into stages to decrease abandonment.</p>
<p>The <strong><a href="http://malsup.com/jquery/form/">jQuery Form Plugin</a></strong> is an easy way to convert your current forms to AJAX forms while preserving their functionality for users without Javascript. If you are feeling creative or want to write something more customized, <strong><a href="http://docs.jquery.com/Ajax/serialize">jQuery&#8217;s serialize function</a></strong> will get you almost all the way there.</p>
<h4>Automatically Growing Textareas</h4>
<p>If you&#8217;ve used <a href="http://facebook.com">Facebook</a> or <a href="http://basecamphq.com">Basecamp</a>, you&#8217;ve probably noticed that the textareas get longer when you&#8217;re running out of space. Its aesthetically pleasing and very convenient.</p>
<p>Here&#8217;s a <a href="http://plugins.jquery.com/project/autogrow"><strong>jQuery plugin</strong></a> to add the same behavior to your textareas.</p>
<h4>Spin Buttons</h4>
<p>A spin button is a text box with up/down arrows, allowing the user to easily &#8220;nudge&#8221; a numeric value up or down. Like a combo box, the user can still type in their own value.</p>
<p>They are most useful when the range of possible values is fairly small &#8211; for example selecting the number of diners in a reservation.</p>
<p>The <strong><a href="http://code.google.com/p/jquery-spin-button/">jQuery Spin Button</a></strong> plugin is a nice implementation of this control.</p>
<h4>One More Thing</h4>
<p>Each of these ten solutions requires at least one external javascript library, and some require stylesheets. Implementing all ten would be great, but including a bunch of external javascript / css files can drastically increase the load time of your page.</p>
<p>Therefore, we recommend you do 2 things:</p>
<ol>
<li>Concatenate your Javascript and CSS files as much as makes sense.</li>
<li>Compress them using Dean Edward&#8217;s <a href="http://dean.edwards.name/packer/">packer</a> and <a href="http://www.cssdrive.com/index.php/main/csscompressor/">CSSDrive&#8217;s CSS Compressor</a>, respectively.</li>
</ol>
<p>Also, if you know of any scripts that we missed here let us know in the comments. Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/10-javascript-tricks-for-better-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

