Exemple #1
0
 public function datarow($_table = null, $_id = null, $_metatable = false)
 {
     if (!$_table) {
         $_table = $this->module();
     }
     // if myid parameter set use it else use url parameter for myid
     if (!$_id) {
         $_id = $this->childparam();
     }
     $tmp_result = $this->sql()->table($_table)->where('id', $_id)->select();
     if ($tmp_result->num() == 1) {
         $tmp_result = $tmp_result->assoc();
         // add meta table rows as filed to datarow, can access via meta in datarow
         if ($_metatable) {
             $metas = $this->sql()->table('options')->where('post_id', $_id)->field('option_key', 'option_value', 'option_meta')->select()->allassoc();
             foreach ($metas as $key => $value) {
                 $myval = $value['option_meta'];
                 if (substr($myval, 0, 1) === '{') {
                     $myval = json_decode($myval, true);
                 }
                 $mykey = strtok($value['option_key'], '_');
                 $tmp_result['meta'][$mykey] = $myval;
             }
         }
         return $tmp_result;
     } elseif ($tmp_result->num() > 1) {
         \lib\error::access(T_("id is found 2 or more times. it's imposible!"));
     } else {
         \lib\error::access(T_("Url incorrect: id not found"));
         return false;
     }
     return null;
 }
Exemple #2
0
 public function pagnation_make($_total_records, $_length = null)
 {
     if (!$_length && !$this->pagnation_get('custom_length') && !$this->pagnation_get('length')) {
         \lib\error::internal("PAGENAMTION LENGTH NOTFOUND");
         return;
     } else {
         $length = $this->pagnation_get('length') ? $this->pagnation_get('length') : intval($_length);
     }
     $total_pages = intval(ceil($_total_records / $length));
     $current = $this->pagnation_get('current') ? $this->pagnation_get('current') : 1;
     $next = $current + 1;
     $prev = $current - 1;
     if ($current > $total_pages) {
         $this->pagnation_error();
     }
     $this->pagnation_set('total_pages', $total_pages);
     $this->pagnation_set('current', $current);
     $this->pagnation_set('next', $next <= $total_pages ? $next : false);
     $this->pagnation_set('prev', $prev >= 1 ? $prev : false);
     $this->pagnation_set('count_link', 7);
     $path = \lib\router::get_url() ? '/' . \lib\router::get_url() : null;
     if ($path === null) {
         $path = preg_replace("/\\/page\\=\\d+/", "", $_SERVER['REQUEST_URI']);
     }
     $current_url = $this->url('base') . $path;
     $this->pagnation_set('current_url', $this->pagnation_get('custom_length') ? $current_url . "/length={$length}" : $current_url);
     $this->pagnation_set('length', $length);
 }
Exemple #3
0
 public function mvc_inject_finder($_name, $_args, $_call)
 {
     $return = false;
     $method_exists = array_key_exists($_call, $this->Methods);
     $call_method_exists = method_exists($this, $_call);
     if (!$method_exists && !$call_method_exists) {
         \lib\error::internal(get_called_class() . "()->{$_name}()");
     }
     if ($method_exists && array_key_exists('before', $this->Methods[$_call])) {
         foreach ($this->Methods[$_call]['before'] as $key => $before_method) {
             $before_method(...$_args);
         }
     }
     if ($method_exists && array_key_exists('edit', $this->Methods[$_call])) {
         $edit_method = end($this->Methods[$_call]['edit']);
         $return = $edit_method(...$_args);
     } else {
         $return = call_user_func_array(array($this, $_call), $_args);
     }
     if ($method_exists && array_key_exists('after', $this->Methods[$_call])) {
         foreach ($this->Methods[$_call]['after'] as $key => $after_method) {
             $after_method(...$_args);
         }
     }
     return $return;
 }
Exemple #4
0
 function _route()
 {
     $canAccess = $this->option('account', 'meta', 'register');
     if ($canAccess) {
         $this->post('signup')->ALL();
     } else {
         \lib\error::access(T_("Public registration is disabled!"));
     }
 }
Exemple #5
0
 public function __call($name, $args)
 {
     $class_name = "lib\\{$name}";
     if (!class_exists($class_name)) {
         \lib\error::core("lib\\{$name}");
     } else {
         $class_name_valid = $class_name;
         return new $class_name_valid($args);
     }
 }
Exemple #6
0
 public function __call($name, $args)
 {
     $path = array("ilib", "lib");
     foreach ($path as $key => $value) {
         $class_name = "{$value}{$this->prefix}{$name}";
         if (class_exists($class_name)) {
             return new $class_name(...$args);
         }
     }
     \lib\error::core("lib\\{$name}");
 }
Exemple #7
0
 public function __call($name, $args)
 {
     $black = array("_construct", "corridor", "config");
     if (method_exists($this, '_call_corridor') && method_exists($this, '_call') && ($value = $this->_call_corridor($name, $args))) {
         return $this->_call($name, $args, $value);
     } elseif (isset($this->Methods[$name])) {
         return call_user_func_array($this->Methods[$name], $args);
     } elseif (method_exists($this->controller, $name) && !preg_grep("/^{$name}\$/", $black)) {
         return call_user_func_array(array($this->controller, $name), $args);
     }
     \lib\error::internal(get_called_class() . "->{$name}()");
 }
