コード例 #1
0
ファイル: ArtController.class.php プロジェクト: Willshon/OLCS
 public function getArt($cate, $child = true, $uid, $status, $order, $field = true, $row, $onetag, $title, $position, $limit, $focus)
 {
     if ($onetag != '') {
         $map['tag'] = array('like', '%' . $onetag . '%');
     }
     if ($position != '') {
         $map['tj'] = array('in', $position);
     }
     if ($title != '') {
         $map['title'] = array('like', '%' . $title . '%');
     }
     if ($child) {
         $cateids = D('Home/Cate')->getChildrenId($cate);
     } else {
         $cateids = $cate;
     }
     if ($uid != 0) {
         $map['uid'] = array('in', $uid);
     }
     if ($cateids != null) {
         $map['cid'] = array('in', $cateids);
     }
     $map['status'] = array('in', $status);
     if ($focus) {
         $loginuid = is_login();
         $focusuid = M('focus')->where(array('id' => $loginuid, 'type' => 0))->getField('rowid', true);
         $focustag = M('focus')->where(array('id' => $loginuid, 'type' => 2))->getField('rowid', true);
         if ($focustag != null) {
             foreach ($focustag as $key => $vo) {
                 $focustagarr[$key] = '%' . M('tags')->where(array('id' => $vo))->getField('title') . '%';
             }
             $where['tag'] = array('like', $focustagarr, 'OR');
             if ($focusuid != null) {
                 $where['uid'] = array('in', $focusuid);
                 $where['_logic'] = 'or';
             }
             $map['_complex'] = $where;
         } else {
             if ($focusuid != null) {
                 $where['uid'] = array('in', $focusuid);
                 $map['_complex'] = $where;
             } else {
                 $map['status'] = -1;
             }
         }
     }
     $count = $this->model->where($map)->count();
     if ($count > 0) {
         $p = I(C('VAR_PAGE'));
         if ($limit) {
             $data = $this->model->where($map)->order($order)->limit($row)->field($field)->select();
         } else {
             $data = $this->model->where($map)->order($order)->page(!empty($p) ? $p : 1, $row)->field($field)->select();
         }
     }
     if ($data == null) {
         $this->apiError("获取文章列表失败", null);
     } else {
         foreach ($data as $key => $vo) {
             if ($vo['tj'] == 1) {
                 $data[$key]['titleicon'] = '[<i class="icon-thumbs-up"></i> 推荐]';
             }
             if ($vo['tj'] == 2) {
                 $data[$key]['titleicon'] = '[<i class="icon-arrow-up"></i> 置顶]';
             }
             $data[$key]['yesedit'] = getarteditauth($vo['id'], $uid) || is_admin($uid);
             $data[$key]['img'] = getImgs($vo['description'], 0);
             $data[$key]['user'] = query_user(array('nickname', 'username', 'space_url', 'avatar32', 'avatar64'), $vo['uid']);
             if ($title != '') {
                 $data[$key]['title'] = str_replace($title, '<b style="color:red">' . $title . '</b>', $vo['title']);
             }
             if (!empty($vo['tag'])) {
                 $tags = explode(',', $vo['tag']);
                 $data[$key]['linktag'] = '';
                 foreach ($tags as $key1 => $vo1) {
                     $maptag['title'] = $vo1;
                     $maptag['type'] = 1;
                     $tagid = M('tags')->where($maptag)->getField('id');
                     $url = CSU('/tagart/' . $tagid, 'Index/tagart', array('id' => $tagid));
                     if ($onetag != '' && $onetag == $vo1) {
                         $data[$key]['linktag'] .= '<a style="margin-left:5px;color:red;" href="' . $url . '">[' . $vo1 . ']</a>';
                     } else {
                         $data[$key]['linktag'] .= '<a style="margin-left:5px;" href="' . $url . '">[' . $vo1 . ']</a>';
                     }
                 }
             }
         }
         $this->apiSuccess("获取文章列表成功", null, array('data' => $data));
     }
 }
コード例 #2
0
 public function artedit()
 {
     if (IS_POST) {
         $input = new \OT\Input();
         $input->noGPC();
         $uid = $_SESSION['cs_home']['user_auth']['uid'];
         if (!$uid > 0) {
             $this->error('请先登录');
         }
         if (false === ($data = D('Article')->create())) {
             $this->error(0, D('Article')->getError());
         }
         $data['description'] = op_h(I('description'));
         if ($data['cid'] == null) {
             $this->error('分类为空');
         }
         if (mb_strlen(op_h($data['description']), 'utf-8') < 30) {
             $this->error('文章内容必须大于30字');
         }
         if (mb_strlen($data['title'], 'utf-8') > 80) {
             $this->error('文章标题必须小于80字');
         }
         //$data['tag']=op_t($data['tag']);
         foreach ($data['tag'] as $key => $vo) {
             $data['tag'][$key] = mb_substr($vo, 0, 15, 'utf-8');
         }
         D('Tags')->InsertTags($data['tag'], 1, $data['id']);
         $data['tag'] = implode(',', $data['tag']);
         //$data['description']=$data['description'];
         $data['title'] = op_t($data['title']);
         $data['uid'] = $uid;
         $status = $data['status'];
         $ystatus = D('Article')->where(array('id' => $data['id']))->getField('status');
         //保存当前数据对象
         $list = D('Article')->save($data);
         if ($list !== false) {
             if ($status == 1 && $ystatus != 1) {
                 setuserscore($uid, C('ARTSCORE'));
             }
             $this->success('编辑文章成功!', U('Ucenter/userart'));
         } else {
             $this->error('编辑文章失败!');
         }
     } else {
         $uid = is_login();
         $id = I('id');
         if (!is_admin($uid)) {
             $roleauth = getmroleauth($uid);
             // $setting['exts'] =$roleauth['fileext'];
             $extsarr = explode(',', $roleauth['fileext']);
             if (!empty($extsarr)) {
                 $extstr = '';
                 foreach ($extsarr as $key1 => $vo1) {
                     $extstr .= '*.' . $vo1 . ';';
                 }
                 $this->assign('extstr', $extstr);
             }
             if (!getarteditauth($id, $uid)) {
                 $this->error('无权编辑该文章或编辑时间已过', '', false, true);
             }
         }
         $info = callApi('Art/getArtInfo', array($id));
         $info['data']['description'] = stripcslashes($info['data']['description']);
         $this->assign('info', $info['data']);
         $this->display();
     }
 }