Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * ViewPost class file
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2006 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: ViewPost.php 1398 2006-09-08 19:31:03Z xue $
10
 */
11
 
12
/**
13
 * ViewPost class
14
 *
15
 * @author Qiang Xue <qiang.xue@gmail.com>
16
 * @link http://www.pradosoft.com/
17
 * @copyright Copyright &copy; 2006 PradoSoft
18
 * @license http://www.pradosoft.com/license/
19
 */
20
class ViewPost extends BlogPage
21
{
22
	private $_post=null;
23
 
24
	public function onInit($param)
25
	{
26
		parent::onInit($param);
27
		$id=TPropertyValue::ensureInteger($this->Request['id']);
28
		$this->_post=$this->DataAccess->queryPostByID($id);
29
		if($this->_post===null)
30
			throw new BlogException(500,'post_id_invalid',$id);
31
		// if post is not published, only the author and admin can view it
32
		if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID)
33
			throw new BlogException(500,'post_view_disallowed',$id);
34
		$this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8');
35
	}
36
 
37
	public function getCanEditPost()
38
	{
39
		$user=$this->getUser();
40
		return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID;
41
	}
42
 
43
	public function getCurrentPost()
44
	{
45
		return $this->_post;
46
	}
47
 
48
	public function onLoad($param)
49
	{
50
		parent::onLoad($param);
51
		$this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY;
52
		$this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID);
53
		$this->CategoryList->dataBind();
54
		$this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID);
55
		$this->CommentList->dataBind();
56
	}
57
 
58
	public function submitCommentButtonClicked($sender,$param)
59
	{
60
		if($this->IsValid)
61
		{
62
			$commentRecord=new CommentRecord;
63
			$commentRecord->PostID=$this->CurrentPost->ID;
64
			$commentRecord->AuthorName=$this->CommentAuthor->SafeText;
65
			$commentRecord->AuthorEmail=$this->CommentEmail->Text;
66
			$commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText;
67
			$commentRecord->AuthorIP=$this->Request->UserHostAddress;
68
			$commentRecord->Content=$this->CommentContent->SafeText;
69
			$commentRecord->CreateTime=time();
70
			$commentRecord->Status=0;
71
			$this->DataAccess->insertComment($commentRecord);
72
			$this->Response->reload();
73
		}
74
	}
75
 
76
	public function deleteButtonClicked($sender,$param)
77
	{
78
		$this->DataAccess->deletePost($this->CurrentPost->ID);
79
		$this->gotoDefaultPage();
80
	}
81
 
82
	public function repeaterItemCommand($sender,$param)
83
	{
84
		$id=TPropertyValue::ensureInteger($param->CommandParameter);
85
		$this->DataAccess->deleteComment($id);
86
		$this->Response->reload();
87
	}
88
}
89
 
90
?>