DCommentPlugin.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | d_comment [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 DaliyCode All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: DaliyCode <3471677985@qq.com> <author_url:dalicode.com>
  8. // +----------------------------------------------------------------------
  9. namespace plugins\d_comment;
  10. use cmf\lib\Plugin;
  11. use think\Db;
  12. class DCommentPlugin extends Plugin {
  13. public $info = [
  14. 'name' => 'DComment',
  15. 'title' => '通用评论',
  16. 'description' => '文章评论插件',
  17. 'status' => 1,
  18. 'author' => 'code048',
  19. 'version' => '1.3',
  20. 'demo_url' => 'http://www.hongmengy.com',
  21. 'author_url' => 'http://www.hongmengy.com',
  22. ];
  23. public $hasAdmin = 1;
  24. public function install() {
  25. return true;
  26. }
  27. public function uninstall() {
  28. return true;
  29. }
  30. //实现的comment钩子方法
  31. public function comment($param) {
  32. $comments = Db::name('comment')->alias('c')
  33. ->join('__USER__ u', 'c.user_id = u.id', 'left')
  34. ->join('__USER__ ut', 'c.to_user_id = ut.id', 'left')
  35. ->field('c.*,u.user_nickname as username,ut.user_nickname as to_username')
  36. ->where('c.delete_time=0 and c.status=1 and object_id=' . (int) $param['object_id'])
  37. ->order('c.create_time DESC')
  38. ->paginate();
  39. $this->assign("page", $comments->render());
  40. $this->assign('comments', $comments);
  41. $config = $this->getConfig();
  42. $this->assign('total', $comments->total());
  43. $this->assign($config);
  44. $this->assign($param);
  45. return $this->fetch('widget');
  46. }
  47. }