diff options
Diffstat (limited to 'demos/blog/protected')
31 files changed, 2417 insertions, 2417 deletions
diff --git a/demos/blog/protected/Common/BlogDataModule.php b/demos/blog/protected/Common/BlogDataModule.php index 26dfc5cf..a071ba9a 100644 --- a/demos/blog/protected/Common/BlogDataModule.php +++ b/demos/blog/protected/Common/BlogDataModule.php @@ -1,708 +1,708 @@ -<?php
 -/**
 - * BlogDataModule class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * BlogDataModule class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class BlogDataModule extends TModule
 -{
 -	const DB_FILE_EXT='.db';
 -	const DEFAULT_DB_FILE='Application.Data.Blog';
 -	private $_db=null;
 -	private $_dbFile=null;
 -
 -	public function init($config)
 -	{
 -		$this->connectDatabase();
 -	}
 -
 -	public function getDbFile()
 -	{
 -		if($this->_dbFile===null)
 -			$this->_dbFile=Prado::getPathOfNamespace(self::DEFAULT_DB_FILE,self::DB_FILE_EXT);
 -		return $this->_dbFile;
 -	}
 -
 -	public function setDbFile($value)
 -	{
 -		if(($this->_dbFile=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null)
 -			throw new BlogException(500,'blogdatamodule_dbfile_invalid',$value);
 -	}
 -
 -	protected function createDatabase()
 -	{
 -		$schemaFile=dirname(__FILE__).'/schema.sql';
 -		$statements=explode(';',file_get_contents($schemaFile));
 -		foreach($statements as $statement)
 -		{
 -			if(trim($statement)!=='')
 -			{
 -				try {
 -					$command=$this->_db->createCommand($statement);
 -					$command->execute();
 -				}
 -				catch(TDbException $e)
 -				{
 -					throw new BlogException(500,'blogdatamodule_createdatabase_failed',$e->getErrorMessage(),$statement);
 -				}
 -			}
 -		}
 -	}
 -
 -	protected function connectDatabase()
 -	{
 -		$dbFile=$this->getDbFile();
 -		$newDb=!is_file($dbFile);
 -
 -		try {
 -			$this->_db=new TDbConnection("sqlite:".$dbFile);
 -			$this->_db->Active=true;
 -		}
 -		catch(TDbException $e)
 -		{
 -			throw new BlogException(500,'blogdatamodule_dbconnect_failed',$e->getErrorMessage());
 -		}
 -
 -		if($newDb)
 -			$this->createDatabase();
 -	}
 -
 -	protected function generateModifier($filter,$orderBy,$limit)
 -	{
 -		$modifier='';
 -		if($filter!=='')
 -			$modifier=' WHERE '.$filter;
 -		if($orderBy!=='')
 -			$modifier.=' ORDER BY '.$orderBy;
 -		if($limit!=='')
 -			$modifier.=' LIMIT '.$limit;
 -		return $modifier;
 -	}
 -
 -	public function query($sql)
 -	{
 -		try {
 -			$command=$this->_db->createCommand($sql);
 -			return $command->query();
 -		}
 -		catch(TDbException $e)
 -		{
 -			throw new BlogException(500,'blogdatamodule_query_failed',$e->getErrorMessage(),$sql);
 -		}
 -	}
 -
 -	protected function populateUserRecord($row)
 -	{
 -		$userRecord=new UserRecord;
 -		$userRecord->ID=(integer)$row['id'];
 -		$userRecord->Name=$row['name'];
 -		$userRecord->FullName=$row['full_name'];
 -		$userRecord->Role=(integer)$row['role'];
 -		$userRecord->Password=$row['passwd'];
 -		$userRecord->VerifyCode=$row['vcode'];
 -		$userRecord->Email=$row['email'];
 -		$userRecord->CreateTime=(integer)$row['reg_time'];
 -		$userRecord->Status=(integer)$row['status'];
 -		$userRecord->Website=$row['website'];
 -		return $userRecord;
 -	}
 -
 -	public function queryUsers($filter='',$orderBy='',$limit='')
 -	{
 -		if($filter!=='')
 -			$filter='WHERE '.$filter;
 -		$sql="SELECT * FROM tblUsers $filter $orderBy $limit";
 -		$rows=$this->query($sql);
 -		$users=array();
 -		foreach($rows as $row)
 -			$users[]=$this->populateUserRecord($row);
 -		return $users;
 -	}
 -
 -	public function queryUserCount($filter)
 -	{
 -		if($filter!=='')
 -			$filter='WHERE '.$filter;
 -		$sql="SELECT COUNT(id) AS user_count FROM tblUsers $filter";
 -		$result=$this->query($sql);
 -		if(($row=$result->read())!==false)
 -			return $row['user_count'];
 -		else
 -			return 0;
 -	}
 -
 -	public function queryUserByID($id)
 -	{
 -		$sql="SELECT * FROM tblUsers WHERE id=$id";
 -		$result=$this->query($sql);
 -		if(($row=$result->read())!==false)
 -			return $this->populateUserRecord($row);
 -		else
 -			return null;
 -	}
 -
 -	public function queryUserByName($name)
 -	{
 -		$command=$this->_db->createCommand("SELECT * FROM tblUsers WHERE name=?");
 -		$command->bindValue(1, $name);
 -
 -		$result=$command->query();
 -
 -		if(($row=$result->read())!==false)
 -			return $this->populateUserRecord($row);
 -		else
 -			return null;
 -	}
 -
 -	public function insertUser($user)
 -	{
 -		$command=$this->_db->createCommand("INSERT INTO tblUsers ".
 -				"(name,full_name,role,passwd,email,reg_time,status,website) ".
 -				"VALUES (?,?,?,?,?,?,?,?)");
 -		$command->bindValue(1, $user->Name);
 -		$command->bindValue(2, $user->FullName);
 -		$command->bindValue(3, $user->Role);
 -		$command->bindValue(4, $user->Password);
 -		$command->bindValue(5, $user->Email);
 -		$command->bindValue(6, time());
 -		$command->bindValue(7, $user->Status);
 -		$command->bindValue(8, $user->Website);
 -		$command->execute();
 -
 -		$user->ID=$this->_db->getLastInsertID();
 -	}
 -
 -	public function updateUser($user)
 -	{
 -		$command=$this->_db->createCommand("UPDATE tblUsers SET
 -				name=?,
 -				full_name=?,
 -				role=?,
 -				passwd=?,
 -				vcode=?,
 -				email=?,
 -				status=?,
 -				website=?
 -				WHERE id=?");
 -		$command->bindValue(1, $user->Name);
 -		$command->bindValue(2, $user->FullName);
 -		$command->bindValue(3, $user->Role);
 -		$command->bindValue(4, $user->Password);
 -		$command->bindValue(5, $user->VerifyCode);
 -		$command->bindValue(6, $user->Email);
 -		$command->bindValue(7, $user->Status);
 -		$command->bindValue(8, $user->Website);
 -		$command->bindValue(9, $user->ID);
 -		$command->execute();
 -	}
 -
 -	public function deleteUser($id)
 -	{
 -		$command=$this->_db->createCommand("DELETE FROM tblUsers WHERE id=?");
 -		$command->bindValue(1, $id);
 -		$command->execute();
 -	}
 -
 -	protected function populatePostRecord($row)
 -	{
 -		$postRecord=new PostRecord;
 -		$postRecord->ID=(integer)$row['id'];
 -		$postRecord->AuthorID=(integer)$row['author_id'];
 -		if($row['author_full_name']!=='')
 -			$postRecord->AuthorName=$row['author_full_name'];
 -		else
 -			$postRecord->AuthorName=$row['author_name'];
 -		$postRecord->CreateTime=(integer)$row['create_time'];
 -		$postRecord->ModifyTime=(integer)$row['modify_time'];
 -		$postRecord->Title=$row['title'];
 -		$postRecord->Content=$row['content'];
 -		$postRecord->Status=(integer)$row['status'];
 -		$postRecord->CommentCount=(integer)$row['comment_count'];
 -		return $postRecord;
 -	}
 -
 -	public function queryPosts($postFilter,$categoryFilter,$orderBy,$limit)
 -	{
 -		//FIXME this is insecure by design since it misses proper escaping 
 -		$filter='';
 -		if($postFilter!=='')
 -			$filter.=" AND $postFilter";
 -		if($categoryFilter!=='')
 -			$filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)";
 -		$sql="SELECT a.id AS id,
 -					a.author_id AS author_id,
 -					b.name AS author_name,
 -					b.full_name AS author_full_name,
 -					a.create_time AS create_time,
 -					a.modify_time AS modify_time,
 -					a.title AS title,
 -					a.content AS content,
 -					a.status AS status,
 -					a.comment_count AS comment_count
 -				FROM tblPosts a, tblUsers b
 -				WHERE a.author_id=b.id $filter $orderBy $limit";
 -		$rows=$this->query($sql);
 -		$posts=array();
 -		foreach($rows as $row)
 -			$posts[]=$this->populatePostRecord($row);
 -		return $posts;
 -	}
 -
 -	public function queryPostsSearch($keywords,$orderBy,$limit)
 -	{
 -		$sql="SELECT a.id AS id,
 -					a.author_id AS author_id,
 -					b.name AS author_name,
 -					b.full_name AS author_full_name,
 -					a.create_time AS create_time,
 -					a.modify_time AS modify_time,
 -					a.title AS title,
 -					a.content AS content,
 -					a.status AS status,
 -					a.comment_count AS comment_count
 -				FROM tblPosts a, tblUsers b
 -				WHERE a.author_id=b.id AND a.status=0";
 -
 -		foreach($keywords as $keyword)
 -			$sql.=" AND (content LIKE ? OR title LIKE ?)";
 -
 -		$sql.=" $orderBy $limit";
 -
 -		$command=$this->_db->createCommand($sql);
 -
 -		$i=1;
 -		foreach($keywords as $keyword)
 -		{
 -			$command->bindValue($i, "%".$keyword."%");
 -			$i++;
 -		}
 -
 -		$rows=$command->query();
 -
 -		$posts=array();
 -		foreach($rows as $row)
 -			$posts[]=$this->populatePostRecord($row);
 -		return $posts;
 -
 -	}
 -
 -	public function queryPostCount($postFilter,$categoryFilter)
 -	{
 -		//FIXME this is insecure by design since it misses proper escaping 
 -		$filter='';
 -		if($postFilter!=='')
 -			$filter.=" AND $postFilter";
 -		if($categoryFilter!=='')
 -			$filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)";
 -		$sql="SELECT COUNT(a.id) AS post_count
 -				FROM tblPosts a, tblUsers b
 -				WHERE a.author_id=b.id $filter";
 -		$result=$this->query($sql);
 -		if(($row=$result->read())!==false)
 -			return $row['post_count'];
 -		else
 -			return 0;
 -	}
 -
 -	public function queryPostByID($id)
 -	{
 -		$sql="SELECT a.id AS id,
 -		             a.author_id AS author_id,
 -		             b.name AS author_name,
 -		             b.full_name AS author_full_name,
 -		             a.create_time AS create_time,
 -		             a.modify_time AS modify_time,
 -		             a.title AS title,
 -		             a.content AS content,
 -		             a.status AS status,
 -		             a.comment_count AS comment_count
 -		      FROM tblPosts a, tblUsers b
 -		      WHERE a.id=? AND a.author_id=b.id";
 -
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $id);
 -
 -		$result=$command->query();
 -
 -		if(($row=$result->read())!==false)
 -			return $this->populatePostRecord($row);
 -		else
 -			return null;
 -	}
 -
 -	public function insertPost($post,$catIDs)
 -	{
 -		$command=$this->_db->createCommand("INSERT INTO tblPosts
 -				(author_id,create_time,modify_time,title,content,status)
 -				VALUES (?,?,?,?,?,?)");
 -		$command->bindValue(1, $post->AuthorID);
 -		$command->bindValue(2, $post->CreateTime);
 -		$command->bindValue(3, $post->ModifyTime);
 -		$command->bindValue(4, $post->Title);
 -		$command->bindValue(5, $post->Content);
 -		$command->bindValue(6, $post->Status);
 -
 -		$command->execute();
 -		$post->ID=$this->_db->getLastInsertID();
 -		foreach($catIDs as $catID)
 -			$this->insertPostCategory($post->ID,$catID);
 -	}
 -
 -	public function updatePost($post,$newCatIDs=null)
 -	{
 -		if($newCatIDs!==null)
 -		{
 -			$cats=$this->queryCategoriesByPostID($post->ID);
 -			$catIDs=array();
 -			foreach($cats as $cat)
 -				$catIDs[]=$cat->ID;
 -			$deleteIDs=array_diff($catIDs,$newCatIDs);
 -			foreach($deleteIDs as $id)
 -				$this->deletePostCategory($post->ID,$id);
 -			$insertIDs=array_diff($newCatIDs,$catIDs);
 -			foreach($insertIDs as $id)
 -				$this->insertPostCategory($post->ID,$id);
 -		}
 -
 -		$command=$this->_db->createCommand("UPDATE tblPosts SET
 -				modify_time=?,
 -				title=?,
 -				content=?,
 -				status=?
 -				WHERE id=?");
 -		$command->bindValue(1, $post->ModifyTime);
 -		$command->bindValue(2, $post->Title);
 -		$command->bindValue(3, $post->Content);
 -		$command->bindValue(4, $post->Status);
 -		$command->bindValue(5, $post->ID);
 -
 -		$command->execute();
 -	}
 -
 -	public function deletePost($id)
 -	{
 -		$cats=$this->queryCategoriesByPostID($id);
 -		foreach($cats as $cat)
 -			$this->deletePostCategory($id,$cat->ID);
 -
 -		$command=$this->_db->createCommand("DELETE FROM tblComments WHERE post_id=?");
 -		$command->bindValue(1, $id);
 -		$command->execute();
 -
 -		$command=$this->_db->createCommand("DELETE FROM tblPosts WHERE id=?");
 -		$command->bindValue(1, $id);
 -		$command->execute();
 -	}
 -
 -	protected function populateCommentRecord($row)
 -	{
 -		$commentRecord=new CommentRecord;
 -		$commentRecord->ID=(integer)$row['id'];
 -		$commentRecord->PostID=(integer)$row['post_id'];
 -		$commentRecord->AuthorName=$row['author_name'];
 -		$commentRecord->AuthorEmail=$row['author_email'];
 -		$commentRecord->AuthorWebsite=$row['author_website'];
 -		$commentRecord->AuthorIP=$row['author_ip'];
 -		$commentRecord->CreateTime=(integer)$row['create_time'];
 -		$commentRecord->Content=$row['content'];
 -		$commentRecord->Status=(integer)$row['status'];
 -		return $commentRecord;
 -	}
 -
 -	public function queryComments($filter,$orderBy,$limit)
 -	{
 -		//FIXME this is insecure by design since it misses proper escaping 
 -		if($filter!=='')
 -			$filter='WHERE '.$filter;
 -		$sql="SELECT * FROM tblComments $filter $orderBy $limit";
 -		$rows=$this->query($sql);
 -		$comments=array();
 -		foreach($rows as $row)
 -			$comments[]=$this->populateCommentRecord($row);
 -		return $comments;
 -	}
 -
 -	public function queryCommentsByPostID($id)
 -	{
 -		$sql="SELECT * FROM tblComments WHERE post_id=? ORDER BY create_time DESC";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $id);
 -
 -		$rows=$command->query();
 -
 -		$comments=array();
 -		foreach($rows as $row)
 -			$comments[]=$this->populateCommentRecord($row);
 -		return $comments;
 -	}
 -
 -	public function insertComment($comment)
 -	{
 -		$sql="INSERT INTO tblComments
 -				(post_id,author_name,author_email,author_website,author_ip,create_time,status,content)
 -				VALUES (?,?,?,?,?,?,?,?)";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $comment->PostID);
 -		$command->bindValue(2, $comment->AuthorName);
 -		$command->bindValue(3, $comment->AuthorEmail);
 -		$command->bindValue(4, $comment->AuthorWebsite);
 -		$command->bindValue(5, $comment->AuthorIP);
 -		$command->bindValue(6, $comment->CreateTime);
 -		$command->bindValue(7, $comment->Status);
 -		$command->bindValue(8, $comment->Content);
 -
 -		$command->execute();
 -		$comment->ID=$this->_db->getLastInsertID();
 -		$this->query("UPDATE tblPosts SET comment_count=comment_count+1 WHERE id={$comment->PostID}");
 -	}
 -
 -	public function updateComment($comment)
 -	{
 -		$sql="UPDATE tblComments SET status=? WHERE id=?";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $comment->Status);
 -		$command->bindValue(2, $comment->ID);
 -
 -		$command->execute();
 -	}
 -
 -	public function deleteComment($id)
 -	{
 -		$sql="SELECT post_id FROM tblComments WHERE id=?";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $id);
 -		$result=$command->query();
 -
 -		if(($row=$result->read())!==false)
 -		{
 -			$command=$this->_db->createCommand("DELETE FROM tblComments WHERE id=?");
 -			$command->bindValue(1, $id);
 -			$command->execute();
 -
 -			$command=$this->_db->createCommand("UPDATE tblPosts SET comment_count=comment_count-1 WHERE id=?");
 -			$command->bindValue(1, $row['post_id']);
 -			$command->execute();
 -		}
 -	}
 -
 -	protected function populateCategoryRecord($row)
 -	{
 -		$catRecord=new CategoryRecord;
 -		$catRecord->ID=(integer)$row['id'];
 -		$catRecord->Name=$row['name'];
 -		$catRecord->Description=$row['description'];
 -		$catRecord->PostCount=$row['post_count'];
 -		return $catRecord;
 -	}
 -
 -	public function queryCategories()
 -	{
 -		$sql="SELECT * FROM tblCategories ORDER BY name ASC";
 -		$rows=$this->query($sql);
 -		$cats=array();
 -		foreach($rows as $row)
 -			$cats[]=$this->populateCategoryRecord($row);
 -		return $cats;
 -	}
 -
 -	public function queryCategoriesByPostID($postID)
 -	{
 -		$sql="SELECT a.id AS id,
 -				a.name AS name,
 -				a.description AS description,
 -				a.post_count AS post_count
 -				FROM tblCategories a, tblPost2Category b
 -				WHERE a.id=b.category_id AND b.post_id=? ORDER BY a.name";
 -
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $postID);
 -		$rows=$command->query();
 -
 -		$cats=array();
 -		foreach($rows as $row)
 -			$cats[]=$this->populateCategoryRecord($row);
 -		return $cats;
 -	}
 -
 -	public function queryCategoryByID($id)
 -	{
 -		$sql="SELECT * FROM tblCategories WHERE id=?";
 -
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $id);
 -		$result=$command->query();
 -
 -		if(($row=$result->read())!==false)
 -			return $this->populateCategoryRecord($row);
 -		else
 -			return null;
 -	}
 -
 -	public function queryCategoryByName($name)
 -	{
 -		$sql="SELECT * FROM tblCategories WHERE name=?";
 -
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $name);
 -		$result=$command->query();
 -
 -		if(($row=$result->read())!==false)
 -			return $this->populateCategoryRecord($row);
 -		else
 -			return null;
 -	}
 -
 -	public function insertCategory($category)
 -	{
 -		$sql="INSERT INTO tblCategories
 -				(name,description)
 -				VALUES (?,?)";
 -
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $category->Name);
 -		$command->bindValue(2, $category->Description);
 -		$command->execute();
 -
 -		$category->ID=$this->_db->getLastInsertID();
 -	}
 -
 -	public function updateCategory($category)
 -	{
 -		$sql="UPDATE tblCategories SET name=?, description=?, post_count=? WHERE id=?";
 -
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $category->Name);
 -		$command->bindValue(2, $category->Description);
 -		$command->bindValue(3, $category->PostCount);
 -		$command->bindValue(4, $category->ID);
 -
 -		$command->execute();
 -	}
 -
 -	public function deleteCategory($id)
 -	{
 -		$sql="DELETE FROM tblPost2Category WHERE category_id=?";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $id);
 -		$command->execute();
 -
 -		$sql="DELETE FROM tblCategories WHERE id=?";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $id);
 -		$command->execute();
 -	}
 -
 -	public function insertPostCategory($postID,$categoryID)
 -	{
 -		$sql="INSERT INTO tblPost2Category (post_id, category_id) VALUES (?, ?)";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $postID);
 -		$command->bindValue(2, $categoryID);
 -		$command->execute();
 -
 -		$sql="UPDATE tblCategories SET post_count=post_count+1 WHERE id=?";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $categoryID);
 -		$command->execute();
 -
 -	}
 -
 -	public function deletePostCategory($postID,$categoryID)
 -	{
 -		$sql="DELETE FROM tblPost2Category WHERE post_id=? AND category_id=?";
 -		$command=$this->_db->createCommand($sql);
 -		$command->bindValue(1, $postID);
 -		$command->bindValue(2, $categoryID);
 -		$result=$command->query();
 -
 -		if($result->getRowCount()>0)
 -		{
 -			$sql="UPDATE tblCategories SET post_count=post_count-1 WHERE id=?";
 -			$command=$this->_db->createCommand($sql);
 -			$command->bindValue(1, $categoryID);
 -			$command->execute();
 -		}
 -	}
 -
 -	public function queryEarliestPostTime()
 -	{
 -		$sql="SELECT MIN(create_time) AS create_time FROM tblPosts";
 -		$result=$this->query($sql);
 -		if(($row=$result->read())!==false)
 -			return $row['create_time'];
 -		else
 -			return time();
 -	}
 -}
 -
 -class UserRecord
 -{
 -	const ROLE_USER=0;
 -	const ROLE_ADMIN=1;
 -	const STATUS_NORMAL=0;
 -	const STATUS_DISABLED=1;
 -	const STATUS_PENDING=2;
 -	public $ID;
 -	public $Name;
 -	public $FullName;
 -	public $Role;
 -	public $Password;
 -	public $VerifyCode;
 -	public $Email;
 -	public $CreateTime;
 -	public $Status;
 -	public $Website;
 -}
 -
 -class PostRecord
 -{
 -	const STATUS_PUBLISHED=0;
 -	const STATUS_DRAFT=1;
 -	const STATUS_PENDING=2;
 -	const STATUS_STICKY=3;
 -	public $ID;
 -	public $AuthorID;
 -	public $AuthorName;
 -	public $CreateTime;
 -	public $ModifyTime;
 -	public $Title;
 -	public $Content;
 -	public $Status;
 -	public $CommentCount;
 -}
 -
 -class CommentRecord
 -{
 -	public $ID;
 -	public $PostID;
 -	public $AuthorName;
 -	public $AuthorEmail;
 -	public $AuthorWebsite;
 -	public $AuthorIP;
 -	public $CreateTime;
 -	public $Status;
 -	public $Content;
 -}
 -
 -class CategoryRecord
 -{
 -	public $ID;
 -	public $Name;
 -	public $Description;
 -	public $PostCount;
 -}
 -
 +<?php +/** + * BlogDataModule class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * BlogDataModule class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogDataModule extends TModule +{ +	const DB_FILE_EXT='.db'; +	const DEFAULT_DB_FILE='Application.Data.Blog'; +	private $_db=null; +	private $_dbFile=null; + +	public function init($config) +	{ +		$this->connectDatabase(); +	} + +	public function getDbFile() +	{ +		if($this->_dbFile===null) +			$this->_dbFile=Prado::getPathOfNamespace(self::DEFAULT_DB_FILE,self::DB_FILE_EXT); +		return $this->_dbFile; +	} + +	public function setDbFile($value) +	{ +		if(($this->_dbFile=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null) +			throw new BlogException(500,'blogdatamodule_dbfile_invalid',$value); +	} + +	protected function createDatabase() +	{ +		$schemaFile=dirname(__FILE__).'/schema.sql'; +		$statements=explode(';',file_get_contents($schemaFile)); +		foreach($statements as $statement) +		{ +			if(trim($statement)!=='') +			{ +				try { +					$command=$this->_db->createCommand($statement); +					$command->execute(); +				} +				catch(TDbException $e) +				{ +					throw new BlogException(500,'blogdatamodule_createdatabase_failed',$e->getErrorMessage(),$statement); +				} +			} +		} +	} + +	protected function connectDatabase() +	{ +		$dbFile=$this->getDbFile(); +		$newDb=!is_file($dbFile); + +		try { +			$this->_db=new TDbConnection("sqlite:".$dbFile); +			$this->_db->Active=true; +		} +		catch(TDbException $e) +		{ +			throw new BlogException(500,'blogdatamodule_dbconnect_failed',$e->getErrorMessage()); +		} + +		if($newDb) +			$this->createDatabase(); +	} + +	protected function generateModifier($filter,$orderBy,$limit) +	{ +		$modifier=''; +		if($filter!=='') +			$modifier=' WHERE '.$filter; +		if($orderBy!=='') +			$modifier.=' ORDER BY '.$orderBy; +		if($limit!=='') +			$modifier.=' LIMIT '.$limit; +		return $modifier; +	} + +	public function query($sql) +	{ +		try { +			$command=$this->_db->createCommand($sql); +			return $command->query(); +		} +		catch(TDbException $e) +		{ +			throw new BlogException(500,'blogdatamodule_query_failed',$e->getErrorMessage(),$sql); +		} +	} + +	protected function populateUserRecord($row) +	{ +		$userRecord=new UserRecord; +		$userRecord->ID=(integer)$row['id']; +		$userRecord->Name=$row['name']; +		$userRecord->FullName=$row['full_name']; +		$userRecord->Role=(integer)$row['role']; +		$userRecord->Password=$row['passwd']; +		$userRecord->VerifyCode=$row['vcode']; +		$userRecord->Email=$row['email']; +		$userRecord->CreateTime=(integer)$row['reg_time']; +		$userRecord->Status=(integer)$row['status']; +		$userRecord->Website=$row['website']; +		return $userRecord; +	} + +	public function queryUsers($filter='',$orderBy='',$limit='') +	{ +		if($filter!=='') +			$filter='WHERE '.$filter; +		$sql="SELECT * FROM tblUsers $filter $orderBy $limit"; +		$rows=$this->query($sql); +		$users=array(); +		foreach($rows as $row) +			$users[]=$this->populateUserRecord($row); +		return $users; +	} + +	public function queryUserCount($filter) +	{ +		if($filter!=='') +			$filter='WHERE '.$filter; +		$sql="SELECT COUNT(id) AS user_count FROM tblUsers $filter"; +		$result=$this->query($sql); +		if(($row=$result->read())!==false) +			return $row['user_count']; +		else +			return 0; +	} + +	public function queryUserByID($id) +	{ +		$sql="SELECT * FROM tblUsers WHERE id=$id"; +		$result=$this->query($sql); +		if(($row=$result->read())!==false) +			return $this->populateUserRecord($row); +		else +			return null; +	} + +	public function queryUserByName($name) +	{ +		$command=$this->_db->createCommand("SELECT * FROM tblUsers WHERE name=?"); +		$command->bindValue(1, $name); + +		$result=$command->query(); + +		if(($row=$result->read())!==false) +			return $this->populateUserRecord($row); +		else +			return null; +	} + +	public function insertUser($user) +	{ +		$command=$this->_db->createCommand("INSERT INTO tblUsers ". +				"(name,full_name,role,passwd,email,reg_time,status,website) ". +				"VALUES (?,?,?,?,?,?,?,?)"); +		$command->bindValue(1, $user->Name); +		$command->bindValue(2, $user->FullName); +		$command->bindValue(3, $user->Role); +		$command->bindValue(4, $user->Password); +		$command->bindValue(5, $user->Email); +		$command->bindValue(6, time()); +		$command->bindValue(7, $user->Status); +		$command->bindValue(8, $user->Website); +		$command->execute(); + +		$user->ID=$this->_db->getLastInsertID(); +	} + +	public function updateUser($user) +	{ +		$command=$this->_db->createCommand("UPDATE tblUsers SET +				name=?, +				full_name=?, +				role=?, +				passwd=?, +				vcode=?, +				email=?, +				status=?, +				website=? +				WHERE id=?"); +		$command->bindValue(1, $user->Name); +		$command->bindValue(2, $user->FullName); +		$command->bindValue(3, $user->Role); +		$command->bindValue(4, $user->Password); +		$command->bindValue(5, $user->VerifyCode); +		$command->bindValue(6, $user->Email); +		$command->bindValue(7, $user->Status); +		$command->bindValue(8, $user->Website); +		$command->bindValue(9, $user->ID); +		$command->execute(); +	} + +	public function deleteUser($id) +	{ +		$command=$this->_db->createCommand("DELETE FROM tblUsers WHERE id=?"); +		$command->bindValue(1, $id); +		$command->execute(); +	} + +	protected function populatePostRecord($row) +	{ +		$postRecord=new PostRecord; +		$postRecord->ID=(integer)$row['id']; +		$postRecord->AuthorID=(integer)$row['author_id']; +		if($row['author_full_name']!=='') +			$postRecord->AuthorName=$row['author_full_name']; +		else +			$postRecord->AuthorName=$row['author_name']; +		$postRecord->CreateTime=(integer)$row['create_time']; +		$postRecord->ModifyTime=(integer)$row['modify_time']; +		$postRecord->Title=$row['title']; +		$postRecord->Content=$row['content']; +		$postRecord->Status=(integer)$row['status']; +		$postRecord->CommentCount=(integer)$row['comment_count']; +		return $postRecord; +	} + +	public function queryPosts($postFilter,$categoryFilter,$orderBy,$limit) +	{ +		//FIXME this is insecure by design since it misses proper escaping  +		$filter=''; +		if($postFilter!=='') +			$filter.=" AND $postFilter"; +		if($categoryFilter!=='') +			$filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)"; +		$sql="SELECT a.id AS id, +					a.author_id AS author_id, +					b.name AS author_name, +					b.full_name AS author_full_name, +					a.create_time AS create_time, +					a.modify_time AS modify_time, +					a.title AS title, +					a.content AS content, +					a.status AS status, +					a.comment_count AS comment_count +				FROM tblPosts a, tblUsers b +				WHERE a.author_id=b.id $filter $orderBy $limit"; +		$rows=$this->query($sql); +		$posts=array(); +		foreach($rows as $row) +			$posts[]=$this->populatePostRecord($row); +		return $posts; +	} + +	public function queryPostsSearch($keywords,$orderBy,$limit) +	{ +		$sql="SELECT a.id AS id, +					a.author_id AS author_id, +					b.name AS author_name, +					b.full_name AS author_full_name, +					a.create_time AS create_time, +					a.modify_time AS modify_time, +					a.title AS title, +					a.content AS content, +					a.status AS status, +					a.comment_count AS comment_count +				FROM tblPosts a, tblUsers b +				WHERE a.author_id=b.id AND a.status=0"; + +		foreach($keywords as $keyword) +			$sql.=" AND (content LIKE ? OR title LIKE ?)"; + +		$sql.=" $orderBy $limit"; + +		$command=$this->_db->createCommand($sql); + +		$i=1; +		foreach($keywords as $keyword) +		{ +			$command->bindValue($i, "%".$keyword."%"); +			$i++; +		} + +		$rows=$command->query(); + +		$posts=array(); +		foreach($rows as $row) +			$posts[]=$this->populatePostRecord($row); +		return $posts; + +	} + +	public function queryPostCount($postFilter,$categoryFilter) +	{ +		//FIXME this is insecure by design since it misses proper escaping  +		$filter=''; +		if($postFilter!=='') +			$filter.=" AND $postFilter"; +		if($categoryFilter!=='') +			$filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)"; +		$sql="SELECT COUNT(a.id) AS post_count +				FROM tblPosts a, tblUsers b +				WHERE a.author_id=b.id $filter"; +		$result=$this->query($sql); +		if(($row=$result->read())!==false) +			return $row['post_count']; +		else +			return 0; +	} + +	public function queryPostByID($id) +	{ +		$sql="SELECT a.id AS id, +		             a.author_id AS author_id, +		             b.name AS author_name, +		             b.full_name AS author_full_name, +		             a.create_time AS create_time, +		             a.modify_time AS modify_time, +		             a.title AS title, +		             a.content AS content, +		             a.status AS status, +		             a.comment_count AS comment_count +		      FROM tblPosts a, tblUsers b +		      WHERE a.id=? AND a.author_id=b.id"; + +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $id); + +		$result=$command->query(); + +		if(($row=$result->read())!==false) +			return $this->populatePostRecord($row); +		else +			return null; +	} + +	public function insertPost($post,$catIDs) +	{ +		$command=$this->_db->createCommand("INSERT INTO tblPosts +				(author_id,create_time,modify_time,title,content,status) +				VALUES (?,?,?,?,?,?)"); +		$command->bindValue(1, $post->AuthorID); +		$command->bindValue(2, $post->CreateTime); +		$command->bindValue(3, $post->ModifyTime); +		$command->bindValue(4, $post->Title); +		$command->bindValue(5, $post->Content); +		$command->bindValue(6, $post->Status); + +		$command->execute(); +		$post->ID=$this->_db->getLastInsertID(); +		foreach($catIDs as $catID) +			$this->insertPostCategory($post->ID,$catID); +	} + +	public function updatePost($post,$newCatIDs=null) +	{ +		if($newCatIDs!==null) +		{ +			$cats=$this->queryCategoriesByPostID($post->ID); +			$catIDs=array(); +			foreach($cats as $cat) +				$catIDs[]=$cat->ID; +			$deleteIDs=array_diff($catIDs,$newCatIDs); +			foreach($deleteIDs as $id) +				$this->deletePostCategory($post->ID,$id); +			$insertIDs=array_diff($newCatIDs,$catIDs); +			foreach($insertIDs as $id) +				$this->insertPostCategory($post->ID,$id); +		} + +		$command=$this->_db->createCommand("UPDATE tblPosts SET +				modify_time=?, +				title=?, +				content=?, +				status=? +				WHERE id=?"); +		$command->bindValue(1, $post->ModifyTime); +		$command->bindValue(2, $post->Title); +		$command->bindValue(3, $post->Content); +		$command->bindValue(4, $post->Status); +		$command->bindValue(5, $post->ID); + +		$command->execute(); +	} + +	public function deletePost($id) +	{ +		$cats=$this->queryCategoriesByPostID($id); +		foreach($cats as $cat) +			$this->deletePostCategory($id,$cat->ID); + +		$command=$this->_db->createCommand("DELETE FROM tblComments WHERE post_id=?"); +		$command->bindValue(1, $id); +		$command->execute(); + +		$command=$this->_db->createCommand("DELETE FROM tblPosts WHERE id=?"); +		$command->bindValue(1, $id); +		$command->execute(); +	} + +	protected function populateCommentRecord($row) +	{ +		$commentRecord=new CommentRecord; +		$commentRecord->ID=(integer)$row['id']; +		$commentRecord->PostID=(integer)$row['post_id']; +		$commentRecord->AuthorName=$row['author_name']; +		$commentRecord->AuthorEmail=$row['author_email']; +		$commentRecord->AuthorWebsite=$row['author_website']; +		$commentRecord->AuthorIP=$row['author_ip']; +		$commentRecord->CreateTime=(integer)$row['create_time']; +		$commentRecord->Content=$row['content']; +		$commentRecord->Status=(integer)$row['status']; +		return $commentRecord; +	} + +	public function queryComments($filter,$orderBy,$limit) +	{ +		//FIXME this is insecure by design since it misses proper escaping  +		if($filter!=='') +			$filter='WHERE '.$filter; +		$sql="SELECT * FROM tblComments $filter $orderBy $limit"; +		$rows=$this->query($sql); +		$comments=array(); +		foreach($rows as $row) +			$comments[]=$this->populateCommentRecord($row); +		return $comments; +	} + +	public function queryCommentsByPostID($id) +	{ +		$sql="SELECT * FROM tblComments WHERE post_id=? ORDER BY create_time DESC"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $id); + +		$rows=$command->query(); + +		$comments=array(); +		foreach($rows as $row) +			$comments[]=$this->populateCommentRecord($row); +		return $comments; +	} + +	public function insertComment($comment) +	{ +		$sql="INSERT INTO tblComments +				(post_id,author_name,author_email,author_website,author_ip,create_time,status,content) +				VALUES (?,?,?,?,?,?,?,?)"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $comment->PostID); +		$command->bindValue(2, $comment->AuthorName); +		$command->bindValue(3, $comment->AuthorEmail); +		$command->bindValue(4, $comment->AuthorWebsite); +		$command->bindValue(5, $comment->AuthorIP); +		$command->bindValue(6, $comment->CreateTime); +		$command->bindValue(7, $comment->Status); +		$command->bindValue(8, $comment->Content); + +		$command->execute(); +		$comment->ID=$this->_db->getLastInsertID(); +		$this->query("UPDATE tblPosts SET comment_count=comment_count+1 WHERE id={$comment->PostID}"); +	} + +	public function updateComment($comment) +	{ +		$sql="UPDATE tblComments SET status=? WHERE id=?"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $comment->Status); +		$command->bindValue(2, $comment->ID); + +		$command->execute(); +	} + +	public function deleteComment($id) +	{ +		$sql="SELECT post_id FROM tblComments WHERE id=?"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $id); +		$result=$command->query(); + +		if(($row=$result->read())!==false) +		{ +			$command=$this->_db->createCommand("DELETE FROM tblComments WHERE id=?"); +			$command->bindValue(1, $id); +			$command->execute(); + +			$command=$this->_db->createCommand("UPDATE tblPosts SET comment_count=comment_count-1 WHERE id=?"); +			$command->bindValue(1, $row['post_id']); +			$command->execute(); +		} +	} + +	protected function populateCategoryRecord($row) +	{ +		$catRecord=new CategoryRecord; +		$catRecord->ID=(integer)$row['id']; +		$catRecord->Name=$row['name']; +		$catRecord->Description=$row['description']; +		$catRecord->PostCount=$row['post_count']; +		return $catRecord; +	} + +	public function queryCategories() +	{ +		$sql="SELECT * FROM tblCategories ORDER BY name ASC"; +		$rows=$this->query($sql); +		$cats=array(); +		foreach($rows as $row) +			$cats[]=$this->populateCategoryRecord($row); +		return $cats; +	} + +	public function queryCategoriesByPostID($postID) +	{ +		$sql="SELECT a.id AS id, +				a.name AS name, +				a.description AS description, +				a.post_count AS post_count +				FROM tblCategories a, tblPost2Category b +				WHERE a.id=b.category_id AND b.post_id=? ORDER BY a.name"; + +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $postID); +		$rows=$command->query(); + +		$cats=array(); +		foreach($rows as $row) +			$cats[]=$this->populateCategoryRecord($row); +		return $cats; +	} + +	public function queryCategoryByID($id) +	{ +		$sql="SELECT * FROM tblCategories WHERE id=?"; + +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $id); +		$result=$command->query(); + +		if(($row=$result->read())!==false) +			return $this->populateCategoryRecord($row); +		else +			return null; +	} + +	public function queryCategoryByName($name) +	{ +		$sql="SELECT * FROM tblCategories WHERE name=?"; + +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $name); +		$result=$command->query(); + +		if(($row=$result->read())!==false) +			return $this->populateCategoryRecord($row); +		else +			return null; +	} + +	public function insertCategory($category) +	{ +		$sql="INSERT INTO tblCategories +				(name,description) +				VALUES (?,?)"; + +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $category->Name); +		$command->bindValue(2, $category->Description); +		$command->execute(); + +		$category->ID=$this->_db->getLastInsertID(); +	} + +	public function updateCategory($category) +	{ +		$sql="UPDATE tblCategories SET name=?, description=?, post_count=? WHERE id=?"; + +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $category->Name); +		$command->bindValue(2, $category->Description); +		$command->bindValue(3, $category->PostCount); +		$command->bindValue(4, $category->ID); + +		$command->execute(); +	} + +	public function deleteCategory($id) +	{ +		$sql="DELETE FROM tblPost2Category WHERE category_id=?"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $id); +		$command->execute(); + +		$sql="DELETE FROM tblCategories WHERE id=?"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $id); +		$command->execute(); +	} + +	public function insertPostCategory($postID,$categoryID) +	{ +		$sql="INSERT INTO tblPost2Category (post_id, category_id) VALUES (?, ?)"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $postID); +		$command->bindValue(2, $categoryID); +		$command->execute(); + +		$sql="UPDATE tblCategories SET post_count=post_count+1 WHERE id=?"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $categoryID); +		$command->execute(); + +	} + +	public function deletePostCategory($postID,$categoryID) +	{ +		$sql="DELETE FROM tblPost2Category WHERE post_id=? AND category_id=?"; +		$command=$this->_db->createCommand($sql); +		$command->bindValue(1, $postID); +		$command->bindValue(2, $categoryID); +		$result=$command->query(); + +		if($result->getRowCount()>0) +		{ +			$sql="UPDATE tblCategories SET post_count=post_count-1 WHERE id=?"; +			$command=$this->_db->createCommand($sql); +			$command->bindValue(1, $categoryID); +			$command->execute(); +		} +	} + +	public function queryEarliestPostTime() +	{ +		$sql="SELECT MIN(create_time) AS create_time FROM tblPosts"; +		$result=$this->query($sql); +		if(($row=$result->read())!==false) +			return $row['create_time']; +		else +			return time(); +	} +} + +class UserRecord +{ +	const ROLE_USER=0; +	const ROLE_ADMIN=1; +	const STATUS_NORMAL=0; +	const STATUS_DISABLED=1; +	const STATUS_PENDING=2; +	public $ID; +	public $Name; +	public $FullName; +	public $Role; +	public $Password; +	public $VerifyCode; +	public $Email; +	public $CreateTime; +	public $Status; +	public $Website; +} + +class PostRecord +{ +	const STATUS_PUBLISHED=0; +	const STATUS_DRAFT=1; +	const STATUS_PENDING=2; +	const STATUS_STICKY=3; +	public $ID; +	public $AuthorID; +	public $AuthorName; +	public $CreateTime; +	public $ModifyTime; +	public $Title; +	public $Content; +	public $Status; +	public $CommentCount; +} + +class CommentRecord +{ +	public $ID; +	public $PostID; +	public $AuthorName; +	public $AuthorEmail; +	public $AuthorWebsite; +	public $AuthorIP; +	public $CreateTime; +	public $Status; +	public $Content; +} + +class CategoryRecord +{ +	public $ID; +	public $Name; +	public $Description; +	public $PostCount; +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Common/BlogErrorHandler.php b/demos/blog/protected/Common/BlogErrorHandler.php index 06042be1..f5144fff 100644 --- a/demos/blog/protected/Common/BlogErrorHandler.php +++ b/demos/blog/protected/Common/BlogErrorHandler.php @@ -1,46 +1,46 @@ -<?php
 -/**
 - * BlogErrorHandler class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('System.Exceptions.TErrorHandler');
 -Prado::using('Application.Common.BlogException');
 -
 -/**
 - * BlogErrorHandler class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class BlogErrorHandler extends TErrorHandler
 -{
 -	/**
 -	 * Displays error to the client user.
 -	 * THttpException and errors happened when the application is in <b>Debug</b>
 -	 * mode will be displayed to the client user.
 -	 * @param integer response status code
 -	 * @param Exception exception instance
 -	 */
 -	protected function handleExternalError($statusCode,$exception)
 -	{
 -		if($exception instanceof BlogException)
 -		{
 -			$message=$exception->getMessage();
 -			Prado::log($message,TLogger::ERROR,'BlogApplication');
 -			$message=urldecode($this->getApplication()->getSecurityManager()->hashData($message));
 -			$this->Response->redirect($this->Service->constructUrl('ErrorReport',array('msg'=>$message),false));
 -		}
 -		else
 -			parent::handleExternalError($statusCode,$exception);
 -	}
 -}
 -
 +<?php +/** + * BlogErrorHandler class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Exceptions.TErrorHandler'); +Prado::using('Application.Common.BlogException'); + +/** + * BlogErrorHandler class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogErrorHandler extends TErrorHandler +{ +	/** +	 * Displays error to the client user. +	 * THttpException and errors happened when the application is in <b>Debug</b> +	 * mode will be displayed to the client user. +	 * @param integer response status code +	 * @param Exception exception instance +	 */ +	protected function handleExternalError($statusCode,$exception) +	{ +		if($exception instanceof BlogException) +		{ +			$message=$exception->getMessage(); +			Prado::log($message,TLogger::ERROR,'BlogApplication'); +			$message=urldecode($this->getApplication()->getSecurityManager()->hashData($message)); +			$this->Response->redirect($this->Service->constructUrl('ErrorReport',array('msg'=>$message),false)); +		} +		else +			parent::handleExternalError($statusCode,$exception); +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Common/BlogException.php b/demos/blog/protected/Common/BlogException.php index 17ae526f..e5ade8a3 100644 --- a/demos/blog/protected/Common/BlogException.php +++ b/demos/blog/protected/Common/BlogException.php @@ -1,31 +1,31 @@ -<?php
 -/**
 - * BlogException class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * BlogException class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class BlogException extends THttpException
 -{
 -	/**
 -	 * @return string path to the error message file
 -	 */
 -	protected function getErrorMessageFile()
 -	{
 -		return dirname(__FILE__).'/messages.txt';
 -	}
 -}
 -
 +<?php +/** + * BlogException class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * BlogException class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogException extends THttpException +{ +	/** +	 * @return string path to the error message file +	 */ +	protected function getErrorMessageFile() +	{ +		return dirname(__FILE__).'/messages.txt'; +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Common/BlogPage.php b/demos/blog/protected/Common/BlogPage.php index aaf0c7e1..a5ac514e 100644 --- a/demos/blog/protected/Common/BlogPage.php +++ b/demos/blog/protected/Common/BlogPage.php @@ -1,49 +1,49 @@ -<?php
 -/**
 - * BlogPage class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * BlogPage class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class BlogPage extends TPage
 -{
 -	public function onPreInit($param)
 -	{
 -		parent::onPreInit($param);
 -		$this->Theme=$this->Application->Parameters['ThemeName'];
 -	}
 -
 -	public function getDataAccess()
 -	{
 -		return $this->getApplication()->getModule('data');
 -	}
 -
 -	public function gotoDefaultPage()
 -	{
 -		$this->gotoPage($this->Service->DefaultPage);
 -	}
 -
 -	public function gotoPage($pagePath,$getParameters=null)
 -	{
 -		$this->Response->redirect($this->Service->constructUrl($pagePath,$getParameters,false));
 -	}
 -
 -	public function reportError($errorCode)
 -	{
 -		$this->gotoPage('ErrorReport',array('id'=>$errorCode));
 -	}
 -}
 -
 +<?php +/** + * BlogPage class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * BlogPage class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogPage extends TPage +{ +	public function onPreInit($param) +	{ +		parent::onPreInit($param); +		$this->Theme=$this->Application->Parameters['ThemeName']; +	} + +	public function getDataAccess() +	{ +		return $this->getApplication()->getModule('data'); +	} + +	public function gotoDefaultPage() +	{ +		$this->gotoPage($this->Service->DefaultPage); +	} + +	public function gotoPage($pagePath,$getParameters=null) +	{ +		$this->Response->redirect($this->Service->constructUrl($pagePath,$getParameters,false)); +	} + +	public function reportError($errorCode) +	{ +		$this->gotoPage('ErrorReport',array('id'=>$errorCode)); +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Common/BlogUser.php b/demos/blog/protected/Common/BlogUser.php index 865d7659..08418965 100644 --- a/demos/blog/protected/Common/BlogUser.php +++ b/demos/blog/protected/Common/BlogUser.php @@ -1,60 +1,60 @@ -<?php
 -/**
 - * BlogUser class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('System.Security.TUser');
 -
 -/**
 - * BlogUser class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class BlogUser extends TUser
 -{
 -	private $_id;
 -
 -	public function getID()
 -	{
 -		return $this->_id;
 -	}
 -
 -	public function setID($value)
 -	{
 -		$this->_id=$value;
 -	}
 -
 -	public function getIsAdmin()
 -	{
 -		return $this->isInRole('admin');
 -	}
 -
 -	public function saveToString()
 -	{
 -		$a=array($this->_id,parent::saveToString());
 -		return serialize($a);
 -	}
 -
 -	public function loadFromString($data)
 -	{
 -		if(!empty($data))
 -		{
 -			list($id,$str)=unserialize($data);
 -			$this->_id=$id;
 -			return parent::loadFromString($str);
 -		}
 -		else
 -			return $this;
 -	}
 -}
 -
 +<?php +/** + * BlogUser class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Security.TUser'); + +/** + * BlogUser class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogUser extends TUser +{ +	private $_id; + +	public function getID() +	{ +		return $this->_id; +	} + +	public function setID($value) +	{ +		$this->_id=$value; +	} + +	public function getIsAdmin() +	{ +		return $this->isInRole('admin'); +	} + +	public function saveToString() +	{ +		$a=array($this->_id,parent::saveToString()); +		return serialize($a); +	} + +	public function loadFromString($data) +	{ +		if(!empty($data)) +		{ +			list($id,$str)=unserialize($data); +			$this->_id=$id; +			return parent::loadFromString($str); +		} +		else +			return $this; +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Common/BlogUserManager.php b/demos/blog/protected/Common/BlogUserManager.php index efaa7f1f..26a4427a 100644 --- a/demos/blog/protected/Common/BlogUserManager.php +++ b/demos/blog/protected/Common/BlogUserManager.php @@ -1,95 +1,95 @@ -<?php
 -/**
 - * BlogUserManager class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('System.Security.IUserManager');
 -Prado::using('Application.Common.BlogUser');
 -
 -/**
 - * BlogUserManager class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class BlogUserManager extends TModule implements IUserManager
 -{
 -	public function getGuestName()
 -	{
 -		return 'Guest';
 -	}
 -
 -	/**
 -	 * Returns a user instance given the user name.
 -	 * @param string user name, null if it is a guest.
 -	 * @return TUser the user instance, null if the specified username is not in the user database.
 -	 */
 -	public function getUser($username=null)
 -	{
 -		if($username===null)
 -			return new BlogUser($this);
 -		else
 -		{
 -			$username=strtolower($username);
 -			$db=$this->Application->getModule('data');
 -			if(($userRecord=$db->queryUserByName($username))!==null)
 -			{
 -				$user=new BlogUser($this);
 -				$user->setID($userRecord->ID);
 -				$user->setName($username);
 -				$user->setIsGuest(false);
 -				$user->setRoles($userRecord->Role===UserRecord::ROLE_USER?'user':'admin');
 -				return $user;
 -			}
 -			else
 -				return null;
 -		}
 -	}
 -
 -	/**
 -	 * Validates if the username and password are correct.
 -	 * @param string user name
 -	 * @param string password
 -	 * @return boolean true if validation is successful, false otherwise.
 -	 */
 -	public function validateUser($username,$password)
 -	{
 -		$db=$this->Application->getModule('data');
 -		if(($userRecord=$db->queryUserByName($username))!==null)
 -			return $userRecord->Password===md5($password) && $userRecord->Status===UserRecord::STATUS_NORMAL;
 -		else
 -			return false;
 -	}
 -
 -	/**
 -	 * Saves user auth data into a cookie.
 -	 * @param THttpCookie the cookie to receive the user auth data.
 -	 * @since 3.1.1
 -	 */
 -	public function saveUserToCookie($cookie)
 -	{
 -		// do nothing since we don't support cookie-based auth in this example
 -	}
 -
 -	/**
 -	 * Returns a user instance according to auth data stored in a cookie.
 -	 * @param THttpCookie the cookie storing user authentication information
 -	 * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
 -	 * @since 3.1.1
 -	 */
 -	public function getUserFromCookie($cookie)
 -	{
 -		// do nothing since we don't support cookie-based auth in this example
 -		return null;
 -	}
 -}
 -
 +<?php +/** + * BlogUserManager class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Security.IUserManager'); +Prado::using('Application.Common.BlogUser'); + +/** + * BlogUserManager class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogUserManager extends TModule implements IUserManager +{ +	public function getGuestName() +	{ +		return 'Guest'; +	} + +	/** +	 * Returns a user instance given the user name. +	 * @param string user name, null if it is a guest. +	 * @return TUser the user instance, null if the specified username is not in the user database. +	 */ +	public function getUser($username=null) +	{ +		if($username===null) +			return new BlogUser($this); +		else +		{ +			$username=strtolower($username); +			$db=$this->Application->getModule('data'); +			if(($userRecord=$db->queryUserByName($username))!==null) +			{ +				$user=new BlogUser($this); +				$user->setID($userRecord->ID); +				$user->setName($username); +				$user->setIsGuest(false); +				$user->setRoles($userRecord->Role===UserRecord::ROLE_USER?'user':'admin'); +				return $user; +			} +			else +				return null; +		} +	} + +	/** +	 * Validates if the username and password are correct. +	 * @param string user name +	 * @param string password +	 * @return boolean true if validation is successful, false otherwise. +	 */ +	public function validateUser($username,$password) +	{ +		$db=$this->Application->getModule('data'); +		if(($userRecord=$db->queryUserByName($username))!==null) +			return $userRecord->Password===md5($password) && $userRecord->Status===UserRecord::STATUS_NORMAL; +		else +			return false; +	} + +	/** +	 * Saves user auth data into a cookie. +	 * @param THttpCookie the cookie to receive the user auth data. +	 * @since 3.1.1 +	 */ +	public function saveUserToCookie($cookie) +	{ +		// do nothing since we don't support cookie-based auth in this example +	} + +	/** +	 * Returns a user instance according to auth data stored in a cookie. +	 * @param THttpCookie the cookie storing user authentication information +	 * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data. +	 * @since 3.1.1 +	 */ +	public function getUserFromCookie($cookie) +	{ +		// do nothing since we don't support cookie-based auth in this example +		return null; +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Common/XListMenu.php b/demos/blog/protected/Common/XListMenu.php index 7dadfbe4..92ab2984 100644 --- a/demos/blog/protected/Common/XListMenu.php +++ b/demos/blog/protected/Common/XListMenu.php @@ -1,127 +1,127 @@ -<?php
 -/**
 - * XListMenu and XListMenuItem class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('System.Web.UI.WebControls.TListControl');
 -
 -/**
 - * XListMenu class
 - *
 - * XListMenu displays a list of hyperlinks that can be used for page menus.
 - * Menu items adjust their css class automatically according to the current
 - * page displayed. In particular, a menu item is considered as active if
 - * the URL it represents is for the page currently displayed.
 - *
 - * Usage of XListMenu is similar to PRADO list controls. Each list item has
 - * two extra properties: {@link XListMenuItem::setPagePath PagePath} and
 - * {@link XListMenuItem::setNavigateUrl NavigateUrl}. The former is used to
 - * determine if the item is active or not, while the latter specifies the
 - * URL for the item. If the latter is not specified, a URL to the page is
 - * generated automatically.
 - *
 - * In template, you may use the following tags to specify a menu:
 - * <code>
 - *   <com:XListMenu ActiveCssClass="class1" InactiveCssClass="class2">
 - *      <com:XListMenuItem Text="Menu 1" PagePath="Page1" />
 - *      <com:XListMenuItem Text="Menu 2" PagePath="Page2" NavigateUrl="/page2" />
 - *   </com:XListMenu>
 - * </code>
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class XListMenu extends TListControl
 -{
 -	public function addParsedObject($object)
 -	{
 -		if($object instanceof XListMenuItem)
 -			parent::addParsedObject($object);
 -	}
 -
 -	public function getActiveCssClass()
 -	{
 -		return $this->getViewState('ActiveCssClass','');
 -	}
 -
 -	public function setActiveCssClass($value)
 -	{
 -		$this->setViewState('ActiveCssClass',$value,'');
 -	}
 -
 -	public function getInactiveCssClass()
 -	{
 -		return $this->getViewState('InactiveCssClass','');
 -	}
 -
 -	public function setInactiveCssClass($value)
 -	{
 -		$this->setViewState('InactiveCssClass',$value,'');
 -	}
 -
 -	public function render($writer)
 -	{
 -		if(($activeClass=$this->getActiveCssClass())!=='')
 -			$activeClass=' class="'.$activeClass.'"';
 -		if(($inactiveClass=$this->getInactiveCssClass())!=='')
 -			$inactiveClass=' class="'.$inactiveClass.'"';
 -		$currentPagePath=$this->getPage()->getPagePath();
 -		$writer->write("<ul>\n");
 -		foreach($this->getItems() as $item)
 -		{
 -			$pagePath=$item->getPagePath();
 -			//if(strpos($currentPagePath.'.',$pagePath.'.')===0)
 -			if($pagePath[strlen($pagePath)-1]==='*')
 -			{
 -				if(strpos($currentPagePath.'.',rtrim($pagePath,'*'))===0)
 -					$cssClass=$activeClass;
 -				else
 -					$cssClass=$inactiveClass;
 -			}
 -			else
 -			{
 -				if($pagePath===$currentPagePath)
 -					$cssClass=$activeClass;
 -				else
 -					$cssClass=$inactiveClass;
 -			}
 -			if(($url=$item->getNavigateUrl())==='')
 -				$url=$this->getService()->constructUrl($pagePath);
 -			$writer->write("<li><a href=\"$url\"$cssClass>".$item->getText()."</a></li>\n");
 -		}
 -		$writer->write("</ul>");
 -	}
 -}
 -
 -class XListMenuItem extends TListItem
 -{
 -	public function getPagePath()
 -	{
 -		return $this->getValue();
 -	}
 -
 -	public function setPagePath($value)
 -	{
 -		$this->setValue($value);
 -	}
 -
 -	public function getNavigateUrl()
 -	{
 -		return $this->hasAttribute('NavigateUrl')?$this->getAttribute('NavigateUrl'):'';
 -	}
 -
 -	public function setNavigateUrl($value)
 -	{
 -		$this->setAttribute('NavigateUrl',$value);
 -	}
 -}
 -
 +<?php +/** + * XListMenu and XListMenuItem class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Web.UI.WebControls.TListControl'); + +/** + * XListMenu class + * + * XListMenu displays a list of hyperlinks that can be used for page menus. + * Menu items adjust their css class automatically according to the current + * page displayed. In particular, a menu item is considered as active if + * the URL it represents is for the page currently displayed. + * + * Usage of XListMenu is similar to PRADO list controls. Each list item has + * two extra properties: {@link XListMenuItem::setPagePath PagePath} and + * {@link XListMenuItem::setNavigateUrl NavigateUrl}. The former is used to + * determine if the item is active or not, while the latter specifies the + * URL for the item. If the latter is not specified, a URL to the page is + * generated automatically. + * + * In template, you may use the following tags to specify a menu: + * <code> + *   <com:XListMenu ActiveCssClass="class1" InactiveCssClass="class2"> + *      <com:XListMenuItem Text="Menu 1" PagePath="Page1" /> + *      <com:XListMenuItem Text="Menu 2" PagePath="Page2" NavigateUrl="/page2" /> + *   </com:XListMenu> + * </code> + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class XListMenu extends TListControl +{ +	public function addParsedObject($object) +	{ +		if($object instanceof XListMenuItem) +			parent::addParsedObject($object); +	} + +	public function getActiveCssClass() +	{ +		return $this->getViewState('ActiveCssClass',''); +	} + +	public function setActiveCssClass($value) +	{ +		$this->setViewState('ActiveCssClass',$value,''); +	} + +	public function getInactiveCssClass() +	{ +		return $this->getViewState('InactiveCssClass',''); +	} + +	public function setInactiveCssClass($value) +	{ +		$this->setViewState('InactiveCssClass',$value,''); +	} + +	public function render($writer) +	{ +		if(($activeClass=$this->getActiveCssClass())!=='') +			$activeClass=' class="'.$activeClass.'"'; +		if(($inactiveClass=$this->getInactiveCssClass())!=='') +			$inactiveClass=' class="'.$inactiveClass.'"'; +		$currentPagePath=$this->getPage()->getPagePath(); +		$writer->write("<ul>\n"); +		foreach($this->getItems() as $item) +		{ +			$pagePath=$item->getPagePath(); +			//if(strpos($currentPagePath.'.',$pagePath.'.')===0) +			if($pagePath[strlen($pagePath)-1]==='*') +			{ +				if(strpos($currentPagePath.'.',rtrim($pagePath,'*'))===0) +					$cssClass=$activeClass; +				else +					$cssClass=$inactiveClass; +			} +			else +			{ +				if($pagePath===$currentPagePath) +					$cssClass=$activeClass; +				else +					$cssClass=$inactiveClass; +			} +			if(($url=$item->getNavigateUrl())==='') +				$url=$this->getService()->constructUrl($pagePath); +			$writer->write("<li><a href=\"$url\"$cssClass>".$item->getText()."</a></li>\n"); +		} +		$writer->write("</ul>"); +	} +} + +class XListMenuItem extends TListItem +{ +	public function getPagePath() +	{ +		return $this->getValue(); +	} + +	public function setPagePath($value) +	{ +		$this->setValue($value); +	} + +	public function getNavigateUrl() +	{ +		return $this->hasAttribute('NavigateUrl')?$this->getAttribute('NavigateUrl'):''; +	} + +	public function setNavigateUrl($value) +	{ +		$this->setAttribute('NavigateUrl',$value); +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Layouts/MainLayout.php b/demos/blog/protected/Layouts/MainLayout.php index cfc42d50..b7956d75 100644 --- a/demos/blog/protected/Layouts/MainLayout.php +++ b/demos/blog/protected/Layouts/MainLayout.php @@ -1,24 +1,24 @@ -<?php
 -/**
 - * MainLayout class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * MainLayout class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class MainLayout extends TTemplateControl
 -{
 -}
 -
 +<?php +/** + * MainLayout class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * MainLayout class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class MainLayout extends TTemplateControl +{ +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/AdminMenu.php b/demos/blog/protected/Pages/Admin/AdminMenu.php index a631d5b5..4687a5ce 100644 --- a/demos/blog/protected/Pages/Admin/AdminMenu.php +++ b/demos/blog/protected/Pages/Admin/AdminMenu.php @@ -1,24 +1,24 @@ -<?php
 -/**
 - * AdminMenu class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * AdminMenu class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class AdminMenu extends TTemplateControl
 -{
 -}
 -
 +<?php +/** + * AdminMenu class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * AdminMenu class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class AdminMenu extends TTemplateControl +{ +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/ConfigMan.php b/demos/blog/protected/Pages/Admin/ConfigMan.php index 61516c27..c60a04e8 100644 --- a/demos/blog/protected/Pages/Admin/ConfigMan.php +++ b/demos/blog/protected/Pages/Admin/ConfigMan.php @@ -1,77 +1,77 @@ -<?php
 -/**
 - * ConfigMan class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * ConfigMan class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class ConfigMan extends BlogPage
 -{
 -	const CONFIG_FILE='Application.Data.Settings';
 -
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		if(!$this->IsPostBack)
 -		{
 -			$parameters=$this->Application->Parameters;
 -			$this->SiteTitle->Text=$parameters['SiteTitle'];
 -			$this->SiteSubtitle->Text=$parameters['SiteSubtitle'];
 -			$this->SiteOwner->Text=$parameters['SiteOwner'];
 -			$this->AdminEmail->Text=$parameters['AdminEmail'];
 -			$this->MultipleUser->Checked=TPropertyValue::ensureBoolean($parameters['MultipleUser']);
 -			$this->AccountApproval->Checked=TPropertyValue::ensureBoolean($parameters['AccountApproval']);
 -			$this->PostPerPage->Text=$parameters['PostPerPage'];
 -			$this->RecentComments->Text=$parameters['RecentComments'];
 -			$this->PostApproval->Checked=TPropertyValue::ensureBoolean($parameters['PostApproval']);
 -			$themes=$this->Service->ThemeManager->AvailableThemes;
 -			$this->ThemeName->DataSource=$themes;
 -			$this->ThemeName->dataBind();
 -			$this->ThemeName->SelectedValue=array_search($parameters['ThemeName'],$themes);
 -		}
 -	}
 -
 -	public function saveButtonClicked($sender,$param)
 -	{
 -		$dom=new TXmlDocument;
 -		$dom->Encoding='utf-8';
 -		$dom->TagName='parameters';
 -		$elements=$dom->Elements;
 -		$elements[]=$this->createParameter('SiteTitle',$this->SiteTitle->Text);
 -		$elements[]=$this->createParameter('SiteSubtitle',$this->SiteSubtitle->Text);
 -		$elements[]=$this->createParameter('SiteOwner',$this->SiteOwner->Text);
 -		$elements[]=$this->createParameter('AdminEmail',$this->AdminEmail->Text);
 -		$elements[]=$this->createParameter('MultipleUser',$this->MultipleUser->Checked);
 -		$elements[]=$this->createParameter('AccountApproval',$this->AccountApproval->Checked);
 -		$elements[]=$this->createParameter('PostPerPage',$this->PostPerPage->Text);
 -		$elements[]=$this->createParameter('RecentComments',$this->RecentComments->Text);
 -		$elements[]=$this->createParameter('PostApproval',$this->PostApproval->Checked);
 -		$themeName=$this->ThemeName->SelectedItem->Text;
 -		$elements[]=$this->createParameter('ThemeName',$themeName);
 -		$dom->saveToFile(Prado::getPathOfNamespace(self::CONFIG_FILE,'.xml'));
 -		if($themeName!==$this->Theme->Name)
 -			$this->Response->reload();
 -	}
 -
 -	private function createParameter($id,$value)
 -	{
 -		$element=new TXmlElement('parameter');
 -		$element->Attributes['id']=$id;
 -		$element->Attributes['value']=TPropertyValue::ensureString($value);
 -		return $element;
 -	}
 -}
 -
 +<?php +/** + * ConfigMan class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ConfigMan class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ConfigMan extends BlogPage +{ +	const CONFIG_FILE='Application.Data.Settings'; + +	public function onLoad($param) +	{ +		parent::onLoad($param); +		if(!$this->IsPostBack) +		{ +			$parameters=$this->Application->Parameters; +			$this->SiteTitle->Text=$parameters['SiteTitle']; +			$this->SiteSubtitle->Text=$parameters['SiteSubtitle']; +			$this->SiteOwner->Text=$parameters['SiteOwner']; +			$this->AdminEmail->Text=$parameters['AdminEmail']; +			$this->MultipleUser->Checked=TPropertyValue::ensureBoolean($parameters['MultipleUser']); +			$this->AccountApproval->Checked=TPropertyValue::ensureBoolean($parameters['AccountApproval']); +			$this->PostPerPage->Text=$parameters['PostPerPage']; +			$this->RecentComments->Text=$parameters['RecentComments']; +			$this->PostApproval->Checked=TPropertyValue::ensureBoolean($parameters['PostApproval']); +			$themes=$this->Service->ThemeManager->AvailableThemes; +			$this->ThemeName->DataSource=$themes; +			$this->ThemeName->dataBind(); +			$this->ThemeName->SelectedValue=array_search($parameters['ThemeName'],$themes); +		} +	} + +	public function saveButtonClicked($sender,$param) +	{ +		$dom=new TXmlDocument; +		$dom->Encoding='utf-8'; +		$dom->TagName='parameters'; +		$elements=$dom->Elements; +		$elements[]=$this->createParameter('SiteTitle',$this->SiteTitle->Text); +		$elements[]=$this->createParameter('SiteSubtitle',$this->SiteSubtitle->Text); +		$elements[]=$this->createParameter('SiteOwner',$this->SiteOwner->Text); +		$elements[]=$this->createParameter('AdminEmail',$this->AdminEmail->Text); +		$elements[]=$this->createParameter('MultipleUser',$this->MultipleUser->Checked); +		$elements[]=$this->createParameter('AccountApproval',$this->AccountApproval->Checked); +		$elements[]=$this->createParameter('PostPerPage',$this->PostPerPage->Text); +		$elements[]=$this->createParameter('RecentComments',$this->RecentComments->Text); +		$elements[]=$this->createParameter('PostApproval',$this->PostApproval->Checked); +		$themeName=$this->ThemeName->SelectedItem->Text; +		$elements[]=$this->createParameter('ThemeName',$themeName); +		$dom->saveToFile(Prado::getPathOfNamespace(self::CONFIG_FILE,'.xml')); +		if($themeName!==$this->Theme->Name) +			$this->Response->reload(); +	} + +	private function createParameter($id,$value) +	{ +		$element=new TXmlElement('parameter'); +		$element->Attributes['id']=$id; +		$element->Attributes['value']=TPropertyValue::ensureString($value); +		return $element; +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/PostMan.php b/demos/blog/protected/Pages/Admin/PostMan.php index bf6597b1..c2ceb73f 100644 --- a/demos/blog/protected/Pages/Admin/PostMan.php +++ b/demos/blog/protected/Pages/Admin/PostMan.php @@ -1,73 +1,73 @@ -<?php
 -/**
 - * PostMan class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * PostMan class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class PostMan extends BlogPage
 -{
 -	protected function bindData()
 -	{
 -		$offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize;
 -		$limit=$this->PostGrid->PageSize;
 -		$this->PostGrid->DataSource=$this->DataAccess->queryPosts('','','ORDER BY a.status DESC, modify_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();
 -	}
 -}
 -
 +<?php +/** + * PostMan class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * PostMan class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class PostMan extends BlogPage +{ +	protected function bindData() +	{ +		$offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; +		$limit=$this->PostGrid->PageSize; +		$this->PostGrid->DataSource=$this->DataAccess->queryPosts('','','ORDER BY a.status DESC, modify_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/UserMan.php b/demos/blog/protected/Pages/Admin/UserMan.php index 5901c334..231f6c84 100644 --- a/demos/blog/protected/Pages/Admin/UserMan.php +++ b/demos/blog/protected/Pages/Admin/UserMan.php @@ -1,75 +1,75 @@ -<?php
 -/**
 - * UserMan class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * UserMan class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class UserMan extends BlogPage
 -{
 -	protected function bindData()
 -	{
 -		$author=$this->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();
 -	}
 -}
 -
 +<?php +/** + * UserMan class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * UserMan class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class UserMan extends BlogPage +{ +	protected function bindData() +	{ +		$author=$this->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/ErrorReport.php b/demos/blog/protected/Pages/ErrorReport.php index 50d4a047..2b086f5f 100644 --- a/demos/blog/protected/Pages/ErrorReport.php +++ b/demos/blog/protected/Pages/ErrorReport.php @@ -1,29 +1,29 @@ -<?php
 -/**
 - * ErrorReport class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * ErrorReport class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class ErrorReport extends BlogPage
 -{
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		$this->ErrorMessage->Text=$this->Application->SecurityManager->validateData(urldecode($this->Request['msg']));
 -	}
 -}
 -
 +<?php +/** + * ErrorReport class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ErrorReport class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ErrorReport extends BlogPage +{ +	public function onLoad($param) +	{ +		parent::onLoad($param); +		$this->ErrorMessage->Text=$this->Application->SecurityManager->validateData(urldecode($this->Request['msg'])); +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/EditCategory.php b/demos/blog/protected/Pages/Posts/EditCategory.php index 76013264..d60418be 100644 --- a/demos/blog/protected/Pages/Posts/EditCategory.php +++ b/demos/blog/protected/Pages/Posts/EditCategory.php @@ -1,61 +1,61 @@ -<?php
 -/**
 - * EditCategory class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * EditCategory class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class EditCategory extends BlogPage
 -{
 -	private $_category;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		$id=TPropertyValue::ensureInteger($this->Request['id']);
 -		$this->_category=$this->DataAccess->queryCategoryByID($id);
 -		if($this->_category===null)
 -			throw new BlogException(500,'category_id_invalid',$id);
 -	}
 -
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		if(!$this->IsPostBack)
 -		{
 -			$this->CategoryName->Text=$this->_category->Name;
 -			$this->CategoryDescription->Text=$this->_category->Description;
 -		}
 -	}
 -
 -	public function saveButtonClicked($sender,$param)
 -	{
 -		if($this->IsValid)
 -		{
 -			$this->_category->Name=$this->CategoryName->Text;
 -			$this->_category->Description=$this->CategoryDescription->Text;
 -			$this->DataAccess->updateCategory($this->_category);
 -			$this->gotoPage('Posts.ListPost',array('cat'=>$this->_category->ID));
 -		}
 -	}
 -
 -	public function checkCategoryName($sender,$param)
 -	{
 -		$name=$this->CategoryName->Text;
 -		$param->IsValid=$this->DataAccess->queryCategoryByName($name)===null;
 -	}
 -}
 -
 +<?php +/** + * EditCategory class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditCategory class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditCategory extends BlogPage +{ +	private $_category; + +	public function onInit($param) +	{ +		parent::onInit($param); +		$id=TPropertyValue::ensureInteger($this->Request['id']); +		$this->_category=$this->DataAccess->queryCategoryByID($id); +		if($this->_category===null) +			throw new BlogException(500,'category_id_invalid',$id); +	} + +	public function onLoad($param) +	{ +		parent::onLoad($param); +		if(!$this->IsPostBack) +		{ +			$this->CategoryName->Text=$this->_category->Name; +			$this->CategoryDescription->Text=$this->_category->Description; +		} +	} + +	public function saveButtonClicked($sender,$param) +	{ +		if($this->IsValid) +		{ +			$this->_category->Name=$this->CategoryName->Text; +			$this->_category->Description=$this->CategoryDescription->Text; +			$this->DataAccess->updateCategory($this->_category); +			$this->gotoPage('Posts.ListPost',array('cat'=>$this->_category->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.php b/demos/blog/protected/Pages/Posts/EditPost.php index 8d754b30..3ba6f069 100644 --- a/demos/blog/protected/Pages/Posts/EditPost.php +++ b/demos/blog/protected/Pages/Posts/EditPost.php @@ -1,78 +1,78 @@ -<?php
 -/**
 - * EditPost class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * EditPost class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class EditPost extends BlogPage
 -{
 -	private $_postRecord=null;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		$id=TPropertyValue::ensureInteger($this->Request['id']);
 -		$this->_postRecord=$this->DataAccess->queryPostByID($id);
 -		if($this->_postRecord===null)
 -			throw new BlogException(500,'post_id_invalid',$id);
 -		// only the author and admin can edit the post
 -		if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID)
 -			throw new BlogException(500,'post_edit_disallowed',$id);
 -	}
 -
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		if(!$this->IsPostBack)
 -		{
 -			$postRecord=$this->_postRecord;
 -			$this->Title->Text=$postRecord->Title;
 -			$this->Content->Text=$postRecord->Content;
 -			$this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT;
 -			$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->_postRecord;
 -			$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->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));
 -		}
 -	}
 -}
 -
 +<?php +/** + * EditPost class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditPost class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditPost extends BlogPage +{ +	private $_postRecord=null; + +	public function onInit($param) +	{ +		parent::onInit($param); +		$id=TPropertyValue::ensureInteger($this->Request['id']); +		$this->_postRecord=$this->DataAccess->queryPostByID($id); +		if($this->_postRecord===null) +			throw new BlogException(500,'post_id_invalid',$id); +		// only the author and admin can edit the post +		if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID) +			throw new BlogException(500,'post_edit_disallowed',$id); +	} + +	public function onLoad($param) +	{ +		parent::onLoad($param); +		if(!$this->IsPostBack) +		{ +			$postRecord=$this->_postRecord; +			$this->Title->Text=$postRecord->Title; +			$this->Content->Text=$postRecord->Content; +			$this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT; +			$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->_postRecord; +			$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->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.php b/demos/blog/protected/Pages/Posts/ListPost.php index 0e0a044c..7ff9dac9 100644 --- a/demos/blog/protected/Pages/Posts/ListPost.php +++ b/demos/blog/protected/Pages/Posts/ListPost.php @@ -1,142 +1,142 @@ -<?php
 -/**
 - * ListPost class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * ListPost class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class ListPost extends BlogPage
 -{
 -	private $_posts;
 -	private $_category;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		$this->_posts=$this->DataAccess->queryPosts(
 -				$this->getPostFilter(),
 -				$this->getCategoryFilter(),
 -				'ORDER BY a.status DESC, 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;
 -		}
 -		$this->Title=$this->Application->Parameters['SiteTitle'];
 -	}
 -
 -	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()
 -	{
 -		if(($time=TPropertyValue::ensureInteger($this->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);
 -			return "create_time>=$startTime AND create_time<$endTime";
 -		}
 -		else
 -			return '';
 -	}
 -
 -	private function getPostFilter()
 -	{
 -		$filter='(a.status=0 OR a.status=3)';
 -		if(($timeFilter=$this->getTimeFilter())!=='')
 -			return "$filter AND $timeFilter";
 -		else
 -			return $filter;
 -	}
 -
 -	private function getCategoryFilter()
 -	{
 -		if(($catID=$this->Request['cat'])!==null)
 -		{
 -			$catID=TPropertyValue::ensureInteger($catID);
 -			return "category_id=$catID";
 -		}
 -		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->_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();
 -		}
 -	}
 -}
 -
 +<?php +/** + * ListPost class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ListPost class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ListPost extends BlogPage +{ +	private $_posts; +	private $_category; + +	public function onInit($param) +	{ +		parent::onInit($param); +		$this->_posts=$this->DataAccess->queryPosts( +				$this->getPostFilter(), +				$this->getCategoryFilter(), +				'ORDER BY a.status DESC, 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; +		} +		$this->Title=$this->Application->Parameters['SiteTitle']; +	} + +	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() +	{ +		if(($time=TPropertyValue::ensureInteger($this->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); +			return "create_time>=$startTime AND create_time<$endTime"; +		} +		else +			return ''; +	} + +	private function getPostFilter() +	{ +		$filter='(a.status=0 OR a.status=3)'; +		if(($timeFilter=$this->getTimeFilter())!=='') +			return "$filter AND $timeFilter"; +		else +			return $filter; +	} + +	private function getCategoryFilter() +	{ +		if(($catID=$this->Request['cat'])!==null) +		{ +			$catID=TPropertyValue::ensureInteger($catID); +			return "category_id=$catID"; +		} +		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->_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(); +		} +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/MyPost.php b/demos/blog/protected/Pages/Posts/MyPost.php index fd65cc57..7d0be020 100644 --- a/demos/blog/protected/Pages/Posts/MyPost.php +++ b/demos/blog/protected/Pages/Posts/MyPost.php @@ -1,51 +1,51 @@ -<?php
 -/**
 - * MyPost class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * MyPost class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class MyPost extends BlogPage
 -{
 -	protected function bindData()
 -	{
 -		$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 DESC, 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: ');
 -	}
 -}
 -
 +<?php +/** + * MyPost class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * MyPost class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class MyPost extends BlogPage +{ +	protected function bindData() +	{ +		$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 DESC, 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.php b/demos/blog/protected/Pages/Posts/NewCategory.php index 5df0c85b..b5bf26e9 100644 --- a/demos/blog/protected/Pages/Posts/NewCategory.php +++ b/demos/blog/protected/Pages/Posts/NewCategory.php @@ -1,41 +1,41 @@ -<?php
 -/**
 - * NewCategory class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * NewCategory class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class NewCategory extends BlogPage
 -{
 -	public function saveButtonClicked($sender,$param)
 -	{
 -		if($this->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;
 -	}
 -}
 -
 +<?php +/** + * NewCategory class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewCategory class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewCategory extends BlogPage +{ +	public function saveButtonClicked($sender,$param) +	{ +		if($this->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.php b/demos/blog/protected/Pages/Posts/NewPost.php index 2f894cd5..45b1a794 100644 --- a/demos/blog/protected/Pages/Posts/NewPost.php +++ b/demos/blog/protected/Pages/Posts/NewPost.php @@ -1,57 +1,57 @@ -<?php
 -/**
 - * NewPost class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * NewPost class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class NewPost extends BlogPage
 -{
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		if(!$this->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->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->ModifyTime=$postRecord->CreateTime;
 -			$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));
 -		}
 -	}
 -}
 -
 +<?php +/** + * NewPost class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewPost class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewPost extends BlogPage +{ +	public function onLoad($param) +	{ +		parent::onLoad($param); +		if(!$this->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->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->ModifyTime=$postRecord->CreateTime; +			$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.php b/demos/blog/protected/Pages/Posts/ViewPost.php index 662dc659..5831ba93 100644 --- a/demos/blog/protected/Pages/Posts/ViewPost.php +++ b/demos/blog/protected/Pages/Posts/ViewPost.php @@ -1,90 +1,90 @@ -<?php
 -/**
 - * ViewPost class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * ViewPost class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class ViewPost extends BlogPage
 -{
 -	private $_post=null;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		$id=TPropertyValue::ensureInteger($this->Request['id']);
 -		$this->_post=$this->DataAccess->queryPostByID($id);
 -		if($this->_post===null)
 -			throw new BlogException(500,'post_id_invalid',$id);
 -		// if post is not published, only the author and admin can view it
 -		if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID)
 -			throw new BlogException(500,'post_view_disallowed',$id);
 -		$this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8');
 -	}
 -
 -	public function getCanEditPost()
 -	{
 -		$user=$this->getUser();
 -		return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID;
 -	}
 -
 -	public function getCurrentPost()
 -	{
 -		return $this->_post;
 -	}
 -
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		$this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY;
 -		$this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID);
 -		$this->CategoryList->dataBind();
 -		$this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID);
 -		$this->CommentList->dataBind();
 -	}
 -
 -	public function submitCommentButtonClicked($sender,$param)
 -	{
 -		if($this->IsValid)
 -		{
 -			$commentRecord=new CommentRecord;
 -			$commentRecord->PostID=$this->CurrentPost->ID;
 -			$commentRecord->AuthorName=$this->CommentAuthor->SafeText;
 -			$commentRecord->AuthorEmail=$this->CommentEmail->Text;
 -			$commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText;
 -			$commentRecord->AuthorIP=$this->Request->UserHostAddress;
 -			$commentRecord->Content=$this->CommentContent->SafeText;
 -			$commentRecord->CreateTime=time();
 -			$commentRecord->Status=0;
 -			$this->DataAccess->insertComment($commentRecord);
 -			$this->Response->reload();
 -		}
 -	}
 -
 -	public function deleteButtonClicked($sender,$param)
 -	{
 -		$this->DataAccess->deletePost($this->CurrentPost->ID);
 -		$this->gotoDefaultPage();
 -	}
 -
 -	public function repeaterItemCommand($sender,$param)
 -	{
 -		$id=TPropertyValue::ensureInteger($param->CommandParameter);
 -		$this->DataAccess->deleteComment($id);
 -		$this->Response->reload();
 -	}
 -}
 -
 +<?php +/** + * ViewPost class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ViewPost class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ViewPost extends BlogPage +{ +	private $_post=null; + +	public function onInit($param) +	{ +		parent::onInit($param); +		$id=TPropertyValue::ensureInteger($this->Request['id']); +		$this->_post=$this->DataAccess->queryPostByID($id); +		if($this->_post===null) +			throw new BlogException(500,'post_id_invalid',$id); +		// if post is not published, only the author and admin can view it +		if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID) +			throw new BlogException(500,'post_view_disallowed',$id); +		$this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8'); +	} + +	public function getCanEditPost() +	{ +		$user=$this->getUser(); +		return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID; +	} + +	public function getCurrentPost() +	{ +		return $this->_post; +	} + +	public function onLoad($param) +	{ +		parent::onLoad($param); +		$this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY; +		$this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID); +		$this->CategoryList->dataBind(); +		$this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID); +		$this->CommentList->dataBind(); +	} + +	public function submitCommentButtonClicked($sender,$param) +	{ +		if($this->IsValid) +		{ +			$commentRecord=new CommentRecord; +			$commentRecord->PostID=$this->CurrentPost->ID; +			$commentRecord->AuthorName=$this->CommentAuthor->SafeText; +			$commentRecord->AuthorEmail=$this->CommentEmail->Text; +			$commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText; +			$commentRecord->AuthorIP=$this->Request->UserHostAddress; +			$commentRecord->Content=$this->CommentContent->SafeText; +			$commentRecord->CreateTime=time(); +			$commentRecord->Status=0; +			$this->DataAccess->insertComment($commentRecord); +			$this->Response->reload(); +		} +	} + +	public function deleteButtonClicked($sender,$param) +	{ +		$this->DataAccess->deletePost($this->CurrentPost->ID); +		$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/SearchPost.php b/demos/blog/protected/Pages/SearchPost.php index dc483f9a..437435f9 100644 --- a/demos/blog/protected/Pages/SearchPost.php +++ b/demos/blog/protected/Pages/SearchPost.php @@ -1,68 +1,68 @@ -<?php
 -
 -class SearchPost extends BlogPage
 -{
 -	private $_posts;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		$this->_posts=$this->DataAccess->queryPostsSearch(
 -				$this->getPostKeywords(),
 -				'ORDER BY create_time DESC',
 -				'LIMIT '.$this->getPageOffset().','.$this->getPageSize());
 -	}
 -
 -	private function getPostKeywords()
 -	{
 -		return explode(' ',$this->Request['keyword']);
 -	}
 -
 -	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;
 -		}
 -	}
 -}
 -
 +<?php + +class SearchPost extends BlogPage +{ +	private $_posts; + +	public function onInit($param) +	{ +		parent::onInit($param); +		$this->_posts=$this->DataAccess->queryPostsSearch( +				$this->getPostKeywords(), +				'ORDER BY create_time DESC', +				'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); +	} + +	private function getPostKeywords() +	{ +		return explode(' ',$this->Request['keyword']); +	} + +	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 diff --git a/demos/blog/protected/Pages/Users/EditUser.php b/demos/blog/protected/Pages/Users/EditUser.php index c574ca6b..8d5cb090 100644 --- a/demos/blog/protected/Pages/Users/EditUser.php +++ b/demos/blog/protected/Pages/Users/EditUser.php @@ -1,69 +1,69 @@ -<?php
 -/**
 - * EditUser class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * EditUser class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class EditUser extends BlogPage
 -{
 -	private $_userRecord=null;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		if(($id=$this->Request['id'])!==null)
 -		{
 -			$id=TPropertyValue::ensureInteger($id);
 -			if(!$this->User->IsAdmin && $this->User->ID!==$id)
 -				throw new BlogException(500,'profile_edit_disallowed',$id);
 -		}
 -		else
 -			$id=$this->User->ID;
 -		if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null)
 -			throw new BlogException(500,'profile_id_invalid',$id);
 -	}
 -
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		if(!$this->IsPostBack)
 -		{
 -			$userRecord=$this->_userRecord;
 -			$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->_userRecord;
 -			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));
 -		}
 -	}
 -}
 -
 +<?php +/** + * EditUser class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditUser class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditUser extends BlogPage +{ +	private $_userRecord=null; + +	public function onInit($param) +	{ +		parent::onInit($param); +		if(($id=$this->Request['id'])!==null) +		{ +			$id=TPropertyValue::ensureInteger($id); +			if(!$this->User->IsAdmin && $this->User->ID!==$id) +				throw new BlogException(500,'profile_edit_disallowed',$id); +		} +		else +			$id=$this->User->ID; +		if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null) +			throw new BlogException(500,'profile_id_invalid',$id); +	} + +	public function onLoad($param) +	{ +		parent::onLoad($param); +		if(!$this->IsPostBack) +		{ +			$userRecord=$this->_userRecord; +			$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->_userRecord; +			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.php b/demos/blog/protected/Pages/Users/NewUser.php index 40e79910..50f9f123 100644 --- a/demos/blog/protected/Pages/Users/NewUser.php +++ b/demos/blog/protected/Pages/Users/NewUser.php @@ -1,58 +1,58 @@ -<?php
 -/**
 - * NewUser class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * NewUser class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class NewUser extends BlogPage
 -{
 -	public function onInit($param)
 -	{
 -		if(!$this->User->IsAdmin && !TPropertyValue::ensureBoolean($this->Application->Parameters['MultipleUser']))
 -			throw new BlogException(500,'newuser_registration_disallowed');
 -	}
 -
 -	public function checkUsername($sender,$param)
 -	{
 -		$username=strtolower($this->Username->Text);
 -		$param->IsValid=$this->DataAccess->queryUserByName($username)===null;
 -	}
 -
 -	public function createUser($sender,$param)
 -	{
 -		if($this->IsValid)
 -		{
 -			$userRecord=new UserRecord;
 -			$userRecord->Name=strtolower($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;
 -			if(TPropertyValue::ensureBoolean($this->Application->Parameters['AccountApproval']))
 -				$userRecord->Status=UserRecord::STATUS_PENDING;
 -			else
 -				$userRecord->Status=UserRecord::STATUS_NORMAL;
 -			$this->DataAccess->insertUser($userRecord);
 -			$authManager=$this->Application->getModule('auth');
 -			$authManager->login($this->Username->Text,$this->Password->Text);
 -			$this->gotoDefaultPage();
 -		}
 -	}
 -}
 -
 +<?php +/** + * NewUser class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewUser class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewUser extends BlogPage +{ +	public function onInit($param) +	{ +		if(!$this->User->IsAdmin && !TPropertyValue::ensureBoolean($this->Application->Parameters['MultipleUser'])) +			throw new BlogException(500,'newuser_registration_disallowed'); +	} + +	public function checkUsername($sender,$param) +	{ +		$username=strtolower($this->Username->Text); +		$param->IsValid=$this->DataAccess->queryUserByName($username)===null; +	} + +	public function createUser($sender,$param) +	{ +		if($this->IsValid) +		{ +			$userRecord=new UserRecord; +			$userRecord->Name=strtolower($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; +			if(TPropertyValue::ensureBoolean($this->Application->Parameters['AccountApproval'])) +				$userRecord->Status=UserRecord::STATUS_PENDING; +			else +				$userRecord->Status=UserRecord::STATUS_NORMAL; +			$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.php b/demos/blog/protected/Pages/Users/ViewUser.php index 75bd711a..86c27592 100644 --- a/demos/blog/protected/Pages/Users/ViewUser.php +++ b/demos/blog/protected/Pages/Users/ViewUser.php @@ -1,42 +1,42 @@ -<?php
 -/**
 - * ViewUser class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * ViewUser class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class ViewUser extends BlogPage
 -{
 -	private $_userRecord=null;
 -
 -	public function onInit($param)
 -	{
 -		parent::onInit($param);
 -		if(($id=$this->Request['id'])!==null)
 -			$id=TPropertyValue::ensureInteger($id);
 -		else
 -			$id=$this->User->ID;
 -		if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null)
 -			throw new BlogException(500,'profile_id_invalid',$id);
 -		$this->_userRecord->Email=strtr(strtoupper($this->_userRecord->Email),array('@'=>' at ','.'=>' dot '));
 -	}
 -
 -	public function getProfile()
 -	{
 -		return $this->_userRecord;
 -	}
 -}
 -
 +<?php +/** + * ViewUser class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ViewUser class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ViewUser extends BlogPage +{ +	private $_userRecord=null; + +	public function onInit($param) +	{ +		parent::onInit($param); +		if(($id=$this->Request['id'])!==null) +			$id=TPropertyValue::ensureInteger($id); +		else +			$id=$this->User->ID; +		if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null) +			throw new BlogException(500,'profile_id_invalid',$id); +		$this->_userRecord->Email=strtr(strtoupper($this->_userRecord->Email),array('@'=>' at ','.'=>' dot ')); +	} + +	public function getProfile() +	{ +		return $this->_userRecord; +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Portlets/AccountPortlet.php b/demos/blog/protected/Portlets/AccountPortlet.php index 2bbe55d3..40be36ae 100644 --- a/demos/blog/protected/Portlets/AccountPortlet.php +++ b/demos/blog/protected/Portlets/AccountPortlet.php @@ -1,31 +1,31 @@ -<?php
 -/**
 - * AccountPortlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('Application.Portlets.Portlet');
 -
 -/**
 - * AccountPortlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class AccountPortlet extends Portlet
 -{
 -	public function logout($sender,$param)
 -	{
 -		$this->Application->getModule('auth')->logout();
 -		$this->Response->reload();
 -	}
 -}
 -
 +<?php +/** + * AccountPortlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * AccountPortlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +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/ArchivePortlet.php b/demos/blog/protected/Portlets/ArchivePortlet.php index 003eb0cc..f8bd488e 100644 --- a/demos/blog/protected/Portlets/ArchivePortlet.php +++ b/demos/blog/protected/Portlets/ArchivePortlet.php @@ -1,62 +1,62 @@ -<?php
 -/**
 - * ArchivePortlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('Application.Portlets.Portlet');
 -
 -/**
 - * ArchivePortlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -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();
 -	}
 -}
 -
 +<?php +/** + * ArchivePortlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * ArchivePortlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +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/CategoryPortlet.php b/demos/blog/protected/Portlets/CategoryPortlet.php index d95b0661..0b451db8 100644 --- a/demos/blog/protected/Portlets/CategoryPortlet.php +++ b/demos/blog/protected/Portlets/CategoryPortlet.php @@ -1,38 +1,38 @@ -<?php
 -/**
 - * CategoryPortlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('Application.Portlets.Portlet');
 -
 -/**
 - * CategoryPortlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class CategoryPortlet extends Portlet
 -{
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		$cats=$this->Application->getModule('data')->queryCategories();
 -		foreach($cats as $cat)
 -		{
 -			$cat->ID=$this->Service->constructUrl('Posts.ListPost',array('cat'=>$cat->ID));
 -			$cat->Name.=' (' . $cat->PostCount .')';
 -		}
 -		$this->CategoryList->DataSource=$cats;
 -		$this->CategoryList->dataBind();
 -	}
 -}
 -
 +<?php +/** + * CategoryPortlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * CategoryPortlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class CategoryPortlet extends Portlet +{ +	public function onLoad($param) +	{ +		parent::onLoad($param); +		$cats=$this->Application->getModule('data')->queryCategories(); +		foreach($cats as $cat) +		{ +			$cat->ID=$this->Service->constructUrl('Posts.ListPost',array('cat'=>$cat->ID)); +			$cat->Name.=' (' . $cat->PostCount .')'; +		} +		$this->CategoryList->DataSource=$cats; +		$this->CategoryList->dataBind(); +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Portlets/CommentPortlet.php b/demos/blog/protected/Portlets/CommentPortlet.php index c3549928..ff8d075a 100644 --- a/demos/blog/protected/Portlets/CommentPortlet.php +++ b/demos/blog/protected/Portlets/CommentPortlet.php @@ -1,40 +1,40 @@ -<?php
 -/**
 - * CommentPortlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('Application.Portlets.Portlet');
 -
 -/**
 - * CommentPortlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class CommentPortlet extends Portlet
 -{
 -	public function onLoad($param)
 -	{
 -		parent::onLoad($param);
 -		$commentLimit=TPropertyValue::ensureInteger($this->Application->Parameters['RecentComments']);
 -		$comments=$this->Application->getModule('data')->queryComments('','ORDER BY create_time DESC',"LIMIT $commentLimit");
 -		foreach($comments as $comment)
 -		{
 -			$comment->ID=$this->Service->constructUrl('Posts.ViewPost',array('id'=>$comment->PostID)).'#c'.$comment->ID;
 -			if(strlen($comment->Content)>40)
 -				$comment->Content=substr($comment->Content,0,40).' ...';
 -		}
 -		$this->CommentList->DataSource=$comments;
 -		$this->CommentList->dataBind();
 -	}
 -}
 -
 +<?php +/** + * CommentPortlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * CommentPortlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class CommentPortlet extends Portlet +{ +	public function onLoad($param) +	{ +		parent::onLoad($param); +		$commentLimit=TPropertyValue::ensureInteger($this->Application->Parameters['RecentComments']); +		$comments=$this->Application->getModule('data')->queryComments('','ORDER BY create_time DESC',"LIMIT $commentLimit"); +		foreach($comments as $comment) +		{ +			$comment->ID=$this->Service->constructUrl('Posts.ViewPost',array('id'=>$comment->PostID)).'#c'.$comment->ID; +			if(strlen($comment->Content)>40) +				$comment->Content=substr($comment->Content,0,40).' ...'; +		} +		$this->CommentList->DataSource=$comments; +		$this->CommentList->dataBind(); +	} +} +  ?>
\ No newline at end of file diff --git a/demos/blog/protected/Portlets/LoginPortlet.php b/demos/blog/protected/Portlets/LoginPortlet.php index 6f400f0a..58c056b3 100644 --- a/demos/blog/protected/Portlets/LoginPortlet.php +++ b/demos/blog/protected/Portlets/LoginPortlet.php @@ -1,39 +1,39 @@ -<?php
 -/**
 - * LoginPortlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('Application.Portlets.Portlet');
 -
 -/**
 - * LoginPortlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class LoginPortlet extends Portlet
 -{
 -	public function validateUser($sender,$param)
 -	{
 -		$authManager=$this->Application->getModule('auth');
 -		if(!$authManager->login(strtolower($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());
 -	}
 -}
 -
 +<?php +/** + * LoginPortlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * LoginPortlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class LoginPortlet extends Portlet +{ +	public function validateUser($sender,$param) +	{ +		$authManager=$this->Application->getModule('auth'); +		if(!$authManager->login(strtolower($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/Portlet.php b/demos/blog/protected/Portlets/Portlet.php index 50cb634d..6a7cee70 100644 --- a/demos/blog/protected/Portlets/Portlet.php +++ b/demos/blog/protected/Portlets/Portlet.php @@ -1,24 +1,24 @@ -<?php
 -/**
 - * Portlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -/**
 - * Portlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -class Portlet extends TTemplateControl
 -{
 -}
 -
 +<?php +/** + * Portlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * Portlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +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 index 10ef0499..4f7d6ebf 100644 --- a/demos/blog/protected/Portlets/SearchPortlet.php +++ b/demos/blog/protected/Portlets/SearchPortlet.php @@ -1,39 +1,39 @@ -<?php
 -/**
 - * SearchPortlet class file
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - * @version $Id$
 - */
 -
 -Prado::using('Application.Portlets.Portlet');
 -
 -/**
 - * SearchPortlet class
 - *
 - * @author Qiang Xue <qiang.xue@gmail.com>
 - * @link http://www.pradosoft.com/
 - * @copyright Copyright © 2006 PradoSoft
 - * @license http://www.pradosoft.com/license/
 - */
 -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),false);
 -		$this->Response->redirect($url);
 -	}
 -}
 -
 +<?php +/** + * SearchPortlet class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * SearchPortlet class + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +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),false); +		$this->Response->redirect($url); +	} +} +  ?>
\ No newline at end of file  | 