Exemple #8
0
 function _route()
 {
     // do for exception url
     self::_exception();
     // check permission
     self::_permission();
     // Restrict unwanted module
     if (!$this->cpModlueList()) {
         \lib\error::page(T_("Not found!"));
     }
     // Restrict unwanted child
     // if($mychild && !($mychild=='add' || $mychild=='edit' || $mychild=='delete' || $mychild=='list' || $mychild=='options'))
     // 	\lib\error::page(T_("Not found!"));
     $this->cpFindDisplay();
 }
Exemple #9
0
 function __construct($object = false)
 {
     parent::__construct($object);
     $settings = $this->option('account', null, false, $this);
     $mymodule = $this->module();
     $isValid = false;
     // // entire account part is disabled
     // if(isset($settings['status']) && !$settings['status'])
     // {
     // 	\lib\error::core('Disabled!');
     // }
     // check access permission to account
     // if user set passphrase for enter account
     if (isset($settings['meta']['passphrase']) && $settings['meta']['passphrase'] && $mymodule !== 'logout') {
         // if user set pass key
         if (isset($settings['meta']['passkey']) && $settings['meta']['passkey']) {
             // get pass key and save it in myphrase variable
             $myPassKey = $settings['meta']['passkey'];
             $myPassValue = \lib\utility::get($myPassKey);
             // if user not set pass value in get, then check cookie for it
             if ($myPassValue === null) {
                 $myPassValue = \lib\utility\cookie::read($myPassKey);
             }
             // if not set this passkey and incorrect
             if ($myPassValue === null) {
                 $isValid = false;
             } elseif (isset($settings['meta']['passvalue']) && $settings['meta']['passvalue']) {
                 // passvalue exist and equal
                 if ($settings['meta']['passvalue'] === $myPassValue) {
                     $isValid = true;
                 } else {
                     $isValid = false;
                 }
             } else {
                 $isValid = true;
             }
             // if can access set cookie
             if ($isValid) {
                 \lib\utility\cookie::write($myPassKey, $myPassValue, 60 * 60 * 24 * 7);
                 // allow 1week
             } else {
                 \lib\utility\cookie::delete($myPassKey);
                 \lib\error::login();
             }
         }
     }
 }
Exemple #10
0
 /**
  * return list of posts in custom term like cat or tag
  * @return [type] datarow
  */
 public function sp_postsInTerm($_limit = null)
 {
     $url = $this->url('path');
     if (substr($url, 0, 4) === 'tag/') {
         $url = substr($url, 4, $url);
     }
     if (substr($url, 0, 11) === 'book-index/') {
         preg_match("#^book-index/([^\\/]*)(.*)\$#", $url, $m);
         $url_raw = "book/{$m['1']}";
         if ($m[2] !== '') {
             $qry = $this->sql()->table('posts')->where('post_status', 'publish')->order('id', 'ASC');
             $qry->join('termusages')->on('termusage_id', '#posts.id')->and('termusage_foreign', '#"posts"');
             $qry->join('terms')->on('id', '#termusages.term_id')->and('term_url', $url)->groupby('#posts.id');
         } else {
             $parent_id = $this->sql()->table('posts')->where('post_url', $url_raw)->and('post_status', 'publish')->select()->assoc('id');
             $qry = $this->sql()->table('posts')->where('post_parent', $parent_id)->and('post_status', 'publish')->order('id', 'ASC');
         }
         return $qry->select()->allassoc();
     }
     $qry = $this->sql()->table('posts')->where('post_status', 'publish')->order('id', 'DESC');
     $qry->join('termusages')->on('termusage_id', '#posts.id')->and('termusage_foreign', '#"posts"')->field(false);
     $qry->join('terms')->on('id', '#termusages.term_id')->and('term_url', $url)->groupby('#posts.id')->field(false);
     // hasan :|
     $pagenation = [];
     if ($_limit) {
         $qryCount = clone $qry;
         $qryCount->field("#count(posts.id)");
         $count = $qryCount->select()->num();
         $pagenationPages = ceil($count / $_limit);
         $pagenationCurrent = \lib\router::get_storage("pagenation");
         $pagenationNext = \lib\router::get_storage("pagenation") + 1;
         $pagenationPrev = \lib\router::get_storage("pagenation") - 1;
         if ($pagenationCurrent !== null and $pagenationCurrent < 1 || $pagenationCurrent > $pagenationPages) {
             \lib\error::page(T_("Does not exist!"));
             return;
         }
         $pagenation = ["num_page" => $pagenationPages, "pages" => intval($pagenationPages), "current" => $pagenationCurrent == 0 ? 1 : intval($pagenationCurrent), "next" => $pagenationNext <= $pagenationPages ? $pagenationNext : false, "prev" => $pagenationPrev >= 1 ? $pagenationPrev : false, "count_link" => 7, "current_url" => \lib\router::get_url()];
         $start = \lib\router::get_storage("pagenation") ? (\lib\router::get_storage("pagenation") - 1) * $_limit : 0;
         $qry->limit($start, $_limit);
     }
     return ["pagenation" => $pagenation, "result" => $qry->select()->allassoc()];
 }
