'key', 'key' => 'longstring', 'value' => 'longstring', ); /** * Get all configurations from database OR session if it was yet loaded * This function is called at start of program and global var '$conf' is filled with response, so use global $conf instead of call this function. * #### Example * ```php * $confs = Configuration::getAll(); * var_dump($confs); * ```. * @return array Array of configurations */ public function getAll() { if (!isset($_SESSION['configuration'])) { $configurationManager = new self(); $configs = $configurationManager->loadAll(); $confTab = array(); foreach ($configs as $config) { $this->confTab[$config->key] = decrypt($config->value); } $_SESSION['configuration'] = serialize($this->confTab); } else { $this->confTab = unserialize($_SESSION['configuration']); } } //Définit / récupere un set de configurations générique public static function setting($name,$settings=null){ if(!isset($settings)) return isset($GLOBALS['setting'][$name]) ? $GLOBALS['setting'][$name] : array(); $GLOBALS['setting'][$name] = $settings; } //Met en page (tableau html) un set de configuration générique public static function html($name){ global $conf; $options = isset($GLOBALS['setting'][$name]) ? $GLOBALS['setting'][$name] : array(); ?> $infos): $input = ''; if(!is_array($infos)): ?>

- get($key); $attributes['value'] = 'value="'.(isset($infos['default']) && empty($confValue) ? htmlentities($infos['default']) : htmlentities($confValue)).'"'; if(isset($infos['parameters'])){ foreach($infos['parameters'] as $attribute=>$parameter){ if(isset($attributes[$attribute])) continue; $attributes[$attribute] = $attribute.'="'.$parameter.'"'; } } switch($infos['type']){ case 'password': $attributes['type'] = 'data-type="password"'; $input = ''; break; case 'dictionnary': $attributes['type'] = 'data-type="dictionnary"'; $attributes['parameters'] = 'data-slug="'.$infos['slug'].'"'; $input = ' Activer'; break; case 'select': unset($attributes['value']); $input = ''; break; case 'user': $attributes['data-type'] = 'data-type="user"'; $input = ''; break; case 'rank': $attributes['data-type'] = 'data-type="user" data-types="rank"'; $input = ''; break; case 'number': $input = ''; break; case 'hour': $input = ''; break; case 'date': $input = ''; break; case 'textarea': $input = ''; break; case 'wysiwyg': $attributes['data-type'] = 'data-type="wysiwyg"'; $attributes['class'] = 'class="m-0"'; unset($attributes['value']); $input = ''; break; case 'file': //Si input file "multiple", possibilité de normlaiser le //tableau $_FILES récupéré avec la fonction => normalize_php_files(); unset($attributes['class']); $input = ''; break; case 'dropzone': $attributes['id'] = 'id="document"'; $documents = preg_replace("/documents=\"(.*)\"/i", "$1", $attributes['documents']); unset($attributes['documents']); $input = '
'.$documents.'
'; break; default: Plugin::callHook('configuration_fields',array(&$input, $infos, $attributes)); if(empty($input)) $input = ''; break; } echo $input; ?>
get('myConfigKey'); // print myConfigKey value * ```. * @param string configuration key * @param string configuration namespace (default is 'conf') * * @return string valeur de la configuration */ public function get($key) { return isset($this->confTab[$key]) ? htmlspecialchars_decode($this->confTab[$key]) : ''; } /** * Update or insert configuration value in database with specified key * #### Example * ```php * global $conf; // global var, contain configurations * echo $conf->put('myNewConfigKey','hello!'); //create configuration myNewConfigKey with value 'hello!' * echo $conf->put('myNewConfigKey','hello 2!'); //update configuration myNewConfigKey with value 'hello2!' * ```. * * @param string configuration key * @param string configuration value * @param string configuration namespace (default is 'conf') */ public function put($key, $value) { $secured_value = encrypt($value); $configurationManager = new self(); if (isset($this->confTab[$key])) { $configurationManager->change(array('value' => $secured_value), array('key' => $key)); } else { $configurationManager->add($key, $secured_value); } $this->confTab[$key] = $value; unset($_SESSION['configuration']); } /** * Remove configuration value in database with specified key * #### Example * ```php * global $conf; // global var, contain configurations * echo $conf->remove('myNewConfigKey'); //delete myNewConfigKey from 'conf' default namespace * echo $conf->remove('myNewConfigKey','myCustomPluginConfig'); //delete myNewConfigKey from 'myCustomPluginConfig' namespace * ```. * * @param string configuration key * @param string configuration namespace (default is 'conf') */ public function add($key, $value) { $config = new self(); $config->key = $key; $config->value = $value; $config->save(); $this->confTab[$key] = $value; unset($_SESSION['configuration']); } }