| Server IP : 37.9.174.138 / Your IP : 216.73.216.117 Web Server : Apache System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64 User : ftpuser ( 1001) PHP Version : 8.4.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/ttjs.cz/dev/app/classes/ |
Upload File : |
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace app\classes;
/**
* Description of ModuleConfig
*
* @author maros
*/
class ModuleConfig {
protected $moduleName;
protected $app;
protected $config;
protected $incConfigs = array();
protected $basePath;
CONST PERMISSIONS = "permissions";
public function __construct($class) {
$this->app = \App::getInstance();
if (is_object($class)) {
$rc = new \ReflectionClass(get_class($class));
$fullPath = dirname($rc->getFileName());
} else {
$fullPath = str_replace("\\", "/", $class);
}
$modulePath = substr($fullPath, strpos($fullPath, "modules/") + 8);
$this->moduleName = substr($modulePath, 0, strpos($modulePath, "/")) . "_module";
$this->config = $this->app->getConfig($this->moduleName);
if ($this->config === false) {
$this->app->addConfigVariable($this->moduleName, array());
$this->config = array();
}
$this->basePath = DOCUMENT_ROOT . "modules/" . substr($modulePath, 0, strpos($modulePath, "/")) . "/";
}
public function getConfig($key) {
if (key_exists($key, $this->config)) {
return $this->config[$key];
}
return $this->getIncConfig("temp", $key);
}
public function setConfig($key, $val) {
if (!key_exists($key, $this->config)) {
$this->addConfigVariable($key);
}
$this->config[$key] = $val;
$this->app->setConfig($this->moduleName, $this->config);
return true;
}
public function addConfigVariable($key, $val = "") {
if (key_exists($key, $this->config)) {
return false;
}
$this->config[$key] = $val;
$this->app->setConfig($this->moduleName, $this->config);
return true;
}
public function getIncConfig($scope = false, $key = false, $configFile = "config") {
$config = array();
if (key_exists($configFile, $this->incConfigs)) {
$config = &$this->incConfigs[$configFile];
} else if (file_exists($this->basePath . $configFile . ".ini")) {
$this->incConfigs[$configFile] = parse_ini_file($this->basePath . $configFile . ".ini", true, INI_SCANNER_TYPED);
$config = &$this->incConfigs[$configFile];
}
if ($scope === false) {
return count($config) === 0 ? false : $config;
}
if ($key === false) {
return key_exists($scope, $config) ? $config[$scope] : false;
}
return key_exists($scope, $config) && key_exists($key, $config[$scope]) ? $config[$scope][$key] : false;
}
protected function hasPermissions($scope, $type = false) {
if ($type !== false) {
return isset($this->config["permissions"]) && isset($this->config["permissions"][$scope]) && in_array($type, $this->config["permissions"][$scope]);
}
try {
$user = BasicUser::getLoggedUser();
$type = $user->_get("type");
return isset($this->config["permissions"]) && isset($this->config["permissions"][$scope]) && in_array($type, $this->config["permissions"][$scope]);
} catch (\Exception $ex) {
}
return false;
}
public function hasReadPermissions($type = false) {
return $this->hasPermissions("R", $type);
}
public function hasWritePermissions($type = false) {
return $this->hasPermissions("W", $type);
}
public function verifyReadPermissions() {
if (!$this->hasReadPermissions()) {
throw new \Exception(\app\constants\ResponseCodes::ACCESS_DENIED, \app\constants\ResponseCodes::ACCESS_DENIED);
}
}
public function verifyWritePermissions() {
if (!$this->hasWritePermissions()) {
throw new \Exception(\app\constants\ResponseCodes::ACCESS_DENIED, \app\constants\ResponseCodes::ACCESS_DENIED);
}
}
public function getBasePath() {
return $this->basePath;
}
}