Inheritance: extends Zend_Validate_Abstract
    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if the $value is a valid url that starts with http(s)://
     * and the hostname is a valid TLD
     *
     * @param  string $value
     * @throws Zend_Validate_Exception if a fatal error occurs for validation process
     * @return boolean
     */
    public function isValid($value)
    {
        if (!is_string($value)) {
            $this->_error(self::INVALID_URL);
             return false;
        }
		
        $this->_setValue($value);
        //get a Zend_Uri_Http object for our URL, this will only accept http(s) schemes
        try {
            $uriHttp = Zend_Uri_Http::fromString($value);
        } catch (Zend_Uri_Exception $e) {
            $this->_error(self::INVALID_URL);
            return false;
        }
        
        //if we have a valid URI then we check the hostname for valid TLDs, and not local urls
        $hostnameValidator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS); //do not allow local hostnames, this is the default

        if (!$hostnameValidator->isValid($uriHttp->getHost())) {
            $this->_error(self::INVALID_URL);
            return false;
        }
        return true;
    }
Ejemplo n.º 2
0
function validateInstance($instance)
{
    if ($instance == 'www' || $instance == 'www.' || $instance == 'dev') {
        $ret = false;
        echo json_encode(array('exists' => $ret));
        die;
    }
    // Check that the selected instance name is a valid standard host name
    $validate = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
    if (!$validate->isValid($instance)) {
        $ret = false;
        echo json_encode(array('exists' => $ret));
        die;
    }
    $cupid = new Cupid();
    $cupid->init();
    $exists = $cupid->instanceExists($instance);
    if (!$exists) {
        $ret = true;
        echo json_encode(array('exists' => $ret));
    } else {
        $ret = false;
        echo json_encode(array('exists' => $ret));
    }
    $cupid->disconnect();
}
Ejemplo n.º 3
0
 public function validate(array $attributes)
 {
     if (empty($attributes[$this->_attributeName])) {
         return true;
     }
     $attributeValues = $attributes[$this->_attributeName];
     switch ($this->_options) {
         case 'URN':
             $urnValidator = new EngineBlock_Validator_Urn();
             foreach ($attributeValues as $attributeValue) {
                 if (!$urnValidator->validate($attributeValue)) {
                     $this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_URN, $this->_attributeName, $this->_options, $attributeValue);
                     return false;
                 }
             }
             break;
         case 'HostName':
             $hostnameValidator = new Zend_Validate_Hostname();
             foreach ($attributeValues as $attributeValue) {
                 if (!$hostnameValidator->isValid($attributeValue)) {
                     $this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_HOSTNAME, $this->_attributeName, $this->_options, $attributeValue);
                     return false;
                 }
             }
             break;
         case 'URL':
             foreach ($attributeValues as $attributeValue) {
                 if (!Zend_Uri::check($attributeValue)) {
                     $this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_URL, $this->_attributeName, $this->_options, $attributeValue);
                     return false;
                 }
             }
             break;
         case 'URI':
             $uriValidator = new EngineBlock_Validator_Uri();
             foreach ($attributeValues as $attributeValue) {
                 if (!$uriValidator->validate($attributeValue)) {
                     $this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_URI, $this->_attributeName, $this->_options, $attributeValue);
                     return false;
                 }
             }
             break;
         case 'EmailAddress':
             $emailValidator = new Zend_Validate_EmailAddress();
             foreach ($attributeValues as $attributeValue) {
                 if (!$emailValidator->isValid($attributeValue)) {
                     $this->_messages[] = array(self::ERROR_ATTRIBUTE_VALIDATOR_EMAIL, $this->_attributeName, $this->_options, $attributeValue);
                     return false;
                 }
             }
             break;
         default:
             throw new EngineBlock_Exception("Unknown validate option '{$this->_options}' for attribute validation");
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array(Zend_Validate_Hostname::ALLOW_IP, true, array('1.2.3.4', '10.0.0.1', '255.255.255.255')), array(Zend_Validate_Hostname::ALLOW_IP, false, array('0.0.0.0', '0.0.0.256')), array(Zend_Validate_Hostname::ALLOW_DNS, true, array('example.com', 'example.museum')), array(Zend_Validate_Hostname::ALLOW_DNS, false, array('localhost', 'localhost.localdomain', '1.2.3.4')), array(Zend_Validate_Hostname::ALLOW_LOCAL, true, array('localhost', 'localhost.localdomain', 'example.com')), array(Zend_Validate_Hostname::ALLOW_ALL, true, array('localhost', 'example.com', '1.2.3.4')));
     foreach ($valuesExpected as $element) {
         $validator = new Zend_Validate_Hostname($element[0]);
         foreach ($element[2] as $input) {
             $this->assertEquals($element[1], $validator->isValid($input));
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Set the Hostname / IP to connect to.
  * @param	string			$host	Hostname / IP of the Database.
  * @return	Couchdb_Config	$this	This main class for method chaining.
  * @throws	Couchdb_Exception_Parameter
  */
 public function setHost($host)
 {
     $ip = new Zend_Validate_Ip();
     $name = new Zend_Validate_Hostname();
     if ($ip->isValid($host) xor $name->isValid($host)) {
         throw new Couchdb_Exception_Parameter("Wrong Parameters, host must either be a valid hostname or an IP");
     }
     $this->_host = $host;
     return $this;
 }
Ejemplo n.º 6
0
 protected function _factory($type, $userId, $userIp, $cache = true, $preview = null, $portals = null, $channels = null, $seriesId = null, $offset = 0, $limit = null, Zend_Date $start = null, Zend_Date $finish = null, $showId = null, $exclude = null, $searchTerm = null, $searchFilter = null, $transcript = null)
 {
     $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS, true, false);
     $userIp = $validator->isValid($userIp) ? $userIp : null;
     unset($validator);
     $start = $start ? strval($start) : null;
     $finish = $finish ? strval($finish) : null;
     $stmt = Zend_Registry::get('dbh')->proc('page_content_load');
     $stmt->bindParam(':preview', $preview, PDO::PARAM_INT);
     $stmt->bindParam(':portals', $portals, PDO::PARAM_INT);
     $stmt->bindParam(':channels', $channels, PDO::PARAM_INT);
     /*
     $stmt->bindParam(':series', $seriesId, PDO::PARAM_INT);
     $stmt->bindParam(':exclude', $exclude, PDO::PARAM_INT);
     $stmt->bindParam(':show', $showId, PDO::PARAM_STR);
     $stmt->bindParam(':start', $start, PDO::PARAM_STR);
     $stmt->bindParam(':finish', $finish, PDO::PARAM_STR);		
     $stmt->bindParam(':search', $searchTerm, PDO::PARAM_STR);
     $stmt->bindParam(':filter', $searchFilter, PDO::PARAM_STR);
     $stmt->bindParam(':user', $user->id, PDO::PARAM_INT);
     $stmt->bindParam(':ip', $userIp, PDO::PARAM_STR);
     $stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
     $stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
     $stmt->bindParam(':type', $type, PDO::PARAM_STR);
     */
     $results = array();
     try {
         $stmt->execute();
         $pageContent = array();
         $rowCount = 0;
         do {
             $results[] = $stmt->fetchAll(Zend_Db::FETCH_OBJ);
         } while ($stmt->nextRowset());
         $stmt->closeCursor();
     } catch (Zend_Db_Statement_Exception $e) {
         if ('HYC00' == $stmt->errorCode()) {
             $results[] = $stmt->fetchAll(Zend_Db::FETCH_OBJ);
         }
     }
     foreach ($results as $rowset) {
         foreach ($rowset as $row) {
             if (isset($row->found_rows)) {
                 $rowCount = $row->found_rows;
                 continue;
             } else {
                 $pageContent[] = Showcase_Content::factory($row, $cache);
             }
         }
     }
     $binds = array($user->id, $userIp, $offset, $limit, $type, $portals, $channels, $seriesId, $exclude, $showId, $start, $finish, $searchTerm, $searchFilter, $preview);
     //print_r($binds);
     //print_r($results);
     //echo "CALL page_content_load(".implode($binds,',').")";
     return array('contents' => $showId ? $pageContent[0] : $pageContent, 'rows' => !$rowCount ? count($pageContent) : $rowCount);
 }
 public function save()
 {
     $value = $this->getValue();
     if (strlen($value) == 0) {
         Mage::throwException(Mage::helper("mailup")->__("Please fill the admin console URL"));
     }
     $validator = new Zend_Validate_Hostname();
     if (!$validator->isValid($value)) {
         Mage::throwException(Mage::helper("mailup")->__("Admin console URL is not in the right format"));
     }
     return parent::save();
 }
Ejemplo n.º 8
0
 /**
  * (non-PHPdoc)
  * @see library/Zend/Form/Zend_Form_Element#init()
  */
 public function init()
 {
     parent::init();
     /**
      * @todo Change this wired error messages to something more user friendly, or even use simple email regex matching validator
      */
     $validatorHostname = new Zend_Validate_Hostname();
     $validatorHostname->setMessages(array(Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed", Zend_Validate_Hostname::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list", Zend_Validate_Hostname::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position", Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'", Zend_Validate_Hostname::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part", Zend_Validate_Hostname::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname", Zend_Validate_Hostname::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name", Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed"));
     $validatorEmail = new Zend_Validate_EmailAddress(Zend_Validate_Hostname::ALLOW_DNS, false, $validatorHostname);
     $validatorEmail->setMessages(array(Zend_Validate_EmailAddress::INVALID => "'%value%' is not a valid email address", Zend_Validate_EmailAddress::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'", Zend_Validate_EmailAddress::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'", Zend_Validate_EmailAddress::DOT_ATOM => "'%localPart%' not matched against dot-atom format", Zend_Validate_EmailAddress::QUOTED_STRING => "'%localPart%' not matched against quoted-string format", Zend_Validate_EmailAddress::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'"));
     $this->addValidator($validatorEmail);
 }
Ejemplo n.º 9
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return boolean
  * @throws \Zend_Valid_Exception If validation of $value is impossible
  */
 public function isValid($value, $context = array())
 {
     $this->_setValue($value);
     if ($value) {
         try {
             $uri = \Zend_Uri::factory($value);
             // Check the host against the allowed values; delegated to \Zend_Filter.
             $validate = new \Zend_Validate_Hostname(\Zend_Validate_Hostname::ALLOW_DNS | \Zend_Validate_Hostname::ALLOW_IP | \Zend_Validate_Hostname::ALLOW_LOCAL);
             if (!$validate->isValid($uri->getHost())) {
                 foreach ($validate->getMessages() as $key => $msg) {
                     $this->_error($key);
                 }
                 return false;
             }
             if (function_exists('curl_init')) {
                 $ch = curl_init($value);
                 if (false === $ch) {
                     $this->_error(self::ERROR_URL_NOT_VALID);
                     return false;
                 }
                 // Authentication
                 // if ($usr) {
                 // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                 // curl_setopt($ch, CURLOPT_USERPWD, $usr.':'.$pwd);
                 // }
                 // curl_setopt($ch, CURLOPT_FILETIME, true);
                 curl_setopt($ch, CURLOPT_NOBODY, true);
                 /**
                  * @todo Unknown CA's should probably be imported...
                  */
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                 $valid = curl_exec($ch);
                 if (!$valid) {
                     $this->_error(self::ERROR_SITE_NOT_FOUND);
                 }
                 // $return = curl_getinfo($ch, CURLINFO_FILETIME);
                 // \MUtil_Echo::r('Date at server: '.date('r', $return));
                 curl_close($ch);
                 return $valid;
             } else {
                 return true;
             }
         } catch (\Exception $e) {
             $this->_error(self::ERROR_URL_NOT_VALID);
             $this->setMessage($e->getMessage(), self::ERROR_URL_NOT_VALID);
             return false;
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid email address
  * according to RFC2822
  *
  * @link http://www.ietf.org/rfc/rfc2822.txt RFC2822
  * @link http://www.columbia.edu/kermit/ascii.html US-ASCII characters
  * @param string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_messages = array();
     // Split email address up
     if (!preg_match('/^(.+)@([^@]+)$/', $value, $matches)) {
         $this->_messages[] = "'{$value}' is not a valid email address in the basic format local-part@hostname";
         return false;
     }
     $localPart = $matches[1];
     $hostname = $matches[2];
     /**
      * @todo 0.9 ZF-42 implement basic MX check on hostname via dns_get_record()
      */
     // Match hostname part
     $hostnameResult = $this->_hostnameValidator->isValid($hostname);
     if (!$hostnameResult) {
         $this->_messages[] = "'{$hostname}' is not a valid hostname for email address '{$value}'";
         // Get messages from hostnameValidator
         foreach ($this->_hostnameValidator->getMessages() as $message) {
             $this->_messages[] = $message;
         }
     }
     // First try to match the local part on the common dot-atom format
     $localResult = false;
     // Dot-atom characters are: 1*atext *("." 1*atext)
     // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
     //        "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
     $atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f';
     $atext .= '\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d';
     if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $localPart)) {
         $localResult = true;
     } else {
         $this->_messages[] = "'{$localPart}' not matched against dot-atom format";
     }
     // If not matched, try quoted string format
     if (!$localResult) {
         // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
         // qtext: Non white space controls, and the rest of the US-ASCII characters not
         //   including "\" or the quote character
         $noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
         $qtext = $noWsCtl . '\\x21\\x23-\\x5b\\x5d-\\x7e';
         $ws = '\\x20\\x09';
         if (preg_match('/^\\x22([' . $ws . $qtext . '])*[$ws]?\\x22$/', $localPart)) {
             $localResult = true;
         } else {
             $this->_messages[] = "'{$localPart}' not matched against quoted-string format";
         }
     }
     if (!$localResult) {
         $this->_messages[] = "'{$localPart}' is not a valid local part for email address '{$value}'";
     }
     // If both parts valid, return true
     if ($localResult && $hostnameResult) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 11
0
 /**
  * Ensures that an exception is thrown when a bad local regex is supplied
  *
  * @return void
  */
 public function testBadRegexLocal()
 {
     try {
         $this->_validator->setRegex('local', '/')->isValid('anything');
         $this->fail('Expected Zend_Validate_Exception not thrown for bad local network name regex');
     } catch (Zend_Validate_Exception $e) {
         $this->assertContains('local network name validation failed', $e->getMessage());
     }
 }
Ejemplo n.º 12
0
 public function __construct($allow = self::ALLOW_DNS, $validateIdn = true, $validateTld = false, Zend_Validate_Ip $ipValidator = null)
 {
     $this->_messageTemplates[self::IP_ADDRESS_NOT_ALLOWED] = trlKwfStatic("'%value%' appears to be an IP address, but IP addresses are not allowed");
     $this->_messageTemplates[self::UNKNOWN_TLD] = trlKwfStatic("'%value%' appears to be a DNS hostname but cannot match TLD against known list");
     $this->_messageTemplates[self::INVALID_DASH] = trlKwfStatic("'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position");
     $this->_messageTemplates[self::INVALID_HOSTNAME_SCHEMA] = trlKwfStatic("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'");
     $this->_messageTemplates[self::UNDECIPHERABLE_TLD] = trlKwfStatic("'%value%' appears to be a DNS hostname but cannot extract TLD part");
     $this->_messageTemplates[self::INVALID_HOSTNAME] = trlKwfStatic("'%value%' does not match the expected structure for a DNS hostname");
     $this->_messageTemplates[self::INVALID_LOCAL_NAME] = trlKwfStatic("'%value%' does not appear to be a valid local network name");
     $this->_messageTemplates[self::LOCAL_NAME_NOT_ALLOWED] = trlKwfStatic("'%value%' appears to be a local network name but local network names are not allowed");
     parent::__construct($allow, $validateIdn, $validateTld, $ipValidator);
 }
Ejemplo n.º 13
0
 /**
  * Valid?
  * @param $value
  * @return boolean
  */
 public function isValid($value)
 {
     $valueString = (string) $value;
     $this->_setValue($valueString);
     $uri = Zend_Uri::factory($value);
     $uriSchema = $uri->getScheme();
     try {
         $uri->valid();
     } catch (Exception $e) {
         $this->_error(self::INVALID);
         return false;
     }
     $validatorHostname = new Zend_Validate_Hostname(array('allow' => Zend_Validate_Hostname::ALLOW_DNS, 'idn' => true, 'tld' => false));
     $protocol = !empty($uriSchema) ? $uriSchema . '://' : '';
     $urlHostname = str_replace($protocol, "", $value);
     if (!$validatorHostname->isValid($urlHostname)) {
         $this->_error(self::INVALID_HOSTNAME);
         return false;
     }
     return true;
 }
Ejemplo n.º 14
0
 /**
  * Returns true if the value is a valid url that starts with http(s)://
  * and the hostname is a valid TLD.
  *
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     // Invalid if not string.
     if (!is_string($value)) {
         $this->_error(self::INVALID_URL);
         return false;
     }
     $this->_setValue($value);
     try {
         // Try to parse a URL.
         $uriHttp = Zend_Uri_Http::fromString($value);
     } catch (Zend_Uri_Exception $e) {
         // Invalid if not URL.
         $this->_error(self::INVALID_URL);
         return false;
     }
     $hostnameValidator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_LOCAL);
     // Allow local URLs.
     if (!$hostnameValidator->isValid($uriHttp->getHost())) {
         $this->_error(self::INVALID_URL);
         return false;
     }
     return true;
 }
Ejemplo n.º 15
0
 /**
  * @see ZF-2861
  */
 public function testIpValidatorMessagesShouldBeTranslated()
 {
     require_once 'Zend/Validate/Ip.php';
     $ipValidator = new Zend_Validate_Ip();
     require_once 'Zend/Translate.php';
     $translations = array('notIpAddress' => 'this is the IP error message');
     $translator = new Zend_Translate('array', $translations);
     $this->_validator->setTranslator($translator)->setIpValidator($ipValidator);
     $this->_validator->isValid('0.239,512.777');
     $messages = $ipValidator->getMessages();
     $found = false;
     foreach ($messages as $code => $message) {
         if (array_key_exists($code, $translations)) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found);
     $this->assertEquals($translations[$code], $message);
 }
Ejemplo n.º 16
0
 /**
  * @group ZF-11334
  * @see http://www.ietf.org/rfc/rfc2732.txt
  */
 public function testSupportsIpv6AddressesWhichContainHexDigitF()
 {
     $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
     $this->assertTrue($validator->isValid('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210'));
     $this->assertTrue($validator->isValid('1080:0:0:0:8:800:200C:417A'));
     $this->assertTrue($validator->isValid('3ffe:2a00:100:7031::1'));
     $this->assertTrue($validator->isValid('1080::8:800:200C:417A'));
     $this->assertTrue($validator->isValid('::192.9.5.5'));
     $this->assertTrue($validator->isValid('::FFFF:129.144.52.38'));
     $this->assertTrue($validator->isValid('2010:836B:4179::836B:4179'));
 }
Ejemplo n.º 17
0
 /**
  * Returns true if and only if the host string passes validation. If no host is passed,
  * then the host contained in the instance variable is used.
  *
  * @param  string $host The HTTP host
  * @return boolean
  * @uses   Zend_Filter
  */
 public function validateHost($host = null)
 {
     if ($host === null) {
         $host = $this->_host;
     }
     // If the host is empty, then it is considered invalid
     if (strlen($host) === 0) {
         return false;
     }
     // Check the host against the allowed values; delegated to Zend_Filter.
     $validate = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
     return $validate->isValid($host);
 }
Ejemplo n.º 18
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return array|true
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidationRules();
     $inputValidation = ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation');
     if (!is_null($inputValidation)) {
         switch ($inputValidation) {
             case 'alphanumeric':
                 $validator = new \Zend_Validate_Alnum(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic or non-numeric characters.', $label), \Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new \Zend_Validate_Digits();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Digits::INVALID);
                 $validator->setMessage(__('"%1" contains non-numeric characters.', $label), \Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new \Zend_Validate_Alpha(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic characters.', $label), \Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 __("Invalid type given. String expected")
                 __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 __("'%value%' does not match the expected structure for a DNS hostname")
                 __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 __("'%value%' does not appear to be a valid local network name")
                 __("'%value%' does not appear to be a valid URI hostname")
                 __("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 __("'%value%' appears to be a local network name but local network names are not allowed")
                 __("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 __("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new \Zend_Validate_EmailAddress();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(__('"%1" uses too many characters.', $label), \Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(__("'%value%' looks like an IP address, which is not an acceptable format."), \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), \Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), \Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'."), \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but cannot extract TLD part."), \Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(__("'%value%' does not look like a valid local network name."), \Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(__("'%value%' looks like a local network name, which is not an acceptable format."), \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded."), \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 $validator = new \Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 break;
             case 'date':
                 $validator = new \Zend_Validate_Date(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Date::INVALID);
                 $validator->setMessage(__('"%1" is not a valid date.', $label), \Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(__('"%1" does not fit the entered date format.', $label), \Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Returns TRUE if value is a valid hostname, FALSE otherwise.
  * Depending upon the value of $allow, Internet domain names, IP
  * addresses, and/or local network names are considered valid.
  * The default is HOST_ALLOW_ALL, which considers all of the
  * above to be valid.
  *
  * @deprecated since 0.8.0
  * @param      mixed   $value
  * @param      integer $allow bitfield for HOST_ALLOW_DNS, HOST_ALLOW_IP, HOST_ALLOW_LOCAL
  * @return     boolean
  */
 public static function isHostname($value, $allow = self::HOST_ALLOW_ALL)
 {
     require_once 'Zend/Validate/Hostname.php';
     $validator = new Zend_Validate_Hostname($allow);
     return $validator->isValid($value);
 }
Ejemplo n.º 20
0
 /**
  * @group GH-451
  */
 public function testVermögensberaterIdns()
 {
     $validator = new Zend_Validate_Hostname();
     $this->assertTrue($validator->isValid('mysite.vermögensberater'));
 }
Ejemplo n.º 21
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel());
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 $this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 $this->__("Invalid type given. String expected")
                 $this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 $this->__("'%value%' does not match the expected structure for a DNS hostname")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 $this->__("'%value%' does not appear to be a valid local network name")
                 $this->__("'%value%' does not appear to be a valid URI hostname")
                 $this->__("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 $this->__("'%value%' appears to be a local network name but local network names are not allowed")
                 $this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
Ejemplo n.º 22
0
 /**
  * @ZF-12314
  */
 public function testDKSpecialChars()
 {
     $this->assertTrue($this->_validator->isValid('testæøå.dk'));
 }
Ejemplo n.º 23
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid email address
  * according to RFC2822
  *
  * @link   http://www.ietf.org/rfc/rfc2822.txt RFC2822
  * @link   http://www.columbia.edu/kermit/ascii.html US-ASCII characters
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $valueString = (string) $value;
     $this->_setValue($valueString);
     // Split email address up
     if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_localPart = $matches[1];
     $this->_hostname = $matches[2];
     // Match hostname part
     $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())->isValid($this->_hostname);
     if (!$hostnameResult) {
         $this->_error(self::INVALID_HOSTNAME);
         // Get messages and errors from hostnameValidator
         foreach ($this->hostnameValidator->getMessages() as $message) {
             $this->_messages[] = $message;
         }
         foreach ($this->hostnameValidator->getErrors() as $error) {
             $this->_errors[] = $error;
         }
     }
     // MX check on hostname via dns_get_record()
     if ($this->_validateMx) {
         if ($this->validateMxSupported()) {
             $result = dns_get_mx($this->_hostname, $mxHosts);
             if (count($mxHosts) < 1) {
                 $hostnameResult = false;
                 $this->_error(self::INVALID_MX_RECORD);
             }
         } else {
             /**
              * MX checks are not supported by this system
              * @see Zend_Validate_Exception
              */
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
         }
     }
     // First try to match the local part on the common dot-atom format
     $localResult = false;
     // Dot-atom characters are: 1*atext *("." 1*atext)
     // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
     //        "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
     $atext = 'a-zA-Z0-9\\x21\\x23\\x24\\x25\\x26\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b\\x7c\\x7d';
     if (preg_match('/^[' . $atext . ']+(\\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
         $localResult = true;
     } else {
         // Try quoted string format
         // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
         // qtext: Non white space controls, and the rest of the US-ASCII characters not
         //   including "\" or the quote character
         $noWsCtl = '\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f';
         $qtext = $noWsCtl . '\\x21\\x23-\\x5b\\x5d-\\x7e';
         $ws = '\\x20\\x09';
         if (preg_match('/^\\x22([' . $ws . $qtext . '])*[$ws]?\\x22$/', $this->_localPart)) {
             $localResult = true;
         } else {
             $this->_error(self::DOT_ATOM);
             $this->_error(self::QUOTED_STRING);
             $this->_error(self::INVALID_LOCAL_PART);
         }
     }
     // If both parts valid, return true
     if ($localResult && $hostnameResult) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 24
0
 protected function _assignGroups($credentials)
 {
     $options = array(0 => $this->language->get('text_select_a_group'));
     if ($credentials) {
         $validate = new Zend_Validate_Hostname();
         if (!$validate->isValid($credentials['hostname'])) {
             $this->error['warning'] = $this->language->get('error_please_provide_a_valid_hostname');
             return $options;
         }
         $client = $this->_getClient($credentials['hostname'], $credentials['key']);
         $params['enable'] = true;
         $result = $this->_execute($client, 'getGroups', $params);
         if ($result && $result['status']) {
             foreach ($result['data'] as $item) {
                 $options[$item['id']] = $item['name'];
             }
         } else {
             $this->error['warning'] = $this->language->get('error_invalid_api_key');
             return $options;
         }
     }
     return $options;
 }
Ejemplo n.º 25
0
/**
 * 
 */
function createNewPassword(&$dbHandler, &$argsObj, &$userObj, $newPasswordSendMethod)
{
    $op = new stdClass();
    $op->user_feedback = '';
    $op->new_password = '';
    // Try to validate mail configuration
    //
    // From Zend Documentation
    // You may find you also want to match IP addresses, Local hostnames, or a combination of all allowed types.
    // This can be done by passing a parameter to Zend_Validate_Hostname when you instantiate it.
    // The paramter should be an integer which determines what types of hostnames are allowed.
    // You are encouraged to use the Zend_Validate_Hostname constants to do this.
    // The Zend_Validate_Hostname constants are: ALLOW_DNS to allow only DNS hostnames, ALLOW_IP to allow IP addresses,
    // ALLOW_LOCAL to allow local network names, and ALLOW_ALL to allow all three types.
    //
    $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
    $smtp_host = config_get('smtp_host');
    $password_on_screen = $newPasswordSendMethod == 'display_on_screen';
    if ($validator->isValid($smtp_host) || $password_on_screen) {
        $dummy = resetPassword($dbHandler, $argsObj->user_id, $newPasswordSendMethod);
        $op->user_feedback = $dummy['msg'];
        $op->status = $dummy['status'];
        $op->new_password = $dummy['password'];
        if ($op->status >= tl::OK) {
            logAuditEvent(TLS("audit_pwd_reset_requested", $userObj->login), "PWD_RESET", $argsObj->user_id, "users");
            $op->user_feedback = lang_get('password_reseted');
            if ($password_on_screen) {
                $op->user_feedback = lang_get('password_set') . $dummy['password'];
            }
        } else {
            $op->user_feedback = sprintf(lang_get('password_cannot_be_reseted_reason'), $op->user_feedback);
        }
    } else {
        $op->status = tl::ERROR;
        $op->user_feedback = lang_get('password_cannot_be_reseted_invalid_smtp_hostname');
    }
    return $op;
}
Ejemplo n.º 26
0
 /**
  * Test for IDN serbia .rs
  *
  * @group GH-115
  */
 public function testIDNRS()
 {
     $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
     $this->assertTrue($validator->isValid('test.rs'));
 }
Ejemplo n.º 27
0
 /**
  * Ensures that getAllow() returns expected default value
  *
  * @return void
  */
 public function testGetAllow()
 {
     $this->assertEquals(Zend_Validate_Hostname::ALLOW_DNS, $this->_validator->getAllow());
 }
Ejemplo n.º 28
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator = new Zend_Validate_Date($format);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 break;
         }
     }
     return true;
 }
Ejemplo n.º 29
0
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */
/**
 * Standalone Validate_Hostname test script
 * 
 * Please note this file should be encoded as UTF-8 in order to run correctly
 * 
 * @see Zend_Validate_Hostname
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../library/');
require_once 'Zend/Validate/Hostname.php';
// Set up expected values
$valuesExpected = array(array(Zend_Validate_Hostname::CHECK_TLD, false, array('bürger.de', 'hãllo.de', 'hållo.se')), array(Zend_Validate_Hostname::CHECK_IDN, true, array('bürger.de', 'hãllo.de', 'hållo.se')), array(Zend_Validate_Hostname::CHECK_IDN, true, array('bÜrger.de', 'hÃllo.de', 'hÅllo.se')), array(Zend_Validate_Hostname::CHECK_IDN, false, array('hãllo.se', 'bürger.com', 'hãllo.uk')));
// Run test
$ok = true;
foreach ($valuesExpected as $element) {
    $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS, $element[0]);
    foreach ($element[2] as $input) {
        print "{$input} - ";
        if ($validator->isValid($input) === $element[1]) {
            print 'Pass';
        } else {
            print 'Fail ' . implode("\n", $validator->getMessages());
            $ok = false;
        }
        print "\n";
    }
    print "\n";
}
print $ok ? "All tests passed OK :-)\n" : "Some tests failed!\n";
Ejemplo n.º 30
0
 /**
  * @ZF-8312
  */
 public function testInvalidDoubledIdn()
 {
     $this->assertFalse($this->_validator->isValid('test.com / http://www.test.com'));
 }