示例#1
0
 public function del()
 {
     if (IS_POST) {
         $uid = Q('uid', 0, 'intval');
         //删除文章
         if (Q('post.delcontent')) {
             $ModelCache = cache('model');
             foreach ($ModelCache as $model) {
                 $contentModel = ContentModel::getInstance($model['mid']);
                 $contentModel->where(array('uid' => $uid))->del();
             }
         }
         //删除评论
         if (Q('post.delcomment')) {
             M('comment')->where(array('uid' => $uid))->del();
         }
         //删除附件
         if (Q('post.delupload')) {
             M('upload')->where(array('uid' => $uid))->del();
         }
         //删除用户
         M('user')->del($uid);
         $this->success('删除成功...');
     } else {
         $uid = Q("uid", 0, "intval");
         $field = M('user')->find($uid);
         $this->assign('field', $field);
         $this->display();
     }
 }
 public function index()
 {
     //编号,也就是下载第几个链接,有的是多文件下载用的!
     $k = I('get.k', 0, 'intval');
     //字段名称
     $f = I('get.f', '');
     if (empty($this->id) || empty($this->catid) || empty($f)) {
         $this->error("参数有误!");
     }
     //模型ID
     $modelid = getCategory($this->catid, 'modelid');
     $Model_field = F("Model_field_" . $modelid);
     //判断字段类型
     if (!in_array($Model_field[$f]['formtype'], array('downfiles', 'downfile'))) {
         $this->error('下载地址错误!');
     }
     $this->db = ContentModel::getInstance($modelid);
     $data = $this->db->relation(true)->where(array("id" => $this->id, 'status' => 99))->find();
     if (empty($data)) {
         $this->error("该信息不存在!");
     }
     $this->db->dataMerger($data);
     if (!empty($data)) {
         //取得下载字段信息
         $downfiles = $data[$f];
         $dowUnserialize = unserialize($downfiles);
         if ($dowUnserialize) {
             $info = $dowUnserialize[$k];
             if (empty($info)) {
                 $this->error("该下载地址已经失效!");
             }
         } else {
             $info = array();
             $info['filename'] = basename($downfiles);
             $info['point'] = 0;
             $info['groupid'] = 0;
         }
         //当前客户端标识
         $aut = md5($this->userid . $this->groupid . substr($_SERVER['HTTP_USER_AGENT'], 0, 254));
         //加密
         //格式:aut|栏目ID|信息id|下载编号|字段
         $key = authcode(implode('|', array($aut, $this->catid, $this->id, $k, $f)), '', '', 3600);
         $this->assign("info", $data);
         $this->assign("fileurl", U("Download/d", array('key' => urlencode($key))));
         $this->assign("filename", $info['filename']);
         $this->assign("point", $info['point']);
         $this->assign("groupid", $info['groupid']);
         $this->assign("Member_group", F("Member_group"));
         $this->assign("SEO", seo($this->catid, urldecode($info['filename']), '', ''));
         $this->display("Public:download");
     } else {
         $this->error("该信息不存在!");
     }
 }
 /**
  * 审核文章
  */
 public function audit()
 {
     if ($aids = Q('aid')) {
         $ContentModel = ContentModel::getInstance($this->mid);
         foreach ($aids as $aid) {
             $data = array('aid' => $aid, 'content_status' => 1);
             $ContentModel->save($data);
         }
         $this->success('操作成功');
     } else {
         $this->error('参数错误');
     }
 }
示例#4
0
 public function del($aid)
 {
     $ContentModel = ContentModel::getInstance($this->mid);
     if ($ContentModel->del($aid)) {
         //删除文章tag属性
         M('content_tag')->where(array('cid' => $this->cid))->del();
         //生成栏目静态
         $this->createCategoryHtml($this->cid);
         Hook::listen('content_del');
         return true;
     } else {
         $this->error = '删除文章失败';
     }
 }
示例#5
0
 /**
  * 删除文章
  * @param $aid 文章aid
  * @return bool
  */
 public function del($aid)
 {
     $ContentModel = ContentModel::getInstance($this->mid);
     $map['aid'] = array('IN', $aid);
     //删除文章静态文件
     $content = $ContentModel->where($map)->find();
     //执行删除
     if ($ContentModel->del($aid)) {
         //删除文章tag
         $map['cid'] = $content['cid'];
         $map['aid'] = $content['aid'];
         M('content_tag')->where($map)->del();
         Hook::listen('CONTENT_DEL');
         return true;
     } else {
         $this->error = '删除文章失败';
     }
 }
示例#6
0
 /**
  * 删除用户
  * @return mixed
  */
 public function delUser()
 {
     $uid = Q('uid', 0, 'intval');
     //删除文章
     if (Q('post.delcontent')) {
         $map = array('uid' => array('EQ', $uid));
         $ModelCache = S('model');
         foreach ($ModelCache as $model) {
             $contentModel = ContentModel::getInstance($model['mid']);
             $contentModel->where($map)->del();
         }
     }
     //评论表存在时删除评论
     if (Q('post.delcomment') && M()->tableExists('addon_comment')) {
         $map = array('userid' => array('EQ', $uid));
         M('addon_comment')->where($map)->del();
     }
     //删除附件
     if (Q('post.delupload')) {
         $map = array('uid' => array('EQ', $uid));
         M('upload')->where($map)->del();
     }
     //后台历史菜单
     M('menu_favorite')->where($map)->del();
     $map = array('space_uid' => array('EQ', $uid), 'guest_uid' => array('EQ', $uid), '_logic' => 'OR');
     //删除访客
     M('user_guest')->where($map)->del();
     //日志记录
     $map = array('uid' => array('EQ', $uid));
     M('user_credits')->where($map)->del();
     if (M('user')->del($uid)) {
         return true;
     } else {
         $this->error = '删除失败';
     }
 }
