function read_args($product_type, $category, $id) { # url example for this # http://yoursite.com/index.php?route=home/read_args/shirts/latest/100 echo '<strong>Here is how to read the url arguments:</strong><br /><br />'; // Direct Method echo "<strong>Direct Method:</strong><br /><br />"; echo $product_type . "<br />"; echo $category . "<br />"; echo $id . "<br /><br />"; // Indirect Methods echo "<strong>Indirect Methods:</strong><br />"; echo "<pre>"; echo '<br />--Method One--<br />'; // Method One echo $this->uri->parts[2] . '<br />'; echo $this->uri->parts[3] . '<br />'; echo $this->uri->parts[4] . '<br />'; echo '<br />--Method Two--<br />'; // Method Two echo $this->uri->part(2) . '<br />'; echo $this->uri->part(3) . '<br />'; echo $this->uri->part(4) . '<br />'; echo '<br />--Method Three--<br />'; // Method Three $args = ezphp::ez_get('arguments'); echo $args[0] . '<br />'; echo $args[1] . '<br />'; echo $args[2] . '<br />'; echo '<br />--Method Four--<br />'; // Method Four echo $this->shirts . '<br />'; echo $this->latest . '<br />'; echo $this->{100} . '<br />'; }
function do_clean_xss($is_image = false) { $file = $this->upload_path . $this->file_name; if (filesize($file) == 0) { return false; } if (($data = @file_get_contents($file)) === false) { return false; } if (!($fp = @fopen($file, 'r+b'))) { return false; } if ($is_image == true) { // short tags not processed for images for they contain it usually $data = str_replace(array('<?php', '<?PHP'), array('<?php', '<?PHP'), $data); } else { $input = ezphp::ez_get('input'); $data = $input->clean_xss($data); } flock($fp, LOCK_EX); fwrite($fp, $data); flock($fp, LOCK_UN); fclose($fp); }
private function parseURL() { $ezphp_config = setting::getInstance(); $path = ""; $route_path = empty($_GET['route']) ? '' : $_GET['route']; $route_path = trim($route_path, '/\\'); $route_path_len = strlen($route_path); if ($route_path_len > 1 && substr($route_path, -1) == '/') { $route_path = substr($route_path, 0, -1); } elseif ($route_path_len == 0) { $route_path = '/'; } //print $route_path;exit; // for routed urls start $routes = $ezphp_config->get['routes']; if (count($routes) > 0) { if (!in_array('/', array_keys($routes))) { $controller = $ezphp_config->get['application']['default_controller'] ? $ezphp_config->get['application']['default_controller'] : 'home'; $routes['/'] = $controller . '/index'; } foreach ($routes as $route => $uri) { if (strpos($route, ':') !== false) { $wildcard = array(':any', ':alphanum', ':num', ':alpha'); $regex = array('(.+)', '([a-z0-9]+)', '([0-9]+)', '([a-z]+)'); $route = str_replace($wildcard, $regex, $route); } if (preg_match('#^' . $route . '$#u', $route_path)) { if (strpos($uri, '$') !== false && strpos($route, '(') !== false) { // for regex routing $route_path = preg_replace('#^' . $route . '$#', $uri, $route_path); } else { // for normal routing $route_path = $uri; } // we found a valid route $lib_uri = ezphp::ez_get('uri'); $lib_uri->ruri = $route_path; $lib_uri->rparts = explode('/', $route_path); break; } } } // for routed urls end // filter bad/malacious urls // (not sure whether we really need this...) // $route_path = $this->filter_url($route_path); $parts = explode('/', str_replace('../', '', $route_path)); $path = __SITE_PATH . '/content/controllers/'; // Find right controller including sub-dirs foreach ($parts as $part) { $fullpath = $path . $part; // do we have dir? if (is_dir($fullpath)) { $path .= $part . '/'; array_shift($parts); continue; } // find the file if (is_file($fullpath . '.php')) { $this->__controller = $part; array_shift($parts); break; } } if (empty($this->__controller)) { if (@$parts[0]) { $this->__controller = $parts[0]; } } if (empty($this->__controller)) { # default controller $def_controller = $ezphp_config->get['application']['default_controller']; $this->__controller = $def_controller ? $def_controller : 'home'; } $method = ''; if (!empty($parts)) { $method = array_shift($parts); } $this->__action = !empty($method) ? $method : 'index'; $this->__args = $parts; # do we have the same suffix in url and config file? if (count($this->__args)) { if ($this->match_suffix(end($this->__args)) === false) { # show the 404 error page $this->error404(); return; } } if ($this->match_suffix($this->__action) === false || $this->match_suffix($this->__controller) === false) { # show the 404 error page $this->error404(); return; } ######################### # strip url suffix if any if (count($this->__args)) { foreach ($this->__args as $key => $value) { $this->__args[$key] = $this->clean_suffix($value); } } $this->__action = $this->clean_suffix($this->__action); $this->__controller = $this->clean_suffix($this->__controller); ################# # is this private action/function? $private = substr($this->__action, 0, 8); if (strtolower($private) === "private_") { # show the 404 error page $this->error404(); } else { $this->__file = $path . $this->__controller . '.php'; $this->__file = str_replace('../', '', $this->__file); } }
public function __get($index) { return ezphp::ez_get($index); }
<?php // include the core startup file require './core/startup.php'; // load the loader ezphp::ez_set('load', new load()); // load the router ezphp::ez_set('router', new router()); // load the model ezphp::ez_set('model', new model()); // load the view ezphp::ez_set('view', new view()); // dispatch the controller ezphp::ez_get('router')->dispatch(); ?>
function model($model, $object_name = '') { if (!strlen($model)) { return false; } if (ezphp::ez_get('mod_' . $model)) { return ezphp::ez_get('mod_' . $model); } elseif (isset(self::$mod_objects['mod_' . $model])) { return self::$mod_objects['mod_' . $model]; } /* // get the respective controller's path for the model if (strpos($model, '/') !== false) { global $router; $controller_path = $router->controllerPath(); $controller_path = substr(strrchr($controller_path, 'controllers'), 11); $model_path = str_ireplace(end(explode('/', $router->controllerPath())), '', $controller_path); $path = __SITE_PATH . '/content/models' . $model_path . $model . '.php'; } else { $path = __SITE_PATH . '/content/models/' . $model . '.php'; } */ $path = __SITE_PATH . '/content/models/' . $model . '.php'; $model_class = $model; // get class name from subdir-x if specified one if (strpos($model, '/') !== false) { $model_class = end(explode('/', $model)); $model = str_replace('/', '_', $model); $model = str_replace('\\', '_', $model); } $class = $model_class . '_model'; if (file_exists($path) === false) { throw new Exception('Model Not Found: ' . $path); return false; } // include the model class include $path; if (class_exists($class)) { $class_instance = new $class(); // make it global for use in Cs, Vs $ref_name = $model; if (strlen($object_name)) { $ref_name = $object_name; ezphp::ez_set($object_name, $class_instance); } else { ezphp::ez_set($model, $class_instance); } // for instance returning self::$mod_objects['mod_' . $ref_name] = $class_instance; ezphp::ez_set('mod_' . $ref_name, $class_instance); if (is_object($class_instance)) { return $class_instance; } else { exit('Could not instantiate the class: ' . __SITE_PATH . '/content/models/' . $model . '.php'); } } else { exit("<strong>Class could not be found: {$class}</strong>"); return false; } }
function render($view_name) { $path = __SITE_PATH . '/content/views/' . $view_name . '.php'; if (file_exists($path) === false || is_readable($path) === false) { throw new Exception('View Not Found In ' . $path); return false; } // set view path ezphp::ez_set('ez_view_path', dirname($path) . '/'); $this->view_path = dirname($path) . '/'; $this->vars['ez_view_path'] = dirname($path) . '/'; # load variables to views from controller extract($this->vars); // for cache $qstring = $_SERVER['QUERY_STRING']; $qstring = preg_replace("/[^a-zA-Z0-9_]+/", '_', $qstring); # cache the current file //if (__ENABLE_CACHE == '1' && !$this->cache->isCached($view_name . $qstring)) if (__ENABLE_CACHE == '1') { $cache_data = $this->getContent($path); $this->cache->set($view_name . $qstring, $cache_data); $file = glob(__SITE_PATH . '/cache/' . 'cache.' . $view_name . $qstring . '.*'); } if ($this->no_template == true || ezphp::ez_get('use_template') == '0') { $ez_layout_content = ''; if (__ENABLE_CACHE == '1') { if ($file[0]) { $handle = fopen($file[0], 'r') or die('Could not open the file: ' . $file[0]); $cache = fread($handle, filesize($file[0])); fclose($handle); print unserialize($cache); } } else { include $path; } if (!file_exists($file[0]) || !is_readable($file[0]) || empty($cache)) { include $path; } } else { if (__ENABLE_CACHE == '1') { $ez_layout_content = $this->cache->get($view_name . $qstring); } else { $ez_layout_content = $this->getContent($path); } if (empty($ez_layout_content)) { $ez_layout_content = $this->getContent($path); } // load the template file include_once __SITE_PATH . '/template/' . ezphp::get_template() . '/template.php'; } }
# get cache info $enable_cache = $ezphp_config->get['cache']['enable_cache']; if (!in_array($enable_cache, $possible_values)) { exit('[cache]<br /> enable_cache should have a value 0 or 1'); } define('__ENABLE_CACHE', $ezphp_config->get['cache']['enable_cache']); define('__CACHE_TIME', $ezphp_config->get['cache']['cache_lifetime']); // do we have to use the template in the first place ? $use_template = $ezphp_config->get['template']['use_template']; if (!in_array($use_template, $possible_values)) { exit('[template]<br /> use_template should have a value 0 or 1'); } ezphp::ez_set('use_template', $use_template); # get template name and path $template_dir = $ezphp_config->get['template']['template_dir']; if (ezphp::ez_get('use_template') == '1' && !strlen(trim($template_dir))) { exit('template directory needs to be specified in the config file !!'); } define('__TEMPLATE_PATH', './template/' . $template_dir . '/'); define('__FULL_PATH', __SITE_PATH . '/template/' . $template_dir . '/'); // set the template options ezphp::set_template($template_dir); ezphp::ez_set('ez_templath_path', __TEMPLATE_PATH); ezphp::ez_set('ez_full_path', __FULL_PATH); ezphp::ez_set('ez_template_name', $template_dir); ezphp::ez_set('ez_content_path', __SITE_PATH . '/content/'); ezphp::ez_set('ez_base_path', __SITE_PATH . '/'); # get database info $__use_db = $ezphp_config->get['database']['use_db']; if (!in_array($__use_db, $possible_values)) { exit('[security]<br /> use_db should have a value 0 or 1');
protected function __get($index) { return ezphp::ez_get($index); }