├── image ├── error.png ├── loading.gif ├── success.png ├── warning.png ├── comment-list.jpg └── comment-children.jpg ├── README.md ├── CHANGELOG.md ├── js ├── ajaxcomment.min.js └── ajaxcomment.js ├── Action.php └── Plugin.php /image/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlwz/AjaxComment-For-Typecho/HEAD/image/error.png -------------------------------------------------------------------------------- /image/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlwz/AjaxComment-For-Typecho/HEAD/image/loading.gif -------------------------------------------------------------------------------- /image/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlwz/AjaxComment-For-Typecho/HEAD/image/success.png -------------------------------------------------------------------------------- /image/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlwz/AjaxComment-For-Typecho/HEAD/image/warning.png -------------------------------------------------------------------------------- /image/comment-list.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlwz/AjaxComment-For-Typecho/HEAD/image/comment-list.jpg -------------------------------------------------------------------------------- /image/comment-children.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlwz/AjaxComment-For-Typecho/HEAD/image/comment-children.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AjaxComment For Typecho 2 | 3 | Typecho插件:支持Ajax评论 4 | 5 | 开发者:情留メ蚊子 6 | 7 | 插件地址:[http://www.94qing.com/ajaxcomment-for-typecho.html](http://www.94qing.com/ajaxcomment-for-typecho.html) 8 | 9 | 最新版本:1.0.0.0 10 | 11 | 更新日期:2017-01-12 -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 1.0.0.2 *(2017-04-26)* 5 | ---------------------------- 6 | 7 | * 支持pjax 8 | 9 | Version 1.0.0.1 *(2017-04-17)* 10 | ---------------------------- 11 | 12 | * 修改代码错误 13 | * 使用异常方法输出评论检测 14 | 15 | Version 1.0.0.0 *(2017-01-12)* 16 | ---------------------------- 17 | 18 | * 第一个版本,Ajax评论 19 | -------------------------------------------------------------------------------- /js/ajaxcomment.min.js: -------------------------------------------------------------------------------- 1 | function AjaxComment_serialize(form){var field,l,s=[];if(typeof form=='object'&&form.nodeName=="FORM"){var len=form.elements.length;for(var i=0;i2){refchild.innerHTML+=childs[i].textContent}}}function insertBeforeHtml(refchild,refchild2,html){var childs=parseToDOMs(html);for(var i=0;i2){refchild.innerHTML=childs[i].textContent+refchild.innerHTML}}}function comment_append(content_html){var new_id=0;var regx=content_html.match(/id(\s+|)=(\s+|)("|'|)((.*?)comment-\d+)("|'|\s+|>)/g);if(regx){var tmp=regx[0];new_id=tmp.match(/\d+/g)[0];id_format=tmp.replace(new_id,'{id}').replace(/\s+/g,'').replace(/(id=|"|')/g,'')}if(new_id==0)content_html+=success_div;var form=_id(respond_id).getElementsByTagName('form')[0];form.getElementsByTagName('textarea')[0].value='';if(document.getElementsByClassName(comment_list_class_one).length==0){var comment_list=document.createElement(comment_list_element);comment_list.className=comment_list_class;_id(respond_id).parentNode.insertBefore(comment_list,_id(respond_id))}if(_id('comment-parent')==undefined){appendChildHtml(document.getElementsByClassName(comment_list_class_one)[0],content_html)}else{var parent_id=id_format.replace('{id}',_id('comment-parent').value);TypechoComment.cancelReply();if(_id(parent_id).getElementsByClassName(comment_children_list_class_one).length==0){var children_list=document.createElement(comment_children_list_element);children_list.className=comment_children_list_class;_id(parent_id).appendChild(children_list)}var refchild=_id(parent_id).getElementsByClassName(comment_children_list_class_one)[0];if(refchild.innerHTML.indexOf(comment_list_class_one)!=-1){refchild=refchild.getElementsByClassName(comment_list_class_one)[0]}else{var comment_list=document.createElement(comment_list_element);comment_list.className=comment_list_class;refchild.appendChild(comment_list);refchild=comment_list}if(comments_order=='DESC'){var refchild2=refchild.childNodes[0];insertBeforeHtml(refchild,refchild2,content_html)}else{appendChildHtml(refchild,content_html)}}if(new_id>0){appendChildHtml(_id(id_format.replace('{id}',new_id)),success_div);location.hash='#'+id_format.replace('{id}',new_id)}}function registAjaxCommentEvent(){if(respond_id==null||ajaxcomment_url==null){return}var r=_id(respond_id);if(null!=r){var forms=r.getElementsByTagName('form');if(forms.length>0){if(_id('AjaxComment_loading')==undefined){appendChildHtml(forms[0].getElementsByTagName('textarea')[0].parentNode,loading_div)}if(_id('AjaxComment_error')==undefined){appendChildHtml(forms[0].getElementsByTagName('textarea')[0].parentNode,error_div)}forms[0].onsubmit=function(){var form=_id(respond_id).getElementsByTagName('form')[0];_id('AjaxComment_loading').style.display='block';_id('AjaxComment_error').style.display='none';AjaxComment_post(ajaxcomment_url,AjaxComment_serialize(form),function(xhr){_id('AjaxComment_loading').style.display='none';if(xhr.status==200){comment_append(xhr.responseText)}else if(xhr.status==405){_id('AjaxComment_error').style.display='block';_id('AjaxComment_msg').innerHTML=xhr.responseText}else{alert('Ajax 未知错误')}});return false}}}}if(typeof(jQuery)!='undefined'&&jQuery.support.pjax){jQuery(document).on('pjax:success',function(event,data,status,xhr,options){var ma=data.match(/var(\s+)(respond_id(\s+|)=(\s+|)("|'|)respond-post-(\d+)("|'|)(\s+|);)/i);if(ma){eval(ma[2])}else{respond_id=null}var ma=data.match(/var(\s+)(ajaxcomment_url(\s+|)=(\s+|)("|'|)(.*?)("|'|)(\s+|);)/i);if(ma){eval(ma[2])}else{ajaxcomment_url=null}registAjaxCommentEvent()})}registAjaxCommentEvent(); -------------------------------------------------------------------------------- /js/ajaxcomment.js: -------------------------------------------------------------------------------- 1 | function AjaxComment_serialize(form) { 2 | var field, l, s = []; 3 | if (typeof form == 'object' && form.nodeName == "FORM") { 4 | var len = form.elements.length; 5 | for (var i = 0; i < len; i++) { 6 | field = form.elements[i]; 7 | if (field.name && !field.disabled && field.type != 'file' && field.type != 'reset' && field.type != 'submit' && field.type != 'button') { 8 | if (field.type == 'select-multiple') { 9 | l = form.elements[i].options.length; 10 | for (var j = 0; j < l; j++) { 11 | if (field.options[j].selected) s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[j].value); 12 | } 13 | } else if ((field.type != 'checkbox' && field.type != 'radio') || field.checked) { 14 | s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value); 15 | } 16 | } 17 | } 18 | } 19 | return s.join('&').replace(/%20/g, '+'); 20 | } 21 | 22 | function AjaxComment_post(url, data, callback) { 23 | var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); 24 | xhr.open('POST', url); 25 | xhr.onreadystatechange = function() { 26 | if (xhr.readyState == 4) callback && callback(xhr); 27 | }; 28 | xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 29 | xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 30 | xhr.send(data); 31 | return xhr; 32 | } 33 | 34 | function _id(id) { 35 | return document.getElementById(id); 36 | } 37 | 38 | function parseToDOMs(str) { 39 | var div = document.createElement('div'); 40 | div.innerHTML = str; 41 | return div.childNodes; 42 | } 43 | 44 | function appendChildHtml(refchild, html) { 45 | var childs = parseToDOMs(html); 46 | for (var i = 0; i < childs.length; i++) { 47 | if (childs[i].nodeType == 1) { 48 | refchild.appendChild(childs[i]); 49 | } else if (childs[i].nodeType == 3 && childs[i].textContent.length > 2) { 50 | refchild.innerHTML += childs[i].textContent; 51 | } 52 | } 53 | } 54 | 55 | function insertBeforeHtml(refchild, refchild2, html) { 56 | var childs = parseToDOMs(html); 57 | for (var i = 0; i < childs.length; i++) { 58 | if (childs[i].nodeType == 1) { 59 | refchild.insertBefore(childs[i], refchild2) 60 | } else if (childs[i].nodeType == 3 && childs[i].textContent.length > 2) { 61 | refchild.innerHTML = childs[i].textContent + refchild.innerHTML; 62 | } 63 | } 64 | } 65 | 66 | function comment_append(content_html) { 67 | var new_id = 0; 68 | var regx = content_html.match(/id(\s+|)=(\s+|)("|'|)((.*?)comment-\d+)("|'|\s+|>)/g); 69 | if (regx) { 70 | var tmp = regx[0]; 71 | new_id = tmp.match(/\d+/g)[0]; 72 | id_format = tmp.replace(new_id, '{id}').replace(/\s+/g, '').replace(/(id=|"|')/g, ''); 73 | } 74 | 75 | if (new_id == 0) content_html += success_div; 76 | 77 | var form = _id(respond_id).getElementsByTagName('form')[0]; 78 | form.getElementsByTagName('textarea')[0].value = ''; 79 | 80 | if (document.getElementsByClassName(comment_list_class_one).length == 0) { 81 | var comment_list = document.createElement(comment_list_element); 82 | comment_list.className = comment_list_class; 83 | _id(respond_id).parentNode.insertBefore(comment_list, _id(respond_id)); 84 | } 85 | 86 | if (_id('comment-parent') == undefined) { 87 | appendChildHtml(document.getElementsByClassName(comment_list_class_one)[0], content_html); 88 | } else { 89 | var parent_id = id_format.replace('{id}', _id('comment-parent').value); 90 | TypechoComment.cancelReply(); 91 | 92 | if (_id(parent_id).getElementsByClassName(comment_children_list_class_one).length == 0) { 93 | var children_list = document.createElement(comment_children_list_element); 94 | children_list.className = comment_children_list_class; 95 | _id(parent_id).appendChild(children_list); 96 | } 97 | 98 | var refchild = _id(parent_id).getElementsByClassName(comment_children_list_class_one)[0]; 99 | if (refchild.innerHTML.indexOf(comment_list_class_one) != -1) { 100 | refchild = refchild.getElementsByClassName(comment_list_class_one)[0]; 101 | } else { 102 | var comment_list = document.createElement(comment_list_element); 103 | comment_list.className = comment_list_class; 104 | refchild.appendChild(comment_list); 105 | refchild = comment_list; 106 | } 107 | if (comments_order == 'DESC') { 108 | var refchild2 = refchild.childNodes[0]; 109 | insertBeforeHtml(refchild, refchild2, content_html); 110 | } else { 111 | appendChildHtml(refchild, content_html); 112 | } 113 | } 114 | 115 | if (new_id > 0) { 116 | appendChildHtml(_id(id_format.replace('{id}', new_id)), success_div); 117 | location.hash = '#' + id_format.replace('{id}', new_id); 118 | } 119 | } 120 | 121 | function registAjaxCommentEvent() { 122 | if (respond_id == null || ajaxcomment_url == null) 123 | { 124 | return; 125 | } 126 | var r = _id(respond_id); 127 | if (null != r) { 128 | var forms = r.getElementsByTagName('form'); 129 | if (forms.length > 0) { 130 | if (_id('AjaxComment_loading') == undefined) { 131 | appendChildHtml(forms[0].getElementsByTagName('textarea')[0].parentNode, loading_div); 132 | } 133 | if (_id('AjaxComment_error') == undefined) { 134 | appendChildHtml(forms[0].getElementsByTagName('textarea')[0].parentNode, error_div); 135 | } 136 | 137 | forms[0].onsubmit = function() { 138 | var form = _id(respond_id).getElementsByTagName('form')[0]; 139 | _id('AjaxComment_loading').style.display = 'block'; 140 | _id('AjaxComment_error').style.display = 'none'; 141 | AjaxComment_post(ajaxcomment_url, AjaxComment_serialize(form), 142 | function(xhr) { 143 | _id('AjaxComment_loading').style.display = 'none'; 144 | if (xhr.status == 200) { 145 | comment_append(xhr.responseText); 146 | } else if (xhr.status == 405) { 147 | _id('AjaxComment_error').style.display = 'block'; 148 | _id('AjaxComment_msg').innerHTML = xhr.responseText; 149 | } else { 150 | alert('Ajax 未知错误'); 151 | } 152 | }); 153 | return false; 154 | } 155 | } 156 | } 157 | } 158 | 159 | if (typeof(jQuery) != 'undefined' && jQuery.support.pjax) { 160 | jQuery(document).on('pjax:success', 161 | function(event, data, status, xhr, options) { 162 | var ma = data.match(/var(\s+)(respond_id(\s+|)=(\s+|)("|'|)respond-post-(\d+)("|'|)(\s+|);)/i); 163 | if (ma) { 164 | eval(ma[2]); 165 | } else { 166 | respond_id = null 167 | } 168 | var ma = data.match(/var(\s+)(ajaxcomment_url(\s+|)=(\s+|)("|'|)(.*?)("|'|)(\s+|);)/i); 169 | if (ma) { 170 | eval(ma[2]); 171 | } else { 172 | ajaxcomment_url = null 173 | } 174 | registAjaxCommentEvent(); 175 | }); 176 | } 177 | 178 | registAjaxCommentEvent(); -------------------------------------------------------------------------------- /Action.php: -------------------------------------------------------------------------------- 1 | request->filter('int')->get('comment_post_ID'); 33 | $comment_parent = $this->request->filter('int')->get('parent'); 34 | if ($comment_parent == 0) { 35 | $comment_parent = $this->request->filter('int')->get('comment_parent'); 36 | } 37 | 38 | $post = Typecho_Widget::widget('Widget_Archive', 'type=single', 'cid=' . $comment_post_ID, false); 39 | if (!isset($post) || !($post instanceof Widget_Archive) || !$post->have() || !$post->is('single')) { 40 | $this->err('文章不存在'); 41 | } 42 | 43 | if (!$post->allow('comment')) { 44 | $this->err(_t('对不起,此内容的评论功能已经关闭!')); 45 | } 46 | 47 | $options = Typecho_Widget::widget('Widget_Options'); 48 | $settings = $options->plugin('AjaxComment'); 49 | $user = Typecho_Widget::widget('Widget_User'); 50 | 51 | /** 检查来源 */ 52 | if ($options->commentsCheckReferer) { 53 | $referer = $this->request->getReferer(); 54 | 55 | if (empty($referer)) { 56 | $this->err(_t('评论来源页错误')); 57 | } 58 | 59 | $refererPart = parse_url($referer); 60 | $currentPart = parse_url($post->permalink); 61 | 62 | if ($refererPart['host'] != $currentPart['host'] || 0 !== strpos($refererPart['path'], $currentPart['path'])) { 63 | //自定义首页支持 64 | if ('page:' . $post->cid == $options->frontPage) { 65 | $currentPart = parse_url(rtrim($options->siteUrl, '/') . '/'); 66 | 67 | if ($refererPart['host'] != $currentPart['host'] || 0 !== strpos($refererPart['path'], $currentPart['path'])) { 68 | $this->err(_t('评论来源页错误')); 69 | } 70 | } else { 71 | $this->err(_t('评论来源页错误')); 72 | } 73 | } 74 | } 75 | 76 | $comment = array(); 77 | $comment['permalink'] = $post->pathinfo; 78 | $comment['type'] = 'comment'; 79 | $comment['text'] = $this->request->text; 80 | $comment['parent'] = $comment_parent; 81 | 82 | if (!$user->hasLogin()) { 83 | $comment['author'] = $this->request->filter('trim')->author; 84 | $comment['mail'] = $this->request->filter('trim')->mail; 85 | $comment['url'] = $this->request->filter('trim')->url; 86 | 87 | /** 修正用户提交的url */ 88 | if (!empty($comment['url'])) { 89 | $urlParams = parse_url($comment['url']); 90 | if (!isset($urlParams['scheme'])) { 91 | $comment['url'] = 'http://' . $comment['url']; 92 | } 93 | } 94 | } else { 95 | $comment['author'] = $user->screenName; 96 | $comment['mail'] = $user->mail; 97 | $comment['url'] = $user->url; 98 | } 99 | 100 | if ($settings->comment_needchinese) { 101 | if (!preg_match('/[一-龥]/u', $comment['text'])) { 102 | $this->err('评论内容中必须含有中文'); 103 | } 104 | } 105 | 106 | Typecho_Plugin::factory('Widget_Feedback')->finishComment = array($this, 'Widget_Feedback_finishComment'); 107 | 108 | try { 109 | $commentWidget = Typecho_Widget::widget('Widget_Feedback', 'checkReferer=false', $comment, false); 110 | $commentWidget->action(); 111 | } catch (Exception $e) { 112 | $this->err($e->getMessage()); 113 | } 114 | } 115 | 116 | /** 117 | * 输出错误 118 | * 119 | * @param $errmsg 120 | */ 121 | public function err($errmsg) 122 | { 123 | header('HTTP/1.1 405 Method Not Allowed'); 124 | echo $errmsg; 125 | exit; 126 | } 127 | 128 | /** 129 | * 评论后续处理 130 | * 131 | * @access public 132 | * @param object $comments 评论信息 133 | * @return void 134 | */ 135 | public function Widget_Feedback_finishComment($comments) 136 | { 137 | $options = Typecho_Widget::widget('Widget_Options'); 138 | $options->commentsPageBreak = 0; 139 | 140 | $_themeDir = rtrim($options->themeFile($options->theme), '/') . '/'; 141 | $ajaxfile = $_themeDir . 'comments.php'; 142 | if (file_exists($ajaxfile)) { 143 | $file_content = file_get_contents($ajaxfile); 144 | $check_code = "return true; ?>"; 145 | $file_content = $check_code . $file_content . " $comments->cid); 150 | $comments_Archive = Typecho_Widget::widget('Widget_Comments_Archive', $parameter); 151 | if (!$comments_Archive->have()) { 152 | $this->err('获取评论出错'); 153 | } 154 | 155 | $db = Typecho_Db:: get(); 156 | $parentids = array(); 157 | $parentids[] = $comments->coid; 158 | 159 | $parent = $comments->parent; 160 | while ($parent) { 161 | $parentids[] = $parent; 162 | $parentRows = $db->fetchRow($db->select('parent') 163 | ->from('table.comments') 164 | ->where('coid = ? AND status = ?', $parent, 'approved') 165 | ->limit(1)); 166 | $parent = $parentRows['parent']; 167 | } 168 | $this->getlistComments($comments, $comments_Archive, $parentids); 169 | return; 170 | } 171 | 172 | private function getlistComments($comments, $comments_Archive, $parentids, $lv = 0) 173 | { 174 | while ($comments_Archive->next()) { 175 | if ($comments_Archive->coid == $comments->coid) { 176 | /* 177 | if ($lv == 0 && count($comments_Archive->stack) == 1) { 178 | $singleCommentOptions = ''; 179 | } else { 180 | $singleCommentOptions = 'before=&after='; 181 | } 182 | */ 183 | $singleCommentOptions = 'before=&after='; 184 | $comments_Archive->length = 1; 185 | $comments_Archive->stack = array($comments->coid => $comments_Archive->row); 186 | $comments_Archive->listComments($singleCommentOptions); 187 | return true; 188 | } elseif (in_array($comments_Archive->coid, $parentids)) { 189 | $comments_Archive->stack = $comments_Archive->children; 190 | if ($this->getlistComments($comments, $comments_Archive, $parentids, $lv++)) { 191 | return true; 192 | } 193 | } 194 | } 195 | return false; 196 | } 197 | 198 | /** 199 | * 绑定动作 200 | * 201 | * @access public 202 | * @return void 203 | */ 204 | public function action() 205 | { 206 | $this->on($this->request->is('do=post'))->post_comment(); 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /Plugin.php: -------------------------------------------------------------------------------- 1 | afterRender = array( 45 | 'AjaxComment_Plugin', 46 | 'Widget_Archive_afterRender' 47 | ); 48 | 49 | Helper::addAction('ajaxcomment', 'AjaxComment_Action'); 50 | } 51 | 52 | /** 53 | * 禁用插件方法,如果禁用失败,直接抛出异常 54 | * 55 | * @static 56 | * @access public 57 | * @return void 58 | * @throws Typecho_Plugin_Exception 59 | */ 60 | public static function deactivate() 61 | { 62 | Helper::removeAction('ajaxcomment'); 63 | } 64 | 65 | /** 66 | * 获取插件配置面板 67 | * 68 | * @access public 69 | * @param Typecho_Widget_Helper_Form $form 配置面板 70 | * @return void 71 | */ 72 | public static function config(Typecho_Widget_Helper_Form $form) 73 | { 74 | $options = Typecho_Widget::widget('Widget_Options'); 75 | $plugin_url = $options->pluginUrl . '/' . basename(dirname(__FILE__)) . '/'; 76 | 77 | $note = '


78 | 1、打开当前主题下的comments.php文件
79 | 2、评论主体设置方法:搜索【listComments】,如果为listComments()则使用默认值,否则按照before的元素设置
80 | 3、评论嵌套设置方法:搜索【threadedComments】,如果没有找到则使用默认,否则查找【第二个 threadedComments】使用关键词上级的元素
81 | 4、以上方法仅对标准结构的主题
'; 82 | 83 | $compression_open = new Typecho_Widget_Helper_Form_Element_Checkbox('ajaxcomment_open', array('ajaxcomment_open' => '开启 Ajax 评论'), 'ajaxcomment_open', _t('是否开启 Ajax 评论')); 84 | $form->addInput($compression_open); 85 | 86 | $comment_list_element = new Typecho_Widget_Helper_Form_Element_Text('comment_list_element', null, 'ol', '评论主体元素', '     <ol class="comment-list">'); 87 | $comment_list_element->input->setAttribute('style', 'float:left; width:200px;'); 88 | $form->addInput($comment_list_element); 89 | 90 | $comment_list_class = new Typecho_Widget_Helper_Form_Element_Text('comment_list_class', null, 'comment-list', '评论主体样式', '     <ol class="comment-list">'); 91 | $comment_list_class->input->setAttribute('style', 'float:left; width:200px;'); 92 | $form->addInput($comment_list_class); 93 | 94 | 95 | $comment_children_list_element = new Typecho_Widget_Helper_Form_Element_Text('comment_children_list_element', null, 'div', '评论嵌套元素', '     <div class="comment-list">'); 96 | $comment_children_list_element->input->setAttribute('style', 'float:left; width:200px;'); 97 | $form->addInput($comment_children_list_element); 98 | 99 | $comment_children_list_class = new Typecho_Widget_Helper_Form_Element_Text('comment_children_list_class', null, 'comment-children', '评论嵌套样式', '     <div class="comment-children">' . $note); 100 | $comment_children_list_class->input->setAttribute('style', 'float:left; width:200px;'); 101 | $form->addInput($comment_children_list_class); 102 | 103 | $comment_needchinese = new Typecho_Widget_Helper_Form_Element_Checkbox('comment_needchinese', array('comment_needchinese' => '评论内容中必须含有中文'), 'comment_needchinese', _t('其他设置')); 104 | $form->addInput($comment_needchinese); 105 | 106 | if (!$options->commentsThreaded) { 107 | echo ' 评论回复功能未启用, 请先在 "设置"->"评论"->"评论显示" 启用评论回复.
'; 108 | } 109 | 110 | $img = '



评论主体说明:
'; 111 | $img .= '


评论镶嵌说明:
'; 112 | echo ''; 115 | } 116 | 117 | public static function configHandle($settings, $isInit) 118 | { 119 | $db = Typecho_Db::get(); 120 | if (!$settings['comment_list_element']) { 121 | $settings['comment_list_element'] = 'ol'; 122 | } 123 | if (!$settings['comment_list_class']) { 124 | $settings['comment_list_class'] = 'comment-list'; 125 | } 126 | if (!$settings['comment_children_list_element']) { 127 | $settings['comment_children_list_element'] = 'div'; 128 | } 129 | if (!$settings['comment_children_list_class']) { 130 | $settings['comment_children_list_class'] = 'comment-children'; 131 | } 132 | 133 | $pluginName = 'plugin:AjaxComment'; 134 | $select = $db->select()->from('table.options')->where('name = ?', $pluginName); 135 | $options = $db->fetchAll($select); 136 | if (empty($settings)) { 137 | if (!empty($options)) { 138 | $db->query($db->delete('table.options')->where('name = ?', $pluginName)); 139 | } 140 | } else { 141 | if (empty($options)) { 142 | $db->query($db->insert('table.options')->rows(array( 143 | 'name' => $pluginName, 144 | 'value' => serialize($settings), 145 | 'user' => 0 146 | ))); 147 | } else { 148 | foreach ($options as $option) { 149 | $value = unserialize($option['value']); 150 | $value = array_merge($value, $settings); 151 | $db->query($db->update('table.options') 152 | ->rows(array('value' => serialize($value))) 153 | ->where('name = ?', $pluginName) 154 | ->where('user = ?', $option['user'])); 155 | } 156 | } 157 | } 158 | } 159 | 160 | /** 161 | * 个人用户的配置面板 162 | * 163 | * @access public 164 | * @param Typecho_Widget_Helper_Form $form 165 | * @return void 166 | */ 167 | public static function personalConfig(Typecho_Widget_Helper_Form $form) 168 | { 169 | } 170 | 171 | public static function Widget_Archive_afterRender($archive) 172 | { 173 | if (!$archive->is('single')) { 174 | return; 175 | } 176 | if (!$archive->allow('comment')) { 177 | return; 178 | } 179 | 180 | $options = Typecho_Widget::widget('Widget_Options'); 181 | $settings = $options->plugin('AjaxComment'); 182 | if (!$settings->ajaxcomment_open) { 183 | return; 184 | } 185 | 186 | $plugin_url = $options->pluginUrl . '/' . basename(dirname(__FILE__)) . '/'; 187 | ?> 188 | 205 | '; 207 | } 208 | 209 | } --------------------------------------------------------------------------------