Example #1
0
 public function actionCreate()
 {
     $model = new WeddingGroup();
     if (isset($_POST['WeddingGroup'])) {
         $model->attributes = $_POST['WeddingGroup'];
         if ($model->save()) {
             //谁创建谁默认属于本团队成员
             $glinkAttr = array('groupid' => $model->id, 'uid' => $this->uid, 'isAdmin' => 1);
             $glModel = new GroupLink();
             $glModel->attributes = $glinkAttr;
             $glModel->save();
             //相关标签
             $tags = $_POST['tagnames'];
             $tags = !empty($tags) ? array_unique(array_filter($tags)) : array();
             $tagids = array();
             if (!empty($tags)) {
                 foreach ($tags as $str) {
                     $_tmp = explode('-', $str);
                     if ($_tmp[1] > 0) {
                         //添加对应关系
                         if (Tags::addRelation($_tmp[1], $model->id, 'wgroup')) {
                             $tagids[] = $_tmp[1];
                         }
                     } else {
                         //查找是否有对应话题
                         $_tagid = Tags::findAndAdd($_tmp[0], 'wgroup', $model->id);
                         if ($_tagid) {
                             $tagids[] = $_tagid;
                         }
                     }
                 }
                 $tagids = !empty($tagids) ? array_unique(array_filter($tagids)) : array();
             }
             $tagStr = join(',', $tagids);
             WeddingGroup::model()->updateByPk($model->id, array('tagids' => $tagStr));
             $this->redirect(array('group/view', 'id' => $model->id));
         }
     }
     //未认证用户不能创建团队
     if (!$this->userInfo['creditStatus']) {
         $this->message(0, '请完善资料并提交个人认证', Yii::app()->createurl('users/config', array('type' => 'info')));
     } else {
         //todo,创建的团队数量限制
     }
     //获取所有受推荐地区
     $topAreas = Area::getTops(0);
     $areas = CHtml::listData($topAreas, 'id', 'title');
     $suggestTags = Tags::getTops('posts');
     $data = array('model' => $model, 'areas' => $areas, 'suggestTags' => $suggestTags);
     $this->render('create', $data);
 }
Example #2
0
 public function actionUpdate($type)
 {
     if (!in_array($type, array('info', 'passwd', 'tags'))) {
         $this->message(0, '您的操作有误');
     }
     if (isset($_POST) and !empty($_POST)) {
         $model = new Users();
         if ($type == 'info') {
             $intoData['truename'] = zmf::filterInput($_POST['truename'], 't', 1);
             if (!$intoData['truename']) {
                 $this->message(0, '用户名不能为空');
             }
             //如果用户修改了用户名,则判断是否被使用
             if ($intoData['truename'] != $this->userInfo['truename']) {
                 $info = Users::getInfoByName($intoData['truename']);
                 if ($info) {
                     $this->message(0, '该用户名已被使用');
                 }
             }
             $intoData['sex'] = tools::val('sex');
             $intoData['areaid'] = tools::val('areaid');
             $intoData['content'] = zmf::filterInput($_POST['desc'], 't', 1);
         } elseif ($type == 'passwd') {
             $old = zmf::filterInput($_POST['old_password'], 't', 1);
             $info = Users::model()->findByPk($this->uid);
             if (!$old) {
                 $this->message(0, '请输入原始密码');
             } elseif (md5($old) != $info['password']) {
                 $this->message(0, '原始密码不正确');
             }
             if (!$_POST['password']) {
                 $this->message(0, '请输入密码');
             } elseif (strlen($_POST['password']) < 5) {
                 $this->message(0, '新密码过短,请重新输入');
             }
             $intoData['password'] = md5($_POST['password']);
         } elseif ($type == 'tags') {
             //相关标签
             $tags = $_POST['tagnames'];
             $tags = !empty($tags) ? array_unique(array_filter($tags)) : array();
             $tagids = array();
             if (!empty($tags)) {
                 foreach ($tags as $str) {
                     $_tmp = explode('-', $str);
                     if ($_tmp[1] > 0) {
                         //添加对应关系
                         if (Tags::addRelation($_tmp[1], $this->uid, 'user')) {
                             $tagids[] = $_tmp[1];
                         }
                     } else {
                         //查找是否有对应话题
                         $_tagid = Tags::findAndAdd($_tmp[0], 'user', $this->uid);
                         if ($_tagid) {
                             $tagids[] = $_tagid;
                         }
                     }
                 }
                 $tagids = !empty($tagids) ? array_unique(array_filter($tagids)) : array();
             }
             $tagStr = join(',', $tagids);
             $intoData['tagids'] = $tagStr;
         }
         zmf::delFCache("userInfo-{$this->uid}");
         if ($model->updateByPk($this->uid, $intoData)) {
             $this->message(1, '修改成功', Yii::app()->createUrl('users/config'));
         } else {
             $this->message(1, '修改成功', Yii::app()->createUrl('users/config'));
         }
     }
     $suggestTags = array();
     if ($type == 'tags') {
         //推荐的标签
         $suggestTags = Tags::getTops('posts');
     }
     $data = array('info' => $this->userInfo, 'type' => $type, 'suggestTags' => $suggestTags);
     $this->render('update', $data);
 }
