예제 #1
0
 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 />';
 }
예제 #2
0
 static function set_template($template_name)
 {
     self::$template_name = $template_name;
     return self::$template_name;
 }
예제 #3
0
 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('&lt;?php', '&lt;?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);
 }
예제 #4
0
파일: ezphp.php 프로젝트: alvarpoon/aeg
 public static function activate()
 {
     ezphp::init();
     // Nothing more at this time.
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
 public function __set($index, $value)
 {
     ezphp::ez_set($index, $value);
 }
예제 #7
0
<?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();
?>

예제 #8
0
 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;
     }
 }
예제 #9
0
 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';
     }
 }
예제 #10
0
function include_autoloads($autoloads)
{
    foreach ($autoloads as $autoload) {
        if (is_array($autoload)) {
            $class_name = $autoload[0];
            $args = $autoload;
            array_shift($args);
            // shift the first value eg class name
            $args = $args[0];
        } else {
            $class_name = $autoload;
        }
        $file = __SITE_PATH . '/classes/' . $class_name . '.php';
        if (file_exists($file) === true) {
            include $file;
            if (count($args) === 0) {
                ezphp::ez_set($class_name, new $class_name());
            } elseif (count($args) === 1) {
                if (is_array($args)) {
                    ezphp::ez_set($class_name, new $class_name($args[0]));
                } else {
                    ezphp::ez_set($class_name, new $class_name($args));
                }
            } elseif (count($args) > 1) {
                if (method_exists($class_name, '__construct') === false) {
                    exit("Constructor for the class <strong>{$class_name}</strong> does not exist, you should not pass arguments to this class or provide a constructor for it!");
                }
                $refMethod = new ReflectionMethod($class_name, '__construct');
                $params = $refMethod->getParameters();
                $re_args = array();
                foreach ($params as $key => $param) {
                    if ($param->isPassedByReference()) {
                        $re_args[$key] =& $args[$key];
                    } else {
                        $re_args[$key] = $args[$key];
                    }
                }
                $refClass = new ReflectionClass($class_name);
                ezphp::ez_set($class_name, $refClass->newInstanceArgs((array) $re_args));
            }
        }
    }
}
예제 #11
0
 protected function __set($index, $value)
 {
     ezphp::ez_set($index, $value);
 }