/** * check if table is loaded, * if not, empty model is been used * and warning is printed */ public function is_ready_test() { if (!$this->ready) { ELog::warning("EModel without table has been used. Please fix this."); } return $this->ready; }
public static function load() { //treat url erasing extra parts $current_uri = $_SERVER['REQUEST_URI']; //keeping a local copy ERewriter::$oldurl = $current_uri; $matches = array(); foreach (EConfig::$data['rewrite'] as $key => $value) { if (!is_array($value)) { ELog::warning("You need to specify a second value as a rewrite rule in rewrite.conf.php"); return; } //handle with normal rewrite that //permits to have parameters if ($value[1] == "normal") { $pos = strpos($current_uri, $key); //if we found a rewrite rule that can be applied if ($pos !== false) { //rewrite only at the very start of the string if ($pos == 0) { //record the allowed key $matches[strlen($key)] = array($key, $value[0]); } } } else { if ($value[1] == "exact") { $current_uri_t = explode("?", $current_uri)[0]; if ($current_uri_t == $key) { if (ERewriter::$rewritable) { $rewritten = str_replace($key, $value[0], $current_uri); //TODO FIX HERE //$rewritten = preg_replace("$key", $value, $current_uri, 1); $_SERVER['REQUEST_URI'] = $rewritten; //setting rewritable to false ERewriter::$rewritable = false; break; } } } } } if (ERewriter::$rewritable) { ksort($matches); $matches = array_reverse(array_values($matches)); if (isset($matches[0])) { $rule = $matches[0]; $rewritten = str_replace($rule[0], $rule[1], $current_uri); //TODO FIX HERE FIRST OCCURRENCE //$rewritten = preg_replace("$key", $value, $current_uri, 1); $_SERVER['REQUEST_URI'] = $rewritten; } } }
public static function parse_file($filename) { //initializing empty array $result = array(); //mapping file line per line //$cache = new ECacheFile($filename); //$file = $cache->get(); //$file = explode("\n",$file); $file = file($filename); $file = EConfig::erase_php_code($file); foreach ($file as $line) { if (!empty($line)) { $chunks = explode("|", $line); //gives correct key and correct value, erasing line break. //control if is set more than once if (isset($result[$chunks[0]])) { //ELog::warning("<b>".$chunks[0]."</b> property is set more than once in ".$filename." config file!"); } else { //control if is set to empty value if (count($chunks) < 2) { ELog::warning("<b>" . $chunks[0] . "</b> property has empty value in " . $filename . " config file!"); } else { //load 1:1 data and gives a simple value if (count($chunks) == 2) { $result[$chunks[0]] = rtrim($chunks[1], "\n"); } else { //load 1:n data and gives an array if (count($chunks) > 2) { $data = array(); for ($i = 1; $i < count($chunks); $i++) { $data[] = rtrim($chunks[$i], "\n"); } $result[$chunks[0]] = $data; } else { ELog::error("unknown error in EConfig loading"); } } } } } } return $result; }
public static function render($url = "") { //setting default if (empty($url)) { $url = $_SERVER['REQUEST_URI']; } //getting correct input $uri = explode("?", $url); //ignoring all normal get part as for now $input = trim($uri[0], "/"); $chunks = explode("/", $input); if (isset($chunks[0])) { $controller = $chunks[0]; unset($chunks[0]); } if (isset($chunks[1])) { $method = $chunks[1]; unset($chunks[1]); } //building controller name $controller = ucfirst($controller) . "Controller"; $args = $chunks; $string_args = array(); //resetting array index and getting last element $args = array_values($args); $last = end($args); $extraargs = explode("?", $last); if (count($extraargs) >= 2) { unset($args[count($args) - 1]); //erase last raw unparsed element //add last element if (!empty($extraargs[1])) { $args[] = $extraargs[0]; } //manually injecting get data EHeaderDataParser::add_from_string($extraargs[1]); } /* TODO: reevaluate this //the final arrays cointains also the string version of the argument //eg. $args['save'] = 0; foreach($args as $arg){ $string_args[$arg] = 1; //just some random data } */ //checking if controller is available if (class_exists($controller)) { $current_controller = new $controller(); $current_controller->set_args($args); if (empty($method)) { if (method_exists($current_controller, 'index')) { $current_controller->index($chunks); } } else { if ($method[0] != '_') { //makes methods with _ not callable if (method_exists($current_controller, $method)) { $current_controller->{$method}($args); } else { ELog::warning($controller . "->" . $method . "() is not defined. Please define it."); } } } } else { ELog::warning($controller . " class is not defined. Please define it."); } }
public function get_last_raw_result() { if (!empty($this->last_raw_result)) { return $this->last_raw_result; } else { ELog::warning("no request performed"); return false; } }
/** * execute query on database * @param string $q * @return null */ public static function q($q) { if (EDatabase::$opened == true) { EDatabase::$queries += 1; $ret = mysqli_query(EDatabase::$db_link, $q); $error = mysqli_error(EDatabase::$db_link); if (empty($error)) { $ret = $ret; } else { ELog::warning($error . "<br>Query string: " . $q); } return $ret; } else { if (EDatabase::$debug == false) { ELog::warning("sql session not already opened!"); } } }