summaryrefslogtreecommitdiff
path: root/demos/blog/protected/Pages/SearchPost.php
diff options
context:
space:
mode:
authorxue <>2006-05-30 03:26:33 +0000
committerxue <>2006-05-30 03:26:33 +0000
commit6e0338629774fffe5fbe7136dfce34ce83844a5c (patch)
tree9520eaa7c3c278b5ebf525a0d1e09f0a4cdf7779 /demos/blog/protected/Pages/SearchPost.php
parent7f508e187e4539a16cdbb1dd6a4b1133c53cf24d (diff)
Blog demo is completed.
Diffstat (limited to 'demos/blog/protected/Pages/SearchPost.php')
-rw-r--r--demos/blog/protected/Pages/SearchPost.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/demos/blog/protected/Pages/SearchPost.php b/demos/blog/protected/Pages/SearchPost.php
new file mode 100644
index 000000000..53e8401cc
--- /dev/null
+++ b/demos/blog/protected/Pages/SearchPost.php
@@ -0,0 +1,76 @@
+<?php
+
+class SearchPost extends BlogPage
+{
+ private $_posts;
+
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ $this->_posts=$this->DataAccess->queryPosts(
+ $this->getPostFilter(),
+ '',
+ 'ORDER BY create_time DESC',
+ 'LIMIT '.$this->getPageOffset().','.$this->getPageSize());
+ }
+
+ private function getPostFilter()
+ {
+ $filter='a.status=0';
+ $keywords=explode(' ',$this->Request['keyword']);
+ foreach($keywords as $keyword)
+ {
+ if(($keyword=$this->DataAccess->escapeString(trim($keyword)))!=='')
+ $filter.=" AND content LIKE '%$keyword%'";
+ }
+ return $filter;
+ }
+
+ 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 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 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;
+ }
+ }
+}
+
+?> \ No newline at end of file