/** * Add default pagevar settings to every page * @param GetResponseEvent $event */ public function setDefaultPageVars(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } // set some defaults $this->pageVars->set('lang', \ZLanguage::getLanguageCode()); $this->pageVars->set('langdirection', \ZLanguage::getDirection()); $this->pageVars->set('title', \System::getVar('defaultpagetitle')); $this->pageVars->set('meta.charset', \ZLanguage::getDBCharset()); $this->pageVars->set('meta.description', \System::getVar('defaultmetadescription')); $this->pageVars->set('meta.keywords', \System::getVar('metakeywords')); $schemeAndHost = $event->getRequest()->getSchemeAndHttpHost(); $baseUrl = $event->getRequest()->getBaseUrl(); $this->pageVars->set('homepath', $schemeAndHost . $baseUrl); }
/** * Get Feeds via SimplePie * * @param integer fid feed id (not required if feed url is present) * @param string furl feed url or urls for Multifeed request (not requred if feed id is present) * @param integer limit set how many items are returned per feed with Multifeeds (default is all) * @param integer cron set to 1 to update all caches right now (default is 0, update cache only if needed) * @return mixed item array containing total item count, error information, and object with all the requested feeds */ public function getfeed($args) { if (!PluginUtil::isAvailable('systemplugin.simplepie')) { throw new Exception(__('<strong>Fatal error: The required SimplePie system plugin is not available.</strong>')); } // Argument check if ((!isset($args['fid']) || !is_numeric($args['fid'])) && (!isset($args['furl']) || (!is_string($args['furl']) && (!is_array($args['furl']))))) { return LogUtil::registerArgsError(); } // Optional arguments. if (!isset($args['limit']) || !is_numeric($args['limit'])) { $args['limit'] = 0; // 0 = don't set a limit } if (!isset($args['cron']) || !is_numeric($args['cron'])) { $args['cron'] = 0; // not a cron job update } else { $args['cron'] = 1; // it is a cron job update } // get all module vars for later use $modvars = $this->getVars(); // check if the feed id is set, grab the feed from the db if (isset($args['fid'])) { $feed = ModUtil::apiFunc('Feeds', 'user', 'get', array('fid' => $args['fid'])); $url = $feed['url']; } elseif(isset($args['furl'])) { $url = $args['furl']; } // Now setup SimplePie for the feed $theFeed = new SimplePieFeed(); $theFeed->set_feed_url($url); $theFeed->set_cache_location(CacheUtil::getLocalDir($modvars['cachedirectory'])); $theFeed->enable_order_by_date(true); // Get the charset used for the output, and tell SimplePie about it so it will try to use the same for its output $charset = ZLanguage::getDBCharset(); if ($charset != '') { $theFeed->set_output_encoding($charset); } // Set the feed limits (note: this is a per feed limit that applies if multiple feeds are used) if ($args['limit'] > 0) { $theFeed->set_item_limit($args['limit']); } // Set Cache Duration if ($args['cron'] == 1) { $theFeed->set_cache_duration(0); // force cache to update immediately (a cron job needs to do that) } elseif ($modvars['usingcronjob'] == 1) { // Using a cron job to update the cache (but not this time), so per SimplePie docs... $theFeed->set_cache_duration(999999999); // set to 999999999 to not update the cache with this request $theFeed->set_timeout(-1); // set timeout to -1 to prevent SimplePie from retrying previous failed feeds } else { $theFeed->set_cache_duration($modvars['cacheinterval']); // Use the specified cache interval. } // tell SimplePie to go and do its thing $theFeed->init(); $returnFeed['count'] = $theFeed->get_item_quantity(); // total items returned $returnFeed['error'] = $theFeed->error(); // Return any errors $returnFeed['feed'] = $theFeed; // The feed information // Per SimplePie documentation, there is a bug in versions of PHP older than 5.3 where PHP doesn't release memory properly in certain cases. // This is the workaround $theFeed->__destruct(); unset($theFeed); return $returnFeed; }