Exemple #11
0
 /**
  * check route of account
  * @return [type] [description]
  */
 function _route()
 {
     // exit();
     // \lib\debug::true("check", 'hi');
     // var_dump();
     $mymodule = $this->module();
     $referer = \lib\router::urlParser('referer', 'domain');
     $from = \lib\utility\cookie::read('from');
     $from = $from ? $from : \lib\utility::get('from');
     $islogin = $this->login();
     // set referrer in cookie
     if ($referer !== Domain) {
         \lib\utility\cookie::write('referer', $referer, 60 * 15);
     }
     // check permission for changepass
     if ($mymodule === 'changepass' && $from !== 'verification' && !$islogin) {
         \lib\error::access(T_("you can't access to this page!"));
     }
     switch ($mymodule) {
         case 'home':
             $this->redirector()->set_url("login")->redirect();
             break;
         case 'verification':
         case 'verificationsms':
             if ($from && $from !== 'recovery' && $from !== 'signup' && $from !== 'verification') {
                 \lib\error::access(T_("you can't access to this page!"));
             }
             $this->model_name = '\\addons\\content_account\\' . $mymodule . '\\model';
             $this->display_name = 'content_account\\' . $mymodule . '\\display.html';
             $this->post($mymodule)->ALL($mymodule);
             $this->get()->ALL($mymodule);
             break;
         case 'signup':
             return;
             /**
             
             Fix it later, only access if posible
             */
         /**
         
         Fix it later, only access if posible
         */
         case 'login':
         case 'recovery':
             if ($islogin) {
                 \lib\debug::true(T_("you are logined to system!"));
                 $myreferer = \lib\router::urlParser('referer', 'host');
                 $myssid = isset($_SESSION['ssid']) ? '?ssid=' . $_SESSION['ssid'] : null;
                 if (\lib\router::get_storage('CMS')) {
                     $this->redirector()->set_domain()->set_sub_domain(\lib\router::get_storage('CMS'))->set_url()->redirect();
                 } else {
                     $this->redirector()->set_domain()->set_url()->redirect();
                 }
             }
         case 'changepass':
             $this->model_name = '\\addons\\content_account\\' . $mymodule . '\\model';
             $this->display_name = 'content_account\\' . $mymodule . '\\display.html';
             $this->post($mymodule)->ALL($mymodule);
             $this->get()->ALL($mymodule);
             break;
         case 'smsdelivery':
         case 'smscallback':
             $uid = 201500001;
             if (\lib\utility::get('uid') == $uid || \lib\utility\cookie::read('uid') == $uid) {
                 $this->model_name = '\\addons\\content_account\\sms\\model';
                 $this->display_name = 'content_account\\sms\\display.html';
                 $this->post($mymodule)->ALL($mymodule);
                 $this->get($mymodule)->ALL($mymodule);
             } else {
                 \lib\error::access("SMS");
             }
             break;
             // logout user from system then redirect to ermile
         // logout user from system then redirect to ermile
         case 'logout':
             $this->model_name = '\\lib\\mvc\\model';
             $this->model()->put_logout();
             $this->redirector()->set_domain()->set_url()->redirect();
             break;
         default:
             \lib\error::page();
             break;
     }
     // $this->route_check_true = true;
 }
Exemple #12
0
 function __call($name, $args)
 {
     $remove = array("table", "select", "update", "insert", "delete", "form", "join");
     if (isset($this->subClass) && preg_grep("/^" . $name . "\$/", $remove)) {
         \lib\error::page("joinMaker method {$sCaller} not found");
     }
     preg_match("/^([a-z]+)([A-Z].*)?\$/", $name, $caller);
     switch ($caller[1]) {
         case 'where':
         case 'if':
         case 'and':
         case 'or':
         case 'like':
         case 'orlike':
         case 'andlike':
         case 'on':
             $sCaller = 'conditionsCaller';
             array_unshift($args, $caller[1]);
             break;
         case 'selects':
             $sCaller = 'selectCaller';
             break;
         case 'update':
         case 'insert':
         case 'delete':
         case 'select':
         case 'show':
             $sCaller = 'syntaxCaller';
             array_unshift($args, $caller[1]);
             break;
         default:
             $sCaller = $caller[1] . 'Caller';
             break;
     }
     $sName = isset($caller[2]) ? strtolower($caller[2]) : null;
     if (!method_exists($this, $sCaller)) {
         \lib\error::page("maker method {$sCaller} not found");
     }
     $ret = $this->{$sCaller}($sName, $args);
     return $ret === null ? $this : $ret;
 }
Exemple #13
0
 /**
  * check ssid in get return and after check set login data for user
  * check user permissions and validate session for disallow unwanted attack
  * @param  [type] $_type [description]
  * @return [type]        [description]
  */
 public function checkMainAccount($_type = null)
 {
     $_type = $_type !== null ? $_type : $this->put_ssidStatus();
     switch ($_type) {
         // user want to attack to our system! logout from system and show message
         case 'attack':
             $this->put_logout();
             \lib\error::bad(T_("you want hijack us!!?"));
             break;
             // only log out user from system
         // only log out user from system
         case 'logout':
             $this->put_logout('redirect');
             break;
             // if user_id set in options table login user to system
         // if user_id set in options table login user to system
         case is_numeric($_type):
             $mydatarow = $this->sql()->tableUsers()->whereId($_type)->select()->assoc();
             $myfields = array('id', 'user_mobile', 'user_email', 'user_displayname', 'user_meta', 'user_status', 'user_permission');
             $this->setLoginSession($mydatarow, $myfields);
             break;
             // ssid does not available on this sub domain
         // ssid does not available on this sub domain
         case 'notlogin':
             $this->put_logout('redirect');
             break;
         default:
             break;
     }
 }
