Example #1
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$api = new clAPI('http://feeds.feedburner.com/bassistscom');
if ($api->parse('1 hour')) {
    ?>
	<?php 
    $api->info();
    ?>
	<h4><a href="<?php 
    echo $api->get('channel/link');
    ?>
"><?php 
    echo $api->get('channel/title');
    ?>
</a></h4>
	<ul>
		<?php 
    foreach ($api->get('channel/item', 10) as $item) {
        ?>
			<li><a href="<?php 
        echo $item->get('link');
        ?>
"><?php 
        echo $item->get('title');
        ?>
</a></li>
		<?php 
    }
    ?>
Example #2
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$flickrCount = eregi('iPhone', $browser) ? 12 : 10;
$api = new clAPI('http://api.flickr.com/services/rest');
$api->param('method', 'flickr.people.getPublicPhotos');
$api->param('api_key', '');
$api->param('user_id', '');
$api->param('page', 1);
$api->param('per_page', 12);
?>

<?php 
if ($api->parse('1 hour')) {
    ?>
	<?php 
    $api->info();
    ?>
	<?php 
    foreach ($api->get('photos/photo', $flickrCount) as $photo) {
        ?>
	
		<li><a href="http://www.flickr.com/photos/netgeek/<?php 
        echo $photo->get('@id');
        ?>
"><img src="http://farm<?php 
        echo $photo->get('@farm');
        ?>
.static.flickr.com/<?php 
        echo $photo->get('@server');
Example #3
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 -->
Example #4
0
<?php

require_once '../src/coreylib.php';
$twitter_username = '';
$twitter_password = '';
$api = new clAPI('twitter.com/statuses/user_timeline.xml');
$api->param('count', 5);
$api->basicAuth($twitter_username, $twitter_password);
echo date('r', time());
?>

    <div id="twitter">
      <div id="twitter_div">
      <h2 class="twitter">Latest Updates <span>  &#187; Twitter</span></h2>
      <ul id="twitter_update_list">


<?php 
if ($api->parse('1 hour')) {
    ?>
      <ul>
<?php 
    foreach ($api->get('status') as $post) {
        ?>

<?php 
        $tweet = $post->get('text');
        // Convert URL's with protocol prefix
        $tweet = ereg_replace("[a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%])*", "<a href=\"\\0\">\\0</a>", $tweet);
        //Convert URL with just www.
        $tweet = ereg_replace("(^| |\n)(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://\\2\">\\2</a>", $tweet);
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$feedburner_uri = 'coreylib-cookbook';
$api = new clAPI('https://feedburner.google.com/api/awareness/1.0/GetFeedData');
$api->param('uri', $feedburner_uri);
if ($api->parse('10 minutes')) {
    ?>
	<h4><?php 
    echo $api->get('feed@uri');
    ?>
</h4>
	<p>
		<?php 
    echo $api->get('feed/entry[0]@hits');
    ?>
 hits 
		as of <?php 
    echo date('F j', strtotime($api->get('feed/entry[0]@date')));
    ?>
</p>
	</p>
<?php 
}
Example #6
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$api = new clAPI('http://feeds.feedburner.com/typepad/sethsmainblog');
$api->curlopt(CURLOPT_USERAGENT, "feedburnerclient");
if ($api->parse()) {
    ?>
	<?php 
    $api->info();
    ?>
	<h4><a href="<?php 
    echo $api->get('link[0]@href');
    ?>
"><?php 
    echo $api->get('title');
    ?>
</a></h4>
	<ul>
		<?php 
    foreach ($api->get('entry', 10) as $entry) {
        ?>
			<li><a href="<?php 
        echo $entry->get('link[0]@href');
        ?>
"><?php 
        echo $entry->get('title');
        ?>
</a></li>
		<?php 
    }
 public static function saveContent($name, $content, $cacheFor = 0)
 {
     if (self::isMysqlMode()) {
         // mysql cache
         if (!self::initMySql()) {
             return false;
         } else {
             $md5 = md5($name);
             $now = gmdate('Y/m/d H:i:s');
             if (!@mysql_query("REPLACE INTO `" . self::cacheTableName() . "` (id, cached_on, content) VALUES ('{$md5}', '{$now}', '" . mysql_escape_string($content) . "')", self::$mysqlConnection) && ($error = mysql_error(self::$mysqlConnection))) {
                 clAPI::error("Failed to cache <b>{$md5}</b>. See server error log for details.");
                 error_log("Failed to cache [{$md5}]: {$error}");
                 return false;
             } else {
                 return true;
             }
         }
     } else {
         // file system cache
         if (!($init = self::initFileSystem($name))) {
             return false;
         } else {
             list($fileName, $cachePath, $pathToFile) = $init;
         }
         if (@file_put_contents($pathToFile, $content) === false) {
             clAPI::error("Failed to save cache file {$pathToFile}.");
             return false;
         } else {
             return true;
         }
     }
 }
Example #8
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$api = new clAPI('http://feeds.technorati.com/search/iphone?language=n');
if ($api->parse()) {
    ?>
	<?php 
    $api->info();
}
?>


Example #9
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
clAPI::configure('trace', false);
$api = new clAPI('http://buzz.googleapis.com/feeds/thepythonist/public/posted');
$api->parse();
$api->info();
echo $api->first('//feed:author/feed:name');
Example #10
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$associate_tag = '';
$access_key_id = '';
$secret_code = '';
$api = new clAWSECS($associate_tag, $access_key_id, $secret_code);
$api->param("Keywords", "Jaco Pastorious");
$api->parse();
$api->info();
Example #11
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
$api_key = '';
$login = '';
$api = new clAPI('http://api.bit.ly/shorten');
$api->param('longUrl', 'http://collegeman.net');
$api->param('version', '2.0.1');
$api->param('apiKey', $api_key);
$api->param('login', $login);
$api->param('format', 'xml');
?>

<?php 
if ($api->parse()) {
    ?>
	<?php 
    if ($api->get('errorCode') == '0') {
        ?>
		<?php 
        $api->info('results');
        ?>
		<?php 
        echo $api->get('results/nodeKeyVal/shortUrl');
        ?>
	<?php 
    } else {
        ?>
		<?php 
        $api->info();
Example #12
0
<?php

require_once '../src/coreylib.php';
clAPI::configure('debug', true);
clAPI::configure('trace', false);
?>

<?php 
$delicious_username = '';
$delicious_password = '';
$api = new clAPI('https://api.del.icio.us/v1/posts/recent');
$api->basicAuth($delicious_username, $delicious_password);
if ($api->parse('5 minutes')) {
    ?>
	<?php 
    $api->info();
    ?>
	<h4><a href="http://delicious.com/"<?php 
    echo $delicious_username;
    ?>
">Delicious/<?php 
    echo $delicious_username;
    ?>
</a></h4>
	<ul>
		<?php 
    foreach ($api->get('post') as $post) {
        ?>
			<li style="clear:both;">
				<a href="<?php 
        echo $post->get('@href');
Example #13
0
 function get($path = null, $limit = null, $forceReturnWrapper = false)
 {
     if ($path) {
         clAPI::trace("Searching for <b>&quot;{$path}&quot;</b>");
     }
     if ($path === null) {
         return $forceReturnWrapper ? $this : $this->__value;
     }
     $node = $this;
     foreach (split('\\/', $path) as $childName) {
         $index = $attribute = null;
         if (preg_match('/^@(.*)?$/', $childName, $matches)) {
             // attribute only
             $childName = null;
             $attribute = $matches[1];
             clAPI::trace("Searching for attribute named {$attribute}");
         } else {
             if (preg_match('/(.*)\\[(\\d+)\\](@(.*))?$/', $childName, $matches)) {
                 // array request with/out attribute
                 $childName = $matches[1];
                 $index = (int) $matches[2];
                 $attribute = isset($matches[4]) ? $matches[4] : null;
                 clAPI::trace("Searching for element <b>{$childName}" . '[' . "{$index}]</b>" . ($attribute ? ", attribute <b>{$attribute}</b>" : ''));
             } else {
                 if (preg_match('/([^@]+)(@(.*))?$/', $childName, $matches)) {
                     // element request with/out attribute
                     $childName = $matches[1];
                     $attribute = isset($matches[3]) ? $matches[3] : null;
                     clAPI::trace("Searching for element <b>{$childName}</b>" . ($attribute ? ", attribute <b>{$attribute}</b>" : ''));
                 }
             }
         }
         if (!$childName && $attribute) {
             /*
             if (!isset($node->__attributes[$attribute])) {
             	clAPI::error("<b>$node->__name</b> does not have an attribute named <b>$attribute</b>");
             	return null;
             }
             */
             return isset($node->__attributes[$attribute]) ? $node->__attributes[$attribute] : null;
         }
         if ($childName && is_array($node)) {
             clAPI::error("You are looking for <b>{$childName}</b> in an array of elements, which isn't possible");
             return null;
         } else {
             if (!isset($node->__children[$childName])) {
                 clAPI::error("{$childName} is not a child of {$node->__name}");
                 return null;
             } else {
                 $node = $node->__children[$childName];
                 if ($index !== null) {
                     if (!is_array($node)) {
                         clAPI::error("{$node->__name} is not an array of elements or {$index} does not exist");
                         return null;
                     } else {
                         $node = $node[$index];
                     }
                 }
                 if ($attribute !== null) {
                     /* this won't work because sometimes feeds just drop the attribute definition... boo.
                     			if (!count($node->__attributes)) {
                     				clAPI::error("$childName does not have any attributes");
                     				return null;
                     			}
                     			
                     			if (!isset($node->__attributes[$attribute])) {
                     				clAPI::error("$node->__name does not have an attribute named $attribute");
                     				return null;
                     			}
                     			*/
                     return isset($node->__attributes[$attribute]) ? $node->__attributes[$attribute] : null;
                 }
             }
         }
     }
     if (is_object($node)) {
         if (!count($node->__children) && !$forceReturnWrapper) {
             return $node->__value;
         } else {
             return $node;
         }
     } else {
         if (is_array($node) && is_numeric($limit)) {
             return array_slice($node, 0, $limit);
         } else {
             return $node;
         }
     }
 }
Example #14
0
<?php

require_once "../src/coreylib.php";
?>

<?php 
$api = new clAPI("http://twitter.com/statuses/public_timeline.xml");
if ($api->parse('10 minutes')) {
    ?>
	<?php 
    $status = $api->get('status[5]');
    ?>
	<div><?php 
    echo $status->renderTwitterLink();
    ?>
</div>
<?php 
}
    the_content();
    ?>
                    
                    <?php 
    function cmp($a, $b)
    {
        if ($a->watchers == $b->watchers) {
            return 0;
        }
        return $a->watchers < $b->watchers ? -1 : 1;
    }
    ?>
                    
                    <div id="projects">
        				<?php 
    $api = new clAPI('http://github.com/api/v1/xml/kennethreitz');
    ?>
        				<?php 
    if ($api->parse('1 hour')) {
        ?>
        					<?php 
        foreach (array_reverse($api->xpath('//repository')) as $repo) {
            ?>
        						<div>
        							<h2 style="margin: 1em 0 0.3em -0.8em;">
        								&raquo; <a href="<?php 
            echo $repo->url;
            ?>
" class="black">
        								<?php 
            echo $repo->name;
<?php

clAPI::configure(array("display_errors" => false, "debug" => false, "nocache" => false, "max_download_tries" => 3, "trace" => false));
// wordpress defaults:
clCache::configure(array('nocreate' => false, 'mysql_host' => DB_HOST, 'mysql_username' => DB_USER, 'mysql_password' => DB_PASSWORD, 'mysql_database' => DB_NAME, 'mysql_table_prefix' => 'coreylib_'));
<?php

clAPI::configure(array('display_errors' => false, 'debug' => false, 'nocache' => false, 'max_download_tries' => 3, 'trace' => false));
clCache::configure(array('nocreate' => false, 'mysql_host' => DB_HOST, 'mysql_username' => DB_USER, 'mysql_password' => DB_PASSWORD, 'mysql_database' => DB_NAME, 'mysql_table_prefix' => 'coreylib_'));
Example #18
0
            echo $id;
            ?>
"><?php 
            echo $entry->get('title');
            ?>
</a></div>
		<?php 
        }
        ?>
	<?php 
    }
}
?>

<?php 
$api = new clAPI('http://gdata.youtube.com/feeds/api/standardfeeds/most_recent');
$api->param('v', 2);
if ($api->parse('1 hour')) {
    ?>
	<h4><?php 
    echo $api->get('title');
    ?>
</h4>
	<?php 
    $api->info();
    ?>
	<?php 
    foreach ($api->get('entry', 10) as $entry) {
        ?>
		<?php 
        // this nasty bit extracts the video id from entry@id:
Example #19
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', true);
?>

<?php 
require_once "../src/coreylib.php";
?>

<?php 
$api = new clAPI("http://karlacollegeman.com/feed/");
if ($api->parse('10 minutes')) {
    ?>
	<?php 
    $api->info();
    ?>
	
	<?php 
    foreach ($api->get('channel/item') as $item) {
        ?>
		<a href="<?php 
        echo $item->get('link');
        ?>
"><?php 
        echo $item->get('title');
        ?>
</a>
		<p><?php 
        echo $item->get('content:encoded');
        ?>
<?php

error_reporting(E_ALL);
ini_set('display_errors', true);
require_once "../src/coreylib.php";
clAPI::configure('debug', false);
?>

<?php 
$mashup = new clMashup();
$mashup->add('anthony jackson', new clAPI('http://search.twitter.com/search.atom?q=anthony+jackson'))->items_at('entry')->sort_by('updated');
$mashup->add('adam nitti', new clAPI('http://search.twitter.com/search.atom?q=adam+nitti'))->items_at('entry')->sort_by('updated');
$mashup->add('john patitucci', new clAPI('http://search.twitter.com/search.atom?q=john+patitucci'))->items_at('entry')->sort_by('updated');
$mashup->add('jaco pastorious', new clAPI('http://search.twitter.com/search.atom?q=jaco+pastorious'))->items_at('entry')->sort_by('updated');
$mashup->parse('2 seconds');
$mashup->info();
$mashup->sort();
?>

<?php 
if ($mashup->count()) {
    ?>
	<ul>
		<?php 
    foreach ($mashup as $item) {
        ?>
			<li><b><?php 
        echo $item->get('updated');
        ?>
</b> <em><?php 
        echo $item->source;
Example #21
0
<?php

require_once '../coreylib.php';
// create a new instance of the coreylib clAPI class
$api = new clAPI('http://twitter.com/statuses/user_timeline.xml?screen_name=collegeman');
// parse the feed!
$api->parse('10 minutes');
// analyze your feed with the info() method:
$api->info();
?>

<style>
* {
	font-family: Tahoma, sans-serif;
}

ul {
	list-style-type: none;	
	margin: 0;
	padding: 0;
}

ul li {
	padding: 10px;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border: 1px solid #ccc;
	margin: 0 0 10px 0;
}
</style>