tumblr-data-provider Library that pulls posts from tumblr + data provider class that can be used with CListView or CGridView

  1. Requirements
  2. Usage

This is my very first contribution to the world of open source. I needed to build a blog for http://www.instinctiv.com/ (which is built on Yii) and as tumblr is one of the best blogging solutions on the web and its API allows to pull the content however you'd like without anyone knowing that its hosted on tumblr - it was an amazing shortcut to writing a blog software for the site.

Requirements

Yii 1.1 or above (actually developed and tested only on 1.1.6)

Usage

Unpack the archive with files in lets say protected/extensions/tumblr/ then in your controller just instantiate the tumblr library that pulls the posts with the preferred tumblr user ID and then instantiate the data provider.

class BlogController extends Controller
	{
		public function actionIndex()
		{
			Yii::import('application.extensions.tumblr.ETumblrDataProvider', true);
			
			$tumblrLib = new ETumblrJson('instinctiv');
			$dataProvider = new ETumblrDataProvider($tumblrLib);
			
			$this->render('index', array(
				'dataProvider' => $dataProvider
			));
		}
	}

In your views/blog/index.php lets have this:

$this->widget('zii.widgets.CListView', array(
	'dataProvider' => $dataProvider,
	'itemView' => '_post',
));

Then in views/blog/_post.php you will have each blog post as PHP array under the "$data" var. As tumblr allows different types of posts (quote, text, video, audio, photo) and it produces different response for each and every of them, I would recommend having your _post.php view to have code that does the generic styling (html + css classes, ids), something like this:

<div class="post">
	<div class="date"><?php echo $data['date']; ?></div>
	<?php $this->renderPartial('_' . $data['type'] . 'Post', array('data' => $data)); ?>
</div>

This way you will have to create protected/views/blog/_audioPost.php, protected/views/blog/_videoPost.php, etc for every kind of post but you will have maximum control over the content.

Future enhencements:

  • Have in mind that to minimize requests to remote host (tumblr api servers) thus reducing lag of page loads, caching should be implemented.
  • Build another simple class to take care of remote requests, tumblr JSON API lib should not care how the posts are fetched.

As this is my first extension, feel free to report bugs, suggest improvements, etc, here or at:

dimitar@instinctiv.com

Regards, Dimitar Dinchev at http://instinctiv.com/

6 0
4 followers
455 downloads
Yii Version: 1.1
License: MIT
Category: Web Service
Developed by: Veseliq
Created on: Feb 28, 2011
Last updated: 13 years ago

Downloads

show all

Related Extensions