示例#7
0
 public function edit()
 {
     $aid = Q('aid', 0, 'intval');
     if (!$aid) {
         $this->error('文章不存在');
     }
     $mid = $this->_category[$this->_cid]['mid'];
     $ContentModel = new Content($mid);
     $result = $ContentModel->find($aid);
     if ($result['uid'] != $_SESSION['uid']) {
         $this->error('没有修改权限');
     }
     if (IS_POST) {
         if ($ContentModel->edit($_POST)) {
             $this->success('发表成功!');
         } else {
             $this->error($ContentModel->error);
         }
     } else {
         $aid = Q('aid', 0, 'intval');
         if (!$aid) {
             $this->error('参数错误');
         }
         $ContentModel = ContentModel::getInstance($this->_mid);
         $editData = $ContentModel->find($aid);
         //获取分配字段
         $form = K('ContentForm');
         $this->assign('form', $form->get($editData));
         //分配验证规则
         $this->assign('formValidate', $form->formValidate);
         $this->assign('editData', $editData);
         $this->display('edit.php');
     }
 }
 public function push()
 {
     if (IS_POST) {
         $id = I('post.id');
         $modelid = I('post.modelid');
         $catid = I('post.catid');
         $action = I('get.action');
         if (!$id || !$action || !$modelid || !$catid) {
             $this->error("参数不正确");
         }
         switch ($action) {
             //推荐位
             case "position_list":
                 $posid = $_POST['posid'];
                 if ($posid && is_array($posid)) {
                     $position_data_db = D('Position');
                     $fields = F("Model_field_" . $modelid);
                     $tablename = ucwords($this->model[$modelid]['tablename']);
                     if (!$tablename) {
                         $this->error("模型不能为空!");
                     }
                     $ids = explode("|", $id);
                     $Content = ContentModel::getInstance($modelid);
                     foreach ($ids as $k => $aid) {
                         //取得信息
                         $re = $Content->relation(true)->where(array("id" => $aid))->find();
                         if ($re) {
                             $Content->dataMerger($re);
                             //推送数据
                             $textcontent = array();
                             foreach ($fields as $_key => $_value) {
                                 //判断字段是否入库到推荐位字段
                                 if ($_value['isposition']) {
                                     $textcontent[$_key] = $re[$_key];
                                 }
                             }
                             //样式进行特别处理
                             $textcontent['style'] = $re['style'];
                             //推送到推荐位
                             $status = $position_data_db->position_update($aid, $modelid, $catid, $posid, $textcontent, 0, 1);
                             $r = $re = null;
                         }
                     }
                     $this->success("推送到推荐位成功!");
                 } else {
                     $this->error("请选择推荐位!");
                 }
                 break;
                 //同步发布到其他栏目
             //同步发布到其他栏目
             case "push_to_category":
                 $ids = explode("|", $id);
                 $relation = I("post.relation");
                 if (!$relation) {
                     $this->error("请选择需要推送的栏目!");
                 }
                 $relation = explode("|", $relation);
                 if (is_array($relation)) {
                     //过滤相同栏目和自身栏目
                     foreach ($relation as $k => $classid) {
                         if ($classid == $catid) {
                             unset($relation[$k]);
                         }
                     }
                     //去除重复
                     $relation = array_unique($relation);
                     if (count($relation) < 1) {
                         $this->error("请选择需要推送的栏目!");
                     }
                     $tablename = ucwords($this->model[$modelid]['tablename']);
                     if (!$tablename) {
                         $this->error("模型不能为空!");
                     }
                     $Content = ContentModel::getInstance($modelid);
                     import('Content');
                     $ContentAPI = new Content();
                     foreach ($ids as $k => $aid) {
                         //取得信息
                         $r = $Content->relation(true)->where(array("id" => $aid))->find();
                         $linkurl = $r['url'];
                         if ($r) {
                             $ContentAPI->othor_catid($relation, $linkurl, $r, $modelid);
                         }
                     }
                     $this->success("推送其他栏目成功!");
                 } else {
                     $this->error("请选择需要推送的栏目!");
                 }
                 break;
             default:
                 $this->error("请选择操作!");
                 break;
         }
     } else {
         $id = I('get.id');
         $action = I('get.action');
         $modelid = I('get.modelid');
         $catid = I("get.catid");
         if (!$id || !$action || !$modelid || !$catid) {
             $this->error("参数不正确!");
         }
         $tpl = $action == "position_list" ? "push_list" : "push_to_category";
         switch ($action) {
             //推荐位
             case "position_list":
                 $position = F("Position");
                 if (!empty($position)) {
                     $array = array();
                     foreach ($position as $_key => $_value) {
                         if ($_value['modelid'] && $_value['modelid'] != $modelid || $_value['catid'] && strpos(',' . getCategory($_value['catid'], 'arrchildid') . ',', ',' . $catid . ',') === false) {
                             continue;
                         }
                         $array[$_key] = $_value['name'];
                     }
                     $this->assign("Position", $array);
                 }
                 break;
                 //同步发布到其他栏目
             //同步发布到其他栏目
             case "push_to_category":
                 break;
             default:
                 $this->error("请选择操作!");
                 break;
         }
         $this->assign("id", $id);
         $this->assign("action", $action);
         $this->assign("modelid", $modelid);
         $this->assign("catid", $catid);
         $this->assign("show_header", true);
         $this->display($tpl);
     }
 }
 /**
  * 获得入库数据
  *
  * @return array|bool
  */
 public function get()
 {
     $data = $_POST;
     //添加文章时设置 作者uid
     if (!isset($data['aid'])) {
         $data['uid'] = $_SESSION['user']['uid'];
     }
     //文章状态设置 0 待审核 1 发表 2 自动
     $auto_send_time = Q('auto_send_time', null, 'strtotime');
     if ($auto_send_time && $auto_send_time > time()) {
         $data['content_status'] = 2;
     } else {
         if ($data['content_status'] == 2) {
             $data['content_status'] = 1;
         }
     }
     //没有添加内容时初始设置
     if (empty($data['content'])) {
         $data['content'] = '';
     }
     //添加时间
     if (!empty($data['addtime'])) {
         $data['addtime'] = strtotime($data['addtime']);
     }
     //修改时间
     $data['updatetime'] = time();
     //阅读积分处理
     if (!empty($data['readpoint']) && !is_numeric($data['readpoint'])) {
         $data['readpoint'] = 0;
     }
     //文章模型
     $ContentModel = ContentModel::getInstance($this->mid);
     //自动提取文章描述
     if (empty($data['description'])) {
         $len = isset($data['auto_desc_length']) ? $data['auto_desc_length'] : 200;
         $data['description'] = mb_substr(strip_tags($data['content']), 0, $len, 'utf-8');
     }
     foreach ($this->field as $fieldInfo) {
         //字段禁用
         if ($fieldInfo['status'] == 0) {
             continue;
         }
         //不需要处理的字段
         if (in_array($fieldInfo['field_name'], $this->noDealField)) {
             continue;
         }
         $field = $fieldInfo['field_name'];
         //字段set选项
         $set = $fieldInfo['set'];
         //字段二次处理方法
         $METHOD = $fieldInfo['field_type'];
         $data[$field] = empty($data[$field]) ? '' : $data[$field];
         if (method_exists($this, $METHOD)) {
             $Value = $this->{$METHOD}($fieldInfo, $data[$field]);
             if ($fieldInfo['table_type'] == 1) {
                 //主表数据
                 $data[$field] = $Value;
             } else {
                 //副表
                 $data[$fieldInfo['table_name']][$field] = $Value;
             }
         }
         //封面栏目与链接不允许发表
         if (!isset($data['cid']) || !in_array($this->category[$data['cid']]['cattype'], array(1, 4))) {
             $this->error = '栏目选择错误';
             return false;
         }
         //如果字段设置唯一性验证时执行验证操作
         if ((int) $fieldInfo['isunique'] == 1) {
             if (M($fieldInfo['table_name'])->where($field . "='{$Value}'")->find()) {
                 $this->error = $fieldInfo['title'] . '已经存在';
                 return false;
             }
         }
         //模型自动验证规则设置
         $validateRule = array();
         //验证时机 1 有这个表单就验证  2 必须验证 3 表单不为空才验证
         $validateOccasion = (int) $fieldInfo['required'] ? 2 : 3;
         //设置验证规则
         if (isset($set['minlength']) && isset($set['maxlength'])) {
             $maxlength = (int) $set['maxlength'];
             $minlength = (int) $set['minlength'];
             if ($maxlength > $minlength) {
                 $validateRule[] = array($field, "minlen:{$minlength}", $fieldInfo['title'] . " 数量不能小于{$minlength}个字", $validateOccasion, 3);
                 $validateRule[] = array($field, "maxlen:{$maxlength}", $fieldInfo['title'] . " 数量不能大于{$maxlength}个字", $validateOccasion, 3);
             }
         }
         //验证规则
         if (!empty($fieldInfo['validate'])) {
             $regexp = $fieldInfo['validate'];
             $error = empty($fieldInfo['error']) ? $fieldInfo['title'] . '输入错误' : $set['error'];
             $validateRule[] = array($field, "regexp:{$regexp}", $error, $validateOccasion, 3);
         }
         //必须输入验证
         if ($fieldInfo['required'] == 1) {
             $validateRule[] = array($field, "nonull", $fieldInfo['title'] . '不能为空', $validateOccasion, 3);
         }
         //模型Validate属性设置验证规则
         if (!empty($validateRule)) {
             foreach ($validateRule as $validate) {
                 $ContentModel->addValidate($validate);
             }
         }
     }
     //如果没有缩略图时,删除图片属性
     if (isset($data['flag'])) {
         if (empty($data['thumb'])) {
             //没有缩略图时,删除图片属性
             if (false !== ($k = array_search('图片', $data['flag']))) {
                 unset($data['flag'][$k]);
             }
         } else {
             $data['flag'][] = '图片';
         }
         $data['flag'] = implode(',', array_unique($data['flag']));
     }
     return $data;
 }
