<?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>jamiedavi.es</title>
	<atom:link href="http://jamiedavi.es/feed" rel="self" type="application/rss+xml" />
	<link>http://jamiedavi.es</link>
	<description>living life in the cloud</description>
	<lastBuildDate>Wed, 08 Apr 2009 16:42:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SlideShare API without url_file_open</title>
		<link>http://jamiedavi.es/slideshare-api-without-url_file_open-17.php</link>
		<comments>http://jamiedavi.es/slideshare-api-without-url_file_open-17.php#comments</comments>
		<pubDate>Sat, 24 Jan 2009 21:36:35 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Coding & Projects]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jamiedavi.es/?p=17</guid>
		<description><![CDATA[Recently while writing some code that utilised the SlideShare API I found myself on a server which had url_file_open turned off in the php.ini and this couldn&#8217;t be over-rode with a .htaccess file either. So I had to re-write the code which used file_get_contents using the cURL library.
I needed to replace the get_data function within [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Recently while writing some code that utilised the <a href="http://www.slideshare.net/developers">SlideShare API</a> I found myself on a server which had url_file_open turned off in the php.ini and this couldn&#8217;t be over-rode with a .htaccess file either. So I had to re-write the code which used <a href="http://uk.php.net/file_get_contents">file_get_contents</a> using the <a href="http://curl.haxx.se/">cURL</a> library.</p>
<p>I needed to replace the get_data function within the SSUtil.php file (part of the <a href="http://code.google.com/p/slideshare-phpkit/">SlideShare PHP kit</a>). Initially it looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> get_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$call</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ts</span><span style="color: #339933;">=</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$hash</span><span style="color: #339933;">=</span><span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">secret</span><span style="color: #339933;">.</span><span style="color: #000088;">$ts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	try <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$res</span><span style="color: #339933;">=</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;">apiurl</span><span style="color: #339933;">.</span><span style="color: #000088;">$call</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;?api_key=<span style="color: #006699; font-weight: bold;">$this-&gt;key</span>&amp;ts=<span style="color: #006699; font-weight: bold;">$ts</span>&amp;hash=<span style="color: #006699; font-weight: bold;">$hash</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$params</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;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Log the exception and return $res as blank</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Following some time spent with google and a bit or trial-and-error I came up with this which seems to work in its place:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> get_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$call</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$timeout</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ts</span><span style="color: #339933;">=</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$hash</span><span style="color: #339933;">=</span><span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">secret</span><span style="color: #339933;">.</span><span style="color: #000088;">$ts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;"># use CURL library to fetch remote file
</span>	try <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">apiurl</span><span style="color: #339933;">.</span><span style="color: #000088;">$call</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;?api_key=<span style="color: #006699; font-weight: bold;">$this-&gt;key</span>&amp;ts=<span style="color: #006699; font-weight: bold;">$ts</span>&amp;hash=<span style="color: #006699; font-weight: bold;">$hash</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$params</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file_contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file_contents</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Log the exception and return $res as blank</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, for any other unlucky souls who find themselves on a server which doesn&#8217;t support url_file_open then there you are. </p>
]]></content:encoded>
			<wfw:commentRss>http://jamiedavi.es/slideshare-api-without-url_file_open-17.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Difficult First Post &#8230;</title>
		<link>http://jamiedavi.es/the-difficult-first-post-3.php</link>
		<comments>http://jamiedavi.es/the-difficult-first-post-3.php#comments</comments>
		<pubDate>Sat, 24 Jan 2009 20:15:14 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Jamie's Mind]]></category>
		<category><![CDATA[that]]></category>
		<category><![CDATA[this]]></category>
		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://jamiedavi.es/?p=3</guid>
		<description><![CDATA[
Well I hope not. This isn&#8217;t the first &#8216;Difficult First Post&#8216; I&#8217;ve made but at least then I knew where I wanted to take the site. Anyway. A place for my thoughts and musings on what I&#8217;m up to in the world of Psychology, teaching, writing or coding.
]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="size-full wp-image-5 alignleft" title="301040817-4a23ef3abb-tm" src="http://jamiedavi.es/wp-content/uploads/2009/01/301040817-4a23ef3abb-tm.jpg" alt="301040817-4a23ef3abb-tm" width="512" height="60" /></p>
<p>Well I hope not. This isn&#8217;t the first &#8216;<a href="http://www.psychblog.co.uk/the-difficult-first-post-16.html">Difficult First Post</a>&#8216; I&#8217;ve made but at least then I knew where I wanted to take the site. Anyway. A place for my thoughts and musings on what I&#8217;m up to in the world of Psychology, teaching, writing or coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamiedavi.es/the-difficult-first-post-3.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
