<?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_'));
 static function cache($cache = null)
 {
     if (!is_null($cache)) {
         if (!$cache instanceof clCache) {
             throw new Exception('Object %s does not inherit from clCache', get_class($object));
         }
         self::$cache = new clStash($cache);
     }
     if (!self::$cache) {
         try {
             // default is FileCache
             $class = COREYLIB_DEFAULT_CACHE_STRATEGY;
             $cache = new $class();
             self::$cache = new clStash($cache);
         } catch (Exception $e) {
             clApi::log($e, E_USER_WARNING);
             return false;
         }
     }
     return self::$cache;
 }
示例#3
0
        //$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 -->
			<?php 
            $content = $entry->first('feed:content')->__toString();
            $content = substr($content, 5, strlen($content) - 5);
            $href = $entry->first('feed:link[@rel="alternate"]/@href');
            ?>
	
			<li><?php 
            echo $content;
            ?>
 <a href="<?php 
            echo $href;
            ?>
">&raquo;</a></li>
		<?php 
        }
        ?>
		</ul>
		<?php 
        clCache::save();
        ?>
	<?php 
    }
}
 /**
  * Initialize MySQL caching: connect to the database and create the cache table if needed.
  * @return When initialization succeeds, true; otherwise, false.
  */
 private static function initMySql()
 {
     if (self::$mysqlTableExists === null) {
         clAPI::trace('Initializing MySQL cache.');
         if (!(self::$mysqlConnection = mysql_connect(self::$options['mysql_host'], self::$options['mysql_username'], self::$options['mysql_password']))) {
             clAPI::error('Failed to connect to the MySQL server.');
             return false;
         }
         if (!@mysql_select_db(self::$options['mysql_database'], self::$mysqlConnection)) {
             clAPI::error('Unable to select database `' . self::$options['mysql_database'] . '`');
             return false;
         }
         if (!self::$options['nocreate']) {
             self::$mysqlTableExists = self::cacheTableName() == self::getVar("SHOW TABLES LIKE '" . self::cacheTableName() . "'");
             if (!self::$mysqlTableExists) {
                 clAPI::trace('Creating cache table <b>' . self::cacheTableName() . '</b>');
                 if (!@mysql_query('CREATE TABLE `' . self::cacheTableName() . '` (`id` VARCHAR(32) NOT NULL PRIMARY KEY, `cached_on` DATETIME NOT NULL, `content` LONGBLOB)', self::$mysqlConnection)) {
                     clAPI::error('Failed to create cache table `' . self::cacheTableName() . '`: ' . mysql_error(self::$mysqlConnection));
                     return false;
                 } else {
                     self::$mysqlTableExists = true;
                 }
             } else {
                 return true;
             }
         } else {
             self::$mysqlTableExists = true;
             clAPI::warn("You didn't let coreylib check to see if the cache table was there.  Hope you're right.");
             return true;
         }
     } else {
         return self::$mysqlTableExists;
     }
 }