header = array('AjaxComments_Plugin', 'headerScript'); Typecho_Plugin::factory('Widget_Archive')->footer = array('AjaxComments_Plugin', 'footerScript'); } /** * 禁用插件方法,如果禁用失败,直接抛出异常 * * @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) { $options = Helper::options(); $wn_img = '×'; $er_img = '×'; $ok_img = ''; $file_contents = ''; $db = Typecho_Db::get(); $select = $db->fetchRow($db ->select('cid')->from('table.comments') ->where('table.comments.status = ?', 'approved') ->limit(1) ); if ($select){ $select = $db->fetchRow($db ->select('cid', 'created', 'type', 'slug')->from('table.contents') ->where('table.contents.cid = ?', $select['cid']) ); $select['text'] = ''; //fix php5.6 warning $select = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($select); $permalink = $select['permalink']; $fh = fopen($permalink, 'r'); $file_contents = file_get_contents($permalink); fclose($fh); } else { echo $wn_img, ' 警告! 未能找到任何评论, 以下测试失败...
'; } $registered = $db->fetchRow($db ->select()->from('table.options') ->where('name = ?', 'plugin:AjaxComments') ); $jq_set = new Typecho_Widget_Helper_Form_Element_Radio( 'jq_set', array('0'=> '自己处理', '1'=> '随着本插件载入'), 1, 'jQuery 来源', '若选择 "随着本插件载入", 会从 CDN 自动载入 jQurey 1.8.3 到 header().'); $form->addInput($jq_set); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_comments : '#comments h4'; $trgar = explode(' ', $trg); $htm_trg = strtr( $trgar[0], array( '.' => 'class="', '#' => 'id="')); $htm_trg .= stristr($htm_trg, 'id=') ? '"' : ''; if (!isset($trgar[1])) { $trgar[1] = ''; $chkd = stripos($file_contents, $htm_trg) ? $ok_img : $wn_img; } else { $tmp = substr($file_contents, stripos($file_contents, $htm_trg), 80); $chkd = (stripos($file_contents, $htm_trg) && stristr($tmp, $trgar[1])) ? $ok_img : $wn_img; $trgar[1] = '<'. $trgar[1]. '>'; } if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $loadingLan = new Typecho_Widget_Helper_Form_Element_Text('loadingLan', NULL, '正在提交, 请稍候...', _t('等待提示'), _t('正在提交时的提示信息')); $loadingLan->input->setAttribute('style', 'float:left; width:200px;margin-right:10px'); $form->addInput($loadingLan->addRule('required', _t('必须填写等待提示'))); $subSuccess = new Typecho_Widget_Helper_Form_Element_Text('subSuccess', NULL, '评论提交成功', _t('成功提示'), _t('提交成功时的提示信息')); $subSuccess->input->setAttribute('style', 'float:left; width:200px;margin-right:10px'); $form->addInput($subSuccess->addRule('required', _t('必须填写成功提示'))); $errUsername = new Typecho_Widget_Helper_Form_Element_Text('errUsername', NULL, '必须填写用户名', _t('用户名提示'), _t('用户名为空时的提示信息')); $errUsername->input->setAttribute('style', 'float:left; width:200px;margin-right:10px'); $form->addInput($errUsername->addRule('required', _t('必须填写用户名提示'))); $errEmail = new Typecho_Widget_Helper_Form_Element_Text('errEmail', NULL, '必须填写邮箱地址', _t('电子邮箱提示'), _t('电子邮箱为空时的提示信息')); $errEmail->input->setAttribute('style', 'float:left; width:200px;margin-right:10px'); $form->addInput($errEmail->addRule('required', _t('必须填写电子邮箱提示'))); $errRuleEmail = new Typecho_Widget_Helper_Form_Element_Text('errRuleEmail', NULL, '邮箱地址不正确', _t('电子邮箱错误提示'), _t('电子邮箱格式错误时的提示信息')); $errRuleEmail->input->setAttribute('style', 'float:left; width:200px;margin-right:10px'); $form->addInput($errRuleEmail->addRule('required', _t('必须填写电子邮箱错误提示'))); $errText = new Typecho_Widget_Helper_Form_Element_Text('errText', NULL, '必须填写评论内容', _t('评论内容提示'), _t('评论内容为空时的提示信息')); $errText->input->setAttribute('style', 'float:left; width:200px;margin-right:10px'); $form->addInput($errText->addRule('required', _t('评论内容提示'))); $_comments = new Typecho_Widget_Helper_Form_Element_Text( '_comments', NULL, $trg, '评论总数', ' '. $chkd. ' <'. $htm_trg. '>'. $trgar[1]. '有 xx 条评论...'); $_comments->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_comments); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_comment_list : '.comment-list'; $htm_trg = strtr( $trg, array( '.' => 'class="', '#' => 'id="')); $chkd = (stripos($file_contents, $htm_trg)) ? $ok_img : $wn_img; if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $_comment_list = new Typecho_Widget_Helper_Form_Element_Text( '_comment_list', NULL, $trg, '评论主体', ' '. $chkd. ' <ol '. $htm_trg. '">'); $_comment_list->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_comment_list); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_comment_reply : '.comment-reply'; $htm_trg = strtr( $trg, array( '.' => 'class="', '#' => 'id="')); $chkd = (stripos($file_contents, $htm_trg)) ? $ok_img : $wn_img; if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $_comment_reply = new Typecho_Widget_Helper_Form_Element_Text( '_comment_reply', NULL, $trg, '回复', ' '. $chkd. ' <div '. $htm_trg. '"><a href=" ...'); $_comment_reply->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_comment_reply); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_comment_form : '#comment_form'; $htm_trg = strtr( $trg, array( '.' => 'class="', '#' => 'id="')); $htm_trg .= stristr($htm_trg, 'id=') ? '"' : ''; $chkd = (stripos($file_contents, $htm_trg)) ? $ok_img : $wn_img; if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $_comment_form = new Typecho_Widget_Helper_Form_Element_Text( '_comment_form', NULL, $trg, '表单', ' '. $chkd. ' <form .. '. $htm_trg. ' ... >'); $_comment_form->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_comment_form); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_respond : '.respond'; $htm_trg = strtr( $trg, array( '.' => 'class="', '#' => 'id="')); $htm_trg .= stristr($htm_trg, 'id=') ? '"' : ''; $chkd = (stripos($file_contents, $htm_trg)) ? $ok_img : $wn_img; if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $_respond = new Typecho_Widget_Helper_Form_Element_Text( '_respond', NULL, $trg, '评论框', ' '. $chkd. ' <div id="respond-post- xx " '. $htm_trg. ' ... >'); $_respond->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_respond); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_textarea : '.textarea'; $htm_trg = strtr( $trg, array( '.' => 'class="', '#' => 'id="')); $htm_trg .= stristr($htm_trg, 'id=') ? '"' : ''; $chkd = (stripos($file_contents, $htm_trg)) ? $ok_img : $wn_img; if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $_textarea = new Typecho_Widget_Helper_Form_Element_Text( '_textarea', NULL, $trg, '內容', ' '. $chkd. ' <textarea .. '. $htm_trg. ' ... >'); $_textarea->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_textarea); $trg = $registered ? Helper::options()->plugin('AjaxComments')->_submit : '.submit'; $htm_trg = strtr( $trg, array( '.' => 'class="', '#' => 'id="')); $htm_trg .= stristr($htm_trg, 'id=') ? '"' : ''; $chkd = (stripos($file_contents, $htm_trg)) ? $ok_img : $wn_img; if (!stristr($htm_trg, 'id=') && !stristr($htm_trg, 'class=')) $chkd = $er_img; $_submit = new Typecho_Widget_Helper_Form_Element_Text( '_submit', NULL, $trg, '提交', ' '. $chkd. ' <input .. '. $htm_trg. ' ... >

提示不正常项目请查找模板比对, 修改后先保存设置, 再回来重新检查.
id 使用 ( # ) ; class 使用 ( . ) ; 请勿直接输入 "id" 或 "class".
( 测试结果僅供参考, 若还有不正常, 请详细修改以上对应标签. ) '); $_submit->input->setAttribute('style', 'float:left; width:200px;'); $form->addInput($_submit); $wn_msg = ''; if ($select){ $wn_msg = (stripos($file_contents, 'id="cancel-comment-reply-link"')) ? '已采用内置嵌套评论 ' . $ok_img : $er_img . ' 不支持内置嵌套评论.';} if ($options->commentsThreaded == 0) $wn_msg = $wn_img . ' 嵌套回复功能未开启, 测试失败.'; echo '当前使用的外观是 [ ', $options->theme, ' ] ', $wn_msg, ''; } /** * 个人用户的配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form * @return void */ public static function personalConfig(Typecho_Widget_Helper_Form $form){} /** * 自定义 header * * @param $header * @param $that * @return mixed */ public static function headerScript($header, $that) { if (Helper::options()->plugin('AjaxComments')->jq_set == 1) { echo "\n"; } return $header; } /** * 自定义 footer * @param $that */ public static function footerScript($that) { if (Typecho_Widget::widget('Widget_Archive')->is('single')) include('AjaxComments/typecho-ajax-comm.php'); } }