示例#1
0
 /**
  * 修改内容
  * @param type $data
  * @return boolean
  */
 public function edit($data = '')
 {
     if (empty($data)) {
         if (!empty($this->data)) {
             $data = $this->data;
             // 重置数据
             $this->data = array();
         } else {
             $this->error = L('_DATA_TYPE_INVALID_');
             return false;
         }
     }
     $this->id = (int) $data['id'];
     $this->catid = (int) $data['catid'];
     $this->modelid = getCategory($this->catid, 'modelid');
     //取得表单令牌验证码
     $data[C("TOKEN_NAME")] = $_POST[C("TOKEN_NAME")];
     //标签
     tag('content_edit_begin', $data);
     //栏目数据
     $catidinfo = getCategory($this->catid);
     if (empty($catidinfo)) {
         $this->error = '获取不到栏目数据!';
         return false;
     }
     //setting配置
     $catidsetting = $catidinfo['setting'];
     //前台投稿状态判断
     if (!defined('IN_ADMIN') || defined('IN_ADMIN') && IN_ADMIN == false) {
         //前台投稿编辑是否需要审核
         if ($catidsetting['member_editcheck']) {
             $data['status'] = 1;
         }
     }
     $model = ContentModel::getInstance($this->modelid);
     //真实发布时间
     $data['inputtime'] = $inputtime = $model->where(array("id" => $this->id))->getField('inputtime');
     //更新时间处理
     if ($data['updatetime'] && !is_numeric($data['updatetime'])) {
         $data['updatetime'] = strtotime($data['updatetime']);
     } elseif (!$data['updatetime']) {
         $data['updatetime'] = time();
     }
     //自动提取摘要,如果有设置自动提取,且description为空,且有内容字段才执行
     $this->description($data);
     //转向地址
     if ($data['islink'] == 1) {
         $urls["url"] = $_POST['linkurl'];
     } else {
         //生成该篇地址
         $urls = $this->generateUrl($data);
     }
     $data['url'] = $urls["url"];
     $content_input = new \content_input($this->modelid);
     //保存一份旧数据
     $oldata = $data;
     $data = $content_input->get($data, 2);
     if ($data) {
         //数据验证
         $data = $model->relation(true)->create($data, 2);
         if (false == $data) {
             $this->error = $model->getError();
             $this->tokenRecovery($data);
             return false;
         }
     } else {
         $this->error = $content_input->getError();
         return false;
     }
     //自动提取缩略图,从content 中提取
     $this->getThumb($data);
     $oldata['thumb'] = $data['thumb'];
     //数据修改,这里使用关联操作
     $status = $model->relation(true)->where(array('id' => $this->id))->save($data);
     if (false === $status) {
         $this->error = $model->getError();
         $this->tokenRecovery($data);
         return false;
     }
     //字段合并
     $model->dataMerger($data);
     //调用回调更新
     $content_update = new \content_update($this->modelid);
     $content_update->update($oldata);
     //更新附件状态,把相关附件和文章进行管理
     $attachment = service('Attachment');
     $attachment->api_update('', 'c-' . $data['catid'] . '-' . $id, 2);
     //标签
     tag('content_edit_end', $data);
     //生成相关
     $generatelish = 0;
     if (defined('IN_ADMIN') && IN_ADMIN) {
         //是否生成内容页
         if ($catidsetting['generatehtml']) {
             //生成静态
             if ($catidsetting['content_ishtml'] && $data['status'] == 99) {
                 $this->Html->show($data);
             }
         }
         //如果是未审核,删除已经生成
         if ($catidsetting['content_ishtml'] && !$data['islink'] && $data['status'] != 99) {
             $this->data($data)->deleteHtml();
         }
         //生成列表
         if ((int) $catidsetting['generatelish'] > 0) {
             $generatelish = (int) $catidsetting['generatelish'];
         }
     } else {
         //投稿内容页生成,直接审核通过的直接生成内容页
         if ($data['status'] == 99) {
             //生成静态
             if ($catidsetting['content_ishtml']) {
                 $this->Html->show($data);
             }
         } else {
             if ($catidsetting['content_ishtml'] && !$data['islink']) {
                 $this->data($data)->deleteHtml();
             }
         }
         //列表生成
         if ((int) $catidsetting['member_generatelish'] > 0) {
             $generatelish = (int) $catidsetting['member_generatelish'];
         }
     }
     //列表生成
     switch ($generatelish) {
         //生成当前栏目
         case 1:
             $this->Html->category($data['catid']);
             break;
             //生成首页
         //生成首页
         case 2:
             $this->Html->index();
             break;
             //生成父栏目
         //生成父栏目
         case 3:
             if ($catidinfo['parentid']) {
                 $this->Html->category($catidinfo['parentid']);
             }
             break;
             //生成当前栏目与父栏目
         //生成当前栏目与父栏目
         case 4:
             $this->Html->category($data['catid']);
             if ($catidinfo['parentid']) {
                 $this->Html->category($catidinfo['parentid']);
             }
             break;
             //生成父栏目与首页
         //生成父栏目与首页
         case 5:
             if ($catidinfo['parentid']) {
                 $this->Html->category($catidinfo['parentid']);
             }
             $this->Html->index();
             break;
             //生成当前栏目、父栏目与首页
         //生成当前栏目、父栏目与首页
         case 6:
             $this->Html->category($data['catid']);
             $this->Html->createRelationHtml($data['catid']);
             $this->Html->index();
             break;
     }
     //生成上一篇下一篇
     $this->relatedContent($this->catid, $this->id, 'edit');
     return true;
 }
