Exemple #1
0
 /**
  * 发布活动
  * @param int    $id
  * @param int    $cover_id
  * @param string $title
  * @param string $explain
  * @param string $sTime
  * @param string $eTime
  * @param string $address
  * @param int    $limitCount
  * @param string $deadline
  * autor:xjw129xjt
  */
 public function doPost($id = 0, $cover_id = 0, $title = '', $explain = '', $sTime = '', $eTime = '', $address = '', $limitCount = 0, $deadline = '', $type_id = 0)
 {
     if (!is_login()) {
         $this->error('请登陆后再投稿。');
     }
     if (!$cover_id) {
         $this->error('请上传封面。');
     }
     if (trim(op_t($title)) == '') {
         $this->error('请输入标题。');
     }
     if ($type_id == 0) {
         $this->error('请选择分类。');
     }
     if (trim(op_h($explain)) == '') {
         $this->error('请输入内容。');
     }
     if (trim(op_h($address)) == '') {
         $this->error('请输入地点。');
     }
     if ($sTime < $deadline) {
         $this->error('报名截止不能大于活动开始时间');
     }
     if ($deadline == '') {
         $this->error('请输入截止日期');
     }
     if ($sTime > $eTime) {
         $this->error('活动开始时间不能大于活动结束时间');
     }
     $content = D('Event')->create();
     $content['explain'] = op_h($content['explain']);
     $content['title'] = op_t($content['title']);
     $content['sTime'] = strtotime($content['sTime']);
     $content['eTime'] = strtotime($content['eTime']);
     $content['deadline'] = strtotime($content['deadline']);
     $content['type_id'] = intval($type_id);
     if ($id) {
         $content_temp = D('Event')->find($id);
         if (!is_administrator(is_login())) {
             //不是管理员则进行检测
             if ($content_temp['uid'] != is_login()) {
                 $this->error('小样儿,可别学坏。别以为改一下页面元素就能越权操作。');
             }
         }
         $content['uid'] = $content_temp['uid'];
         //权限矫正,防止被改为管理员
         $rs = D('Event')->save($content);
         $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('Event/Index/detail', array('id' => $id));
         $weiboApi = new WeiboApi();
         $weiboApi->resetLastSendTime();
         $weiboApi->sendWeibo("我修改了活动【" . $title . "】:" . $postUrl);
         if ($rs) {
             $this->success('编辑成功。', U('detail', array('id' => $content['id'])));
         } else {
             $this->success('编辑失败。', '');
         }
     } else {
         if (C('NEED_VERIFY') && !is_administrator()) {
             $content['status'] = 0;
             $tip = '但需管理员审核通过后才会显示在列表中,请耐心等待。';
             $user = query_user(array('username', 'nickname'), is_login());
             D('Common/Message')->sendMessage(C('USER_ADMINISTRATOR'), "{$user['nickname']}发布了一个活动,请到后台审核。", $title = '活动发布提醒', U('Admin/Event/verify'), is_login(), 2);
         }
         $rs = D('Event')->add($content);
         //同步到微博
         $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('Event/Index/detail', array('id' => $rs));
         $weiboApi = new WeiboApi();
         $weiboApi->resetLastSendTime();
         $weiboApi->sendWeibo("我发布了一个新的活动【" . $title . "】:" . $postUrl);
         if ($rs) {
             $this->success('发布成功。' . $tip, U('index'));
         } else {
             $this->success('发布失败。', '');
         }
     }
 }
 public function addGroup()
 {
     if (!is_login()) {
         $this->apiError('请登陆后再发起活动。');
     }
     //基本信息
     $aTitle = I('title', '', 'op_t');
     $aDetail = I('detail', '', 'op_h');
     $aTypeId = I('type_id', 0, 'intval');
     /* $aBackground = I('background', 0, 'intval');*/
     $aType = I('type', 0, 'intval');
     $aLogo = I('logo', 0, 'intval');
     $aId = I('id', 0, 'intval');
     /*   if (!$aBackground) {
              $this->apiError('请上传封面。');
          }*/
     if (trim(op_t($aTitle)) == '') {
         $this->apiError('请输入标题。');
     }
     if ($aTypeId == 0) {
         $this->apiError('请选择分类。');
     }
     if (trim(op_h($aDetail)) == '') {
         $this->apiError('请填写群组介绍。');
     }
     /*     if (!$aLogo) {
                $this->apiError('请上传背景');
            }*/
     $data = D('Group/Group')->create();
     $data['detail'] = $aDetail;
     $data['title'] = $aTitle;
     $data['logo'] = $aLogo;
     /* $data['background'] = $aBackground;*/
     $data['type'] = $aType;
     $data['type_id'] = $aTypeId;
     $data['create_time'] = time();
     $data['uid'] = is_login();
     //根据id查看是否已有活动
     if ($aId) {
         $Group = D('Group/Group')->find($aId);
         if (!is_administrator(is_login())) {
             //不是管理员则进行检测
             if ($Group['uid'] != is_login()) {
                 $this->apiError('无权编辑');
             }
         }
         //编辑基本信息
         $result = D('Group/Group')->where(array('id' => $aId))->save($data);
         $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('Event/Index/group', array('id' => $aId));
         $weiboApi = new WeiboApi();
         $weiboApi->resetLastSendTime();
         $weiboApi->sendWeibo("我修改了群组【" . $aTitle . "】:" . $postUrl);
         if ($result) {
             $this->apiSuccess('编辑成功。', U('detail', array('id' => $data['id'])));
         } else {
             $this->apiError('编辑失败。');
         }
     } else {
         if (modC('NEED_VERIFY', 1, 'group') && !is_administrator()) {
             $data['status'] = 0;
             $user = query_user(array('username', 'nickname'), is_login());
             D('Common/Message')->sendMessage(C('USER_ADMINISTRATOR'), "{$user['nickname']}发布了一个活动,请到后台审核。", $title = '活动发布提醒', U('Admin/Group/verify'), is_login(), 2);
         }
         $Group = D('Group/Group')->add($data);
         //同步到微博
         $postUrl = "http://{$_SERVER['HTTP_HOST']}" . U('Group/Index/group', array('id' => $Group));
         $weiboModel = D('Weibo/Weibo');
         $weiboModel->addWeibo("我发布了一个新的活动【" . $aTitle . "】:" . $postUrl);
         if ($Group) {
             $this->apiSuccess('发布成功。但需管理员审核通过后才会显示在列表中,请耐心等待。');
         } else {
             $this->apiError('发布失败。');
         }
     }
 }
 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)));
 }
Exemple #4
0
 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');
     }
     //写入帖子的内容
     $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();
     if ($isEdit) {
         $weiboApi->sendWeibo("我更新了帖子【" . $title . "】:" . $postUrl);
     } else {
         $weiboApi->sendWeibo("我发表了一个新的帖子【" . $title . "】:" . $postUrl);
     }
     //显示成功消息
     $message = $isEdit ? '编辑成功。' : '发表成功。' . getScoreTip($before, $after) . getToxMoneyTip($tox_money_before, $tox_money_after);
     $this->success($message, U('Forum/Index/detail', array('id' => $post_id)));
 }