Exemple #14
0
 public function caller(...$_args)
 {
     if (count($_args) < 3) {
         error::internal("caller arguments count");
         return;
     } elseif (!$_args[0] && !$args[1] || !$_args[2]) {
         error::internal("caller arguments invalid");
         return;
     }
     $caller = [$_args[0], $_args[1]];
     $route = new route(false);
     if (!is_array($_args[2])) {
         $_args[2] = [$_args[2]];
     }
     $return_route = call_user_func_array(array($route, 'check_route'), $_args[2]);
     if ($route->status) {
         array_push($caller, new api\args_callback(['method' => 'caller', 'match' => $route->match]));
         if (!isset($this->caller)) {
             $this->caller = array();
         }
         array_push($this->caller, $caller);
     }
 }
Exemple #15
0
 /**
  * optimize sql table, fields and value
  * @param  [string] $table [set table name]
  * @param  [string] $field [set field name]
  * @param  [string] $value [set value]
  * @return [string]        [optimize of string]
  * @example
  * 	oSting(users)			return #users#
  * 	oSting(users, id)		return #users.id#
  * 	oSting(users, id, 150)	return #users.id 150#
  */
 public function oString($table, $field = null, $value = null, $checkCondition = true)
 {
     if ($value !== null) {
         $cInt = false;
         // for insert or update multiple row
         if (is_array($value)) {
         } elseif (preg_match("/^#(.*)\$/", $value, $v)) {
             $value = $v[1];
             $cInt = true;
         } elseif (substr($value, 0, 1) == '#') {
             $value = substr($value, 1);
             $cInt = true;
         } else {
             $sTable = "get" . ucfirst(dbconnection::get_db_name());
             $cTable = sql\table::$sTable($table);
             if (isset($cTable->{$field})) {
                 $type = $cTable->{$field}->type;
                 $int = array("int", "tinyint", "smallint", "decimal");
                 preg_match("/^([^@]*)@/", $type, $tp);
                 if (preg_grep("/^" . $tp[1] . "\$/", $int)) {
                     $cInt = true;
                 }
                 if ($this->auto_validate) {
                     $status = $this->auto_validate($field, $cTable->{$field}, $value);
                     if (!is_bool($status)) {
                         \lib\debug::error($status, $field, 'form');
                     }
                 }
             }
             if (isset($cTable->{$field}->closure) && $checkCondition) {
                 $gTable = $cTable->{$field}->closure;
                 $value = preg_replace("/^\\\\#/", "#", $value);
                 $v = new validator(array($field, $value), $gTable->validate, 'form');
                 $value = $v->compile();
                 $value = $value == '' && is_string($value) && $value === false ? "NULL" : $value;
             }
             // switch by type of field and encode data if needed
             // var_dump($cTable->$field->type);
             if (isset($cTable->{$field}->type)) {
                 $atPos = strpos($cTable->{$field}->type, '@');
             } else {
                 // return false;
                 \lib\error::page("Field {$field} does not exist!");
             }
             if ($atPos !== false) {
                 switch (substr($cTable->{$field}->type, 0, $atPos)) {
                     // if the type of field is int do nothing
                     case 'tinyint':
                     case 'smallint':
                     case 'mediumint':
                     case 'int':
                     case 'bigint':
                     case 'decimal':
                     case 'float':
                         break;
                         // else doing entities
                     // else doing entities
                     case 'tinytext':
                     case 'text':
                     case 'mediumtext':
                     case 'longtext':
                     default:
                         // if does not contain meta doing nothing and encode value
                         if (strpos($field, '_meta') === false) {
                             $value = htmlentities($value, ENT_QUOTES, "UTF-8");
                         }
                         break;
                 }
             }
             // if(!$cInt)
             // {
             // 	$value = htmlentities($value, ENT_QUOTES, "UTF-8");
             // }
         }
         if (is_array($value)) {
             $optimize = $value;
         } else {
             $optimize = $cInt ? "{$value}" : "'{$value}'";
         }
     } else {
         $optimize = "`{$table}`";
         if ($field) {
             if (preg_match("/^#/", $field)) {
                 $optimize = preg_replace("/^#/", "", $field);
             } else {
                 // $optimize .= $field ? ($field === "*") ? ".$field" : ".`$field`" : "";
                 if ($field) {
                     if ($field === "*") {
                         $optimize .= ".{$field}";
                     } else {
                         $optimize .= ".`{$field}`";
                     }
                 } else {
                     $optimize .= "";
                 }
             }
         }
     }
     return $optimize;
 }
