<?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>{5} Setfive - Talking to the World &#187; php code</title>
	<atom:link href="http://shout.setfive.com/tag/php-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://shout.setfive.com</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jul 2010 19:09:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Google Calender embed missing events</title>
		<link>http://shout.setfive.com/2009/08/04/google-calender-embed-missing-events/</link>
		<comments>http://shout.setfive.com/2009/08/04/google-calender-embed-missing-events/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 18:14:16 +0000</pubDate>
		<dc:creator>Ashish Datta</dc:creator>
				<category><![CDATA[Free Advice]]></category>
		<category><![CDATA[dumb]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php code]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=230</guid>
		<description><![CDATA[So we decided to use the Google Calendar API in one of our applications to allow users to easily view and export events from outside the app. In general, the API was working well &#8211; I was using the Zend library to interact with Google and things seemed fine. That was until I tried to [...]]]></description>
			<content:encoded><![CDATA[<p>So we decided to use the Google Calendar API in one of our applications to allow users to easily view and export events from outside the app. In general, the API was working well &#8211; I was using the Zend library to interact with Google and things seemed fine.</p>
<p>That was until I tried to embed the calendar using Google&#8217;s iframe embed code. For some reason, events weren&#8217;t showing up in the embeded iframe calendar even though they were showing up in the actual calendar on calendar.google.com. Even stranger, the events were present in a JSON object on the embeded page and they were showing up in the RSS feed for the calendar.</p>
<p>After literally days of debugging and experimenting I finally found out the culprit.</p>
<p>For some reason, events created via the API that start and end at exactly the same time &#8211; say a start date of 08-05-2009 10:00:00 and an end date of 08-05-2009 10:00:00 don&#8217;t render on the embeded iframe calendar.</p>
<p>What is even more bizarre is that if you create an event via the web interface that starts and ends at the same time, it will render correctly on an embeded calendar.</p>
<p>Anyway, that was weird. All the events without explicit start and end times now last a grand total of one minute.</p>
<p>PS. Kudos to Daum for finding a constant for PHP&#8217;s date() function to generate RFC3339 timestamps.</p>
<p>Use like so:</p>
<pre class="php" name="code">
  $date = date(DATE_RFC3339, $timestamp);
</pre>
<p>To get back a valid RFC3339 for the Google Calendar API. </p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2009/08/04/google-calender-embed-missing-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FOSS Fridays: OpenSSL in PHP</title>
		<link>http://shout.setfive.com/2009/07/31/foss-fridays-openssl-in-php/</link>
		<comments>http://shout.setfive.com/2009/07/31/foss-fridays-openssl-in-php/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 21:14:48 +0000</pubDate>
		<dc:creator>Ashish Datta</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php code]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=202</guid>
		<description><![CDATA[Well Twitter has “Follow Fridays” so I thought we should do FOSS Fridays. I don’t really have a plan for this and it might not last but let’s see where it goes. In the last few days a couple of people have asked for tips on how to use OpenSSL from PHP. So here is [...]]]></description>
			<content:encoded><![CDATA[<p>Well Twitter has “Follow Fridays” so I thought we should do FOSS Fridays. I don’t really have a plan for this and it might not last but let’s see where it goes.</p>
<p>In the last few days a couple of people have asked for tips on how to use OpenSSL from PHP. So here is a snippet on how to do it. This comes out of an application that provides a shared authentication system between our client’s LDAP system and their partner’s systems.</p>
<p>It works like so:</p>
<ol>
<li>Users login to the application using their LDAP credentials.</li>
<li>When the users request to visit the partner site, our system packages up their login information, encrypts it, signs it, and shoots it along with the user to the partner site.</li>
<li>Next, the partner checks if the user has an account and if they do it logs them in. Otherwise, it creates them a new account and logs them in.</li>
</ol>
<p>All of this is done transparently so that the user doesn’t know they’ve actually left the original site.</p>
<p>Here is the code to do it. PS. it’s from a Symfony application.</p>
<pre class="php" name="code">
$user = $this-&gt;getUser();

$profile = $user-&gt;getProfile();

if(is_null($profile)){ die("Could not get user profile?"); }

$email = $profile-&gt;getEmail();

$firstName = $profile-&gt;getFirstName();

$lastName = $profile-&gt;getLastName();

$password = $request-&gt;getParameter("password");

$keyText = file_get_contents(sfConfig::get("sf_root_dir") . "/" . sfConfig::get("app_their_public_key"));

$theirPublicKey = openssl_pkey_get_public($keyText);

$keyText = file_get_contents(sfConfig::get("sf_root_dir") . "/" . sfConfig::get("app_our_private_key"));

$outPrivateKey = openssl_pkey_get_private($keyText);

$arr = array();

$arr["U_EMAIL"] = $email;

$arr["U_PASSWORD"] = $password;

$arr["U_FIRST_NAME"] = $firstName;

$arr["U_LAST_NAME"] = $lastName;

$arr["RL_E"] = $this-&gt;generateUrl("ps_error", array(), true);

$arr["RL_S"] = "PRIVATE URL";

$arr["ETIME"] = time() + 60;

$queryString = http_build_query($arr);

$res = openssl_sign($queryString, $signature, $outPrivateKey);

if(!$res){ throw new sfException("Could not sign the payload!", 1); }

$t = openssl_pkey_get_details($theirPublicKey);

$t = (int) ($t['bits'] / 8 ) - 11;

$l=strlen($queryString);

$cryptPayload = '';

for ($i=0; $i&lt;$l; $i+= $t) {

  $block = substr($queryString, $i, $t);

  if (!openssl_public_encrypt($block,$tS, $theirPublicKey)){
    throw new sfException('failed encrypt', 1);
   }

  $cryptPayload .= $tS;
}

$this-&gt;encodedSignature = base64_encode($signature);

$this-&gt;encodedData = base64_encode($cryptPayload);
</pre>
<p>The net result of all of this is an encrypted payload with the user’s credentials and a signature of the payload. The payload is encrypted with “their” public key and then signed with “our” private key. This ensures that only they can open the package and only we can generate valid signatures.</p>
<p>Happy Friday! </p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2009/07/31/foss-fridays-openssl-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yahoo BOSS is sahweet!</title>
		<link>http://shout.setfive.com/2008/08/13/yahoo-boss-is-sahweet/</link>
		<comments>http://shout.setfive.com/2008/08/13/yahoo-boss-is-sahweet/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 04:14:44 +0000</pubDate>
		<dc:creator>Ashish Datta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php code]]></category>
		<category><![CDATA[wikia search]]></category>
		<category><![CDATA[yahoo boss]]></category>

		<guid isPermaLink="false">http://shout.setfive.com/?p=10</guid>
		<description><![CDATA[A couple of weeks ago I ran across this article on Techcrunch. Basically, a Yahoo! engineer used Yahoo Boss! and the Google App engine to make a &#8220;who,what,where,when&#8221; answering service. Since I want one I took a look at the code, but since its on the GAE the code is in Python for the GAE. [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I ran across <a href="http://www.techcrunch.com/2008/08/04/yahoo-boss-is-so-open-it-runs-on-googles-app-engine/" target="_blank">this article</a> on Techcrunch.</p>
<p>Basically, a <a href="http://zooie.wordpress.com/2008/08/04/yahoo-boss-google-app-engine-integrated/" target="_blank">Yahoo! engineer</a> used Yahoo Boss! and the <a href="http://code.google.com/appengine/" target="_blank">Google App engine</a> to make a &#8220;who,what,where,when&#8221; <a href="http://bossy.appspot.com/" target="_blank">answering service</a>. Since I want one I took a look at the code, but since its on the GAE the code is in Python for the GAE.</p>
<p>Anyway, since its like 50 lines of code I decided to take a look at BOSS and port it over to PHP. The quick and dirty PHP clocks in at 200 lines and is available for <a href="http://code.setfive.com/wikialabs/boss.php?q=when%20was%20the%20challenger%20disaster&amp;c=render" target="_blank">testing</a>. The PHP returns JSON code with an optional callback specified with c=</p>
<p>Feel free to use it for whatever &#8211; just play nice</p>
<p style="text-align: left;">It might even make it into a super secret <a href="http://fp029.sjc.wikia-inc.com/search/search.html#when%20did%20the%20titanic%20sink" target="_blank">Wikia framework</a>!</p>
<p style="text-align: left;">Code is available <a href="http://code.setfive.com/wikialabs/boss.code.php" target="_blank">here</a>.</p>
<p style="text-align: left;">Vik does a really good job of explaining how the <a href="http://zooie.wordpress.com/2008/08/04/yahoo-boss-google-app-engine-integrated/" target="_blank">process works</a>. Unfortunately, its not particularly consistent or accurate. But it is pretty neat and considering its only 200 lines a good demonstration of thinking outside the box.</p>
]]></content:encoded>
			<wfw:commentRss>http://shout.setfive.com/2008/08/13/yahoo-boss-is-sahweet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