Example #3
0
 /**
  * 已取消其他文章类型,默认为游记
  * @param type $classify,分类
  */
 public function actionCreate($id = '')
 {
     $id = zmf::filterInput($id);
     if (!zmf::uid()) {
         $this->redirect(array('site/login'));
     }
     if ($id) {
         $model = $this->loadModel($id);
         if ($model->uid != zmf::uid()) {
             if (!Users::checkPower('editpost', false, true)) {
                 throw new CHttpException(403, '不被允许的操作.');
             }
         }
     } else {
         $model = new Posts();
         $model->classify = Posts::CLASSIFY_WEDDING;
         //文章分类
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'posts-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['Posts'])) {
         //判断是否应被禁止
         //todo,应排除编辑
         //            $forbidInfo = Posts::isForbidden($_POST['Posts']['content'], 'post');
         //            if ($forbidInfo['status'] != Posts::STATUS_PASSED) {
         //                //todo,增加用户非法操作次数
         //                $_POST['Posts']['status'] = Posts::STATUS_STAYCHECK;
         //            }
         //处理文本
         $filter = Posts::handleContent($_POST['Posts']['content']);
         $_POST['Posts']['content'] = $filter['content'];
         foreach ($_POST['Posts'] as $k => $val) {
             $_POST['Posts'][$k] = zmf::filterInput($val, 't');
         }
         if (Yii::app()->session['checkHasBadword'] == 'yes') {
             $_POST['Posts']['status'] = Posts::STATUS_STAYCHECK;
         }
         if (!$model->isNewRecord) {
             $_POST['Posts']['updateTime'] = zmf::now();
             $isNew = false;
         } else {
             $isNew = true;
         }
         unset(Yii::app()->session['checkHasBadword']);
         if (!empty($filter['attachids'])) {
             $attkeys = array_filter(array_unique($filter['attachids']));
             if (!empty($attkeys)) {
                 $_POST['Posts']['faceimg'] = $attkeys[0];
                 //默认将文章中的第一张图作为封面图
             }
         } else {
             $_POST['Posts']['faceimg'] = '';
             //否则将封面图置为空(有可能编辑后没有图片了)
         }
         //相关标签
         $tags = $_POST['tagnames'];
         $tags = !empty($tags) ? array_unique(array_filter($tags)) : array();
         $model->attributes = $_POST['Posts'];
         if ($model->save()) {
             //将上传的图片置为通过
             Attachments::model()->updateAll(array('status' => Posts::STATUS_DELED), 'logid=:logid AND classify=:classify', array(':logid' => $model->id, ':classify' => 'posts'));
             if (!empty($attkeys)) {
                 $attstr = join(',', $attkeys);
                 if ($attstr != '') {
                     Attachments::model()->updateAll(array('status' => Posts::STATUS_PASSED, 'logid' => $model->id), 'id IN(' . $attstr . ')');
                 }
             }
             //相关标签
             $tagids = array();
             if (!empty($tags)) {
                 foreach ($tags as $str) {
                     $_tmp = explode('-', $str);
                     if ($_tmp[1] > 0) {
                         //添加对应关系
                         if (Tags::addRelation($_tmp[1], $model->id, 'posts')) {
                             $tagids[] = $_tmp[1];
                         }
                     } else {
                         //查找是否有对应话题
                         $_tagid = Tags::findAndAdd($_tmp[0], 'posts', $model->id);
                         if ($_tagid) {
                             $tagids[] = $_tagid;
                         }
                     }
                 }
                 $tagids = !empty($tagids) ? array_unique(array_filter($tagids)) : array();
                 $tagStr = join(',', $tagids);
                 if ($tagStr != '') {
                     Posts::model()->updateByPk($model->id, array('tagids' => $tagStr));
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     //未认证用户不能创建团队
     if (!$this->userInfo['creditStatus']) {
         $this->message(0, '请完善资料并提交个人认证', Yii::app()->createurl('users/config', array('type' => 'info')));
     }
     //文章分类
     $cols = Column::allCols(1, 0, 1, Posts::CLASSIFY_WEDDING);
     if (!$model->isNewRecord) {
         $model->content = zmf::text(array('action' => 'edit'), $model->content, false, 600);
     }
     //获取所有受推荐地区
     $topAreas = Area::getTops(0);
     $areas = CHtml::listData($topAreas, 'id', 'title');
     //推荐的标签
     $suggestTags = Tags::getTops('posts');
     //我所加入的团队
     $groups = WeddingGroup::getUserGroup($this->uid);
     $this->pageTitle = '新增作品 - ' . zmf::config('sitename');
     $this->render('create', array('model' => $model, 'cols' => $cols, 'action' => $action, 'areas' => $areas, 'suggestTags' => $suggestTags, 'groups' => $groups));
 }