From 05869f23f798c9393e2bc6d310d56a97a11d1acd Mon Sep 17 00:00:00 2001 From: xue <> Date: Mon, 29 May 2006 02:05:19 +0000 Subject: Added blog demo (not done yet) --- demos/blog/protected/Pages/Posts/EditCategory.page | 36 +++++++ demos/blog/protected/Pages/Posts/EditCategory.php | 44 ++++++++ demos/blog/protected/Pages/Posts/EditPost.page | 41 ++++++++ demos/blog/protected/Pages/Posts/EditPost.php | 51 ++++++++++ demos/blog/protected/Pages/Posts/ListPost.page | 27 +++++ demos/blog/protected/Pages/Posts/ListPost.php | 44 ++++++++ demos/blog/protected/Pages/Posts/MyPost.page | 46 +++++++++ demos/blog/protected/Pages/Posts/MyPost.php | 34 +++++++ demos/blog/protected/Pages/Posts/NewCategory.page | 36 +++++++ demos/blog/protected/Pages/Posts/NewCategory.php | 24 +++++ demos/blog/protected/Pages/Posts/NewPost.page | 41 ++++++++ demos/blog/protected/Pages/Posts/NewPost.php | 34 +++++++ demos/blog/protected/Pages/Posts/ViewPost.page | 113 +++++++++++++++++++++ demos/blog/protected/Pages/Posts/ViewPost.php | 73 +++++++++++++ demos/blog/protected/Pages/Posts/config.xml | 7 ++ 15 files changed, 651 insertions(+) create mode 100644 demos/blog/protected/Pages/Posts/EditCategory.page create mode 100644 demos/blog/protected/Pages/Posts/EditCategory.php create mode 100644 demos/blog/protected/Pages/Posts/EditPost.page create mode 100644 demos/blog/protected/Pages/Posts/EditPost.php create mode 100644 demos/blog/protected/Pages/Posts/ListPost.page create mode 100644 demos/blog/protected/Pages/Posts/ListPost.php create mode 100644 demos/blog/protected/Pages/Posts/MyPost.page create mode 100644 demos/blog/protected/Pages/Posts/MyPost.php create mode 100644 demos/blog/protected/Pages/Posts/NewCategory.page create mode 100644 demos/blog/protected/Pages/Posts/NewCategory.php create mode 100644 demos/blog/protected/Pages/Posts/NewPost.page create mode 100644 demos/blog/protected/Pages/Posts/NewPost.php create mode 100644 demos/blog/protected/Pages/Posts/ViewPost.page create mode 100644 demos/blog/protected/Pages/Posts/ViewPost.php create mode 100644 demos/blog/protected/Pages/Posts/config.xml (limited to 'demos/blog/protected/Pages/Posts') diff --git a/demos/blog/protected/Pages/Posts/EditCategory.page b/demos/blog/protected/Pages/Posts/EditCategory.page new file mode 100644 index 00000000..fdde2648 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/EditCategory.page @@ -0,0 +1,36 @@ + + +

Update Post Category

+ +Category name + + +
+ +
+ +Description +
+ +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/EditCategory.php b/demos/blog/protected/Pages/Posts/EditCategory.php new file mode 100644 index 00000000..fd2d0707 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/EditCategory.php @@ -0,0 +1,44 @@ +Request['id']); + if(($cat=$this->DataAccess->queryCategoryByID($id))!==null) + return $cat; + else + throw new BlogException('xxx'); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $catRecord=$this->getCurrentCategory(); + $this->CategoryName->Text=$catRecord->Name; + $this->CategoryDescription->Text=$catRecord->Description; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $categoryRecord=$this->getCurrentCategory(); + $categoryRecord->Name=$this->CategoryName->Text; + $categoryRecord->Description=$this->CategoryDescription->Text; + $this->DataAccess->updateCategory($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/EditPost.page b/demos/blog/protected/Pages/Posts/EditPost.page new file mode 100644 index 00000000..591f5945 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/EditPost.page @@ -0,0 +1,41 @@ + + +

Update Post

+ +Title + +
+ +
+ +Content + +
+ +
+ +Categories
+ +
+ + +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/EditPost.php b/demos/blog/protected/Pages/Posts/EditPost.php new file mode 100644 index 00000000..57e92b1c --- /dev/null +++ b/demos/blog/protected/Pages/Posts/EditPost.php @@ -0,0 +1,51 @@ +Request['id']); + if(($post=$this->DataAccess->queryPostByID($id))!==null) + return $post; + else + throw new BlogException('xxx'); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $postRecord=$this->getCurrentPost(); + $this->Title->Text=$postRecord->Title; + $this->Content->Text=$postRecord->Content; + $this->DraftMode->Checked=$postRecord->Status===0; + $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->getCurrentPost(); + $postRecord->Title=$this->Title->Text; + $postRecord->Content=$this->Content->Text; + $postRecord->Status=$this->DraftMode->Checked?0:1; + $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.page b/demos/blog/protected/Pages/Posts/ListPost.page new file mode 100644 index 00000000..15fc3d0c --- /dev/null +++ b/demos/blog/protected/Pages/Posts/ListPost.page @@ -0,0 +1,27 @@ + + + + +
+
+<%# $this->DataItem->Title %> +
+
+<%# date('l, F j, Y \a\t h:i:s a',$this->DataItem->CreateTime) %> +
+
+<%# $this->DataItem->Content %> +
+ +
+
+
+ +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/ListPost.php b/demos/blog/protected/Pages/Posts/ListPost.php new file mode 100644 index 00000000..6d56b543 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/ListPost.php @@ -0,0 +1,44 @@ +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); + $timeFilter="create_time>=$startTime AND create_time<$endTime"; + } + if(($catID=$this->Request['cat'])!==null) + { + $catID=TPropertyValue::ensureInteger($catID); + $catFilter="category_id=$catID"; + } + if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) + $offset=0; + if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) + $limit=self::DEFAULT_LIMIT; + return $this->DataAccess->queryPosts('',$timeFilter,$catFilter,'ORDER BY create_time DESC',"LIMIT $offset,$limit"); + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->PostList->DataSource=$this->getPosts(); + $this->PostList->dataBind(); + } +} + +?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/MyPost.page b/demos/blog/protected/Pages/Posts/MyPost.page new file mode 100644 index 00000000..95a32ac9 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/MyPost.page @@ -0,0 +1,46 @@ + + +