Exemple #16
0
 public function loadController()
 {
     /**
      * find controller;
      */
     $url_property = router::get_url_property(-1);
     $myrep = router::get_repository_name();
     if (!router::get_controller()) {
         $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\' . router::get_method() . '\\controller';
         $prv_class = router::get_class();
         // var_dump($controller_name);
         if (!class_exists($controller_name)) {
             if ((!isset($url_property[1]) || $url_property[1] != router::get_method()) && router::get_method() != 'home') {
                 router::add_url_property(router::get_method());
             }
             $prv_method = router::get_method();
             router::set_method('home');
             $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\' . router::get_method() . '\\controller';
             // var_dump(router::get_url_property(-1));
             // var_dump($controller_name);
             if (!class_exists($controller_name)) {
                 router::set_class($prv_class);
                 $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\controller';
                 // var_dump(router::get_url_property(-1));
                 // var_dump($controller_name);
                 if (!class_exists($controller_name)) {
                     if ((!isset($url_property[0]) || $url_property[0] != router::get_class()) && router::get_class() != 'home') {
                         router::add_url_property(router::get_class());
                     }
                     router::set_class('home');
                     $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\' . router::get_method() . '\\controller';
                     // var_dump(router::get_url_property(-1));
                     // var_dump($controller_name);
                     //
                     if (!class_exists($controller_name)) {
                         router::set_class('home');
                         $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\controller';
                         // var_dump(router::get_url_property(-1));
                         // $controller_name='\account\home\controller';
                         // var_dump($controller_name);
                         if (!class_exists($controller_name)) {
                             \lib\error::page("content not found");
                         }
                     }
                 }
             }
         }
     } else {
         $controller_name = router::get_controller();
     }
     router::set_controller($controller_name);
     if (!class_exists($controller_name)) {
         error::page($controller_name);
     }
     $controller = new $controller_name();
     self::$controller = $controller;
     // running template base module for homepage
     if (\lib\router::get_storage('CMS') && $myrep == 'content' && method_exists($controller, 's_template_finder')) {
         $controller->s_template_finder();
     }
     if (method_exists($controller, '_route')) {
         $controller->_route();
     }
     if (router::get_controller() !== $controller_name) {
         $this->loadController();
         return;
     }
     if (method_exists($controller, 'config')) {
         $controller->config();
     }
     if (method_exists($controller, 'options')) {
         $controller->options();
     }
     if (count(router::get_url_property(-1)) > 0 && $controller->route_check_true === false) {
         error::page('Unavailable');
     }
     $controller->_corridor();
 }
Exemple #17
0
 public function __call($name, $args)
 {
     if (preg_grep("/^{$name}\$/", array('get', 'post', 'put', 'delete'))) {
         array_unshift($args, $name);
         return call_user_func_array(array($this, 'check_api'), $args);
     } elseif (method_exists('\\lib\\router', $name)) {
         return call_user_func_array('\\lib\\router::' . $name, $args);
     }
     \lib\error::page(get_called_class() . "->{$name}()");
 }
Exemple #18
0
 public function __construct($_clean_url = null)
 {
     self::$repository = repository;
     $path = preg_replace("/^\\.\\//", "/", '/');
     $clean_url = $_clean_url !== null ? $_clean_url : $_SERVER['REQUEST_URI'];
     if (preg_match("#0x#", $clean_url)) {
         // error
     }
     $clean_url = preg_replace("#0x#Ui", "", $clean_url);
     $clean_url = preg_replace("#^https?://{$_SERVER['HTTP_HOST']}\\/#", '', $clean_url);
     $clean_url = preg_replace("#^{$path}#", '', $clean_url);
     $clean_url = urldecode($clean_url);
     preg_match("/^([^?]*)(\\?.*)?\$/", $clean_url, $url);
     self::$real_url_string = self::$url_string = $url[1];
     self::$real_url_array = self::$url_array = preg_split("[\\/]", preg_replace("/^\\/|\\/\$/", '', $url[1]), -1, PREG_SPLIT_NO_EMPTY);
     // HTTP_HOST is not secure and attacker can change it
     $domain = $_SERVER['HTTP_HOST'];
     self::$domain = preg_split("[\\.]", $domain);
     self::$sub_domain = self::$domain;
     array_pop(self::$sub_domain);
     array_pop(self::$sub_domain);
     if (isset(self::$real_url_array[0]) && self::$real_url_array[0] == 'home' || isset(self::$real_url_array[1]) && self::$real_url_array[1] == 'home') {
         \lib\error::page("home");
     }
     /**
      * user want control panel or CMS
      */
     if (defined('CMS') && constant('CMS')) {
         $myCP = constant('CMS') === true ? 'cp' : constant('CMS');
         router::set_storage('CMS', $myCP);
     } else {
         router::set_storage('CMS', 'cp');
     }
     /**
      * before router
      */
     if (self::$auto_repository) {
         // first get subdomain and if not exist get first url part as mysub
         $mysub = router::get_sub_domain();
         if (!$mysub) {
             $mysub = router::get_url(0);
             router::$sub_is_fake = true;
             // router::$sub_is_fake = $mysub? true: false;
             // router::set_storage('language', router::get_storage('defaultLanguage') );
         }
         if ($mysub) {
             // automatically set repository if folder of it exist
             $myaddons = array();
             $mysub_real = $mysub;
             $myloc = null;
             $mysub_valid = null;
             // check for account with specefic name
             if (\lib\router::get_storage('CMS')) {
                 $myaddons[\lib\router::get_storage('CMS')] = 'cp';
                 $myaddons['account'] = 'account';
             }
             // check this sub is exist in our data or not
             if (array_key_exists($mysub, $myaddons)) {
                 $mysub = $myaddons[$mysub];
                 $mysub_valid = true;
             }
             // set repository name
             $myrep = 'content_' . $mysub;
             // check content_aaa folder is exist in project or saloos addons folder
             if (is_dir(root . $myrep)) {
                 $myloc = false;
             } elseif ($mysub_valid && is_dir(addons . $myrep)) {
                 $myloc = addons;
             }
             // if folder exist
             if (!is_null($myloc)) {
                 // if url is fake, show it like subdomain and remove from url
                 if (router::$sub_is_fake) {
                     router::remove_url($mysub_real);
                     router::set_sub_domain($mysub_real);
                 }
                 // set repository to this folder
                 $myparam = array($myrep);
                 if ($myloc) {
                     array_push($myparam, $myloc);
                 }
                 // call function and pass param value to it
                 router::set_repository(...$myparam);
             }
         }
     }
     if (self::$auto_api) {
         // automatically allow api, if you wan't to desable it, only set a value
         $route = new router\route("/^api([^\\/]*)/", function ($reg) {
             router::remove_url($reg->url);
             router::set_storage('api', true);
         });
     }
     if (class_exists('\\cls\\route')) {
         $router = new \cls\route();
         $router->main = $this;
         if (method_exists($router, "_before")) {
             $router->_before();
         }
     }
     // like dev or com or ir or ...
     if (!defined('Tld')) {
         define('Tld', router::get_root_domain('tld'));
     }
     $this->check_router();
     /**
      * after router
      */
     if (class_exists('\\cls\\route')) {
         if (method_exists($router, "_after")) {
             $router->_after();
         }
     }
     // Define Project Constants *******************************************************************
     // declate some constant variable for better use in all part of app
     // like .dev or .com
     if (!defined('MainTld')) {
         // if enabling multi domain and set default tld define main tld
         if (\lib\utility\option::get('config', 'meta', 'multiDomain') && ($defaultTld = \lib\utility\option::get('config', 'meta', 'defaultTld'))) {
             define('MainTld', '.' . $defaultTld);
         } else {
             define('MainTld', Tld === 'dev' ? '.dev' : '.com');
         }
     }
     // like ermile
     if (!defined('Domain')) {
         define('Domain', router::get_root_domain('domain'));
     }
     // like account
     if (!defined('SubDomain')) {
         define('SubDomain', router::get_sub_domain());
     }
     // like  127.0.0.1
     if (!defined('ClientIP')) {
         define('ClientIP', router::get_clientIP());
     }
     // like ermile.com
     if (!defined('Service')) {
         define('Service', Domain . '.' . Tld);
     }
     // like test
     if (!defined('Module')) {
         define('Module', router::get_url(0));
     }
     // like https://ermile.com
     router::set_storage('url_site', Protocol . '://' . Domain . '.' . Tld . '/');
     // set MyAccount for use in all part of services
     if (!defined('AccountService')) {
         // if user want main account and set main account name
         if (\lib\utility\option::get('config', 'meta', 'useMainAccount') && \lib\utility\option::get('config', 'meta', 'mainAccount') === constant('MainService')) {
             define('AccountService', constant('MainService'));
         } else {
             define('AccountService', Domain);
         }
     }
     // check for account with specefic name
     if (!defined('MyAccount') && \lib\router::get_storage('CMS')) {
         // set MyAccount for use in all part of services
         define('MyAccount', 'account');
     }
     router::$base = Protocol . '://';
     if (router::$sub_is_fake) {
         router::$base .= Service . (SubDomain ? '/' . SubDomain : null);
     } else {
         router::$base .= SubDomain . '.' . Service;
     }
     if (count(explode('.', SubDomain)) > 1) {
         die("<p>Saloos only support one subdomain!</p>");
     } elseif (SubDomain === 'www') {
         header('Location: ' . router::get_storage('url_site'), true, 301);
     }
 }
Exemple #19
0
 /**
  * [__call description]
  * @param  [type] $_name [description]
  * @param  [type] $_args [description]
  * @return [type]       [description]
  */
 public function __call($_name, $_args)
 {
     if (preg_grep("/^{$_name}\$/", array('get', 'post', 'put', 'delete'))) {
         array_unshift($_args, $_name);
         return call_user_func_array(array($this, 'check_api'), $_args);
     } elseif (method_exists('\\lib\\router', $_name)) {
         return call_user_func_array('\\lib\\router::' . $_name, $_args);
     } elseif (preg_match("#^inject_((after_|before_)?.+)\$#Ui", $_name, $inject)) {
         return $this->inject($inject[1], $_args);
     } elseif (preg_match("#^i(.*)\$#Ui", $_name, $icall)) {
         return $this->mvc_inject_finder($_name, $_args, $icall[1]);
     }
     \lib\error::page(get_called_class() . "->{$_name}()");
 }
