tagCloud = array('MyTagCloud_Plugin', 'process'); } /** * 禁用插件方法,如果禁用失败,直接抛出异常 * * @static * @access public * @return void * @throws Typecho_Plugin_Exception */ public static function deactivate(){} /** * 获取插件配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ public static function config(Typecho_Widget_Helper_Form $form) { // 是否启用 $compatibilityMode = new Typecho_Widget_Helper_Form_Element_Radio('enable', array( self::ENABLE_YES => _t('启用'), self::ENABLE_NO => _t('不启用') ), self::ENABLE_YES, _t('是否启用该插件'), _t("启用后将这段PHP代码放到需要显示标签的模板中即可 Typecho_Plugin::factory('usr/themes/sidebar.php')->tagCloud(); ")); $form->addInput($compatibilityMode->addRule('enum', _t('必须选择一个模式'), array(self::ENABLE_YES, self::ENABLE_NO))); // 是否显示没使用的标签 $compatibilityMode = new Typecho_Widget_Helper_Form_Element_Radio('zero', array( self::ZERO_SHOW => _t('显示'), self::ZERO_HIDE => _t('不显示') ), self::ZERO_SHOW, _t('显示没使用的标签'), _t("默认显示所有标签,请根据自己需要进行设置。")); $form->addInput($compatibilityMode->addRule('enum', _t('必须选择一个模式'), array(self::ZERO_SHOW, self::ZERO_HIDE))); // 前台显示栏目标题 $title = new Typecho_Widget_Helper_Form_Element_Text('title', NULL, '标签', _t('前台显示栏目标题')); $form->addInput($title); // 最多显示标签数量 $limit = new Typecho_Widget_Helper_Form_Element_Text('limit', NULL, '20', _t('最多显示标签数量')); $form->addInput($limit); } /** * 个人用户的配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form * @return void */ public static function personalConfig(Typecho_Widget_Helper_Form $form){} /** * 插件实现方法 * * @access public * @return void */ public static function process() { $enable = Typecho_Widget::widget('Widget_Options')->plugin('MyTagCloud')->enable; $zero = Typecho_Widget::widget('Widget_Options')->plugin('MyTagCloud')->zero; $title = Typecho_Widget::widget('Widget_Options')->plugin('MyTagCloud')->title; $limit = (int)Typecho_Widget::widget('Widget_Options')->plugin('MyTagCloud')->limit; // 是否启用 if ($enable != self::ENABLE_YES) { return; } // 查找满足条件的标签 $tags = Typecho_Widget::widget('Widget_Metas_Tag_Cloud', array( 'sort' => 'count', 'ignoreZeroCount' => $zero == self::ZERO_HIDE ? true : false, 'desc' => true, 'limit' => $limit )); // 是否有标签 if ($tags->have()) { self::render($title, $tags); } } /** * 输出Html标签 * * @access public * @return void */ public static function render($title, $tags) { // 拼接并输出html $html = '

'. $title .'

'; while ($tags->next()) { $html .= "{$tags->name}"; } $html .= '
'; echo $html; } }