My Posts

+ + + + + + + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/MyPost.php b/demos/blog/protected/Pages/Posts/MyPost.php new file mode 100644 index 00000000..be03ca63 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/MyPost.php @@ -0,0 +1,34 @@ +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 ASC, 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.page b/demos/blog/protected/Pages/Posts/NewCategory.page new file mode 100644 index 00000000..92fe1468 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/NewCategory.page @@ -0,0 +1,36 @@ + + +

New Post Category

+ +Category name + + +
+ +
+ +Description +
+ +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/NewCategory.php b/demos/blog/protected/Pages/Posts/NewCategory.php new file mode 100644 index 00000000..d36f6af1 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/NewCategory.php @@ -0,0 +1,24 @@ +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.page b/demos/blog/protected/Pages/Posts/NewPost.page new file mode 100644 index 00000000..a49188f6 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/NewPost.page @@ -0,0 +1,41 @@ + + +

Write a New Post

+ +Title + +
+ +
+ +Content + +
+ +
+ +Categories
+ +
+ + +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/NewPost.php b/demos/blog/protected/Pages/Posts/NewPost.php new file mode 100644 index 00000000..055c7f92 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/NewPost.php @@ -0,0 +1,34 @@ +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->Text; + $postRecord->Content=$this->Content->Text; + $postRecord->Status=$this->DraftMode->Checked?0:1; + $postRecord->CreateTime=time(); + $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.page b/demos/blog/protected/Pages/Posts/ViewPost.page new file mode 100644 index 00000000..4b233615 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/ViewPost.page @@ -0,0 +1,113 @@ + + +
+
+<%= $this->CurrentPost->Title %> +
+
+<%= date('l, F j, Y \a\t h:i:s a',$this->CurrentPost->CreateTime) %> +by +<%= '' . $this->CurrentPost->AuthorName . '' %> +<%= $this->CanEditPost ? '| Edit | ' : ''; +%> +CanEditPost %> + Attributes.onclick="if(!confirm('Are you sure to delete this post? This will also delete all related comments.')) return false;" + /> +
+
+<%= $this->CurrentPost->Content %> +
+ +
+ +
+ +

Comments

+ + + +
+
+DataItem->ID %> + Visible=<%= $this->Page->CanEditPost %> Style="float:right"/> +<%# date('F j, Y \a\t h:i:s a',$this->DataItem->CreateTime) %> +by +<%# $this->DataItem->AuthorWebsite==='' ? + $this->DataItem->AuthorName : + '' . $this->DataItem->AuthorName . '' %> +
+
+<%# $this->DataItem->Content %> +
+
+
+
+ +

Leave your comment

+ +Name + +
+ +
+ +Email address + + +
+ +
+ +Personal website +
+ +
+ +Comment + +
+ +
+ + + +
+
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/ViewPost.php b/demos/blog/protected/Pages/Posts/ViewPost.php new file mode 100644 index 00000000..309bedc1 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/ViewPost.php @@ -0,0 +1,73 @@ +_postID===null) + $this->_postID=TPropertyValue::ensureInteger($this->Request['id']); + return $this->_postID; + } + + public function getCurrentPost() + { + if($this->_post===null) + { + if(($this->_post=$this->DataAccess->queryPostByID($this->getPostID()))===null) + $this->reportError(BlogErrors::ERROR_POST_NOT_FOUND); + } + return $this->_post; + } + + public function getCanEditPost() + { + $user=$this->getUser(); + $authorID=$this->getCurrentPost()->AuthorID; + return $authorID===$user->getID() || $user->isInRole('admin'); + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->getPostID()); + $this->CategoryList->dataBind(); + $this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->getPostID()); + $this->CommentList->dataBind(); + } + + public function submitCommentButtonClicked($sender,$param) + { + if($this->IsValid) + { + $commentRecord=new CommentRecord; + $commentRecord->PostID=$this->CurrentPost->ID; + $commentRecord->AuthorName=$this->CommentAuthor->Text; + $commentRecord->AuthorEmail=$this->CommentEmail->Text; + $commentRecord->AuthorWebsite=$this->CommentWebsite->Text; + $commentRecord->AuthorIP=$this->Request->UserHostAddress; + $commentRecord->Content=$this->CommentContent->Text; + $commentRecord->CreateTime=time(); + $commentRecord->Status=0; + $this->DataAccess->insertComment($commentRecord); + $this->Response->reload(); + } + } + + public function deleteButtonClicked($sender,$param) + { + $this->DataAccess->deletePost($this->PostID); + $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 diff --git a/demos/blog/protected/Pages/Posts/config.xml b/demos/blog/protected/Pages/Posts/config.xml new file mode 100644 index 00000000..1c04e946 --- /dev/null +++ b/demos/blog/protected/Pages/Posts/config.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file -- cgit v1.2.3