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/Admin/AdminMenu.php | 7 ++ demos/blog/protected/Pages/Admin/AdminMenu.tpl | 16 +++ demos/blog/protected/Pages/Admin/ConfigMan.page | 56 ++++++++++ demos/blog/protected/Pages/Admin/ConfigMan.php | 15 +++ demos/blog/protected/Pages/Admin/PostMan.page | 76 ++++++++++++++ demos/blog/protected/Pages/Admin/PostMan.php | 56 ++++++++++ demos/blog/protected/Pages/Admin/Settings.page | 4 + demos/blog/protected/Pages/Admin/UserMan.page | 95 +++++++++++++++++ demos/blog/protected/Pages/Admin/UserMan.php | 58 +++++++++++ demos/blog/protected/Pages/Admin/config.xml | 8 ++ demos/blog/protected/Pages/ErrorReport.page | 15 +++ demos/blog/protected/Pages/ErrorReport.php | 12 +++ 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 ++ demos/blog/protected/Pages/Users/EditUser.page | 74 ++++++++++++++ demos/blog/protected/Pages/Users/EditUser.php | 43 ++++++++ demos/blog/protected/Pages/Users/NewUser.page | 104 +++++++++++++++++++ demos/blog/protected/Pages/Users/NewUser.php | 31 ++++++ demos/blog/protected/Pages/Users/ViewUser.page | 21 ++++ demos/blog/protected/Pages/Users/ViewUser.php | 19 ++++ demos/blog/protected/Pages/Users/config.xml | 7 ++ 34 files changed, 1368 insertions(+) create mode 100644 demos/blog/protected/Pages/Admin/AdminMenu.php create mode 100644 demos/blog/protected/Pages/Admin/AdminMenu.tpl create mode 100644 demos/blog/protected/Pages/Admin/ConfigMan.page create mode 100644 demos/blog/protected/Pages/Admin/ConfigMan.php create mode 100644 demos/blog/protected/Pages/Admin/PostMan.page create mode 100644 demos/blog/protected/Pages/Admin/PostMan.php create mode 100644 demos/blog/protected/Pages/Admin/Settings.page create mode 100644 demos/blog/protected/Pages/Admin/UserMan.page create mode 100644 demos/blog/protected/Pages/Admin/UserMan.php create mode 100644 demos/blog/protected/Pages/Admin/config.xml create mode 100644 demos/blog/protected/Pages/ErrorReport.page create mode 100644 demos/blog/protected/Pages/ErrorReport.php 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 create mode 100644 demos/blog/protected/Pages/Users/EditUser.page create mode 100644 demos/blog/protected/Pages/Users/EditUser.php create mode 100644 demos/blog/protected/Pages/Users/NewUser.page create mode 100644 demos/blog/protected/Pages/Users/NewUser.php create mode 100644 demos/blog/protected/Pages/Users/ViewUser.page create mode 100644 demos/blog/protected/Pages/Users/ViewUser.php create mode 100644 demos/blog/protected/Pages/Users/config.xml (limited to 'demos/blog/protected/Pages') diff --git a/demos/blog/protected/Pages/Admin/AdminMenu.php b/demos/blog/protected/Pages/Admin/AdminMenu.php new file mode 100644 index 00000000..40f40b88 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/AdminMenu.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/AdminMenu.tpl b/demos/blog/protected/Pages/Admin/AdminMenu.tpl new file mode 100644 index 00000000..596f3ed2 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/AdminMenu.tpl @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/ConfigMan.page b/demos/blog/protected/Pages/Admin/ConfigMan.page new file mode 100644 index 00000000..ad728284 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/ConfigMan.page @@ -0,0 +1,56 @@ + + +

Administration Center

+ + + + + +Title +
+ +
+ +Subtitle +
+ +
+ +Owner name +
+ +
+ +Owner email +
+ +
+ +Site theme +
+ +
+ +
+ + + + + +
+ + +
+ +
+ + + + +
+ +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/ConfigMan.php b/demos/blog/protected/Pages/Admin/ConfigMan.php new file mode 100644 index 00000000..dcbe1537 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/ConfigMan.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/PostMan.page b/demos/blog/protected/Pages/Admin/PostMan.page new file mode 100644 index 00000000..8ba8ef29 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/PostMan.page @@ -0,0 +1,76 @@ + + +

Administration Center

