コード例 #1
0
 /**
  * @brief showTag 显示某标签下的文章
  *
  * @param $params 参数
  *
  * @return void
  */
 public function showTag($params)
 {
     // 根据 Meta 别名获取 Meta ID
     $meta = new MetaLibrary();
     $meta->setType(2);
     $meta->setName(urldecode($params['name']));
     if (!($m = $meta->getMeta())) {
         Response::error(404);
         return;
     }
     // 获取文章数据
     Widget::initWidget('Post');
     Widget::getWidget('Post')->setPerPage(8);
     Widget::getWidget('Post')->setCurrentPage(isset($params['page']) ? $params['page'] : 1);
     Widget::getWidget('Post')->setCurrentMeta($m[0]['mid']);
     Widget::getWidget('Post')->query();
     // 设置标题、描述、关键词
     Widget::getWidget('Global')->title = $m[0]['name'];
     Widget::getWidget('Global')->description = $m[0]['description'];
     Widget::getWidget('Global')->keywords = $m[0]['name'];
     $this->display('index.php');
 }
コード例 #2
0
 /**
  * @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);
 }