示例#10
0
 /**
  * 上下篇生成
  * @param type $catid
  * @param type $id 
  */
 public function related_content($catid, $id, $action = "edit")
 {
     if (!$catid || !$id) {
         return;
     }
     $modelid = getCategory($catid, 'modelid');
     $db = ContentModel::getInstance($modelid);
     $where = array();
     $where['catid'] = $catid;
     $where['status'] = array("EQ", "99");
     $where['id'] = array("LT", $id);
     $data[] = $db->relation(true)->where($where)->order(array("id" => "DESC"))->find();
     if ($action == "edit") {
         $where['id'] = array("GT", $id);
         $data[] = $db->relation(true)->where($where)->find();
     }
     import('Html');
     $html = get_instance_of('Html');
     foreach ($data as $r) {
         if ($r['islink'] || empty($r['id'])) {
             continue;
         }
         $db->dataMerger($r);
         $setting = getCategory($r['catid'], 'setting');
         $content_ishtml = $setting['content_ishtml'];
         if (!$content_ishtml) {
             continue;
         }
         $html->show($r, 1, 'edit');
     }
     return true;
 }
示例#11
0
文件: Content.class.php 项目: jyht/v5
 public function del($aid)
 {
     $ContentModel = ContentModel::getInstance($this->_mid);
     $data = $ContentModel->find($aid);
     if (!$data) {
         $this->error = '文章不存在';
         return false;
     }
     if ($ContentModel->del($aid)) {
         //删除文章tag属性
         M('content_tag')->where(array('mid' => $this->_mid, 'cid' => $data['cid']))->del();
         return true;
     } else {
         $this->error = '删除文章失败';
     }
 }