+ + + + + + + + + <%# + $this->Parent->DataItem->Status===0 ? + 'Published' : + ($this->Parent->DataItem->Status===1 ? 'Draft' : 'Pending') + %> + + + Parent->DataItem->Status %> > + + + + + + + + + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/PostMan.php b/demos/blog/protected/Pages/Admin/PostMan.php new file mode 100644 index 00000000..a99332eb --- /dev/null +++ b/demos/blog/protected/Pages/Admin/PostMan.php @@ -0,0 +1,56 @@ +PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; + $limit=$this->PostGrid->PageSize; + $this->PostGrid->DataSource=$this->DataAccess->queryPosts('','','','ORDER BY a.status DESC, create_time DESC',"LIMIT $offset,$limit"); + $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount('','',''); + $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: '); + } + + public function editItem($sender,$param) + { + $this->PostGrid->EditItemIndex=$param->Item->ItemIndex; + $this->bindData(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $postID=$this->PostGrid->DataKeys[$item->ItemIndex]; + $postRecord=$this->DataAccess->queryPostByID($postID); + $postRecord->Status=TPropertyValue::ensureInteger($item->Cells[2]->PostStatus->SelectedValue); + $this->DataAccess->updatePost($postRecord); + $this->PostGrid->EditItemIndex=-1; + $this->bindData(); + } + + public function cancelItem($sender,$param) + { + $this->PostGrid->EditItemIndex=-1; + $this->bindData(); + } +} + +?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/Settings.page b/demos/blog/protected/Pages/Admin/Settings.page new file mode 100644 index 00000000..48dfde96 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/Settings.page @@ -0,0 +1,4 @@ + +Welcome, User->Name %> />! +This page contains site settings accessible only to site admin. + \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/UserMan.page b/demos/blog/protected/Pages/Admin/UserMan.page new file mode 100644 index 00000000..a8b634c6 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/UserMan.page @@ -0,0 +1,95 @@ + + +

Administration Center

+ + + + + + + + <%# $this->Parent->DataItem->Role===0 ? 'User' : 'Admin' %> + + + Parent->DataItem->Role %> > + + + + + + + + <%# + $this->Parent->DataItem->Status===0 ? + 'Normal' : + ($this->Parent->DataItem->Status===1 ? 'Disabled' : 'Pending') + %> + + + Parent->DataItem->Status %> > + + + + + + + + # + ''.{0}.'' + + + + + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/UserMan.php b/demos/blog/protected/Pages/Admin/UserMan.php new file mode 100644 index 00000000..1cb62482 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/UserMan.php @@ -0,0 +1,58 @@ +User->ID; + $offset=$this->UserGrid->CurrentPageIndex*$this->UserGrid->PageSize; + $limit=$this->UserGrid->PageSize; + $this->UserGrid->DataSource=$this->DataAccess->queryUsers('','ORDER BY status DESC, name ASC',"LIMIT $offset,$limit"); + $this->UserGrid->VirtualItemCount=$this->DataAccess->queryUserCount(''); + $this->UserGrid->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + $this->bindData(); + } + + public function changePage($sender,$param) + { + $this->UserGrid->CurrentPageIndex=$param->NewPageIndex; + $this->bindData(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } + + public function editItem($sender,$param) + { + $this->UserGrid->EditItemIndex=$param->Item->ItemIndex; + $this->bindData(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $userID=$this->UserGrid->DataKeys[$item->ItemIndex]; + $userRecord=$this->DataAccess->queryUserByID($userID); + $userRecord->Role=TPropertyValue::ensureInteger($item->Cells[1]->UserRole->SelectedValue); + $userRecord->Status=TPropertyValue::ensureInteger($item->Cells[2]->UserStatus->SelectedValue); + $this->DataAccess->updateUser($userRecord); + $this->UserGrid->EditItemIndex=-1; + $this->bindData(); + } + + public function cancelItem($sender,$param) + { + $this->UserGrid->EditItemIndex=-1; + $this->bindData(); + } +} + +?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/config.xml b/demos/blog/protected/Pages/Admin/config.xml new file mode 100644 index 00000000..c99e5892 --- /dev/null +++ b/demos/blog/protected/Pages/Admin/config.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/demos/blog/protected/Pages/ErrorReport.page b/demos/blog/protected/Pages/ErrorReport.page new file mode 100644 index 00000000..a9b461d9 --- /dev/null +++ b/demos/blog/protected/Pages/ErrorReport.page @@ -0,0 +1,15 @@ + + +

Error

+ +

+<%= $this->ErrorMessage %> +

+ +

+Please report to us +if you believe this error is caused by our system. Thanks! +

+ + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/ErrorReport.php b/demos/blog/protected/Pages/ErrorReport.php new file mode 100644 index 00000000..3b24170f --- /dev/null +++ b/demos/blog/protected/Pages/ErrorReport.php @@ -0,0 +1,12 @@ +Request['id']); + return BlogErrors::getMessage($id); + } +} + +?> \ No newline at end of file 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 diff --git a/demos/blog/protected/Pages/Users/EditUser.page b/demos/blog/protected/Pages/Users/EditUser.page new file mode 100644 index 00000000..8c21fd50 --- /dev/null +++ b/demos/blog/protected/Pages/Users/EditUser.page @@ -0,0 +1,74 @@ + + +

Update Profile

+ + + +Username +
+ + +
+ +Full name +
+ + +
+ +Password +
+ + + +
+ +Re-type Password +
+ + + +
+ +Email Address +
+ + + + +
+ +Personal Website +
+ + +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/EditUser.php b/demos/blog/protected/Pages/Users/EditUser.php new file mode 100644 index 00000000..e3efcfd1 --- /dev/null +++ b/demos/blog/protected/Pages/Users/EditUser.php @@ -0,0 +1,43 @@ +DataAccess->queryUserByID($this->User->ID))!==null) + return $user; + else + throw new BlogException('xxx'); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $userRecord=$this->getCurrentUser(); + $this->Username->Text=$userRecord->Name; + $this->FullName->Text=$userRecord->FullName; + $this->Email->Text=$userRecord->Email; + $this->Website->Text=$userRecord->Website; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $userRecord=$this->getCurrentUser(); + if($this->Password->Text!=='') + $userRecord->Password=md5($this->Password->Text); + $userRecord->FullName=$this->FullName->Text; + $userRecord->Email=$this->Email->Text; + $userRecord->Website=$this->Website->Text; + $this->DataAccess->updateUser($userRecord); + $authManager=$this->Application->getModule('auth'); + $this->gotoPage('Users.ViewUser',array('id'=>$userRecord->ID)); + } + } +} + +?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/NewUser.page b/demos/blog/protected/Pages/Users/NewUser.page new file mode 100644 index 00000000..eba2dcec --- /dev/null +++ b/demos/blog/protected/Pages/Users/NewUser.page @@ -0,0 +1,104 @@ + + +

Create New Account

+ + + +Username +
+ + + + + +
+ +Full name +
+ + +
+ +Password +
+ + + + +
+ +Re-type Password +
+ + + +
+ +Email Address +
+ + + + +
+ +Personal Website +
+ + +
+ + + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/NewUser.php b/demos/blog/protected/Pages/Users/NewUser.php new file mode 100644 index 00000000..166abf66 --- /dev/null +++ b/demos/blog/protected/Pages/Users/NewUser.php @@ -0,0 +1,31 @@ +Username->Text; + $param->IsValid=$this->DataAccess->queryUserByName($username)===null; + } + + public function createUser($sender,$param) + { + if($this->IsValid) + { + $userRecord=new UserRecord; + $userRecord->Name=$this->Username->Text; + $userRecord->FullName=$this->FullName->Text; + $userRecord->Role=0; + $userRecord->Password=md5($this->Password->Text); + $userRecord->Email=$this->Email->Text; + $userRecord->CreateTime=time(); + $userRecord->Website=$this->Website->Text; + $this->DataAccess->insertUser($userRecord); + $authManager=$this->Application->getModule('auth'); + $authManager->login($this->Username->Text,$this->Password->Text); + $this->gotoDefaultPage(); + } + } +} + +?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/ViewUser.page b/demos/blog/protected/Pages/Users/ViewUser.page new file mode 100644 index 00000000..2dba6b77 --- /dev/null +++ b/demos/blog/protected/Pages/Users/ViewUser.page @@ -0,0 +1,21 @@ + + +

User Profile

+ +Username: <%= $this->CurrentUser->Name %> +
+ +Full name: <%= $this->CurrentUser->FullName %> +
+ +Email: <%= $this->CurrentUser->Email %> +
+ +Privilege: <%= $this->CurrentUser->Role===0? 'User':'Administrator' %> +
+ +Personal website: <%= $this->CurrentUser->Website %> +
+ + +
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/ViewUser.php b/demos/blog/protected/Pages/Users/ViewUser.php new file mode 100644 index 00000000..3485f56b --- /dev/null +++ b/demos/blog/protected/Pages/Users/ViewUser.php @@ -0,0 +1,19 @@ +_currentUser===null) + { + $id=TPropertyValue::ensureInteger($this->Request['id']); + if(($this->_currentUser=$this->DataAccess->queryUserByID($id))===null) + throw new BlogException('xxx'); + } + return $this->_currentUser; + } +} + +?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/config.xml b/demos/blog/protected/Pages/Users/config.xml new file mode 100644 index 00000000..df8e4ad1 --- /dev/null +++ b/demos/blog/protected/Pages/Users/config.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file -- cgit v1.2.3