做了一个新的布局,感觉比以前的舒服.
jquery的特效也修改了.移到到内容区块就把文本的颜色改成漂亮的蓝色.移除去掉.
[javascript] // javascript document
$(document).ready(function(e) {
$user=$(div .user);
$text=$(div .text);
$(div .content).each(function(index){
$(this).mousemove(function(){
$user.eq(index).css(color,#0a8cd2);
// $user.eq(index).css(background,#ffe6ad);
// $text.eq(index).css(background,#fffdf6);
}).mouseout(function(){
$user.eq(index).css(color,#000);
// $user.eq(index).css(background,#e6f0f9);
// $text.eq(index).css(background,#f8fbfd);
});
});
});
// javascript document
$(document).ready(function(e) {
$user=$(div .user);
$text=$(div .text);
$(div .content).each(function(index){
$(this).mousemove(function(){
$user.eq(index).css(color,#0a8cd2);
// $user.eq(index).css(background,#ffe6ad);
// $text.eq(index).css(background,#fffdf6);
}).mouseout(function(){
$user.eq(index).css(color,#000);
// $user.eq(index).css(background,#e6f0f9);
// $text.eq(index).css(background,#f8fbfd);
});
});
});
数据库中增加了 time字段,类型为int,长度为 11;
添加留言时,调用 time()函数返回的ux时间戳,
数据库中读出时,调用 date()函数
[php] date('y-m-d h:i:s',$value['time']);//对时间戳进行转换为日期
date('y-m-d h:i:s',$value['time']);//对时间戳进行转换为日期
然后还添加了一个分页代码
[php] function index() {
include page.class.php;
$rows = $this->db->count('select * from data');
$page = new page($rows, 5, );
$page -> set(head, 条留言);
$page -> set(first, 首页)
-> set(prev, 上一页)
-> set(next, 下一页)
-> set(last, 尾页);
$list=$this->db
->order('id desc')
->limit($page->getlimit())
->select();
$this->assign(page,$page->fpage(0,3,4,5,6));
$this->assign(list,$list);
$this->assign(title, 我的留言板); //分配标题变量给头部模板header.tpl
$this->display(); //包括替换模板中的变量输出模板页面
}
function index() {
include page.class.php;
$rows = $this->db->count('select * from data');
$page = new page($rows, 5, );
$page -> set(head, 条留言);
$page -> set(first, 首页)
-> set(prev, 上一页)
-> set(next, 下一页)
-> set(last, 尾页);
$list=$this->db
->order('id desc')
->limit($page->getlimit())
->select();
$this->assign(page,$page->fpage(0,3,4,5,6));
$this->assign(list,$list);
$this->assign(title, 我的留言板); //分配标题变量给头部模板header.tpl
$this->display(); //包括替换模板中的变量输出模板页面
}
效果还不错噢.
page.class.php 源码附上
[php] 条记录,
'prev' => 上一页,
'next' => 下一页,
'first'=> 首页,
'last' => 末页
); //在分页信息中显示内容,可以自己通过set()方法设置
private $listnum = 10; //默认分页列表显示的个数
/**
构造方法,可以设置分页类的属性
@param int $total 计算分页的总记录数
@param int $listrows 可选的,设置每页需要显示的记录数,默认为25条
@param mixed $query 可选的,为向目标页面传递参数,可以是数组,也可以是查询字符串格式
@param bool $ord 可选的,默认值为true, 页面从第一页开始显示,false则为最后一页
*/
public function __construct($total, $listrows=25, $query=, $ord=true){
$this->total = $total;
$this->listrows = $listrows;
$this->uri = $this->geturi($query);
$this->pagenum = ceil($this->total / $this->listrows);
/*以下判断用来设置当前面*/
if(!empty($_get[page])) {
$page = $_get[page];
}else{
if($ord)
$page = 1;
else
$page = $this->pagenum;
}
if($total > 0) {
if(preg_match('/\d/', $page) ){
$this->page = 1;
}else{
$this->page = $page;
}
}else{
$this->page = 0;
}
$this->limit = limit .$this->getlimit();
}
/**
用于设置显示分页的信息,可以进行连贯操作
@param string $param 是成员属性数组config的下标
@param string $value 用于设置config下标对应的元素值
@return object 返回本对象自己$this, 用于连惯操作
*/
function set($param, $value){
if(array_key_exists($param, $this->config)){
$this->config[$param] = $value;
}
return $this;
}
/* 不是直接去调用,通过该方法,可以使用在对象外部直接获取私有成员属性limit和page的值 */
function __get($args){
if($args == limit || $args == page)
return $this->$args;
else
return null;
}
/**
按指定的格式输出分页
@param int 0-7的数字分别作为参数,用于自定义输出分页结构和调整结构的顺序,默认输出全部结构
@return string 分页信息内容
*/
function fpage(){
$arr = func_get_args();
$html[0] = 共 {$this->total} {$this->config[head]} ;
$html[1] = 本页 .$this->disnum(). 条 ;
$html[2] = 本页从 {$this->start()}-{$this->end()} 条 ;
$html[3] = {$this->page}/{$this->pagenum}页 ;
$html[4] = $this->firstprev();
$html[5] = $this->pagelist();
$html[6] = $this->nextlast();
$html[7] = $this->gopage();
$fpage = '
';
if(count($arr) $arr = array(0, 1,2,3,4,5,6,7);
for($i = 0; $i $fpage .= $html[$arr[$i]];
$fpage .= '
';
return $fpage;
}
/* 格式为 1,5,*/
function getlimit(){
if($this->page > 0)
return ($this->page-1)*$this->listrows., {$this->listrows};
else
return 0;
}
/* 在对象内部使用的私有方法,用于自动获取访问的当前url */
private function geturi($query){
$request_uri = $_server[request_uri];
$url = strstr($request_uri,'?') ? $request_uri : $request_uri.'?';
if(is_array($query))
$url .= http_build_query($query);
else if($query != )
$url .= &.trim($query, ?&);
$arr = parse_url($url);
if(isset($arr[query])){
parse_str($arr[query], $arrs);
unset($arrs[page]);
$url = $arr[path].'?'.http_build_query($arrs);
}
if(strstr($url, '?')) {
if(substr($url, -1)!='?')
$url = $url.'&';
}else{
$url = $url.'?';
}
return $url;
}
/* 在对象内部使用的私有方法,用于获取当前页开始的记录数 */
private function start(){
if($this->total == 0)
return 0;
else
return ($this->page-1) * $this->listrows+1;
}
/* 在对象内部使用的私有方法,用于获取当前页结束的记录数 */
private function end(){
return min($this->page * $this->listrows, $this->total);
}
/* 在对象内部使用的私有方法,用于获取上一页和首页的操作信息 */
private function firstprev(){
if($this->page > 1) {
$str = uri}page=1'>{$this->config[first]} ;
$str .= uri}page=.($this->page-1).'>{$this->config[prev]} ;
return $str;
}
}
/* 在对象内部使用的私有方法,用于获取页数列表信息 */
private function pagelist(){
$linkpage = ;
$inum = floor($this->listnum/2);
/*当前页前面的列表 */
for($i = $inum; $i >= 1; $i--){
$page = $this->page-$i;
if($page >= 1)
$linkpage .= uri}page={$page}'>{$page} ;
}
/*当前页的信息 */
if($this->pagenum > 1)
$linkpage .= {$this->page} ;
/*当前页后面的列表 */
for($i=1; $i $page = $this->page+$i;
if($page pagenum)
$linkpage .= uri}page={$page}'>{$page} ;
else
break;
}
$linkpage .= '';
return $linkpage;
}
/* 在对象内部使用的私有方法,获取下一页和尾页的操作信息 */
private function nextlast(){
if($this->page != $this->pagenum) {
$str = uri}page=.($this->page+1).'>{$this->config[next]} ;
$str .= uri}page=.($this->pagenum).'>{$this->config[last]} ;
return $str;
}
}
/* 在对象内部使用的私有方法,用于显示和处理表单跳转页面 */
private function gopage(){
if($this->pagenum > 1) {
return ' '.$this->pagenum.')?'.$this->pagenum.':this.value;location=\''.$this->uri.'page=\'+page+\'\'} value='.$this->page.'>'.$this->pagenum.')?'.$this->pagenum.':this.previoussibling.value;location=\''.$this->uri.'page=\'+page+\'\'> ';
}
}
/* 在对象内部使用的私有方法,用于获取本页显示的记录条数 */
private function disnum(){
if($this->total > 0){
return $this->end()-$this->start()+1;
}else{
return 0;
}
}
}
条记录,
'prev' => 上一页,
'next' => 下一页,
'first'=> 首页,
'last' => 末页
); //在分页信息中显示内容,可以自己通过set()方法设置
private $listnum = 10; //默认分页列表显示的个数
/**
构造方法,可以设置分页类的属性
@param int $total 计算分页的总记录数
@param int $listrows 可选的,设置每页需要显示的记录数,默认为25条
@param mixed $query 可选的,为向目标页面传递参数,可以是数组,也可以是查询字符串格式
@param bool $ord 可选的,默认值为true, 页面从第一页开始显示,false则为最后一页
*/
public function __construct($total, $listrows=25, $query=, $ord=true){
$this->total = $total;
$this->listrows = $listrows;
$this->uri = $this->geturi($query);
$this->pagenum = ceil($this->total / $this->listrows);
/*以下判断用来设置当前面*/
if(!empty($_get[page])) {
$page = $_get[page];
}else{
if($ord)
$page = 1;
else
$page = $this->pagenum;
}
if($total > 0) {
if(preg_match('/\d/', $page) ){
$this->page = 1;
}else{
$this->page = $page;
}
}else{
$this->page = 0;
}
$this->limit = limit .$this->getlimit();
}
/**
用于设置显示分页的信息,可以进行连贯操作
@param string $param 是成员属性数组config的下标
@param string $value 用于设置config下标对应的元素值
@return object 返回本对象自己$this, 用于连惯操作
*/
function set($param, $value){
if(array_key_exists($param, $this->config)){
$this->config[$param] = $value;
}
return $this;
}
/* 不是直接去调用,通过该方法,可以使用在对象外部直接获取私有成员属性limit和page的值 */
function __get($args){
if($args == limit || $args == page)
return $this->$args;
else
return null;
}
/**
按指定的格式输出分页
@param int 0-7的数字分别作为参数,用于自定义输出分页结构和调整结构的顺序,默认输出全部结构
@return string 分页信息内容
*/
function fpage(){
$arr = func_get_args();
$html[0] = 共 {$this->total} {$this->config[head]} ;
$html[1] = 本页 .$this->disnum(). 条 ;
$html[2] = 本页从 {$this->start()}-{$this->end()} 条 ;
$html[3] = {$this->page}/{$this->pagenum}页 ;
$html[4] = $this->firstprev();
$html[5] = $this->pagelist();
$html[6] = $this->nextlast();
$html[7] = $this->gopage();
$fpage = '
';
if(count($arr) $arr = array(0, 1,2,3,4,5,6,7);
for($i = 0; $i $fpage .= $html[$arr[$i]];
$fpage .= '
';
return $fpage;
}
/* 格式为 1,5,*/
function getlimit(){
if($this->page > 0)
return ($this->page-1)*$this->listrows., {$this->listrows};
else
return 0;
} /* 在对象内部使用的私有方法,用于自动获取访问的当前url */
private function geturi($query){
$request_uri = $_server[request_uri];
$url = strstr($request_uri,'?') ? $request_uri : $request_uri.'?';
if(is_array($query))
$url .= http_build_query($query);
else if($query != )
$url .= &.trim($query, ?&);
$arr = parse_url($url);
if(isset($arr[query])){
parse_str($arr[query], $arrs);
unset($arrs[page]);
$url = $arr[path].'?'.http_build_query($arrs);
}
if(strstr($url, '?')) {
if(substr($url, -1)!='?')
$url = $url.'&';
}else{
$url = $url.'?';
}
return $url;
}
/* 在对象内部使用的私有方法,用于获取当前页开始的记录数 */
private function start(){
if($this->total == 0)
return 0;
else
return ($this->page-1) * $this->listrows+1;
}
/* 在对象内部使用的私有方法,用于获取当前页结束的记录数 */
private function end(){
return min($this->page * $this->listrows, $this->total);
}
/* 在对象内部使用的私有方法,用于获取上一页和首页的操作信息 */
private function firstprev(){
if($this->page > 1) {
$str = uri}page=1'>{$this->config[first]} ;
$str .= uri}page=.($this->page-1).'>{$this->config[prev]} ;
return $str;
}
}
/* 在对象内部使用的私有方法,用于获取页数列表信息 */
private function pagelist(){
$linkpage = ;
$inum = floor($this->listnum/2);
/*当前页前面的列表 */
for($i = $inum; $i >= 1; $i--){
$page = $this->page-$i;
if($page >= 1)
$linkpage .= uri}page={$page}'>{$page} ;
}
/*当前页的信息 */
if($this->pagenum > 1)
$linkpage .= {$this->page} ;
/*当前页后面的列表 */
for($i=1; $i $page = $this->page+$i;
if($page pagenum)
$linkpage .= uri}page={$page}'>{$page} ;
else
break;
}
$linkpage .= '';
return $linkpage;
}
/* 在对象内部使用的私有方法,获取下一页和尾页的操作信息 */
private function nextlast(){
if($this->page != $this->pagenum) {
$str = uri}page=.($this->page+1).'>{$this->config[next]} ;
$str .= uri}page=.($this->pagenum).'>{$this->config[last]} ;
return $str;
}
}
/* 在对象内部使用的私有方法,用于显示和处理表单跳转页面 */
private function gopage(){
if($this->pagenum > 1) {
return ' '.$this->pagenum.')?'.$this->pagenum.':this.value;location=\''.$this->uri.'page=\'+page+\'\'} value='.$this->page.'>'.$this->pagenum.')?'.$this->pagenum.':this.previoussibling.value;location=\''.$this->uri.'page=\'+page+\'\'> ';
}
}
/* 在对象内部使用的私有方法,用于获取本页显示的记录条数 */
private function disnum(){
if($this->total > 0){
return $this->end()-$this->start()+1;
}else{
return 0;
}
}
}
这是一个很强大的分页类噢.虽然样子丑了点,不过,可以改造一下哩
mysql.class.php呢我修改了一下 limit方法,使他可以支持一个参数的,和两个参数的,更方便操作了
[php] public function limit($offset,$length=null){
if (is_null($length)) {
$this->query_list['limit']='limit '.$offset;
return $this;
}else {
if(!isset($length)){
$length = $offset;
$offset = 0;
}
$this->query_list['limit'] = 'limit '.$offset.','.$length;
return $this;
}
public function limit($offset,$length=null){
if (is_null($length)) {
$this->query_list['limit']='limit '.$offset;
return $this;
}else {
if(!isset($length)){
$length = $offset;
$offset = 0;
}
$this->query_list['limit'] = 'limit '.$offset.','.$length;
return $this;
}
还学会了设置时区.
[php] date_default_timezone_set(prc); //设置时区(中国
date_default_timezone_set(prc); //设置时区(中国
修改了 mytpl.class.php 模板引擎,不会造成溢出什么的了
[php] '; //在模板中嵌入动态数据变量的右定界符号
private $tpl_vars = array(); //内部使用的临时变量
/**
将php中分配的值会保存到成员属性$tpl_vars中,用于将板中对应的变量进行替换
@param string $tpl_var 需要一个字符串参数作为关联数组下标,要和模板中的变量名对应
@param mixed $value 需要一个标量类型的值,用来分配给模板中变量的值
*/
function assign($tpl_var, $value = null) {
if ($tpl_var != ''){
$globals[$tpl_var] = $value;
$this->tpl_vars[$tpl_var] = $value;
}
}
/**
加载指定目录下的模板文件,并将替换后的内容生成组合文件存放到另一个指定目录下
@param string $filename 提供模板文件的文件名
*/
function display($filename) {
/* 到指定的目录中寻找模板文件 */
$tplfile = $this->template_dir.'/'.$filename;
/* 如果需要处理的模板文件不存在,则退出并报告错误 */
if(!file_exists($tplfile)) {
die(模板文件{$tplfile}不存在!);
}
/* 获取组合的模板文件,该文件中的内容都是被替换过的 */
$filenamemd5 = md5($filename);
$comfilename = $this->compile_dir./com_.$filenamemd5.'.php';
/* 判断替换后的文件是否存在或是存在但有改动,都需要重新创建 */
if(!file_exists($comfilename) || filemtime($comfilename) /* 调用内部替换模板方法 */
$repcontent = $this->tpl_replace(file_get_contents($tplfile));
/* 保存由系统组合后的脚本文件 */
file_put_contents($comfilename, $repcontent);
}
/* 包含处理后的模板文件输出给客户端 */
include($comfilename);
}
/**
内部使用的私有方法,使用正则表达式将模板文件''中的语句替换为对应的值或php代码
@param string $content 提供从模板文件中读入的全部内容字符串
@return $repcontent 返回替换后的字符串
*/
private function tpl_replace($content) {
/* 将左右定界符号中,有影响正则的特殊符号转义 例如,转义\ */
$left = preg_quote($this->left_delimiter, '/');
$right = preg_quote($this->right_delimiter, '/');
/* 匹配模板中各种标识符的正则表达式的模式数组 */
$pattern = array(
/* 匹配模板中变量 ,例如, */
'/'.$left.'\s*\$([a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]*)\s*'.$right.'/i',
/* 匹配模板中if标识符,例如 */
'/'.$left.'\s*if\s*(.+?)\s*'.$right.'(.+?)'.$left.'\s*\/if\s*'.$right.'/ies',
/* 匹配elseif标识符, 例如 */
'/'.$left.'\s*else\s*if\s*(.+?)\s*'.$right.'/ies',
/* 匹配else标识符, 例如 */
'/'.$left.'\s*else\s*'.$right.'/is',
/* 用来匹配模板中的loop标识符,用来遍历数组中的值, 例如 */
'/'.$left.'\s*loop\s+\$(\s+)\s+\$([a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]*)\s*'.$right.'(.+?)'.$left.'\s*\/loop\s*'.$right.'/is',
/* 用来遍历数组中的键和值,例如 $value }> */
'/'.$left.'\s*loop\s+\$(\s+)\s+\$([a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]*)\s*=>\s*\$(\s+)\s*'.$right.'(.+?)'.$left.'\s*\/loop \s*'.$right.'/is',
/* 匹配include标识符, 例如,'' */
'/'.$left.'\s*include\s+[\\']?(.+?)[\\']?\s*'.$right.'/ie'
);
/* 替换从模板中使用正则表达式匹配到的字符串数组 */
$replacement = array(
/* 替换模板中的变量 tpl_vars[var]; */
'tpl_vars[${1}]; ?>',
/* 替换模板中的if字符串 */
'$this->stripvtags(\'\',\'${2}\')',
/* 替换elseif的字符串 */
'$this->stripvtags(\'\',)',
/* 替换else的字符串 */
'',
/* 以下两条用来替换模板中的loop标识符为foreach格式 */
'tpl_vars[${1}] as $this->tpl_vars[${2}]) { ?>${3}',
'tpl_vars[${1}] as $this->tpl_vars[${2}] => $this->tpl_vars[${3}]) { ?>${4}',
/*替换include的字符串*/
'file_get_contents($this->template_dir./'.$globals['classname'].'/${1})'
);
/* 使用正则替换函数处理 */
$s_content=$content;
$repcontent = preg_replace($pattern, $replacement, $content);
/* 如果还有要替换的标识,递归调用自己再次替换 */
if(preg_match('/'.$left.'([^('.$right.')]{1,})'.$right.'/', $repcontent)) {
if($s_content==$content) {
$repcontent = $this->tpl_replace($repcontent);
}
}
/* 返回替换后的字符串 */
return $repcontent;
}
/**
内部使用的私有方法,用来将条件语句中使用的变量替换为对应的值
@param string $expr 提供模板中条件语句的开始标记