header = array('PostRating_Plugin', 'headerScript');
Typecho_Plugin::factory('Widget_Archive') ->footer = array('PostRating_Plugin', 'footerScript');
$db = Typecho_Db::get();
$postrating = $db->getPrefix() . 'postrating';
Helper::addPanel(3, 'PostRating/manage.php', '文章评分', '管理文章评分', 'administrator');
// 数据库若无 'postrating' table 则建立
if (current($db->fetchRow("SHOW TABLES LIKE '$postrating'")) != $postrating) {
$createTable = $db->query("CREATE TABLE ". $postrating ." (
cid int(10) NOT NULL,
rating int(2) NOT NULL,
ip varchar(32) NOT NULL,
name varchar(32) NOT NULL,
created int(10) NOT NULL,
UNIQUE KEY created (created)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
if ($createTable) return('"postrating" table 创建成功, 插件已经被激活!');
else throw new Typecho_Plugin_Exception('"postrating" table 创建失败, 无法使用本插件!');
}
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removePanel(3, 'PostRating/manage.php');
// 删除 'postrating' table
$db = Typecho_Db::get();
$config = Typecho_Widget::widget('Widget_Options')->plugin('PostRating');
if ($config->drop_table) $db->query("DROP TABLE IF EXISTS " . $db->getPrefix() . 'postrating');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$jq_set = new Typecho_Widget_Helper_Form_Element_Radio(
'jq_set', array(0 => '自己处理', 1 => '随着本插件载入'), 0,
'jQuery 来源', '若选择 "随着本插件载入", 会从 Google API 自动载入 jQurey 1.2.6 到 header().');
$form->addInput($jq_set);
$options = Typecho_Widget::widget('Widget_Options');
$plug_url = $options->pluginUrl;
$db = Typecho_Db::get();
$registered = $db->fetchRow($db->select()->from('table.options')
->where('name = ?', 'plugin:PostRating')
);
$img = $registered ? $options->plugin('PostRating')->img_set : 'star_19';
$cats = array('star', 'custom_star', 'black_star',
'fat_star', 'custom_fat_star', 'black_fat_star',
'heart', 'custom_heart', 'black_heart',
'ball', 'custom_ball', 'black_ball');
$size = array(16, 19, 23);
$i = 0;
foreach($cats as $c) {
foreach($size as $s) {
$file = $c.'_'.$s;
$row[$file] = '
';
}
$i++;
$row[$file] .= $i % 3 ? '' : '
';
}
$img_set = new Typecho_Widget_Helper_Form_Element_Radio(
'img_set', $row, 'star_19',
'选取評分图片', '请选取适合模板的图片. 若改用自己创建的图片会更有个性.');
$form->addInput($img_set);
$num = new Typecho_Widget_Helper_Form_Element_Text(
'num', NULL, 5,
'图片数量(总分)', '建议 5 或 10 个, 决定之后, 请不要随意更改, 以免计分错乱.');
$num->input->setAttribute('class', 'mini');
$form->addInput($num->addRule('isInteger', _t('请填入一个数字')));
$tmp = $registered ? $options->plugin('PostRating')->color : '#fa0';
$color_demo = '
';
$color = new Typecho_Widget_Helper_Form_Element_Text(
'color', NULL, '#fa0',
'图片主体颜色', $color_demo);
$color->input->setAttribute('class', 'mini');
$color->input->setAttribute('style', 'float:left');
$form->addInput($color);
$tmp = $registered ? $options->plugin('PostRating')->un_rating_color : '#aaa';
$color_demo = '
';
$un_rating_color = new Typecho_Widget_Helper_Form_Element_Text(
'un_rating_color', NULL, '#aaa',
'未评分的颜色', $color_demo);
$un_rating_color->input->setAttribute('class', 'mini');
$un_rating_color->input->setAttribute('style', 'float:left');
$form->addInput($un_rating_color);
$tmp = $registered ? $options->plugin('PostRating')->hover_color : '#f00';
$color_demo = '
';
$hover_color = new Typecho_Widget_Helper_Form_Element_Text(
'hover_color', NULL, '#f00',
'鼠标悬停颜色', $color_demo);
$hover_color->input->setAttribute('class', 'mini');
$hover_color->input->setAttribute('style', 'float:left');
$form->addInput($hover_color);
$tmp = $registered ? $options->plugin('PostRating')->active_color : '#0a0';
$color_demo = '
';
$active_color = new Typecho_Widget_Helper_Form_Element_Text(
'active_color', NULL, '#0a0',
'评分完成颜色', $color_demo);
$active_color->input->setAttribute('class', 'mini');
$active_color->input->setAttribute('style', 'float:left');
$form->addInput($active_color);
$before = new Typecho_Widget_Helper_Form_Element_Text(
'before', NULL, '请为这篇文章评分: ',
'图片的前置语', '此语句在文章或独立页面, 可以评分时才出现.');
$form->addInput($before);
$after = new Typecho_Widget_Helper_Form_Element_Text(
'after', NULL, '( 已有 {person} 人评分, 平均得分: {avg} 分 )',
'图片的后置语', '此语句在文章或独立页面, 已有评分才出现, 首页或其它页会在鼠标提示.');
$form->addInput($after);
$no_rating = new Typecho_Widget_Helper_Form_Element_Text(
'no_rating', NULL, '( 这篇文章尚未评分 )',
'未评分提示语', '此语句在文章或独立页面, 从未被评分过才出现, 首页或其它页会在鼠标提示.
以上三个语句可用参数:{person} 评分人数、{avg} 平均分数.');
$form->addInput($no_rating);
$finished = new Typecho_Widget_Helper_Form_Element_Text(
'finished', NULL, '您评了 {rating} 分, 谢谢!',
'评分完提示语', '此语句在评分完才出现. 可用参数:{rating} 评分.');
$form->addInput($finished);
$need_login = new Typecho_Widget_Helper_Form_Element_Radio(
'need_login', array(0 => '所有访客皆可评分', 1 => '用戶登录后才可评分'), 0,
'访客评分权', '以 IP 或昵称作判断, 每人在每篇文章只能评分一次. ( 管理者不在此限 )');
$form->addInput($need_login);
$drop_table = new Typecho_Widget_Helper_Form_Element_Radio(
'drop_table', array(0 => '不刪除', 1 => '刪除'), 0,
'禁用时删除所有评分', '若决定以后不再使用此插件, 或想清空评分数据, 请选择删除后再禁用.