Exemple #20
0
 /**
  * return
  * @param  string $_loc  location
  * @param  string $_type type of permission needed
  * @return [type]        [description]
  */
 public static function access($_content = null, $_loc = null, $_type = null, $_block = null)
 {
     $myStatus = null;
     $su = null;
     // if user is superviser then set su to true
     // permission id 1 is supervisior of system
     if (isset($_SESSION['user']['permission']) && $_SESSION['user']['permission'] === "1") {
         $su = true;
         $suStatus = self::permListFill('su');
     }
     // if programmer not set content, give it automatically from address
     if ($_content === 'all') {
         $myStatus = [];
         if ($su) {
             foreach ($suStatus as $key => $value) {
                 if (isset($value['enable'])) {
                     $myStatus[$key] = $value['enable'];
                 }
             }
         } elseif (isset($_SESSION['permission'])) {
             foreach ($_SESSION['permission'] as $key => $value) {
                 if (isset($value['enable'])) {
                     $myStatus[$key] = $value['enable'];
                 }
             }
         }
         return $myStatus;
     } elseif (!$_content) {
         $_content = \lib\router::get_repository_name();
         if ($_content !== "content") {
             $_content = substr($_content, strpos($_content, '_') + 1);
         }
     }
     if (!isset($suStatus[$_content]) || !isset($suStatus[$_content]['modules'])) {
         $su = false;
     }
     // if user want specefic location
     if ($_loc == 'all') {
         if ($su) {
             $myStatus = $suStatus[$_content]['modules'];
         } elseif (isset($_SESSION['permission'][$_content]['modules'])) {
             $myStatus = $_SESSION['permission'][$_content]['modules'];
         }
     } elseif ($_loc) {
         if ($_type) {
             if ($su) {
                 if (isset($suStatus[$_content]['modules'][$_loc][$_type])) {
                     $myStatus = $suStatus[$_content]['modules'][$_loc][$_type];
                 }
             } elseif (isset($_SESSION['permission'][$_content]['modules'][$_loc][$_type])) {
                 $myStatus = $_SESSION['permission'][$_content]['modules'][$_loc][$_type];
             }
         } else {
             if ($su) {
                 $myStatus = $suStatus[$_content]['modules'][$_loc];
             } elseif (isset($_SESSION['permission'][$_content]['modules'][$_loc])) {
                 $myStatus = $_SESSION['permission'][$_content]['modules'][$_loc];
             }
         }
     } else {
         if ($su) {
             $myStatus = $suStatus[$_content]['enable'];
         } elseif (isset($_SESSION['permission'][$_content]['enable'])) {
             $myStatus = $_SESSION['permission'][$_content]['enable'];
         }
     }
     if (!$myStatus) {
         if ($_block === "notify" && $_type && $_loc) {
             $msg = null;
             switch ($_type) {
                 case 'view':
                     $msg = "You can't view this part of system";
                     break;
                 case 'add':
                     $msg = T_("You can't add new") . ' ' . T_($_loc);
                     break;
                 case 'edit':
                     $msg = T_("You can't edit") . ' ' . T_($_loc);
                     break;
                 case 'delete':
                     $msg = T_("You can't delete") . ' ' . T_($_loc);
                     break;
                 default:
                     $msg = "You can't access to this part of system";
                     break;
             }
             $msg = $msg . "<br/> " . T_("Because of your permission");
             \lib\debug::error(T_($msg));
             // exit();
         } elseif ($_block) {
             \lib\error::access(T_("You can't access to this page!"));
         } else {
             // do nothing!
         }
     }
     return $myStatus;
 }
