<?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>Nate&#039;s blog &#187; Php</title>
	<atom:link href="http://www.natenewz.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.natenewz.com</link>
	<description>My various projects</description>
	<lastBuildDate>Tue, 29 Jun 2010 18:00:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sorting Version Numbers in PHP</title>
		<link>http://www.natenewz.com/2010/06/29/sorting-version-numbers-in-php/</link>
		<comments>http://www.natenewz.com/2010/06/29/sorting-version-numbers-in-php/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 17:51:50 +0000</pubDate>
		<dc:creator>nate</dc:creator>
				<category><![CDATA[None]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[numbers]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://www.natenewz.com/?p=371</guid>
		<description><![CDATA[What&#8217;s the problem? Say you have a version number such as 1.2.3 stored in a MySql database as a varchar, and you want to sort this version number. Without any decimals, here is the sorting descending:
+&#8212;&#8212;&#8212;+
&#124; version &#124;
+&#8212;&#8212;&#8212;+
&#124; 9960    &#124;
&#124; 9952    &#124;
&#124; 9765    &#124;
&#124; 9764  [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s the problem? Say you have a version number such as 1.2.3 stored in a MySql database as a varchar, and you want to sort this version number. Without any decimals, here is the sorting descending:<br />
+&#8212;&#8212;&#8212;+<br />
| version |<br />
+&#8212;&#8212;&#8212;+<br />
| 9960    |<br />
| 9952    |<br />
| 9765    |<br />
| 9764    |<br />
| 10011   |<br />
+&#8212;&#8212;&#8212;+<br />
5 rows in set (0.00 sec)<br />
It thinks 9960 &gt; 10011<br />
If you don&#8217;t have a decimal point this can be easily remedied by doing:<br />
ORDER BY CAST(version AS UNSIGNED) DESC<br />
But as soon as you put a decimal into the version, it ignores everything to the right of the decimal point.<br />
My solution is a PHP sorting algorithm.<br />
$versions is an indexed array that has this format, which could easily come from a database<br />
array<br/>&nbsp;&nbsp;0&nbsp;=&gt;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;array<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8217;id&#8217;&nbsp;=&gt;&nbsp;int&nbsp;88<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8217;version&#8217;&nbsp;=&gt;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;=&gt;&nbsp;int&nbsp;0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;=&gt;&nbsp;int&nbsp;9<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;=&gt;&nbsp;int&nbsp;10011<br/>&nbsp;&nbsp;1&nbsp;=&gt;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;array<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8217;id&#8217;&nbsp;=&gt;&nbsp;int&nbsp;87<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8217;version&#8217;&nbsp;=&gt;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;=&gt;&nbsp;int&nbsp;0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;=&gt;&nbsp;int&nbsp;9<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;=&gt;&nbsp;int&nbsp;9960</p>
<pre  id='PHP' class="prettyprint" >
// convert all values to ints
array_walk_recursive($versions, function(&amp;$val, $i)
{
    if (is_string($val))
        $val = (int)$val;
});
// make to arrays the same length by padding them with 0s
function normalize($a, $b)
{
    $al = count($a);
    $bl = count($b);
    if ($al &lt; $bl)
    {
        // add 0s to $a until they are the same size
        while (count($a) &lt; $bl)
            $a[] = 0;
    }
    elseif ($al &gt; $bl)
    {
        // add 0s to $b until they are the same size
        while ($al &gt; count($b))
            $b[] = 0;
    }
    return array($a, $b);
}
//compare to integers and decide which one is bigger
// return 0 if they are equal
function check($a, $b)
{
    if ($a &lt; $b)
        return 1;
    elseif ($a &gt; $b)
        return -1;
    else
        return 0;
}
// sort the array
usort($versions, function($a, $b)
{
    // make sure the major_version arrays have the same length, pad with 0s to correct
    list($a['version'], $b['version']) = normalize($a['version'], $b['version']);
    for ($i=0; $i &lt; count($a['version']); $i++)
        $check = check($a['version'][$i], $b['version'][$i]);
    return $check;
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.natenewz.com/2010/06/29/sorting-version-numbers-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Zenphoto and Wordpress</title>
		<link>http://www.natenewz.com/2009/10/13/integrating-zenphoto-and-wordpress/</link>
		<comments>http://www.natenewz.com/2009/10/13/integrating-zenphoto-and-wordpress/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 05:28:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[None]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[seamless]]></category>
		<category><![CDATA[zenphoto]]></category>

		<guid isPermaLink="false">http://www.natenewz.com/blog/?p=93</guid>
		<description><![CDATA[
Update: I am now using google picasa with the kpicasa plugin. I&#39;ve determined that this is the best method of putting a complete gallery onto a post or page. This completely eliminates zenphoto. If you are committed to using zenphoto, and you have your theme set up exactly the way you want it, then this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.zenphoto.org/"><img alt="Zenphoto" class="size-medium wp-image-96" height="117" src="http://www.natenewz.com/wp-content/uploads/2009/10/zenphoto-300x108.jpg" title="zenphoto" width="329" /></a><a href="http://www.wordpress.org/"><img alt="wordpress" class="size-full wp-image-97" height="117" src="http://www.natenewz.com/wp-content/uploads/2009/10/wordpress-icon-512-300x300.png" title="wordpress-icon-512-300x300" width="117" /></a></p>
<p>Update: I am now using google picasa with the kpicasa plugin. I&#39;ve determined that this is the best method of putting a complete gallery onto a post or page. This completely eliminates zenphoto. If you are committed to using zenphoto, and you have your theme set up exactly the way you want it, then this method will work, but over time if you ever make a change to your wordpress theme, you have to update your look-alike zenphoto theme. Common plugins for zenphoto wordpress integration allow you to put individual albums or photos into posts.<br style="clear: both;" /><br />
	After reading <a href="http://wpengineer.com/embed-wordpress-functions-outside-wordpress/trackback/" target="_blank" title="Calling wordpress functions outside of wordpress">Frank&#39;s post on using wordpress functions outside of wordpress</a>, I had a good idea: Make a zenphoto theme with the wordpress navigation. This allows a nearly seamless level of integration between zenphoto and wordpress. The best starting point for this outline is if you already have a nice looking wordpress theme. The result of this will give you a wordpress &quot;page&quot; that redirects to a lookalike wordpress zenphoto theme complete with wordpress navigation, footer, page title, header, etc. First, you need a way of getting the paths of the blog directory, and the zenphoto directory. I have a www/blog/ folder and a www/gallery/ folder in this example. Place config.php in www/ config.php</p>
<pre class="prettyprint">< ?php
/* config file to unite wordpress and zenphoto */
define('BLOG_PATH', "$_SERVER['DOCUMENT_ROOT']/blog");
// do a var_dump($_SERVER); to find out what something is
define('GALLERY_PATH', "$_SERVER['DOCUMENT_ROOT']/gallery');
?></pre>
<p>You may have to var_dump($_SERVER) to find out the best way of getting to your site&#39;s directory. Okay, we have paths to reference from zenphoto to get to the wordpress directory. Let&#39;s dig into a zenphoto theme. Zenphoto themes are laid out with various files that are called depending on if you are at the zenphoto homepage (index.php), or if you have clicked on an album (album.php), or an image (image.php) and a few others. Your best bet is to copy the &#39;default&#39; zenphoto theme to a folder with a different name, such as nate-theme, then modify it. Let&#39;s look at index.php The first step is to follow Franks post and include the wordpress loader wp-load.php. Put at the very top of your zp-themes index.php file:</p>
<pre class="prettyprint" id="PHP">&lt; ?php
require_once(&quot;{$_SERVER[&#39;something&#39;]}/www/config.php&quot;);
require_once(BLOG_PATH.&quot;/wp-load.php&quot;);
// var_dump(get_current_theme()); // call this to see the name of the wordpress theme activated
if (get_current_theme() == &quot;My Wordpress Theme&quot;) // if the current theme is my wp theme, use it. otherwise use default zenphoto theme
{?&gt;
// wordpress html+php here
&lt; ?php
}else{
?&gt;
// original zenphoto default index.php file here
&lt;?php
}
?&gt;</pre>
<p>This is in case the wordpress theme get&#39;s changed to something else, zenphoto will revert back to the original html/php &#8212; whatever is in the else statement. So then, just copy the basic html structure from the header.php footer.php index.php files from your wordpress theme. You can now call the functions for listing the navigation, <a href="http://codex.wordpress.org/wp_list_pages">wp_list_pages()</a>, getting options <a href="http://codex.wordpress.org/Function_Reference/get_option">get_option()</a>, getting blog title and other information <a href="http://codex.wordpress.org/Template_Tags/bloginfo">bloginfo()</a>, etc. One requirement for this to work, is that the zenphoto and wordpress functions don&#39;t interfere. Luckily, no two functions have the same name, and so this does work. I haven&#39;t tested recreating the sidebar widgets in the zenphoto theme, although it should theoretically work. As for the zenphoto style sheet, I played a trick on apache to make this work. I told apache to parse .css files in the styles/ directory of zenphoto theme as a php file. Just make a .htaccess file in the styles directory, and add this line to it: AddType application/x-httpd-php .css This will allow you to apply the same technique as the index.php page with the if get_current_theme==xx else block. Just use the normal css in the else, and the wordpress css in the if parts. The last step to making this a nearly seamless integration is following my previous post on hardlinking the navigation. create the custom field redirect to the key /gallery/ or the url path to your gallery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.natenewz.com/2009/10/13/integrating-zenphoto-and-wordpress/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
