403Webshell
Server IP : 85.158.181.41  /  Your IP : 216.73.217.12
Web Server : Apache
System : Linux cloud9-vm129 6.1.178+1-ph #ph SMP PREEMPT_DYNAMIC Wed Jul 29 09:00:54 UTC 2026 x86_64
User : moncbefd ( 1024)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/moncbefd/www.moneta.at/system/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/moncbefd/www.moneta.at/system/classes/ConfigurationStorage.inc.php
<?php
/* --------------------------------------------------------------
	ConfigurationStorage.inc.php 2019-06-18
	Gambio GmbH
	http://www.gambio.de
	Copyright (c) 2018 Gambio GmbH
	Released under the GNU General Public License (Version 2)
	[http://www.gnu.org/licenses/gpl-2.0.html]
	--------------------------------------------------------------
*/

/*
CREATE TABLE IF NOT EXISTS `configuration_storage` (
  `key` varchar(255) NOT NULL,
  `value` varchar(255) DEFAULT NULL,
  `last_modified` timestamp NOT NULL DEFAULT '1000-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`key`)
) ENGINE=MyISAM
*/

/**
 * Class ConfigurationStorage
 */
class ConfigurationStorage
{
	const CS_SEPARATOR = '/';
 
	/**
     * @var string
     */
	protected $_namespace;
    
    /**
     * @var bool
     */
	protected $_use_cache;
    
    /**
     * @var CI_DB_query_builder
     */
	protected $queryBuilder;
    
    /**
     * ConfigurationStorage constructor.
     *
     * @param string $p_namespace
     */
	public function __construct($p_namespace = '')
	{
		$this->_namespace = $p_namespace;
		$this->_use_cache = false;
		
		$this->queryBuilder = StaticGXCoreLoader::getDatabaseQueryBuilder();
	}

	/*
	** Create/Update
	*/

	public function set($p_key, $p_value)
	{
        $data = [
            'key' => $this->_make_db_key($p_key),
            'value' => $p_value,
            'last_modified' => date('Y-m-d H:i:s')
        ];
		
		$this->queryBuilder->replace('configuration_storage', $data);
	}

	public function set_all(array $p_tree)
	{
		$t_flat_array = $this->_flatten_array($p_tree);
		foreach($t_flat_array as $t_key => $t_value)
		{
			$this->set($t_key, $t_value);
		}
	}


	/*
	** Read
	*/

	public function get($p_key)
	{
        $value = false;
        
        $result = $this->queryBuilder->select('value')
            ->from('configuration_storage')
            ->where('key', $this->_make_db_key($p_key))
            ->get()
            ->result_array();
        
        
        if (count($result)) {
        
            while ($row = array_shift($result)) {
        
                $value = $row['value'];
            }
        }
        
        return $value;
	}
    
    public function is($p_key)
    {
        $result = $this->get($p_key);
        
        return $result === 1 || $result === true || $result === '1' || $result === 'true';
    }
    
	public function get_all($p_prefix = '')
	{
        $dbKey = $this->_make_db_key($p_prefix);
        
        $result = $this->queryBuilder->select('key, value')->from('configuration_storage')->like('key', $dbKey)
            ->get()->result_array();
        
        $values = [];
        
        if (count($result)) {
            
            while ($row = array_shift($result)) {
                
                $key = str_replace($this->_make_db_key(''), '', $row['key']);
                
                $values[$key] = $row['value'];
            }
        }
        
        return $values;
	}

	public function get_all_tree($p_prefix = '')
	{
		$t_flat = $this->get_all($p_prefix);
		
		return $this->_convert_to_tree_array($t_flat);
	}


	/*
	** Delete
	*/

	public function delete($p_key)
	{
	    $this->queryBuilder->delete('configuration_storage', ['key' => $this->_make_db_key($p_key)]);
	}

	/**
	* deletes entire namespace or a subtree from the namespace
	*/
	public function delete_all($p_prefix = '')
	{
		if($p_prefix != '')
		{
			$t_prefix = $p_prefix . self::CS_SEPARATOR;
		}
		else
		{
			$t_prefix = '';
		}
        
        $this->queryBuilder->like('key', $this->_make_db_key($t_prefix), 'after')
            ->delete('configuration_storage');
	}

	/*
	** Helper functions
	*/

	protected function _make_db_key($p_key)
	{
	    return $this->_namespace . self::CS_SEPARATOR . $p_key;
	}

	protected function _convert_to_tree_array(array $p_flat_array)
	{
		$t_out_array = array();
		foreach($p_flat_array as $t_flat_key => $t_value)
		{
			$t_split_key = explode(self::CS_SEPARATOR, $t_flat_key);
			$t_current_skey = array_shift($t_split_key);
			$t_current_node =& $t_out_array;
			while(empty($t_split_key) !== true)
			{
				if(isset($t_current_node[$t_current_skey]))
				{
					if(is_array($t_current_node[$t_current_skey]) !== true)
					{
						$t_current_node_value = $t_current_node[$t_current_skey];
						$t_current_node[$t_current_skey] = array('_' => $t_current_node_value);
					}
				}
				else
				{
					$t_current_node[$t_current_skey] = array();
				}
				$t_current_node =& $t_current_node[$t_current_skey];
				$t_current_skey = array_shift($t_split_key);
			}
			$t_current_node[$t_current_skey] = $t_value;
		}
		return $t_out_array;
	}

	public function _flatten_array(array $p_tree_array, $p_prefix = '')
	{
		$t_out_array = array();
		if(empty($p_prefix))
		{
			$t_top_prefix = '';
		}
		else
		{
			$t_top_prefix = $p_prefix . self::CS_SEPARATOR;
		}

		foreach($p_tree_array as $t_key => $t_value)
		{
			if(is_array($t_value))
			{
				$t_flattened_sub_tree = $this->_flatten_array($t_value, $t_key);
				foreach($t_flattened_sub_tree as $subtree_key => $subtree_value)
				{
					$t_out_array[$t_top_prefix . $subtree_key] = $subtree_value;
				}
			}
			else
			{
				if($t_key === '_')
				{
					$t_out_array[$p_prefix] = $t_value;
				}
				else
				{
					$t_out_array[$p_prefix . self::CS_SEPARATOR . $t_key] = $t_value;
				}
			}
		}

		return $t_out_array;
	}
}


Youez - 2016 - github.com/yon3zu
LinuXploit