説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AskLogic.php 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * User: xyz
  4. * Date: 2022/8/12
  5. * Time: 9:31
  6. */
  7. namespace app\api\logic\v1;
  8. use think\Db;
  9. class AskLogic
  10. {
  11. // 拼装html代码
  12. public function GetReplyHtml($data = array())
  13. {
  14. $ReplyHtml = '';
  15. // 如果是需要审核的评论则返回空
  16. if (empty($data['is_review'])) return $ReplyHtml;
  17. /*拼装html代码*/
  18. // 友好显示时间
  19. $data['add_time'] = friend_date($data['add_time']);
  20. // 处理内容格式
  21. $data['content'] = htmlspecialchars_decode($data['content']);
  22. if (!empty($data['at_users_id'])) {
  23. $data['content'] = '回复 @'.$data['at_usersname'].':&nbsp;'.$data['content'];
  24. }
  25. // 删除评论回答URL
  26. $DelAnswerUrl = $this->GetUrlData($data, 'DelAnswerUrl');
  27. // 拼装html
  28. $ReplyHtml = <<<EOF
  29. <li class="secend-li" id="{$data['answer_id']}_answer_li">
  30. <div class="head-secend">
  31. <a><img src="{$data['head_pic']}" style="width:30px;height:30px;border-radius:100%;margin-right: 16px;"></a>
  32. <strong>{$data['username']}</strong>
  33. <span style="margin:0 10px"> | </span>
  34. <span>{$data['add_time']}</span>
  35. <div style="flex-grow:1"></div>
  36. <span id="{$data['answer_id']}_replyA" onclick="replyUser('{$data['answer_pid']}','{$data['users_id']}','{$data['username']}','{$data['answer_id']}')" class="secend-huifu-btn" style="cursor: pointer;">回复</span>
  37. &nbsp;&nbsp;|&nbsp;&nbsp;
  38. <a data-url="{$DelAnswerUrl}" onclick="DataDel(this, '{$data['answer_id']}', 2)" class="secend-huifu-btn" style="cursor: pointer; color:red;">删除</a>
  39. </div>
  40. <div class="secend-huifu-text">
  41. {$data['content']}
  42. </div>
  43. </li>
  44. EOF;
  45. // 返回html
  46. $ReturnHtml = ['review' => false, 'htmlcode' => $ReplyHtml];
  47. return $ReturnHtml;
  48. }
  49. // Url处理
  50. public function GetUrlData($param = array(), $SpecifyUrl = null)
  51. {
  52. if (empty($param['ask_id'])) $param['ask_id'] = 0;
  53. $result = [];
  54. // 最新问题url
  55. $result['NewDateUrl'] = url('plugins/Ask/index');
  56. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=index';
  57. // 问题详情页url
  58. $result['AskDetailsUrl'] = url('plugins/Ask/details', ['ask_id'=>$param['ask_id']]);
  59. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=details&ask_id='.$param['ask_id'];
  60. // 推荐问题url
  61. $result['RecomDateUrl'] = url('plugins/Ask/index', ['type_id'=>0, 'is_recom'=>1]);
  62. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=index&is_recom=1';
  63. // 悬赏问题列表url
  64. $result['RewardUrl'] = url('plugins/Ask/index', ['type_id'=>0, 'is_recom'=>3]);
  65. // 等待回答url
  66. $result['PendingAnswerUrl'] = url('plugins/Ask/index', ['type_id'=>0, 'is_recom'=>2]);
  67. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=index&is_recom=2';
  68. // 提交回答url
  69. $result['AddAnswerUrl'] = url('plugins/Ask/ajax_add_answer', ['ask_id'=>$param['ask_id'], '_ajax'=>1], true, false, 1, 1, 0);
  70. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_add_answer&ask_id='.$param['ask_id'];
  71. // 删除回答url
  72. $result['DelAnswerUrl'] = url('plugins/Ask/ajax_del_answer', ['ask_id'=>$param['ask_id'], '_ajax'=>1], true, false, 1, 1, 0);
  73. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_del_answer&ask_id='.$param['ask_id'];
  74. // 点赞回答url
  75. $result['ClickLikeUrl'] = url('plugins/Ask/ajax_click_like', ['_ajax'=>1], true, false, 1, 1, 0);
  76. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_click_like';
  77. // 发布问题url
  78. $result['AddAskUrl'] = url('plugins/Ask/add_ask');
  79. // 提交问题url
  80. $result['SubmitAddAsk'] = url('plugins/Ask/add_ask', ['_ajax'=>1], true, false, 1, 1, 0);
  81. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=add_ask';
  82. // 编辑问题url
  83. $result['EditAskUrl'] = url('plugins/Ask/edit_ask', ['ask_id'=>$param['ask_id']]);
  84. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=edit_ask&ask_id='.$param['ask_id'];
  85. // 用户问题首页
  86. $result['UsersIndexUrl'] = url('plugins/Ask/ask_index');
  87. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ask_index';
  88. // 编辑回答url
  89. $result['EditAnswer'] = url('plugins/Ask/ajax_edit_answer');
  90. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_edit_answer';
  91. if ('ajax_edit_answer' == request()->action()) {
  92. $result['EditAnswer'] = url('plugins/Ask/ajax_edit_answer', ['_ajax'=>1], true, false, 1, 1, 0);
  93. }
  94. // 采纳最佳答案url
  95. $result['BestAnswerUrl'] = url('plugins/Ask/ajax_best_answer', ['ask_id'=>$param['ask_id'], '_ajax'=>1], true, false, 1, 1, 0);
  96. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_best_answer&ask_id='.$param['ask_id'];
  97. // 获取指定数量的评论数据(分页)
  98. $result['ShowCommentUrl'] = url('plugins/Ask/ajax_show_comment', ['ask_id'=>$param['ask_id'], '_ajax'=>1], true, false, 1, 1, 0);
  99. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_show_comment&ask_id='.$param['ask_id'].'&_ajax=1';
  100. // 创始人审核评论URL(前台)
  101. $result['ReviewCommentUrl'] = url('plugins/Ask/ajax_review_comment', ['ask_id'=>$param['ask_id'], '_ajax'=>1], true, false, 1, 1, 0);
  102. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_review_comment&ask_id='.$param['ask_id'].'&_ajax=1';
  103. // 创始人审核问题URL(前台)
  104. $result['ReviewAskUrl'] = url('plugins/Ask/ajax_review_ask', ['_ajax'=>1], true, false, 1, 1, 0);
  105. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=ajax_review_ask&_ajax=1';
  106. // 按点赞量排序url
  107. $result['AnswerLikeNum'] = url('plugins/Ask/details', ['ask_id' => $param['ask_id']], true, false, 1, 1, 0);
  108. // 等待回答url
  109. if (!empty($param['type_id'])) {
  110. $result['PendingAnswerUrl'] = url('plugins/Ask/index', ['type_id'=>$param['type_id'], 'is_recom'=>2]);
  111. // ROOT_DIR.'/index.php?m=plugins&c=Ask&a=index&type_id='.$param['type_id'].'&is_recom=2';
  112. }
  113. if (!empty($SpecifyUrl)) {
  114. if (!empty($result[$SpecifyUrl])) {
  115. return $result[$SpecifyUrl];
  116. }else{
  117. return $result['NewDateUrl'];
  118. }
  119. }else{
  120. return $result;
  121. }
  122. }
  123. /*
  124. * 获取限制提交频率
  125. */
  126. public function GetRateData(){
  127. $rate = [];
  128. $data = Db::name('weapp')->where(['code'=>'Ask'])->getField('data');
  129. $dataArr = unserialize($data);
  130. !empty($dataArr['rate']) && $rate = $dataArr['rate'];
  131. return $rate;
  132. }
  133. // 内容转义处理
  134. public function ContentDealWith($param = null)
  135. {
  136. if (!empty($param['content'])) {
  137. $content = $param['content'];
  138. }else if(!empty($param['ask_content'])){
  139. $content = $param['ask_content'];
  140. }else{
  141. return false;
  142. }
  143. // 斜杆转义
  144. $content = addslashes($content);
  145. // 过滤内容的style属性
  146. $content = preg_replace('/style(\s*)=(\s*)[\'|\"](.*?)[\'|\"]/i', '', $content);
  147. // 过滤内容的class属性
  148. $content = preg_replace('/class(\s*)=(\s*)[\'|\"](.*?)[\'|\"]/i', '', $content);
  149. return $content;
  150. }
  151. /*
  152. * 获取敏感词过滤设置信息
  153. */
  154. public function GetSensitiveData(){
  155. $sensitive = [];
  156. $data = Db::name('weapp')->where(['code'=>'Ask'])->getField('data');
  157. $dataArr = unserialize($data);
  158. !empty($dataArr['sensitive']) && $sensitive = $dataArr['sensitive'];
  159. if (!empty($sensitive['sensitive_data'])){
  160. $sensitive['sensitive_data'] = str_replace(",",",",$sensitive['sensitive_data']);
  161. $sensitive['sensitive_data'] = explode(",",$sensitive['sensitive_data']);
  162. }
  163. return $sensitive;
  164. }
  165. /*
  166. * 判断是否存在敏感词
  167. * @paramarray $list 定义敏感词一维数组
  168. * @paramstring $string 要过滤的内容
  169. * @returnstring $log 处理结果[敏感词个数,敏感词内容,替换后的字符串]
  170. */
  171. public function sensitive($list, $string){
  172. $count = 0; //违规词的个数
  173. $sensitiveWord = ''; //违规词
  174. $stringAfter = $string; //替换后的内容
  175. $pattern = "/" . implode("|", $list) . "/i"; //定义正则表达式
  176. if (preg_match_all($pattern, $string, $matches)) { //匹配到了结果
  177. $patternList = $matches[0]; //匹配到的数组
  178. $count = count($patternList);
  179. $sensitiveWord = implode(',', $patternList); //敏感词数组转字符串
  180. $replaceArray = array_combine($patternList, array_fill(0, count($patternList), '**')); //把匹配到的数组进行合并,替换使用
  181. $stringAfter = strtr($string, $replaceArray); //结果替换
  182. }
  183. return [$count,$sensitiveWord,$stringAfter];
  184. }
  185. }