<?php 
// +----------------------------------------------------------------------
// 最便捷的php框架
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://www.ky53.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.ky53.net )
// +----------------------------------------------------------------------

/**
 
 * @author   qq:974005652(zhx626@126.com) by老顽童
 * @version  1.0
 +------------------------------------------------------------------------------
 */
final class Session {
	public $data = array();
			
  	public function __construct() {		
		if (!session_id()) {
			ini_set('session.use_cookies', 'On');
			ini_set('session.use_trans_sid', 'Off');
		
			session_set_cookie_params(0, '/');
			session_start();
		}
		
		$this->data =& $_SESSION;
	}
}
final class Cookie {	 
	public static  function set($name,$value,$time=0,$path='/',$host='',$secure=0,$httponly =0){
		if(!$host){
			$hosts=$_SERVER['HTTP_HOST'];
			$hostss=explode('.',$hosts);
			if(count($hostss)==3)$host=$hostss[1].'.'.$hostss[2];
			
			}
		if(!$time)$time=time()+3600*24*30;
		setcookie($name,$value,$time,$path,$host,$secure,$httponly);	
	}
	public static function remove($name){	
		setcookie($name,'');
	}
	public static function get($name=''){
		if($name)
			return $_COOKIE[$name];
		else
			return $_COOKIE;
	}
	
}
class data {//改造类

 
  function action(){

  }
  function model(){
  
  }
  function cache(){
  
  }
  





}
// +----------------------------------------------------------------------
// 最便捷的php框架
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://www.ky53.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.ky53.net )
// +----------------------------------------------------------------------

/**
 
 * @author   qq:974005652(zhx626@126.com) by老顽童
 * @version  1.0
 +------------------------------------------------------------------------------
 */
final class Pagination {
	public $total = 0;
	public $page = 1;
	public $limit = 20;
	public $num_links = 10;
	public $url = '';
	public $text = 'Showing {start} - {end} of {total} ({pages} Pages)';
	public $text_first = '|&lt;';
	public $text_last = '&gt;|';
	public $text_next = '&gt;';
	public $text_prev = '&lt;';
	public $style_links = 'links';
	public $style_results = 'results';
	public $style_html =false;	//false == admin ,true=catelog
	public $page_style='';
	 