示例#12
0
 public function shows()
 {
     $catid = I('get.catid', 0, 'intval');
     $id = I('get.id', 0, 'intval');
     $page = intval($_GET[C("VAR_PAGE")]);
     $page = max($page, 1);
     //获取当前栏目数据
     $category = getCategory($catid);
     if (empty($category)) {
         send_http_status(404);
         exit;
     }
     //反序列化栏目配置
     $category['setting'] = $category['setting'];
     //检查是否禁止访问动态页
     if ($category['setting']['showoffmoving']) {
         send_http_status(404);
         exit;
     }
     //模型ID
     $this->modelid = $category['modelid'];
     $this->db = ContentModel::getInstance($this->modelid);
     $data = $this->db->relation(true)->where(array("id" => $id, 'status' => 99))->find();
     if (empty($data)) {
         send_http_status(404);
         exit;
     }
     $this->db->dataMerger($data);
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //载入字段数据处理类
     if (false == require_cache(RUNTIME_PATH . 'content_output.class.php')) {
         D("Category")->category_cache();
         D("Content_cache")->model_content_cache();
         require RUNTIME_PATH . 'content_output.class.php';
     }
     $content_output = new content_output($this->modelid);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     $output_data['title'] = strip_tags($output_data['title']);
     //SEO
     $seo_keywords = '';
     if (!empty($output_data['keywords'])) {
         $seo_keywords = implode(',', $output_data['keywords']);
     }
     $seo = seo($catid, $output_data['title'], $output_data['description'], $seo_keywords);
     //内容页模板
     $template = $output_data['template'] ? $output_data['template'] : $category['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     unset($newstempid);
     //分页处理
     $pages = $titles = '';
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] == 1) {
         //自动分页
         if ($maxcharperpage < 10) {
             $maxcharperpage = 500;
         }
         //按字数分割成几页处理开始
         import('Contentpage', APP_PATH . C("APP_GROUP_PATH") . '/Contents/ORG');
         $contentpage = new Contentpage();
         $contentfy = $contentpage->get_data($output_data['content'], $maxcharperpage);
         //自动分页有时会造成返回空,如果返回空,就不分页了
         if (!empty($contentfy)) {
             $output_data['content'] = $contentfy;
         }
     }
     //分配解析后的文章数据到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $seo);
     //栏目ID
     $this->assign("catid", $catid);
     //分页生成处理
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] > 0) {
         $urlrules = $this->url->show($data, $page);
         //手动分页
         $CONTENT_POS = strpos($output_data['content'], '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $output_data['content']));
             $pagenumber = count($contents);
             $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => $urlrules['page']))->show("default");
             //判断[page]出现的位置是否在第一位
             if ($CONTENT_POS < 7) {
                 $content = $contents[$page];
             } else {
                 $content = $contents[$page - 1];
             }
             //分页
             $this->assign("pages", $pages);
             $this->assign("content", $content);
         }
     } else {
         $this->assign("content", $output_data['content']);
     }
     $this->display("Show:" . $template);
 }
