Exemple #1
0
<!-- load coreylib -->
<?php 
require_once '../src/coreylib.php';
?>
<!-- two levels of debugging, should something go wrong... -->
<?php 
//clAPI::configure('debug', true);
//clAPI::configure('trace', false);
?>

<?php 
if (!clCache::cached('google.buzz.feed', '1 second')) {
    ?>
	<!-- create a new API parser with the feed address -->
	<?php 
    $api = new clAPI('http://buzz.googleapis.com/feeds/108964711519495307614/public/posted');
    ?>
	<!-- parse it  -->
	<?php 
    if ($api->parse()) {
        ?>
		<!-- uncomment this line if you want a pretty tree to explore -->
		<?php 
        //$api->info()
        ?>
		<!-- use xpath to grab all of the <entry> elements -->
		<ul>
		<?php 
        foreach ($api->xpath('//feed:entry') as $entry) {
            ?>
			<!-- for each entry element, grab the alternate link and the content -->
 function parse($cacheFor = 0)
 {
     $this->content = false;
     $this->cacheFor = $cacheFor;
     $qs = $this->queryString();
     $url = $this->url . ($qs ? '?' . $qs : '');
     $this->cacheName = $url . md5($this->username . $this->password) . md5($this->consumerKey . $this->accessToken);
     $contentCameFromCache = false;
     if ($this->cacheFor && !clAPI::$options['nocache']) {
         $this->content = clCache::cached($this->cacheName, $this->cacheFor, true);
     }
     if ($this->content === false) {
         if (!$this->multi_mode) {
             $try = 0;
             do {
                 $try++;
                 $this->content = $this->download($url);
             } while (empty($this->content) && $try < clAPI::$options['max_download_tries']);
         } else {
             // in multi mode, the curl handle is returned from download, not content
             return $this->download($url);
         }
     } else {
         // in multi mode, when content is cached, we return it
         if ($this->multi_mode) {
             return $this->content;
         } else {
             $contentCameFromCache = true;
         }
     }
     return $this->parseText($this->content, $contentCameFromCache);
 }
function cl_cached($cache_key, $cache_for = -1, $cache = null)
{
    return clCache::cached($cache_key, $cache_for, $cache);
}
 function parse($cacheFor = 0)
 {
     $this->content = false;
     $qs = $this->queryString();
     $url = $this->url . ($qs ? '?' . $qs : '');
     $cacheName = $url . md5($this->username . $this->password);
     $contentCameFromCache = false;
     if ($cacheFor && !clAPI::$options['nocache']) {
         $this->content = clCache::cached($cacheName, $cacheFor, true);
     }
     if ($this->content === false) {
         $try = 0;
         do {
             $try++;
             $this->content = $this->download($url);
         } while (empty($this->content) && $try < clAPI::$options['max_download_tries']);
     } else {
         $contentCameFromCache = true;
     }
     if (!$this->content) {
         self::error("Failed to download {$this->url}");
         return false;
     }
     if ($this->parserType == COREYLIB_PARSER_XML) {
         if (!($this->sxml = simplexml_load_string($this->content, null, LIBXML_NOCDATA))) {
             self::error("Failed to parse {$this->url}");
             return false;
         }
         $this->tree = new clNode($this->sxml);
     }
     if ($cacheFor && !$contentCameFromCache && !clAPI::$options['nocache']) {
         clCache::saveContent($cacheName, $this->content, $cacheFor);
     }
     return true;
 }