array(), 'feed' => array(), 'entryRenderer' => array(), 'feedRenderer' => array(), ); /** * Set plugin loader for use with Extensions * * @param Zend_Loader_PluginLoader_Interface */ public static function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader) { self::$_pluginLoader = $loader; } /** * Get plugin loader for use with Extensions * * @return Zend_Loader_PluginLoader_Interface */ public static function getPluginLoader() { if (!isset(self::$_pluginLoader)) { #require_once 'Zend/Loader/PluginLoader.php'; self::$_pluginLoader = new Zend_Loader_PluginLoader(array( 'Zend_Feed_Writer_Extension_' => 'Zend/Feed/Writer/Extension/', )); } return self::$_pluginLoader; } /** * Add prefix path for loading Extensions * * @param string $prefix * @param string $path * @return void */ public static function addPrefixPath($prefix, $path) { $prefix = rtrim($prefix, '_'); $path = rtrim($path, DIRECTORY_SEPARATOR); self::getPluginLoader()->addPrefixPath($prefix, $path); } /** * Add multiple Extension prefix paths at once * * @param array $spec * @return void */ public static function addPrefixPaths(array $spec) { if (isset($spec['prefix']) && isset($spec['path'])) { self::addPrefixPath($spec['prefix'], $spec['path']); } foreach ($spec as $prefixPath) { if (isset($prefixPath['prefix']) && isset($prefixPath['path'])) { self::addPrefixPath($prefixPath['prefix'], $prefixPath['path']); } } } /** * Register an Extension by name * * @param string $name * @return void * @throws Zend_Feed_Exception if unable to resolve Extension class */ public static function registerExtension($name) { $feedName = $name . '_Feed'; $entryName = $name . '_Entry'; $feedRendererName = $name . '_Renderer_Feed'; $entryRendererName = $name . '_Renderer_Entry'; if (self::isRegistered($name)) { if (self::getPluginLoader()->isLoaded($feedName) || self::getPluginLoader()->isLoaded($entryName) || self::getPluginLoader()->isLoaded($feedRendererName) || self::getPluginLoader()->isLoaded($entryRendererName) ) { return; } } try { self::getPluginLoader()->load($feedName); self::$_extensions['feed'][] = $feedName; } catch (Zend_Loader_PluginLoader_Exception $e) { } try { self::getPluginLoader()->load($entryName); self::$_extensions['entry'][] = $entryName; } catch (Zend_Loader_PluginLoader_Exception $e) { } try { self::getPluginLoader()->load($feedRendererName); self::$_extensions['feedRenderer'][] = $feedRendererName; } catch (Zend_Loader_PluginLoader_Exception $e) { } try { self::getPluginLoader()->load($entryRendererName); self::$_extensions['entryRenderer'][] = $entryRendererName; } catch (Zend_Loader_PluginLoader_Exception $e) { } if (!self::getPluginLoader()->isLoaded($feedName) && !self::getPluginLoader()->isLoaded($entryName) && !self::getPluginLoader()->isLoaded($feedRendererName) && !self::getPluginLoader()->isLoaded($entryRendererName) ) { #require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Could not load extension: ' . $name . 'using Plugin Loader. Check prefix paths are configured and extension exists.'); } } /** * Is a given named Extension registered? * * @param string $extensionName * @return boolean */ public static function isRegistered($extensionName) { $feedName = $extensionName . '_Feed'; $entryName = $extensionName . '_Entry'; $feedRendererName = $extensionName . '_Renderer_Feed'; $entryRendererName = $extensionName . '_Renderer_Entry'; if (in_array($feedName, self::$_extensions['feed']) || in_array($entryName, self::$_extensions['entry']) || in_array($feedRendererName, self::$_extensions['feedRenderer']) || in_array($entryRendererName, self::$_extensions['entryRenderer']) ) { return true; } return false; } /** * Get a list of extensions * * @return array */ public static function getExtensions() { return self::$_extensions; } /** * Reset class state to defaults * * @return void */ public static function reset() { self::$_pluginLoader = null; self::$_prefixPaths = array(); self::$_extensions = array( 'entry' => array(), 'feed' => array(), 'entryRenderer' => array(), 'feedRenderer' => array(), ); } /** * Register core (default) extensions * * @return void */ public static function registerCoreExtensions() { self::registerExtension('DublinCore'); self::registerExtension('Content'); self::registerExtension('Atom'); self::registerExtension('Slash'); self::registerExtension('WellFormedWeb'); self::registerExtension('Threading'); self::registerExtension('ITunes'); } public static function lcfirst($str) { $str[0] = strtolower($str[0]); return $str; } }