PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Core/spController.php

http://speedphp.googlecode.com/
PHP | 259 lines | 127 code | 23 blank | 109 comment | 28 complexity | 00ce166b2646efb83f4ce22240c74b01 MD5 | raw file
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. // SpeedPHP??PHP??, Copyright (C) 2008 - 2010 SpeedPHP.com //
  4. /////////////////////////////////////////////////////////////////
  5. /**
  6. * spController ????????? ??????????????????spController
  7. */
  8. class spController {
  9. /**
  10. * ????
  11. */
  12. public $v;
  13. /**
  14. * ????????
  15. */
  16. private $__template_vals = array();
  17. /**
  18. * ????
  19. */
  20. public function __construct()
  21. {
  22. if(TRUE == $GLOBALS['G_SP']['view']['enabled']){
  23. $this->v = spClass('spView');
  24. }
  25. }
  26. /**
  27. *
  28. * ????
  29. *
  30. * ???????????????????????????
  31. *
  32. * @param $url ???????
  33. * @param $delay ????
  34. */
  35. public function jump($url, $delay = 0){
  36. echo "<html><head><meta http-equiv='refresh' content='{$delay};url={$url}'></head><body></body></html>";
  37. exit;
  38. }
  39. /**
  40. *
  41. * ??????
  42. *
  43. * ???????????????????????????
  44. *
  45. * @param $msg ???????????
  46. * @param $url ????
  47. */
  48. public function error($msg, $url = ''){
  49. $url = empty($url) ? "window.history.back();" : "location.href=\"{$url}\";";
  50. 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>";
  51. exit;
  52. }
  53. /**
  54. *
  55. * ??????
  56. *
  57. * ???????????????????????????
  58. *
  59. * @param $msg ???????????
  60. * @param $url ????
  61. */
  62. public function success($msg, $url = ''){
  63. $url = empty($url) ? "window.history.back();" : "location.href=\"{$url}\";";
  64. 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>";
  65. exit;
  66. }
  67. /**
  68. * ????????????????
  69. */
  70. public function __set($name, $value)
  71. {
  72. if(TRUE == $GLOBALS['G_SP']['view']['enabled'] && false !== $value){
  73. $this->v->engine->assign(array($name=>$value));
  74. }
  75. $this->__template_vals[$name] = $value;
  76. }
  77. /**
  78. * ??????????????
  79. */
  80. public function __get($name)
  81. {
  82. return $this->__template_vals[$name];
  83. }
  84. /**
  85. * ????
  86. *
  87. * @param $tplname ???????
  88. * @param $output ????????????FALSE???HTML????
  89. */
  90. public function display($tplname, $output = TRUE)
  91. {
  92. @ob_start();
  93. if(TRUE == $GLOBALS['G_SP']['view']['enabled']){
  94. $this->v->display($tplname);
  95. }else{
  96. extract($this->__template_vals);
  97. require($tplname);
  98. }
  99. if( TRUE != $output )return ob_get_clean();
  100. }
  101. /**
  102. * ??????
  103. * @param tplname ??????
  104. */
  105. public function auto_display($tplname)
  106. {
  107. if( TRUE != $this->v->displayed && FALSE != $GLOBALS['G_SP']['view']['auto_display']){
  108. if( method_exists($this->v->engine, 'templateExists') && TRUE == $this->v->engine->templateExists($tplname))$this->display($tplname);
  109. }
  110. }
  111. /**
  112. * ???????????????????
  113. */
  114. public function __call($name, $args)
  115. {
  116. if(in_array($name, $GLOBALS['G_SP']["auto_load_controller"])){
  117. return spClass($name)->__input($args);
  118. }elseif(!method_exists( $this, $name )){
  119. spError("?? {$name}????<br />?????????(".get_class($this).")?????????");
  120. }
  121. }
  122. /**
  123. * ????????
  124. */
  125. public function getView()
  126. {
  127. $this->v->addfuncs();
  128. return $this->v->engine;
  129. }
  130. /**
  131. * ?????????
  132. * @param $lang ????
  133. */
  134. public function setLang($lang)
  135. {
  136. if( array_key_exists($lang, $GLOBALS['G_SP']["lang"]) ){
  137. @ob_start();
  138. $domain = ('www.' == substr($_SERVER["HTTP_HOST"],0,4)) ? substr($_SERVER["HTTP_HOST"],4) : $_SERVER["HTTP_HOST"];
  139. setcookie($GLOBALS['G_SP']['sp_app_id']."_SpLangCookies", $lang, time()+31536000, '/', $domain ); // ????
  140. $_SESSION[$GLOBALS['G_SP']['sp_app_id']."_SpLangSession"] = $lang;
  141. return TRUE;
  142. }
  143. return FALSE;
  144. }
  145. /**
  146. * ?????????
  147. */
  148. public function getLang()
  149. {
  150. if( !isset($_COOKIE[$GLOBALS['G_SP']['sp_app_id']."_SpLangCookies"]) )return $_SESSION[$GLOBALS['G_SP']['sp_app_id']."_SpLangSession"];
  151. return $_COOKIE[$GLOBALS['G_SP']['sp_app_id']."_SpLangCookies"];
  152. }
  153. }
  154. /**
  155. * spArgs
  156. * ???????
  157. * spArgs????$_GET/$_POST?$_COOKIE????????????????
  158. * ????????
  159. */
  160. class spArgs {
  161. /**
  162. * ?????????
  163. */
  164. private $args = null;
  165. /**
  166. * ????
  167. *
  168. */
  169. public function __construct(){
  170. $this->args = $_REQUEST;
  171. }
  172. /**
  173. * ???????????????????????????
  174. *
  175. * @param name ???????????????????????
  176. * @param default ?????????????????????
  177. * @param method ???????GET?POST?COOKIE
  178. */
  179. public function get($name = null, $default = FALSE, $method = null)
  180. {
  181. if(null != $name){
  182. if( $this->has($name) ){
  183. if( null != $method ){
  184. switch (strtolower($method)) {
  185. case 'get':
  186. return $_GET[$name];
  187. case 'post':
  188. return $_POST[$name];
  189. case 'cookie':
  190. return $_COOKIE[$name];
  191. }
  192. }
  193. return $this->args[$name];
  194. }else{
  195. return (FALSE === $default) ? FALSE : $default;
  196. }
  197. }else{
  198. return $this->args;
  199. }
  200. }
  201. /**
  202. * ???????????????????????????
  203. *
  204. * @param name ??????
  205. * @param value ?????
  206. */
  207. public function set($name, $value)
  208. {
  209. $this->args[$name] = $value;
  210. }
  211. /**
  212. * ????????
  213. *
  214. * @param name ??????????
  215. */
  216. public function has($name)
  217. {
  218. return isset($this->args[$name]);
  219. }
  220. /**
  221. * ???????????
  222. * @param args ?????????
  223. */
  224. public function __input($args = -1)
  225. {
  226. if( -1 == $args )return $this;
  227. @list( $name, $default, $method ) = $args;
  228. return $this->get($name, $default, $method);
  229. }
  230. /**
  231. * ??????
  232. */
  233. public function request(){
  234. return $_SERVER["QUERY_STRING"];
  235. }
  236. }