	public function render() {
	
		$total = $this->total;
		if ($this->page < 1) {
			$page = 1;
		} else {
			$page = $this->page;
		}
		
		if (!$this->limit) {
			$limit = 10;
		} else {
			$limit = $this->limit;
		}
		$num_links = $this->num_links;
		$num_pages = ceil($total / $limit);
		
		$output = '';

		$Previous='上一页';$Next='下一页';
		
		if ($page > 1) {
		   
			if($this->style_html){	
				$output .= ' <li><a class="first" href="' . str_replace('{page}', 1, $this->url) . '">' . '<img src="'.__WEBURL__.'images/up.png">' . '</a> <a class="firstend" href="' . str_replace('{page}', $page - 1, $this->url) . '">' . '<img src="'.__WEBURL__.'images/upfirst.png">' . '</a> </li>';
				 if($this->page_style=='category'){$output_page .= ' <span ><a class="preon" href="' . str_replace('{page}', $page - 1, $this->url) . '">' . $Previous. '</a> </span>';}
			}else{
			
				$output .= ' <a href="' . str_replace('{page}', 1, $this->url) . '">' . $this->text_first . '</a> <a href="' . str_replace('{page}', $page - 1, $this->url) . '">' . $this->text_prev . '</a> ';
			}
    	}else{if($num_pages>1){ if($this->page_style=='category'){$output_page .= ' <span ><a class="pre">' . $Previous . '</a> </span>';}}}

		if ($num_pages > 1) {
			if ($num_pages <= $num_links) {
				$start = 1;
				$end = $num_pages;
			} else {
				$start = $page - floor($num_links / 2);
				$end = $page + floor($num_links / 2);
			
				if ($start < 1) {
					$end += abs($start) + 1;
					$start = 1;
				}
						
				if ($end > $num_pages) {
					$start -= ($end - $num_pages);
					$end = $num_pages;
				}
			}

			if ($start > 1) {
				//$output .= ' .... ';
			}

			for ($i = $start; $i <= $end; $i++) {
				
					if($this->style_html)	{
						if ($page == $i) {
						    if($this->page_style=='category'){$output_page .='<a  title=""  class="pageon">'.$i.'</a>';}//锟铰加凤拷锟斤拷页锟斤拷页2011/9/5 by laowantong
							$output .= '<li> <b>' . $i . '</b> </li>';
						} else {
							$output .= ' <li><a href="' . str_replace('{page}', $i, $this->url) . '">' . $i . '</a> </li>';
							 if($this->page_style=='category'){$output_page .='<a href="'. str_replace('{page}', $i, $this->url) .'" title="">'.$i.'</a>';}
						}
					}else{
						if ($page == $i) {
							$output .= ' <a href="javascript:;"><strong><font color="red">' . $i . '</font></strong></a> ';
						} else {
							$output .= ' <a href="' . str_replace('{page}', $i, $this->url) . '">' . $i . '</a> ';
						}
					}
					
			}
							
			if ($end < $num_pages) {
				//$output .= ' .... ';
			}
		}
		
   		if ($page < $num_pages) {
			if($this->style_html)	{
				$output .= ' <li><a class="next" href="' . str_replace('{page}', $page + 1, $this->url) . '">' . '<img src="'.__WEBURL__.'images/next.png">' . '</a> <a class="nextend" href="' . str_replace('{page}', $num_pages, $this->url) . '">' .  '<img src="'.__WEBURL__.'images/nextlast.png">' . '</a> </li>';
			if($this->page_style=='category'){$output_page .='<a  href="' . str_replace('{page}', $page + 1, $this->url) . '">' . '...' . '</a><a  href="' . str_replace('{page}', $num_pages, $this->url) . '">' . $num_pages . '</a><span class="pagebreak"></span>';}	
			 if($this->page_style=='category'){$output_page.='<span><a class="next" href="' . str_replace('{page}', $page + 1, $this->url) . '">' .  $Next . '</a></span>';}	
			}else{
				//$output .= ' <a href="' . str_replace('{page}', 1, $this->url) . '">' . $this->text_first . '</a> <a href="' . str_replace('{page}', $page - 1, $this->url) . '">' . $this->text_prev . '</a> ';
				$output .= ' <a href="' . str_replace('{page}', $page + 1, $this->url) . '">' . $this->text_next . '</a> <a href="' . str_replace('{page}', $num_pages, $this->url) . '">' . $this->text_last . '</a> ';
			}
		}else{ if($num_pages>1){if($this->page_style=='category'){$output_page.='<span><a class="nexton">' .  $Next . '</a></span>';}}}
		
		$find = array(
			'{start}',
			'{end}',
			'{total}',
			'{pages}'
		);
		
		$replace = array(
			($total) ? (($page - 1) * $limit) + 1 : 0,
			((($page - 1) * $limit) > ($total - $limit)) ? $total : ((($page - 1) * $limit) + $limit),
			$total, 
			$num_pages
		);
		
		if($this->style_html)	{
			
			
			 if($this->page_style=='category'){return $output_page;} else{return ($output ? '<div class="' . $this->style_links . '"><ul>'  . '<li class="' . $this->style_results . '">' . str_replace($find, $replace, $this->text) . '</li>'. $output . '</ul></div>' : '');}
		}else{
			return ($output ? '<div class="' . $this->style_links . '">' . $output . '</div>' : '') . '<div class="' . $this->style_results . '">' . str_replace($find, $replace, $this->text) . '</div>';
		}
	}
	public function renderTotal() {
		$total = $this->total;
		if ($this->page < 1) {
			$page = 1;
		} else {
			$page = $this->page;
		}
		
		if (!$this->limit) {
			$limit = 10;
		} else {
			$limit = $this->limit;
		}
		$num_links = $this->num_links;
		$num_pages = ceil($total / $limit);
		
		$output = '';
		
		if ($page > 1) {
			if($this->style_html){	
				$output .= ' <li><a class="first" href="' . str_replace('{page}', 1, $this->url) . '">' . '<img src="'.__WEBURL__.'images/up.png">' . '</a> <a class="firstend" href="' . str_replace('{page}', $page - 1, $this->url) . '">' . '<img src="'.__WEBURL__.'images/upfirst.png">' . '</a> </li>';
			}else{
				$output .= ' <a href="' . str_replace('{page}', 1, $this->url) . '">' . $this->text_first . '</a> <a href="' . str_replace('{page}', $page - 1, $this->url) . '">' . $this->text_prev . '</a> ';
			}
    	}

		if ($num_pages > 1) {
			if ($num_pages <= $num_links) {
				$start = 1;
				$end = $num_pages;
			} else {
				$start = $page - floor($num_links / 2);
				$end = $page + floor($num_links / 2);
			
				if ($start < 1) {
					$end += abs($start) + 1;
					$start = 1;
				}
						
				if ($end > $num_pages) {
					$start -= ($end - $num_pages);
					$end = $num_pages;
				}
			}

			if ($start > 1) {
				//$output .= ' .... ';
			}

			for ($i = $start; $i <= $end; $i++) {
				
					if($this->style_html)	{
						if ($page == $i) {
							$output .= '<li> <b>' . $i . '</b> </li>';
						} else {
							$output .= ' <li><a href="' . str_replace('{page}', $i, $this->url) . '">' . $i . '</a> </li>';
						}
					}else{
						if ($page == $i) {
							$output .= ' <a href="javascript:;"><strong><font color="red">' . $i . '</font></strong></a> ';
						} else {
							$output .= ' <a href="' . str_replace('{page}', $i, $this->url) . '">' . $i . '</a> ';
						}
					}
					
			}
							
			if ($end < $num_pages) {
				//$output .= ' .... ';
			}
		}
		
   		if ($page < $num_pages) {
			if($this->style_html)	{
				$output .= ' <li><a class="next" href="' . str_replace('{page}', $page + 1, $this->url) . '">' . '<img src="'.__WEBURL__.'images/next.png">' . '</a> <a class="nextend" href="' . str_replace('{page}', $num_pages, $this->url) . '">' .  '<img src="'.__WEBURL__.'images/nextlast.png">' . '</a> </li>';
			}else{
				//$output .= ' <a href="' . str_replace('{page}', 1, $this->url) . '">' . $this->text_first . '</a> <a href="' . str_replace('{page}', $page - 1, $this->url) . '">' . $this->text_prev . '</a> ';
				$output .= ' <a href="' . str_replace('{page}', $page + 1, $this->url) . '">' . $this->text_next . '</a> <a href="' . str_replace('{page}', $num_pages, $this->url) . '">' . $this->text_last . '</a> ';
			}
		}
		
		$find = array(
			'{start}',
			'{end}',
			'{total}',
			'{pages}'
		);
		
		$replace = array(
			($total) ? (($page - 1) * $limit) + 1 : 0,
			((($page - 1) * $limit) > ($total - $limit)) ? $total : ((($page - 1) * $limit) + $limit),
			$total, 
			$num_pages
		);
		
		if($this->style_html)	{
			return ($output ?  str_replace($find, $replace, $this->text)  : '');
		}else{
			return ($output ? '<div class="' . $this->style_links . '">' . $output . '</div>' : '') . '<div class="' . $this->style_results . '">' . str_replace($find, $replace, $this->text) . '</div>';
		}
	}
}

?>