开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 17

L/wp-plugin

forked from NextApp/wp-plugin
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
wp-plugin
/
modules
/
Comment.php
wp-plugin
/
modules
/
Comment.php
Comment.php 7.14 KB
一键复制 编辑 原始数据 按行查看 历史
Winter Lau 提交于 2014年09月11日 07:09 +08:00 . initial commit
<?php
class Nextapp_Comment extends Nextapp_Controller
{
public function indexAction()
{
$this->listAction();
}
public function listAction()
{
$postId = (int)$this->getParam('post') < 0 ? 0 : (int)$this->getParam('post', 0);
$fromComment = (int)$this->getParam('fromComment') < 0 ? 0 : (int)$this->getParam('fromComment', 0);
$fetchCount = (int)$this->getParam('fetchCount', 10);
$orderBy = 'comment_ID';
$sortMethod = $this->getParam('sortMethod');
if ($sortMethod == 'ascend') {
$order = 'ASC';
}elseif ($sortMethod == 'descend') {
$order = 'DESC';
}else {
$order = empty($postId) ? 'DESC' : 'ASC';
}
$orderWhere = $order == 'ASC' ? '>' : '<';
$userId = get_current_user_id();
$commentCount = 0;
$commentResult = array();
global $wp_version;
switch (substr($wp_version, 0, 3)) {
case '2.7':
case '2.8':
case '2.9':
case '3.0':
global $wpdb;
$where = '(comment_approved = \'1\'';
$where .= $userId > 0 ? ' OR (comment_approved = \'0\' AND user_id = \'' . $userId . '\'))' : ')';
$where .= empty($postId) ? '' : ' AND comment_post_ID = ' . $postId;
$result = $wpdb->get_results("SELECT COUNT(*) AS fetchCount FROM {$wpdb->comments} WHERE $where");
if (is_array($result)) {
$result = current($result);
if (is_object($result)) {
$commentCount = $result->fetchCount;
}
}
if ($commentCount > 0) {
$where .= empty($fromComment) ? '' : ' AND comment_ID ' . $orderWhere . ' ' . $fromComment;
$commentResult = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE $where ORDER BY $orderBy$order LIMIT $fetchCount");
}
break;
case '3.1':
default:
$GLOBALS['nextapp_userId'] = $userId;
$filterWhere = create_function('$clauses',
'global $wpdb; global $nextapp_userId;
if($nextapp_userId>0) {
$clauses[\'where\'] = "{$clauses[\'where\']} AND ($wpdb->comments.comment_approved = \'1\' OR ($wpdb->comments.comment_approved = \'0\' AND $wpdb->comments.user_id = \'$nextapp_userId\')) ";
}else {
$clauses[\'where\'] = "{$clauses[\'where\']} AND $wpdb->comments.comment_approved = \'1\' ";
}
return $clauses;
');
add_filter('comments_clauses', $filterWhere);
$commentCount = get_comments(array('post_id' => $postId, 'count' => true));
if ((int)$commentCount > 0) {
$GLOBALS['nextapp_args'] = array(
'orderWhere' => $orderWhere,
'fromComment' => $fromComment
);
$filterWhere = create_function('$clauses',
'global $wpdb; global $nextapp_args;
if(!empty($nextapp_args[\'fromComment\'])) {
$clauses[\'where\']="{$clauses[\'where\']} AND $wpdb->comments.comment_ID {$nextapp_args[\'orderWhere\']} {$nextapp_args[\'fromComment\']} ";
}
return $clauses;');
add_filter('comments_clauses', $filterWhere);
$commentResult = get_comments(array('post_id' => $postId, 'orderby' => $orderBy, 'order' => $order, 'number' => $fetchCount));
}
break;
}
$this->getXmlRoot()->commentCount = $commentCount;
if (is_array($commentResult) && count($commentResult) > 0) {
$node = $this->getXmlRoot()->comments;
foreach ($commentResult as $key => $comment) {
if (empty($comment->comment_ID)) {continue ;}
$node->comment[$key]->id = $comment->comment_ID;
$node->comment[$key]->post = $comment->comment_post_ID;
$node->comment[$key]->name = (object)$comment->comment_author;
$node->comment[$key]->title = (object)get_post_field('post_title', $comment->comment_post_ID);
$node->comment[$key]->email = (object)$comment->comment_author_email;
$node->comment[$key]->url = (object)$comment->comment_author_url;
$node->comment[$key]->body = (object)$comment->comment_content;
$node->comment[$key]->pubDate = $comment->comment_date;
}
}
$this->renderXml();
}
public function pubAction()
{
$comments = array(
'comment_post_ID' => (int)$this->getPost('post', 0),
'comment_content' => (string)$this->getPost('body'),
'comment_author' => (string)$this->getPost('name'),
'comment_author_email' => (string)$this->getPost('email'),
'comment_author_url' => (string)$this->getPost('url')
);
if (empty($comments['comment_post_ID'])) {
$this->renderError(self::ERROR_INVALID_PARAMETERS, 'Please specify the post ID.');
}
if (empty($comments['comment_content'])) {
$this->renderError(self::ERROR_INVALID_PARAMETERS, 'Please input post the content.');
}
$post = get_post($comments['comment_post_ID']);
if (empty($post)) {
$this->renderError(0, 'This post is not exists.');
}
if (!comments_open($comments['comment_post_ID'])) {
$this->renderError(0, __('Sorry, comments are closed for this item.'));
}
$userId = get_current_user_id();
if (empty($userId) && (get_option('comment_registration') || 'private' === get_post_status($post))) {
$this->renderError(0, __('Sorry, you must be logged in to post a comment.'));
}
if ($userId > 0) {
$comments['user_id'] = $userId;
$currentUser = wp_get_current_user();
empty($comments['comment_author']) && $comments['comment_author'] = $currentUser->display_name ? $currentUser->display_name : $currentUser->user_login;
empty($comments['comment_author_email']) && $comments['comment_author_email'] = $currentUser->user_email;
empty($comments['comment_author_url']) && $comments['comment_author_url'] = $currentUser->user_url;
}
# Repeated testing whether published.
global $wpdb;
$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '{$comments['comment_post_ID']}' AND comment_approved != 'trash' AND(comment_author = '{$comments['comment_author']}' ";
if ($comments['comment_author_email']) {
$dupe .= "OR comment_author_email = '{$comments['comment_author_email']}' ";
}
$dupe .= ") AND comment_content = '{$comments['comment_content']}' LIMIT 1";
if ($wpdb->get_var($dupe)) {
$this->renderError(0, __('Duplicate comment detected; it looks as though you&#8217;ve already said that!'));
}
$result = wp_new_comment($comments);
if (empty($result)) {
$this->renderError();
}else {
$message = '';
if (wp_get_comment_status($result) != 'approved') {
$message = __('Your comment is awaiting moderation.');
}
$this->renderSuccess(null, $message);
}
}
public function deleteAction()
{
$commentId = (int)$this->getParam('comment', 0);
if (empty($commentId)) {
$this->renderError(self::ERROR_INVALID_PARAMETERS);
}
if (!get_current_user_id()) {
$this->renderError(self::ERROR_NO_LOGINED);
}
$comment = get_comment($commentId);
if (empty($comment)) {
$this->renderError(0, 'This comment is not exists.');
}
global $wp_version;
switch (substr($wp_version, 0, 3)) {
case '2.7':
case '2.8':
case '2.9':
case '3.0':
$can = current_user_can('edit_post', $comment->comment_ID);
break;
default:
$can = current_user_can('edit_comment', $comment->comment_ID);
break;
}
if (empty($can)) {
$this->renderError(self::ERROR_PERMISSION_DENIED, 'Sorry, you didn\'t remove comments permissions.');
}
$result = wp_delete_comment($commentId);
if (empty($result)) {
$this->renderError();
}else {
$this->renderSuccess();
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

WordPress 的扩展插件
暂无标签
GPL-3.0
使用 GPL-3.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kyzone/wp-plugin.git
git@gitee.com:kyzone/wp-plugin.git
kyzone
wp-plugin
wp-plugin
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /