Monday, August 25, 2008

Label Me

Of the API features that Google offers for their Blogger service the one that I was most surprised to see missing is a method to retrieve all the tags(category) for a blog. Though listed in their query parameters is the syntax for search by tag/category, the "cloud" was missing. The below code takes care of this missing feature.

::NOTE::
This class will be rolled into my helper classes soon.

class CW_Blog_Util {
const BLOGGER_URL = 'http://www.blogger.com/feeds/blogId/posts/default';

/**
* associative array holding blog tbl properties
*
* @var array
*/
private $_blogs = array();

/**
* blog title
*
* @var string
*/
private $_title = "";

private $_gDataQuery = null;

private $_gQuery = null;

public function __construct() {
$this->_gQuery = new Zend_Gdata();
}

public function getAllEntries() {

$query = $this->_getGdataQuery();
$feed = $this->_gQuery->getFeed($query);

return $feed;
}

public function getLatestBlog() {

$query = $this->_getGdataQuery();
$feed = $this->_gQuery->getFeed($query);

return $feed->current();
}

public function getBlogListByTag($tag) {

$query = $this->_getGdataQuery();
$query->setCategory($tag);

$feed = $this->_gQuery->getFeed($query);

return $feed;
}

public function getBlogLabels() {

$labels = array();

foreach ($this->getAllEntries() as $attr) {

for ($i = 0; $i < count($attr->category); $i++) {
$labels[] = $attr->category[$i]->term;
}
}

return array_count_values($labels);
}

private function _getGdataQuery() {
$this->_gDataQuery = new Zend_Gdata_Query(self::BLOGGER_URL);

return $this->_gDataQuery;
}

}

// Usage
$blogs = new CW_Blog_Util();

foreach ($blogs->getBlogLabels() as $label => $count) {
print "Label {$label}
";
}

Tuesday, August 19, 2008

McKinna Wiles is Reborn

In anticapation for my daughter, McKinna Wiles, birth I have revamped http://www.mckinna-wiles.com/ using Wordpress as the CMS and a modified theme from wpzone.net.

Enjoy

Monday, August 4, 2008

Access XML Nodes From Namespaces With Zend Framework

One of the requirements for a project that I am working on is that a "weather" module display on on of the main pages.  At first glance this should be pretty easy.  While working on it I noticed that I wanted to access more of the information that the feed had available.  I found plenty of tutorials on how to access the node values using SimpleXML, but I couldn't find what I was looking for utilizing Zend Framework.

After a quick response from the mailing list and references to the PHP online manual I came up with the solution.

Thanks to Pádraic Brady for the assistance.


Zend_Feed::registerNamespace('yweather','http://xml.weather.yahoo.com/ns/rss/1.0');
Zend_Feed::registerNamespace('geo','http://www.w3.org/2003/01/geo/wgs84_pos#');

$feed = Zend_Feed::import("http://weather.yahooapis.com/forecastrss?p=38105");

// Conditional Codes: http://developer.yahoo.com/weather/#codes
$condition = $feed->current()->{'yweather:condition'};
$text      = $condition->getDOM()->getAttribute('text');
print "Text {$text}
";

$astronomy = $feed->{'yweather:astronomy'};
$text      = $astronomy->getDOM()->getAttribute('sunrise');
print "Sunrise Attribute {$text}
";
          
$lat  = $feed->current()->{'geo:lat'};
$text = $lat->getDOM()->nodeValue;
print "Latitude {$text}
";