示例#13
0
 public function move()
 {
     if (IS_POST) {
         $ContentModel = ContentModel::getInstance($this->_mid);
         //移动方式  1 从指定ID  2 从指定栏目
         $from_type = Q("post.from_type", NULL, "intval");
         //目标栏目cid
         $to_cid = Q("post.to_cid", NULL, 'intval');
         if ($to_cid) {
             switch ($from_type) {
                 case 1:
                     //移动aid
                     $aid = Q("post.aid", NULL, "trim");
                     $aid = explode("|", $aid);
                     if ($aid && is_array($aid)) {
                         foreach ($aid as $id) {
                             if (is_numeric($id)) {
                                 $ContentModel->join(null)->save(array("aid" => $id, "cid" => $to_cid));
                             }
                         }
                     }
                     break;
                 case 2:
                     //来源栏目cid
                     $from_cid = Q("post.from_cid", NULL, 'intval');
                     if ($from_cid) {
                         foreach ($from_cid as $d) {
                             if (is_numeric($d)) {
                                 $ContentModel->join(null)->where("cid={$d}")->save(array("cid" => $to_cid));
                             }
                         }
                     }
                     break;
             }
         }
         $this->success('移动成功!');
     } else {
         $category = array();
         foreach ($this->_category as $n => $v) {
             //排除非本模型或外部链接类型栏目或单文章栏目
             if ($v['mid'] != $this->_mid || $v['cattype'] == 3 || $v['cattype'] == 4) {
                 continue;
             }
             $selected = '';
             if ($this->_cid == $v['cid']) {
                 $v['selected'] = "selected";
             }
             //非本栏目模型关闭
             if ($v['cattype'] != 1) {
                 $v['disabled'] = 'disabled';
             }
             $category[$n] = $v;
         }
         $this->category = $category;
         $this->display();
     }
 }
 /**
  * 移动文章
  */
 public function move()
 {
     if (IS_POST) {
         $ContentModel = ContentModel::getInstance($this->mid);
         //移动方式  1 从指定ID  2 从指定栏目
         $from_type = Q("post.from_type", 0, "intval");
         //目标栏目cid
         $to_cid = Q("post.to_cid", 0, 'intval');
         if ($to_cid) {
             switch ($from_type) {
                 case 1:
                     //移动aid
                     $aid = Q("post.aid", 0, "trim");
                     $aid = explode("|", $aid);
                     if ($aid && is_array($aid)) {
                         foreach ($aid as $id) {
                             if (is_numeric($id)) {
                                 $ContentModel->save(array("aid" => $id, "cid" => $to_cid));
                             }
                         }
                     }
                     break;
                 case 2:
                     //来源栏目cid
                     $from_cid = Q("post.from_cid", 0);
                     if ($from_cid) {
                         foreach ($from_cid as $d) {
                             if (is_numeric($d)) {
                                 $table = $this->model[$this->category[$d]['mid']]['table_name'];
                                 M($table)->where("cid={$d}")->save(array("cid" => $to_cid));
                             }
                         }
                     }
                     break;
             }
             $this->success('移动成功!');
         } else {
             $this->error('请选择目录栏目');
         }
     } else {
         $category = array();
         foreach ($this->category as $n => $v) {
             //排除非本模型或外部链接类型栏目或单文章栏目
             if ($v['mid'] != $this->mid || $v['cattype'] == 3 || $v['cattype'] == 4) {
                 continue;
             }
             if ($this->cid == $v['cid']) {
                 $v['selected'] = "selected";
             }
             //封面栏目
             if ($v['cattype'] == 2) {
                 $v['disabled'] = 'disabled';
             }
             $category[$n] = $v;
         }
         $this->assign('category', $category);
         $this->display();
     }
 }
 /**
  * 根据id批量生成内容页 
  */
 public function batch_show()
 {
     if (IS_POST) {
         $catid = intval($_GET['catid']);
         if (!$catid) {
             $this->error("栏目ID不能为空!");
         }
         $modelid = getCategory($catid, 'modelid');
         $setting = getCategory($catid, 'setting');
         $content_ishtml = $setting['content_ishtml'];
         if ($content_ishtml) {
             //主表名
             $table_name = ucwords($this->model[$modelid]['tablename']);
             if (empty($table_name)) {
                 $this->error("模型不存在!");
             }
             $this->db = ContentModel::getInstance($modelid);
             if (empty($_POST['ids'])) {
                 $this->error("您没有勾选信息!");
             }
             import('Html');
             $this->html = get_instance_of('Html');
             $ids = implode(',', $_POST['ids']);
             $where = array();
             $where['catid'] = array("EQ", $catid);
             $where['id'] = array("IN", $ids);
             $where['status'] = array("EQ", 99);
             $rs = $this->db->relation(true)->where($where)->select();
             foreach ($rs as $r) {
                 $this->db->dataMerger($r);
                 if ($r['islink']) {
                     continue;
                 }
                 if ($r['status'] != 99) {
                     continue;
                 }
                 $this->html->show($r, 0, 'edit');
             }
             $this->success("生成成功!");
         } else {
             $this->error("该栏目无需生成!");
         }
     } else {
         $catid = intval($_GET['catid']);
         if (!$catid) {
             $this->error("栏目ID不能为空!");
         }
         $modelid = getCategory($catid, 'modelid');
         $setting = getCategory($catid, 'setting');
         $content_ishtml = $setting['content_ishtml'];
         if ($content_ishtml) {
             //主表名
             $table_name = ucwords($this->model[$modelid]['tablename']);
             if (empty($table_name)) {
                 $this->error("模型不存在!");
             }
             $this->db = ContentModel::getInstance($modelid);
             if (empty($_GET['ids'])) {
                 $this->error("您没有勾选信息!");
             }
             import('Html');
             $this->html = get_instance_of('Html');
             $ids = (int) $_GET['ids'];
             $where = array();
             $where['catid'] = array("EQ", $catid);
             $where['id'] = array("EQ", $ids);
             $where['status'] = array("EQ", 99);
             $r = $this->db->relation(true)->where($where)->find();
             //数据处理,把关联查询的结果集合并
             $this->db->dataMerger($r);
             if ($r['status'] != 99) {
                 $this->error("该信息未审核!无需生成");
             }
             if ($r['islink']) {
                 $this->error("链接文章无需生成!");
             } else {
                 $this->html->show($r, 0, 'edit');
             }
             $this->success("生成成功!");
         } else {
             $this->error("该栏目无需生成!");
         }
     }
 }