示例#2
0
 /**
  * 修改内容 
  * @param array $data 数据
  * @param type $id 信息ID
  * @return boolean 
  */
 public function edit($data, $id)
 {
     $data['id'] = $id;
     $this->catid = (int) $data['catid'];
     $this->modelid = getCategory($this->catid, 'modelid');
     //取得表单令牌验证码
     $data[C("TOKEN_NAME")] = $_POST[C("TOKEN_NAME")];
     //标签
     tag("content_edit_begin", $data);
     //栏目数据
     $catidinfo = getCategory($this->catid);
     if (empty($catidinfo)) {
         $this->error = '获取不到栏目数据!';
         return false;
     }
     //setting配置
     $catidsetting = $catidinfo['setting'];
     //前台投稿状态判断
     if (defined('IN_ADMIN') && IN_ADMIN == false) {
         //前台投稿编辑是否需要审核
         if ($catidsetting['member_editcheck']) {
             $data['status'] = 1;
         }
     }
     //数据模型对象
     $this->contentModel = ContentModel::getInstance($this->modelid);
     $data['inputtime'] = $inputtime = $this->contentModel->where(array("id" => $id))->getField("inputtime");
     //更新时间处理
     if ($data['updatetime'] && !is_numeric($data['updatetime'])) {
         $data['updatetime'] = strtotime($data['updatetime']);
     } elseif (!$data['updatetime']) {
         $data['updatetime'] = time();
     }
     //自动提取摘要,如果有设置自动提取,且description为空,且有内容字段才执行
     if (isset($_POST['add_introduce']) && $data['description'] == '' && isset($data['content'])) {
         $content = $data['content'];
         $introcude_length = intval($_POST['introcude_length']);
         $data['description'] = str_cut(str_replace(array("\r\n", "\t", '[page]', '[/page]', '“', '”', ' '), '', strip_tags($content)), $introcude_length);
     }
     //转向地址
     if ($data['islink'] == 1) {
         $urls["url"] = $_POST['linkurl'];
     } else {
         //生成该篇地址
         $urls = $this->url->show($data);
     }
     $data['url'] = $urls["url"];
     //inputtime为真实发表时间,不允许修改
     if (isset($data['inputtime'])) {
         unset($data['inputtime']);
     }
     if (false == require_cache(RUNTIME_PATH . 'content_input.class.php')) {
         D("Category")->category_cache();
         D("Content_cache")->model_content_cache();
         require RUNTIME_PATH . 'content_input.class.php';
     }
     $content_input = new content_input($this->modelid);
     //保存一份旧数据
     $oldata = $data;
     $data = $content_input->get($data, 2);
     if ($data) {
         //数据验证
         $data = $this->contentModel->create($data, 2);
         if (false == $data) {
             $this->error = $this->contentModel->getError();
             $this->contentModel->tokenRecovery($data);
             return false;
         }
     } else {
         $this->error = $content_input->getError();
         return false;
     }
     //取得副表下标
     $getRelationName = $this->contentModel->getRelationName();
     //检查content字段在主表还是副表
     $isContent = isset($data['content']) ? 1 : 0;
     //自动提取缩略图,从content 中提取
     if (empty($data['thumb'])) {
         $content = $isContent ? $data['content'] : $data[$getRelationName]['content'];
         $auto_thumb_no = I('.auto_thumb_no', 1, 'intval') - 1;
         if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
             $oldata['thumb'] = $data['thumb'] = $matches[3][$auto_thumb_no];
         }
     }
     //数据修改,这里使用关联操作
     $status = $this->contentModel->relation(true)->where(array('id' => $id))->save($data);
     if (false === $status) {
         $this->error = $this->contentModel->getError();
         $this->contentModel->tokenRecovery($data);
         return false;
     }
     //字段合并
     $this->contentModel->dataMerger($data);
     $oldata['inputtime'] = $data['inputtime'] = $inputtime;
     //调用 update
     if (false == require_cache(RUNTIME_PATH . 'content_update.class.php')) {
         D("Category")->category_cache();
         D("Content_cache")->model_content_cache();
         require RUNTIME_PATH . 'content_update.class.php';
     }
     $content_update = new content_update($this->modelid);
     $updateStatus = $content_update->update($oldata);
     if (false == $updateStatus) {
         $this->error = $content_update->getError();
         return false;
     }
     //更新附件状态,把相关附件和文章进行管理
     $attachment = service("Attachment");
     $attachment->api_update('', 'c-' . $data['catid'] . '-' . $id, 2);
     //更新到全站搜索
     if ($data['status'] == 99) {
         $this->search_api($id, $data, "updata");
     } else {
         $this->search_api($id, $data, "delete");
     }
     //标签
     tag("content_edit_end", $data);
     //生成相关
     $generatelish = 0;
     import('Html');
     $html = get_instance_of('Html');
     if (defined('IN_ADMIN') && IN_ADMIN) {
         //是否生成内容页
         if ($catidsetting['generatehtml']) {
             //生成静态
             if ($catidsetting['content_ishtml'] && $data['status'] == 99) {
                 $html->show($data, 0, 'edit');
             }
         }
         //如果是未审核,删除已经生成
         if ($catidsetting['content_ishtml'] && !$data['islink'] && $data['status'] == 1) {
             $this->deleteHtml($data['catid'], $id, $inputtime, $data['prefix'], $data);
         }
         //生成列表
         if ((int) $catidsetting['generatelish'] > 0) {
             $generatelish = (int) $catidsetting['generatelish'];
         }
     } else {
         //投稿内容页生成,直接审核通过的直接生成内容页
         if ($data['status'] == 99) {
             //生成静态
             if ($catidsetting['content_ishtml']) {
                 $html->show($data, 0, 'edit');
             }
         } else {
             if ($catidsetting['content_ishtml'] && !$data['islink']) {
                 $this->deleteHtml($data['catid'], $id, $inputtime, $data['prefix'], $data);
             }
         }
         //列表生成
         if ((int) $catidsetting['member_generatelish'] > 0) {
             $generatelish = (int) $catidsetting['member_generatelish'];
         }
     }
     //列表生成
     switch ($generatelish) {
         //生成当前栏目
         case 1:
             $html->create_relation_html($data['catid']);
             break;
             //生成首页
         //生成首页
         case 2:
             $html->index();
             break;
             //生成父栏目
         //生成父栏目
         case 3:
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             break;
             //生成当前栏目与父栏目
         //生成当前栏目与父栏目
         case 4:
             $html->create_relation_html($data['catid']);
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             break;
             //生成父栏目与首页
         //生成父栏目与首页
         case 5:
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             $html->index();
             break;
             //生成当前栏目、父栏目与首页
         //生成当前栏目、父栏目与首页
         case 6:
             $html->create_relation_html($data['catid']);
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             $html->index();
             break;
     }
     //生成上一篇下一篇
     $this->related_content($data['catid'], $id, "edit");
     return true;
 }
