public static function save($value, $type, $standard = null)
 {
     $var = $standard;
     if ($value !== null) {
         if ($type == VAR_DB || $type == VAR_ARR_DB) {
             $var = Sanitize::saveDb($value);
         } elseif ($type == VAR_HTML || $type == VAR_ARR_HTML) {
             $var = Sanitize::saveHTML($value);
         } elseif ($type == VAR_INT || $type == VAR_ARR_INT) {
             $var = Sanitize::saveInt($value);
         } elseif ($type == VAR_ALNUM || $type == VAR_ARR_ALNUM) {
             $var = Sanitize::saveAlNum($value, true);
         } elseif ($type == VAR_URI || $type == VAR_ARR_URI) {
             $var = Sanitize::saveAlNum($value, false);
         } else {
             $var = Sanitize::removeNullByte($value);
         }
     } else {
         if ($standard === null) {
             if ($type == VAR_DB || $type == VAR_ALNUM || $type == VAR_HTML || $type == VAR_URI) {
                 $var = '';
             } elseif ($type == VAR_INT) {
                 $var = 0;
             } elseif ($type == VAR_ARR_INT || $type == VAR_ARR_DB || $type == VAR_ARR_ALNUM || $type == VAR_ARR_NONE || $type == VAR_ARR_HTML || $type == VAR_ARR_URI) {
                 $var = array();
             } else {
                 $var = null;
             }
         }
     }
     return $var;
 }
Ejemplo n.º 2
0
 /**
  * Updates the value for the configuration key specified as parameter.
  *
  * If the third parameter is null (it is the default value) the script tries to get
  * the value by name (without group!) from the input data (query string). If no data is found
  * the default value from Variables::get() for the specified type will be used.
  *
  * This function throws a notice if the key is not found.
  *
  * The data won't be saved by this function! You have to call Config::save() for this!
  *
  * @see Variables::get()
  * @see Config::save()
  * @param string Config key in the format Group.Key
  * @param int Type of variable (one of the standard types that are accepted by Request::get().
  * @param mixed Value to change to specified config key.
  **/
 public static function set($key, $type = VAR_NONE, $value = null)
 {
     if (self::$data == null) {
         self::baseConfig();
     }
     list($sgroup, $name) = explode('.', $key, 2);
     if ($value == null) {
         $value = Request::get($name, $type);
     }
     if (isset(self::$data[$key]) == true) {
         self::$data[$key] = $value;
         if ($type == VAR_INT || $type == VAR_ARR_INT) {
             $value = Sanitize::saveInt($value);
         }
         self::$changes[$key] = array('key' => $key, 'value' => $value, 'type' => $type);
     } else {
         Core::throwError("Config::set() - Specified key does not exist.");
     }
 }