示例#16
0
 /**
  * 生成文章的上一篇与下一篇(关联文章)
  * @param $mid 模型mid
  * @param $aid 文章aid
  */
 public function relation_content($mid, $aid)
 {
     $model = ContentModel::getInstance($mid);
     //生成上一篇
     $preAid = $model->where('aid<' . $aid)->limit(1)->order("aid DESC")->getField('aid');
     if ($preAid) {
         $this->content($mid, $preAid);
     }
     //生成下一篇
     $nextAid = $model->where('aid>' . $aid)->limit(1)->order("aid ASC")->getField('aid');
     if ($nextAid) {
         $this->content($mid, $nextAid);
     }
 }
示例#17
0
 public function delCategory($cid)
 {
     if (!$cid || !isset($this->category[$cid])) {
         $this->error = 'cid参数错误';
         return false;
     }
     //如果存在子栏目不进行删除
     if (M('category')->where(array('pid' => $cid))->find()) {
         $this->error = '请先删除子栏目';
         return false;
     }
     $ContentModel = ContentModel::getInstance($this->category[$cid]['mid']);
     $ContentModel->where(array('cid' => $cid))->del();
     //删除栏目权限
     M("category_access")->where("cid={$cid}")->del();
     //删除栏目
     if ($this->del($cid)) {
         $html = new Html();
         //生成首页
         $html->index();
         //更新父级栏目
         $parentCategory = Data::parentChannel(S('category'), $cid);
         if (!empty($parentCategory)) {
             foreach ($parentCategory as $cat) {
                 $html->relation_category($cat['cid']);
             }
         }
         //更新缓存
         $this->updateCache();
         return true;
     } else {
         $this->error = '删除失败';
         return false;
     }
 }
