public function create($link = '', $lang = '') { $hideDefaultLanguage = Config::get('options/hide_default_language') ? true : false; if (!$link) { $url = $this->clean('http://' . $this->_domin . $_SERVER['PHP_SELF']); //$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); if ($hideDefaultLanguage && $lang == defualtLang()) { return $url; } if ($this->_query) { return $url . '&lang=' . $lang; } return $url . '?lang=' . $lang; } if ($this->validUrl($link)) { if (!$lang) { $lang = currentLang(); } $link = $this->clean($link); if ($hideDefaultLanguage && $lang == defualtLang()) { return $link; } if ($this->_query) { return $link . '&lang=' . $lang; } return $link . '?lang=' . $lang; } return $link . '?lang=' . $lang; //return false; }
function internalRequestURI() : string { $requestUri = currentUri() ? str_replace(DIRECTORY_INDEX . '/', '', currentUri()) : substr(server('currentPath'), 1); if (isset($requestUri[strlen($requestUri) - 1]) && $requestUri[strlen($requestUri) - 1] === '/') { $requestUri = substr($requestUri, 0, -1); } $requestUri = internalCleanInjection(internalRouteURI($requestUri)); $requestUri = internalCleanURIPrefix($requestUri, currentLang()); if (defined('_CURRENT_PROJECT')) { $requestUri = internalCleanURIPrefix($requestUri, _CURRENT_PROJECT); } return $requestUri; }
/** * DBContent::__construct() * initialize variables values * @return void */ public function __construct() { // get languages json files path $this->_langFile = Config::get('paths/lang_files'); // check if file language exist if ($this->getLangFile(currentLang())) { // set the language = current language $this->_theLang = currentLang(); } else { // set defulat language $this->_theLang = defualtLang(); } // open language .json file $this->getCurrentLanguageFile(); }
function prevPath(bool $isPath = true) : string { if (!isset($_SERVER['HTTP_REFERER'])) { return false; } $str = str_replace(sslStatus() . host() . BASE_DIR . indexStatus(), '', $_SERVER['HTTP_REFERER']); if (currentLang()) { $str = explode("/", $str); return $str[1]; } if ($isPath === true) { return $str; } else { $str = explode("/", $str); $count = count($str); if ($count > 1) { return $str[$count - 1]; } return $str[0]; } }
public function get($table, $id = '') { if (Config::get('options/hide_untranslated') == true) { if ($id) { if ($this->checkIfContentExistInCurrentLanguage($table, $id)) { $sql = "SELECT * FROM {$this->_tableName} WHERE id = {$id} AND lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { return $this->_results[0]; } return false; } elseif (Config::get('options/alert_user_available_lang') == true) { return notValiableMessage(currentLang()) . $this->valiableLang(); } } else { $sql = "SELECT * FROM {$this->_tableName} WHERE lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { return $this->_results; } return false; } } else { if ($id) { if ($this->checkIfContentExistInCurrentLanguage($table, $id)) { $sql = "SELECT * FROM {$this->_tableName} WHERE id = {$id} AND lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { return $this->_results[0]; } } else { /* $sql = "SELECT * FROM {$this->_tableName} WHERE id = {$id} AND lang = '" . defualtLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if($this->$correctFunctionName($sql)) { if(count($this->_results)) { return $this->_results[0]; } else { if(Config::get('options/alert_user_available_lang') == true) { return notValiableMessage(currentLang()) . $this->valiableLang(); } } }*/ return notValiableMessage(currentLang()) . $this->valiableLang(); } } else { $sql = "SELECT * FROM {$this->_tableName} WHERE lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { $inCurrentLang = $this->_results; $sql = "SELECT * FROM {$this->_tableName} WHERE lang <> '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; $this->{$correctFunctionName}($sql); $postsNotTraslated = $this->_results; $x = 0; foreach ($postsNotTraslated as $c) { if ($this->valiableLang($c['id'], $table) == false) { unset($postsNotTraslated[$x]); } else { $postsNotTraslated[$x]['title'] = $c['title'] . '<small>' . $this->valiableLang($c['id'], $table) . '</small>'; } $x++; } $results = array_merge((array) $postsNotTraslated, (array) $inCurrentLang); usort($results, function ($a, $b) { return $a['id'] - $b['id']; }); return $results; } return false; } } }
function prevPath($isPath = true) { if (!is_bool($isPath)) { $isPath = true; } $str = str_replace(sslStatus() . host() . BASE_DIR . indexStatus(), '', server("referer")); if (currentLang()) { $str = explode("/", $str); return $str[1]; } if ($isPath === true) { return $str; } else { $str = explode("/", $str); $count = count($str); if ($count > 1) { return $str[$count - 1]; } return $str[0]; } }
/** * this main function for this class (only this function is public!!) * get correct content from tables in currect language * @param string $table * @param number $id * @return mixed */ public function get($table, $id = '') { // check if hide untranslated option is enabled if (Config::get('options/hide_untranslated') == true) { // check if $id is set if ($id) { // check if post is exist in current language or not if ($this->checkIfContentExistInCurrentLanguage($table, $id)) { // create select statement $sql = "SELECT * FROM {$this->_tableName} WHERE id = {$id} AND lang = '" . currentLang() . "'"; // create function name we need $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { // return first record return $this->_results[0]; } // this else return to if in line 278 - if($this->$correctFunctionName($sql)) // check if alert_user_available_lang is enabled alert user (this post not avaliable in his language and get him links for post in a valiable languages) } elseif (Config::get('options/alert_user_available_lang') == true) { return notValiableMessage(currentLang()) . $this->valiableLang(); } // this else return for if in line 272 - if($id) } else { // if $id not set so the user in home/blog page then get all posts // create select statement $sql = "SELECT * FROM {$this->_tableName} WHERE lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { return $this->_results; } // if not returnd anything then we have error in calling function then return false.. return false; } // this else return to line 270 - if(Config::get('options/hide_untranslated') == true) // if hide_untranslated option is desabled } else { // if $id set if ($id) { // check if post is exist in current language or not if ($this->checkIfContentExistInCurrentLanguage($table, $id)) { // create select statement $sql = "SELECT * FROM {$this->_tableName} WHERE id = {$id} AND lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { return $this->_results[0]; } } else { // this noted code , to get posts in defualte language if it not exist in current language you can enabled this code and remove (return notValiableMessage(currentLang()) . $this->valiableLang();) in line 331 /* $sql = "SELECT * FROM {$this->_tableName} WHERE id = {$id} AND lang = '" . defualtLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if($this->$correctFunctionName($sql)) { if(count($this->_results)) { return $this->_results[0]; } else { if(Config::get('options/alert_user_available_lang') == true) { return notValiableMessage(currentLang()) . $this->valiableLang(); } } }*/ // return this post is not a valiable in current language and links for post in a valiable in languages return notValiableMessage(currentLang()) . $this->valiableLang(); } } else { // create select statement to get all contents in current language $sql = "SELECT * FROM {$this->_tableName} WHERE lang = '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; if ($this->{$correctFunctionName}($sql)) { /** * @var array $inCurrentLang save all contents in current language */ $inCurrentLang = $this->_results; // get all contents in other languages $sql = "SELECT * FROM {$this->_tableName} WHERE lang <> '" . currentLang() . "'"; $correctFunctionName = $this->_dbType . 'Query'; $this->{$correctFunctionName}($sql); /** * @var array $postsNotTraslated to save all contents in other languages */ $postsNotTraslated = $this->_results; /** * @var int $x counter */ $x = 0; foreach ($postsNotTraslated as $c) { // remove record from $postsNotTraslated if content avalible in current language if ($this->valiableLang($c['id'], $table) == false) { unset($postsNotTraslated[$x]); } else { // if this content is not a valiable in current language add hint for user to valiable language $postsNotTraslated[$x]['title'] = $c['title'] . '<small>' . $this->valiableLang($c['id'], $table) . '</small>'; } $x++; } /** * @var array $results merge $inCurrentLang and $postsNotTraslated and store it by id number (you can change this to date or anything else!) */ $results = array_merge((array) $postsNotTraslated, (array) $inCurrentLang); usort($results, function ($a, $b) { return $a['id'] - $b['id']; }); return $results; } return false; } } }
/** * * @param stirng $link * @param stribg $lang * @return string */ public function create($link = '', $lang = '') { // check if hide_default_language option is enabled $hideDefaultLanguage = Config::get('options/hide_default_language') ? true : false; // check if $link is empty if (!$link) { // create link (current page) $url = $this->clean('http://' . $this->_domin . $_SERVER['PHP_SELF']); //$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); // if hide_default_language option is enabled and $lang is defualte language return same link if ($hideDefaultLanguage && $lang == defualtLang()) { return $url; } // check if url have query string if ($this->_query) { return $url . '&lang=' . $lang; } return $url . '?lang=' . $lang; } // check if $link is a valide URL if ($this->validUrl($link)) { // if $lang is emty set it current language if (!$lang) { $lang = currentLang(); } // clean link $link = $this->clean($link); // if $hideDefaultLanguage is true and $lang is default language return same link if ($hideDefaultLanguage && $lang == defualtLang()) { return $link; } // if $_query is true if ($this->_query) { return $link . '&lang=' . $lang; } return $link . '?lang=' . $lang; } return $link . '?lang=' . $lang; //return false; }
function prevUrl() : string { if (!isset($_SERVER['HTTP_REFERER'])) { return false; } $str = str_replace(sslStatus() . host() . BASE_DIR . indexStatus(), "", $_SERVER['HTTP_REFERER']); if (currentLang()) { $strEx = explode("/", $str); $str = str_replace($strEx[0] . "/", "", $str); } return siteUrl(internalCleanInjection($str)); }
</div> <div class="clear"></div> <?php } ?> </div> </div> <!-- /.container --> <script src="assets/js/jquery-1.9.1.min.js"></script> <script src="assets/js/bootstrap.js"></script> <script src="assets/js/bootstrap.min.js"></script> <script src="assets/js/sweet-alert.js"></script> <script src="assets/js/sweet-alert.min.js"></script> <script type="text/javascript"> <?php if (currentLang() !== Detect::browser()) { if (!in_array(Detect::browser(), enabledLanguagesList())) { ?> swal({title: '<?php __("Browser Language", Detect::browser()); echo '-' . languageNameIntongue(Detect::browser()) . '!'; ?> ', text: "Sorry Your Browser Language Not Supported", imageUrl: "assets/sad.png" }); <?php } else { ?> swal({title: '<?php __("Browser Language", Detect::browser());
function getDir($lang = '') { if (!$lang) { $lang = currentLang(); } echo Config::get('lang_dir/' . strtolower($lang)); }