From 2ea02214b2fb6bedb58dbbd318ef171a9e146524 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Mon, 29 May 2006 03:08:07 +0000
Subject: Merge from 3.0 branch till 1099.

---
 demos/blog/protected/Portlets/AccountPortlet.php  | 14 +++++++
 demos/blog/protected/Portlets/AccountPortlet.tpl  | 20 ++++++++++
 demos/blog/protected/Portlets/ArchivePortlet.php  | 45 +++++++++++++++++++++++
 demos/blog/protected/Portlets/ArchivePortlet.tpl  | 15 ++++++++
 demos/blog/protected/Portlets/CategoryPortlet.php | 15 ++++++++
 demos/blog/protected/Portlets/CategoryPortlet.tpl | 24 ++++++++++++
 demos/blog/protected/Portlets/LoginPortlet.php    | 22 +++++++++++
 demos/blog/protected/Portlets/LoginPortlet.tpl    | 36 ++++++++++++++++++
 demos/blog/protected/Portlets/Portlet.php         |  7 ++++
 demos/blog/protected/Portlets/SearchPortlet.php   | 22 +++++++++++
 demos/blog/protected/Portlets/SearchPortlet.tpl   | 21 +++++++++++
 11 files changed, 241 insertions(+)
 create mode 100644 demos/blog/protected/Portlets/AccountPortlet.php
 create mode 100644 demos/blog/protected/Portlets/AccountPortlet.tpl
 create mode 100644 demos/blog/protected/Portlets/ArchivePortlet.php
 create mode 100644 demos/blog/protected/Portlets/ArchivePortlet.tpl
 create mode 100644 demos/blog/protected/Portlets/CategoryPortlet.php
 create mode 100644 demos/blog/protected/Portlets/CategoryPortlet.tpl
 create mode 100644 demos/blog/protected/Portlets/LoginPortlet.php
 create mode 100644 demos/blog/protected/Portlets/LoginPortlet.tpl
 create mode 100644 demos/blog/protected/Portlets/Portlet.php
 create mode 100644 demos/blog/protected/Portlets/SearchPortlet.php
 create mode 100644 demos/blog/protected/Portlets/SearchPortlet.tpl

(limited to 'demos/blog/protected/Portlets')

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 -->
-- 
cgit v1.2.3