Exemple #21
0
 function s_template_finder()
 {
     // if lang exist in module or subdomain remove it and continue
     $currentLang = substr(router::get_storage('language'), 0, 2);
     $defaultLang = substr(router::get_storage('defaultLanguage'), 0, 2);
     if ($currentLang === SubDomain && $currentLang !== $defaultLang) {
         \lib\router::set_sub_domain(null);
     }
     // elseif($currentLang === $this->module() && $currentLang !== $defaultLang)
     // 	\lib\router::remove_url($currentLang);
     // continue find best template for this condition
     $mymodule = $this->module();
     if ($mymodule == 'home') {
         // if home template exist show it
         if (is_file(root . 'content/template/home.html')) {
             $this->display_name = 'content\\template\\home.html';
         }
         $this->get()->ALL();
         return 0;
     } elseif ($mymodule == 'search') {
         if (is_file(root . 'content/template/search.html')) {
             $this->display_name = 'content\\template\\search.html';
         }
         $this->get()->ALL();
         return;
     } elseif ($mymodule == 'feed') {
         $site_title = $this->view()->data->site['title'];
         $site_desc = $this->view()->data->site['desc'];
         $site_protocol = $this->url('MainProtocol') . '://';
         $site_url = $this->url('MainSite');
         $rss = new \lib\utility\RSS($site_protocol, $site_url, $site_title, $site_desc);
         // add posts
         foreach ($this->model()->get_feeds() as $row) {
             $rss->addItem($row['link'], $row['title'], $row['desc'], $row['date']);
         }
         $rss->create();
         // \lib\utility\RSS::create();
         exit;
         return;
     }
     if (!empty(db_name)) {
         $myurl = $this->model()->s_template_finder();
     } else {
         $myurl = null;
     }
     // if url does not exist show 404 error
     if (!$myurl) {
         // var_dump($mymodule);
         // var_dump(\lib\router::get_storage('language'));
         // if user entered url contain one of our site language
         $currentPath = $this->url('path', '_');
         // if custom template exist show this template
         if (is_file(root . 'content/template/static_' . $currentPath . '.html')) {
             $this->display_name = 'content\\template\\static_' . $currentPath . '.html';
         } elseif (is_file(root . 'content/template/404.html')) {
             header("HTTP/1.1 404 NOT FOUND");
             $this->display_name = 'content\\template\\404.html';
         } else {
             \lib\error::page(T_("Does not exist!"));
             return;
         }
     } elseif (is_file(root . 'content/template/' . $myurl['type'] . '-' . $myurl['slug'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['type'] . '-' . $myurl['slug'] . '.html';
     } elseif (is_file(root . 'content/template/' . $myurl['type'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['type'] . '.html';
     } elseif (is_file(root . 'content/template/' . $myurl['table'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['table'] . '.html';
     } elseif (is_file(root . 'content/template/dafault.html')) {
         $this->display_name = 'content\\template\\dafault.html';
     }
     $this->route_check_true = true;
     $this->get(null, $myurl['table'])->ALL();
     // $this->get()->ALL();
 }
 function config()
 {
     // Restrict unwanted module
     if (!$this->cpModlueList()) {
         \lib\error::page(T_("Not found!"));
     }
     $mymodule = $this->cpModule('table');
     $cpModule = $this->cpModule('raw');
     $mychild = $this->child();
     $mypath = $this->url('path', '_');
     // Restrict unwanted child
     // if($mychild && !($mychild=='add' || $mychild=='edit' || $mychild=='delete' || $mychild=='list' || $mychild=='options'))
     // 	\lib\error::page(T_("Not found!"));
     if (is_file(addons . 'content_cp/' . $cpModule . '/model.php')) {
         $this->model_name = 'content_cp\\' . $cpModule . '\\model';
     } elseif (is_file(addons . 'content_cp/' . $mymodule . '/model.php')) {
         $this->model_name = 'content_cp\\' . $mymodule . '\\model';
     }
     switch ($cpModule) {
         case 'home':
             break;
         case 'profile':
             // Check permission and if user can do this operation
             // allow to do it, else show related message in notify center
             $this->access('cp', 'profile', 'edit', 'notify');
             //allow put on profile
             $this->display_name = 'content_cp/templates/module_profile.html';
             $this->get(null, 'datatable')->ALL('/^[^\\/]*$/');
             $this->put('profile')->ALL();
             break;
         case 'options':
             //allow put on profile
             // $this->display_name	= 'content_cp/templates/module_options.html';
             $this->get(null, 'datatable')->ALL('/^[^\\/]*$/');
             $this->put('options')->ALL();
             break;
             // case 'permissions':
             // 	$this->display_name	= 'content_cp/templates/module_permissions.html';
             // 	$this->get(null, 'datatable')->ALL('/^[^\/]*$/');
             // 	$this->put('permissions')->ALL();
             // 	break;
         // case 'permissions':
         // 	$this->display_name	= 'content_cp/templates/module_permissions.html';
         // 	$this->get(null, 'datatable')->ALL('/^[^\/]*$/');
         // 	$this->put('permissions')->ALL();
         // 	break;
         case 'logout':
             $mydomain = AccountService ? AccountService . MainTld : null;
             $this->redirector(null, false)->set_domain($mydomain)->set_url('logout')->redirect();
             break;
         default:
             if (is_file(addons . 'content_cp/templates/module_' . $mymodule . '.html')) {
                 $this->display_name = 'content_cp/templates/module_' . $mymodule . '.html';
             } else {
                 $this->display_name = 'content_cp/templates/module_display.html';
             }
             $this->get(null, 'datatable')->ALL('/^[^\\/]*$/');
             // on each module except home and some special module with child like /post/add
             if ($mychild) {
                 if (is_file(addons . 'content_cp/templates/child_' . $mymodule . '.html')) {
                     $this->display_name = 'content_cp/templates/child_' . $mymodule . '.html';
                 } else {
                     $this->display_name = 'content_cp/templates/child_display.html';
                 }
                 //all("edit=.*")
                 $this->route_check_true = true;
                 switch ($mychild) {
                     case 'delete':
                         $this->redirector()->set_url($this->cpModule('raw'));
                         //->redirect();
                         // $this->delete($mychild)->ALL('/^[^\/]*\/[^\/]*$/');
                         $this->post($mychild)->ALL('/^[^\\/]*\\/[^\\/]*$/');
                         $this->get($mychild)->ALL('/^[^\\/]*\\/[^\\/]*$/');
                         // @hasan: regular?
                         // $this->display_name = null;
                         // $this->redirector()->set_url($cpModule);//->redirect();
                         return;
                         break;
                     case 'edit':
                         // var_dump($this->model()->datarow());
                         $this->get(null, 'child')->ALL('/^[^\\/]*\\/[^\\/]*$/');
                         $this->put($mychild)->ALL('/^[^\\/]*\\/[^\\/]*$/');
                         break;
                     case 'add':
                         $this->get(null, 'child')->ALL('/^[^\\/]*\\/[^\\/]*$/');
                         $this->post($mychild)->ALL('/^[^\\/]*\\/[^\\/]*$/');
                         break;
                     case 'list':
                         $this->route_check_true = false;
                         $this->get($mychild)->ALL();
                         $this->post($mychild)->ALL();
                         break;
                     case 'options':
                         $this->route_check_true = false;
                         $this->get($mychild)->ALL();
                         $this->post($mychild)->ALL();
                         break;
                     default:
                         break;
                 }
             }
             break;
     }
     if (is_file(addons . 'content_cp/templates/static_' . $mypath . '.html')) {
         $this->display_name = 'content_cp/templates/static_' . $mypath . '.html';
     }
 }