/**
  * @brief postPost 添加一篇文章
  *
  * @return void
  */
 public function postPost()
 {
     $p = array();
     $p['title'] = htmlspecialchars(Request::P('title', 'string'));
     $p['content'] = Request::P('content', 'string');
     $p['category'] = Request::P('category', 'array');
     if (!$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;
     $user = Widget::getWidget('User')->getUser();
     $p['uid'] = $user['uid'];
     $p['alias'] = '';
     $p['type'] = 1;
     $p['status'] = 1;
     // 发布文章
     $post = new PostLibrary();
     $meta = new MetaLibrary();
     $pid = $post->postPost($p);
     // 处理分类
     foreach ($p['category'] as $c) {
         $meta->addRelation($c, $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, $pid);
         }
     }
     // 处理新附件
     $meta = new MetaLibrary();
     $meta->setType(3);
     $meta->setPID(1000000000);
     $attachments = $meta->getMeta();
     foreach ($attachments as $a) {
         $meta->movRelation($a['mid'], 1000000000, $pid);
     }
     // 插件接口
     $p['pid'] = $pid;
     Plugin::call('postPost', $p);
     $r = array('success' => TRUE, 'message' => _t('Add post success.'));
     Response::ajaxReturn($r);
 }
 /**
  * @brief postPage 发布页面
  *
  * @return void
  */
 public function postPage()
 {
     $p = array();
     $p['title'] = Request::P('title', 'string');
     $p['alias'] = Request::P('alias', 'string');
     $p['content'] = Request::P('content', 'string');
     if (!$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;
     $user = Widget::getWidget('User')->getUser();
     $p['uid'] = $user['uid'];
     $p['top'] = 0;
     $p['type'] = 2;
     $p['status'] = 1;
     $post = new PostLibrary();
     // 检查别名是否重复
     if ($post->getPage($p['alias'])) {
         $r = array('success' => FALSE, 'message' => _t('Alias already exists.'));
         Response::ajaxReturn($r);
         return;
     }
     // 写入页面
     $pid = $post->postPost($p);
     // 处理新附件
     $meta = new MetaLibrary();
     $meta->setType(3);
     $meta->setPID(1000000000);
     $attachments = $meta->getMeta();
     foreach ($attachments as $a) {
         $meta->movRelation($a['mid'], 1000000000, $pid);
     }
     // 插件接口
     $p['pid'] = $pid;
     Plugin::call('postPage', $p);
     $r = array('success' => TRUE, 'message' => _t('Add page success.'));
     Response::ajaxReturn($r);
 }