/** * 入口函数,初始化路由器 * * @access public * @return void * @throws Typecho_Widget_Exception */ public function execute() { /** 验证路由地址 **/ $action = $this->request->action; //兼容老版本 if (empty($action)) { $widget = trim($this->request->widget, '/'); $objectName = 'Widget_' . str_replace('/', '_', $widget); if (Typecho_Common::isAvailableClass($objectName)) { $widgetName = $objectName; } } else { /** 判断是否为plugin */ $actionTable = array_merge($this->_map, unserialize($this->widget('Widget_Options')->actionTable)); if (isset($actionTable[$action])) { $widgetName = $actionTable[$action]; } } if (isset($widgetName) && class_exists($widgetName)) { $reflectionWidget = new ReflectionClass($widgetName); if ($reflectionWidget->implementsInterface('Widget_Interface_Do')) { $this->widget($widgetName)->action(); return; } } throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404); }
/** * 获取可用的连接 * * @access public * @return Typecho_Http_Client_Adapter */ public static function get() { $adapters = func_get_args(); if (empty($adapters)) { $adapters = array(); $adapterFiles = glob(dirname(__FILE__) . '/Client/Adapter/*.php'); foreach ($adapterFiles as $file) { $adapters[] = substr(basename($file), 0, -4); } } foreach ($adapters as $adapter) { $adapterName = 'Typecho_Http_Client_Adapter_' . $adapter; if (Typecho_Common::isAvailableClass($adapterName) && call_user_func(array($adapterName, 'isAvailable'))) { return new $adapterName(); } } return false; }
/** * * Load a format-render class file. * * @access public * * @return bool True if loaded, false if not. * */ function loadFormatObj($format) { $format = ucwords(strtolower($format)); $file = $format . '.php'; $class = "Text_Wiki_Render_{$format}"; if (!Typecho_Common::isAvailableClass($class)) { $loc = $this->findFile('render', $file); if ($loc) { // found the class include_once $loc; } else { // can't find the class return $this->error("Rendering format class '{$class}' not found"); } } $this->formatObj[$format] = new $class($this); }