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; } } }
/** * 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; } } }