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); }
public function ALL($route = null) { if ($route === null) { $route = array(\lib\router::get_url()); } else { $route = func_get_args(); } $this->REST(...$route)->SERVER(); return $this; }
function max($max) { $url = \lib\router::get_url(-1); if (count($url) > 0 && \lib\router::get_class() == $url[0]) { array_shift($url); } if (count($url) > 0 && \lib\router::get_method() == $url[0]) { array_shift($url); } if (count($url) > $max) { $this->status = false; } }
/** * get the list of pages * @param boolean $_select for use in select box * @return [type] return string or dattable */ public function sp_books_nav() { $myUrl = \lib\router::get_url(-1); $result = ['cats' => null, 'pages' => null]; $parent_search = null; switch (count($myUrl)) { // book/book1 case 2: $myUrl = $this->url('path'); $parent_search = 'id'; break; // book/book1/jeld1 // book/book1/jeld1 case 3: $myUrl = $this->url('path'); $parent_search = 'parent'; break; // book/book1/jeld1/page1 // book/book1/jeld1/page1 case 4: $myUrl = $myUrl[0] . '/' . $myUrl[1] . '/' . $myUrl[2]; $parent_search = 'parent'; break; // on other conditions return false // on other conditions return false default: return false; } // get id of current page $qry = $this->sql()->table('posts')->where('post_type', 'book')->and('post_url', $myUrl)->and('post_status', 'publish')->field('id', '#post_parent as parent')->select(); if ($qry->num() != 1) { return; } $datarow = $qry->assoc(); // get list of category or jeld $qry = $this->sql()->table('posts')->where('post_type', 'book')->and('post_status', 'publish')->and('post_parent', $datarow[$parent_search])->field('id', '#post_title as title', '#post_parent as parent', '#post_url as url')->select(); if ($qry->num() < 1) { return; } $result['cats'] = $qry->allassoc(); $catsid = $qry->allassoc('id'); $catsid = implode($catsid, ', '); // check has page on category or only in $qry2 = $this->sql()->table('posts')->where('post_type', 'book')->and('post_status', 'publish')->and('post_parent', 'IN', '(' . $catsid . ')')->field('id'); $qry2 = $qry2->select(); $result['pages'] = $qry2->num(); return $result; }
/** * [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 static function send($_mobile, $_status = null, $_arg = null, $_service = MainService) { $_status = is_null($_status) ? \lib\router::get_url() : $_status; $mymessage = T_(ucfirst($_service)) . "\n"; switch ($_status) { case 'signup': $mymessage .= T_('your verification code is') . ' ' . $_arg; break; case 'recovery': $mymessage .= T_('your recovery code is') . ' ' . $_arg; break; case 'verification': $mymessage .= T_('you account is verified successfully'); break; case 'changepass': $mymessage .= T_('your password is changed successfully'); break; default: $mymessage .= T_('thanks for using our service') . "\n" . T_('made in iran'); break; } $mymessage .= "\n\n" . ucfirst($_service) . '.com'; if (substr($_mobile, 0, 2) == '98') { $iran = true; } else { $iran = null; } if ($iran) { $api = new \KavenegarApi(); $result = $api->send($_mobile, $mymessage, 0); // $result = $api->select(27657835); // $result = $api->cancel(27657835); // $result = $api->selectoutbox(1410570000); // $result = $api->account_info(); // var_dump($result);exit(); } else { \lib\debug::warn(T_('now we only support Iran!')); if (DEBUG) { \lib\debug::warn("Think sms is send to {$_mobile}!"); \lib\debug::true($mymessage); } } }
/** * return module name for use in view or other place * @param [type] $_title [description] * @return [type] [description] */ public function child($_title = null) { $mychild = router::get_url(1); if (strrpos($mychild, '=') !== false) { $mychild = substr($mychild, 0, strrpos($mychild, '=')); } if (!$_title) { return $mychild; } if ($mychild == 'add') { return T_('add new'); } if ($mychild == 'edit') { return T_('edit'); } if ($mychild == 'delete') { return T_('delete'); } }
/** * 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()]; }
/** * check status of permission to access special module * @param [type] $route [description] * @return [type] [description] */ public function check($route) { $mysub = router::get_sub_domain(); if (router::get_sub_domain() === "cp") { $mymodule = router::get_url(0); $mychild = router::get_url(1); $mymethod = $this->api_method; $myrequest = 'view'; $myblock = 'block'; if (strrpos($mychild, '=') !== false) { $mychild = substr($mychild, 0, strrpos($mychild, '=')); } // set request name by type of it switch ($mymethod) { case 'get': $myrequest = 'view'; break; case 'post': $myrequest = 'add'; $myblock = 'notify'; break; case 'put': $myrequest = 'edit'; $myblock = 'notify'; break; case 'delete': $myrequest = 'delete'; $myblock = 'notify'; break; default: $myrequest = '#invalid'; break; } // find request by 2th slash in url named as child switch ($mychild) { case 'add': $myrequest = 'add'; break; case 'edit': $myrequest = 'edit'; break; case 'delete': $myrequest = 'delete'; break; } // set some setting for special module switch ($mymodule) { case 'posts': case 'pages': case 'users': case 'options': case 'permissions': case 'tags': case 'cats': break; case 'profile': $myblock = false; break; default: break; } // Check permission and if user can do this operation // allow to do it, else show related message in notify center $myController = \lib\main::$controller; $myController->access($mysub, $mymodule, $myrequest, $myblock); } parent::check(...func_get_args()); }
public function config() { // $this->data->list = $this->cpModlueList('all'); $this->data->bodyclass = 'fixed unselectable'; $this->include->css = false; $this->include->js = false; $this->include->fontawesome = true; $this->include->datatable = true; $this->include->chart = true; $this->include->introjs = true; $this->include->lightbox = true; $this->include->editor = true; $this->include->cp = true; $this->include->uploader = true; $this->global->js = array(); $this->data->display['cp_posts'] = "content_cp/posts/layout.html"; $this->data->saloos['version'] = \lib\saloos::getLastVersion(); $this->data->saloos['lastUpdate'] = \lib\saloos::getLastUpdate(); $this->data->saloos['langlist'] = ['fa_IR' => 'Persian - فارسی', 'en_US' => 'English', 'ar_SU' => 'Arabic - العربية']; $this->data->modules = $this->controller::$manifest['modules']->get_modules(); // $this->global->js = [$this->url->myStatic.'js/highcharts/highcharts.js']; // $this->data->page['desc'] = 'salam'; $mymodule = $this->module(); $this->data->page['desc'] = $this->controller::$manifest['modules']->get_modules($mymodule, "desc"); $this->data->page['title'] = $this->controller::$manifest['modules']->get_modules($mymodule, "title"); $this->data->page['haschild'] = $this->controller::$manifest['modules']->get_modules($mymodule, "childless") ? false : true; $this->data->page['title'] = T_(ucfirst(\lib\router::get_url(' '))); $this->data->cpModule = $this->cpModule(); $this->data->dir['right'] = $this->global->direction == 'rtl' ? 'left' : 'right'; $this->data->dir['left'] = $this->global->direction == 'rtl' ? 'right' : 'left'; switch ($mymodule) { case 'visitors': if (\lib\utility\option::get('config', 'meta', 'logVisitors')) { // create for chart $type = \lib\utility::get('type'); $utype = \lib\utility::get('utype'); $stype = \lib\utility::get('stype'); $atype = \lib\utility::get('atype'); $this->data->chart_type = $type ? $type : 'column'; $this->data->chart_unique_type = $utype ? $utype : 'areaspline'; $this->data->chart_signup_type = $stype ? $stype : 'areaspline'; $this->data->chart_answered_type = $atype ? $atype : 'column'; // $this->data->visitors = $this->model()->visitors(); // $this->data->visitors_unique = $this->model()->visitors(true); $this->data->visitors = \lib\utility\visitor::chart(); $this->data->visitors_unique = \lib\utility\visitor::chart(true); // get period of signup from user $this->data->period = \lib\utility::get('period'); switch ($this->data->period) { case 'year': $period = "%Y"; break; case 'month': $period = "%Y-%m"; break; case 'week': $period = "%Y " . T_('week') . "%V"; break; case 'day': default: $period = "%Y-%m-%d"; break; } $this->data->signup = \lib\db\chart\users::signup($period); if (class_exists('\\lib\\db\\chart\\polls')) { $this->data->answered = \lib\db\chart\polls::answeredCount($period); } if ($this->data->visitors <= 1) { $this->data->error = T_("Chart must be contain at least 2 column!"); } } break; case 'home': $this->data->countOf['posts'] = $this->model()->countOf('posts'); $this->data->countOf['pages'] = $this->model()->countOf('pages'); $this->data->countOf['attachments'] = $this->model()->countOf('attachments'); $this->data->countOf['books'] = $this->model()->countOf('books'); $this->data->countOf['tags'] = $this->model()->countOf('tags'); $this->data->countOf['categories'] = $this->model()->countOf('categories'); $this->data->countOf['users'] = $this->model()->countOf('users'); $this->data->bodyclass .= ' unselectable'; // check visitor is new or not $this->data->visitor_new = false; $ref = \lib\router::urlParser('referer', 'sub'); if ($ref !== 'cp' && $ref !== null) { $this->data->visitor_new = true; } if (\lib\utility\option::get('config', 'meta', 'logVisitors')) { // create for chart $this->data->chart_type = 'column'; $this->data->visitors = \lib\utility\visitor::chart(); $this->data->visitors_toppages = \lib\utility\visitor::top_pages(15); if ($this->data->visitors <= 1) { $this->data->error = T_("Chart must be contain at least 2 column!"); } } break; default: # code... break; } if ($this->data->page['haschild']) { // Check permission and if user can do this operation // allow to do it, else show related message in notify center $myResult = $this->access('cp', $mymodule, 'add'); $this->data->page['haschild'] = $myResult ? true : false; } // $f = array_keys($this->controller::modules_hasnot('disable')); // $feature = []; // foreach ($f as $key => $value) { // $feature[$value] = true; // } // $this->data->site['title'] = T_('Control Panel'). ' - ' . $this->data->site['title']; }
/** * clearly return url property for use * @param [type] $_type type of url you need * @param [type] $_arg an argument for pass into some condition * @return [type] the url value */ public function url($_type = null, $_arg = null) { $tmp_result = null; $myprefix = Protocol . "://"; $mypostfix = '/'; $mytld = router::get_root_domain('tld'); switch ($_type) { // sub domain like 'account' case 'sub': return router::get_sub_domain($_arg); break; case 'path': $myUrl = router::get_url($_arg); if ($_arg == '_') { // filter url to delete disallow characters $myUrl = router::urlfilterer($myUrl); // dont use $ in id $myUrl = str_replace('$', 'dollar', $myUrl); } return $myUrl; break; case 'breadcrumb': $myurl = router::get_url(-1); $breadcrumb = array(); foreach ($myurl as $value) { $tmp_pos = strpos($value, '='); array_push($breadcrumb, $tmp_pos ? substr($value, 0, $tmp_pos) : $value); } return $breadcrumb; break; case 'param': return \lib\utility::get(null, $_arg); break; // domain tld like 'com' // domain tld like 'com' case 'tld': return $mytld; break; // domain name like 'ermile' // domain name like 'ermile' case 'domain': return router::get_root_domain('domain'); break; // domain name except subdomain like 'ermile.com' // domain name except subdomain like 'ermile.com' case 'raw': return router::get_root_domain('domain') . '.' . $mytld; break; // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/' // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/' case 'root': return $myprefix . router::get_root_domain() . $mypostfix; break; // use main protocol and give it from config file if not exist use root url // return http or https // use main protocol and give it from config file if not exist use root url // return http or https case 'MainProtocol': if (defined('MainProtocol') && constant('MainProtocol') && is_string(constant('MainProtocol'))) { return constant('MainProtocol'); } else { return 'http'; } break; // use main site and give it from config file if not exist use root url // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/' // use main site and give it from config file if not exist use root url // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/' case 'MainSite': if (defined('MainSite') && constant('MainSite') && is_string(constant('MainSite'))) { return constant('MainSite'); } else { return router::get_root_domain() . $mypostfix; } break; // base url for user in base tag with http[s] // base url for user in base tag with http[s] case 'base': return router::$base; break; // full url except get parameter with http[s] // full url except get parameter with http[s] case 'full': return $myprefix . router::get_domain() . '/' . router::get_url(); break; // return module info // return module info case 'module': if ($_arg === 'prefix') { $mymodule = substr(router::get_url(0), 0, -1); } elseif ($_arg == 'array') { $mymodule = router::get_url(-1); } elseif ($_arg == 'cp') { $mymodule = router::get_url(0); switch ($mymodule) { case 'tags': case 'cats': $mymodule = 'terms'; break; case 'pages': $mymodule = 'posts'; break; } } else { $mymodule = router::get_url(0); } return $mymodule; break; case 'child': $mychild = router::get_url(1); if (strrpos($mychild, '=') !== false) { $mychild = substr($mychild, 0, strrpos($mychild, '=')); } if (!$_arg) { return $mychild; } if ($mychild == 'add') { return T_('add new'); } if ($mychild == 'edit') { return T_('edit'); } if ($mychild == 'delete') { return T_('delete'); } break; // login service and main service with full address // login service and main service with full address case 'LoginService': case 'account': return $myprefix . AccountService . MainTld . '/' . MyAccount; break; case 'MainService': $_arg = is_array($_arg) ? $_arg : array('com', 'dev'); if (in_array($mytld, $_arg)) { return $myprefix . constant('MainService') . '.' . $mytld; } else { return $myprefix . constant('MainService') . MainTld; } break; default: return null; break; } }
/** * create special message depending on settings * @param [type] $_msg [description] * @param [type] $_arg [description] * @param [type] $_settings [description] * @return [type] [description] */ private static function message($_msg = null, $_arg = null, $_settings = null) { $_arg = trim($_arg); $sms_msg = null; $sms_header = null; $sms_footer = null; $sms_maxOne = 160; $sms_forceOne = null; $sms_template = ['signup', 'recovery', 'verification', 'changepass']; $template = null; // if user want one of our template create message automatically if (in_array($_msg, $sms_template)) { $template = $_msg; } elseif (!$_msg) { $template = is_null($_msg) ? \lib\router::get_url() : $_msg; } // set message header if (isset($_settings['meta']['header']) && $_settings['meta']['header']) { $sms_header = T_($_settings['meta']['header']); } // set message footer if (isset($_settings['meta']['footer']) && $_settings['meta']['footer']) { $sms_footer = T_($_settings['meta']['footer']); } // set message footer if (isset($_settings['meta']['one']) && $_settings['meta']['one']) { $sms_forceOne = $_settings['meta']['one']; } // if user want our template if ($template) { // if user want to send message for this template // then create related message if (isset($_settings['meta'][$template])) { // set related message depending on status passed switch ($template) { case 'signup': $_msg = T_('Your verification code is') . ' ' . $_arg; break; case 'recovery': $_msg = T_('Your recovery code is') . ' ' . $_arg; break; case 'verification': $_msg = T_('You account is verified successfully'); break; case 'changepass': $_msg = T_('Your password is changed successfully'); break; } } else { return false; } } else { // else if possible translate user message $_msg = T_($_msg); } $_msg = trim($_msg); // if message is not set then return false if (!$_msg) { return false; } // create complete message $sms_msg = $sms_header . "\n" . $_msg . "\n\n" . $sms_footer; if ($sms_forceOne && mb_strlen($sms_msg) > self::is_rtl($sms_msg, true)) { // create complete message $sms_msg = $sms_header . "\n" . $_msg; if ($sms_forceOne && mb_strlen($sms_msg) > self::is_rtl($sms_msg, true)) { // create complete message $sms_msg = $_msg; } } // return final message:) return $sms_msg; }
public function config() { // $this->data->list = $this->cpModlueList('all'); $this->data->bodyclass = 'fixed'; $this->include->css = false; $this->include->js = false; $this->include->fontawesome = true; $this->include->datatable = true; $this->include->chart = true; $this->include->introjs = true; $this->include->lightbox = true; $this->include->editor = true; $this->include->cp = true; $this->include->uploader = true; $this->global->js = array(); // $this->global->js = [$this->url->myStatic.'js/highcharts/highcharts.js']; // $this->data->page['desc'] = 'salam'; $this->data->page['haschild'] = true; $this->data->page['title'] = T_(ucfirst(\lib\router::get_url(' '))); $this->data->dir['right'] = $this->global->direction == 'rtl' ? 'left' : 'right'; $this->data->dir['left'] = $this->global->direction == 'rtl' ? 'right' : 'left'; $mymodule = $this->module(); switch ($mymodule) { case 'tags': $this->data->page['desc'] = T_('Assign keywords to your posts using tags'); break; case 'categories': $this->data->page['desc'] = T_('Use categories to define sections of your site and group related posts'); $this->data->page['title'] = T_('Categories'); break; case 'filecategories': $this->data->page['desc'] = T_('Use categories to define sections of your site and group related files'); $this->data->page['title'] = T_('File Categories'); break; case 'bookcategories': $this->data->page['desc'] = T_('Use categories to define sections of your site and group related books'); $this->data->page['title'] = T_('Book Categories'); break; case 'books': $this->data->page['desc'] = T_('Use book to define important parts to use in posts'); $this->data->page['title'] = T_('books'); break; case 'posts': $this->data->page['desc'] = T_('Use posts to share your news in specefic category'); break; case 'pages': $this->data->page['desc'] = T_('Use pages to share your static content'); break; case 'attachments': $this->data->page['desc'] = T_('Upload your media'); break; case 'socialnetwork': $this->data->page['desc'] = T_('Publish new post in social networks'); break; case 'options': $this->data->page['desc'] = T_('Edit your site general options'); $this->data->page['haschild'] = false; break; case 'visitors': if (LogVisitors) { // create for chart $type = \lib\utility::get('type'); $utype = \lib\utility::get('utype'); $this->data->chart_type = $type ? $type : 'column'; $this->data->chart_unique_type = $utype ? $utype : 'areaspline'; $this->data->visitors = $this->model()->visitors(); $this->data->visitors_unique = $this->model()->visitors(true); if ($this->data->visitors <= 1) { $this->data->error = T_("Chart must be contain at least 2 column!"); } } break; case 'home': $this->data->page['title'] = T_('Dashboard'); $this->data->countOf['posts'] = $this->model()->countOf('posts'); $this->data->countOf['pages'] = $this->model()->countOf('pages'); $this->data->countOf['attachments'] = $this->model()->countOf('attachments'); $this->data->countOf['books'] = $this->model()->countOf('books'); $this->data->countOf['tags'] = $this->model()->countOf('tags'); $this->data->countOf['categories'] = $this->model()->countOf('categories'); $this->data->countOf['users'] = $this->model()->countOf('users'); $this->data->bodyclass .= ' unselectable'; // check visitor is new or not $this->data->visitor_new = false; $ref = \lib\router::urlParser('referer', 'sub'); if ($ref !== 'cp' && $ref !== null) { $this->data->visitor_new = true; } if (LogVisitors) { // create for chart $this->data->chart_type = 'column'; $this->data->visitors = $this->model()->visitors(); $this->data->visitors_toppages = $this->model()->visitors_toppages(15); if ($this->data->visitors <= 1) { $this->data->error = T_("Chart must be contain at least 2 column!"); } } break; default: # code... break; } if ($this->data->page['haschild']) { // Check permission and if user can do this operation // allow to do it, else show related message in notify center $myResult = $this->access('cp', $mymodule, 'add'); $this->data->page['haschild'] = $myResult ? true : false; } // $this->data->site['title'] = T_('Control Panel'). ' - ' . $this->data->site['title']; }
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'); }