@@ -24,4 +39,17 @@ posted by
+
+
\ 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 6d56b543..bed18222 100644
--- a/demos/blog/protected/Pages/Posts/ListPost.php
+++ b/demos/blog/protected/Pages/Posts/ListPost.php
@@ -1,13 +1,59 @@
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * ListPost class
+ *
+ * @author Qiang Xue
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ */
class ListPost extends BlogPage
{
- const DEFAULT_LIMIT=10;
+ private $_posts;
+ private $_category;
- public function getPosts()
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $this->_posts=$this->DataAccess->queryPosts(
+ $this->getPostFilter(),
+ $this->getCategoryFilter(),
+ 'ORDER BY 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;
+ }
+ }
+
+ 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()
{
- $timeFilter='';
- $catFilter='';
if(($time=TPropertyValue::ensureInteger($this->Request['time']))>0)
{
$year=(integer)($time/100);
@@ -19,25 +65,76 @@ class ListPost extends BlogPage
$year++;
}
$endTime=mktime(0,0,0,$month,1,$year);
- $timeFilter="create_time>=$startTime AND create_time<$endTime";
+ return "create_time>=$startTime AND create_time<$endTime";
}
+ else
+ return '';
+ }
+
+ private function getPostFilter()
+ {
+ $filter='a.status=0';
+ if(($timeFilter=$this->getTimeFilter())!=='')
+ return "$filter AND $timeFilter";
+ else
+ return $filter;
+ }
+
+ private function getCategoryFilter()
+ {
if(($catID=$this->Request['cat'])!==null)
{
$catID=TPropertyValue::ensureInteger($catID);
- $catFilter="category_id=$catID";
+ return "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");
+ 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->getPosts();
+ $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();
+ }
}
}
diff --git a/demos/blog/protected/Pages/Posts/MyPost.page b/demos/blog/protected/Pages/Posts/MyPost.page
index 95a32ac9..ca153166 100644
--- a/demos/blog/protected/Pages/Posts/MyPost.page
+++ b/demos/blog/protected/Pages/Posts/MyPost.page
@@ -25,7 +25,7 @@
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * 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()
@@ -7,8 +24,8 @@ class MyPost extends BlogPage
$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 ASC, create_time DESC',"LIMIT $offset,$limit");
- $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount("author_id=$author",'','');
+ $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();
}
diff --git a/demos/blog/protected/Pages/Posts/NewCategory.page b/demos/blog/protected/Pages/Posts/NewCategory.page
index 92fe1468..43dba79b 100644
--- a/demos/blog/protected/Pages/Posts/NewCategory.page
+++ b/demos/blog/protected/Pages/Posts/NewCategory.page
@@ -1,3 +1,5 @@
+<%@ Title="Create New Category" %>
+
New Post Category
@@ -14,7 +16,7 @@
Display="Dynamic"
OnServerValidate="checkCategoryName"
Text="...must be unique"
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />
@@ -27,10 +29,11 @@
Columns="50"
Rows="5" />
-
+
\ 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 d36f6af1..215200a9 100644
--- a/demos/blog/protected/Pages/Posts/NewCategory.php
+++ b/demos/blog/protected/Pages/Posts/NewCategory.php
@@ -1,5 +1,22 @@
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * 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)
diff --git a/demos/blog/protected/Pages/Posts/NewPost.page b/demos/blog/protected/Pages/Posts/NewPost.page
index a49188f6..15071e3a 100644
--- a/demos/blog/protected/Pages/Posts/NewPost.page
+++ b/demos/blog/protected/Pages/Posts/NewPost.page
@@ -1,28 +1,31 @@
+<%@ Title="Write New Post" %>
+
-Write a New Post
+Write New Post
-Title
+Title
-
+
-Content
+Content
-
+
-Categories
+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
index 055c7f92..7d02557d 100644
--- a/demos/blog/protected/Pages/Posts/NewPost.php
+++ b/demos/blog/protected/Pages/Posts/NewPost.php
@@ -1,5 +1,22 @@
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * 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)
@@ -17,9 +34,14 @@ class NewPost extends BlogPage
if($this->IsValid)
{
$postRecord=new PostRecord;
- $postRecord->Title=$this->Title->Text;
- $postRecord->Content=$this->Content->Text;
- $postRecord->Status=$this->DraftMode->Checked?0:1;
+ $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->AuthorID=$this->User->ID;
$cats=array();
diff --git a/demos/blog/protected/Pages/Posts/ViewPost.page b/demos/blog/protected/Pages/Posts/ViewPost.page
index 4b233615..5bd80a52 100644
--- a/demos/blog/protected/Pages/Posts/ViewPost.page
+++ b/demos/blog/protected/Pages/Posts/ViewPost.page
@@ -5,6 +5,10 @@
<%= $this->CurrentPost->Title %>
+
CurrentPost->Status===PostRecord::STATUS_DRAFT?'[Draft]':'[Pending approval]'%> />
<%= date('l, F j, Y \a\t h:i:s a',$this->CurrentPost->CreateTime) %>
by
<%= '' . $this->CurrentPost->AuthorName . '' %>
@@ -47,11 +51,11 @@ by
<%# date('F j, Y \a\t h:i:s a',$this->DataItem->CreateTime) %>
by
<%# $this->DataItem->AuthorWebsite==='' ?
- $this->DataItem->AuthorName :
- '' . $this->DataItem->AuthorName . '' %>
+ htmlentities($this->DataItem->AuthorName,ENT_QUOTES,'UTF-8') :
+ '' . htmlentities($this->DataItem->AuthorName,ENT_QUOTES,'UTF-8') . '' %>
@@ -65,7 +69,7 @@ by
ValidationGroup="comment""
Display="Dynamic"
Text="...is required"
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />