<?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>Web Development Blog &#187; API</title>
	<atom:link href="http://www.leigeber.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leigeber.com</link>
	<description>This web development blog features fresh articles on JavaScript, AJAX, CSS, XHTML, PHP, Photoshop and more.</description>
	<lastBuildDate>Sat, 13 Feb 2010 02:05:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Custom Digg Counter in WordPress with PHP</title>
		<link>http://www.leigeber.com/2008/04/custom-digg-counter-in-wordpress-with-php/</link>
		<comments>http://www.leigeber.com/2008/04/custom-digg-counter-in-wordpress-with-php/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 21:08:55 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[digg]]></category>

		<guid isPermaLink="false">http://www.leigeber.com/?p=14</guid>
		<description><![CDATA[This tutorial shows how to create a custom Digg counter using the Digg API and PHP in WordPress.]]></description>
			<content:encoded><![CDATA[<p>You will notice in the lower right corner of this entry that there is a reference to the number of Diggs for this post. If you click the counter you are taken to Digg. Digg does offer a few easily integrable scripts at <a href="http://digg.com/tools/integrate" target="_blank">http://digg.com/tools/integrate</a> but does not document how to create a custom counter. To accomplish this you need to use the Digg API which is very easy to work with. There is no registration and your access key is simply the source domain. This example is customized for WordPress but can easily be modified to work in any PHP based project.</p>
<p>Here is the PHP function to grab the number of Diggs from the Digg API.</p>
<p><code>function getDiggs($url) {<br />
  $sturl = 'http://services.digg.com/stories?link='.$url.'&#038;appkey=<br />
http%3A%2F%2Fwww.yourdomain.com&#038;count=1';<br />
  $ch = curl_init($sturl);<br />
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);<br />
  curl_setopt($ch,CURLOPT_USERAGENT,"www.yourdomain.com");<br />
  curl_setopt($ch,CURLOPT_TIMEOUT,10);<br />
  $res = curl_exec($ch);<br />
  $resinfo = curl_getinfo($ch);<br />
  curl_close($ch);<br />
  if($resinfo['http_code'] === 200) {<br />
    preg_match('/diggs\="([0-9]+)"/si', $res, $r);<br />
    $diggs = number_format(($r[1]) ? str_replace(',', '', $r[1]) : '0');<br />
    if($diggs == 1) {<br />
      $response = $diggs .' Digg';<br />
    } else {<br />
      $response = $diggs .' Diggs';<br />
    }<br />
  } else {<br />
    $response = 'Error';<br />
  }<br />
  echo $response;<br />
}</code></p>
<p>If you plan on displaying your Diggs on multiple pages create a folder in your theme directory and include the file with the following&#8230;</p>
<p><code>&lt;?php include(TEMPLATEPATH .'/folder/script.php'); ?></code></p>
<p>Setup the variables to build the Digg link and the URL to pass to the PHP function. This will use the current post URL in a loop or on a standalone page so there is nothing to hardcode.</p>
<p><code>$diggurl = urlencode(get_permalink($post->ID));<br />
$diggtitle = urlencode(get_the_title($post->post_parent));<br />
$digglink = 'http://digg.com/submit?url='.$diggurl.'&amp;title='.$diggtitle;<br />
</code></p>
<p>Finally add the link, in my case I have positioned the reference in the bottom right of the post and added a bubble comment background to the link with CSS. In the href I am passing the encoded link and the encoded title to Digg. You can also pass through the media type, description, and topic if you want. <a href="http://digg.com/tools/integrate#3" target="_blank">Click here</a> for details.</p>
<p><code>&lt;a href="&lt;?php echo $digglink ?>" class="diggticker">&lt;?php getDiggs($diggurl); ?>&lt;/a></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leigeber.com/2008/04/custom-digg-counter-in-wordpress-with-php/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Mapping Using the Google Maps API &amp; PHP</title>
		<link>http://www.leigeber.com/2008/04/map-your-users-using-the-google-maps-api-and-php/</link>
		<comments>http://www.leigeber.com/2008/04/map-your-users-using-the-google-maps-api-and-php/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 21:23:51 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.leigeber.com/?p=11</guid>
		<description><![CDATA[Using a combination of a couple APIs, PHP and Curl you can easily incorporate maps into your website that fairly accurately identify a visitor’s location. This tutorial breaks down the core elements of creating a dynamic Google map.]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://sandbox.leigeber.com/google_maps_api.php" width="453" height="278" scrolling="no" frameborder="1" style="border:2px solid #bfc79f; padding:1px" name="map_example"></iframe></p>
<p>Using a combination of a couple APIs, PHP and Curl you can easily incorporate maps into your website that fairly accurately identify a visitor&#8217;s location. Knowing a users location and further being able to map the location has many practical applications. I am going to breakdown the core elements of creating a map just like the one above. I plan on following up soon with more advanced Google Maps examples.</p>
<p>You will need the users&#8217; address to begin. If you run a site that collects that information during registration it can be used for mapping otherwise you can get the users city, state and country by grabbing their IP address and then calling one of the available geocoding APIs available.</p>
<p><strong>Grab the users IP address.</strong><br />
<code>$ip = $_SERVER['REMOTE_ADDR'];</code></p>
<p><strong>Get the users City, State and Country.</strong><br />
<code>$sturl = 'http://api.hostip.info/get_html.php?ip='.$ip;<br />
$ch = curl_init($sturl);<br />
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);<br />
curl_setopt($ch,CURLOPT_TIMEOUT,10);<br />
$res = curl_exec($ch);<br />
$resinfo = curl_getinfo($ch);<br />
curl_close($ch);<br />
preg_match('/City: ([a-zA-Z].+[a-zA-Z]+)/', $res, $r);<br />
preg_match('/ \(([A-Z][A-Z])/', $res, $s);<br />
$city = $r[1];<br />
$country = $s[1];<br />
</code></p>
<p>The above API at <a href="http://hostip.info/" target="_blank">http://hostip.info/</a> can also return the latitude and longitude which is needed to map the location however for the purposes of this demo I am using the Google geo locator API. You will also need a Google Maps API key which can be requested from http://code.google.com/apis/maps/index.html. </p>
<p><strong>Call the Google API to get the latitude and longitude.</strong><br />
<code>$key = "Your Google Maps API Key";<br />
$address = urlencode($city.", ".$country);<br />
$sturl = 'http://maps.google.com/maps/geo?q=' . $address . '&#038;output=csv&#038;key=' . $key;<br />
$ch = curl_init($sturl);<br />
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);<br />
curl_setopt($ch,CURLOPT_TIMEOUT,10);<br />
$res = curl_exec($ch);<br />
$resinfo = curl_getinfo($ch);<br />
curl_close($ch);<br />
$res = explode(",",$res);<br />
$latitude = $res[2];<br />
$longitude = $res[3];<br />
</code></p>
<p><strong>Insert an image tag with the following SRC referencing Google&#8217;s API.</strong><br />
<code>http://maps.google.com/staticmap?key=' . $key . '&#038;size=506x280&#038;markers=' . $latitude . ',' . $longitude . '&#038;zoom=3<br />
</code></p>
<p>This is just the tip of the iceberg. For more details on the API visit the Google documentation at <a href="http://code.google.com/apis/maps/documentation/" target="_blank">http://code.google.com/apis/maps/documentation/</a>.</p>
<p><strong><a href='http://www.leigeber.com/wp-content/uploads/2008/04/google_maps_api.zip'>Click here</a> to download the PHP source code.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leigeber.com/2008/04/map-your-users-using-the-google-maps-api-and-php/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
