You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					118 lines
				
				3.9 KiB
			
		
		
			
		
	
	
					118 lines
				
				3.9 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								    include_once(dirname(__FILE__)."/library/publicBase.php");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    class run extends publicBase {
							 | 
						||
| 
								 | 
							
								        public $control_name;
							 | 
						||
| 
								 | 
							
								        public $control_func;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        public function __construct() {
							 | 
						||
| 
								 | 
							
								            $this->beforecheckpara();
							 | 
						||
| 
								 | 
							
								            $this->checkpara();
							 | 
						||
| 
								 | 
							
								            $this->action();
							 | 
						||
| 
								 | 
							
								            $this->display();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        private function beforecheckpara() {
							 | 
						||
| 
								 | 
							
								            $url = trim(trim($_GET['argv']), '/');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            $func_uri = explode('/', $url);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            $_GET['argv'] = 'api/_api_' . $url;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            $this->para['viewFormat'] = 'json';
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        private function checkpara() {
							 | 
						||
| 
								 | 
							
								            $argv = trim(trim($_GET['argv']),'/');
							 | 
						||
| 
								 | 
							
								            if(empty($argv)) {
							 | 
						||
| 
								 | 
							
								                $this->control_name = 'index';
							 | 
						||
| 
								 | 
							
								                $this->control_func = 'home';
							 | 
						||
| 
								 | 
							
								            } else {
							 | 
						||
| 
								 | 
							
								                $array = explode('/', $argv);
							 | 
						||
| 
								 | 
							
								                $this->control_name = $array[0];
							 | 
						||
| 
								 | 
							
								                $this->control_func = $array[1]=='' ? 'home' : $array[1];
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            // 还原GET
							 | 
						||
| 
								 | 
							
								            if(!empty($array)) {
							 | 
						||
| 
								 | 
							
								                unset($_GET['argv']);
							 | 
						||
| 
								 | 
							
								                unset($array[0]);
							 | 
						||
| 
								 | 
							
								                unset($array[1]);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								                $count = count($array);
							 | 
						||
| 
								 | 
							
								                for($i=1;$i<=$count/2;$i++) {
							 | 
						||
| 
								 | 
							
								                    $_GET[$array[$i*2]] = $array[$i*2+1];
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            // 如果URI带有常规传参形式,并入$_GET
							 | 
						||
| 
								 | 
							
								            $pos = strpos($_SERVER['REQUEST_URI'], '?');
							 | 
						||
| 
								 | 
							
								            if($pos!==false) {
							 | 
						||
| 
								 | 
							
								                $new_uri = substr($_SERVER['REQUEST_URI'], $pos+1);
							 | 
						||
| 
								 | 
							
								                $new_uri_arr = explode("&", $new_uri);
							 | 
						||
| 
								 | 
							
								                foreach($new_uri_arr as $v) {
							 | 
						||
| 
								 | 
							
								                    $new_para = explode("=", $v);
							 | 
						||
| 
								 | 
							
								                    $_GET[$new_para[0]] = $new_para[1];
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        private function action() {
							 | 
						||
| 
								 | 
							
								            $control_func = empty($this->control_func) ? 'home' : $this->control_func;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            // 判断控制层文件是否存在
							 | 
						||
| 
								 | 
							
								            $control_path = dirname(__FILE__).'/control/'.$this->control_name.'.php';
							 | 
						||
| 
								 | 
							
								            if(!file_exists($control_path)) {
							 | 
						||
| 
								 | 
							
								                die('/'.$this->control_name.'.php not exist.');
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            include_once ($control_path);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            // 判断控制层方法是否存在
							 | 
						||
| 
								 | 
							
								            $obj = new $this->control_name;
							 | 
						||
| 
								 | 
							
								            ##如下根据情况传递公共变量值##################
							 | 
						||
| 
								 | 
							
								            if (is_array($this->para)) {
							 | 
						||
| 
								 | 
							
								                foreach ($this->para as $k=>$v) {
							 | 
						||
| 
								 | 
							
								                    $func = 'set' . $k;
							 | 
						||
| 
								 | 
							
								                    $obj->$func($v);
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            ##如上根据情况传递公共变量值##################
							 | 
						||
| 
								 | 
							
								            if (method_exists($obj, $control_func)) {
							 | 
						||
| 
								 | 
							
								                $res = $obj->$control_func();
							 | 
						||
| 
								 | 
							
								            } else {
							 | 
						||
| 
								 | 
							
								                die('method '.$this->control_func.' not exist.');
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            if($obj->getViewFormat()=='json' && $res===false) {
							 | 
						||
| 
								 | 
							
								                echo urldecode($obj->getError());
							 | 
						||
| 
								 | 
							
								                exit;
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            $this->view = array_merge($this->view, $obj->getView());
							 | 
						||
| 
								 | 
							
								            $this->viewFormat = $obj->getViewFormat();
							 | 
						||
| 
								 | 
							
								            $this->viewTpl = $obj->getViewTpl();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        private function display() {
							 | 
						||
| 
								 | 
							
								            if($this->viewFormat=='json') {
							 | 
						||
| 
								 | 
							
								                $display = new DisplayJson();
							 | 
						||
| 
								 | 
							
								            } elseif($this->viewFormat=='string') {
							 | 
						||
| 
								 | 
							
								                $display = new DisplayNone();
							 | 
						||
| 
								 | 
							
								            } else {
							 | 
						||
| 
								 | 
							
								                $tpl_path = $this->viewTpl=='' ? $this->control_name.'/'.$this->control_func.'.html' : $this->viewTpl;
							 | 
						||
| 
								 | 
							
								                if(!file_exists(dirname(__FILE__) . '/view/templates/'.$tpl_path)) { // 判断模板是否存在
							 | 
						||
| 
								 | 
							
								                    die("{$tpl_path} not exist.");
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								                $display = new DisplaySmarty($tpl_path);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            $display->setView($this->view);
							 | 
						||
| 
								 | 
							
								            $display->execute();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    new run();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 |