基于SS框架的留言本前台控制器

来源:互联网 发布:威斯特伐利亚和约知乎 编辑:程序博客网 时间:2024/06/05 00:07

备用

<?php/** * Title:Gues.ct.php * Description:前台控制器 * @author:Jiangbin - zhangjb@shengshi.com.cn * Date:2012-2-20 */ require_once($_SERVER["DOCUMENT_ROOT"]."/require/global.fun.php");_IMPORT_DB("CDSGues_users","abc");_IMPORT_DB("CDSGues_posts","abc");class _CCTGues extends CController{var $ip;public function __init(){$this->set_page_base("abc");return array(_METHOD('index',array(),false,false),_METHOD('add',array(),false,false),_METHOD('search',array("key"),false,false),_METHOD('detail',array("pid"),false,false),);}function __ready(){$this->ip             = $this->GetIP();$this->page_title     = "Guestbook";_S("page_title", $this->page_title);return true;}function index(){$rt = array();$rt1 = array();$cds = new CDSGues_posts();$count = $cds->count();$page = _P('page');$per_page = 5; //每页记录数$maxpage = ceil($count/$per_page);$page<1 && $page=1;$page>$maxpage && $page=$maxpage;$cds->set_limit($page,$per_page);$cds->set_order_by(array("pid" => "DESC"));$rt = $cds->select(_EQ("parent_id", 0));   //输出父id为0,也就是所有的留言foreach($rt as $key=>$value){$v = $value['pid'];$rt1[$v] = $cds->select(_EQ("parent_id", $v));  //留言的回复}//echo $cds->get_sql();_S("count",$count);_S("page",$page);_S("per_page",$per_page);_S("rt", $rt);_S("rt1", $rt1);if($_GET['ver']=="php"){$this->set_page(false);$this->warning("php版本".phpversion());}}/** * @date:2012-2-22 * @description:添加留言 */function add(){$this->set_page(false);$htmlData = '';if (!empty($_POST['message'])){if (get_magic_quotes_gpc()){$htmlData = stripslashes($_POST['message']);}else{$htmlData = $_POST['message'];}}$data = array('message'   => $htmlData,'parent_id' => '0',);$cds = new CDSGues_posts();if($data['message']){$cds->set_message($data['message']);$cds->set_addtime(date("Y-m-d h:i:s"));$cds->set_addip($this->ip);$cds->set_parent_id($data['parent_id']);$cds->insert();$this->warning("Insert Success!");return false;}else{//echo "Insert Fail!";}}/** * @date:2012-2-23 * @parma: integer $key * @description:搜索留言 */function search($key){//$this->set_page(false);$key = trim(_P('key'));   //关键字if($key == ""){$this->warning("请输入关键字!", "/abc/gues/");return false; }else{$keyword = "'%".$key."%'";$cds  = new CDSGues_posts();$data = array();$data = $cds->execsql("SELECT * FROM gues_posts WHERE `message` LIKE ".$keyword);//print_r($data);//echo $cds->get_sql();//exit();if(count($data) != 0){_S("data", $data);}else{$this->error(0, "not found!");return false;}}return true;}/** * @date:2012-2-24 * @parma: integer $pid * @description:留言详细 */function detail($pid){if(!$pid){$this->error(1, "缺少参数!");return false;}$bg = new CDSGues_posts();$bg->set_order_by(array("pid" => 'DESC'));if($bg->select(_EQ("pid", $pid))){_S('bg', $bg);}}function GetIP(){if ($_SERVER["HTTP_X_FORWARDED_FOR"])$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];else if ($_SERVER["HTTP_CLIENT_IP"])$ip = $_SERVER["HTTP_CLIENT_IP"];else if ($_SERVER["REMOTE_ADDR"])$ip = $_SERVER["REMOTE_ADDR"];else if (getenv("HTTP_X_FORWARDED_FOR"))$ip = getenv("HTTP_X_FORWARDED_FOR");else if (getenv("HTTP_CLIENT_IP"))$ip = getenv("HTTP_CLIENT_IP");else if (getenv("REMOTE_ADDR"))$ip = getenv("REMOTE_ADDR");else$ip = "Unknown";return $ip;}function error($code, $message){ echo "error:($code) $message";return false;}private function warning($str, $url = '/abc/gues/'){echo "<script type='text/javascript'>alert('".$str."');location.href='".$url."';</script>";return false;}function __finally(){}}?>


原创粉丝点击