/** * 信息提交 */ public function post() { if (IS_POST) { //表单ID $modelid = $formid = (int) $this->_post("formid"); //模型 $moinfo = $this->Model_form[$formid]; if (!$moinfo) { $this->error("该表单不存在或者已经关闭!"); } $tablename = M('Model')->where(array("modelid" => $formid))->getField("tablename"); $tablename = ucwords($tablename); $db = M($tablename); $setting = unserialize($moinfo['setting']); $time = time(); //时间判断 if ($setting['starttime']) { if ($time < (int) $setting['starttime']) { $this->error("还没开始!"); } } if ($setting['endtime']) { if ($time > (int) $setting['endtime']) { $this->error("已经结束!"); } } //是否允许游客提交 if ((int) $setting['allowunreg'] == 0) { //判断是否登陆 if (!AppframeAction::$Cache['uid']) { $this->error("请先登陆!"); } } //是否允许同一IP多次提交 if ((int) $setting['allowmultisubmit'] == 0) { $ip = get_client_ip(); $count = $db->where(array("ip" => $ip))->count(); if ($count) { $this->error("你已经提交过了!"); } } $info = array_merge($_POST['info'], array(C("TOKEN_NAME") => $_POST[C("TOKEN_NAME")])); //关闭表单验证 C('TOKEN_ON', false); $data = $db->create($info); if ($data) { require_cache(RUNTIME_PATH . 'content_input.class.php'); require_cache(RUNTIME_PATH . 'content_update.class.php'); $content_input = new content_input($modelid, $this); $inputinfo = $content_input->get($data, 0); //检查数据是否有问题! if (is_bool($inputinfo) && $inputinfo == false) { $this->error($content_input->error); } //主表字段内容 $systeminfo = $inputinfo['system']; //增加一些系统必要字段 $uid = AppframeAction::$Cache['uid']; $username = AppframeAction::$Cache['username']; $systeminfo['userid'] = $uid ? $uid : 0; $systeminfo['username'] = $username ? $username : "******"; $systeminfo['datetime'] = time(); $systeminfo['ip'] = get_client_ip(); if (!$db->autoCheckToken($info)) { $this->error("表单令牌错误!"); } //写入数据 $id = $db->data($systeminfo)->add(); if ($id) { //信息量+1 M("Model")->where(array("modelid" => $modelid))->setInc("items"); //调用 update $content_update = new content_update($modelid, $id, $this); $content_update->update($systeminfo); $forward = $_POST['forward'] ? $_POST['forward'] : ""; //发送邮件 if ($setting['sendmail'] && $setting['mails']) { $mails = explode("|", $setting['mails']); $title = $systeminfo['username'] . " 提交了新的表单信息!"; $message = "刚刚有人在《" . $moinfo['name'] . "》中提交了新的信息,请进入后台查看!"; SendMail($mails, $title, $message); } $this->success("提交成功!", $forward); } else { $this->error("提交失败!"); } } else { $this->error(M($tablename)->getError()); } } }
/** * 修改内容 * @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; }
/** * 修改内容 * @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; }
/** * 修改内容 * * @param $datas */ public function edit_content($data, $id) { $model_tablename = $this->model_tablename; //前台权限判断 if (!defined('IN_ADMIN')) { $_username = param::get_cookie('_username'); $us = $this->get_one(array('id' => $id, 'username' => $_username)); if (!$us) { return false; } } $this->search_db = pc_base::load_model('search_model'); require_once CACHE_MODEL_PATH . 'content_input.class.php'; require_once CACHE_MODEL_PATH . 'content_update.class.php'; $content_input = new content_input($this->modelid); $inputinfo = $content_input->get($data); $systeminfo = $inputinfo['system']; $modelinfo = $inputinfo['model']; if ($data['inputtime'] && !is_numeric($data['inputtime'])) { $systeminfo['inputtime'] = strtotime($data['inputtime']); } elseif (!$data['inputtime']) { $systeminfo['inputtime'] = SYS_TIME; } else { $systeminfo['inputtime'] = $data['inputtime']; } if ($data['updatetime'] && !is_numeric($data['updatetime'])) { $systeminfo['updatetime'] = strtotime($data['updatetime']); } elseif (!$data['updatetime']) { $systeminfo['updatetime'] = SYS_TIME; } else { $systeminfo['updatetime'] = $data['updatetime']; } //自动提取摘要 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'] = addslashes($systeminfo['description']); } //自动提取缩略图 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 { //更新URL地址 $urls = $this->url->show($id, 0, $systeminfo['catid'], $systeminfo['inputtime'], $data['prefix'], $inputinfo, 'edit'); $systeminfo['url'] = $urls[0]; } //主表 $this->table_name = $this->db_tablepre . $model_tablename; $this->update($systeminfo, array('id' => $id)); //附属表 $this->table_name = $this->table_name . '_data'; $this->update($modelinfo, array('id' => $id)); $this->search_api($id, $inputinfo); //调用 update $content_update = new content_update($this->modelid, $id); $content_update->update($data); //更新附件状态 if (pc_base::load_config('system', 'attachment_stat')) { $this->attachment_db = pc_base::load_model('attachment_model'); $this->attachment_db->api_update('', 'c-' . $systeminfo['catid'] . '-' . $id, 2); } //更新审核列表 $this->content_check_db = pc_base::load_model('content_check_model'); $check_data = array('catid' => $systeminfo['catid'], 'siteid' => $this->siteid, 'title' => $systeminfo['title'], 'status' => $systeminfo['status']); if (!isset($systeminfo['status'])) { unset($check_data['status']); } $this->content_check_db->update($check_data, array('checkid' => 'c-' . $id . '-' . $this->modelid)); //生成静态 $html = pc_base::load_app_class('html', 'content'); if ($urls['content_ishtml']) { $html->show($urls[1], $urls['data']); } //在添加和修改内容处定义了 INDEX_HTML if (defined('INDEX_HTML')) { $html->index(); } if (defined('RELATION_HTML')) { $html->create_relation_html($systeminfo['catid']); } return true; }
/** * 修改内容 * @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; }