function isActive() { // check for the availability of the ZFeed systemplugin that provides SimplePie if (PluginUtil::isAvailable(PluginUtil::getServiceId('SystemPlugin_ZFeed_Plugin'))) { return true; } return false; }
/** * Find the editor title when provided with editorname * * @param array $args * @return string */ public function getEditorTitle($args) { if (!PluginUtil::isAvailable('moduleplugin.scribite.' . strtolower($args['editorname']))) { return ''; } $className = 'ModulePlugin_Scribite_' . $args['editorname'] . '_Plugin'; $instance = PluginUtil::loadPlugin($className); return $instance->getMetaDisplayName(); }
/** * 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; }
/** * view items */ public function view($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Feeds::', "::", ACCESS_EDIT), LogUtil::getErrorMsgPermission()); $startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : null, 'GET'); $property = FormUtil::getPassedValue('feeds_property', isset($args['feeds_property']) ? $args['feeds_property'] : null, 'POST'); $category = FormUtil::getPassedValue("feeds_{$property}_category", isset($args["feeds_{$property}_category"]) ? $args["feeds_{$property}_category"] : null, 'POST'); $clear = FormUtil::getPassedValue('clear', false, 'POST'); $purge = FormUtil::getPassedValue('purge', false, 'GET'); if (!PluginUtil::isAvailable('systemplugin.simplepie')) { LogUtil::registerError($this->__('<strong>Fatal error: The required SimplePie system plugin is not available.</strong><br /><br />Zikula ships with the SimplePie plugin located in the docs/examples/plugins/ExampleSystemPlugin/SimplePie directory. It must be copied (or symlinked) from there and pasted into the /plugins directory. The plugin must then be installed. This is done via the Extensions module. Click on the System Plugins menu item and install the SimplePie plugin.')); } if ($purge) { if (ModUtil::apiFunc('Feeds', 'admin', 'purgepermalinks')) { LogUtil::registerStatus($this->__('Purging of the pemalinks was successful')); } else { LogUtil::registerError($this->__('Purging of the pemalinks has failed')); } return System::redirect(strpos(System::serverGetVar('HTTP_REFERER'), 'purge') ? ModUtil::url('Feeds', 'admin', 'view') : System::serverGetVar('HTTP_REFERER')); } if ($clear) { $property = null; $category = null; } // get module vars for later use $modvars = ModUtil::getVar('Feeds'); if ($modvars['enablecategorization']) { // load the category registry util $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Feeds', 'feeds'); $properties = array_keys($catregistry); // Validate and build the category filter - mateo if (!empty($property) && in_array($property, $properties) && !empty($category)) { $catFilter = array($property => $category); } // Assign a default property - mateo if (empty($property) || !in_array($property, $properties)) { $property = $properties[0]; } // plan ahead for ML features $propArray = array(); foreach ($properties as $prop) { $propArray[$prop] = $prop; } } // Get all the feeds $items = ModUtil::apiFunc('Feeds', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'order' => 'fid', 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null)); $feedsitems = array(); foreach ($items as $item) { if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_READ)) { // Options for the item $options = array(); if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_EDIT)) { $options[] = array('url' => ModUtil::url('Feeds', 'user', 'display', array('fid' => $item['fid'])), 'image' => 'kview.png', 'title' => $this->__('View')); $options[] = array('url' => ModUtil::url('Feeds', 'admin', 'modify', array('fid' => $item['fid'])), 'image' => 'xedit.png', 'title' => $this->__('Edit')); if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_DELETE)) { $options[] = array('url' => ModUtil::url('Feeds', 'admin', 'delete', array('fid' => $item['fid'])), 'image' => '14_layer_deletelayer.png', 'title' => $this->__('Delete')); } } $item['options'] = $options; $feedsitems[] = $item; } } // Assign the items and modvars to the template $this->view->assign('feedsitems', $feedsitems); $this->view->assign($modvars); // Assign the default language $this->view->assign('lang', ZLanguage::getLanguageCode()); // Assign the categories information if enabled if ($modvars['enablecategorization']) { $this->view->assign('catregistry', $catregistry); $this->view->assign('numproperties', count($propArray)); $this->view->assign('properties', $propArray); $this->view->assign('property', $property); $this->view->assign("category", $category); } // Assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Feeds', 'user', 'countitems', array('category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // Return the output that has been generated by this function return $this->view->fetch('admin/view.tpl'); }