<?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>Server Side Guy</title>
	<atom:link href="http://serversideguy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://serversideguy.com</link>
	<description>Just another Barsness Solutions weblog</description>
	<lastBuildDate>Tue, 23 Feb 2010 23:27:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To:  Read a CSV in PHP</title>
		<link>http://serversideguy.com/2010/02/23/how-to-read-a-csv-in-php/</link>
		<comments>http://serversideguy.com/2010/02/23/how-to-read-a-csv-in-php/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 23:27:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=236</guid>
		<description><![CDATA[Reading a CSV in PHP is much easier than I anticipated with the advent of the fgetcsv() function for PHP 4.  The function basically reads a file line by line and performs and explode on the delimiter, returning the array.  Here&#8217;s some sample code:

$length = 0;
&#160;
if &#40; &#40;$handle = @fopen&#40;$file, &#34;r&#34;&#41;&#41; !== FALSE [...]]]></description>
			<content:encoded><![CDATA[<p>Reading a CSV in PHP is much easier than I anticipated with the advent of the fgetcsv() function for PHP 4.  The function basically reads a file line by line and performs and explode on the delimiter, returning the array.  Here&#8217;s some sample code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</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: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgetcsv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #009900;">&#41;</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: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//dumps an array corresponding </span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The length parameter is option as of PHP 5.0.4.  Using a limited line length makes execution slightly faster, so if it is realistic to limit line length (even if limiting it at a great value) it could improve script execution time significantly.</p>
<p>The function also allows for setting the enclosure and escape characters.  </p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2010/02/23/how-to-read-a-csv-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Send an Email using PHPmailer and Gmail for SMTP</title>
		<link>http://serversideguy.com/2010/01/14/how-to-send-an-email-using-phpmailer-and-gmail-for-smtp/</link>
		<comments>http://serversideguy.com/2010/01/14/how-to-send-an-email-using-phpmailer-and-gmail-for-smtp/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 07:16:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com.mu.barsnesssolutions.com/?p=233</guid>
		<description><![CDATA[I needed to offer a client the ability to send Email using PHPmailer and Gmail.  The below is what I came up with, which worked flawlessly:

require&#40;&#34;PHPMailer_v5.1/class.phpmailer.php&#34;&#41;;
&#160;
$mail             = new PHPMailer&#40;&#41;;
&#160;
$body             = [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to offer a client the ability to send Email using PHPmailer and Gmail.  The below is what I came up with, which worked flawlessly:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PHPMailer_v5.1/class.phpmailer.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span>             <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$body</span>             <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Message Body&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Mailer</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;smtp&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ssl://smtp.gmail.com&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">465</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SMTPAuth</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// turn on SMTP authentication </span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;username@gmail.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// SMTP username </span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// SMTP password </span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// telling the class to use SMTP</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFrom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'from@address.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'First Last'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PHPMailer Test Subject via smtp, basic with authentication&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AltBody</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;To view the message, please use an HTML compatible email viewer!&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// optional, comment out and test</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MsgHTML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email@address.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'First Last'</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: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</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;Mailer Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ErrorInfo</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;Message sent!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The part that threw me for a loop was right here:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ssl://smtp.gmail.com&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I was using simply smtp.gmail.com.  I knew from setting up mail clients that you needed to use SSL, but it didn&#8217;t occur to me to tell PHPmailer to do the same.  When it came to me, simply looking up how to instruct PHPmailer to use SSL did the trick.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2010/01/14/how-to-send-an-email-using-phpmailer-and-gmail-for-smtp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress in_tree() function</title>
		<link>http://serversideguy.com/2010/01/11/wordpress-in_tree-function/</link>
		<comments>http://serversideguy.com/2010/01/11/wordpress-in_tree-function/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 18:27:52 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=227</guid>
		<description><![CDATA[Just created a wordpress funciton in_tree($a, $b) which checks to see if page ID $a is in the tree of page ID $b.  That is, it checks to see if $a is a child of $b or $a is $b.

/**
 * Checks to see if a $in_tree_id is in the tree of
 * $in_tree_root [...]]]></description>
			<content:encoded><![CDATA[<p>Just created a wordpress funciton in_tree($a, $b) which checks to see if page ID $a is in the tree of page ID $b.  That is, it checks to see if $a is a child of $b or $a is $b.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Checks to see if a $in_tree_id is in the tree of
 * $in_tree_root post (is a child of or is the post
 * ID provided)
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> in_tree<span style="color: #009900;">&#40;</span><span style="color: #000088;">$in_tree_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$in_tree_root</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;">$in_tree_id</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$in_tree_root</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$in_tree_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> in_tree<span style="color: #009900;">&#40;</span>get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$in_tree_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$in_tree_root</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2010/01/11/wordpress-in_tree-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using sys_get_temp_dir() in PHP &lt; 5.2.1</title>
		<link>http://serversideguy.com/2009/12/30/using-sys_get_temp_dir-in-php-5-2-1/</link>
		<comments>http://serversideguy.com/2009/12/30/using-sys_get_temp_dir-in-php-5-2-1/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 23:39:21 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPExcel]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=222</guid>
		<description><![CDATA[I wanted to use the PHPExcel package on my Debian system running 5.2.0, however PHPExcel 1.7.1 requires the sys_get_temp_dir() function which doesn&#8217;t exist prior to PHP 5.2.1.  Of course aside from updating PHP, we would need to replicate the functionality of sys_get_temp_dir().  This gem in the php.net comments on the function provides a workaround.

if &#40; [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to use the PHPExcel package on my Debian system running 5.2.0, however PHPExcel 1.7.1 requires the sys_get_temp_dir() function which doesn&#8217;t exist prior to PHP 5.2.1.  Of course aside from updating PHP, we would need to replicate the functionality of sys_get_temp_dir().  This gem in the php.net comments on the function provides a workaround.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sys_get_temp_dir'</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;">function</span> <span style="color: #990000;">sys_get_temp_dir</span><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: #000088;">$temp</span><span style="color: #339933;">=</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TMP'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">=</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TEMP'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">=</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TMPDIR'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$temp</span><span style="color: #339933;">=</span><span style="color: #990000;">tempnam</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</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: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/30/using-sys_get_temp_dir-in-php-5-2-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Hide a Wordpress Sidebar From Pages</title>
		<link>http://serversideguy.com/2009/12/22/how-to-hide-a-wordpress-sidebar-from-pages/</link>
		<comments>http://serversideguy.com/2009/12/22/how-to-hide-a-wordpress-sidebar-from-pages/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:30:25 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=216</guid>
		<description><![CDATA[In combination with my previous post on adding multiple sidebars to a Wordpress theme, I had the need to display one of them only when looking at the blog part of wordpress.  This is pretty straightforward, but basically we just need to check if we are not on a page and display the sidebar.

//If [...]]]></description>
			<content:encoded><![CDATA[<p>In combination with my previous post on <a href="http://serversideguy.com/2009/12/21/how-to-add-a-sidebar-to-a-wordpress-theme/">adding multiple sidebars</a> to a Wordpress theme, I had the need to display one of them only when looking at the blog part of wordpress.  This is pretty straightforward, but basically we just need to check if we are not on a page and display the sidebar.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//If we are viewing posts, not a page, print the posts sidebar</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_page<span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Posts Sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
	<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/22/how-to-hide-a-wordpress-sidebar-from-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Add a Sidebar to a Wordpress Theme</title>
		<link>http://serversideguy.com/2009/12/21/how-to-add-a-sidebar-to-a-wordpress-theme/</link>
		<comments>http://serversideguy.com/2009/12/21/how-to-add-a-sidebar-to-a-wordpress-theme/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 12:21:58 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=212</guid>
		<description><![CDATA[I recently needed a little more control over the sidebar on a theme and had never added a sidebar to a theme before. I wanted certain widgets to show up only on posts and the rest to show up on posts and pages.  The below is how to add the sidebar:
In the functions.php page, we [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed a little more control over the sidebar on a theme and had never added a sidebar to a theme before. I wanted certain widgets to show up only on posts and the rest to show up on posts and pages.  The below is how to add the sidebar:</p>
<p>In the functions.php page, we need to modify the code which looks like this:</p>

<div class="wp_syntax"><div 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;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To make it look like this:</p>

<div class="wp_syntax"><div 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;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	register_sidebar<span style="color: #009900;">&#40;</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;">'Top Sidebar'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	register_sidebar<span style="color: #009900;">&#40;</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;">'Posts Sidebar'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	register_sidebar<span style="color: #009900;">&#40;</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;">'Bottom Sidebar'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, when calling a sidebar, we just need to call it by name as in the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Top Sidebar</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Top Sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Posts Sidebar</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Posts Sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Bottom Sidebar</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Bottom Sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span></pre></div></div>

<p>Obviously we have freedom to name our sidebars as we please.  Look for more info on making a sidebar only show up on posts in an upcoming post.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/21/how-to-add-a-sidebar-to-a-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To pass an Array in the Querystring Using PHP</title>
		<link>http://serversideguy.com/2009/12/18/how-to-pass-an-array-in-the-querystring-using-php/</link>
		<comments>http://serversideguy.com/2009/12/18/how-to-pass-an-array-in-the-querystring-using-php/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 00:07:09 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Querystring]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=209</guid>
		<description><![CDATA[I recently ran across a silly Wordpress situation where I needed to pass an array in the querystring.  Here&#8217;s what I came up with:

$array = array&#40;'a' =&#62; 1, 'b' =&#62; 2, 'c' =&#62; 3&#41;;
$array = rawurlencode&#40;serialize&#40;$array&#41;&#41;;
echo '&#60;a href=&#34;./getarray.php?a=' . $array . '&#34;&#62;Pass array&#60;/a&#62;';

Then on the receiving getarray.php:

$array = unserialize&#40;stripslashes&#40;$_GET&#91;'error_array'&#93;&#41;&#41;;

]]></description>
			<content:encoded><![CDATA[<p>I recently ran across a silly Wordpress situation where I needed to pass an array in the querystring.  Here&#8217;s what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;./getarray.php?a='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$array</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;Pass array&lt;/a&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then on the receiving getarray.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/18/how-to-pass-an-array-in-the-querystring-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Custom Author Page (author-x.php)</title>
		<link>http://serversideguy.com/2009/12/18/wordpress-custom-author-page-author-x-php/</link>
		<comments>http://serversideguy.com/2009/12/18/wordpress-custom-author-page-author-x-php/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 13:12:11 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=204</guid>
		<description><![CDATA[It was recently asked in a newsgroup how to make the Wordpress author function like the wordpress category page.  The format of the category page is category-x.php.  Replace the x with the category ID you would like a custom page for (e.g. category-14.php) and when browsing category x the custom page category-x.php is [...]]]></description>
			<content:encoded><![CDATA[<p>It was recently asked in a newsgroup how to make the Wordpress author function like the wordpress category page.  The format of the category page is category-x.php.  Replace the x with the category ID you would like a custom page for (e.g. category-14.php) and when browsing category x the custom page category-x.php is processed instead of category.php.</p>
<p>In my research, I didn&#8217;t see a previously implemented way to do this with author.php, so I came up with these modifications to the author.php page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$curauth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_queried_object</span><span style="color: #009900;">&#40;</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;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$curauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$curauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.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: #666666; font-style: italic;">//Default author page</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The idea here is to have author.php check to see if author-x.php exists.  If it does, include that file.  If not, process the default author.php in the else condition.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/18/wordpress-custom-author-page-author-x-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Get Google Voice Call Length in PHP (Google Voice API)</title>
		<link>http://serversideguy.com/2009/12/08/how-to-get-google-voice-call-length-in-php-google-voice-api/</link>
		<comments>http://serversideguy.com/2009/12/08/how-to-get-google-voice-call-length-in-php-google-voice-api/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 13:33:03 +0000</pubDate>
		<dc:creator>tim barsness</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=196</guid>
		<description><![CDATA[I am interested in building a google voice / highrise mashup that tags people by how long overall I&#8217;ve talked to them.  I ran across this bit of PHP code by Aaronpk that attempts to use the main voice functionality as an API.  And it works really well.
The below is adapted from that [...]]]></description>
			<content:encoded><![CDATA[<p>I am interested in building a google voice / highrise mashup that tags people by how long overall I&#8217;ve talked to them.  I ran across <a href="http://github.com/aaronpk/Google-Voice-PHP-API" target="_blank">this bit of PHP code by Aaronpk</a> that attempts to use the main voice functionality as an API.  And it works really well.</p>
<p>The below is adapted from that code to get all calls and get the duration of the calls.  Of course, duration is approximate, but that&#8217;s as good as it is going to get for me.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$cookieFile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/tmp/gvCookies.txt'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #000088;">$cookieFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><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: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// fetch the login page</span>
<span style="color: #990000;">curl_setopt</span><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: #0000ff;">'https://www.google.com/accounts/ServiceLogin?passive=true&amp;service=grandcentral'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><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;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/name=&quot;GALX&quot;\s*value=&quot;([^&quot;]+)&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$GALX</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>
	throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not parse for GALX token'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><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: #0000ff;">'https://www.google.com/accounts/ServiceLoginAuth?service=grandcentral'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'Email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'Passwd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'continue'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'https://www.google.com/voice/account/signin'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'service'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'grandcentral'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'GALX'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$GALX</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Process login</span>
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</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: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/name=&quot;_rnr_se&quot;.*?value=&quot;(.*?)&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$rnr_se</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</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;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not log in to Google Voice with username: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$login</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get results for all recent calls, paginated of course</span>
<span style="color: #990000;">curl_setopt</span><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: #0000ff;">'https://www.google.com/voice/inbox/recent/all/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<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>
<span style="color: #990000;">curl_setopt</span><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: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><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: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// load the &quot;wrapper&quot; xml (contains two elements, json and html)</span>
<span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">documentElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// now make a dom parser which can parse the contents of the HTML tag</span>
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">documentElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// replace all &quot;&amp;&quot; with &quot;&amp;&quot; so it can be parsed</span>
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadHTML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xpath</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMXPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dom</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$calls</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: #666666; font-style: italic;">// Call duration isn't included, so foreach $json-&gt;messages, getting gc-message-call-details for each element</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$mid</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$convo</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//find this conversation by message id</span>
	<span style="color: #000088;">$elements</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;//div[@id='<span style="color: #006699; font-weight: bold;">$mid</span>']&quot;</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: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$elements</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$element</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$elements</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//find the gc-message-call-details contents</span>
		<span style="color: #000088;">$XMsg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xpath</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;//span[@class='gc-message-call-details']&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$element</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//add details to the convo</span>
		<span style="color: #000088;">$convo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">details</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$XMsg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//add $convo to results</span>
	<span style="color: #000088;">$calls</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$convo</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$calls</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$mid</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$convo</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Call <span style="color: #006699; font-weight: bold;">$mid</span> lasted <span style="color: #006699; font-weight: bold;">$convo-&gt;details</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/08/how-to-get-google-voice-call-length-in-php-google-voice-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>$_Get Getter 1.1</title>
		<link>http://serversideguy.com/2009/12/07/_get-getter-1-1/</link>
		<comments>http://serversideguy.com/2009/12/07/_get-getter-1-1/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 19:57:08 +0000</pubDate>
		<dc:creator>andy stramer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://serversideguy.com/?p=202</guid>
		<description><![CDATA[Thanks to the help of Daniel Watrous, an improved version of our $_Get Getter Wordpress plugin is now available. It is now able to pull multiple variables from the query string.
You can get the new version here.
]]></description>
			<content:encoded><![CDATA[<p>Thanks to the help of Daniel Watrous, an improved version of our $_Get Getter Wordpress plugin is now available. It is now able to pull multiple variables from the query string.</p>
<p>You can get the new version <a href="http://serversideguy.com/wordpress/plugins/_get-getter/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://serversideguy.com/2009/12/07/_get-getter-1-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
