예제 #1
0
 /**
  * Processes a preference item's new value
  *
  * @param string $key
  *
  * @return mixed
  */
 static function process($key)
 {
     $value = isset($_POST['value']) ? CoreUtils::trim($_POST['value']) : null;
     switch ($key) {
         case "cg_itemsperpage":
             $thing = 'Color Guide items per page';
             if (!is_numeric($value)) {
                 throw new \Exception("{$thing} must be a number");
             }
             $value = intval($value, 10);
             if ($value < 7 || $value > 20) {
                 throw new \Exception("{$thing} must be between 7 and 20");
             }
             break;
         case "p_vectorapp":
             if (!empty($value) && !isset(CoreUtils::$VECTOR_APPS[$value])) {
                 throw new \Exception("The specified app is invalid");
             }
             break;
         case "p_hidediscord":
         case "p_disable_ga":
         case "cg_hidesynon":
         case "cg_hideclrinfo":
             $value = $value ? 1 : 0;
             break;
         case "discord_token":
             Response::fail("You cannot change the {$key} setting");
     }
     return $value;
 }
예제 #2
0
 /**
  * Processes a configuration item's new value
  *
  * @param string $key
  *
  * @return mixed
  */
 static function process($key)
 {
     $value = CoreUtils::trim($_POST['value']);
     if ($value === '') {
         return null;
     }
     switch ($key) {
         case "reservation_rules":
         case "about_reservations":
             $value = CoreUtils::sanitizeHtml($value, $key === 'reservation_rules' ? array('li', 'ol') : array('p'));
             break;
     }
     return $value;
 }
예제 #3
0
파일: Input.php 프로젝트: ponydevs/MLPVC-RR
 /**
  * Creates a class instance based on the settings provided
  * All options are optional and have default fallbacks
  *
  * $o = array(
  *     // Prevents $ERROR_MISSING from being triggered
  *     Input::$IS_OPTIONAL => bool,
  *     // Throw exceptions instead of calling CoreUtils::Respond
  *     Input::$THROW_EXCEPTIONS => bool,
  *     // Range for length/size validation (choose one)
  *     Input::$IN_RANGE => [int],        // input >= int
  *     Input::$IN_RANGE => [int1, int2], // input >= $mix && input <= $max
  *     Input::$IN_RANGE => [null, int],  // input <= int
  *     // Custom error strings
  *     Input::$CUSTOM_ERROR_MESSAGES => array(
  *         Input::$ERROR_MISSING => string,
  *         Input::$ERROR_INVALID => string,
  *         Input::$ERROR_RANGE => string,
  *         'custom' => string,
  *     )
  * )
  *
  * @param string $key
  * @param string $type
  * @param array $o
  *
  * @return Input
  */
 public function __construct($key, $type, $o = null)
 {
     if (isset($o[self::THROW_EXCEPTIONS])) {
         $this->_respond = $o[self::THROW_EXCEPTIONS] === false;
     }
     if ($type instanceof RegExp) {
         $this->_validator = function ($value) use($type) {
             return $type->match($value) ? self::ERROR_NONE : self::ERROR_INVALID;
         };
     } else {
         if (is_callable($type)) {
             $this->_validator = $type;
         } else {
             if (empty(self::$SUPPORTED_TYPES[$type])) {
                 $this->_outputError('Input type is invalid');
             }
         }
     }
     $this->_type = $type;
     if (!is_string($key)) {
         $this->_outputError('Input key missing or invalid');
     }
     $this->_key = $key;
     $this->_silentFail = isset($o[self::SILENT_FAILURE]) && $o[self::SILENT_FAILURE] === true;
     $this->_source = $SRC = isset($o[self::METHOD_GET]) && $o[self::METHOD_GET] === true ? '_GET' : '_POST';
     $_SRC = $GLOBALS[$SRC];
     if (!isset($_SRC[$key]) || CoreUtils::length($_SRC[$key]) === 0) {
         $result = empty($o[self::IS_OPTIONAL]) ? self::ERROR_MISSING : self::ERROR_NONE;
     } else {
         $this->_value = $this->_type === 'text' ? CoreUtils::trim($_SRC[$key], true) : CoreUtils::trim($_SRC[$key]);
         $this->_origValue = $this->_value;
         $this->_range = $o[self::IN_RANGE] ?? null;
         $result = $this->_validate();
     }
     if ($result !== self::ERROR_NONE) {
         $this->_outputError(!empty($o[self::CUSTOM_ERROR_MESSAGES][$result]) ? $o[self::CUSTOM_ERROR_MESSAGES][$result] : "Error wile checking \${$SRC}['{$this->_key}'] (code {$result})", $result);
     }
 }