Пример #1
0
 /**
  * Process RSS feed and return results.
  *
  * @param $feed_url
  * @param null $cache_name
  * @param int $cache_expires
  * @return array|mixed
  */
 public static function getNewsFeed($feed_url, $cache_name = NULL, $cache_expires = 900)
 {
     if (!is_null($cache_name)) {
         $feed_cache = Cache::get('feed_' . $cache_name);
     } else {
         $feed_cache = null;
     }
     if ($feed_cache) {
         return $feed_cache;
     }
     // Catch the occasional error when the RSS feed is malformed or the HTTP request times out.
     try {
         $news_feed = Reader::import($feed_url);
     } catch (\Exception $e) {
         $news_feed = NULL;
     }
     if (!is_null($news_feed)) {
         $latest_news = array();
         $article_num = 0;
         foreach ($news_feed as $item) {
             $article_num++;
             $news_item = array('num' => $article_num, 'title' => $item->getTitle(), 'timestamp' => $item->getDateModified()->getTimestamp(), 'description' => trim($item->getDescription()), 'link' => $item->getLink(), 'categories' => $item->getCategories()->getValues());
             $latest_news[] = $news_item;
         }
         $latest_news = array_slice($latest_news, 0, 10);
         if (!is_null($cache_name)) {
             Cache::set($latest_news, 'feed_' . $cache_name, array('feeds', $cache_name), $cache_expires);
         }
         return $latest_news;
     }
 }
Пример #2
0
 public function __construct()
 {
     $di = \Phalcon\Di::getDefault();
     $cache_driver = $di['cache_driver'];
     $pool = new \Stash\Pool($cache_driver);
     $pool->setNamespace(\FA\Cache::getSitePrefix('doctrine'));
     $this->_cache = $pool;
 }
Пример #3
0
            $cache_driver->setOptions($cache_config['memcached']);
            break;
        case 'file':
            $cache_driver = new \Stash\Driver\FileSystem();
            $cache_driver->setOptions($cache_config['file']);
            break;
        default:
        case 'memory':
        case 'ephemeral':
            $cache_driver = new \Stash\Driver\Ephemeral();
            break;
    }
    // Register Stash as session handler if necessary.
    if (!$cache_driver instanceof \Stash\Driver\Ephemeral) {
        $pool = new \Stash\Pool($cache_driver);
        $pool->setNamespace(\FA\Cache::getSitePrefix('session'));
        $session = new \Stash\Session($pool);
        \Stash\Session::registerHandler($session);
    }
    return $cache_driver;
});
$di->set('cache', array('className' => '\\FA\\Cache', 'arguments' => array(array('type' => 'service', 'name' => 'cache_driver'), array('type' => 'parameter', 'value' => 'user'))));
// Register URL handler.
$di->setShared('url', array('className' => '\\FA\\Url', 'arguments' => array(array('type' => 'service', 'name' => 'config'), array('type' => 'service', 'name' => 'request'), array('type' => 'service', 'name' => 'dispatcher'))));
// Register session service.
$di->setShared('session', '\\FA\\Session');
// Register CSRF prevention security token service.
$di->setShared('csrf', array('className' => '\\FA\\Csrf', 'arguments' => array(array('type' => 'service', 'name' => 'session'))));
// Register view helpers.
$di->setShared('viewHelper', '\\FA\\Phalcon\\Service\\ViewHelper');
// Register Flash notification service.