public function getData($id)
 {
     $contentHandler = new ContentHandlerModel();
     $res = $this->where(array('news_id' => $id))->find();
     $res['content'] = $contentHandler->displayHtmlContent($res['content']);
     return $res;
 }
示例#2
0
 public function getList($map, $field = '*', $limit = 0, $order = 'create_time desc')
 {
     if ($limit) {
         $list = $this->where($map)->field($field)->order($order)->limit($limit)->select();
     } else {
         $list = $this->where($map)->field($field)->select();
     }
     $contentHandler = new ContentHandlerModel();
     foreach ($list as &$val) {
         $val['description'] = $contentHandler->displayHtmlContent($val['description']);
     }
     return $list;
 }
 /**
  * 帖子发布跟编辑。
  */
 public function doEdit()
 {
     $aPostId = I('post.post_id', 0, 'intval');
     $aGroupId = I('post.group_id', 0, 'intval');
     $aTitle = I('post.title', '', 'text');
     $aCategory = I('post.category', 0, 'intval');
     $attach_ids = I('post.attach_ids', '', 'text');
     if ($attach_ids) {
         $aContent = I('post.content', '', 'filter_content');
         $img_ids = explode(',', $attach_ids);
         //把图片和内容结合
         //    dump($img_ids);
         foreach ($img_ids as &$v) {
             $v = D('Picture')->where(array('status' => 1))->getById($v);
             if (!is_bool(strpos($v['path'], 'http://'))) {
                 $v = $v['path'];
             } else {
                 $v = getRootUrl() . substr($v['path'], 1);
             }
             $v = '<p><img src="' . $v . '" style=""/></p><br>';
         }
         $img_ids = implode('', $img_ids);
         $aContent = $img_ids . $aContent;
         $contentHandler = new ContentHandlerModel();
         $aContent = $contentHandler->filterHtmlContent($aContent);
         //把图片和内容结合END
     } else {
         $aContent = I('post.content', '', 'filter_content');
     }
     if (is_joined($aGroupId) != 1) {
         $this->error('您无发布帖子权限');
     }
     //判断是不是编辑模式
     $isEdit = $aPostId ? true : false;
     //如果是编辑模式,确认当前用户能编辑帖子
     $this->requireLogin();
     $this->requireGroupExists($aGroupId);
     if ($isEdit) {
         $this->requirePostExists($aPostId);
         $this->checkActionLimit('edit_group_post', 'GroupPost', $aPostId, is_login(), true);
         $this->checkAuth('Group/Index/edit', get_post_admin($aPostId), '您无编辑帖子权限');
     } else {
         $this->checkActionLimit('add_group_post', 'GroupPost', 0, is_login(), true);
         $this->checkAuth('Group/Index/addPost', -1, '您无添加帖子权限');
     }
     if (empty($aGroupId)) {
         $this->error('请选择帖子所在的群组');
     }
     if (empty($aTitle)) {
         $this->error('请填写帖子标题');
     }
     if (empty($aContent)) {
         $this->error('请填写帖子内容');
     }
     $model = M('GroupPost');
     $cover = get_pic($aContent);
     $cover = $cover == null ? '' : $cover;
     $len = modC('SUMMARY_LENGTH', 50);
     if ($isEdit) {
         $data = array('id' => $aPostId, 'title' => $aTitle, 'summary' => mb_substr(text($aContent), 0, $len, 'utf-8'), 'cover' => $cover, 'content' => $aContent, 'parse' => 0, 'group_id' => $aGroupId, 'cate_id' => $aCategory);
         $result = $model->editPost($data);
         //添加到最新动态
         $dynamic['group_id'] = $aGroupId;
         $dynamic['uid'] = is_login();
         $dynamic['type'] = 'update_post';
         $dynamic['row_id'] = $aPostId;
         M('GroupDynamic')->addDynamic($dynamic);
         if (!$result) {
             $this->error('编辑失败:' . $model->getError());
         }
     } else {
         $data = array('uid' => is_login(), 'title' => $aTitle, 'summary' => mb_substr(text($aContent), 0, $len, 'utf-8'), 'cover' => $cover, 'content' => $aContent, 'parse' => 0, 'group_id' => $aGroupId, 'cate_id' => $aCategory);
         $result = $model->createPost($data);
         if (!$result) {
             $this->error('发表失败。');
         }
         $aPostId = $result;
         //添加到最新动态
         $dynamic['group_id'] = $aGroupId;
         $dynamic['uid'] = is_login();
         $dynamic['type'] = 'post';
         $dynamic['row_id'] = $aPostId;
         M('GroupDynamic')->addDynamic($dynamic);
         //增加活跃度
         M('Group')->where(array('id' => $aGroupId))->setInc('activity');
         M('GroupMember')->where(array('group_id' => $aGroupId, 'uid' => is_login()))->setInc('activity');
     }
     //实现发布帖子发布图片轻博客(公共内容)
     $group = M('Group')->getGroup($aGroupId);
     $this->sendWeibo($aPostId, $isEdit, $group);
     //显示成功消息
     $message = $isEdit ? '编辑成功。' : '发表成功。' . cookie('score_tip');
     $this->success($message, U('Group/Index/detail', array('id' => $aPostId)));
 }
 public function getSimpleListPage($map, $page = 1, $order = 'create_time desc', $r = 20, $field = '*')
 {
     $totalCount = $this->where($map)->count();
     if ($totalCount) {
         $list = $this->where($map)->page($page, $r)->order($order)->field($field)->select();
         $contentHandler = new ContentHandlerModel();
         foreach ($list as &$val) {
             $val['content'] = $contentHandler->displayHtmlContent($val['content']);
         }
     }
     return array($list, $totalCount);
 }
 private function _doEditQusetion()
 {
     $aId = I('post.id', 0, 'intval');
     $need_audit = modC('QUESTION_NEED_AUDIT', 1, 'Question');
     if ($aId) {
         $data['id'] = $aId;
         $now_data = M('Mob/Question')->getData($aId);
         $this->checkAuth('Question/Index/edit', $now_data['uid'], '没有编辑该问题权限!');
         if ($need_audit) {
             $data['status'] = 2;
         }
         $this->checkActionLimit('edit_question', 'question', $now_data['id'], get_uid());
     } else {
         $this->checkAuth('Question/Index/add', -1, '没有发布问题的权限!');
         $this->checkActionLimit('add_question', 'question', 0, get_uid());
         $data['uid'] = get_uid();
         $data['answer_num'] = $data['good_question'] = 0;
         if ($need_audit) {
             $data['status'] = 2;
         } else {
             $data['status'] = 1;
         }
     }
     $data['title'] = I('post.title', '', 'text');
     $data['category'] = I('post.category', 0, 'intval');
     $attach_ids = I('post.attach_ids', '0', 'op_t');
     if ($attach_ids) {
         $data['description'] = I('post.description', '', 'filter_content');
         $img_ids = explode(',', $attach_ids);
         //把图片和内容结合
         //    dump($img_ids);
         foreach ($img_ids as &$v) {
             $v = D('Picture')->where(array('status' => 1))->getById($v);
             if (!is_bool(strpos($v['path'], 'http://'))) {
                 $v = $v['path'];
             } else {
                 $v = getRootUrl() . substr($v['path'], 1);
             }
             $v = '<p><img src="' . $v . '" style=""/></p><br>';
         }
         $img_ids = implode('', $img_ids);
         //  dump($img_ids);
         $data['description'] = $img_ids . $data['description'];
         $contentHandler = new ContentHandlerModel();
         $data['description'] = $contentHandler->filterHtmlContent($data['description']);
         //把图片和内容结合END
     } else {
         $data['description'] = I('post.description', '', 'filter_content');
     }
     if (!mb_strlen($data['title'], 'utf-8')) {
         $this->error('标题不能为空!');
     }
     $res = M('Mob/Question')->editData($data);
     $title = $aId ? "编辑" : "提";
     if ($res) {
         if (!$aId) {
             $aId = $res;
             if ($need_audit) {
                 $data['status'] = 1;
                 $data['info'] = $title . '问题成功!' . ' 请等待审核~';
                 $this->ajaxReturn($data);
             }
         }
         if (M('Common/Module')->isInstalled('Weibo')) {
             //安装了轻博客模块
             //同步到轻博客
             $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('Mob/Question/questionDetail', array('id' => $aId));
             $weiboModel = M('Mob/Weibo');
             $weiboModel->addWeibo("我问了一个问题【" . $data['title'] . "】:" . $postUrl);
         }
         $data['status'] = 1;
         $data['info'] = $title . '问题成功!' . ' 请等待审核~';
     } else {
         $data['status'] = 0;
         $data['info'] = $title . '问题失败!';
     }
     $this->ajaxReturn($data);
 }
