/Core/spController.php
http://speedphp.googlecode.com/ · PHP · 259 lines · 127 code · 23 blank · 109 comment · 28 complexity · 00ce166b2646efb83f4ce22240c74b01 MD5 · raw file
- <?php
- /////////////////////////////////////////////////////////////////
- // SpeedPHP??PHP??, Copyright (C) 2008 - 2010 SpeedPHP.com //
- /////////////////////////////////////////////////////////////////
-
- /**
- * spController ????????? ??????????????????spController
- */
- class spController {
-
- /**
- * ????
- */
- public $v;
-
- /**
- * ????????
- */
- private $__template_vals = array();
-
- /**
- * ????
- */
- public function __construct()
- {
- if(TRUE == $GLOBALS['G_SP']['view']['enabled']){
- $this->v = spClass('spView');
- }
- }
-
- /**
- *
- * ????
- *
- * ???????????????????????????
- *
- * @param $url ???????
- * @param $delay ????
- */
- public function jump($url, $delay = 0){
- echo "<html><head><meta http-equiv='refresh' content='{$delay};url={$url}'></head><body></body></html>";
- exit;
- }
-
- /**
- *
- * ??????
- *
- * ???????????????????????????
- *
- * @param $msg ???????????
- * @param $url ????
- */
- public function error($msg, $url = ''){
- $url = empty($url) ? "window.history.back();" : "location.href=\"{$url}\";";
- echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><script>function sptips(){alert(\"{$msg}\");{$url}}</script></head><body onload=\"sptips()\"></body></html>";
- exit;
- }
-
- /**
- *
- * ??????
- *
- * ???????????????????????????
- *
- * @param $msg ???????????
- * @param $url ????
- */
- public function success($msg, $url = ''){
- $url = empty($url) ? "window.history.back();" : "location.href=\"{$url}\";";
- echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><script>function sptips(){alert(\"{$msg}\");{$url}}</script></head><body onload=\"sptips()\"></body></html>";
- exit;
- }
-
- /**
- * ????????????????
- */
- public function __set($name, $value)
- {
- if(TRUE == $GLOBALS['G_SP']['view']['enabled'] && false !== $value){
- $this->v->engine->assign(array($name=>$value));
- }
- $this->__template_vals[$name] = $value;
- }
-
-
- /**
- * ??????????????
- */
- public function __get($name)
- {
- return $this->__template_vals[$name];
- }
-
- /**
- * ????
- *
- * @param $tplname ???????
- * @param $output ????????????FALSE???HTML????
- */
- public function display($tplname, $output = TRUE)
- {
- @ob_start();
- if(TRUE == $GLOBALS['G_SP']['view']['enabled']){
- $this->v->display($tplname);
- }else{
- extract($this->__template_vals);
- require($tplname);
- }
- if( TRUE != $output )return ob_get_clean();
- }
-
- /**
- * ??????
- * @param tplname ??????
- */
- public function auto_display($tplname)
- {
- if( TRUE != $this->v->displayed && FALSE != $GLOBALS['G_SP']['view']['auto_display']){
- if( method_exists($this->v->engine, 'templateExists') && TRUE == $this->v->engine->templateExists($tplname))$this->display($tplname);
- }
- }
-
- /**
- * ???????????????????
- */
- public function __call($name, $args)
- {
- if(in_array($name, $GLOBALS['G_SP']["auto_load_controller"])){
- return spClass($name)->__input($args);
- }elseif(!method_exists( $this, $name )){
- spError("?? {$name}????<br />?????????(".get_class($this).")?????????");
- }
- }
-
- /**
- * ????????
- */
- public function getView()
- {
- $this->v->addfuncs();
- return $this->v->engine;
- }
- /**
- * ?????????
- * @param $lang ????
- */
- public function setLang($lang)
- {
- if( array_key_exists($lang, $GLOBALS['G_SP']["lang"]) ){
- @ob_start();
- $domain = ('www.' == substr($_SERVER["HTTP_HOST"],0,4)) ? substr($_SERVER["HTTP_HOST"],4) : $_SERVER["HTTP_HOST"];
- setcookie($GLOBALS['G_SP']['sp_app_id']."_SpLangCookies", $lang, time()+31536000, '/', $domain ); // ????
- $_SESSION[$GLOBALS['G_SP']['sp_app_id']."_SpLangSession"] = $lang;
- return TRUE;
- }
- return FALSE;
- }
- /**
- * ?????????
- */
- public function getLang()
- {
- if( !isset($_COOKIE[$GLOBALS['G_SP']['sp_app_id']."_SpLangCookies"]) )return $_SESSION[$GLOBALS['G_SP']['sp_app_id']."_SpLangSession"];
- return $_COOKIE[$GLOBALS['G_SP']['sp_app_id']."_SpLangCookies"];
- }
- }
-
- /**
- * spArgs
- * ???????
- * spArgs????$_GET/$_POST?$_COOKIE????????????????
- * ????????
- */
-
- class spArgs {
- /**
- * ?????????
- */
- private $args = null;
-
- /**
- * ????
- *
- */
- public function __construct(){
- $this->args = $_REQUEST;
- }
-
- /**
- * ???????????????????????????
- *
- * @param name ???????????????????????
- * @param default ?????????????????????
- * @param method ???????GET?POST?COOKIE
- */
- public function get($name = null, $default = FALSE, $method = null)
- {
- if(null != $name){
- if( $this->has($name) ){
- if( null != $method ){
- switch (strtolower($method)) {
- case 'get':
- return $_GET[$name];
- case 'post':
- return $_POST[$name];
- case 'cookie':
- return $_COOKIE[$name];
- }
- }
- return $this->args[$name];
- }else{
- return (FALSE === $default) ? FALSE : $default;
- }
- }else{
- return $this->args;
- }
- }
-
- /**
- * ???????????????????????????
- *
- * @param name ??????
- * @param value ?????
- */
- public function set($name, $value)
- {
- $this->args[$name] = $value;
- }
-
- /**
- * ????????
- *
- * @param name ??????????
- */
- public function has($name)
- {
- return isset($this->args[$name]);
- }
-
- /**
- * ???????????
- * @param args ?????????
- */
- public function __input($args = -1)
- {
- if( -1 == $args )return $this;
- @list( $name, $default, $method ) = $args;
- return $this->get($name, $default, $method);
- }
-
- /**
- * ??????
- */
- public function request(){
- return $_SERVER["QUERY_STRING"];
- }
- }