Exemplo n.º 1
0
 public function _initialize()
 {
     $APP_NAME = $this->app['app_alias'];
     $this->APP_NAME = $APP_NAME;
     $data['APP_NAME'] = $APP_NAME;
     $havent_read = S('cat_havent_read' . is_login());
     if (empty($havent_read)) {
         $map['rec_uid'] = is_login();
         $map['readed'] = 0;
         $havent_read = D('cat_send')->where($map)->count();
         S('cat_havent_read' . is_login(), $havent_read, 60);
     }
     $data['havent_read'] = $havent_read;
     $map['status'] = 1;
     $tree = D('cat_entity')->where($map)->order('sort desc')->select();
     $menu_list = array('left' => array(array('tab' => 'home', 'title' => '首页', 'href' => U('Cat/index/index'))), 'right' => array(array('tab' => 'post', 'title' => '发布'), array('tab' => 'orders', 'title' => '个人中心', 'href' => U('Cat/center/my'))));
     foreach ($tree as $category) {
         if ($category['show_nav']) {
             $menu = array('tab' => 'category_' . $category['id'], 'title' => $category['alias'], 'href' => U('Cat/index/li', array('name' => $category['name'])));
             $menu_list['left'][] = $menu;
         }
         if (CheckCanPostEntity(is_login(), $category['id']) && $category['show_post']) {
             $menu = array('tab' => 'category_' . $category['id'], 'title' => $category['alias'], 'href' => U('Cat/index/post', array('name' => $category['name'])));
             $menu_list['right'][0]['children'][] = $menu;
         }
     }
     $this->assign('sub_menu', $menu_list);
     $this->assign('current', 'home');
     $this->assign($data);
 }
 /**
  * 执行添加信息
  */
 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 = M('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 = M('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 = M('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 = M('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;
             M('Data')->where($map_data)->delete();
         }
         $dataModel = M('Data');
         foreach ($_POST 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 = op_h($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 (M('Common/Module')->isInstalled('Weibo')) {
                         //安装了轻博客模块
                         $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('cat/index/info', array('info_id' => $rs_info), null, true);
                         $weiboModel = M('Weibo/Weibo');
                         $weiboModel->addWeibo("我发布了一个新的 " . $entity['alias'] . "信息 【" . $info['title'] . "】:" . $postUrl);
                     }
                 }
                 $this->success('发布成功。' . cookie('score_tip'));
             }
         }
     } else {
         $this->error('发布失败。');
     }
 }
Exemplo n.º 3
0
 private function requireCanPost($aEntityId)
 {
     $entity = D('store_entity')->find($aEntityId);
     /**权限认证**/
     $can_post = CheckCanPostEntity(is_login(), $aEntityId);
     if (!$can_post) {
         $this->error('对不起,您无权发布。');
         return $entity;
     }
     return $entity;
     /**权限认证end*/
 }
Exemplo n.º 4
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('发布失败。');
     }
 }