/** * (non-PHPdoc) * @see EFeedItemAbstract::setLink() */ public function setLink( $link ){ $validator = new CUrlValidator(); if(!$validator->validateValue($link)) throw new CException( Yii::t('EFeed', $link. ' does not seem to be a valid URL') ); $this->addTag('link','',array('href'=>$link)); $this->addTag('id', EFeed::uuid($link,'urn:uuid:')); }
function __construct($url) { $urlValidator = new CUrlValidator(); if ($urlValidator->validateValue($url)) { $this->url = $url; } else { throw new CException(Yii::t('EGMap', 'EGMapKMLService.url must be a valid URL address')); } }
public function beforeSave($event) { $model = $this->getOwner(); if (!method_exists($model, "uploadFiles")) { return false; } $upload_files = $model->uploadFiles(); foreach ($upload_files as $attr => $params) { $params = array_merge($this->_params, $params); if (!isset($params["dir"])) { throw new CException('param "dir" is required in "uploadFiles" method'); } $file_dir = $_SERVER["DOCUMENT_ROOT"] . $params['dir']; if (substr($file_dir, -1) !== '/') { $file_dir .= '/'; } if (!file_exists($file_dir)) { mkdir($file_dir); chmod($file_dir, 0777); } $file_saved = false; $upload = CUploadedFile::getInstance($model, $attr); if ($upload) { if ($params['hash_store']) { $file_name = $this->generateFileHashName($upload->name); } else { $file_name = $upload->name; } $file_path = $file_dir . $file_name; $file_saved = $upload->saveAs($file_path); } else { $validator = new CUrlValidator(); if ($validator->validateValue($model->{$attr})) { $image_data = file_get_contents($model->image); $file_name = $this->generateFileHashName($model->image); $file_path = $file_dir . $file_name; if (file_put_contents($file_path, $image_data)) { $file_saved = true; } } if (!$model->isNewRecord) { $model->{$attr} = $model->model()->findByPk($model->primaryKey)->{$attr}; } } if ($file_saved) { chmod($file_path, 0777); if ($file_saved && $model->id) { $object = $model->findByPk($model->id); if ($object->{$attr}) { FileSystemHelper::deleteFileWithSimilarNames($file_dir, $object->{$attr}); } } $model->{$attr} = $file_name; } } }
/** * Add support for protocol-relative URLs. {@see http://paulirish.com/2010/the-protocol-relative-url/} * * @param string $value * * @return string */ public function validateValue($value) { // Ignore URLs with any environment variables in them if (mb_strpos($value, '{') !== false) { return $value; } if ($this->defaultScheme !== null && strncmp($value, '/', 1) === 0) { $this->defaultScheme = null; } return parent::validateValue($value); }
/** * @see BatchAttributeValueDataAnalyzer::analyzeByValue() */ protected function analyzeByValue($value) { if ($value == null) { return; } $validator = new CUrlValidator(); $validator->defaultScheme = 'http'; $validatedUrl = $validator->validateValue($value); if ($validatedUrl === false) { $this->messageCountData[static::INVALID]++; return; } if (strlen($validatedUrl) > $this->maxLength) { $this->messageCountData[static::URL_TOO_LONG]++; } }
public function actionCreate() { $token = Yii::app()->request->getParam('token'); $url = Yii::app()->request->getParam('url'); $title = Yii::app()->request->getParam('title'); $list = Yii::app()->request->getParam('list'); $user = Users::model()->find('`key` = :key', ['key' => $token]); if ($user === null) { $this->renderJSON(['is_error' => true, 'message' => 'Invalid User Token']); } if (Yii::app()->request->getPost('token') !== $token) { $this->renderJSON("Only accepts POST requests"); } $urlValidator = new CUrlValidator(); if (!$urlValidator->validateValue($url)) { $this->renderJSON(['is_error' => true, 'data' => '', 'message' => 'Not valid URL']); } $bookmark = new Bookmarks(); if (!empty($list)) { $list = $user->lists(['condition' => 'name = :name', 'params' => ['name' => $list]]); if (empty($list)) { $this->renderJSON(['is_error' => true, 'data' => '', 'message' => 'Not valid list']); } else { $bookmark->list_id = $list[0]->id; } } if (!empty($title)) { $bookmark->title = $title; } else { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); $body = curl_exec($curl); curl_close($curl); if ($body !== false && preg_match('#<title>([^<]+)#i', $body, $match)) { $bookmark->title = $match[1]; } } $bookmark->user_id = $user->id; $bookmark->url = $url; $bookmark->save(); $this->renderJSON(['is_error' => false, 'data' => ['id' => (int) $bookmark->id, 'title' => $bookmark->title, 'list' => $bookmark->list ? $bookmark->list->name : null, 'url' => $bookmark->url], 'message' => 'Success']); }
/** * Given a value, resolve that the value is a correctly formatted url. If not, an * InvalidValueToSanitizeException is thrown. * @param string $modelClassName * @param string $attributeName * @param mixed $value * @param array $mappingRuleData */ public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData) { assert('is_string($modelClassName)'); assert('is_string($attributeName)'); assert('$mappingRuleData == null'); if ($value == null) { return $value; } $maxLength = DatabaseCompatibilityUtil::getMaxVarCharLength(); $validator = new CUrlValidator(); $validator->defaultScheme = 'http'; $validatedUrl = $validator->validateValue($value); if ($validatedUrl === false) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid url format.')); } if (strlen($validatedUrl) > $maxLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'URL was too long.')); } return $validatedUrl; }
/** * * Property setter the 'about' RSS 1.0 channel element * * @param string value of 'about' channel tag */ public function setRSS1ChannelAbout($url) { $validator = new CUrlValidator(); if (!$validator->validateValue($url)) { throw new CException(Yii::t('EFeed', $url . ' does not seem to be a valid URL')); } $this->addChannelTag('ChannelAbout', $url); }
/** * * Property link setter * @param string URI $link */ public function setLink($link) { $validator = new CUrlValidator(); $validator->pattern = '/(((f|ht){1}tp:\\/\\/)[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)/i'; if (!$validator->validateValue($link)) { throw new CException(Yii::t('EFeed', $link . ' does not seem to be a valid URL')); } $this->addTag('link', $link); }
public function validateUpload($field, $value) { switch ($field) { case "newUpload": if ($this->newUpload != '0' && $this->newUpload) { $newFile = $this->file; $path = Yii::getPathOfAlias('application'); $old = $path . '/upload/temp/' . $newFile; $new = $path . '/files/' . uid() . DS . $newFile; if (!file_exists($path . '/files/' . uid())) { $test = mkdir($path . '/files/' . uid() . '/'); } if (!copy($old, $new)) { $this->addError('file', "There was an error uploading the file, please upload again"); } else { $dmm = $this->getDetails(); if ($dmm != NULL) { $this->width = $dmm["width"]; $this->height = $dmm["height"]; $this->duration = $dmm['duration']; $this->aspect = (double) $dmm["width"] / (double) $dmm["height"]; } else { unlink($new); $this->addError('file', "Invalid Movie File!"); } } } break; case "fileUrl": if (!$this->newUpload && !empty($this->fileUrl)) { $validator = new CUrlValidator(); if ($validator->validateValue($this->fileUrl)) { $this->file = $this->fileUrl; } else { $this->addError('fileUrl', 'Invalid video url'); } } break; } }
/** * * ATOM style link * @param string $url */ public function setLink($url) { if (null === $this->elements->itemAt('head')) { $this->elements->add('head', new CMap()); } $validator = new CUrlValidator(); if (!$validator->validateValue($url)) { throw new CException(Yii::t('EGMap', 'EGMapKMLFeed.setLink Url does not seem to valid')); } $item = '<atom:link href="' . $url . '" />'; $this->elements->itemAt('head')->add('link', $item); }
/** * @dataProvider providerAllowEmpty * * @param string $url * @param array $allowEmpty * @param string $assertion */ public function testAllowEmpty($url, $allowEmpty, $assertion) { $urlValidator = new CUrlValidator(); $urlValidator->allowEmpty = $allowEmpty; $result = $urlValidator->validateValue($url); $this->assertEquals($assertion, $result); }
private function _downloadImageByUrl($url) { $file = array('name' => $url); $urlValid = new CUrlValidator(); if ($urlValid->validateValue($_REQUEST['url'])) { $inputFileName = tempnam(sys_get_temp_dir(), 'URL'); @file_put_contents($inputFileName, fopen($_REQUEST['url'], 'r')); $file['size'] = @filesize($inputFileName); if ($file['size'] < 1) { $file['error'] = 'Не удалось скачать URL'; } else { $file['tmpName'] = $inputFileName; } } else { $file['error'] = 'Неправильный URL'; } return $file; }
protected function resolveValidatedUrl($url) { $validator = new CUrlValidator(); $validator->defaultScheme = 'http'; return $validator->validateValue($url); }
/** * * Property link setter * @param string URI $link */ public function setLink($link) { $validator = new CUrlValidator(); if(!$validator->validateValue($link)) throw new CException( Yii::t('EFeed', $link. ' does not seem to be a valid URL') ); $this->addTag('link', $link); }
protected function validateUrl($value) { if ($value == null) { return true; } $validator = new CUrlValidator(); if (!$validator->validateValue($value)) { return Zurmo::t('EmailTemplatesModule', 'Use a valid URL.'); } return true; }
/** * Custom validator for an array of URLs */ public function validateUrlArray($attr, $params) { $values = $this->{$attr}; $urlValidator = new CUrlValidator(); $allowEmpty = array_key_exists('allowEmpty', $params) && $params['allowEmpty']; if (is_array($values)) { foreach ($values as $url) { if ($urlValidator->validateValue($url) || $allowEmpty && empty($url)) { continue; } $this->addError($attr, Yii::t('admin', 'The specified URL "{url}" is not in the correct format.', array('{url}' => CHtml::encode($url)))); } } }
public function actionUpdateBGPicUrl() { header('Content-type: application/json'); if (!Yii::app()->request->isPostRequest) { IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT); return; } if (!IjoyPlusServiceUtils::validateAPPKey()) { IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID); return; } if (IjoyPlusServiceUtils::validateUserID()) { IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID); return; } try { $url = Yii::app()->request->getParam("url"); $validator = new CUrlValidator(); if (!$validator->validateValue($url)) { IjoyPlusServiceUtils::exportServiceError(Constants::URL_INVALID); } $msgs = User::model()->updateBGPicUrl(Yii::app()->user->id, $url); IjoyPlusServiceUtils::exportServiceError(Constants::SUCC); } catch (Exception $e) { IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR); } }