Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
LoveKKComment修复在正式版中评论报错问题,原因是正式版Helper::widgetById方法初始化未传入参数
Browse files Browse the repository at this point in the history
  • Loading branch information
ylqjgm committed Jan 8, 2019
1 parent 0793adf commit d9f850f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 64 additions & 23 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class LoveKKComment_Action extends Widget_Abstract_Users implements Widget_Inter
/**
* 构造函数
*
* @param $request
* @param $response
* @param null $params
* @param mixed $request 请求对象
* @param mixed $response 输出对象
* @param null $params 请求参数
*
* @throws Typecho_Plugin_Exception
*/
Expand All @@ -41,8 +41,8 @@ public function __construct($request, $response, $params = NULL)
*
* @access private
*
* @param string $act
* @param null $form
* @param string $act 当前操作
* @param mixed $form 表单对象
*/
private function html($act = 'forget', $form = NULL)
{
Expand Down Expand Up @@ -210,7 +210,7 @@ private function forgetForm()
*
* @access private
*
* @param int $uid
* @param int $uid 用户编号
*
* @return Typecho_Widget_Helper_Form
*/
Expand Down
69 changes: 50 additions & 19 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static public function personalConfig(Typecho_Widget_Helper_Form $form)
* @static
* @access public
*
* @param array $settings
* @param array $settings 配置数据
*
* @return string
* @throws Typecho_Plugin_Exception
Expand Down Expand Up @@ -283,8 +283,9 @@ static public function configCheck(array $settings)
* @static
* @access public
*
* @param $comment
* @param mixed $comment 评论对象
*
* @throws Typecho_Db_Exception
* @throws Typecho_Plugin_Exception
* @throws \PHPMailer\PHPMailer\Exception
*/
Expand All @@ -305,10 +306,11 @@ static public function doComment($comment)
* @static
* @access public
*
* @param $comment
* @param $edit
* @param $status
* @param mixed $comment 评论对象
* @param mixed $edit 编辑对象
* @param string $status 评论状态
*
* @throws Typecho_Db_Exception
* @throws Typecho_Plugin_Exception
* @throws \PHPMailer\PHPMailer\Exception
*/
Expand All @@ -332,8 +334,9 @@ static public function doApproved($comment, $edit, $status)
* @static
* @access public
*
* @param $comment
* @param mixed $comment 评论对象
*
* @throws Typecho_Db_Exception
* @throws Typecho_Plugin_Exception
* @throws \PHPMailer\PHPMailer\Exception
*/
Expand All @@ -349,25 +352,26 @@ static public function asyncApproved($comment)
* @static
* @access public
*
* @param $commentId
* @param bool $isApproved
* @param int $commentId 评论编号
* @param bool $isApproved 是否为审核操作
*
* @return bool|string
* @throws Typecho_Db_Exception
* @throws Typecho_Plugin_Exception
* @throws \PHPMailer\PHPMailer\Exception
*/
static public function sendMail($commentId, $isApproved = FALSE)
{
// 重新获取评论数据
$comment = Helper::widgetById('comments', $commentId);
$comment = self::getWidget('Comments', 'coid', $commentId);
// 收件人地址
$address = $comment->mail;
// 上级评论对象
$parentComment = NULL;
// 不是帖子发表者
if ( $comment->authorId != $comment->ownerId ) {
// 获取作者信息
$author = Helper::widgetById('users', $comment->ownerId);
$author = self::getWidget('Users', 'uid', $comment->ownerId);
// 收件地址
$address = $author->mail;
// 上级评论
Expand All @@ -377,7 +381,7 @@ static public function sendMail($commentId, $isApproved = FALSE)
// 评论回复
if ( 0 < $comment->parent ) {
// 获取上级对象
$parentComment = Helper::widgetById('comments', $comment->parent);
$parentComment = self::getWidget('Comments', 'coid', $comment->parent);
// 是否获取到且用户ID不同或邮件地址不同
if ( isset($parentComment->coid) && $comment->mail != $parentComment->mail ) {
// 收件地址
Expand Down Expand Up @@ -431,7 +435,7 @@ static public function sendMail($commentId, $isApproved = FALSE)
// 读取模板
$html = file_get_contents(dirname(__FILE__) . '/theme/reply.html');
// 获取文章
$post = Helper::widgetById('contents', $parentComment->cid);
$post = self::getWidget('Contents', 'cid', $parentComment->cid);
// 替换模板
$data['html'] = str_replace(
array(
Expand Down Expand Up @@ -545,7 +549,7 @@ static public function sendMail($commentId, $isApproved = FALSE)
* @static
* @access public
*
* @param $data
* @param array $data 公共参数
*
* @return bool|string
* @throws Typecho_Plugin_Exception
Expand Down Expand Up @@ -612,7 +616,7 @@ static public function sendCloud($data)
* @static
* @access public
*
* @param $param
* @param array $param 公共参数
*
* @return bool|string
* @throws Typecho_Plugin_Exception
Expand Down Expand Up @@ -705,7 +709,7 @@ static public function aliyun($param)
* @static
* @access public
*
* @param $param
* @param array $param 公共参数
*
* @return bool
* @throws Typecho_Plugin_Exception
Expand Down Expand Up @@ -814,14 +818,41 @@ static public function forgetLink()
}
}

/**
* 获取Widget对象
*
* @static
* @access private
*
* @param string $table 数据表名
* @param string $key 查询关键字
* @param mixed $val 数据数据
*
* @return mixed
* @throws Typecho_Db_Exception
*/
static private function getWidget($table, $key, $val)
{
// 类名称
$className = 'Widget_Abstract_' . $table;
// 初始化数据库
$db = Typecho_Db::get();
// 初始化类
$widget = new $className(Typecho_Request::getInstance(), Typecho_Widget_Helper_Empty::getInstance());
// 查询数据
$db->fetchRow($widget->select()->where($key . ' = ?', $val)->limit(1), array($widget, 'push'));

return $widget;
}

/**
* 阿里云签名
*
* @static
* @access private
*
* @param $param
* @param $accesssecret
* @param array $param 签名参数
* @param string $accesssecret 秘钥
*
* @return string
*/
Expand Down Expand Up @@ -854,7 +885,7 @@ static private function sign($param, $accesssecret)
* @static
* @access private
*
* @param $val
* @param string $val 要转换的编码
*
* @return string|string[]|null
*/
Expand All @@ -877,7 +908,7 @@ static private function percentEncode($val)
* @static
* @access private
*
* @param $param
* @param array $param 发送参数
*
* @return bool|string
*/
Expand Down
Loading

0 comments on commit d9f850f

Please sign in to comment.