Server IP : 195.201.23.43 / Your IP : 3.147.59.186 Web Server : Apache System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64 User : kdecoratie ( 1041) PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/kdecoratie/public_html/administrator/components/com_admintools/Helper/ |
Upload File : |
<?php /** * @package admintools * @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\AdminTools\Admin\Helper; // Protect from unauthorized access use Exception; use FOF30\Container\Container; use JFactory; use Joomla\Registry\Registry; defined('_JEXEC') or die(); /** * A helper class to handle the storage of configuration values in the database */ class Storage { /** @var Registry The internal values registry */ private $config = null; /** @var Container The component's container */ private $container; /** @var Storage Singleton instance */ static $instance = null; /** * Singleton implementation * * @return Storage */ public static function &getInstance() { if (is_null(static::$instance)) { static::$instance = new Storage(); } return static::$instance; } /** * Storage constructor. */ public function __construct() { $this->container = Container::getInstance('com_admintools'); $this->load(); } /** * Retrieve a value * * @param string $key The key to retrieve * @param mixed $default Default value if the key is not set * * @return mixed The key's value (or the default value) */ public function getValue($key, $default = null) { return $this->config->get($key, $default); } /** * Set a configuration value * * @param string $key Key to set * @param mixed $value Value to set the key to * @param bool $save Should I save everything to database? * * @return mixed The old value of the key */ public function setValue($key, $value, $save = false) { $x = $this->config->set($key, $value); if ($save) { $this->save(); } return $x; } /** * Resets the storage * * @param bool $save Should I save everything to database? */ public function resetContents($save = false) { $this->config->loadArray(array()); if ($save) { $this->save(); } } /** * Load the configuration information from the database * * @return void */ public function load() { $db = $this->container->db; $query = $db->getQuery(true) ->select($db->quoteName('value')) ->from($db->quoteName('#__admintools_storage')) ->where($db->quoteName('key') . ' = ' . $db->quote('cparams')); $db->setQuery($query); $error = 0; try { $res = $db->loadResult(); } catch (Exception $e) { $error = $e->getCode(); } if (method_exists($db, 'getErrorNum') && $db->getErrorNum()) { $error = $db->getErrorNum(); } if ($error) { $res = null; } $this->config = new Registry($res); } /** * Save the configuration information to the database * * @return void */ public function save() { $db = $this->container->db; $data = $this->config->toArray(); $data = json_encode($data); $query = $db->getQuery(true) ->delete($db->quoteName('#__admintools_storage')) ->where($db->quoteName('key') . ' = ' . $db->quote('cparams')); $db->setQuery($query); $db->execute(); $object = (object)array( 'key' => 'cparams', 'value' => $data ); $db->insertObject('#__admintools_storage', $object); } }Private