footer = array('AnotherLike_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('AnotherLike_Plugin', 'footer');
Helper::addAction('like', 'AnotherLike_Action');
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
// contents 如果没有likes字段,则添加
if (!array_key_exists('likes', $db->fetchRow($db->select()->from('table.contents'))))
$db->query('ALTER TABLE `'. $prefix .'contents` ADD `likes` INT(10) DEFAULT 0;');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){
Helper::removeAction('like');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){
/** 文章页A标签点赞的class */
$likeClass = new Typecho_Widget_Helper_Form_Element_Text(
'likeClass',NULL ,'post-like',
_t('点赞A标签的class'),
_t('点赞的自定义样式,默认为.post-like。可自定义CSS样式,无需加.')
);
/** 是否加载jquery */
$jquery = new Typecho_Widget_Helper_Form_Element_Radio(
'jquery', array('0'=> '手动加载', '1'=> '自动加载'), 1, '选择jQuery来源',
'若选择"手动加载",则需要你手动加载jQuery到你的主题里,若选择"自动加载",本插件会自动加载jQuery到你的主题里。');
$form->addInput($jquery);
$form->addInput($likeClass);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){
}
/**
* 输出点赞链接或者点赞次数
*
* 语法: AnotherLike_Plugin::theLike();
* 输出: '赞 ('.$row['like'].')'
*
* 语法: AnotherLike_Plugin::theLike(false);
* 输出: 0
*
* @access public
* @param bool $link 是否输入链接 (false为显示纯数字)
* @return string
*/
public static function theLike($link = true){
$db = Typecho_Db::get();
$cid = Typecho_Widget::widget('Widget_Archive')->cid;
$row = $db->fetchRow($db->select('likes')->from('table.contents')->where('cid = ?', $cid));
if($link){
$settings = Helper::options()->plugin('AnotherLike');
//echo ' '.$row['likes'].'
('.$row['likes'].') 点赞需要刷新一下页面~(*/ω\*)';
// echo '
$post_likes
$after