Return to Snippet

Revision: 31189
at September 1, 2010 00:34 by ichnoweb


Updated Code
<?php
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,"http://demo.tumblr.com/api/read/json");
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	$result = curl_exec($ch);
	curl_close($ch);
	
	$result = str_replace("var tumblr_api_read = ","",$result);
	$result = str_replace(';','',$result);
	$result = str_replace('\u00a0','&nbsp;',$result);

	$jsondata = json_decode($result,true);
	$posts = $jsondata['posts'];
	var_dump($posts);
	$blogroll = "";
	foreach($posts as $post){
		$blogroll .= "<p>";
		$date = date('d.m.Y',$post['unix-timestamp']);
		$blogroll .= $date."<br />";
		switch ($post['type']) {
			case 'photo':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a>";
				break;
			
			case 'link':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['link-text']."</a><br />";
				$blogroll .= substr(strip_tags($post['link-description']),0,100)."...";
				break;

			case 'regular':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['regular-title']."</a><br />";
				$blogroll .= substr(strip_tags($post['regular-body']),0,100)."...";
				break;

			case 'quote':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
				$blogroll .= substr(strip_tags($post['quote-text']),0,100)."...";
				break;
				
			case 'conversation':
				if(empty($post['conversation-title'])){
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
				}else{
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['conversation-title']."</a><br />";
				}
				$blogroll .= substr(nl2br($post['conversation-text']),0,100);
				break;
				
			case 'audio':
				if(empty($post['audio-caption'])){
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
				}else{
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".strip_tags($post['audio-caption'])."</a><br />";
				}
				break;
			
			default:
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a>";
				break;
		}
		$blogroll .= "</p>";
	}
	
	echo $blogroll;
?>

Revision: 31188
at September 1, 2010 00:32 by ichnoweb


Updated Code
<?php
	$ch = curl_init();
	##curl_setopt($ch,CURLOPT_URL,"http://ichnoweb.tumblr.com/api/read/json?num=4");
	curl_setopt($ch,CURLOPT_URL,"http://demo.tumblr.com/api/read/json");
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	$result = curl_exec($ch);
	curl_close($ch);
	
	$result = str_replace("var tumblr_api_read = ","",$result);
	$result = str_replace(';','',$result);
	$result = str_replace('\u00a0','&nbsp;',$result);

	$jsondata = json_decode($result,true);
	$posts = $jsondata['posts'];
	var_dump($posts);
	$blogroll = "";
	foreach($posts as $post){
		$blogroll .= "<p>";
		$date = date('d.m.Y',$post['unix-timestamp']);
		$blogroll .= $date."<br />";
		switch ($post['type']) {
			case 'photo':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a>";
				break;
			
			case 'link':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['link-text']."</a><br />";
				$blogroll .= substr(strip_tags($post['link-description']),0,100)."...";
				break;

			case 'regular':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['regular-title']."</a><br />";
				$blogroll .= substr(strip_tags($post['regular-body']),0,100)."...";
				break;

			case 'quote':
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
				$blogroll .= substr(strip_tags($post['quote-text']),0,100)."...";
				break;
				
			case 'conversation':
				if(empty($post['conversation-title'])){
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
				}else{
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['conversation-title']."</a><br />";
				}
				$blogroll .= substr(nl2br($post['conversation-text']),0,100);
				break;
				
			case 'audio':
				if(empty($post['audio-caption'])){
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
				}else{
					$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".strip_tags($post['audio-caption'])."</a><br />";
				}
				break;
			
			default:
				$blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a>";
				break;
		}
		$blogroll .= "</p>";
	}
	
	echo $blogroll;
?>

Revision: 31187
at August 31, 2010 22:58 by ichnoweb


Initial Code
<?php
// Get the latest quote from my tumblog

$ci = curl_init('http://syntagmatic.tumblr.com/api/read/json?num=1&type=quote');
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
$input = curl_exec($ci);
curl_close($ci);
$input = str_replace('var tumblr_api_read = ','',$input);
$input = str_replace(';','',$input);
$input = str_replace('\u00a0','&nbsp;',$input);
$value = json_decode($input, true);
$content = $value['posts'];

echo "<div class='quote'>";
    echo "<div class='text'>";
        echo $content[0]['quote-text'];
    echo "</div>";
    echo "<div class='source'>";
        echo $content[0]['quote-source'];
    echo "</div>";
echo "</div>";

?>

Initial URL


Initial Description
Tumblr API: http://www.tumblr.com/docs/de/api

Initial Title
Process Tumblr JSON Feed

Initial Tags
json

Initial Language
PHP