示例#3
0
 /**
  * 修改内容 
  * @param array $data 数据
  * @param type $id 信息ID
  * @return boolean 
  */
 public function edit($data, $id)
 {
     require_array(array(RUNTIME_PATH . 'content_input.class.php', RUNTIME_PATH . 'content_update.class.php'));
     $this->catid = (int) $data['catid'];
     $this->modelid = $this->categorys[$this->catid]['modelid'];
     //主表操作开始
     $this->table_name = ucwords($this->Model[$this->modelid]['tablename']);
     $this->fbtable_name = $this->table_name . "_data";
     $this->Content = new ContentModel($this->table_name);
     $content_input = new content_input($this->modelid, $this);
     $inputinfo = $content_input->get($data);
     if (is_bool($inputinfo) && $inputinfo == false) {
         //显示错误
         $this->error($content_input->getError());
         return false;
     }
     //主表字段内容
     $systeminfo = $inputinfo['system'];
     //副表字段内容
     $modelinfo = $inputinfo['model'];
     //栏目数据
     $catidinfo = $this->categorys[$systeminfo['catid']];
     //setting配置
     $catidsetting = unserialize($catidinfo['setting']);
     //前台投稿状态判断
     if (defined('IN_ADMIN') && IN_ADMIN == false) {
         //前台投稿编辑是否需要审核
         if ($catidsetting['member_editcheck']) {
             $systeminfo['status'] = 1;
         }
     }
     //取得inputtime的真实发布时间
     //inputtime为真实发表时间,不允许修改
     $data['inputtime'] = $systeminfo['inputtime'] = $inputtime = $this->Content->where(array("id" => $id))->getField("inputtime");
     //更新时间处理
     if ($data['updatetime'] && !is_numeric($data['updatetime'])) {
         $systeminfo['updatetime'] = strtotime($data['updatetime']);
     } elseif (!$data['updatetime']) {
         $systeminfo['updatetime'] = time();
     } else {
         $systeminfo['updatetime'] = $data['updatetime'];
     }
     //自动提取摘要,如果有设置自动提取,且description为空,且有内容字段才执行
     if (isset($_POST['add_introduce']) && $systeminfo['description'] == '' && isset($modelinfo['content'])) {
         $content = stripslashes($modelinfo['content']);
         $introcude_length = intval($_POST['introcude_length']);
         $systeminfo['description'] = str_cut(str_replace(array("\r\n", "\t", '[page]', '[/page]', '“', '”', ' '), '', strip_tags($content)), $introcude_length);
         $inputinfo['system']['description'] = $systeminfo['description'] = Input::getVar($systeminfo['description']);
     }
     //自动提取缩略图,从content 中提取
     if (isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {
         $content = $content ? $content : stripslashes($modelinfo['content']);
         $auto_thumb_no = intval($_POST['auto_thumb_no']) - 1;
         if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
             $systeminfo['thumb'] = $matches[3][$auto_thumb_no];
         }
     }
     //转向地址
     if ($data['islink'] == 1) {
         $systeminfo['url'] = $_POST['linkurl'];
     } else {
         //生成该篇地址
         $urls = $this->url->show($id, 0, $systeminfo['catid'], $inputtime, $data['prefix'], $inputinfo, 'edit');
         $systeminfo['url'] = $urls[0];
     }
     //使用TP的自动验证,所以要把令牌合并
     $systeminfo = array_merge($systeminfo, array(C("TOKEN_NAME") => $_POST[C("TOKEN_NAME")]));
     $status = $this->Content->create($systeminfo);
     if (!$status) {
         $this->error($this->Content->getError());
     }
     //把副表的数据合并,按关联模型的需求合并
     $status['id'] = $id;
     $fdata = array($this->fbtable_name => $modelinfo);
     $status = array_merge($status, $fdata);
     //删除真实时间的信息,避免被更新
     unset($status['inputtime']);
     //数据修改,这里使用关联操作
     $this->Content->relation(true)->where(array('id' => $id))->save($status);
     //调用 update
     $content_update = new content_update($this->modelid, $id, $this);
     $data['url'] = $systeminfo['url'];
     $content_update->update($data);
     //更新附件状态,把相关附件和文章进行管理
     $this->attachment_db = service("Attachment");
     $this->attachment_db->api_update('', 'c-' . $systeminfo['catid'] . '-' . $id, 2);
     //更新到全站搜索
     if ($systeminfo['status'] == 99) {
         $this->search_api($id, $inputinfo, "updata");
     } else {
         $this->search_api($id, $inputinfo, "delete");
     }
     //生成相关
     $generatelish = 0;
     import('Html');
     $html = new Html();
     if (defined('IN_ADMIN') && IN_ADMIN) {
         //是否生成内容页
         if ($catidsetting['generatehtml']) {
             //生成静态
             if ($urls['content_ishtml'] && $status['status'] == 99) {
                 $html->show($urls[1], $urls['data']);
             }
         }
         //如果是未审核,删除已经生成
         if ($urls['content_ishtml'] && !$data['islink'] && $status['status'] == 1) {
             $this->deleteHtml($data['catid'], $id, $systeminfo['inputtime'], $systeminfo['prefix']);
         }
         //生成列表
         if ((int) $catidsetting['generatelish'] > 0) {
             $generatelish = (int) $catidsetting['generatelish'];
         }
     } else {
         //投稿内容页生成,直接审核通过的直接生成内容页
         if ($status['status'] == 99) {
             //生成静态
             if ($urls['content_ishtml']) {
                 $html->show($urls[1], $urls['data']);
             }
         } else {
             if ($urls['content_ishtml'] && !$data['islink']) {
                 $this->deleteHtml($data['catid'], $id, $systeminfo['inputtime'], $systeminfo['prefix']);
             }
         }
         //列表生成
         if ((int) $catidsetting['member_generatelish'] > 0) {
             $generatelish = (int) $catidsetting['member_generatelish'];
         }
     }
     //列表生成
     switch ($generatelish) {
         //生成当前栏目
         case 1:
             $html->create_relation_html($status['catid']);
             break;
             //生成首页
         //生成首页
         case 2:
             $html->index();
             break;
             //生成父栏目
         //生成父栏目
         case 3:
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             break;
             //生成当前栏目与父栏目
         //生成当前栏目与父栏目
         case 4:
             $html->create_relation_html($status['catid']);
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             break;
             //生成父栏目与首页
         //生成父栏目与首页
         case 5:
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             $html->index();
             break;
             //生成当前栏目、父栏目与首页
         //生成当前栏目、父栏目与首页
         case 6:
             $html->create_relation_html($status['catid']);
             if ($catidinfo['parentid']) {
                 $html->create_relation_html($catidinfo['parentid']);
             }
             $html->index();
             break;
     }
     //生成上一篇下一篇
     $this->related_content($status['catid'], $id, "edit");
     return true;
 }