Example #1
0
 /**
  * Check the validity of the field based on the data submitted. Note that
  * this validation is performed on the wire data - i.e. that which is
  * submitted, before any setFormatter is run
  *
  * Called by the Editor / Join class instances - not expected for general
  * consumption - internal.
  *  @param array $data Data submitted from the client-side 
  *  @param Editor $editor Editor instance
  *  @return boolean Indicate if a field is valid or not.
  *  @internal
  */
 public function validate($data, $editor)
 {
     // Three cases for the validator - closure, string or null
     if (!$this->_validator) {
         return true;
     }
     $val = $this->_readProp($this->name(), $data);
     if (is_string($this->_validator)) {
         $processData = $editor->inData();
         $instances = array('action' => $processData['action'], 'id' => isset($processData['id']) ? str_replace($editor->idPrefix(), '', $processData['id']) : null, 'field' => $this, 'editor' => $editor, 'db' => $editor->db());
         // Don't require the Editor namespace if DataTables validator is given as a string
         if (strpos($this->_validator, "Validate::") === 0) {
             return call_user_func("\\DataTables\\Editor\\" . $this->_validator, $val, $data, $this->_validatorOpts, $instances);
         }
         return call_user_func($this->_validator, $val, $data, $this->_validatorOpts, $instances);
     }
     $validator = $this->_validator;
     return $validator($val, $data, $this);
 }
Example #2
0
 /**
  * Check the validity of the field based on the data submitted. Note that
  * this validation is performed on the wire data - i.e. that which is
  * submitted, before any setFormatter is run
  *
  * Called by the Editor / Join class instances - not expected for general
  * consumption - internal.
  *
  * @param array $data Data submitted from the client-side 
  * @param Editor $editor Editor instance
  * @param * $id Row id that is being validated
  * @return boolean|string `true` if valid, string with error message if not
  * @internal
  */
 public function validate($data, $editor, $id = null)
 {
     // Three cases for the validator - closure, string or null
     if (!count($this->_validator)) {
         return true;
     }
     $val = $this->_readProp($this->name(), $data);
     for ($i = 0, $ien = count($this->_validator); $i < $ien; $i++) {
         $validator = $this->_validator[$i];
         $processData = $editor->inData();
         $instances = array('action' => $processData['action'], 'id' => $id, 'field' => $this, 'editor' => $editor, 'db' => $editor->db());
         if (is_string($validator['func'])) {
             // Don't require the Editor namespace if DataTables validator is given as a string
             if (strpos($validator['func'], "Validate::") === 0) {
                 $res = call_user_func("\\DataTables\\Editor\\" . $validator['func'], $val, $data, $validator['opts'], $instances);
             } else {
                 $res = call_user_func($validator['func'], $val, $data, $validator['opts'], $instances);
             }
         } else {
             $func = $validator['func'];
             $res = $func($val, $data, $this, $instances);
         }
         // Check if there was a validation error and if so, return it
         if ($res !== true) {
             return $res;
         }
     }
     // Validation methods all run, must be valid
     return true;
 }
Example #3
0
 /**
  * Execute an upload
  *
  * @param  \DataTables\Editor $editor Calling Editor instance
  * @return int Primary key value
  * @internal
  */
 public function exec($editor)
 {
     $id = null;
     $upload = $_FILES['upload'];
     // Validation - PHP standard validation
     if ($upload['error'] !== UPLOAD_ERR_OK) {
         if ($upload['error'] === UPLOAD_ERR_INI_SIZE) {
             $this->_error = "File exceeds maximum file upload size";
         } else {
             $this->_error = "There was an error uploading the file (" . $upload['error'] . ")";
         }
         return false;
     }
     // Validation - acceptable file extensions
     if (is_array($this->_extns)) {
         $extn = pathinfo($upload['name'], PATHINFO_EXTENSION);
         if (in_array(strtolower($extn), array_map('strtolower', $this->_extns)) === false) {
             $this->_error = $this->_extnError;
             return false;
         }
     }
     // Validation - custom callback
     for ($i = 0, $ien = count($this->_validators); $i < $ien; $i++) {
         $res = $this->_validators[$i]($upload);
         if (is_string($res)) {
             $this->_error = $res;
             return false;
         }
     }
     // Database
     if ($this->_dbTable) {
         foreach ($this->_dbFields as $column => $prop) {
             // We can't know what the path is, if it has moved into place
             // by an external function - throw an error if this does happen
             if (!is_string($this->_action) && ($prop === self::DB_SYSTEM_PATH || $prop === self::DB_WEB_PATH)) {
                 $this->_error = "Cannot set path information in database " . "if a custom method is used to save the file.";
                 return false;
             }
         }
         // Commit to the database
         $id = $this->_dbExec($editor->db());
     }
     // Perform file system actions
     return $this->_actionExec($id);
 }