/** * @see sfValidatorFile */ protected function doClean($value) { $clean = parent::doClean($value); $size = @getimagesize($clean->getTempName()); if (!$size && !$this->getOption('is_only_image')) { return $clean; } if (!$size) { throw new sfValidatorError($this, 'invalid_image', array('value' => $value['name'])); } list($width, $height) = $size; if ($this->getOption('max_height') < $height) { throw new sfValidatorError($this, 'max_height', array('value' => $value['name'], 'max_height' => $this->getOption('max_height'))); } if ($this->getOption('min_height') > $height) { throw new sfValidatorError($this, 'min_height', array('value' => $value['name'], 'min_height' => $this->getOption('min_height'))); } if ($this->getOption('max_width') < $width) { throw new sfValidatorError($this, 'max_width', array('value' => $value['name'], 'max_width' => $this->getOption('max_width'))); } if ($this->getOption('min_width') > $width) { throw new sfValidatorError($this, 'min_width', array('value' => $value['name'], 'min_width' => $this->getOption('min_width'))); } return $clean; }
protected function doClean($value) { // Getting uploaded file (still in tmp at this stage) $validatedFile = parent::doClean($value); // Loading BitTorrent class require "../lib/bittorrent/Autoload.php"; // Open a new torrent instance $torrent = new PHP_BitTorrent_Torrent(); // Loading it $torrent->loadFromTorrentFile($validatedFile->getTempName()); // Generating hash $hash = sha1(PHP_BitTorrent_Encoder::encode($torrent->getInfo())); // I want to use this hash outside this class, not clean at all, shame on me ^^ define('HASH', $hash); define('SIZE', $torrent->getSize()); // Looking if hash is already posted $sh = Doctrine_Query::create()->select('COUNT(*)')->from("Uploads")->where("hash = ?", $hash)->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR); if ($sh > 0) { throw new sfValidatorError($this, 'already', array('hash' => $hash)); } // Private mode $i = $torrent->getInfo(); if ($this->getOption('private') != $i['private']) { throw new sfValidatorError($this, 'private', array('private' => $this->getOption('private'))); } // Checking if announce URL is correct /*if ($this->getOption('announce') != $torrent->getAnnounce()) throw new sfValidatorError($this, 'announce', array('announce' => $this->getOption('announce'))); */ return $validatedFile; }
/** * @see sfValidatorBase */ protected function doClean($value) { $clean = array(); foreach ($value as $file) { $clean[] = parent::doClean($file); } return $clean; }
protected function doClean($value) { try { return parent::doClean($value); } catch (sfValidatorError $e) { if ($e->getCode() == 'max_size') { $arguments = $e->getArguments(true); throw new sfValidatorError($this, 'max_size', array('max_size' => opConfig::get('image_max_filesize'), 'size' => $arguments['size'])); } throw $e; } }
protected function doClean($value) { $file = parent::doClean($value); if ($file instanceof sfValidatedFile) { try { $client = new Google_Client(); $client->setAuthConfigFile($file->getTempName()); } catch (Google_Exception $e) { throw new sfValidatorError($this, (string) $e); } } return $file; }
protected function doClean($value) { $value = parent::doClean($value); if ($this->hasOption('allowed_extensions')) { $extensions = $this->getOption('allowed_extensions'); if (!is_array($extensions)) { $extensions = array($extensions); } if (!in_array(ltrim($value->getOriginalExtension(), '.'), $extensions)) { throw new sfValidatorError($this, 'invalid_extension'); } } return $value; }
protected function doClean($value) { //ftheeten 2016 02 22 $disableXSDValidation = sfConfig::get('dw_disableXSDValidation'); parent::doClean($value); libxml_use_internal_errors(true); $xml = new DOMDocument(); $errorSchema = new sfValidatorErrorSchema($this); $errorSchemaLocal = new sfValidatorErrorSchema($this); if (!file_exists($value['tmp_name'])) { throw new sfValidatorError($this, 'unreadable_file'); } if (!$xml->load($value['tmp_name'])) { throw new sfValidatorError($this, 'unreadable_file'); } //ftheeten 2016 02 22 to disable the validation of XML (aim is avoiding resolving external schemas) if ($disableXSDValidation === false) { if (!$xml->schemaValidate(sfConfig::get('sf_web_dir') . $this->getOption('xml_path_file'))) { $errorSchemaLocal->addError(new sfValidatorError($this, 'invalid_format'), 'invalid_format_ABCD'); $errors = libxml_get_errors(); $i = 0; foreach ($errors as $error) { $error_msg = $this->displayXmlError($error); $errorSchemaLocal->addError(new sfValidatorError($this, $error_msg), 'invalid_line'); if ($i++ > 100) { break; } } libxml_clear_errors(); if (count($errorSchemaLocal)) { $errorSchema->addError($errorSchemaLocal); } if (count($errorSchema)) { throw new sfValidatorErrorSchema($this, $errorSchema); } } } $class = $this->getOption('validated_file_class'); return new $class($value['name'], 'text/xml', $value['tmp_name'], $value['size'], $this->getOption('path')); }
/** * Check dimensions, perform resize and then call parent validator. * * @param array $value * @return sfValidatedFile */ protected function doClean($value) { $file = parent::doClean($value); // resize the image by default if ($this->getOption('resize')) { // first of all, resize to given maximum and/or width but check for exception // if unsupported file format // FIXME this isn't elegant and should fail better (mime_types check should fail first before resize attempted) try { $image = new ImageTransform($file->getTempName(), $file->getType()); $image->fit($this->getOption('max_width'), $this->getOption('max_height')); $image->save($file->getTempName()); } catch (Exception $e) { // do nothing } } else { // fetch image info list($width, $height, $type, $attr) = getimagesize($file->getTempName()); // do we have some exact required dimensions? if ($this->getOption('required_width') !== false || $this->getOption('required_height') !== false) { $passes_width = ($required_width = $this->getOption('required_width')) ? $width == $required_width : true; $passes_height = ($required_height = $this->getOption('required_height')) ? $height == $required_height : true; if (!$passes_height || !$passes_width) { throw new sfValidatorError($this, 'required_dimensions', array('width' => $width, 'height' => $height, 'required_width' => $required_width, 'required_height' => $required_height)); } } // check both dimensions to show useful error about both width and height if needed if ($width > $this->getOption('max_width') && $height > $this->getOption('max_height')) { throw new sfValidatorError($this, 'max_dimensions', array('width' => $width, 'height' => $height, 'max_width' => $this->getOption('max_width'), 'max_height' => $this->getOption('max_height'))); } elseif ($width > $this->getOption('max_width')) { throw new sfValidatorError($this, 'max_width', array('width' => $width, 'max_width' => $this->getOption('max_width'))); } elseif ($height > $this->getOption('max_height')) { throw new sfValidatorError($this, 'max_height', array('height' => $height, 'max_height' => $this->getOption('max_height'))); } } // now tell sfValidatorFile to do its own checks return $file; }