예제 #1
0
?>
</a></dt>
	<dd id="tabPageAdd" style="display: <?php 
if (!Request::G('page')) {
    ?>
block<?php 
} else {
    ?>
none<?php 
}
?>
; ">
<?php 
if ($pid = Request::G('pid')) {
    $post = new PostLibrary();
    $p = $post->getPage($pid, FALSE);
    ?>
		<form action="<?php 
    path(array('do' => 'editPage'), 'AdminDo');
    ?>
" method="post" name="add_post" id="add-post">
			<div id="add-post-left">
				<textarea style="height: 440px;width:550px;" autocomplete="off" id="add-post-content" name="content"><?php 
    echo $p['content'];
    ?>
</textarea>
			</div>
			<div id="add-post-right">
				<ul id="add-post-option">
				<li>
					<label for="add-post-title" class="add-post-label"><?php 
 /**
  * @brief postComment 发表评论
  *
  * @return void
  */
 public function postComment()
 {
     $c = array();
     // 如果用户已登录,则可以不填写基本信息
     if (Widget::getWidget('User')->isLogin()) {
         $user = Widget::getWidget('User')->getUser();
         $c['uid'] = $user['uid'];
         $c['author'] = $user['username'];
         $c['email'] = $user['email'];
         $c['website'] = $user['website'];
     } else {
         $c['uid'] = 0;
         $c['author'] = Request::P('author', 'string');
         $c['email'] = Request::P('email', 'string');
         $c['website'] = Request::P('website', 'string');
     }
     $c['pid'] = Request::P('postId');
     $c['content'] = Request::P('content', 'string');
     $error = '';
     if (!$c['pid'] || !$c['author'] || !$c['email'] || !$c['content']) {
         // 检查信息完整性
         $error = _t('Author, Email and Content can not be null.');
     } else {
         // 检查文章是否存在、是否允许评论
         Widget::initWidget('Post');
         $post = new PostLibrary();
         $p = $post->getPost($c['pid']);
         if ($p) {
             Widget::getWidget('Post')->setPID($c['pid']);
         } else {
             $p = $post->getPage($c['pid'], FALSE);
             Widget::getWidget('Post')->setAlias($p['alias']);
         }
         if (!Widget::getWidget('Post')->query() || !Widget::getWidget('Post')->postAllowReply()) {
             $error = _t('Comment closed.');
         } else {
             // TODO 敏感词过滤
             // TODO 内容处理
             $c['content'] = str_replace(array("\r\n", "\n", "\r"), '<br />', htmlspecialchars($c['content']));
             $c = Plugin::call('postComment', $c);
             // 写入评论
             $comment = new CommentLibrary();
             $comment->postComment($c);
             // 评论计数加一
             $post->incReply($c['pid']);
             // 保存用户信息
             Response::setCookie('author', $c['author'], time() + 24 * 3600 * 365);
             Response::setCookie('email', $c['email'], time() + 24 * 3600 * 365);
             Response::setCookie('website', $c['website'], time() + 24 * 3600 * 365);
         }
     }
     if ($error) {
         $r = array('success' => FALSE, 'message' => $error);
     } else {
         $r = array('success' => TRUE, 'message' => _t('Post comment success.'));
     }
     if (Request::isAjax()) {
         Response::ajaxReturn($r);
     } else {
         if ($error) {
             Response::error(_t('Post failed'), $error);
         } else {
             Response::back();
         }
     }
 }
 /**
  * @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);
 }
 /**
  * @brief query 根据条件取出文章数据
  *
  * @return bool
  */
 public function query()
 {
     $post = new PostLibrary();
     if ($this->pid) {
         $this->currentPost = 1;
         $page = $post->getPost($this->pid);
         if ($page) {
             $this->posts = array($page);
             return TRUE;
         } else {
             return FALSE;
         }
     } elseif ($this->alias) {
         $this->currentPost = 1;
         $page = $post->getPage($this->alias);
         if ($page) {
             $this->posts = array($page);
             return TRUE;
         } else {
             return FALSE;
         }
     } else {
         $this->currentPost = 0;
         $post->setPerPage($this->perPage);
         $post->setAuthor($this->authorID);
         $post->setCurrentPage($this->currentPage);
         $post->setCurrentMeta($this->currentMeta);
         $post->setSearchWord($this->searchWord);
         $this->posts = $post->getPosts();
         return TRUE;
     }
 }
 /**
  * @brief nav 反回分页数据
  *
  * @return mix
  */
 public function nav()
 {
     $currentPage = $this->currentPage;
     $maxPerPage = $this->perPage;
     if (!$this->pid && !$this->alias) {
         $totalComment = Database::result("SELECT COUNT(`cid`) FROM `{$this->prefix}comments` WHERE `status`={$this->status}");
     } else {
         if ($this->alias) {
             $post = new PostLibrary();
             $p = $post->getPage($this->alias);
             $this->pid = $p['pid'];
         }
         $totalComment = Database::result("SELECT COUNT(`cid`) FROM `{$this->prefix}comments` WHERE `pid`={$this->pid} AND `status`={$this->status}");
     }
     if ($totalComment <= $maxPerPage) {
         return FALSE;
     }
     if ($totalComment % $maxPerPage == 0) {
         $totalPage = floor($totalComment / $maxPerPage);
     } else {
         $totalPage = floor($totalComment / $maxPerPage) + 1;
     }
     return array('totalPage' => $totalPage, 'currentPage' => $currentPage);
 }