summaryrefslogtreecommitdiff
path: root/demos/blog/protected/Portlets
diff options
context:
space:
mode:
authorxue <>2006-05-29 02:05:19 +0000
committerxue <>2006-05-29 02:05:19 +0000
commit05869f23f798c9393e2bc6d310d56a97a11d1acd (patch)
tree046919992ee79e2a7c700ff47999724db1f7b3b7 /demos/blog/protected/Portlets
parent17a098b1d984af47403678b55a3445a0aad3f89f (diff)
Added blog demo (not done yet)
Diffstat (limited to 'demos/blog/protected/Portlets')
-rw-r--r--demos/blog/protected/Portlets/AccountPortlet.php14
-rw-r--r--demos/blog/protected/Portlets/AccountPortlet.tpl20
-rw-r--r--demos/blog/protected/Portlets/ArchivePortlet.php45
-rw-r--r--demos/blog/protected/Portlets/ArchivePortlet.tpl15
-rw-r--r--demos/blog/protected/Portlets/CategoryPortlet.php15
-rw-r--r--demos/blog/protected/Portlets/CategoryPortlet.tpl24
-rw-r--r--demos/blog/protected/Portlets/LoginPortlet.php22
-rw-r--r--demos/blog/protected/Portlets/LoginPortlet.tpl36
-rw-r--r--demos/blog/protected/Portlets/Portlet.php7
-rw-r--r--demos/blog/protected/Portlets/SearchPortlet.php22
-rw-r--r--demos/blog/protected/Portlets/SearchPortlet.tpl21
11 files changed, 241 insertions, 0 deletions
diff --git a/demos/blog/protected/Portlets/AccountPortlet.php b/demos/blog/protected/Portlets/AccountPortlet.php
new file mode 100644
index 00000000..0f0e60c6
--- /dev/null
+++ b/demos/blog/protected/Portlets/AccountPortlet.php
@@ -0,0 +1,14 @@
+<?php
+
+Prado::using('Application.Portlets.Portlet');
+
+class AccountPortlet extends Portlet
+{
+ public function logout($sender,$param)
+ {
+ $this->Application->getModule('auth')->logout();
+ $this->Response->reload();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/blog/protected/Portlets/AccountPortlet.tpl b/demos/blog/protected/Portlets/AccountPortlet.tpl
new file mode 100644
index 00000000..2a401f41
--- /dev/null
+++ b/demos/blog/protected/Portlets/AccountPortlet.tpl
@@ -0,0 +1,20 @@
+<div class="portlet">
+
+<h2 class="portlet-title">Account</h2>
+
+<div class="portlet-content">
+Welcome, <b><%= $this->User->Name %></b>!
+<ul>
+<li><a href="<%= $this->Service->constructUrl('Posts.NewPost') %>">New post</a></li>
+<li><a href="<%= $this->Service->constructUrl('Posts.MyPost') %>">My post</a></li>
+<li><a href="<%= $this->Service->constructUrl('Users.ViewUser',array('id'=>$this->User->ID)) %>">Profile</a></li>
+<%%
+if($this->User->isInRole('admin'))
+ echo '<li><a href="'.$this->Service->constructUrl('Admin.PostMan').'">Admin</a></li>';
+%>
+<li><com:TLinkButton Text="Logout" OnClick="logout" /></li>
+</ul>
+
+</div><!-- end of portlet-content -->
+
+</div><!-- end of portlet -->
diff --git a/demos/blog/protected/Portlets/ArchivePortlet.php b/demos/blog/protected/Portlets/ArchivePortlet.php
new file mode 100644
index 00000000..a004c7a9
--- /dev/null
+++ b/demos/blog/protected/Portlets/ArchivePortlet.php
@@ -0,0 +1,45 @@
+<?php
+
+Prado::using('Application.Portlets.Portlet');
+
+class ArchivePortlet extends Portlet
+{
+ private function makeMonthTime($timestamp)
+ {
+ $date=getdate($timestamp);
+ return mktime(0,0,0,$date['mon'],1,$date['year']);
+ }
+
+ public function onLoad($param)
+ {
+ $currentTime=time();
+ $startTime=$this->Application->getModule('data')->queryEarliestPostTime();
+ if(empty($startTime)) // if no posts
+ $startTime=$currentTime;
+
+ // obtain the timestamp for the initial month
+ $date=getdate($startTime);
+ $startTime=mktime(0,0,0,$date['mon'],1,$date['year']);
+
+ $date=getdate($currentTime);
+ $month=$date['mon'];
+ $year=$date['year'];
+
+ $timestamps=array();
+ while(true)
+ {
+ if(($timestamp=mktime(0,0,0,$month,1,$year))<$startTime)
+ break;
+ $timestamps[]=$timestamp;
+ if(--$month===0)
+ {
+ $month=12;
+ $year--;
+ }
+ }
+ $this->MonthList->DataSource=$timestamps;
+ $this->MonthList->dataBind();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/blog/protected/Portlets/ArchivePortlet.tpl b/demos/blog/protected/Portlets/ArchivePortlet.tpl
new file mode 100644
index 00000000..c576e9f5
--- /dev/null
+++ b/demos/blog/protected/Portlets/ArchivePortlet.tpl
@@ -0,0 +1,15 @@
+<div class="portlet">
+
+<h2 class="portlet-title">Archives</h2>
+
+<div class="portlet-content">
+<ul>
+<com:TRepeater ID="MonthList" EnableViewState="false">
+ <prop:ItemTemplate>
+ <li><a href="<%# $this->Service->constructUrl('Posts.ListPost',array('time'=>date('Ym',$this->DataItem))) %>"><%# date('F Y',$this->DataItem) %></a></li>
+ </prop:ItemTemplate>
+</com:TRepeater>
+</ul>
+</div><!-- end of portlet-content -->
+
+</div><!-- end of portlet -->
diff --git a/demos/blog/protected/Portlets/CategoryPortlet.php b/demos/blog/protected/Portlets/CategoryPortlet.php
new file mode 100644
index 00000000..9c2033aa
--- /dev/null
+++ b/demos/blog/protected/Portlets/CategoryPortlet.php
@@ -0,0 +1,15 @@
+<?php
+
+Prado::using('Application.Portlets.Portlet');
+
+class CategoryPortlet extends Portlet
+{
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ $this->CategoryList->DataSource=$this->Application->getModule('data')->queryCategories();
+ $this->CategoryList->dataBind();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/blog/protected/Portlets/CategoryPortlet.tpl b/demos/blog/protected/Portlets/CategoryPortlet.tpl
new file mode 100644
index 00000000..acbd3bec
--- /dev/null
+++ b/demos/blog/protected/Portlets/CategoryPortlet.tpl
@@ -0,0 +1,24 @@
+<div class="portlet">
+
+<h2 class="portlet-title">
+Categories
+<com:THyperLink
+ Text="[+]"
+ Tooltip="Create a new category"
+ NavigateUrl=<%= $this->Service->constructUrl('Posts.NewCategory') %>
+ Visible=<%= $this->User->isInRole('admin') %> />
+</h2>
+
+<div class="portlet-content">
+<ul>
+<com:TRepeater ID="CategoryList" EnableViewState="false">
+ <prop:ItemTemplate>
+ <li>
+ <a href="<%# $this->Service->constructUrl('Posts.ListPost',array('cat'=>$this->DataItem->ID)) %>"><%# $this->DataItem->Name . ' (' . $this->DataItem->PostCount . ')' %></a>
+ </li>
+ </prop:ItemTemplate>
+</com:TRepeater>
+</ul>
+</div><!-- end of portlet-content -->
+
+</div><!-- end of portlet -->
diff --git a/demos/blog/protected/Portlets/LoginPortlet.php b/demos/blog/protected/Portlets/LoginPortlet.php
new file mode 100644
index 00000000..0085c17f
--- /dev/null
+++ b/demos/blog/protected/Portlets/LoginPortlet.php
@@ -0,0 +1,22 @@
+<?php
+
+Prado::using('Application.Portlets.Portlet');
+
+class LoginPortlet extends Portlet
+{
+ public function validateUser($sender,$param)
+ {
+ $authManager=$this->Application->getModule('auth');
+ if(!$authManager->login($this->Username->Text,$this->Password->Text))
+ $param->IsValid=false;
+ }
+
+ public function loginButtonClicked($sender,$param)
+ {
+ if($this->Page->IsValid)
+ $this->Response->reload();
+ //$this->Response->redirect($this->Application->getModule('auth')->getReturnUrl());
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/blog/protected/Portlets/LoginPortlet.tpl b/demos/blog/protected/Portlets/LoginPortlet.tpl
new file mode 100644
index 00000000..6f8c5d4a
--- /dev/null
+++ b/demos/blog/protected/Portlets/LoginPortlet.tpl
@@ -0,0 +1,36 @@
+<div class="portlet">
+
+<h2 class="portlet-title">Login</h2>
+
+<com:TPanel CssClass="portlet-content" DefaultButton="LoginButton">
+Username
+<com:TRequiredFieldValidator
+ ControlToValidate="Username"
+ ValidationGroup="login"
+ Text="...is required"
+ Display="Dynamic"/>
+<br/>
+<com:TTextBox ID="Username" />
+<br/>
+
+Password
+<com:TCustomValidator
+ ControlToValidate="Password"
+ ValidationGroup="login"
+ Text="...is invalid"
+ Display="Dynamic"
+ OnServerValidate="validateUser" />
+<br/>
+<com:TTextBox ID="Password" TextMode="Password" />
+
+<br/>
+<com:TLinkButton
+ ID="LoginButton"
+ Text="Login"
+ ValidationGroup="login"
+ OnClick="loginButtonClicked" />
+| <a href="<%= $this->Service->constructUrl('Users.NewUser') %>">Register</a>
+
+</com:TPanel><!-- end of portlet-content -->
+
+</div><!-- end of portlet -->
diff --git a/demos/blog/protected/Portlets/Portlet.php b/demos/blog/protected/Portlets/Portlet.php
new file mode 100644
index 00000000..4b1c80e9
--- /dev/null
+++ b/demos/blog/protected/Portlets/Portlet.php
@@ -0,0 +1,7 @@
+<?php
+
+class Portlet extends TTemplateControl
+{
+}
+
+?> \ No newline at end of file
diff --git a/demos/blog/protected/Portlets/SearchPortlet.php b/demos/blog/protected/Portlets/SearchPortlet.php
new file mode 100644
index 00000000..1bad7f1c
--- /dev/null
+++ b/demos/blog/protected/Portlets/SearchPortlet.php
@@ -0,0 +1,22 @@
+<?php
+
+Prado::using('Application.Portlets.Portlet');
+
+class SearchPortlet extends Portlet
+{
+ public function onInit($param)
+ {
+ parent::onInit($param);
+ if(!$this->Page->IsPostBack && ($keyword=$this->Request['keyword'])!==null)
+ $this->Keyword->Text=$keyword;
+ }
+
+ public function search($sender,$param)
+ {
+ $keyword=$this->Keyword->Text;
+ $url=$this->Service->constructUrl('SearchPost',array('keyword'=>$keyword));
+ $this->Response->redirect($url);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/blog/protected/Portlets/SearchPortlet.tpl b/demos/blog/protected/Portlets/SearchPortlet.tpl
new file mode 100644
index 00000000..f88fca7e
--- /dev/null
+++ b/demos/blog/protected/Portlets/SearchPortlet.tpl
@@ -0,0 +1,21 @@
+<div class="portlet">
+
+<h2 class="portlet-title">Search</h2>
+
+<com:TPanel CssClass="portlet-content" DefaultButton="SearchButton">
+Keyword
+<com:TRequiredFieldValidator
+ ControlToValidate="Keyword"
+ ValidationGroup="search"
+ Text="...is required"
+ Display="Dynamic"/>
+<br/>
+<com:TTextBox ID="Keyword" />
+<com:TLinkButton
+ ID="SearchButton"
+ Text="Search"
+ ValidationGroup="search"
+ OnClick="search" />
+</com:TPanel><!-- end of portlet-content -->
+
+</div><!-- end of portlet -->