From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- demos/blog/protected/Pages/Posts/EditCategory.php | 120 ++++----- demos/blog/protected/Pages/Posts/EditPost.php | 154 ++++++------ demos/blog/protected/Pages/Posts/ListPost.php | 282 +++++++++++----------- demos/blog/protected/Pages/Posts/MyPost.php | 100 ++++---- demos/blog/protected/Pages/Posts/NewCategory.php | 80 +++--- demos/blog/protected/Pages/Posts/NewPost.php | 112 ++++----- demos/blog/protected/Pages/Posts/ViewPost.php | 178 +++++++------- 7 files changed, 513 insertions(+), 513 deletions(-) (limited to 'demos/blog/protected/Pages/Posts') diff --git a/demos/blog/protected/Pages/Posts/EditCategory.php b/demos/blog/protected/Pages/Posts/EditCategory.php index 76013264..d60418be 100644 --- a/demos/blog/protected/Pages/Posts/EditCategory.php +++ b/demos/blog/protected/Pages/Posts/EditCategory.php @@ -1,61 +1,61 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * EditCategory class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class EditCategory extends BlogPage -{ - private $_category; - - public function onInit($param) - { - parent::onInit($param); - $id=TPropertyValue::ensureInteger($this->Request['id']); - $this->_category=$this->DataAccess->queryCategoryByID($id); - if($this->_category===null) - throw new BlogException(500,'category_id_invalid',$id); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->CategoryName->Text=$this->_category->Name; - $this->CategoryDescription->Text=$this->_category->Description; - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $this->_category->Name=$this->CategoryName->Text; - $this->_category->Description=$this->CategoryDescription->Text; - $this->DataAccess->updateCategory($this->_category); - $this->gotoPage('Posts.ListPost',array('cat'=>$this->_category->ID)); - } - } - - public function checkCategoryName($sender,$param) - { - $name=$this->CategoryName->Text; - $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditCategory class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditCategory extends BlogPage +{ + private $_category; + + public function onInit($param) + { + parent::onInit($param); + $id=TPropertyValue::ensureInteger($this->Request['id']); + $this->_category=$this->DataAccess->queryCategoryByID($id); + if($this->_category===null) + throw new BlogException(500,'category_id_invalid',$id); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->CategoryName->Text=$this->_category->Name; + $this->CategoryDescription->Text=$this->_category->Description; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $this->_category->Name=$this->CategoryName->Text; + $this->_category->Description=$this->CategoryDescription->Text; + $this->DataAccess->updateCategory($this->_category); + $this->gotoPage('Posts.ListPost',array('cat'=>$this->_category->ID)); + } + } + + public function checkCategoryName($sender,$param) + { + $name=$this->CategoryName->Text; + $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/EditPost.php b/demos/blog/protected/Pages/Posts/EditPost.php index 8d754b30..3ba6f069 100644 --- a/demos/blog/protected/Pages/Posts/EditPost.php +++ b/demos/blog/protected/Pages/Posts/EditPost.php @@ -1,78 +1,78 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * EditPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class EditPost extends BlogPage -{ - private $_postRecord=null; - - public function onInit($param) - { - parent::onInit($param); - $id=TPropertyValue::ensureInteger($this->Request['id']); - $this->_postRecord=$this->DataAccess->queryPostByID($id); - if($this->_postRecord===null) - throw new BlogException(500,'post_id_invalid',$id); - // only the author and admin can edit the post - if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID) - throw new BlogException(500,'post_edit_disallowed',$id); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $postRecord=$this->_postRecord; - $this->Title->Text=$postRecord->Title; - $this->Content->Text=$postRecord->Content; - $this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT; - $this->Categories->DataSource=$this->DataAccess->queryCategories(); - $this->Categories->dataBind(); - $cats=$this->DataAccess->queryCategoriesByPostID($postRecord->ID); - $catIDs=array(); - foreach($cats as $cat) - $catIDs[]=$cat->ID; - $this->Categories->SelectedValues=$catIDs; - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $postRecord=$this->_postRecord; - $postRecord->Title=$this->Title->SafeText; - $postRecord->Content=$this->Content->SafeText; - if($this->DraftMode->Checked) - $postRecord->Status=PostRecord::STATUS_DRAFT; - else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) - $postRecord->Status=PostRecord::STATUS_PENDING; - else - $postRecord->Status=PostRecord::STATUS_PUBLISHED; - $postRecord->ModifyTime=time(); - $cats=array(); - foreach($this->Categories->SelectedValues as $value) - $cats[]=TPropertyValue::ensureInteger($value); - $this->DataAccess->updatePost($postRecord,$cats); - $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditPost extends BlogPage +{ + private $_postRecord=null; + + public function onInit($param) + { + parent::onInit($param); + $id=TPropertyValue::ensureInteger($this->Request['id']); + $this->_postRecord=$this->DataAccess->queryPostByID($id); + if($this->_postRecord===null) + throw new BlogException(500,'post_id_invalid',$id); + // only the author and admin can edit the post + if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID) + throw new BlogException(500,'post_edit_disallowed',$id); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $postRecord=$this->_postRecord; + $this->Title->Text=$postRecord->Title; + $this->Content->Text=$postRecord->Content; + $this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT; + $this->Categories->DataSource=$this->DataAccess->queryCategories(); + $this->Categories->dataBind(); + $cats=$this->DataAccess->queryCategoriesByPostID($postRecord->ID); + $catIDs=array(); + foreach($cats as $cat) + $catIDs[]=$cat->ID; + $this->Categories->SelectedValues=$catIDs; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $postRecord=$this->_postRecord; + $postRecord->Title=$this->Title->SafeText; + $postRecord->Content=$this->Content->SafeText; + if($this->DraftMode->Checked) + $postRecord->Status=PostRecord::STATUS_DRAFT; + else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) + $postRecord->Status=PostRecord::STATUS_PENDING; + else + $postRecord->Status=PostRecord::STATUS_PUBLISHED; + $postRecord->ModifyTime=time(); + $cats=array(); + foreach($this->Categories->SelectedValues as $value) + $cats[]=TPropertyValue::ensureInteger($value); + $this->DataAccess->updatePost($postRecord,$cats); + $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/ListPost.php b/demos/blog/protected/Pages/Posts/ListPost.php index 0e0a044c..7ff9dac9 100644 --- a/demos/blog/protected/Pages/Posts/ListPost.php +++ b/demos/blog/protected/Pages/Posts/ListPost.php @@ -1,142 +1,142 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ListPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ListPost extends BlogPage -{ - private $_posts; - private $_category; - - public function onInit($param) - { - parent::onInit($param); - $this->_posts=$this->DataAccess->queryPosts( - $this->getPostFilter(), - $this->getCategoryFilter(), - 'ORDER BY a.status DESC, create_time DESC', - 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); - if($this->Request['cat']!==null) - { - $catID=TPropertyValue::ensureInteger($this->Request['cat']); - $this->_category=$this->DataAccess->queryCategoryByID($catID); - $this->CategoryPanel->Visible=true; - } - $this->Title=$this->Application->Parameters['SiteTitle']; - } - - private function getPageOffset() - { - if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) - $offset=0; - return $offset; - } - - private function getPageSize() - { - if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) - $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); - return $limit; - } - - private function getTimeFilter() - { - if(($time=TPropertyValue::ensureInteger($this->Request['time']))>0) - { - $year=(integer)($time/100); - $month=$time%100; - $startTime=mktime(0,0,0,$month,1,$year); - if(++$month>12) - { - $month=1; - $year++; - } - $endTime=mktime(0,0,0,$month,1,$year); - return "create_time>=$startTime AND create_time<$endTime"; - } - else - return ''; - } - - private function getPostFilter() - { - $filter='(a.status=0 OR a.status=3)'; - if(($timeFilter=$this->getTimeFilter())!=='') - return "$filter AND $timeFilter"; - else - return $filter; - } - - private function getCategoryFilter() - { - if(($catID=$this->Request['cat'])!==null) - { - $catID=TPropertyValue::ensureInteger($catID); - return "category_id=$catID"; - } - else - return ''; - } - - private function formUrl($newOffset) - { - $gets=array(); - $gets['offset']=$newOffset; - if($this->Request['limit']!==null) - $gets['limit']=$this->Request['limit']; - if($this->Request['time']!==null) - $gets['time']=$this->Request['time']; - if($this->Request['cat']!==null) - $gets['cat']=$this->Request['cat']; - return $this->Service->constructUrl('Posts.ListPost',$gets); - } - - public function getCategory() - { - return $this->_category; - } - - public function onLoad($param) - { - parent::onLoad($param); - $this->PostList->DataSource=$this->_posts; - $this->PostList->dataBind(); - if($this->getPageOffset()>0) - { - if(($offset=$this->getPageOffset()-$this->getPageSize())<0) - $offset=0; - $this->PrevPage->NavigateUrl=$this->formUrl($offset); - $this->PrevPage->Visible=true; - } - if(count($this->_posts)===$this->getPageSize()) - { - $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); - $this->NextPage->Visible=true; - } - } - - public function deleteButtonClicked($sender,$param) - { - if($this->User->IsAdmin) - { - $this->DataAccess->deleteCategory($this->Category->ID); - $this->gotoDefaultPage(); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ListPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ListPost extends BlogPage +{ + private $_posts; + private $_category; + + public function onInit($param) + { + parent::onInit($param); + $this->_posts=$this->DataAccess->queryPosts( + $this->getPostFilter(), + $this->getCategoryFilter(), + 'ORDER BY a.status DESC, create_time DESC', + 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); + if($this->Request['cat']!==null) + { + $catID=TPropertyValue::ensureInteger($this->Request['cat']); + $this->_category=$this->DataAccess->queryCategoryByID($catID); + $this->CategoryPanel->Visible=true; + } + $this->Title=$this->Application->Parameters['SiteTitle']; + } + + private function getPageOffset() + { + if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) + $offset=0; + return $offset; + } + + private function getPageSize() + { + if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) + $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); + return $limit; + } + + private function getTimeFilter() + { + if(($time=TPropertyValue::ensureInteger($this->Request['time']))>0) + { + $year=(integer)($time/100); + $month=$time%100; + $startTime=mktime(0,0,0,$month,1,$year); + if(++$month>12) + { + $month=1; + $year++; + } + $endTime=mktime(0,0,0,$month,1,$year); + return "create_time>=$startTime AND create_time<$endTime"; + } + else + return ''; + } + + private function getPostFilter() + { + $filter='(a.status=0 OR a.status=3)'; + if(($timeFilter=$this->getTimeFilter())!=='') + return "$filter AND $timeFilter"; + else + return $filter; + } + + private function getCategoryFilter() + { + if(($catID=$this->Request['cat'])!==null) + { + $catID=TPropertyValue::ensureInteger($catID); + return "category_id=$catID"; + } + else + return ''; + } + + private function formUrl($newOffset) + { + $gets=array(); + $gets['offset']=$newOffset; + if($this->Request['limit']!==null) + $gets['limit']=$this->Request['limit']; + if($this->Request['time']!==null) + $gets['time']=$this->Request['time']; + if($this->Request['cat']!==null) + $gets['cat']=$this->Request['cat']; + return $this->Service->constructUrl('Posts.ListPost',$gets); + } + + public function getCategory() + { + return $this->_category; + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->PostList->DataSource=$this->_posts; + $this->PostList->dataBind(); + if($this->getPageOffset()>0) + { + if(($offset=$this->getPageOffset()-$this->getPageSize())<0) + $offset=0; + $this->PrevPage->NavigateUrl=$this->formUrl($offset); + $this->PrevPage->Visible=true; + } + if(count($this->_posts)===$this->getPageSize()) + { + $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); + $this->NextPage->Visible=true; + } + } + + public function deleteButtonClicked($sender,$param) + { + if($this->User->IsAdmin) + { + $this->DataAccess->deleteCategory($this->Category->ID); + $this->gotoDefaultPage(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/MyPost.php b/demos/blog/protected/Pages/Posts/MyPost.php index fd65cc57..7d0be020 100644 --- a/demos/blog/protected/Pages/Posts/MyPost.php +++ b/demos/blog/protected/Pages/Posts/MyPost.php @@ -1,51 +1,51 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * MyPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class MyPost extends BlogPage -{ - protected function bindData() - { - $author=$this->User->ID; - $offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; - $limit=$this->PostGrid->PageSize; - $this->PostGrid->DataSource=$this->DataAccess->queryPosts("author_id=$author",'','ORDER BY a.status DESC, create_time DESC',"LIMIT $offset,$limit"); - $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount("author_id=$author",''); - $this->PostGrid->dataBind(); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - $this->bindData(); - } - - public function changePage($sender,$param) - { - $this->PostGrid->CurrentPageIndex=$param->NewPageIndex; - $this->bindData(); - } - - public function pagerCreated($sender,$param) - { - $param->Pager->Controls->insertAt(0,'Page: '); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * MyPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class MyPost extends BlogPage +{ + protected function bindData() + { + $author=$this->User->ID; + $offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; + $limit=$this->PostGrid->PageSize; + $this->PostGrid->DataSource=$this->DataAccess->queryPosts("author_id=$author",'','ORDER BY a.status DESC, create_time DESC',"LIMIT $offset,$limit"); + $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount("author_id=$author",''); + $this->PostGrid->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + $this->bindData(); + } + + public function changePage($sender,$param) + { + $this->PostGrid->CurrentPageIndex=$param->NewPageIndex; + $this->bindData(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/NewCategory.php b/demos/blog/protected/Pages/Posts/NewCategory.php index 5df0c85b..b5bf26e9 100644 --- a/demos/blog/protected/Pages/Posts/NewCategory.php +++ b/demos/blog/protected/Pages/Posts/NewCategory.php @@ -1,41 +1,41 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * NewCategory class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class NewCategory extends BlogPage -{ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $categoryRecord=new CategoryRecord; - $categoryRecord->Name=$this->CategoryName->Text; - $categoryRecord->Description=$this->CategoryDescription->Text; - $this->DataAccess->insertCategory($categoryRecord); - $this->gotoPage('Posts.ListPost',array('cat'=>$categoryRecord->ID)); - } - } - - public function checkCategoryName($sender,$param) - { - $name=$this->CategoryName->Text; - $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewCategory class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewCategory extends BlogPage +{ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $categoryRecord=new CategoryRecord; + $categoryRecord->Name=$this->CategoryName->Text; + $categoryRecord->Description=$this->CategoryDescription->Text; + $this->DataAccess->insertCategory($categoryRecord); + $this->gotoPage('Posts.ListPost',array('cat'=>$categoryRecord->ID)); + } + } + + public function checkCategoryName($sender,$param) + { + $name=$this->CategoryName->Text; + $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/NewPost.php b/demos/blog/protected/Pages/Posts/NewPost.php index 2f894cd5..45b1a794 100644 --- a/demos/blog/protected/Pages/Posts/NewPost.php +++ b/demos/blog/protected/Pages/Posts/NewPost.php @@ -1,57 +1,57 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * NewPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class NewPost extends BlogPage -{ - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Categories->DataSource=$this->DataAccess->queryCategories(); - $this->Categories->dataBind(); - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $postRecord=new PostRecord; - $postRecord->Title=$this->Title->SafeText; - $postRecord->Content=$this->Content->SafeText; - if($this->DraftMode->Checked) - $postRecord->Status=PostRecord::STATUS_DRAFT; - else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) - $postRecord->Status=PostRecord::STATUS_PENDING; - else - $postRecord->Status=PostRecord::STATUS_PUBLISHED; - $postRecord->CreateTime=time(); - $postRecord->ModifyTime=$postRecord->CreateTime; - $postRecord->AuthorID=$this->User->ID; - $cats=array(); - foreach($this->Categories->SelectedValues as $value) - $cats[]=TPropertyValue::ensureInteger($value); - $this->DataAccess->insertPost($postRecord,$cats); - $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewPost extends BlogPage +{ + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Categories->DataSource=$this->DataAccess->queryCategories(); + $this->Categories->dataBind(); + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $postRecord=new PostRecord; + $postRecord->Title=$this->Title->SafeText; + $postRecord->Content=$this->Content->SafeText; + if($this->DraftMode->Checked) + $postRecord->Status=PostRecord::STATUS_DRAFT; + else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) + $postRecord->Status=PostRecord::STATUS_PENDING; + else + $postRecord->Status=PostRecord::STATUS_PUBLISHED; + $postRecord->CreateTime=time(); + $postRecord->ModifyTime=$postRecord->CreateTime; + $postRecord->AuthorID=$this->User->ID; + $cats=array(); + foreach($this->Categories->SelectedValues as $value) + $cats[]=TPropertyValue::ensureInteger($value); + $this->DataAccess->insertPost($postRecord,$cats); + $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/ViewPost.php b/demos/blog/protected/Pages/Posts/ViewPost.php index 662dc659..5831ba93 100644 --- a/demos/blog/protected/Pages/Posts/ViewPost.php +++ b/demos/blog/protected/Pages/Posts/ViewPost.php @@ -1,90 +1,90 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ViewPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ViewPost extends BlogPage -{ - private $_post=null; - - public function onInit($param) - { - parent::onInit($param); - $id=TPropertyValue::ensureInteger($this->Request['id']); - $this->_post=$this->DataAccess->queryPostByID($id); - if($this->_post===null) - throw new BlogException(500,'post_id_invalid',$id); - // if post is not published, only the author and admin can view it - if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID) - throw new BlogException(500,'post_view_disallowed',$id); - $this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8'); - } - - public function getCanEditPost() - { - $user=$this->getUser(); - return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID; - } - - public function getCurrentPost() - { - return $this->_post; - } - - public function onLoad($param) - { - parent::onLoad($param); - $this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY; - $this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID); - $this->CategoryList->dataBind(); - $this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID); - $this->CommentList->dataBind(); - } - - public function submitCommentButtonClicked($sender,$param) - { - if($this->IsValid) - { - $commentRecord=new CommentRecord; - $commentRecord->PostID=$this->CurrentPost->ID; - $commentRecord->AuthorName=$this->CommentAuthor->SafeText; - $commentRecord->AuthorEmail=$this->CommentEmail->Text; - $commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText; - $commentRecord->AuthorIP=$this->Request->UserHostAddress; - $commentRecord->Content=$this->CommentContent->SafeText; - $commentRecord->CreateTime=time(); - $commentRecord->Status=0; - $this->DataAccess->insertComment($commentRecord); - $this->Response->reload(); - } - } - - public function deleteButtonClicked($sender,$param) - { - $this->DataAccess->deletePost($this->CurrentPost->ID); - $this->gotoDefaultPage(); - } - - public function repeaterItemCommand($sender,$param) - { - $id=TPropertyValue::ensureInteger($param->CommandParameter); - $this->DataAccess->deleteComment($id); - $this->Response->reload(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ViewPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ViewPost extends BlogPage +{ + private $_post=null; + + public function onInit($param) + { + parent::onInit($param); + $id=TPropertyValue::ensureInteger($this->Request['id']); + $this->_post=$this->DataAccess->queryPostByID($id); + if($this->_post===null) + throw new BlogException(500,'post_id_invalid',$id); + // if post is not published, only the author and admin can view it + if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID) + throw new BlogException(500,'post_view_disallowed',$id); + $this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8'); + } + + public function getCanEditPost() + { + $user=$this->getUser(); + return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID; + } + + public function getCurrentPost() + { + return $this->_post; + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY; + $this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID); + $this->CategoryList->dataBind(); + $this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID); + $this->CommentList->dataBind(); + } + + public function submitCommentButtonClicked($sender,$param) + { + if($this->IsValid) + { + $commentRecord=new CommentRecord; + $commentRecord->PostID=$this->CurrentPost->ID; + $commentRecord->AuthorName=$this->CommentAuthor->SafeText; + $commentRecord->AuthorEmail=$this->CommentEmail->Text; + $commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText; + $commentRecord->AuthorIP=$this->Request->UserHostAddress; + $commentRecord->Content=$this->CommentContent->SafeText; + $commentRecord->CreateTime=time(); + $commentRecord->Status=0; + $this->DataAccess->insertComment($commentRecord); + $this->Response->reload(); + } + } + + public function deleteButtonClicked($sender,$param) + { + $this->DataAccess->deletePost($this->CurrentPost->ID); + $this->gotoDefaultPage(); + } + + public function repeaterItemCommand($sender,$param) + { + $id=TPropertyValue::ensureInteger($param->CommandParameter); + $this->DataAccess->deleteComment($id); + $this->Response->reload(); + } +} + ?> \ No newline at end of file -- cgit v1.2.3