/** * @brief editPost 编辑一篇文章 * * @return void */ public function editPost() { $p = array(); $p['pid'] = Request::P('pid'); $p['title'] = htmlspecialchars(Request::P('title', 'string')); $p['content'] = Request::P('content', 'string'); $p['category'] = Request::P('category', 'array'); if (!$p['pid'] || !$p['title'] || !$p['content'] || count($p['category']) == 1 && !$p['category'][0]) { $r = array('success' => FALSE, 'message' => _t('Title, Content and Category can not be null.')); Response::ajaxReturn($r); return; } $p['allow_reply'] = Request::P('allowComment') ? 1 : 0; $p['top'] = Request::P('top') ? 1 : 0; $p['alias'] = ''; $p['status'] = 1; // 编辑文章 $post = new PostLibrary(); $meta = new MetaLibrary(); $post->editPost($p); // 删除原有的分类与标签 $meta->setPID($p['pid']); $metas = $meta->getMeta(FALSE); foreach ($metas as $m) { if ($m['type'] == 1 || $m['type'] == 2) { $meta->delRelation($m['mid'], $p['pid']); } } $meta->setPID(0); // 处理分类 foreach ($p['category'] as $c) { $meta->addRelation($c, $p['pid']); } // 处理标签 if ($p['tags'] = Request::P('tags', 'string')) { $p['tags'] = str_replace(array(' ', ',', '、'), ',', $p['tags']); $p['tags'] = explode(',', $p['tags']); $meta->setType(2); foreach ($p['tags'] as $tag) { $meta->setName($tag); $t = $meta->getMeta(); if (!$t) { $t = $meta->addMeta(array('type' => 2, 'name' => $tag)); } else { $t = $t[0]['mid']; } $meta->addRelation($t, $p['pid']); } } // 处理新附件 $meta = new MetaLibrary(); $meta->setType(3); $meta->setPID(1000000000); $attachments = $meta->getMeta(); foreach ($attachments as $a) { $meta->movRelation($a['mid'], 1000000000, $p['pid']); } $r = array('success' => TRUE, 'message' => _t('Edit post success.')); Response::ajaxReturn($r); }
/** * @brief editPage 编辑页面 * * @return void */ public function editPage() { $p = array(); $p['pid'] = Request::P('pid'); $p['title'] = Request::P('title', 'string'); $p['alias'] = Request::P('alias', 'string'); $p['content'] = Request::P('content', 'string'); if (!$p['pid'] || !$p['title'] || !$p['content'] || !$p['alias']) { $r = array('success' => FALSE, 'message' => _t('Title, Content and Alias can not be null.')); Response::ajaxReturn($r); return; } $p['allow_reply'] = Request::P('allowComment') ? 1 : 0; $p['top'] = 0; $p['status'] = 1; $post = new PostLibrary(); // 检查别名是否重复 if (($pid = $post->getPage($p['alias'])) && $pid['pid'] != $p['pid']) { $r = array('success' => FALSE, 'message' => _t('Alias already exists.')); Response::ajaxReturn($r); return; } // 写入页面 $post->editPost($p); // 处理新附件 $meta = new MetaLibrary(); $meta->setType(3); $meta->setPID(1000000000); $attachments = $meta->getMeta(); foreach ($attachments as $a) { $meta->movRelation($a['mid'], 1000000000, $p['pid']); } $r = array('success' => TRUE, 'message' => _t('Edit page success.')); Response::ajaxReturn($r); }