/** * [find_url_from_shortURL description] * @param [type] $_shortURL [description] * @return [type] [description] */ public static function checkShortURL($_shortURL = null) { // set this shorturl, real url:) if (!\lib\utility\option::get('config', 'meta', 'shortURL')) { return null; } if (!$_shortURL) { $_shortURL = \lib\router::get_url(); } $table = null; $field = null; $urlPrefix = substr($_shortURL, 0, 3); switch ($urlPrefix) { case 'sp_': // if this is url of one post $table = 'post'; $field = "*"; break; case 'st_': // else if this is url of one term $table = 'term'; $field = 'term_url as url'; break; } // if prefix is not correct return false if (!$table) { return null; } // remove prefix from url $_shortURL = substr($_shortURL, 3); $id = \lib\utility\shortURL::decode($_shortURL); $table .= 's'; $qry = "SELECT {$field} FROM {$table} WHERE id = {$id}"; $result = \lib\db::get($qry, null, true); if (!is_array($result)) { return false; } if (!\lib\utility\option::get('config', 'meta', 'forceShortURL') && isset($result['post_url'])) { $post_url = $result['post_url']; // redirect to url of this post $myredirect = new \lib\redirector(); $myredirect->set_url($post_url)->redirect(); } // if not force simulate this url return $result; }
public function __construct() { $cls = debug_backtrace(); if (isset($cls[1]['class']) && $cls[1]['class'] == '\\lib\\sql') { $this->cls = $cls[1]['object']; } self::$db_name = self::$db_name ? self::$db_name : db_name; self::$db_user = self::$db_user ? self::$db_user : db_user; self::$db_pass = self::$db_pass ? self::$db_pass : db_pass; // self::$db_host = self::$db_host ? self::$db_host : db_host; if (!isset(self::$dbConnection[self::$db_name])) { // if mysqli class does not exist or have some problem show related error if (!class_exists('mysqli')) { echo "<p>" . T_("we can't find database service!") . " " . T_("please contact administrator!") . "</p>"; \lib\main::$controller->_processor(array('force_stop' => true)); } self::$connection = @new \mysqli(self::$db_host, self::$db_user, self::$db_pass, self::$db_name); if (self::$connection->connect_errno == 0) { self::$connection->set_charset(self::$db_charset); self::$dbConnection[self::$db_name] = self::$connection; } else { if (self::$connection->connect_errno == 1045) { echo "<p>" . T_("We can't connect to database service!") . " " . T_("Please contact administrator!") . "</p>"; \lib\main::$controller->_processor(['force_stop' => true]); } else { if (self::$connection->connect_errno == 1049) { // database does not exist, go to install page // echo( "<p>".T_("We can't connect to correct database!")." " .T_("Please contact administrator!")."</p>" ); // if method exist, used for forms if (method_exists(\lib\main::$controller, 'redirector')) { \lib\main::$controller->redirector()->set_domain()->set_url('cp/install?time=first_time'); \lib\main::$controller->_processor(['force_stop' => true, 'force_json' => true]); } else { $redirector = new \lib\redirector(); $redirector->set_domain()->set_url('cp/install?time=first_time')->redirect(); } } else { $this->error(self::$connection->connect_error, self::$connection->connect_errno); } } } } }
public function pagnation_config() { if (preg_match("#^([1-9][0-9]*)\$#", \lib\router::get_url_property('page'), $_page)) { $page = intval($_page[1]); \lib\router::set_storage('pagnation', $page); $this->pagnation['current'] = $page; \lib\router::remove_url_property('page'); if ($page == 1) { $redirect = new \lib\redirector(null, true); $redirect->url = preg_replace("/\\/page=1/", "", $redirect->url); $redirect->redirect(); } } if (preg_match("#^(\\d+)\$#", \lib\router::get_url_property('length'), $length)) { $this->pagnation_set('length', intval($length[1])); $this->pagnation_set('custom_length', true); \lib\router::remove_url_property('length'); } }
/** * check current protocol and if needed redirect to another! * @return [type] [description] */ private static function check_protocol() { // create new url for protocol checker $newUrl = ""; $currentPath = $_SERVER['REQUEST_URI']; $mainSite = \lib\utility\option::get('config', 'meta', 'redirectURL'); // if redirect to main site is enable and all thing is okay // then redirect to the target url if (\lib\utility\option::get('config', 'meta', 'multiDomain') && \lib\utility\option::get('config', 'meta', 'redirectToMain') && $mainSite && Tld !== 'dev' && parse_url($mainSite, PHP_URL_HOST) != \lib\router::get_root_domain()) { // as soon as posible we create language detector library switch (Tld) { case 'ir': $newUrl = $mainSite . "/fa"; break; default: break; } } elseif ($currentPath !== '/' && rtrim($currentPath, '/') !== $currentPath) { $newUrl = $mainSite . rtrim($currentPath, '/'); } else { // if want to force using https then redirect to https of current url if (\lib\utility\option::get('config', 'meta', 'https')) { if (Protocol === 'http') { $newUrl = 'https://'; } } elseif (Protocol === 'https') { $newUrl = 'http://'; } if ($newUrl) { $newUrl .= router::get_root_domain() . '/' . router::get_url(); } } // var_dump($newUrl);exit(); // if newUrl is exist and we must to redirect // then complete url and redirect to this address if ($newUrl && !\lib\utility::get('force')) { // redirect to best protocol because we want it! $redirector = new \lib\redirector($newUrl); $redirector->redirect(); } }
public static function detect_language() { /** * set default language to storage for next use */ // var_dump(\lib\utility\option::get('config', 'meta', 'defaultLanguage')); $default_lang = \lib\utility\option::get('config', 'meta', 'defaultLang'); if ($default_lang) { router::set_storage('defaultLanguage', $default_lang); } else { router::set_storage('defaultLanguage', 'en_US'); } // if current tld is ir or referrer from site with ir tld, // change language to fa_IR if (\lib\router::get_storage('language')) { $myLang = router::get_storage('language'); switch (Tld) { case 'ir': $myLang = "fa_IR"; break; default: break; } if (defined('MainService') && Tld !== 'dev') { // for example redirect ermile.ir to ermile.com/fa $myLang = substr($myLang, 0, 2); $myredirect = new \lib\redirector(); $myredirect->set_domain()->set_url($myLang)->redirect(); } else { // else show in that domain with fa langusage router::set_storage('language', $myLang); } } /** * Localized Language, defaults to English. * * Change this to localize Saloos. A corresponding MO file for the chosen * language must be installed to content/languages. For example, install * fa_IR.mo to content/languages and set LANGUAGE to 'fa_IR' to enable Persian * language support. */ router::set_storage('language', router::get_storage('defaultLanguage')); if (router::get_repository_name() === 'content') { // $mysub = router::get_sub_domain(); $mysub = router::get_url(0); $myList = \lib\utility\option::languages(); // check langlist with subdomain and if is equal set current language foreach ($myList as $key => $value) { $myLang = substr($key, 0, 2); if ($mysub === $myLang) { if (router::get_storage('defaultLanguage') === $key) { // redirect to homepage $myredirect = new \lib\redirector(); $myredirect->set_domain()->set_url()->redirect(); } else { router::set_storage('language', $key); // update base url router::$base .= '/' . router::get_url(0); router::remove_url($myLang); } } } } else { // change with get all times except on content or root, // because in root user must change language with subdomain if (isset($_GET["lang"])) { router::set_storage('language', $_GET["lang"]); } elseif (isset($_COOKIE["lang"])) { router::set_storage('language', $_COOKIE["lang"]); } // save language preference for future page requests setcookie('lang', router::get_storage('language'), time() + 30 * 24 * 60 * 60, '/', '.' . Service); } // check direction of language and set for rtl languages switch (router::get_storage('language')) { case 'fa_IR': case 'ar_SU': router::set_storage('direction', 'rtl'); break; default: router::set_storage('direction', 'ltr'); break; } return router::get_storage('language'); }
public function __construct() { self::$repository = repository; $path = preg_replace("/^\\.\\//", "/", '/'); $clean_url = $_SERVER['REQUEST_URI']; if (preg_match("#0x#", $clean_url)) { // var_dump("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"); } /** * set default language to storage for next use */ if (defined('DefaultLanguage')) { router::set_storage('defaultLanguage', DefaultLanguage); } else { router::set_storage('defaultLanguage', 'en_US'); } /** * user want control panel or CMS */ if (defined('CMS') && constant('CMS')) { $myCP = constant('CMS') === true ? 'cp' : constant('CMS'); router::set_storage('CMS', $myCP); } elseif (defined('ControlPanel') && constant('ControlPanel')) { $myCP = constant('ControlPanel') === true ? 'cp' : constant('ControlPanel'); router::set_storage('CMS', $myCP); } else { router::set_storage('CMS', false); } /** * 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::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 (defined('Account') && constant('Account')) { $mykey = constant('Account') === true ? 'account' : constant('Account'); $myaddons[$mykey] = 'account'; } // check for account with specefic name if (\lib\router::get_storage('CMS')) { $myaddons[\lib\router::get_storage('CMS')] = 'cp'; } // 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 subdomain is set, change current lang to it, except for default language if (defined('LangList') && constant('LangList')) { // check langlist with subdomain and if is equal set current language foreach (unserialize(LangList) as $key => $value) { if ($mysub === substr($key, 0, 2)) { if (router::get_storage('defaultLanguage') !== $key) { router::set_storage('language', $key); } else { // redirect to homepage $myredirect = new \lib\redirector(); $myredirect->set_domain()->set_url()->redirect(); } } } } } } 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(); } } $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 or ir or ... if (!defined('Tld')) { define('Tld', router::get_root_domain('tld')); } // like .dev or .com if (!defined('MainTld')) { 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 . '/'); if (defined('Account') && constant('Account')) { // if use ermile set Mainservice for creating all account together if (is_string(constant('Account')) && constant('Account') !== constant('MainService')) { $myAccount = constant('Account'); } else { $myAccount = 'account'; } } else { $myAccount = false; } // set MyAccount for use in all part of services if (!defined('AccountService')) { if (defined('Account') && constant('Account') === constant('MainService')) { define('AccountService', constant('MainService')); } else { define('AccountService', Domain); } } // set MyAccount for use in all part of services if (!defined('MyAccount')) { define('MyAccount', $myAccount); } 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); } }