<?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>jek2kdotcom &#187; PHP</title>
	<atom:link href="http://www.jek2k.com/wp/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jek2k.com/wp</link>
	<description>still awake at night?</description>
	<lastBuildDate>Tue, 12 Jan 2010 14:52:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pretty Permalinks on IIS</title>
		<link>http://www.jek2k.com/wp/2009/09/21/pretty-permalinks-on-iis/</link>
		<comments>http://www.jek2k.com/wp/2009/09/21/pretty-permalinks-on-iis/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 17:57:20 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/?p=314</guid>
		<description><![CDATA[Today I needed to optimise a WordPress-driven website for SEO reasons. First thing to do was to enable pretty permalinks, but the website was hosted on a Windows server using IIS 6.0. The best I could obtain out-of-the-box is a permalink structure like this one:
http://www.my-domain.com/index.php/2009/09/21/my-pretty-permalink/
This is better than appending post IDs in  the querystring, but [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed to optimise a WordPress-driven website for SEO reasons. First thing to do was to enable pretty permalinks, but the website was hosted on a Windows server using IIS 6.0. The best I could obtain out-of-the-box is a permalink structure like this one:<em><br />
http://www.my-domain.com/index.php/2009/09/21/my-pretty-permalink/</em></p>
<p>This is better than appending post IDs in  the querystring, but is still far from perfect, as it includes the &#8216;index.php&#8217; string in the URL.</p>
<p>I googled around for possible solutions and workarounds and found <a href="http://www.ikailo.com/94/url-modrewrite-workaround-iis-60/" target="_blank">this useful article</a>. This worked pretty good, but unfortunately didn&#8217;t cater to existing permalinks. In other words, using permalinks like the one above resulted in 404 errors.</p>
<p>I modified the PHP code slightly to add support for existing permalinks (with &#8216;index.php&#8217; in them), so the blog can use pretty permalinks, but old posts linked elsewhere with ugly permalinks work too.</p>
<p><span id="more-314"></span></p>
<p><strong>Source code:</strong></p>
<pre class="brush: php;">
&lt;?php
// This is the default file for the site. Usually index.php
$default = 'index.php';

// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager &gt; Websites &gt; [Site Name] &gt; Properties &gt; Custom Errors &gt;
// 404 &amp; 404;2 &amp; 404;3 &gt; URL (Requires a '/' prefix in IIS).
$thisfile = '404-handler.php';

$_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
$_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;

$qs =&amp; $_SERVER['QUERY_STRING'];
$ru =&amp; $_SERVER['REQUEST_URI'];

// Fix for existing permalinks  (eg. http://www.my-domain.com/index.php/2009/09/21/my-pretty-permalink/)
if(strpos($ru,'/'.$default.'/',0)) $ru = str_replace('/'.$default.'/','',$_SERVER['REQUEST_URI']);

$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['URL'] = $ru = substr($qs, $pos);
$qs = trim(stristr($ru, '?'), '?');

// Required for Wordpress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;

// Fix GET vars
foreach ( $_GET as $var =&gt; $val ) {
 if ( substr($var, 0, 3) == '404') {
 if ( strstr($var, &quot;?&quot;) ) {
 $newvar = substr($var, strpos($var, '?') + 1);
 $_GET[$newvar] = $val;
 }
 unset($_GET[$var]);
 }
 break;
}
include($default);
?&gt;
</pre>
<p>While I know this is just a workaround, this seems to have solved my problem and works pretty good so far.<br />
If anyone knows of better solutions, comments are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2009/09/21/pretty-permalinks-on-iis/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A simple RSS Reader with PHP</title>
		<link>http://www.jek2k.com/wp/2009/05/31/a-simple-rss-reader-with-php/</link>
		<comments>http://www.jek2k.com/wp/2009/05/31/a-simple-rss-reader-with-php/#comments</comments>
		<pubDate>Sun, 31 May 2009 16:43:38 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/?p=269</guid>
		<description><![CDATA[In the last couple of days, I had the need of creating a simple RSS widget for a project, aggregating several RSS feeds from different sources. As this might be a pretty common request and you might need this in your projects, I&#8217;m sharing my script below.
The whole thing is based on the MagpieRSS PHP [...]]]></description>
			<content:encoded><![CDATA[<p>In the last couple of days, I had the need of creating a simple RSS widget for a project, aggregating several RSS feeds from different sources. As this might be a pretty common request and you might need this in your projects, I&#8217;m sharing my script below.<br />
The whole thing is based on the <a href="http://magpierss.sourceforge.net/">MagpieRSS</a> PHP parser.</p>
<p><strong>1. The simple version</strong></p>
<p>This first version simply reads the RSS feeds from different websites and lists the latest posts for each website.<br />
Feed URIs are defined in an array, so you can easily add as many as you want.<br />
Number of posts per website is also easily editable.</p>
<p>This has support for languages different from English, using UTF-8 encoding, and uses <strong>relative dates</strong>.</p>
<p>You can see <a href="http://playground.gnvpartners.net/ex/rss/rss.php">a working example here</a>.<span id="more-269"></span></p>
<p><strong>Source code:</strong></p>
<pre class="brush: php;">

&lt;?php

/* feed URIs */
$urls = array('http://webdesignerwall.com/feed/', 'http://gigaom.com/feed/', 'http://techcrunch.com/feed/', 'http://wordpress.org/development/feed/');

/* number of items for each feed */
$num_items = 5;

@require_once('rss_fetch.inc');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
$posts = array();

foreach($urls as $url) {
$rss = fetch_rss($url);

if($rss) {
$items = array_slice($rss-&gt;items, 0, $num_items);
foreach($items as $item) {
$posts[] = array('title' =&gt; $item['title'], 'link' =&gt; $item['link'], 'date' =&gt; $item['pubdate'], 'source' =&gt; $rss-&gt;channel['title']);
}
}
else {
echo &quot;An error occured!&lt;br /&gt;Error Message: &quot;.magpie_error();
}
}
usort($posts, 'sortdates');
echo &quot;&lt;ul&gt;&quot;;
foreach($posts as $post) {
$title = $post['title'];
$url = $post['link'];
$date = $post['date'];
$source = $post['source'];
echo &quot;&lt;li&gt;&lt;a href='&quot;.$url.&quot;'&gt;&quot;.$title.&quot;&lt;/a&gt; from &lt;strong&gt;&quot;.$source.&quot;&lt;/strong&gt;, &quot;.getrelativetime($date).&quot;&lt;/li&gt;&quot;;
}
echo &quot;&lt;/ul&gt;&quot;;

function sortdates($a, $b) {
if(strtotime($a['date']) &gt; strtotime($b['date'])) {
return -1;
} elseif( strtotime($a['date']) == strtotime($b['date'])) {
return 0;
} elseif( strtotime($a['date']) &lt; strtotime($b['date'])) {
return 1;
}
}

function getrelativetime($date) {
// Credit: http://snipplr.com/view/4912/relative-time/ and http://twitter.pbwiki.com/RelativeTimeScripts
$gap = time() - strtotime($date);
if ($gap&lt;5) {
return 'less than 5 seconds ago';
} else if ($gap&lt;10) {
return 'less than 10 seconds ago';
} else if ($gap&lt;20) {
return 'less than 20 seconds ago';
} else if ($gap&lt;40) {
return 'half a minute ago';
} else if ($gap&lt;60) {
return 'less than a minute ago';
}
$gap = round($gap/60);
if ($gap &lt; 60)
return $gap.' minute'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/60);
if ($gap &lt; 24)
return $gap.' hour'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/24);
if ($gap&lt;7)
return $gap.' day'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/7);
if ($gap&lt;4)
return $gap.' week'.($gap &gt; 1 ? 's' : '').' ago';

return date(&quot;F jS, Y @h:i&quot;, strtotime($date));
}
?&gt;
</pre>
<p><strong>2. The more complex version</strong></p>
<p>Same thing as above, but this version output a list af the most recent posts &#8211; source websites are displayed next to titles. This is definitely more useful if you mean to display recent content from mixed sources.</p>
<p>You can see <a href="http://playground.gnvpartners.net/ex/rss/rss.mixed.php">a working example here</a>.</p>
<p><strong>Source code:</strong></p>
<pre class="brush: php;">

&lt;?php

/* feed URIs */
$urls = array('http://webdesignerwall.com/feed/', 'http://gigaom.com/feed/', 'http://techcrunch.com/feed/', 'http://wordpress.org/development/feed/');

/* number of items for each feed */
$num_items = 5;

@require_once('rss_fetch.inc');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
$posts = array();

foreach($urls as $url) {
$rss = fetch_rss($url);

if($rss) {
$items = array_slice($rss-&gt;items, 0, $num_items);
foreach($items as $item) {
$posts[] = array('title' =&gt; $item['title'], 'link' =&gt; $item['link'], 'date' =&gt; $item['pubdate'], 'source' =&gt; $rss-&gt;channel['title']);
}
}
else {
echo &quot;An error occured!&lt;br /&gt;Error Message: &quot;.magpie_error();
}
}
usort($posts, 'sortdates');
echo &quot;&lt;ul&gt;&quot;;
foreach($posts as $post) {
$title = $post['title'];
$url = $post['link'];
$date = $post['date'];
$source = $post['source'];
echo &quot;&lt;li&gt;&lt;a href='&quot;.$url.&quot;'&gt;&quot;.$title.&quot;&lt;/a&gt; from &lt;strong&gt;&quot;.$source.&quot;&lt;/strong&gt;, &quot;.getrelativetime($date).&quot;&lt;/li&gt;&quot;;
}
echo &quot;&lt;/ul&gt;&quot;;

function sortdates($a, $b) {
if(strtotime($a['date']) &gt; strtotime($b['date'])) {
return -1;
} elseif( strtotime($a['date']) == strtotime($b['date'])) {
return 0;
} elseif( strtotime($a['date']) &lt; strtotime($b['date'])) {
return 1;
}
}

function getrelativetime($date) {
// Credit: http://snipplr.com/view/4912/relative-time/ and http://twitter.pbwiki.com/RelativeTimeScripts
$gap = time() - strtotime($date);
if ($gap&lt;5) {
return 'less than 5 seconds ago';
} else if ($gap&lt;10) {
return 'less than 10 seconds ago';
} else if ($gap&lt;20) {
return 'less than 20 seconds ago';
} else if ($gap&lt;40) {
return 'half a minute ago';
} else if ($gap&lt;60) {
return 'less than a minute ago';
}
$gap = round($gap/60);
if ($gap &lt; 60)
return $gap.' minute'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/60);
if ($gap &lt; 24)
return $gap.' hour'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/24);
if ($gap&lt;7)
return $gap.' day'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/7);
if ($gap&lt;4)
return $gap.' week'.($gap &gt; 1 ? 's' : '').' ago';

return date(&quot;F jS, Y @h:i&quot;, strtotime($date));
}
?&gt;
</pre>
<p><a href="http://playground.gnvpartners.net/ex/rss/rss_reader.zip">Download the source code</a> for both scripts (24k ZIP)</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2009/05/31/a-simple-rss-reader-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP to retrieve cPanel Webalizer stats</title>
		<link>http://www.jek2k.com/wp/2009/02/20/php-to-retrieve-cpanel-webalizer-stats/</link>
		<comments>http://www.jek2k.com/wp/2009/02/20/php-to-retrieve-cpanel-webalizer-stats/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 09:00:58 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/?p=219</guid>
		<description><![CDATA[If you&#8217;re hosting your site on a cPanel-powered server, you&#8217;ll probably know it comes with a built-in stats app called Webalizer. Not that this is the best stats solution out there (I&#8217;d rather go for Google Analytics instead), but it is built-in, so you might want to give it a try.
Some time ago my friend [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re hosting your site on a cPanel-powered server, you&#8217;ll probably know it comes with a built-in stats app called Webalizer. Not that this is the best stats solution out there (I&#8217;d rather go for Google Analytics instead), but it is built-in, so you might want to give it a try.</p>
<p>Some time ago <a href="http://www.giasca.it">my friend Giacomo</a> sent me this little PHP script that allows you to view your cPanel/Webalizer stats from your browser or to make them publicly visible (or maybe make it visible to the client without forcing him to log into cPanel).</p>
<p>Just paste the following code into a text file, save it as stats.php and upload it to your web server.<br />
Viewing it in a browser will display your Webalizer stats and graphs.<br />
<span id="more-219"></span></p>
<pre class="brush: php;">
&lt;?php
$user = 'username'; //cpanel username
$pass = 'password'; //cpanel password
$url = 'www.yourdomain.com'; //do not include 'http://'

//retrieves the webalizer file, either .html or .png
function getFile($file) {
global $user, $pass, $url;
return file_get_contents(&quot;http://&quot; . $user . &quot;:&quot; . $pass . &quot;@&quot; . $url . &quot;:2082/tmp/&quot; . $user . &quot;/webalizer/&quot; . $file);
}
//alters links, either .html or .png
function changeLinks($subject, $type) {
return preg_replace(&quot;/($type=&quot;)(?!http)(.*?)&quot;/is&quot;,&quot;$1$PHP_SELF?$2&quot;&quot;,$subject);
}

if(!empty($_SERVER['QUERY_STRING'])) {

//get file (whether png or html)
$page = getFile($_SERVER['QUERY_STRING']);

//if png, output appropriate header
if(strpos($_SERVER['QUERY_STRING'],'.png') !== false) {
header(&quot;Content-type: image/png&quot;);
}
//change the .png src(s)
else {
$page = changeLinks($page, 'src');
}
}
else {
//get index
$page = getFile('index.html');

//change links
$page = changeLinks($page, 'href');

//change the usage.png src
$page = changeLinks($page, 'src');
}
//output it
echo $page;

?&gt;
 </pre>
<p><a href="http://playground.gnvpartners.net/ex/cpanel_stats.zip">Download the source code </a>(1k ZIP)</p>
<p>This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2009/02/20/php-to-retrieve-cpanel-webalizer-stats/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Display subscriber count for FeedBurner feeds hosted by Google</title>
		<link>http://www.jek2k.com/wp/2009/01/30/display-subscriber-count-for-feedburner-feeds-hosted-by-google/</link>
		<comments>http://www.jek2k.com/wp/2009/01/30/display-subscriber-count-for-feedburner-feeds-hosted-by-google/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 09:00:46 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/?p=230</guid>
		<description><![CDATA[If you&#8217;re using FeedBurner to manage and publicize your RSS feeds, you might already know WordPress plugins like FeedCount, that help you get the number of your feed&#8217;s subscribers &#8211; btw, I&#8217;m assuming you too can&#8217;t stand the ugly FeedBurner default widget.
While this used to work as a charm, you also might have heard FeedBurner [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using FeedBurner to manage and publicize your RSS feeds, you might already know WordPress plugins like <a href="http://www.mapelli.info/feed/feed-count-12">FeedCount</a>, that help you get the number of your feed&#8217;s subscribers &#8211; btw, I&#8217;m assuming you too can&#8217;t stand the ugly FeedBurner default widget.</p>
<p>While this used to work as a charm, you also might have heard FeedBurner has been aquired by Google and it&#8217;s moving feed to Google&#8217;s server. Unfortunately the above plugin stops working for feeds hosted by Google.</p>
<p>My friend <a href="http://pestaola.gr">Stefanos (aka Titanas)</a> recently sent me this piece of code, that easily solves this issue.<br />
It will display the number of your subscribers, <a href="http://playground.gnvpartners.net/ex/feed_count/">like this</a>. </p>
<pre class="brush: php;">
&lt;?php
function get_subscriptors($feedburneruri) {
         $url=&quot;https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=&quot;.$feedburneruri;
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_URL, $url);
         $data = curl_exec($ch); curl_close($ch);
         $xml = new SimpleXMLElement($data);
         return $xml-&gt;feed-&gt;entry['circulation'];
}
?&gt;
Jek2k.com has &lt;?php echo get_subscriptors('jek2kdotcom'); ?&gt; subscribers.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2009/01/30/display-subscriber-count-for-feedburner-feeds-hosted-by-google/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flash-PHP: how to get the server&#8217;s date and time</title>
		<link>http://www.jek2k.com/wp/2008/06/25/flash-php-how-to-get-the-servers-date-and-time/</link>
		<comments>http://www.jek2k.com/wp/2008/06/25/flash-php-how-to-get-the-servers-date-and-time/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 14:51:34 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2008/06/25/flash-php-how-to-get-the-servers-date-and-time/</guid>
		<description><![CDATA[Today a fellow designer asked me how to retrieve the server&#8217;s date and time using Flash.
Since Flash is executed on the client, it reads the date and time of the client. The easiest way I could think of was using a bit of PHP.
We use PHP to get the server&#8217;s date and time, and then [...]]]></description>
			<content:encoded><![CDATA[<p>Today a fellow designer asked me how to retrieve the server&#8217;s date and time using Flash.<br />
Since Flash is executed on the client, it reads the date and time of the client. The easiest way I could think of was using a bit of PHP.<br />
We use PHP to get the server&#8217;s date and time, and then pass the value on to Flash using a flashvar.</p>
<p>Since I had to do this for a colleague, I&#8217;m sharing the final script here, in case someone else needs it.</p>
<p><a href="http://playground.gnvpartners.net/ex/remote_date/">See a working example</a> or <a href="http://playground.gnvpartners.net/ex/remote_date/remote_date.zip">download the source files</a> (24kb, ZIP, comments in italian only).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2008/06/25/flash-php-how-to-get-the-servers-date-and-time/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Retrieving Twitter updates with PHP</title>
		<link>http://www.jek2k.com/wp/2008/06/08/retrieving-twitter-updates-with-php/</link>
		<comments>http://www.jek2k.com/wp/2008/06/08/retrieving-twitter-updates-with-php/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 23:53:33 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2008/06/08/retrieving-twitter-updates-with-php/</guid>
		<description><![CDATA[I&#8217;ve started using Twitter a few months ago. Personally, I like the idea of easily sending short status updates, and the opportunity to integrate it into my blog or my Facebook page.
I&#8217;ve started playing around with Twitter APIs and found an interesting PHP class by Nick Beam.
I&#8217;ve used that class, basically a PHP wrapper for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started using <a href="http://twitter.com/">Twitter</a> a few months ago. Personally, I like the idea of easily sending short status updates, and the opportunity to integrate it into my blog or my Facebook page.</p>
<p>I&#8217;ve started playing around with <a href="http://groups.google.com/group/twitter-development-talk/web/api-documentation">Twitter APIs</a> and found <a href="http://twitter-development-talk.googlegroups.com/web/api_class.phps.txt?gda=bo4h1UMAAADDY4RxBmouwZtsLlfZE2USiiafVgS5RiazxT4znoMLKmG1qiJ7UbTIup-M2XPURDRSOws4Xi3QnSf7-kobJbms4hW8pUgcobEJRPIfCgn0ug">an interesting PHP class</a> by <a href="http://beamdev.blogspot.com/">Nick Beam</a>.<br />
I&#8217;ve used that class, basically a PHP wrapper for the the Twitter APIs, to develop a little PHP script that retrieves the last status updates from my Twitter profile. This can be integrated in virtually any website or blog using PHP, including your WordPress-powered blog.</p>
<p><strong>The basic script</strong><br />
The script lets you define a few parameters:</p>
<ul>
<li>your Twitter username</li>
<li>your password (in case your updates are protected)</li>
<li>the number of status updates to retrieve</li>
</ul>
<p>You can see it in action <a href="http://playground.gnvpartners.net/apps/twitter/twitter.php">here</a>.</p>
<p><strong>Filtering status updates</strong><br />
After I developed this simple script, I thought of using it to send quick updates to my website, like for example &#8220;taking the day off&#8221; or &#8220;starting a new project&#8221;.<br />
I realized I wanted to have the opportunity to filter my Twitted updates, to choose which messages should be published on my websites and which are just personal or part of Twitter conversations.</p>
<p>I decided to add a simple filtering functionality to my script, so that you can add a string to your messages to identify them. For example, I&#8217;m using this features to send updates to <a href="http://playground.gnvpartners.net/">playground.gnvpartners.net</a>, as shown in the screenshot below.</p>
<p style="text-align:center;"><a href="http://playground.gnvpartners.net/"><img src="http://www.jek2k.com/wp//wp/wp-content/uploads/2008/06/twitter1.jpg" alt="twitter1.jpg" /></a></p>
<p>I simply add <strong>[playground]</strong> before each message that I want to be published on that website. The string is obviously fully editable so that you can use any prefix you like.</p>
<p>Here&#8217;s how the PHP function call looks like:</p>
<pre class="brush: php;">
         getTwits('nicolovolpato','password',5,'playground');
</pre>
<p>where the first parameter is your Twitter username, the second one is your password (empty if your tweets are public), the third one is the number of messages to show and the last one is the string you want to use as a filter.</p>
<p>Anyway, I guess the best way to learn how the script works is to download the source and play with it.</p>
<p><a href="http://playground.gnvpartners.net/apps/twitter/twitter_functions.zip"></a></p>
<p><a href="http://www.jek2k.com/wp/wp-content/uploads/2008/06/twitter_toolkit.zip">Download twitter_toolkit.zip</a> (8kb ZIP).</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2008/06/08/retrieving-twitter-updates-with-php/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Building a custom Skype-me button with status icon</title>
		<link>http://www.jek2k.com/wp/2008/02/08/building-a-custom-skype-me-button-with-status-icon/</link>
		<comments>http://www.jek2k.com/wp/2008/02/08/building-a-custom-skype-me-button-with-status-icon/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 23:25:55 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2008/02/08/building-a-custom-skype-me-button-with-status-icon/</guid>
		<description><![CDATA[I&#8217;m not a big fan of Skype and I usually don&#8217;t use it. However, in a recent project, I was asked to add a &#8220;Skype Me&#8221; button in the contacts section of a client&#8217;s website.
I guess you all know Skype provides a bunch of free buttons and even an online wizard to build custom buttons. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not a big fan of Skype and I usually don&#8217;t use it. However, in a recent project, I was asked to add a &#8220;Skype Me&#8221; button in the contacts section of a client&#8217;s website.<br />
I guess you all know Skype provides a bunch of free buttons and even an online wizard to build custom buttons. This works pretty good, except it only allows to use the default Skype buttons and icons and images are PNGs.</p>
<p>What to do then if you need to use custom-designed buttons? Or if you&#8217;re targeting IE6 and have no transparent-PNGs support? I scored 2 on 2, having both those problems.</p>
<p>So I decided to search for some Skype documentation and build a script myself.<br />
Some basic information on creating custom Skype buttons and links <a href="http://www.skype.com/share/buttons/advanced.html">can be found here</a>. This explains how to code links, but still doesn&#8217;t address my problem. Then I found some more in-depth documentation on building web-services and apps interacting with Skype, that <a href="https://developer.skype.com/Docs/Web">can be downloaded from here</a>.</p>
<p>This way I found out that you can call a remote Skype URL, passing in your username and some parameters, to retrieve a status <a href="http://mystatus.skype.com/nicolovolpato">button</a>, a status <a href="http://mystatus.skype.com/nicolovolpato">code</a> or a status <a href="http://mystatus.skype.com/nicolovolpato.txt">string</a>.</p>
<p>The numeric status code is easier to use. Here&#8217;s a short list of numeric codes and their meaning:</p>
<ul>
<li><strong>0</strong> &#8211; unknown</li>
<li><strong>1</strong> &#8211; offline</li>
<li><strong>2</strong> &#8211; online</li>
<li><strong>3</strong> &#8211; away</li>
<li><strong>4</strong> &#8211; not available</li>
<li><strong>5</strong> &#8211; do not disturb</li>
<li><strong>6</strong> &#8211; invisible</li>
<li><strong>7</strong> &#8211; skype me</li>
</ul>
<p>Then I coded a short PHP script to take advantage of this function and retrieve the status code for a given Skype username.</p>
<pre class="brush: php;">
function getSkypeStatus($username) {
	$remote_status = fopen ('http://mystatus.skype.com/'.$username.'.num', 'r');
	if (!$remote_status) {
	    return '0';
	    exit;
	}
	while (!feof ($remote_status)) {
	    $value = fgets ($remote_status, 1024);
	    return trim($value);
	}
	fclose($remote_status);
}
</pre>
<p>Half of the job was done. Now I needed to link each code to a custom-designed status icon.</p>
<pre class="brush: php;">
function getSkypeStatusIcon($username) {
	$status = getSkypeStatus($username);
	// change the path of the icons folder to match your site
	echo '&lt;img src=&quot;/skype-icons/'.$status.'.jpg&quot; alt=&quot;call '.$username.'&quot; /&gt;';
}
</pre>
<p>So that calling the PHP function with the desired username&#8230;</p>
<pre class="brush: php;">
getSkypeStatusIcon('nicolovolpato');
</pre>
<p>&#8230;returns the necessary HTML code for the icon image.</p>
<pre class="brush: php;">
&lt;img src=&quot;/skype-icons/1.jpg&quot; alt=&quot;call nicolovolpato&quot; /&gt;
</pre>
<p>Of course I had then to go back to Photoshop and design my custom icons. I simply named the files like the status codes, where 1.jpg is the icon for offline, 2.jpg is the icon for online and so on.</p>
<p>I&#8217;ve tested this script using my Skype account and other accounts and seems pretty reliable. This is not the only method and I&#8217;m pretty sure this is not even the best method available, but it&#8217;s just the solution I have found to this problem and wanted to share it.</p>
<p><a rel="attachment" href="http://www.jek2k.com/wp//wp/wp-content/uploads/2008/02/skype.php.zip" title="Download skype.php.zip">Download the source code</a> (4k ZIP)</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2008/02/08/building-a-custom-skype-me-button-with-status-icon/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Timed based CSS stylesheet with PHP</title>
		<link>http://www.jek2k.com/wp/2007/05/03/timed-based-css-stylesheet-with-php/</link>
		<comments>http://www.jek2k.com/wp/2007/05/03/timed-based-css-stylesheet-with-php/#comments</comments>
		<pubDate>Thu, 03 May 2007 21:41:00 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2007/05/03/timed-based-css-stylesheet-with-php/</guid>
		<description><![CDATA[It&#8217;s been quite a long time since I last posted an article here at Jek2k.com.
On my company&#8217;s web site I&#8217;ve made a little PHP script to change the CSS stylesheet depending on the time of the day. We have a bright white theme for day time and a dark black one for night time and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been quite a long time since I last posted an article here at Jek2k.com.</p>
<p>On <a href="http://www.gnvpartners.com/web/">my company&#8217;s web site</a> I&#8217;ve made a little PHP script to change the CSS stylesheet depending on the time of the day. We have a bright white theme for day time and a dark black one for night time and Sundays (when we are closed). This script was initially inspired by the beautiful <a href="http://www.radiantmars.com/">Radiant Mars website</a>. </p>
<p>Some of you have asked me how I made it, so here is the code: </p>
<p><pre><pre>
&lt;?php 
// time based Css Swicth
$time = date(&quot;H&quot;);
$date = date(&quot;w&quot;);
if (!isset($_GET[&#039;css&#039;])) {
if ($time &gt;= 9 &amp;&amp; $time &lt; 18 &amp;&amp; $date != 0) { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/day.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? } else { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/night.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? }; 
} else { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/&lt;?php echo $_GET[&#039;css&#039;]; ?&gt;.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? }; ?&gt;
</pre></pre></p>
<p>Looks easy, doesn&#8217;t it? </p>
<p><strong>Let&#8217;s see it in detail</strong>.<br />
  First I&#8217;ve set up two variables to read the current time (hour) of the day and the current day (number, 0 = Sunday) of the week.</p>
<p><pre><pre>
$time = date(&quot;H&quot;);
$date = date(&quot;w&quot;);
</pre></pre></p>
<p>For more information about handling date and time with PHP, please <a href="http://it.php.net/date">see the PHP documentation</a>. </p>
<p>Then we have a pretty simple IF clause to check if the current time is between 9AM and 6PM and today is not Sunday.<br />
  According to this clause, the correct CSS stylesheet is loaded. </p>
<p><pre><pre>if ($time &gt;= 9 &amp;&amp; $time &lt; 18 &amp;&amp; $date != 0) { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/day.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? } else { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/night.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? }; 
</pre></pre></p>
<p>The last part is another IF clause, mainly for debug reasons.<br />
  It checks if we have added a variable to the page&#8217;s URL, ie. pagename.php?css=day. This way we can override the time check and load the desired CSS stylesheet directly. This is useful to test your CSS files without waiting for it to change. </p>
<p>That&#8217;s it. Pretty basic, but remember I&#8217;m just a designer!</p>
<p>Use the <a href="http://it.php.net/date">PHP  date function</a> to read other parameters and modify this script to change the CSS stylesheet according to seasons, holidays, day of the week or whatever you like. </p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2007/05/03/timed-based-css-stylesheet-with-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WordPress: displaying content outside the Loop</title>
		<link>http://www.jek2k.com/wp/2006/10/30/wordpress-displaying-content-outside-the-loop/</link>
		<comments>http://www.jek2k.com/wp/2006/10/30/wordpress-displaying-content-outside-the-loop/#comments</comments>
		<pubDate>Mon, 30 Oct 2006 11:59:45 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/10/30/wordpress-displaying-content-outside-the-loop/</guid>
		<description><![CDATA[I assume everyone out there know what WordPress is and what it does.
The Loop is the process that occurs when WordPress reads the database and outputs your posts or pages to the destination Html page.
A more detailed explanation can be found here.
Inside the Loop you can use Template Tags (see this page) to modify the [...]]]></description>
			<content:encoded><![CDATA[<p>I assume everyone out there know what WordPress is and what it does.</p>
<p><strong>The Loop</strong> is the process that occurs when WordPress reads the database and outputs your posts or pages to the destination Html page.<br />
A more detailed explanation can be found <a href="http://codex.wordpress.org/The_Loop">here</a>.</p>
<p>Inside the Loop you can use <strong>Template Tags</strong> (<a href="http://codex.wordpress.org/Template_Tags">see this page</a>) to modify the output information and choose what elements of the post should be displayed (see <a href="http://codex.wordpress.org/Template_Tags#Post_tags">Post Tags</a>).</p>
<p>This is the very basic concept behind WordPress templates.</p>
<p>With WordPress you have also the ability to make <strong>custom queries</strong> to the database to extract your specific content.<br />
In this case, you will need the following sintax:<br />
<pre><pre>
&lt;?php query_posts(&#039;category_name=news&amp;showposts=5&#039;); ?&gt;
&lt;?php if (have_posts()) : ?&gt;
&lt;?php while (have_posts()) : the_post(); ?&gt;

&nbsp;&nbsp;&nbsp;&nbsp; &lt;div class=&quot;news&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h4&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h4&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php the_excerpt(); ?&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;
</pre></pre></p>
<p>The code above works perfectly when you are inside the Loop, <strong>but what if you are outside of it?</strong><br />
Or if you want to include contents from two different loops, for example for making an Asides section?<br />
Then the <strong>query_posts()</strong> function will not be of any help.</p>
<p>You will have to make a totally new custom query, using a different sintax.<br />
This is needed in order to not overwrite the data retrieved by the main Loop query.</p>
<p>It will look like this:<br />
<pre><pre>
&lt;?php $my_query = new WP_Query(&#039;pagename=another-static-page&#039;); ?&gt;
&lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;
&lt;?php $do_not_duplicate = $post-&gt;ID; ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php the_content(); ?&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;?php endwhile; ?&gt;
</pre></pre></p>
<p>The first line:<br />
<pre><pre>
&lt;?php $my_query = new WP_Query(&#039;pagename=another-static-page&#039;); ?&gt;
</pre></pre><br />
makes the new query and storing the retrieved data inside the <strong>$my_query</strong> variable.<br />
That&#8217;s the reason why we have that strange sintax <strong>$my_query->have_posts()</strong> later on.<br />
This ensures we are browsing data only inside our new variable.</p>
<p>This line:<br />
<pre><pre>
&lt;?php $do_not_duplicate = $post-&gt;ID; ?&gt;
</pre></pre><br />
makes sure we&#8217;re not duplicating posts, so the same post won&#8217;t appear in both queries.</p>
<p>As you can see, then we can output the information with the same good old sintax:<br />
<pre><pre>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php the_content(); ?&gt;
</pre></pre></p>
<p>This way of retrieving and displaying custom information from your WordPress database comes very handy when creating advanced themes or when using WP as a CMS platform and you want to have full control on what is displayed. </p>
<p>As always, the best place to find exhaustive information about Wordpress tweaks is the <a href="http://codex.wordpress.org">Codex website.</a></p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/10/30/wordpress-displaying-content-outside-the-loop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A PHP Css stylesheet switcher</title>
		<link>http://www.jek2k.com/wp/2006/08/01/a-php-css-stylesheet-switcher/</link>
		<comments>http://www.jek2k.com/wp/2006/08/01/a-php-css-stylesheet-switcher/#comments</comments>
		<pubDate>Tue, 01 Aug 2006 00:47:42 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/08/01/a-php-css-stylesheet-switcher/</guid>
		<description><![CDATA[This is an English translation of the original  tutorial.
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
Following my previous article, I keep on publishing the &#8220;secrets&#8221; behind Jek2k.com.
Today we&#8217;ll see how to create a Css stylesheet switcher using PHP, to change your Css on-the-fly.
There are many techniques to do that.
First, using Javascript.
On A List Apart you can find a very well written [...]]]></description>
			<content:encoded><![CDATA[<p>This is an English translation of <a href="http://www.jek2k.com/wp/index.php/2006/06/18/css-switch-con-php/">the original  tutorial</a>.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Following <a href="http://www.jek2k.com/wp/index.php/2006/06/10/drop-down-con-javascript/">my previous article</a>, I keep on publishing the &#8220;secrets&#8221; behind Jek2k.com.<br />
Today we&#8217;ll see how to create a Css stylesheet switcher using PHP, to change your Css on-the-fly.</p>
<p>There are many techniques to do that.<br />
First, using Javascript.<br />
On <a href="http://www.alistapart.com/articles/alternate/" target="_blank">A List Apart</a> you can find a very well written tutorial to create a Css switcher with JS, using a cookie to keep the user&#8217;s preference.<br />
And the obtained page also conforms to W3C standards.</p>
<p>The main problem of this method is that, being Javascript, it runs on the client, so it depends on the browser and requires the user to have JS enabled.<br />
<em>The validity of this technique depends on your site&#8217;s target. No problem if you have a tech-savvy users target, with modern browsers and smart enough to not disable Javascript!</em></p>
<p>I chose to use another method, using PHP, not because of my users, but because I use WordPress, which is written in PHP.<br />
Aside from this, PHP runs on the server, so it is browser-independent.<br />
<a href="http://www.alistapart.com/articles/phpswitch/" target="_blank">A List Apart</a> has a very good tutorial which covers this method too.<br />
A very easy, step-by-step tutorial.</p>
<p>I&#8217;d add just a couple of suggestions, to make it even smoother.</p>
<p>First:<br />
the cookie duration.<br />
Do you really want to keep the cookie for a year??!!? I think it is really too long.</p>
<p>So, in the following piece of code<br />
<pre><pre>
&lt;?php
setcookie (&#039;sitestyle&#039;, $set, time()+31536000, &#039;/&#039;, &#039;yourdomain.com&#039;, &#039;0&#039;);
header(&quot;Location: $HTTP_REFERER&quot;);
?&gt;
</pre></pre><br />
change the value <strong>31536000</strong> (duration of the cookie, in seconds).<br />
to <strong>2592000</strong> to set a monthly cookie, or <strong>604800</strong> to set a weekly one</p>
<p>Second:<br />
the code that reads the cookie. Change the following<br />
<pre><pre>
&lt;?php echo (!$sitestyle)?&#039;defaultstyle&#039;:$sitestyle ?&gt;
</pre></pre><br />
to<br />
<pre><pre>
&lt;?php echo (!$_COOKIE[&#039;sitestyle&#039;])?&#039;defaultstyle&#039;:$_COOKIE[&#039;sitestyle&#039;] ?&gt;
</pre></pre><br />
which seems to work better (at least, it does work better for me). </p>
<p>&nbsp;</p>
<p>Well, that&#8217;s all folks!<br />
I hope this can be useful to someone.</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/08/01/a-php-css-stylesheet-switcher/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
