public function filterHtmlContent($content)
 {
     $content = html($content);
     $content = $this->beforeSave($content);
     $content = filterBase64($content);
     //检测图片src是否为图片并进行过滤
     $content = filterImage($content);
     return $content;
 }
 public function doEdit($post_id = null, $forum_id = 0, $title, $content)
 {
     $post_id = intval($post_id);
     $forum_id = intval($forum_id);
     $title = op_t($title);
     $content = op_h($content);
     //判断是不是编辑模式
     $isEdit = $post_id ? true : false;
     $forum_id = intval($forum_id);
     //如果是编辑模式,确认当前用户能编辑帖子
     if ($isEdit) {
         $this->requireAllowEditPost($post_id);
     }
     //确认当前论坛能发帖
     $this->requireForumAllowPublish($forum_id);
     if ($title == '') {
         $this->error('请输入标题。');
     }
     if ($forum_id == 0) {
         $this->error('请选择发布的版块。');
     }
     if (strlen($content) < 20) {
         $this->error('发表失败:内容长度不能小于20');
     }
     $content = filterBase64($content);
     //检测图片src是否为图片并进行过滤
     $content = filterImage($content);
     //写入帖子的内容
     $model = D('ForumPost');
     if ($isEdit) {
         $data = array('id' => intval($post_id), 'title' => $title, 'content' => $content, 'parse' => 0, 'forum_id' => intval($forum_id));
         $result = $model->editPost($data);
         if (!$result) {
             $this->error('编辑失败:' . $model->getError());
         }
     } else {
         $data = array('uid' => is_login(), 'title' => $title, 'content' => $content, 'parse' => 0, 'forum_id' => $forum_id);
         $before = getMyScore();
         $tox_money_before = getMyToxMoney();
         $result = $model->createPost($data);
         $after = getMyScore();
         $tox_money_after = getMyToxMoney();
         if (!$result) {
             $this->error('发表失败:' . $model->getError());
         }
         $post_id = $result;
     }
     //发布帖子成功,发送一条微博消息
     $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('Forum/Index/detail', array('id' => $post_id));
     $weiboApi = new WeiboApi();
     $weiboApi->resetLastSendTime();
     //实现发布帖子发布图片微博(公共内容)
     $type = 'feed';
     $feed_data = array();
     //解析并成立图片数据
     $arr = array();
     preg_match_all("/<[img|IMG].*?src=[\\'|\"](.*?(?:[\\.gif|\\.jpg|\\.png]))[\\'|\"].*?[\\/]?>/", $data['content'], $arr);
     //匹配所有的图片
     if (!empty($arr[0])) {
         $feed_data['attach_ids'] = '';
         $dm = "http://{$_SERVER['HTTP_HOST']}" . __ROOT__;
         //前缀图片多余截取
         $max = count($arr['1']) > 9 ? 9 : count($arr['1']);
         for ($i = 0; $i < $max; $i++) {
             $tmparray = strpos($arr['1'][$i], $dm);
             if (!is_bool($tmparray)) {
                 $path = mb_substr($arr['1'][$i], strlen($dm), strlen($arr['1'][$i]) - strlen($dm));
                 $result_id = D('Home/Picture')->where(array('path' => $path))->getField('id');
             } else {
                 $path = $arr['1'][$i];
                 $result_id = D('Home/Picture')->where(array('path' => $path))->getField('id');
                 if (!$result_id) {
                     $result_id = D('Home/Picture')->add(array('path' => $path, 'url' => $path, 'status' => 1, 'create_time' => time()));
                 }
             }
             $feed_data['attach_ids'] = $feed_data['attach_ids'] . ',' . $result_id;
         }
         $feed_data['attach_ids'] = substr($feed_data['attach_ids'], 1);
     }
     $feed_data['attach_ids'] != false && ($type = "image");
     //开始发布微博
     if ($isEdit) {
         $weiboApi->sendWeibo("我更新了帖子【" . $title . "】:" . $postUrl, $type, $feed_data);
     } else {
         $weiboApi->sendWeibo("我发表了一个新的帖子【" . $title . "】:" . $postUrl, $type, $feed_data);
     }
     //显示成功消息
     $message = $isEdit ? '编辑成功。' : '发表成功。' . getScoreTip($before, $after) . getToxMoneyTip($tox_money_before, $tox_money_after);
     $this->success($message, U('Forum/Index/detail', array('id' => $post_id)));
 }