File indexing completed on 2024-12-22 05:33:23
0001 <?php 0002 0003 /* 0004 * TRT GFX 3.0.1 (beta build) BackToSlash 0005 * 0006 * support: happy.snizzo@gmail.com 0007 * website: http://trt-gfx.googlecode.com 0008 * credits: Claudio Desideri 0009 * 0010 * This software is released under the MIT License. 0011 * http://opensource.org/licenses/mit-license.php 0012 */ 0013 0014 /* 0015 * 0016 */ 0017 0018 class EStructure { 0019 0020 private static $debug = false; 0021 0022 /* 0023 * Tries to render a method's controller 0024 */ 0025 public static function render($url="") 0026 { 0027 //setting default 0028 if(empty($url)){ 0029 $url = $_SERVER['REQUEST_URI']; 0030 } 0031 0032 //getting correct input 0033 $uri = explode("?", $url); //ignoring all normal get part as for now 0034 $input = trim($uri[0], "/"); 0035 $chunks = explode("/", $input); 0036 0037 if(isset($chunks[0])){ $controller = $chunks[0]; unset($chunks[0]); } 0038 if(isset($chunks[1])){ $method = $chunks[1]; unset($chunks[1]); } 0039 0040 //building controller name 0041 $controller = ucfirst($controller)."Controller"; 0042 0043 $args = $chunks; 0044 $string_args = array(); 0045 0046 //resetting array index and getting last element 0047 $args = array_values($args); 0048 $last = end($args); 0049 $extraargs = explode("?", $last); 0050 if(count($extraargs)>=2){ 0051 unset($args[count($args)-1]); //erase last raw unparsed element 0052 0053 //add last element 0054 if(!empty($extraargs[1])){ 0055 $args[] = $extraargs[0]; 0056 } 0057 0058 //manually injecting get data 0059 EHeaderDataParser::add_from_string($extraargs[1]); 0060 } 0061 0062 /* TODO: reevaluate this 0063 //the final arrays cointains also the string version of the argument 0064 //eg. $args['save'] = 0; 0065 foreach($args as $arg){ 0066 $string_args[$arg] = 1; //just some random data 0067 } 0068 */ 0069 0070 //checking if controller is available 0071 if (class_exists($controller)){ 0072 $current_controller = new $controller(); 0073 $current_controller->set_args($args); 0074 0075 if(empty($method)){ 0076 if(method_exists($current_controller, 'index')){ 0077 $current_controller->index($chunks); 0078 } 0079 } else { 0080 if($method[0]!='_'){ //makes methods with _ not callable 0081 if(method_exists($current_controller,$method)){ 0082 $current_controller->$method($args); 0083 } else { 0084 ELog::warning($controller."->".$method."() is not defined. Please define it."); 0085 } 0086 } 0087 } 0088 } else { 0089 ELog::warning($controller." class is not defined. Please define it."); 0090 } 0091 0092 } 0093 0094 /* 0095 * Used to load controllers inside other views. 0096 * $path contains relative url from views folder 0097 * [$args] contains data arguments that can be used 0098 * in view with data[0], data[1] etc... 0099 * inside view 0100 * 0101 * return void 0102 */ 0103 public static function controller($path){ 0104 echo "calling $path<br>"; 0105 } 0106 0107 /* 0108 * Used to load views from a controller and inside 0109 * other views. 0110 * $url contains relative url from views folder 0111 * [$args] contains data arguments that can be used 0112 * in view with data[0], data[1] etc... 0113 * inside view 0114 * 0115 * return void 0116 */ 0117 public static function view($url) 0118 { 0119 $numargs = func_num_args(); 0120 $arg_list = func_get_args(); 0121 $data = array(); 0122 0123 for ($i = 1; $i < $numargs; $i++) { 0124 $data[] = $arg_list[$i]; 0125 } 0126 0127 $filepath = ELoader::$views_path."/$url.views.php"; 0128 0129 if(file_exists($filepath)){ 0130 include(ELoader::$views_path."/$url.views.php"); 0131 } else { 0132 ELog::error("non-existent view included. Please define $filepath !"); 0133 } 0134 } 0135 0136 } 0137 0138 ?>