示例#18
0
 /**
  * 数据入库前处理
  * @param type $data
  * @param type $type 状态1插入数据,2更新数据,3包含以上两种
  * @return boolean|string 
  */
 public function get($data, $type = 3)
 {
     //数据
     $this->data = $data;
     //栏目id
     $this->catid = (int) $data['catid'];
     //获取内容模型对象
     $this->ContentModel = ContentModel::getInstance($this->modelid);
     foreach ($this->fields as $field => $fieldInfo) {
         //如果是更新状态下,没有数据的,跳过
         if ($type == 2) {
             if (!isset($this->data[$field])) {
                 continue;
             }
         }
         //字段内容
         $value = $this->data[$field];
         //字段别名
         $name = $fieldInfo['name'];
         //最小值
         $minlength = (int) $fieldInfo['minlength'];
         //最大值
         $maxlength = (int) $fieldInfo['maxlength'];
         //数据校验正则
         $pattern = $fieldInfo['pattern'];
         //数据校验未通过的提示信息
         $errortips = empty($fieldInfo['errortips']) ? $name . ' 不符合要求!' : $fieldInfo['errortips'];
         //配置
         $setting = unserialize($fieldInfo['setting']);
         //是否主表
         $issystem = $fieldInfo['issystem'] ? true : false;
         //验证条件
         if (in_array($type, array(1, 3))) {
             //新增时,必须验证
             $condition = 1;
         } else {
             //当存在值时验证
             $condition = 2;
         }
         //进行长度验证
         if ($minlength) {
             $this->ContentModel->addValidate(array($field, 'require', $name . ' 不能为空!', $condition, 'regex', 3), $issystem);
             $this->ContentModel->addValidate(array($field, 'isMin', $name . ' 不得小于 ' . $minlength . "个字符!", $condition, 'function', 3, array($minlength)), $issystem);
         }
         if ($maxlength) {
             $this->ContentModel->addValidate(array($field, 'isMax', $name . ' 不得多于 ' . $maxlength . "个字符!", $condition, 'function', 3, array($maxlength)), $issystem);
         }
         //数据校验正则
         if ($pattern) {
             $this->ContentModel->addValidate(array($field, $pattern, $errortips, 2, 'regex', 3), $issystem);
         }
         //值唯一
         if ($fieldInfo['isunique']) {
             $this->ContentModel->addValidate(array($field, '', $name . " 该值必须不重复!", 2, 'unique', 3), $issystem);
         }
         //字段类型
         $func = $fieldInfo['formtype'];
         //检测对应字段方法是否存在,存在则执行此方法,并传入字段名和字段值
         if (method_exists($this, $func)) {
             $value = $this->{$func}($field, $value);
         }
         //字段扩展,可以对字段内容进行再次处理,类似ECMS字段处理函数
         if ($setting['backstagefun'] || $setting['frontfun']) {
             load("@.treatfun");
             $backstagefun = explode("###", $setting['backstagefun']);
             $usfun = $backstagefun[0];
             $usparam = $backstagefun[1];
             //前后台
             if (defined("IN_ADMIN") && IN_ADMIN) {
                 //检查方法是否存在
                 if (function_exists($usfun)) {
                     //判断是入库执行类型
                     if ((int) $setting['backstagefun_type'] == 1 || (int) $setting['backstagefun_type'] == 3) {
                         //调用自定义函数,参数传入:模型id,栏目ID,信息ID,字段内容,字段名,操作类型,附加参数
                         try {
                             $value = call_user_func($usfun, $this->modelid, $this->catid, 0, $value, $field, ACTION_NAME, $usparam);
                         } catch (Exception $exc) {
                             //记录日志
                             Log::write("模型id:" . $this->modelid . ",错误信息:调用自定义函数" . $usfun . "出现错误!");
                         }
                     }
                 }
             } else {
                 //前台投稿处理自定义函数处理
                 //判断当前用户组是否拥有使用字段处理函数的权限,该功能暂时木有,以后加上
                 if (true) {
                     $backstagefun = explode("###", $setting['frontfun']);
                     $usfun = $backstagefun[0];
                     $usparam = $backstagefun[1];
                     //检查方法是否存在
                     if (function_exists($usfun)) {
                         //判断是入库执行类型
                         if ((int) $setting['backstagefun_type'] == 1 || (int) $setting['backstagefun_type'] == 3) {
                             //调用自定义函数,参数传入:模型id,栏目ID,信息ID,字段内容,字段名,操作类型,附加参数
                             try {
                                 $value = call_user_func($usfun, $this->modelid, $this->catid, 0, $value, $field, ACTION_NAME, $usparam);
                             } catch (Exception $exc) {
                                 //记录日志
                                 Log::write("模型id:" . $this->modelid . ",错误信息:调用自定义函数" . $usfun . "出现错误!");
                             }
                         }
                     }
                 }
             }
         }
         //除去已经处理过的字段
         unset($data[$field]);
         //当没有返回时,或者为 null 时,等于空字符串,null有时会出现mysql 语法错误。
         if (is_null($value)) {
             continue;
         }
         //把系统字段和模型字段分开
         if ($issystem) {
             $this->infoData[$field] = $value;
         } else {
             $this->infoData[$this->ContentModel->getRelationName()][$field] = $value;
         }
     }
     //取得标题颜色
     if (isset($_POST['style_color'])) {
         //颜色选择为隐藏域 在这里进行取值
         $this->infoData['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
         //标题加粗等样式
         if (isset($_POST['style_font_weight'])) {
             $this->infoData['style'] = $this->infoData['style'] . ($_POST['style_font_weight'] ? ';' : '') . strip_tags($_POST['style_font_weight']);
         }
     }
     //如果$data还有存在模型字段以外的值,进行合并
     if (!empty($data)) {
         $this->infoData = array_merge($data, $this->infoData);
     }
     //如果副表没有字段,加个关联ID字段。不然不会在副表插入一条记录
     if (!isset($this->infoData[$this->ContentModel->getRelationName()]) && $this->model[$this->modelid]['type'] == 0) {
         $this->infoData[$this->ContentModel->getRelationName()] = array('id' => 0);
     }
     return $this->infoData;
 }
示例#19
0
 /**
  * 删除文章
  * @param $aid 文章aid
  * @return bool
  */
 public function del($aid)
 {
     $ContentModel = ContentModel::getInstance($this->mid);
     $map['aid'] = array('IN', $aid);
     //删除文章静态文件
     $content = $ContentModel->where($map)->find();
     $content = array_merge($content, $this->category[$content['cid']]);
     $htmlFile = Url::content($content);
     $htmlFile = str_replace(__ROOT__, ROOT_PATH, $htmlFile);
     if (is_file($htmlFile)) {
         @unlink($htmlFile);
     }
     //执行删除
     if ($ContentModel->del($aid)) {
         //删除文章tag
         $map['cid'] = $content['cid'];
         $map['aid'] = $content['aid'];
         M('content_tag')->where($map)->del();
         //生成关联文章
         $this->html->relation_content($this->mid, $content['aid']);
         //生成本栏目
         $this->html->relation_category($content['cid']);
         //生成父级栏目
         $this->html->parent_category($this->cid);
         //生成首页
         $this->html->index();
         Hook::listen('CONTENT_DEL');
         return true;
     } else {
         $this->error = '删除文章失败';
     }
 }
示例#20
0
 public function delCategory($cid)
 {
     $ContentModel = ContentModel::getInstance($this->_category[$cid]['mid']);
     $ContentModel->where(array('cid' => $cid))->del();
     //删除栏目权限
     M("category_access")->where("cid={$cid}")->del();
     //删除栏目
     $state = $this->del($cid);
     $this->updateCache();
     return $state;
 }
示例#21
0
 /**
  * 获得入库数据
  * @param $actionType 1 添加  2 修改
  */
 public function get(array $InsertData)
 {
     //作者uid
     $InsertData['uid'] = session('uid');
     //修改时间
     $InsertData['updatetime'] = time();
     //文章模型
     $ContentModel = ContentModel::getInstance($this->_mid);
     //没有添加内容时初始设置
     if (!isset($InsertData['content'])) {
         $InsertData['content'] = '';
     }
     //自动提取文章描述
     if (isset($InsertData['description']) && empty($InsertData['description'])) {
         $InsertData['description'] = mb_substr(strip_tags($InsertData['content']), 0, 100, 'utf-8');
     }
     //自动提取关键字
     if (isset($InsertData['keywords']) && empty($InsertData['keywords'])) {
         $description = preg_replace("@\\s@is", "", $InsertData['description']);
         $words = String::splitWord($description);
         //没有分词不处理
         if (!empty($words)) {
             $i = 0;
             $k = "";
             foreach ($words as $w => $id) {
                 $k .= $w . ",";
                 $i++;
                 if ($i > 8) {
                     break;
                 }
             }
             $InsertData['keywords'] = substr($k, 0, -1);
         }
     }
     foreach ($this->_field as $field => $fieldInfo) {
         $set = $fieldInfo['set'];
         if (in_array($field, $this->_noDealField)) {
             continue;
         }
         $METHOD = $fieldInfo['field_type'];
         if (method_exists($this, $METHOD) && isset($InsertData[$field])) {
             if ($fieldInfo['table_type'] == 1) {
                 $Value = $this->{$METHOD}($fieldInfo, $InsertData[$field]);
                 $InsertData[$field] = $Value;
             } else {
                 $Value = $this->{$METHOD}($fieldInfo, $InsertData[$field]);
                 $InsertData[$fieldInfo['table_name']][$field] = $Value;
                 //删除旧数据
                 unset($InsertData[$field]);
             }
         }
         //值唯一验证
         if ((int) $fieldInfo['isunique'] == 1) {
             if (M($fieldInfo['table_name'])->where($field . "='{$Value}'")->find()) {
                 $this->error = $fieldInfo['title'] . '已经存在';
                 return false;
             }
         }
         $validateRule = array();
         //验证时间 1 有这个表单就验证  2 必须验证
         $validateOccasion = (int) $fieldInfo['required'] ? 2 : 3;
         //设置验证规则
         if (isset($set['maxlength']) && !empty($set['maxlength'])) {
             $maxlength = (int) $set['maxlength'];
             $minlength = (int) $set['minlength'];
             if ($maxlength && $maxlength > $minlength) {
                 $validateRule[] = array($field, "minlen:{$minlength}", $fieldInfo['title'] . " 数量不能小于{$minlength}个字", $validateOccasion, 3);
                 $validateRule[] = array($field, "maxlen:{$maxlength}", $fieldInfo['title'] . " 数量不能大于{$maxlength}个字", $validateOccasion, 3);
             }
         }
         //验证规则
         if (isset($fieldInfo['validate']) && !empty($fieldInfo['validate'])) {
             $regexp = $fieldInfo['validate'];
             $error = empty($fieldInfo['error']) ? $fieldInfo['title'] . ' 输入错误' : $set['error'];
             $validateRule[] = array($field, "regexp:{$regexp}", $error, $validateOccasion, 3);
         }
         //必须输入验证
         if (isset($fieldInfo['required']) && (int) $fieldInfo['required'] == 1) {
             $validateRule[] = array($field, "nonull", $fieldInfo['title'] . ' 不能为空', $validateOccasion, 3);
         }
         if (!empty($validateRule)) {
             foreach ($validateRule as $validate) {
                 $ContentModel->addValidate($validate);
             }
         }
     }
     //如果没有缩略图时,删除图片属性
     if (!isset($InsertData['flag'])) {
         $InsertData['flag'] = '';
     }
     $flag = explode(',', $InsertData['flag']);
     if (empty($InsertData['thumb'])) {
         if (false !== ($k = array_search('图片', $flag))) {
             unset($flag[$k]);
         }
     } else {
         $flag[] = '图片';
     }
     $InsertData['flag'] = implode(',', array_unique($flag));
     return $InsertData;
 }
 public function edit()
 {
     if (IS_POST) {
         //验证权限
         $this->checkAccess();
         $ContentModel = new Content();
         if ($ContentModel->edit()) {
             $this->success('发表成功!');
         } else {
             $this->error($ContentModel->error);
         }
     } else {
         $aid = Q('aid', 0, 'intval');
         if (!$aid) {
             $this->error('参数错误');
         }
         $ContentModel = ContentModel::getInstance($this->mid);
         $editData = $ContentModel->find($aid);
         //获取分配字段
         $form = K('ContentForm');
         $this->assign('form', $form->get($editData));
         //分配验证规则
         $this->assign('formValidate', $form->formValidate);
         $this->assign('editData', $editData);
         $this->display();
     }
 }
示例#23
0
 /**
  * 删除栏目
  * @param $cid
  * @return bool
  */
 public function delCategory($cid)
 {
     if (!$cid || !isset($this->category[$cid])) {
         $this->error = 'cid参数错误';
         return false;
     }
     /**
      * 获得子栏目
      */
     $category = Data::channelList($this->category, $cid);
     $category[]['cid'] = $cid;
     foreach ($category as $cat) {
         //删除栏目文章
         $ContentModel = ContentModel::getInstance($this->category[$cat['cid']]['mid']);
         $ContentModel->where("cid=" . $cat['cid'])->del();
         //删除栏目权限
         M("category_access")->where("cid=" . $cat['cid'])->del();
         //删除栏目
         $this->del($cat['cid']);
     }
     //        //生成所有栏目
     //        $this->html->all_category();
     //        //生成首页
     //        $this->html->index();
     //更新缓存
     return $this->updateCache();
 }