My website, http://www.kimenye.com, is powered by Joomla! (one of the world's most popular open source content management system). Not being a fun of its usability as a blogging platform, I made the decision to host this blog in Google's Blogger service. Having done that, I found I needed to display links to my blog from my website in a dynamic manner, that didn't require me to manually add links when I add new content. As part of my website, I have a panel where I intend to display the Titles and Links to the blog posts. This article describes how I achieved this.
- Apache Web Server (preferably 2.0)
- PHP 5
- Zend GData PHP Library
Configuration of Zend PHP Library
We will be connecting to the Google Data Services to retrieve posts for the blog. This is done using the Zend GData PHP Library. See this article on the Google Code pages with detailed information on how to configure the libary. There's also a video on the page by one of Google's Software Engineers with step by step instructions. If you are on shared hosting, your mileage may vary following those instructions. I'll outline the failed instructions briefly.
- Upload the Zend Framework library. From the unpacked archive, we need everything in the folder library (i.e the folder XXX\library\Zend).
- Edit the .htaccess file to include the Zend Library folder in the include path.
This did not work for me, as my hosting provider has moved to using PHPSUEXEC and hence don't allow any php directives in the .htaccess file. These have to be moved to a php.ini file created in your public_html folder. I did this, however, this php.ini file was not getting parsed and hence my includes were failing. I checked my configuration using the phpinfo() method and saw that new php.ini file was not being parsed and hence the include_path variable was not being updated.
Using the Zend GData Library
- // no direct access
- defined('_JEXEC') or die('Restricted access');
- //This is the path of where you have uploaded your Zend GData library
- $path = '/home/your_user_name/public_html/libraries/';
- //This method updates the include path to include the Zend GData libaries
- //This is useful if you are in a shared hosting environment where it is not
- //easy to update the include path
- set_include_path(get_include_path() . PATH_SEPARATOR . $path);
- //require the Zend Loader file
- require_once (dirname(__FILE__).DS.'Zend'.DS.'Loader.php');
- * @see Zend_Gdata
- * @see Zend_Gdata_Query
- * @see Zend_Gdata_ClientLogin
- * This is the class to use to connect to the Google Blogger Service
- class BloggerHelper
- function getList()
- $count = 5; //this is the number of items to be returned
- $blogId = 123456789; //this is your blog id
- $email = 'email@example.com'; //This is the email to log into Blogger
- $password = 'password'; //This is the password to log into Blogger
- $client = Zend_Gdata_ClientLogin::getHttpClient($email, $password, 'blogger');
- $gdClient = new Zend_Gdata($client);
- $query = new Zend_Gdata_Query('http://www.blogger.com/feeds/' . $blogId . '/posts/default');
- $feed = $gdClient->getFeed($query);
- $i = 0;
- $lists = array();
- foreach($feed->entries as $entry) //This is a temp hack to remove drafts
- $lists[$i]->link = htmlspecialchars($entry->link->text);
- $lists[$i]->text = $entry->title->text;
- return $lists;
The code shown above requires you to know your blog id. This can be obtained by looking at the request parameters in the url for your blog. A simple way to find this is to log into your Blogger account, click on the blog you want to access and click on the settings link. Now look at the url on your blog. It should have something like "http://www.blogger.com/blog-options-basic.g?blogID=1234567890". The numbers after the string "blogID=" is your blog id.
The getList() method returns an array of objects with the link as the url to the blog post and the text property as the title of the blog. This array of items is then used by a Joomla! module to display this information on the screen.
I've not found an elegant way to distinguish the drafts from the published posts, hence the current way of using the URL will have to do for now. In the future I intend to add some additional logic to do searching based on key words, so it works like an aggregator as well as functionality to display posts published in the last 30 days. Hope this is a nice starting place.