示例#6
0
 public function doAddInfo()
 {
     unset($_POST['__hash__']);
     $entity_id = I('post.entity_id', 0, 'intval');
     $info_id = I('post.info_id', 0, 'intval');
     $aOverTime = I('post.over_time', '', 'op_t');
     $entity = D('cat_entity')->find($entity_id);
     /**权限认证**/
     $can_post = CheckCanPostEntity(is_login(), $entity_id);
     if (!$can_post) {
         $this->error('对不起,您无权发布。');
     }
     /**权限认证end*/
     $info['title'] = I('post.title', '', 'op_t');
     if ($info['title'] == '') {
         $this->error('必须输入标题');
     }
     if (mb_strlen($info['title'], 'utf-8') > 40) {
         $this->error('标题过长。');
     }
     $info['create_time'] = time();
     if ($info_id != 0) {
         //保存逻辑
         $info = D('cat_info')->find($info_id);
         $this->checkAuth('Cat/Index/editInfo', $info['uid'], '你没有编辑该条信息的权限!');
         $this->checkActionLimit('cat_edit_info', 'cat_info', $info['id']);
         if ($aOverTime != '') {
             $info['over_time'] = strtotime($aOverTime);
         }
         $info['id'] = $info_id;
         $res = D('cat_info')->save($info);
         $rs_info = $info['id'];
         if ($res) {
             action_log('cat_edit_info', 'cat_info', $info['id']);
         }
     } else {
         $this->checkAuth('Cat/Index/addInfo', -1, '你没有发布信息的权限!');
         $this->checkActionLimit('cat_add_info', 'cat_info');
         //新增逻辑
         $info['entity_id'] = $entity_id;
         $info['uid'] = is_login();
         if ($entity['need_active'] && !is_administrator()) {
             $info['status'] = 2;
         } else {
             $info['status'] = 1;
         }
         if (isset($_POST['over_time'])) {
             $info['over_time'] = strtotime($_POST['over_time']);
         }
         $rs_info = D('cat_info')->add($info);
         if ($rs_info) {
             action_log('cat_add_info', 'cat_info');
         }
     }
     $rs_data = 1;
     if ($rs_info != 0) {
         if ($info_id != 0) {
             $map_data['info_id'] = $info_id;
             D('Data')->where($map_data)->delete();
         }
         $dataModel = D('Data');
         //处理房屋的图片
         if ($entity_id == 2) {
             $listl = array('zhaopian1' => "", 'zhaopian2' => "", 'zhaopian3' => "", 'zhaopian4' => "", 'zhaopian5' => "");
             $list = $_POST;
             foreach ($list as $key => &$v) {
                 $array = explode(",", $list['zhaopian']);
                 foreach ($array as $k => $val) {
                     $list['zhaopian' . ($k + 1)] = $val;
                 }
                 unset($k, $val);
             }
             unset($list['zhaopian']);
             $list = array_merge($listl, $list);
         } else {
             if ($entity_id == 3) {
                 $list = $_POST;
                 if ($list['zhaopian']) {
                     $img_ids = explode(',', $list['zhaopian']);
                     //把图片和内容结合
                     foreach ($img_ids as &$v) {
                         $v = M('Picture')->where(array('status' => 1))->getById($v);
                         if (!is_bool(strpos($v['path'], 'http://'))) {
                             $v = $v['path'];
                         } else {
                             $v = getRootUrl() . substr($v['path'], 1);
                         }
                         $v = '<p><img src="' . $v . '" style=""/></p><br>';
                     }
                     $img_ids = implode('', $img_ids);
                     $list['jieshao'] = $img_ids . $list['jieshao'];
                     $contentHandler = new ContentHandlerModel();
                     $list['jieshao'] = $data['content'] = $contentHandler->filterHtmlContent($list['jieshao']);
                     //把图片和内容结合END
                 }
                 unset($list['zhaopian']);
             } else {
                 $list = $_POST;
                 if ($list['zhaopian']) {
                     $img_ids = explode(',', $list['zhaopian']);
                     //把图片和内容结合
                     foreach ($img_ids as &$v) {
                         $v = M('Picture')->where(array('status' => 1))->getById($v);
                         if (!is_bool(strpos($v['path'], 'http://'))) {
                             $v = $v['path'];
                         } else {
                             $v = getRootUrl() . substr($v['path'], 1);
                         }
                         $v = '<p><img src="' . $v . '" style=""/></p><br>';
                     }
                     $img_ids = implode('', $img_ids);
                     $list['des'] = $img_ids . $list['des'];
                     $contentHandler = new ContentHandlerModel();
                     $list['des'] = $data['content'] = $contentHandler->filterHtmlContent($list['des']);
                     //把图片和内容结合END
                 }
                 unset($list['zhaopian']);
             }
         }
         // dump($list);exit;
         foreach ($list as $key => $v) {
             if ($key != 'entity_id' && $key != 'over_time' && $key != 'ignore' && $key != 'info_id' && $key != 'title' && $key != '__hash__' && $key != 'file') {
                 if (is_array($v)) {
                     $rs_data = $rs_data && $dataModel->addData($key, implode(',', $v), $rs_info, $entity_id);
                 } else {
                     $v = filter_content($v);
                     $rs_data = $rs_data && $dataModel->addData($key, $v, $rs_info, $entity_id);
                 }
             }
             if ($rs_data == 0) {
                 $this->error($dataModel->getError());
             }
         }
         if ($rs_info && $rs_data) {
             $this->assign('jumpUrl', U('Cat/Index/info', array('info_id' => $rs_info)));
             if ($entity['need_active']) {
                 $this->success('发布成功。' . cookie('score_tip') . ' 请耐心等待管理员审核。通过审核后该信息将出现在前台页面中。');
             } else {
                 if ($entity['show_nav']) {
                     if (D('Common/Module')->isInstalled('Weibo')) {
                         //安装了微博模块
                         $postUrl = U('detail', array('info_id' => $rs_info), null, true);
                         $weiboModel = D('Weibo');
                         $weiboModel->addWeibo(is_login(), "我发布了一个新的 " . $entity['alias'] . "信息 【" . $info['title'] . "】:" . $postUrl);
                     }
                 }
                 $this->success('发布成功。' . cookie('score_tip'));
             }
         }
     } else {
         $this->error('发布失败。');
     }
 }
 public function doSendBlog()
 {
     $aId = I('post.id', 0, 'intval');
     $data['category'] = I('post.category', 0, 'intval');
     if ($aId) {
         $data['id'] = $aId;
         $now_data = M('News/News')->getData($aId);
         if ($now_data['status'] == 1) {
             $this->error('该资讯已被审核,不能被编辑!');
         }
         $category = M('News/newsCategory')->where(array('status' => 1, 'id' => $data['category']))->find();
         if ($category) {
             if ($category['can_post']) {
                 if ($category['need_audit']) {
                     $data['status'] = 2;
                 } else {
                     $data['status'] = 1;
                 }
             } else {
                 $this->error('该分类不能投稿!');
             }
         } else {
             $this->error('该分类不存在或被禁用!');
         }
         $data['status'] = 2;
         $data['template'] = $now_data['detail']['template'] ?: '';
     } else {
         $this->checkActionLimit('add_news', 'news', 0, is_login(), true);
         $data['uid'] = get_uid();
         $data['sort'] = $data['position'] = $data['view'] = $data['comment'] = $data['collection'] = 0;
         $category = M('News/NewsCategory')->where(array('status' => 1, 'id' => $data['category']))->find();
         if ($category) {
             if ($category['can_post']) {
                 if ($category['need_audit']) {
                     $data['status'] = 2;
                 } else {
                     $data['status'] = 1;
                 }
             } else {
                 $this->error('该分类不能投稿!');
             }
         } else {
             $this->error('该分类不存在或被禁用!');
         }
         $data['template'] = '';
     }
     $data['title'] = I('post.title', '', 'text');
     $data['cover'] = I('post.one_attach_id', 0, 'intval');
     $data['description'] = I('post.description', '', 'text');
     $data['dead_line'] = I('post.dead_line', '', 'text');
     $data['content_img'] = I('post.attach_ids', '', 'text');
     if ($data['dead_line'] == '') {
         $data['dead_line'] = 99999999999;
     } else {
         $data['dead_line'] = strtotime($data['dead_line']);
     }
     $data['source'] = I('post.source', '', 'text');
     $data['content'] = I('post.content', '', 'html');
     if (!mb_strlen($data['title'], 'utf-8')) {
         $this->error('标题不能为空!');
     }
     if (mb_strlen($data['content'], 'utf-8') < 20) {
         $this->error('内容不能少于20个字!');
     }
     if ($data['content_img']) {
         $img_ids = explode(',', $data['content_img']);
         //把图片和内容结合
         foreach ($img_ids as &$v) {
             $v = D('Picture')->where(array('status' => 1))->getById($v);
             if (!is_bool(strpos($v['path'], 'http://'))) {
                 $v = $v['path'];
             } else {
                 $v = getRootUrl() . substr($v['path'], 1);
             }
             $v = '<p><img src="' . $v . '" style=""/></p><br>';
         }
         $img_ids = implode('', $img_ids);
         $data['content'] = $img_ids . $data['content'];
         $contentHandler = new ContentHandlerModel();
         $data['content'] = $contentHandler->filterHtmlContent($data['content']);
         //把图片和内容结合END
     }
     //  dump($data['content']);exit;
     $res = M('News/news')->editData($data);
     // dump(M('News/newsModel')->getLastSql());exit;
     $title = $aId ? "编辑" : "新增";
     if ($res) {
         if (!$aId) {
             $aId = $res;
             if ($category['need_audit']) {
                 $return['status'] = 1;
                 $return['info'] = $title . '资讯成功!请等待审核~';
             }
         }
         $return['status'] = 1;
         $return['info'] = $title . '资讯成功!';
     } else {
         $return['status'] = 0;
         $return['info'] = $title . '资讯失败!';
     }
     $this->ajaxReturn($return);
 }
 /**
  * 帖子回复
  */
 public function AddForumComment($is_edit = 0)
 {
     $attach_ids = I('post.attach_ids', '', 'text');
     if ($attach_ids) {
         $aContent = I('post.forumcontent', 0, 'op_t');
         $img_ids = explode(',', $attach_ids);
         //把图片和内容结合
         //    dump($img_ids);
         foreach ($img_ids as &$v) {
             $v = D('Picture')->where(array('status' => 1))->getById($v);
             if (!is_bool(strpos($v['path'], 'http://'))) {
                 $v = $v['path'];
             } else {
                 $v = getRootUrl() . substr($v['path'], 1);
             }
             $v = '<p><img src="' . $v . '" style=""/></p><br>';
         }
         $img_ids = implode('', $img_ids);
         //  dump($img_ids);
         $aContent = $img_ids . $aContent;
         $contentHandler = new ContentHandlerModel();
         $aContent = $contentHandler->filterHtmlContent($aContent);
         //把图片和内容结合END
     } else {
         $aContent = I('post.forumcontent', 0, 'op_t');
     }
     $aPostId = I('post.forumId', 0, 'intval');
     $post_id = $aPostId;
     $content = $aContent;
     if ($is_edit == 0) {
         $content = $this->filterPostContent($content);
         //确认有权限回复
         $this->requireAllowReply($post_id);
         //检测回复时间限制
         $uid = is_login();
         $near = M('ForumPostReply')->where(array('uid' => $uid))->order('create_time desc')->find();
         $cha = time() - $near['create_time'];
         if ($cha > 10) {
             //添加到数据库
             $model = M('Mob/ForumPostReply');
             $result = $model->addReply($post_id, $content);
             if (!$result) {
                 $this->error('回复失败:' . $model->getError());
             }
             //显示成功消息
             $this->success('回复成功。', 'refresh');
         } else {
             $this->error('请10秒之后再回复');
         }
     } else {
         $reply_id = intval($post_id);
         //对帖子内容进行安全过滤
         $content = $this->filterPostContent($content);
         $content = filter_content($content);
         $this->checkAuth('Forum/Index/doReplyEdit', $this->get_expect_ids(0, $reply_id, 0, 0, 1), '你没有编辑该评论权限!');
         if (!$content) {
             $this->error("评论内容不能为空!");
         }
         $data['content'] = $content;
         $data['update_time'] = time();
         $post_id = M('forum_post_reply')->where(array('id' => intval($reply_id), 'status' => 1))->getField('post_id');
         $reply = M('forum_post_reply')->where(array('id' => intval($reply_id)))->save($data);
         if ($reply) {
             S('post_replylist_' . $post_id, null);
             $this->success('编辑评论成功', U('Forum/Index/detail', array('id' => $post_id)));
         } else {
             $this->error("编辑评论失败");
         }
     }
 }