| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* EditPost class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2006 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: EditPost.php 1398 2006-09-08 19:31:03Z xue $
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* EditPost class
|
|
|
14 |
*
|
|
|
15 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
16 |
* @link http://www.pradosoft.com/
|
|
|
17 |
* @copyright Copyright © 2006 PradoSoft
|
|
|
18 |
* @license http://www.pradosoft.com/license/
|
|
|
19 |
*/
|
|
|
20 |
class EditPost extends BlogPage
|
|
|
21 |
{
|
|
|
22 |
private $_postRecord=null;
|
|
|
23 |
|
|
|
24 |
public function onInit($param)
|
|
|
25 |
{
|
|
|
26 |
parent::onInit($param);
|
|
|
27 |
$id=TPropertyValue::ensureInteger($this->Request['id']);
|
|
|
28 |
$this->_postRecord=$this->DataAccess->queryPostByID($id);
|
|
|
29 |
if($this->_postRecord===null)
|
|
|
30 |
throw new BlogException(500,'post_id_invalid',$id);
|
|
|
31 |
// only the author and admin can edit the post
|
|
|
32 |
if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID)
|
|
|
33 |
throw new BlogException(500,'post_edit_disallowed',$id);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function onLoad($param)
|
|
|
37 |
{
|
|
|
38 |
parent::onLoad($param);
|
|
|
39 |
if(!$this->IsPostBack)
|
|
|
40 |
{
|
|
|
41 |
$postRecord=$this->_postRecord;
|
|
|
42 |
$this->Title->Text=$postRecord->Title;
|
|
|
43 |
$this->Content->Text=$postRecord->Content;
|
|
|
44 |
$this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT;
|
|
|
45 |
$this->Categories->DataSource=$this->DataAccess->queryCategories();
|
|
|
46 |
$this->Categories->dataBind();
|
|
|
47 |
$cats=$this->DataAccess->queryCategoriesByPostID($postRecord->ID);
|
|
|
48 |
$catIDs=array();
|
|
|
49 |
foreach($cats as $cat)
|
|
|
50 |
$catIDs[]=$cat->ID;
|
|
|
51 |
$this->Categories->SelectedValues=$catIDs;
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public function saveButtonClicked($sender,$param)
|
|
|
56 |
{
|
|
|
57 |
if($this->IsValid)
|
|
|
58 |
{
|
|
|
59 |
$postRecord=$this->_postRecord;
|
|
|
60 |
$postRecord->Title=$this->Title->SafeText;
|
|
|
61 |
$postRecord->Content=$this->Content->SafeText;
|
|
|
62 |
if($this->DraftMode->Checked)
|
|
|
63 |
$postRecord->Status=PostRecord::STATUS_DRAFT;
|
|
|
64 |
else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval']))
|
|
|
65 |
$postRecord->Status=PostRecord::STATUS_PENDING;
|
|
|
66 |
else
|
|
|
67 |
$postRecord->Status=PostRecord::STATUS_PUBLISHED;
|
|
|
68 |
$postRecord->ModifyTime=time();
|
|
|
69 |
$cats=array();
|
|
|
70 |
foreach($this->Categories->SelectedValues as $value)
|
|
|
71 |
$cats[]=TPropertyValue::ensureInteger($value);
|
|
|
72 |
$this->DataAccess->updatePost($postRecord,$cats);
|
|
|
73 |
$this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID));
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
?>
|