-
-
Save reactmore/9f1d1b68e0efa86201ca2696a131af17 to your computer and use it in GitHub Desktop.
Reactmore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Config; | |
use CodeIgniter\Config\BaseConfig; | |
class Reactmore extends BaseConfig | |
{ | |
public array $app_settings_array = array( | |
"app_version" => "1.1.0", | |
); | |
public array $app_csrf_exclude_uris = array( | |
"notification_processor/create_notification", | |
); | |
private $db; | |
public $settings; | |
public $generalSettings; | |
public $navigation; | |
public $customRoutes; | |
public $themes; | |
public $languages; | |
public $rolesPermissions; | |
public $defaultLang; | |
public $languageTranslations; | |
public $activeLang; | |
public $langBaseUrl = ""; | |
public $authCheck = false; | |
public $authUser = null; | |
public $impersonateCheck = false; | |
public $authImpersonate = null; | |
public function __construct() | |
{ | |
$this->db = \Config\Database::connect(); | |
$this->app_csrf_exclude_uris = app_hooks()->apply_filters('app_filter_app_csrf_exclude_uris', $this->app_csrf_exclude_uris); | |
$this->setGlobalConfigurations(); | |
} | |
private function setGlobalConfigurations() | |
{ | |
$session = \Config\Services::session(); | |
// Get General Settings | |
$this->generalSettings = $this->db->table('general_settings')->where('id', 1)->get()->getRow(); | |
// Get Settings | |
$this->settings = $this->db->table('settings')->where('id', 1)->get()->getRow(); | |
// Get Navigation | |
$this->navigation = $this->db->table('navigation')->where('id', 1)->get()->getRow(); | |
// Get Custom Routes | |
$this->customRoutes = $this->db->table('routes')->get()->getRow(); | |
// Get Themes | |
$this->themes = $this->db->table('themes')->get()->getResult(); | |
// Get languages | |
$this->languages = $this->db->table('languages')->where('status', 1)->get()->getResult(); | |
// Get roles permissions | |
$this->rolesPermissions = $this->db->table('roles_permissions')->get()->getResult(); | |
//set timezone | |
if (!empty($this->generalSettings->timezone)) { | |
config('App')->appTimezone = $this->generalSettings->timezone; | |
date_default_timezone_set($this->generalSettings->timezone); | |
} | |
//set active language | |
$this->defaultLang = $this->db->table('languages')->where('id', $this->generalSettings->site_lang)->get()->getRow(); | |
if (empty($this->defaultLang)) { | |
$this->defaultLang = $this->db->table('languages')->get()->getFirstRow(); | |
} | |
$langSegment = getSegmentValue(1); | |
$langId = null; | |
if (!empty($this->languages)) { | |
foreach ($this->languages as $lang) { | |
if ($langSegment == $lang->short_form) { | |
$langId = $lang->id; | |
break; | |
} | |
} | |
} | |
if (empty($langId)) { | |
$langId = $this->defaultLang->id; | |
} | |
self::setActiveLanguage($langId); | |
if (empty($this->activeLang)) { | |
$this->activeLang = $this->defaultLang; | |
} | |
$session->set('activeLangId', $this->activeLang->id); | |
service('request')->setLocale($this->activeLang->short_form); | |
//set language base URL | |
$this->langBaseUrl = base_url($this->activeLang->short_form); | |
if ($this->activeLang->id == $this->defaultLang->id) { | |
$this->langBaseUrl = base_url(); | |
} | |
//authentication | |
if (!empty($session->get('more_ses_id')) && !empty($session->get('more_ses_role')) && !empty($session->get('more_ses_pass'))) { | |
$user = $this->db->table('users')->where('id', cleanNumber($session->get('more_ses_id')))->get()->getRow(); | |
if (!empty($user) && md5($user->password ?? '') == $session->get('more_ses_pass')) { | |
$this->authCheck = true; | |
$this->authUser = $user; | |
} | |
} | |
//Impersonate | |
if (!empty($session->get('more_oldses_id')) && !empty($session->get('more_oldses_role')) && !empty($session->get('more_oldses_pass'))) { | |
$impersonateUser = $this->db->table('users')->where('id', cleanNumber($session->get('more_oldses_id')))->get()->getRow(); | |
if (!empty($impersonateUser) && md5($impersonateUser->password ?? '') == $session->get('more_oldses_pass')) { | |
$this->impersonateCheck = true; | |
$this->authImpersonate = $impersonateUser; | |
} | |
} | |
} | |
public function setActiveLanguage($langId) | |
{ | |
if (!empty($this->languages)) { | |
foreach ($this->languages as $lang) { | |
if ($langId == $lang->id) { | |
$this->activeLang = $lang; | |
//set language translations | |
$this->languageTranslations = $this->db->table('language_translations')->where('lang_id', $this->activeLang->id)->get()->getResult(); | |
$arrayTranslations = array(); | |
if (!empty($this->languageTranslations)) { | |
foreach ($this->languageTranslations as $item) { | |
$arrayTranslations[$item->label] = $item->translation; | |
} | |
} | |
$this->languageTranslations = $arrayTranslations; | |
break; | |
} | |
} | |
} | |
} | |
public function updateLangBaseURL($shortForm) | |
{ | |
$this->langBaseUrl = base_url($shortForm); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment