<?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>a32.Blog &#187; php</title>
	<atom:link href="http://a32.me/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://a32.me</link>
	<description>It&#039;s all about. IT and &#34;stuff&#34; :)</description>
	<lastBuildDate>Fri, 04 May 2012 07:14:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to run PHP cron tasks without cron available</title>
		<link>http://a32.me/2012/01/do-php-cron-without-cron-available/</link>
		<comments>http://a32.me/2012/01/do-php-cron-without-cron-available/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:47:36 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=2187</guid>
		<description><![CDATA[In most cases hosting panels has CRON jobs available, so using cron is not an issue. Just sometimes you do not want to bother with it because of many reasons like no cpanel password, makes your script installation process complicated, or even cron is simply not available at all. In this case I found interesting technique how [...]]]></description>
			<content:encoded><![CDATA[<p>In most cases hosting panels has CRON jobs available, so using cron is not an issue. Just sometimes you do not want to bother with it because of many reasons like no cpanel password, makes your script installation process complicated, or even cron is simply not available at all.</p>
<p>In this case I found interesting technique how to overcome this.</p>
<p><span id="more-2187"></span></p>
<p>The idea is simple and is borrowed from official documentation comments. In PHP it is possible to <strong>sent browser output and continue to execute other PHP code</strong>.</p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4139588230521520";
/* Intest */
google_ad_slot = "1267310946";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<p>This means that on each page request, PHP generates full HTML, sends to the user and closes the connection. User is happy to view the page, however on the server PHP script may execute useful stuff.</p>
<p>Code looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ob_start</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;">// Generage HTML page here</span>
generate_full_html_page<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;">// All magic goes here</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ignore_user_abort</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">set_time_limit</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: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connection: close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Encoding: none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #990000;">flush</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;">// Now page is sent and it safe to do all needed stuff here</span>
cron_task1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cron_task2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you need to run CRON jobs continuously and not to depend on the user visits, you may initiate a SELF request to the same page using CURL after all tasks are done.</p>
<p>Based on this technique very easy to make a full CRON class which will handle all the dirty job, may be in future )</p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2012%2F01%2Fdo-php-cron-without-cron-available%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2012/01/do-php-cron-without-cron-available/" data-text="How to run PHP cron tasks without cron available">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2012/01/do-php-cron-without-cron-available/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=How to run PHP cron tasks without cron available&amp;body=http://a32.me/2012/01/do-php-cron-without-cron-available/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2012/01/do-php-cron-without-cron-available/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to merge/mix/combine RSS feeds</title>
		<link>http://a32.me/2011/10/combine-mix-merge-rss-feed-php/</link>
		<comments>http://a32.me/2011/10/combine-mix-merge-rss-feed-php/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 08:40:12 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=1736</guid>
		<description><![CDATA[One problem I faced on my multi-language blog setup - it has different feeds for each language. Multi-language plugin WPML which I use does not have feature to mix feeds into one. I like my subscribers to see one common feed which is merged for all languages and leave possibility to subscribe to one language [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://a32.me/wp-content/uploads/2011/10/rss-mix.jpg"><img class="alignleft size-full wp-image-1929" title="rss-mix" src="http://a32.me/wp-content/uploads/2011/10/rss-mix.jpg" alt="" width="97" height="94" /></a>One problem I faced on my multi-language blog setup - it has different feeds for each language. Multi-language plugin WPML which I use does not have feature to mix feeds into one. I like my subscribers to see one common feed which is merged for all languages and leave possibility to subscribe to one language also. I setup simple solution using pure PHP.</p>
<p><span id="more-1736"></span>I did research several times about it and found very few information.</p>
<h2>RSS merge for WordPress</h2>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4139588230521520";
/* Intest */
google_ad_slot = "1267310946";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<p>Very few plugins exists for WordPress and they do not work with recent 3.X versions. Unfortunately.</p>
<h2>Yahoo pipes</h2>
<p>Yahoo pipes is a very flexible and feature rich tool for managing RSS feeds. It is possible fetch, merge, split, filter for any RSS source. It has nice graphical interface for all this.</p>
<p>But I think it is a little but overkill for my two feeds.</p>
<h2>PHP Solution for mixing RSS feeds</h2>
<p>I did not want to bother with PHP coding for such a simple task. But if to compare actual time for coding it is far less then trying different plugins and research.</p>
<p>So I found somewhere on the Internet these two nice libraries:</p>
<ul>
<li><strong>magpierss</strong> - for fetching feeds</li>
<li><strong>feedcreator.class.php</strong> - for publishing feeds</li>
</ul>
<p>With a small PHP glue between them I created simple script for merging several RSS feeds into one. Below is simple script that does the job.</p>
<p>You can <strong>download</strong> full package with libraries included below in the end of post.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Setup part
 * 
 */</span>
<span style="color: #000088;">$DOMAIN_NAME</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://a32.me/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$FEED_URL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DOMAIN_NAME</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'rss/full.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SITE_TITLE</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a32.blog by Constantin Bosneaga'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SITE_DESRIPTION</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Its all about. IT and &quot;stuff&quot; :)'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SITE_AUTHOR</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Constantin Bosneaga'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$RSS_CACHE</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/tmp/rsscache&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$RSS_CACHE_EXP</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7200</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$FEED_LIST</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'http://a32.me/feed/'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'http://a32.me/feed/?lang=ru'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Do not modify below this point
 * 
 */</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_CACHE_ON'</span><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;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_CACHE_DIR'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$RSS_CACHE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_CACHE_AGE'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$RSS_CACHE_EXP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_OUTPUT_ENCODING'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// include required files </span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'magpierss-0.72/rss_fetch.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'feedcreator.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Set RSS properties */</span>
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UniversalFeedCreator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">useCached</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SITE_TITLE</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SITE_DESRIPTION</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DOMAIN_NAME</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">syndicationURL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$FEED_URL</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encoding</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Set Image properties 
$image = new FeedImage();
$image-&gt;title = $SITE_TITLE . &quot; Logo&quot;;
$image-&gt;url = $SITE_LOG_URL;
$image-&gt;link = $DOMAIN_NAME;
$image-&gt;description = &quot;Feed provided by &quot; . $SITE_TITLE . &quot;. Click to visit.&quot;;
$rss-&gt;image = $image;
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showSummary<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$showfullfeed</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: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">,</span> <span style="color: #000088;">$DOMAIN_NAME</span><span style="color: #339933;">,</span> <span style="color: #000088;">$SITE_AUTHOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$SITE_TITLE</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$num_items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span> <span style="color: #000088;">$rss1</span> <span style="color: #339933;">=</span> fetch_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</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: #000088;">$rss1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num_items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$href</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$showfullfeed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$desc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</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: #000088;">$desc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'encoded'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">//                $desc .=  '</span>
			<span style="color: #666666; font-style: italic;">//Copyright &amp;copy; &lt;a href=&quot;'.$DOMAIN_NAME.'&quot;&gt;'.$SITE_TITLE.'&lt;/a&gt;.  All Rights Reserved.</span>
			<span style="color: #666666; font-style: italic;">//';</span>
			<span style="color: #000088;">$pdate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FeedItem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'encoded'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DOMAIN_NAME</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SITE_AUTHOR</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss_item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<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;Error: Cannot fetch feed url - &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fetch all feeds</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$FEED_LIST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> showSummary<span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sort items by date</span>
<span style="color: #000000; font-weight: bold;">function</span> __usort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bd</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">return</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'__usort'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Display items</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveFeed</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RSS1.0&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$RSS_CACHE</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/feed.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Setup part
 * 
 */</span>
<span style="color: #000088;">$DOMAIN_NAME</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://a32.me/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$FEED_URL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DOMAIN_NAME</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'rss/full.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SITE_TITLE</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a32.blog by Constantin Bosneaga'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SITE_DESRIPTION</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Its all about. IT and &quot;stuff&quot; :)'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SITE_AUTHOR</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Constantin Bosneaga'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$RSS_CACHE</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/tmp/rsscache&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$RSS_CACHE_EXP</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7200</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$FEED_LIST</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'http://a32.me/feed/'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'http://a32.me/feed/?lang=ru'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Do not modify below this point
 * 
 */</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_CACHE_ON'</span><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;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_CACHE_DIR'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$RSS_CACHE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_CACHE_AGE'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$RSS_CACHE_EXP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MAGPIE_OUTPUT_ENCODING'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// include required files </span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'magpierss-0.72/rss_fetch.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'feedcreator.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Set RSS properties */</span>
<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UniversalFeedCreator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">useCached</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SITE_TITLE</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SITE_DESRIPTION</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DOMAIN_NAME</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">syndicationURL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$FEED_URL</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encoding</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Set Image properties 
$image = new FeedImage();
$image-&gt;title = $SITE_TITLE . &quot; Logo&quot;;
$image-&gt;url = $SITE_LOG_URL;
$image-&gt;link = $DOMAIN_NAME;
$image-&gt;description = &quot;Feed provided by &quot; . $SITE_TITLE . &quot;. Click to visit.&quot;;
$rss-&gt;image = $image;
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showSummary<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$showfullfeed</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: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">,</span> <span style="color: #000088;">$DOMAIN_NAME</span><span style="color: #339933;">,</span> <span style="color: #000088;">$SITE_AUTHOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$SITE_TITLE</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$num_items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span> <span style="color: #000088;">$rss1</span> <span style="color: #339933;">=</span> fetch_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</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: #000088;">$rss1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num_items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$href</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$showfullfeed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$desc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</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: #000088;">$desc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'encoded'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">//                $desc .=  '</span>
			<span style="color: #666666; font-style: italic;">//Copyright &amp;copy; &lt;a href=&quot;'.$DOMAIN_NAME.'&quot;&gt;'.$SITE_TITLE.'&lt;/a&gt;.  All Rights Reserved.</span>
			<span style="color: #666666; font-style: italic;">//';</span>
			<span style="color: #000088;">$pdate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FeedItem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'encoded'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DOMAIN_NAME</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$SITE_AUTHOR</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss_item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<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;Error: Cannot fetch feed url - &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fetch all feeds</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$FEED_LIST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> showSummary<span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sort items by date</span>
<span style="color: #000000; font-weight: bold;">function</span> __usort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bd</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">return</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">items</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'__usort'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Display items</span>
<span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveFeed</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RSS1.0&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$RSS_CACHE</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/feed.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;</pre></div></div>

<h2>Download RSS feed mixer/combiner</h2>
<p><a href="http://a32.me/other/rss-mixer.tar.gz">Download RSS feed mixer/combiner</a>. Unpack and change the Setup part of the script.</p>
<h2>Vote for wordpress plugin</h2>
<p>If you like to see these functionality done as WordPress plugiun, please leave your vote in comments!</p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F10%2Fcombine-mix-merge-rss-feed-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/10/combine-mix-merge-rss-feed-php/" data-text="How to merge/mix/combine RSS feeds">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/10/combine-mix-merge-rss-feed-php/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=How to merge/mix/combine RSS feeds&amp;body=http://a32.me/2011/10/combine-mix-merge-rss-feed-php/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/10/combine-mix-merge-rss-feed-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Introduction to HTML5 History API</title>
		<link>http://a32.me/2011/10/introduction-to-html5-history-api/</link>
		<comments>http://a32.me/2011/10/introduction-to-html5-history-api/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 07:30:14 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://a32.me/?p=1407</guid>
		<description><![CDATA[HTML5 slowly releases all its beauty. Before HTML5 one thing which was almost completly out of our control was  the browser history manipulation without full page reload (location.hash hacks are not counted here). With appearence of HTML5 History API all things changed, now it is possible to add elements to the history, add navigation handlers and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://a32.me/wp-content/uploads/2011/06/html5.jpg"><img class="size-full wp-image-1388 alignleft" title="html5" src="http://a32.me/wp-content/uploads/2011/06/html5.jpg" alt="" width="96" height="80" /></a>HTML5 slowly releases all its beauty. Before HTML5 one thing which was almost completly out of our control was  the browser history manipulation without full page reload (location.hash hacks are not counted here). With appearence of HTML5 History API all things changed, now it is possible to add elements to the history, add navigation handlers and more.  This time I am going to dive into <strong>HTML5 History API.</strong></p>
<p><span id="more-1407"></span></p>
<h2>History API basics</h2>
<p>History APS bases on the single DOM interface - History object. Each browser tab has its own unique History object, which is accessible  in <strong>window.history</strong>.</p>
<p>History has a number of methods, events and properties that we can control from <strong>JavaScript</strong>. Each page of the browser tab (Document object) is a collection of History objects.</p>
<p>Each element of the history consist of URL, state of the object (state object), can have a title, document object, form data, scroll position and other information related to the page.</p>
<p>The main methods of the History object are:</p>
<ol>
<li><code>window.history.length</code>: Number of entries in the current session history</li>
<li><code>window.history.state</code>: Returns current history object</li>
<li><code>window.history.go(n)</code>: Method allows to walk through history. The argument passed is the offset the current position. If you pass 0, the current page will be updated. If the index goes beyond the history, nothing happens.</li>
<li><code>window.history.back()</code>: The method is identical to calling <code>go(-1)</code></li>
<li><code>window.history.forward()</code>: The method is identical to calling <code>go(1)</code></li>
<li><code>window.history.pushState(data, title [, url])</code>: Adds an element to the history</li>
<li><code>window.history.replaceState(data, title [, url])</code>: Updates the current element of history</li>
</ol>
<p>To go two steps back in history you can use:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">history.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>To add elements of history, you can use <code>history.pushState</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">history.<span style="color: #660066;">pushState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>foo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bar'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Title'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'/baz.html'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>To change the history records we can use <code>history.replaceState</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">history.<span style="color: #660066;">replaceState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>foo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bat'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'New Title'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<h4>Live example</h4>
<p>Now we know the basics, let's look at a live example. We will do a web file manager, which allows you to find the URI of selected image (<a title="html5 history example demo page" href="/other/history/viewer.html" target="_blank">look what you get in the end</a>). The File Manager uses a simple file structure that is written in JavaScript. When you select a picture file or folder is updated dynamically.</p>
<p><img src="http://devfiles.myopera.com/articles/5812/example.png" alt="image" /></p>
<p>We use data-* attributes to store the header of each image and use the property dataset for this property:</p>
<p><code>&lt;li class="photo"&gt; &lt;a href="crab2.png" data-note="Grey crab!"&gt;crab2.png&lt;/a&gt; &lt;/li&gt;</code></p>
<p>To get everything working quickly we load all the pictures and update the src attribute dynamically. But, this acceleration creates a problem - it breaks the back button, so you can not go by pictures forward or backward.</p>
<p>HTML5 history comes to the rescue!</p>
<p>Every time we choose a file new history record is created and document location is updated(it contains a unique URL of the image). This means that we can use the back and forward button navigate through then our images, while in the address bar, we have a direct link to the picture that we can save a bookmark, or send someone else.</p>
<h2>Demo code</h2>
<p>We have 2 divs. One contains a folder structure, the other contains the current picture. Here I will show only the most important moments. <a href="a32.me/other/history/app.js" target="_blank">Source code of example is very short</a> (80 lines) look at it after reading the entire article.</p>
<p>The method bindEvents add handlers for the event <strong>popstate</strong>, which is called when the user navigates through the history and allows the application to updateits state.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'popstate'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  self.<span style="color: #660066;">loadImage</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">state</span>.<span style="color: #660066;">path</span><span style="color: #339933;">,</span> e.<span style="color: #660066;">state</span>.<span style="color: #660066;">note</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The object <strong>event</strong>, which is passed to the event handler has a property <strong>state</strong> - the data that we have passed as first argument to pushState or replaceState.</p>
<p>We bind event handler click event on the DIV element, which is our filestructure. Using the delegation event, we open or close the folder or download a picture (with the addition of history record). We look at the <strong>className</strong> of the parent element in order to understand which of the items we clicked:</p>
<ul>
<li>If this folder we open or close it</li>
<li>If this is a picture, then we show it, and add an element of history</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   dir.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> e.<span style="color: #660066;">target</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">classList</span>.<span style="color: #660066;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'folder'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          self.<span style="color: #660066;">toggleFolders</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">classList</span>.<span style="color: #660066;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'photo'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">//be nice to FF 4 &amp;amp; 5, as they don't have .dataset yet</span>
          <span style="color: #006600; font-style: italic;">//https://bugzilla.mozilla.org/show_bug.cgi?id=560112</span>
          note <span style="color: #339933;">=</span> f.<span style="color: #660066;">dataset</span> <span style="color: #339933;">?</span> f.<span style="color: #660066;">dataset</span>.<span style="color: #660066;">note</span> <span style="color: #339933;">:</span> f.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data-note'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          self.<span style="color: #660066;">loadImage</span><span style="color: #009900;">&#40;</span>f.<span style="color: #660066;">textContent</span><span style="color: #339933;">,</span> note<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          history.<span style="color: #660066;">pushState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>note<span style="color: #339933;">:</span> note<span style="color: #339933;">,</span> path<span style="color: #339933;">:</span>f.<span style="color: #660066;">textContent</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> f.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A method that modifies the contents of pictures and updates its signature is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">loadImage<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> note<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> path<span style="color: #339933;">;</span>
  h2.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span> note<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I have a <a title="html5 history demo application" href="http://a32.me/other/history/viewer.html" target="_blank">simple html5 history demo application</a> that demonstrates the possibility of the updated interface of <strong>History</strong> object. We use <strong>pushState</strong> to add an element of history and event <strong>popstate</strong> to update page content.</p>
<p>In addition, when you click on the picture we get a valid URL in the address bar, so you can save or send it to someone.</p>
<h2>When can I use it?</h2>
<p>Firefox 4+<br />
Safari 5+<br />
Chrome 10+<br />
Opera 11.5+<br />
iOS Safari 4.2+<br />
Android 2.2+<br />
IE ???<br />
<a href="http://caniuse.com/#search=history">See browser list with History API supported</a></p>
<h2>Additional reading</h2>
<p>See my post about <a title="File uploads in HTML5 – what’s new ?" href="http://a32.me/2011/06/file-uploads-in-html5-whats-new/" target="_blank">HTML5 FileUpload API</a></p>
<p>1. <a href="http://diveintohtml5.org/history.html">Manipulating History for Fun &amp; Profit</a><br />
2. <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html">WHATWG HTML5 history API</a><br />
3. <a href="http://dev.w3.org/html5/spec/history.html">W3C history API Spec</a><br />
4. MDC <a href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history">Manipulating the browser history</a><br />
5. <a href="https://github.com/balupton/History.js/">History.js</a> — emulates HTML5 history API(location.hash magic) in browser, which does not support it</p>
<p>rss_only</p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F10%2Fintroduction-to-html5-history-api%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/10/introduction-to-html5-history-api/" data-text="Introduction to HTML5 History API">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/10/introduction-to-html5-history-api/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=Introduction to HTML5 History API&amp;body=http://a32.me/2011/10/introduction-to-html5-history-api/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/10/introduction-to-html5-history-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying a web application via FTP</title>
		<link>http://a32.me/2011/06/deployment-via-ftp-in-linux/</link>
		<comments>http://a32.me/2011/06/deployment-via-ftp-in-linux/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 18:41:45 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=1248</guid>
		<description><![CDATA[When your brand new application looks shinny, it is time to put it on the Internet, process called deployment. Usually this involves several steps, like uploading application files, creating remote database, setting up configuration, etc.. Once it is setup and running you reazlise that your app is missing features X, Y and Z and deployment [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://a32.me/wp-content/uploads/2011/06/ftp.jpg"><img class="alignleft size-thumbnail wp-image-1386" title="ftp" src="http://a32.me/wp-content/uploads/2011/06/ftp-150x150.jpg" alt="" width="90" height="90" /></a>When your brand new application looks shinny, it is time to put it on the Internet, process called deployment. Usually this involves several steps, like uploading application files, creating remote database, setting up configuration, etc.. Once it is setup and running you reazlise that your app is missing features X, Y and Z and deployment starts over and over again, this often leads to strange bugs.</p>
<p>I use simple <strong>lftp</strong> command line tool to automate project deployment via FTP and eliminate any possible deployment errors.</p>
<p><span id="more-1248"></span></p>
<h2>The problem</h2>
<p>When the project becomes complex, deployment is going to be complex too. It includes many steps and forgeting just one can lead to hard tracking situations. Likely you are going to catch bugs like: <strong>it works locally but does not on remote server.</strong></p>
<p>Once it happens over and over again and there is room for an error, this needs to be automated, no more manual actions are needed. <strong>I want it just run-and-forget</strong>.</p>
<p>Here is the list of my basic requirements</p>
<ul>
<li><strong>Mirror application code files</strong>, this involves only updating files that have been changed, project may contains thousands of files and this will take time</li>
<li><strong>Remove</strong> stale application files on server side which are no longer in use</li>
<li><strong>Skip uploading configuration files,</strong> This is a common case, overwriting database configuration on the server with local configuration.</li>
<li><strong>Skip uploading data folders,</strong> while some folders on the server may have user data in it, do not touch these folders</li>
<li><strong>Delete remote cache files, </strong>some frameworks and template engines create remote cache files, which needs to be removed</li>
<li><strong>Change remote permissions,</strong> to be sure folders can be used for uploaded files</li>
<li><strong>Fully automatic</strong>, setup once and run when needed</li>
</ul>
<h2>Lftp - seems like a solution</h2>
<p><strong>lftp</strong> is a program that allows sophisticated ftp and http connections to other hosts. <strong>lftp</strong> can handle six file access methods - ftp, ftps, http, https, hftp.   Every operation in <strong>lftp</strong> is reliable, that is any not fatal error is ignored and the operation is repeated. So if downloading breaks, it will be restarted from the point automatically.</p>
<p><strong>lftp</strong> has shell-like command syntax allowing, it accepts on the input script like program. Each command tells lftp what to do. This gives perfect control of what is going to be uploaded or deleted.</p>
<p>Installing under Ubuntu is pretty straightforward: <strong>apt-get install lftp</strong>. There is also <a title="http://redpark.posterous.com/lftp-for-windows" href="http://redpark.posterous.com/lftp-for-windows" target="_blank">windows version available</a>.</p>
<h2>Usage example</h2>
<p>In this example, <strong>lftp</strong> script is used for uploading CakePHP project, which is not a simple upload task.</p>
<p>In the project folder I created file <strong>sync.sh</strong> which handles all the dirty job, below is the content of the file.</p>
<p><strong>www</strong> is local folder. <strong>public_htm</strong>l is remote folder.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
lftp <span style="color: #000000; font-weight: bold;">&amp;</span>lt;<span style="color: #000000; font-weight: bold;">&amp;</span>lt; EOF
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:ssl-allow no
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:passive-mode <span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:list-options <span style="color: #660033;">-a</span>
open <span style="color: #660033;">-u</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>USERNAME<span style="color: #7a0874; font-weight: bold;">&#93;</span>,<span style="color: #7a0874; font-weight: bold;">&#91;</span>PASSWORD<span style="color: #7a0874; font-weight: bold;">&#93;</span> ftp.host.com
<span style="color: #666666; font-style: italic;"># Upload site configuration</span>
put <span style="color: #660033;">-O</span> public_html<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span> www<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>bootstrap.php
put <span style="color: #660033;">-O</span> public_html<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span> www<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>config<span style="color: #000000; font-weight: bold;">/</span>routes.php
<span style="color: #666666; font-style: italic;"># Mirror program code</span>
mirror <span style="color: #660033;">-R</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--exclude</span> config <span style="color: #660033;">--exclude</span> tmp <span style="color: #660033;">--exclude</span> webroot www<span style="color: #000000; font-weight: bold;">/</span>app public_html<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>app
<span style="color: #666666; font-style: italic;"># Mirror webroot (not delete remote user files)</span>
mirror <span style="color: #660033;">-R</span> <span style="color: #660033;">--exclude</span> user_data www<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>webroot public_html<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>webroot
<span style="color: #7a0874; font-weight: bold;">cd</span> public_html<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>models
mrm <span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> public_html<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>persistent
mrm <span style="color: #000000; font-weight: bold;">*</span>
EOF</pre></div></div>

<p>FTP username or password can be embedded into script itself, which is less secure. More secure way is to add additional lines of bash scripting to ask for password.</p>
<p><strong>put</strong> - uploads one sinlge file. First argument is REMOTE file name, second argument is LOCAL file name.</p>
<p><strong>mirror</strong> - synchronizes local and remote folder. Used swithes are:</p>
<ul>
<li>-R - sync from local to remote (uploading, NOT downloading)</li>
<li>--delete - delete files on remote side which do not exist on local side</li>
<li>--exclude - exclude directory by name</li>
<li>cd - remote change directory command</li>
<li>mrm - remove multiple files</li>
</ul>
<h3>Debugging</h3>
<p>When lftp is run with "-d" switch it shows all FTP commands, which is good for debugging. One more good switch of <strong>mirror</strong> command is "--dry-run", it just shows what is going to be uploaded without any actual action performed.</p>
<p><strong>Beware!</strong> Do not do any experiments on live project with uncommitted changes!!! You may loose your changes. Do a project copy or commit all changes before.</p>
<h2>Conclusion</h2>
<p>Now I am sure that after development round all changes will be uploaded to the server and nothing left behind. Upload script is easy customizable for future projects.</p>
<h3>Resources</h3>
<ul>
<li><a href="http://lftp.yar.ru/lftp-man.html" target="_blank">LFTP man page</a></li>
</ul>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F06%2Fdeployment-via-ftp-in-linux%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/06/deployment-via-ftp-in-linux/" data-text="Deploying a web application via FTP">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/06/deployment-via-ftp-in-linux/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=Deploying a web application via FTP&amp;body=http://a32.me/2011/06/deployment-via-ftp-in-linux/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/06/deployment-via-ftp-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File uploads in HTML5 &#8211; what&#8217;s new ?</title>
		<link>http://a32.me/2011/06/file-uploads-in-html5-whats-new/</link>
		<comments>http://a32.me/2011/06/file-uploads-in-html5-whats-new/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 21:00:10 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://a32.me/?p=1194</guid>
		<description><![CDATA[File uploads have traditionally had very bad usability on the web. The standard solution was uploading files as part of a form, leaving the user to just wait until the process was done. We could offer barely any feedback of what was going on. Several options appeared in HTML5 to make the process more bearable for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://a32.me/wp-content/uploads/2011/06/html5.jpg"><img class="size-full wp-image-1388 alignleft" title="html5 file upload" src="http://a32.me/wp-content/uploads/2011/06/html5.jpg" alt="html5 file upload" width="77" height="64" /></a></p>
<p>File uploads have traditionally had very bad usability on the web. The standard solution was uploading files as part of a form, leaving the user to just wait until the process was done. We could offer barely any feedback of what was going on. Several options appeared in HTML5 to make the process more bearable for the user.</p>
<p><span id="more-1194"></span></p>
<p>In <strong>HTML5</strong> input element have got new attribute <strong>multiple. </strong>It allows to <strong>upload</strong> <strong>multiple</strong> <strong>files</strong> at once without using Flash based uploaders. This attribute receives one value "multiple" and looks like this:</p>
<pre>&lt;input type="file" multiple="multiple" name="files[]" /&gt;</pre>
<p>Pay attention to <em>name, </em>I specified it as an array to receive array of files in PHP script.</p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4139588230521520";
/* Intest */
google_ad_slot = "1267310946";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<p>Once there is the question, what kind of browser does not understand this html5 innovation, the answer is easily predicted, a family of Internet Explorer. Starting with version 9 and below, they do not support this functionality and simply ignore the attribute and sincerely hope that in the final 10 version, they are corrected.</p>
<p>Besides that, we gave the users to upload many files at once, we must take care of them and give them the opportunity to download just the files we need. And then comes to help another new attribute <strong>accept</strong>. Which takes the "<a href="http://www.iana.org/assignments/media-types/index.html">MIME Media Types</a>".</p>
<p><span style="font-family: monospace; font-size: 12px; line-height: 18px; white-space: pre;">&lt;input type="file" multiple="multiple" name="files[]" accept="image" /&gt;</span></p>
<div id="gt-res-content">
<p dir="ltr">This HTML5 code means that you can only upload images, and in the file chooser dialog filed are filtered and will show the user only image file types. Firefox and Safari ignores <strong>accept </strong>tag.</p>
<div dir="ltr">And again we have a problem, the user attempts to send the form, but he was so busy that forgot to fill in file input field . We should not give him a reason to be nervous in this situation. Use another new attribute. Attribute is <strong>required</strong>, takes a string «required», and makes the field mandatory.</div>
</div>
<pre><code>&lt;input type="file" multiple="multiple" name="files[]" accept="image" required="required" title="Please choose at least one file" /&gt;</code></pre>
<p>How will it work when you try to send the form with an empty input, a warning about an error with the following text:</p>
<h3><strong>Firefox html5 file uploads view</strong></h3>
<h3><strong> </strong><a href="http://a32.me/wp-content/uploads/2012/06/ff.png"><img class="alignnone size-full wp-image-1198" title="Firefox html5 file uploads view" src="http://a32.me/wp-content/uploads/2012/06/ff.png" alt="Firefox html5 file uploads view" width="400" height="177" /></a><br />
<strong>Chrome</strong><span class="Apple-style-span" style="font-size: 15px; font-weight: bold;"><strong> html5 file uploads view</strong></span></h3>
<p><strong> </strong><a href="http://a32.me/wp-content/uploads/2012/06/cr.png"><img class="alignnone size-full wp-image-1199" title="Chrome html5 file uploads view" src="http://a32.me/wp-content/uploads/2012/06/cr.png" alt="Chrome html5 file uploads view" width="400" height="229" /></a><br />
<strong> </strong></p>
<h3><strong>Opera</strong><strong> html5 file uploads view</strong></h3>
<p><strong><a href="http://a32.me/wp-content/uploads/2012/06/op.png"><img class="alignnone size-full wp-image-1200" title="Opera html5 file uploads view" src="http://a32.me/wp-content/uploads/2012/06/op.png" alt="Opera html5 file uploads view" width="443" height="141" /></a><br />
</strong></p>
<p>To my surprise, Safari did not show a warning and sent a blank form. The pictures above show how it looks in the three browsers, Chrome does not show a very pleasing look, but once he showed an addition to the errors that took the title of the item.</p>
<h3>Html5 file upload and javascript</h3>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4139588230521520";
/* Intest */
google_ad_slot = "1267310946";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<p>There are still several problems  to be solved for the convenience of the user.</p>
<ul>
<li>Check the file type</li>
<li>File sizes</li>
<li>Number of Files</li>
</ul>
<p>And we have a very simple way to check things out with JavaScript. In the <em>file</em> <em>input</em> element there is an invisible attribute "<strong>files"</strong>, when accessing it returns FilleList object</p>
<p><span style="font-family: monospace; font-size: 12px; line-height: 18px; white-space: pre;">var inputFile = document.getElementById('input').files;</span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">FileList <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
	<span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
	<span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>
	length<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
	<span style="color: #000066; font-weight: bold;">item</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Where 0,1,2 are keys of <em>uploading files</em>.<br />
Length, number of files<br />
Method item() returns file item object.</p>
<p>Refer to the file in two ways:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// First way</span>
<span style="color: #003366; font-weight: bold;">var</span> file <span style="color: #339933;">=</span> inputFile<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Second way</span>
<span style="color: #003366; font-weight: bold;">var</span> file <span style="color: #339933;">=</span> inputFile.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The variable file will contain a file object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">File <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
	constructor<span style="color: #339933;">:</span> File <span style="color: #009900;">&#123;</span>...<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	fileName<span style="color: #339933;">:</span> <span style="color: #3366CC;">'image.png'</span><span style="color: #339933;">,</span>
	fileSize<span style="color: #339933;">:</span> <span style="color: #CC0000;">879394</span><span style="color: #339933;">,</span>
	<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'image.png'</span><span style="color: #339933;">,</span>
	size<span style="color: #339933;">:</span> <span style="color: #CC0000;">879394</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'image/png'</span><span style="color: #339933;">,</span>
	getAsBinary<span style="color: #339933;">,</span>
	getAsDataURL<span style="color: #339933;">,</span>
	getAsText<span style="color: #339933;">,</span>
	lastModifiedDate<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Thu May 16 2011 00:01:34 GMT+0300 (Eastern Europe Daylight Time)'</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Opera has no properties fileSize, FileName but there is a name and size. In Chrome, Firefox, Safari has all four properties. Only in Chrome is the property of lastModifiedDate.</p>
<div id="gt-res-content">
<p>Lets look closer on three methods.</p>
<ul>
<li>getAsBinary: get the source  data of file</li>
<li>getAsDataURL: get the data converted to base64</li>
<li>getAsText: Returns the file's contents as a DOMString in which the file's data is interpreted as text using a given encoding</li>
</ul>
<p>Method getAsDataURL, a very useful thing, as an example it ispossible to show previews of files to be uploaded even before sending them to the server.</p>
<p>Using JavaScript for form validation gives wide possibilities to test  the file size, quantity and even up to the validation of pixels in the image.</p>
<p>Good resource for expolring other html5 details of input element is <a href="http://dev.w3.org/html5/spec/Overview.html#the-input-element" target="_blank">here</a></p>
</div>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F06%2Ffile-uploads-in-html5-whats-new%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/06/file-uploads-in-html5-whats-new/" data-text="File uploads in HTML5 – what’s new ?">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/06/file-uploads-in-html5-whats-new/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=File uploads in HTML5 – what’s new ?&amp;body=http://a32.me/2011/06/file-uploads-in-html5-whats-new/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/06/file-uploads-in-html5-whats-new/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Development in the Cloud</title>
		<link>http://a32.me/2011/04/php-development-in-the-cloud-recommended/</link>
		<comments>http://a32.me/2011/04/php-development-in-the-cloud-recommended/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 03:10:19 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[book]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=983</guid>
		<description><![CDATA[Nevertheless Amazon recent downtime showed us that clouds are not panacea for all problems, they are the future. Especially when quick scale, precise resource allocation is needed. This book is about  applying your PHP skills in a clouds. Most developers gloss over when they hear “the cloud” as the term has been appropriated by marketing types and has very [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://a32.me/wp-content/uploads/2011/04/PHPCloud-cover-small1.png"><img class="size-full wp-image-986 alignleft" title="PHPCloud-cover-small" src="http://a32.me/wp-content/uploads/2011/04/PHPCloud-cover-small1.png" alt="" width="109" height="134" /></a>Nevertheless Amazon recent downtime showed us that clouds are not panacea for all problems, they are the future. Especially when quick scale, precise resource allocation is needed.</p>
<p>This book is about  applying your PHP skills in a clouds.</p>
<p>Most developers gloss over when they hear “the cloud” as the term has been appropriated by marketing types and has very little true meaning anymore. In this book, Vito and Ivo strip bare the buzzwords and help PHP developers figure out what the cloud is actually about and how they can take advantage of what cloud computing has to offer. After reading this book, you will not only have a clear picture of what cloud computing is, but you’ll also be able to utilize the various cloud services that are out there.</p>
<p><span id="more-983"></span></p>
<p>Topics covered include:</p>
<ul>
<li>Cloud Computing primer (characteristics and models)</li>
<li>Cloud Basics (prerequisites and programming)</li>
<li>Cloud Architecture (horizontal scalability, preventing bottlenecks, abstraction, multi-tenancy)</li>
<li>Working with Popular Cloud Infrastructures (Amazon, Rackspace, Azure)</li>
<li>Working with Popular Cloud Platforms (Google, Rackspace, and others)</li>
<li>Working with Popular Cloud Software and Services (OpenID, OAuth, Search, Payments, CRMs, Maps, Storage)</li>
</ul>
<p><a title="Buy on Amazon" href="http://www.amazon.com/PHP-Development-Cloud-Ivo-Jansch/dp/0981034527/ref=sr_1_1?ie=UTF8&amp;qid=1303960398&amp;sr=8-1" target="_blank">Buy on Amazon</a></p>
<p>ISBN	 9780981034522<br />
Pages	 172<br />
Authors	 Ivo Jansch	 Vito Chin<br />
Print	 $39.99<br />
PDF-only	 $36.99</p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F04%2Fphp-development-in-the-cloud-recommended%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/04/php-development-in-the-cloud-recommended/" data-text="PHP Development in the Cloud">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/04/php-development-in-the-cloud-recommended/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=PHP Development in the Cloud&amp;body=http://a32.me/2011/04/php-development-in-the-cloud-recommended/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/04/php-development-in-the-cloud-recommended/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenID login for Yahoo and Google accounts</title>
		<link>http://a32.me/2011/04/openid-login-for-yahoo-and-google-accounts/</link>
		<comments>http://a32.me/2011/04/openid-login-for-yahoo-and-google-accounts/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 15:25:04 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=939</guid>
		<description><![CDATA[I've updated my Openid sample code for logging in  with Yahoo and normal Google accounts. OpenID is an open standard that describes how users can be authenticated in a decentralized manner, obviating the need for services to provide their own ad hoc systems and allowing users to consolidate their digital identities The OpenID protocol does [...]]]></description>
			<content:encoded><![CDATA[<p>I've updated my Openid sample code for logging in  with Yahoo and normal Google accounts.</p>
<p><span id="more-939"></span></p>
<p>OpenID is an open standard that describes how users can be authenticated in a decentralized manner, obviating the need for services to provide their own ad hoc systems and allowing users to consolidate their digital identities</p>
<p>The OpenID protocol does not rely on a central authority to authenticate a user's identity. Moreover, neither services nor the OpenID standard may mandate a specific means by which to authenticate users, allowing for approaches ranging from the common (such as passwords) to the novel (such as smart cards or biometrics).</p>
<p><a href="http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/" target="_self">See original article here for DOWNLOADS and DEMO</a></p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F04%2Fopenid-login-for-yahoo-and-google-accounts%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/04/openid-login-for-yahoo-and-google-accounts/" data-text="OpenID login for Yahoo and Google accounts">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/04/openid-login-for-yahoo-and-google-accounts/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=OpenID login for Yahoo and Google accounts&amp;body=http://a32.me/2011/04/openid-login-for-yahoo-and-google-accounts/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/04/openid-login-for-yahoo-and-google-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Apps as single authentication point for your corporate applications</title>
		<link>http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/</link>
		<comments>http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 08:34:55 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[I|T]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=789</guid>
		<description><![CDATA[This is an update to my post "Google Apps Premier federated login with PHP". Idea is simple, users do not like passwords, less passwords - less pain and more security. Nowadays many companies have gone cloud, which covers most needs, but leaves space for homegrown small applications, ideas, prototypes, etc. It is convenient to organize user login into these applications [...]]]></description>
			<content:encoded><![CDATA[<p>This is an update to my post "<a href="http://a32.me/2010/02/google-apps-premier-federated-login-with-php/" target="_self">Google Apps Premier federated login with PHP</a>". Idea is simple, users do not like passwords, less passwords - less pain and more security.</p>
<p>Nowadays many companies have gone cloud, which covers most needs, but leaves space for homegrown small applications, ideas, prototypes, etc. It is convenient to organize user login into these applications using already existing Google Apps login infrastructure.</p>
<p>This is about using it with PHP.</p>
<p><span id="more-789"></span><script type="text/javascript"><!--
google_ad_client = "ca-pub-4139588230521520";
/* Intest */
google_ad_slot = "1267310946";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<p>Since previous post, I've updated PHP library used to the latest versions and tested them again. Also I rewrite bundled example to work in more transparent way and made it more clear.</p>
<h3>Libraries version</h3>
<p>php-openid-apps-discover-1.0.2.zip<br />
openid-php-openid-2.2.2-0-ga287b2d.zip</p>
<h3>Online demo</h3>
<p><a href="http://a32.me/other/ga-open-id/">http://a32.me/other/ga-open-id/</a></p>
<h3>Downloads</h3>
<p><a href="http://a32.me/other/ga-open-id.tar.gz" target="_self">All-in-one-pack</a> includes libraries and example</p>
<h3>Installation</h3>
<p>Unpack, make sure make <strong>TMP folder with sub-folders are writable.</strong></p>
<h3>Example code</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * @date Created on Feb 22, 2011
 * @author		Constantin Bosneaga &lt;ameoba32@gmail.com&gt;
 * 
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Include files</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;Auth/OpenID/Consumer.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;Auth/OpenID/AX.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;Auth/OpenID/google_discovery.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;Auth/OpenID/FileStore.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;Auth/OpenID/SReg.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;Auth/OpenID/PAPE.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Init login</span>
<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</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;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;tmp&quot;</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;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Temp path '</span><span style="color: #339933;">.</span><span style="color: #000088;">$tmp</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' does not exists'</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_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Temp path '</span><span style="color: #339933;">.</span><span style="color: #000088;">$tmp</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' is not writable'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Return URL</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'return_server'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTPS&quot;</span><span style="color: #009900;">&#93;</span>?<span style="color: #0000ff;">'https://'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'http://'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_PORT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'return_url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'return_server'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;?module=return&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Cache for google discovery (much faster)</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cache'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FileCache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Open id lib has many warnig and notices</span>
<span style="color: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ALL</span> ^ <span style="color: #009900; font-weight: bold;">E_NOTICE</span> ^ <span style="color: #009900; font-weight: bold;">E_WARNING</span> ^ <span style="color: #009900; font-weight: bold;">E_USER_NOTICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$module</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span>?<span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Login form
	 * 
	 * 
	 */</span>	
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">:</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;h1&gt;Login with Google Apps&lt;/h1&gt;
	&lt;form method=&quot;POST&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;module&quot; value=&quot;login&quot;&gt;
	Your Google Apps domain:
	&lt;input type=&quot;text&quot; name=&quot;domain&quot; value=&quot;&quot;&gt;
	&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Login&quot;&gt;
	&lt;/form&gt;	
&nbsp;
	&lt;h1&gt;Login with Google&lt;/h1&gt;
	&lt;form method=&quot;POST&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;module&quot; value=&quot;login&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;domain&quot; value=&quot;https://www.google.com/accounts/o8/id&quot;&gt;
	&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Login&quot;&gt;
	&lt;/form&gt;
&nbsp;
	&lt;h1&gt;Login with Yahoo&lt;/h1&gt;
	&lt;form method=&quot;POST&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;module&quot; value=&quot;login&quot;&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;domain&quot; value=&quot;http://me.yahoo.com&quot;&gt;
	&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Login&quot;&gt;
	&lt;/form&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?</span>	
	<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>	
&nbsp;
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Process login 
	 */</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'login'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$store</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Auth_OpenID_FileStore<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$consumer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Auth_OpenID_Consumer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">new</span> GApps_OpenID_Discovery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consumer</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cache'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		try <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$auth_request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$consumer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'domain'</span><span style="color: #009900;">&#93;</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_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$auth_request</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Auth request object error. Try again'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">/// Request additional parameters</span>
		<span style="color: #000088;">$ax</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Auth_OpenID_AX_FetchRequest<span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/contact/email'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/namePerson/first'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'firstname'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/namePerson/last'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'lastname'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/namePerson/friendly'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'friendly'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/namePerson'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fullname'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/birthDate'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'dob'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/person/gender'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'gender'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/contact/postalCode/home'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'postcode'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/contact/country/home'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'country'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/pref/language'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'language'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> Auth_OpenID_AX_AttrInfo<span style="color: #339933;">::</span><span style="color: #004000;">make</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://axschema.org/pref/timezone'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'timezone'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$auth_request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addExtension</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ax</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Request URL for auth dialog url </span>
		<span style="color: #000088;">$redirect_url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$auth_request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirectURL</span><span style="color: #009900;">&#40;</span>
			<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'return_server'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'return_url'</span><span style="color: #009900;">&#93;</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>Auth_OpenID<span style="color: #339933;">::</span><span style="color: #004000;">isFailure</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirect_url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not redirect to server: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$redirect_url</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$redirect_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	
	<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Return URL, google redirects here after login
	 */</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'return'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$store</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Auth_OpenID_FileStore<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$consumer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Auth_OpenID_Consumer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">new</span> GApps_OpenID_Discovery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consumer</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cache'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$consumer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">complete</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'return_url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Check the response status.</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span> <span style="color: #339933;">==</span> Auth_OpenID_CANCEL<span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Verification cancelled.'</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: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span> <span style="color: #339933;">==</span> Auth_OpenID_FAILURE<span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OpenID authentication failed: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</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: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span> <span style="color: #339933;">!=</span> Auth_OpenID_SUCCESS<span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Other error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Successful login</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Extract returned information</span>
		<span style="color: #000088;">$openid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDisplayIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ax</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Auth_OpenID_AX_FetchResponse<span style="color: #009900;">&#40;</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: #000088;">$ax</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ax</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fromSuccessResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$sreg</span> <span style="color: #339933;">=</span> Auth_OpenID_SRegResponse<span style="color: #339933;">::</span><span style="color: #004000;">fromSuccessResponse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</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: #000088;">$sreg</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$sreg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sreg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contents</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;"># print response
</span>		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;h1&gt;OK&lt;/h1&gt;
		You have successfully verified &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$openid</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$openid</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt; as your identity.&lt;br/&gt;&lt;br/&gt;
		&lt;p&gt;The following AX response received:&lt;/p&gt;
		&lt;pre&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #990000;">nl2br</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/pre&gt;
&nbsp;
		&lt;p&gt;The following sreg response received:&lt;/p&gt;
		&lt;pre&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #990000;">nl2br</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sreg</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/pre&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?</span>
	<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> FileCache <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$cache_file</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp_path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cache_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp_path</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;google.tmp&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$cache</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cache</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cache_file</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre></div></div>


				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2011%2F03%2Fgoogle-apps-as-single-authentication-point-for-your-corporate-applications%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/" data-text="Google Apps as single authentication point for your corporate applications">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=Google Apps as single authentication point for your corporate applications&amp;body=http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2011/03/google-apps-as-single-authentication-point-for-your-corporate-applications/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>PHP Closing tag ?&gt;</title>
		<link>http://a32.me/2010/12/php-closing-tag/</link>
		<comments>http://a32.me/2010/12/php-closing-tag/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 17:58:42 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=665</guid>
		<description><![CDATA[Sometime ago I saw some framework where all files missed PHP closing tags, I wondered why ? Simply, this tag is not required by PHP parser, interesting when this was introduced. But one advantage of this is elimination of hunting down final carriage return character in the end file. This additional CR mess up the output when including. In [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime ago I saw some framework where all files missed PHP closing tags, I wondered why ? Simply, this tag is not required by PHP parser, interesting when this was introduced. But one advantage of this is elimination of hunting down final carriage return character in the end file. This additional CR mess up the output when including.</p>
<p>In projects with 200+ code files, one simple return at the end of file can cause bugs hard to find.</p>
<p><span id="more-665"></span><strong>UPD:</strong> My discovery is clearly described in documentation <img src='http://a32.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a rel="nofollow" href="http://php.net/manual/en/language.basic-syntax.instruction-separation.php">http://php.net/manual/en/language.basic-syntax.instruction-separation.php</a></p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2010%2F12%2Fphp-closing-tag%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2010/12/php-closing-tag/" data-text="PHP Closing tag ?>">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2010/12/php-closing-tag/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=PHP Closing tag ?>&amp;body=http://a32.me/2010/12/php-closing-tag/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2010/12/php-closing-tag/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Publish PHP Code on the web &#8211; Highlight.js</title>
		<link>http://a32.me/2010/09/publish-php-code-on-the-web-highlight-js/</link>
		<comments>http://a32.me/2010/09/publish-php-code-on-the-web-highlight-js/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 20:00:27 +0000</pubDate>
		<dc:creator>Constantin Bosneaga</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://a32.me/?p=602</guid>
		<description><![CDATA[It is often required to publish some code snippets in the blog on PHP or other popular languages like Python, Ruby... Here is simple way to do this.. Use nice JavaScript code formatting library. Just enter program text in &#60;pre&#62;&#60;code&#62;&#60;/code&#62;&#60;/pre&#62; tags in any part of post, include CSS and library and voila: require_once 'Zend.php'; require_once [...]]]></description>
			<content:encoded><![CDATA[<p>It is often required to publish some code snippets in the blog on PHP or other popular languages like Python, Ruby... Here is simple way to do this..</p>
<p><span id="more-602"></span>Use nice JavaScript code formatting library. Just enter program text in &lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt; tags in any part of post, include CSS and library and voila:</p>
<pre><code>require_once 'Zend.php';
require_once 'Zend/Uri/Exception.php';
require_once 'Zend/Uri/Http.php';
require_once 'Zend/Uri/Mailto.php';

abstract class Zend_Uri
{

  /**
   * Return a string representation of this URI.
   *
   * @see     getUri()
   * @return  string
   */
  public function __toString()
  {
      return $this-&gt;getUri();
  }

  static public function factory($uri = 'http')
  {
      $uri = explode(':', $uri, 2);
      $scheme = strtolower($uri[0]);
      $schemeSpecific = isset($uri[1]) ? $uri[1] : '';

      // Security check: $scheme is used to load a class file,
      // so only alphanumerics are allowed.
      if (!ctype_alnum($scheme)) {
          throw new Zend_Uri_Exception('Illegal scheme');
      }
  }
}
</code></pre>
<p><script src="http://yandex.st/highlightjs/5.12/highlight.min.js"></script></p>
<link rel="stylesheet" href="http://yandex.st/highlightjs/5.12/styles/default.min.css">
<link rel="stylesheet" href="http://yandex.st/highlightjs/5.12/styles/vs.min.css">
<script>
  hljs.initHighlightingOnLoad();
</script></p>
<p>This code should be appended into HTML:</p>
<pre>&lt;script src="http://yandex.st/highlightjs/5.12/highlight.min.js"&gt;&lt;/script&gt;</pre>
<div>
<pre>&lt;link rel="stylesheet" href="http://yandex.st/highlightjs/5.12/styles/default.min.css"&gt;</pre>
<pre>&lt;link rel="stylesheet" href="http://yandex.st/highlightjs/5.12/styles/vs.min.css"&gt;</pre>
<pre>&lt;script&gt;</pre>
<pre>  hljs.initHighlightingOnLoad();</pre>
<pre>&lt;/script&gt;</pre>
</div>
<p>Library itself is available through Yandex content distribution network(CDN), so no installation is needed.</p>
<p>Links</p>
<ul>
<li><a href="http://softwaremaniacs.org/media/soft/highlight/test.html" target="_blank">Test page with more themes</a></li>
<li><a href="http://softwaremaniacs.org/soft/highlight/en/" target="_blank">Official library page</a></li>
</ul>
<p>Thanks to Ivan Sagalaev.</p>

				<div class="mr_social_sharing_wrapper">
				<!-- Social Sharing Toolkit v2.0.8 | http://www.active-bits.nl/support/social-sharing-toolkit/ --><span class="mr_social_sharing"><iframe src="https://www.facebook.com/plugins/like.php?locale=en_US&amp;href=http%3A%2F%2Fa32.me%2F2010%2F09%2Fpublish-php-code-on-the-web-highlight-js%2F&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></span><span class="mr_social_sharing"><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="http://a32.me/2010/09/publish-php-code-on-the-web-highlight-js/" data-text="Publish PHP Code on the web – Highlight.js">Tweet</a></span><span class="mr_social_sharing"><script type="IN/Share" data-url="http://a32.me/2010/09/publish-php-code-on-the-web-highlight-js/"></script></span><span class="mr_social_sharing"><a href="mailto:?subject=Publish PHP Code on the web – Highlight.js&amp;body=http://a32.me/2010/09/publish-php-code-on-the-web-highlight-js/"><img src="http://a32.me/wp-content/plugins/social-sharing-toolkit/images/buttons/email.png" alt="Share via email" title="Share via email"/></a></span></div>]]></content:encoded>
			<wfw:commentRss>http://a32.me/2010/09/publish-php-code-on-the-web-highlight-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

