Beispiel #1
0
 public function init()
 {
     parent::init();
     if (is_null($this->getAttrib('size'))) {
         $this->setAttrib('size', 6);
     }
     $validator = new Zend_Validate_Int();
     $validator->setMessage('validation_error_int');
     $this->addValidator($validator);
     $options = array();
     $min = $this->getAttrib('min');
     if (is_null($min)) {
         $min = 0;
     } else {
         $this->setAttrib('min', null);
         // remove from rendered attributes
     }
     $options['min'] = $min;
     $max = $this->getAttrib('max');
     if (is_null($max)) {
         $validator = new Zend_Validate_GreaterThan(array('min' => $min - 1));
         // inclusive not supported in ZF1
         $validator->setMessage('validation_error_number_tooSmall');
     } else {
         $this->setAttrib('max', null);
         // remove from rendered attributes
         $options['max'] = $max;
         $validator = new Zend_Validate_Between(array('min' => $min, 'max' => $max));
         $validator->setMessage('validation_error_number_notBetween');
     }
     $this->addValidator($validator);
 }
Beispiel #2
0
 public function _beforeSave()
 {
     $valid = new Zend_Validate_Between(array('min' => 1, 'max' => 100));
     if (!$valid->isValid($this->getValue())) {
         $this->_dataSaveAllowed = false;
         Mage::throwException(Mage::helper('welance_kraken')->__('Please use a value between 1 and 100'));
     }
     return parent::_beforeSave();
 }
 public function betweenAction()
 {
     $v = new Zend_Validate_Between(array('min' => 1, 'max' => 12));
     $valor = 15;
     if ($v->isValid($valor)) {
         echo "{$valor} eh valido";
     } else {
         echo "{$valor} eh invalido";
         $erros = $v->getMessages();
         print_r($erros);
     }
     exit;
 }
 public function isValid($value)
 {
     if ($value == '-') {
         return true;
     }
     return parent::isValid($value);
 }
Beispiel #5
0
 public function isValidDocument($file, $max, $allowedTypes)
 {
     //check size
     $validator = new Zend_Validate_Between('1', $max);
     if ($validator->isValid($file['size'])) {
     } else {
         // value failed validation; print reasons
         foreach ($validator->getMessages() as $message) {
             return array('Error' => 'Document:' . $message);
         }
     }
     //check the type
     $this->_fileName = $file['name'];
     $return = $this->_checkType($allowedTypes);
     if ($return == false) {
         return array('Error' => 'Non-allowed type of document.');
     }
 }
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     /**
      * The elements of each array are, in order:
      *      - minimum
      *      - maximum
      *      - inclusive
      *      - expected validation result
      *      - array of test input values
      */
     $valuesExpected = array(array(1, 100, true, true, array(1, 10, 100)), array(1, 100, false, false, array(0, 1, 100, 101)), array('a', 'z', true, true, array('a', 'b', 'y', 'z')), array('a', 'z', false, false, array('!', 'a', 'z')));
     foreach ($valuesExpected as $element) {
         $validator = new Zend_Validate_Between($element[0], $element[1], $element[2]);
         foreach ($element[4] as $input) {
             $this->assertEquals($element[3], $validator->isValid($input));
         }
     }
 }
 /**
  * Sets img size
  *
  * @throws Zend_View_Exception
  * @param int $imgSize Size of img must be between 1 and 512
  * @return Zwe_View_Helper_Gravatar
  */
 public function setImgSize($imgSize)
 {
     $betweenValidate = new Zend_Validate_Between(1, 512);
     $result = $betweenValidate->isValid($imgSize);
     if (!$result) {
         throw new Zend_View_Exception(current($betweenValidate->getMessages()));
     }
     $this->_options['imgSize'] = $imgSize;
     return $this;
 }
Beispiel #8
0
 /**
  * Sets validator options
  * Accepts the following option keys:
  *   'min' => scalar, minimum border
  *   'max' => scalar, maximum border
  *   'inclusive' => boolean, inclusive border values
  * @override
  * @param array|\Zend_Config $options
  */
 public function __construct(array $options)
 {
     /**
      * Спецификация конструктора класса Zend_Validate_Between
      * различается между Zend Framework 1.9.6 (Magento 1.4.0.1)
      * и Zend Framework 1.11.1 (Magento 1.5.0.1).
      *
      * Именно для устранения для пользователя данных различий
      * служит наш класс-посредник \Df\Zf\Validate\Between
      */
     if (version_compare(\Zend_Version::VERSION, '1.10', '>=')) {
         /** @noinspection PhpParamsInspection */
         parent::__construct($options);
     } else {
         /** @noinspection PhpParamsInspection */
         parent::__construct(dfa($options, 'min'), dfa($options, 'max'), dfa($options, 'inclusive'));
     }
 }
Beispiel #9
0
 /**
  * Sets img size
  *
  * @throws Zend_View_Exception
  * @param int $imgSize Size of img must be between 1 and 512
  * @return Zend_View_Helper_Gravatar
  */
 public function setImgSize($imgSize)
 {
     /**
      * @see Zend_Validate_Between
      */
     require_once 'Zend/Validate/Between.php';
     $betweenValidate = new Zend_Validate_Between(1, 512);
     $result = $betweenValidate->isValid($imgSize);
     if (!$result) {
         /**
          * @see Zend_View_Exception
          */
         require_once 'Zend/View/Exception.php';
         throw new Zend_View_Exception(current($betweenValidate->getMessages()));
     }
     $this->_options['imgSize'] = $imgSize;
     return $this;
 }
Beispiel #10
0
 /**
  * Built-in Zend between check.  Returns true if and only if $value is between the minimum and maximum boundary values.
  *
  * @param integer $value
  * @param integer $min
  * @param mixed $max
  * @param boolean $inclusive
  *
  * @return boolean Valid?
  */
 public function between($value, $min, $max, $inclusive = true)
 {
     $this->m_ErrorMessage = null;
     require_once 'Zend/Validate/Between.php';
     $validator = new Zend_Validate_Between($min, $max, $inclusive);
     $result = $validator->isValid($value);
     if (!$result) {
         $this->m_ErrorMessage = BizSystem::getMessage("VALIDATESVC_BETWEEN", array($this->m_FieldNameMask, $min, $max));
     }
     return $result;
 }
Beispiel #11
0
 public function testSetGetMessageLengthLimitation()
 {
     Zend_Validate::setMessageLength(5);
     $this->assertEquals(5, Zend_Validate::getMessageLength());
     $valid = new Zend_Validate_Between(1, 10);
     $this->assertFalse($valid->isValid(24));
     $message = current($valid->getMessages());
     $this->assertTrue(strlen($message) <= 5);
 }
 /**
  *
  * @param type $min
  * @param type $max
  * @param type $messages_prefixed
  * @return \Zend_Validate_Between 
  */
 protected function _getValidatorBetween($min = 5, $max = 100, $messages_prefixed = "")
 {
     $between = new Zend_Validate_Between(array('min' => $min, 'max' => $max));
     $between->setMessage(sprintf($this->_translate('ERROR_BETWEEN'), $this->_translate($messages_prefixed), $min, $max), Zend_Validate_Between::NOT_BETWEEN);
     return $between;
 }
 /**
  * Ensures that getInclusive() returns expected default value
  *
  * @return void
  */
 public function testGetInclusive()
 {
     $validator = new Zend_Validate_Between(array('min' => 1, 'max' => 10));
     $this->assertEquals(true, $validator->getInclusive());
 }
 /**
  * Validate Web Search Options
  *
  * @param  array $options
  * @return void
  * @throws Zend_Service_Exception
  */
 protected function _validateWebSearch(array $options)
 {
     $validOptions = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok', 'similar_ok', 'country', 'site', 'subscription', 'license', 'region');
     $this->_compareOptions($options, $validOptions);
     /**
      * @see Zend_Validate_Between
      */
     //require_once 'Zend/Validate/Between.php';
     $between = new Zend_Validate_Between(1, 100, true);
     if (isset($options['results']) && !$between->setMin(1)->setMax(100)->isValid($options['results'])) {
         /**
          * @see Zend_Service_Exception
          */
         //require_once 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception("Invalid value for option 'results': {$options['results']}");
     }
     if (isset($options['start']) && !$between->setMin(1)->setMax(1000)->isValid($options['start'])) {
         /**
          * @see Zend_Service_Exception
          */
         //require_once 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception("Invalid value for option 'start': {$options['start']}");
     }
     if (isset($options['language'])) {
         $this->_validateLanguage($options['language']);
     }
     $this->_validateInArray('type', $options['type'], array('all', 'any', 'phrase'));
     $this->_validateInArray('format', $options['format'], array('any', 'html', 'msword', 'pdf', 'ppt', 'rss', 'txt', 'xls'));
     if (isset($options['license'])) {
         $this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial', 'cc_modifiable'));
     }
     if (isset($options['region'])) {
         $this->_validateInArray('region', $options['region'], array('ar', 'au', 'at', 'br', 'ca', 'ct', 'dk', 'fi', 'fr', 'de', 'in', 'id', 'it', 'my', 'mx', 'nl', 'no', 'ph', 'ru', 'sg', 'es', 'se', 'ch', 'th', 'uk', 'us'));
     }
 }
Beispiel #15
0
 /**
  * Limit valid dates to interval (including) 1000 and 2100.
  */
 public function __construct()
 {
     parent::__construct(array('min' => 1000, 'max' => 2100));
 }
Beispiel #16
0
 /**
  * Validate Tag Search Options
  *
  * @param  array $options
  * @throws Zend_Service_Exception
  * @return void
  */
 protected function _validateTagSearch(array $options)
 {
     $validOptions = array('method', 'api_key', 'user_id', 'tags', 'tag_mode', 'text', 'min_upload_date', 'max_upload_date', 'min_taken_date', 'max_taken_date', 'license', 'sort', 'privacy_filter', 'bbox', 'accuracy', 'machine_tags', 'machine_tag_mode', 'group_id', 'extras', 'per_page', 'page');
     $this->_compareOptions($options, $validOptions);
     /**
      * @see Zend_Validate_Between
      */
     require_once 'Zend/Validate/Between.php';
     $between = new Zend_Validate_Between(1, 500, true);
     if (!$between->isValid($options['per_page'])) {
         /**
          * @see Zend_Service_Exception
          */
         require_once 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option');
     }
     /**
      * @see Zend_Validate_Int
      */
     require_once 'Zend/Validate/Int.php';
     $int = new Zend_Validate_Int();
     if (!$int->isValid($options['page'])) {
         /**
          * @see Zend_Service_Exception
          */
         require_once 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option');
     }
     // validate extras, which are delivered in csv format
     if ($options['extras']) {
         $extras = explode(',', $options['extras']);
         $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');
         foreach ($extras as $extra) {
             /**
              * @todo The following does not do anything [yet], so it is commented out.
              */
             //in_array(trim($extra), $validExtras);
         }
     }
 }
 /**
  * set the max result hits for this search
  *
  * @param integer $hits
  * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters
  */
 public function setHits($hits = 10)
 {
     require_once 'Zend/Validate/Between.php';
     $validator = new Zend_Validate_Between(0, 1000);
     if (!$validator->isValid($hits)) {
         $message = $validator->getMessages();
         require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php';
         throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message));
     }
     $this->_parameters['hits'] = $hits;
     return $this;
 }
Beispiel #18
0
 /**
  * Validate options for an ItemLookup
  *
  * @param array $options Options array to be used for the query
  * @throws Zend_Service_Exception
  * @return void
  */
 protected function _validateItemLookup($options = array())
 {
     if (!is_array($options)) {
         throw new Zend_Service_Exception('Options must be specified as an array');
     }
     // Validate keys in the $options array
     $this->_compareOptions($options, array('ItemId', 'IdType', 'SearchIndex', 'MerchantId', 'Condition', 'DeliveryMethod', 'ISPUPostalCode', 'OfferPage', 'ReviewPage', 'VariationPage', 'ResponseGroup', 'Service', 'SubscriptionId', 'Operation'));
     // Validate ResponseGroup (required)
     if (empty($options['ResponseGroup'])) {
         throw new Zend_Service_Exception('Query requires a ResponseGroup');
     } else {
         $responseGroup = split(',', $options['ResponseGroup']);
         foreach ($responseGroup as $r) {
             if (!in_array($r, array('Request', 'Small', 'Medium', 'Large'))) {
                 throw new Zend_Service_Exception('This wrapper only supports Request, Small, Medium and Large ' . 'ResponseGroups');
             }
         }
     }
     // Validate Sort (optional)
     if (isset($options['Sort'])) {
         $this->_validateInArray('Sort', $options['Sort'], array_values(self::$_searchSort[$options['SearchIndex']]));
     }
     // Validate City (optional)
     if (isset($options['City'])) {
         $this->_validateInArray('City', $options['City'], array('Boston', 'Chicago', 'New York', 'San Francisco', 'Seattle', 'Washington, D.C.'));
     }
     if (isset($options['ItemPage'])) {
         /**
          * @see Zend_Validate_Between
          */
         require_once 'Zend/Validate/Between.php';
         $between = new Zend_Validate_Between(0, 2500, true);
         if (!$between->isValid($options['ItemPage'])) {
             throw new Zend_Service_Exception($options['ItemPage'] . ' is not a valid value for the "ItemPage" option.');
         }
     }
 }
 public function between($min, $max, $value)
 {
     $validator = new Zend_Validate_Between(array('min' => $min, 'max' => $max));
     return $validator->isValid($value);
 }
Beispiel #20
0
 /**
  * Prepares the arguments for the "Video" source
  *
  * @param array $options 
  * @return array
  */
 protected function _prepareVideoSourceArguments(array $options = array())
 {
     $arguments = array();
     if (isset($options['count'])) {
         $between = new Zend_Validate_Between(1, 50, true);
         if (!$between->isValid($options['count'])) {
             throw new Zend_Service_Exception($options['count'] . ' is not valid for the "count" option');
         }
         $arguments['Video.Count'] = (int) $options['count'];
     }
     if (isset($options['offset'])) {
         $between = new Zend_Validate_Between(0, 1000, true);
         if (!$between->isValid($options['offset'])) {
             throw new Zend_Service_Exception($options['offset'] . ' is not valid for the "offset" option');
         }
         $arguments['Video.Offset'] = (int) $options['offset'];
     }
     if (isset($options['adult'])) {
         $arguments['Video.Adult'] = $options['adult'];
     }
     if (isset($options['filters'])) {
         if (is_string($options['filters'])) {
             $options['filters'] = array($options['filters']);
         }
         if (!is_array($options['filters'])) {
             throw new Zend_Service_Exception('The "filters" option must be a string or array of strings');
         }
         $arguments['Video.Filters'] = implode(',', $options['filters']);
     }
     if (isset($options['sortby'])) {
         $arguments['Video.SortBy'] = $options['sortby'];
     }
     return $arguments;
 }
 /**
  * Ensures that getInclusive() returns expected default value
  *
  * @return void
  */
 public function testGetInclusive()
 {
     $validator = new Zend_Validate_Between(1, 10);
     $this->assertEquals(true, $validator->getInclusive());
 }
 public static function overrideBetweenValidator($p_min, $p_max)
 {
     $validator = new Zend_Validate_Between($p_min, $p_max, true);
     $validator->setMessage(_("'%value%' is not between '%min%' and '%max%', inclusively"), Zend_Validate_Between::NOT_BETWEEN);
     return $validator;
 }
Beispiel #23
0
    public function testValidatorBreakChain()
    {
        $data = array(
            'field1' => '150',
            'field2' => '150'
        );

        Zend_Loader::loadClass('Zend_Validate_Between');

        $btw1 = new Zend_Validate_Between(1, 100);

        $btw2 = new Zend_Validate_Between(1, 125);
        $messageUserDefined = 'Something other than the default message';
        $btw2->setMessage($messageUserDefined, Zend_Validate_Between::NOT_BETWEEN);

        $validators = array(
            'field1' => array($btw1, $btw2),
            'field2' => array($btw1, $btw2, Zend_Filter_Input::BREAK_CHAIN => true)
        );
        $input = new Zend_Filter_Input(null, $validators, $data);

        $this->assertFalse($input->hasMissing(), 'Expected hasMissing() to return false');
        $this->assertTrue($input->hasInvalid(), 'Expected hasInvalid() to return true');
        $this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false');
        $this->assertFalse($input->hasValid(), 'Expected hasValid() to return false');

        $messages = $input->getMessages();
        $this->assertType('array', $messages);
        $this->assertEquals(array('field1', 'field2'), array_keys($messages));
        $this->assertEquals(
            $messageUserDefined,
            current($messages['field1']),
            'Expected message to break 2 validators, the message of the latter overwriting that of the former'
            );
        $this->assertEquals(
            "'150' is not between '1' and '100', inclusively",
            current($messages['field2']),
            'Expected rule for field2 to break the validation chain at the first validator'
            );
    }
 protected function validateAndSave($facilityRow, $checkName = true)
 {
     $districtText = $this->tr('Region B (Health District)');
     $provinceText = $this->tr('Region A (Province)');
     $localRegionText = $this->tr('Region C (Local Region)');
     //validate
     $status = ValidationContainer::instance();
     //check for required fields
     if ($checkName) {
         $status->checkRequired($this, 'facility_name', 'Facility name');
         //check for unique
         if ($this->_getParam('facility_name') and !Facility::isUnique($this->_getParam('facility_name'), $this->_getParam('id'))) {
             $status->addError('facility_name', t('That name already exists.'));
         }
     }
     // validate lat & long
     require_once 'Zend/Validate/Float.php';
     require_once 'Zend/Validate/Between.php';
     $lat = $this->getSanParam('facility_latitude');
     $long = $this->getSanParam('facility_longitude');
     $validator = new Zend_Validate_Float();
     $validbetween = new Zend_Validate_Between('-180', '180');
     if ($lat && (!$validator->isValid($lat) || !$validbetween->isValid($lat))) {
         $status->addError('facility_latitude', t('That latitude and longitude does not appear to be valid.'));
     }
     if ($long && (!$validator->isValid($long) || !$validbetween->isValid($long))) {
         $status->addError('facility_longitude', t('That latitude and longitude does not appear to be valid.'));
     }
     $status->checkRequired($this, 'facility_type_id', t('Facility type'));
     $status->checkRequired($this, 'facility_province_id', $provinceText);
     if ($this->setting('display_region_b')) {
         $status->checkRequired($this, 'facility_district_id', $districtText);
     }
     if ($this->setting('display_region_c')) {
         $status->checkRequired($this, 'facility_region_c_id', $localRegionText);
     }
     //$status->checkRequired ( $this, 'facility_city', t ( "City is required." ) );
     list($location_params, $facility_location_tier, $facility_location_id) = $this->getLocationCriteriaValues(array(), 'facility');
     $city_id = false;
     if ($this->getSanParam('facility_city') && !$this->getSanParam('is_new_city')) {
         $city_id = Location::verifyHierarchy($location_params['facility_city'], $location_params['facility_city_parent_id'], $this->setting('num_location_tiers'));
         if ($city_id === false) {
             $status->addError('facility_city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box."));
         }
     }
     $sponsor_date_array = $this->getSanParam('sponsor_start_date');
     // may or may not be array
     $sponsor_end_date_array = $this->getSanParam('sponsor_end_date');
     $sponsor_id = $this->getSanParam('facility_sponsor_id') ? $this->getSanParam('facility_sponsor_id') : null;
     if (is_array($sponsor_id)) {
         $sponsor_array = $sponsor_id;
         $sponsor_id = $sponsor_id[0];
     }
     // todo case where multip array and no_allow_multi
     if (@$this->setting('require_sponsor_dates')) {
         $status->checkRequired($this, 'sponsor_option_id', t('Sponsor dates are required.') . "\n");
         if ($this->setting('allow_multi_sponsors')) {
             // and multiple sponsors option
             if (!is_array($this->getSanParam('sponsor_option_id'))) {
                 $status->addError('sponsor_end_date', t('Sponsor dates are required.') . "\n");
             }
             foreach ($sponsor_array as $i => $val) {
                 if (empty($sponsor_date_array[$i]) || !empty($val)) {
                     $status->addError('sponsor_start_date', t('Sponsor dates are required.') . "\n");
                 }
                 if (empty($sponsor_end_date_array[$i]) || !empty($val)) {
                     $status->addError('sponsor_end_date', t('Sponsor dates are required.') . "\n");
                 }
             }
         }
     }
     // end validation
     if ($status->hasError()) {
         $status->setStatusMessage(t('The facility could not be saved.'));
     } else {
         $location_id = null;
         if ($city_id === false && $this->getSanParam('is_new_city')) {
             $location_id = Location::insertIfNotFound($location_params['facility_city'], $location_params['facility_city_parent_id'], $this->setting('num_location_tiers'));
             if ($location_id === false) {
                 $status->addError('facility_city', t('Could not save that city.'));
             }
         } else {
             if ($city_id) {
                 $location_id = $city_id;
             } else {
                 if ($this->setting('display_region_c')) {
                     $location_id = $this->getSanParam('facility_region_c_id');
                 } else {
                     if ($this->setting('display_region_b')) {
                         $location_id = $this->getSanParam('facility_district_id');
                     } else {
                         $location_id = $this->getSanParam('facility_province_id');
                     }
                 }
             }
             if (strstr($location_id, '_')) {
                 $parts = explode('_', $location_id);
                 $location_id = $parts[count($parts) - 1];
             }
         }
         // save row
         if ($location_id) {
             //map db field names to FORM field names
             $facilityRow->facility_name = $this->getSanParam('facility_name');
             $facilityRow->location_id = $location_id;
             $facilityRow->type_option_id = $this->getSanParam('facility_type_id') ? $this->getSanParam('facility_type_id') : null;
             $facilityRow->facility_comments = $this->_getParam('facility_comments');
             $facilityRow->address_1 = $this->getSanParam('facility_address1');
             $facilityRow->address_2 = $this->getSanParam('facility_address2');
             $facilityRow->lat = $lat;
             $facilityRow->long = $long;
             $facilityRow->postal_code = $this->getSanParam('facility_postal_code');
             $facilityRow->phone = $this->getSanParam('facility_phone');
             $facilityRow->fax = $this->getSanParam('facility_fax');
             $facilityRow->sponsor_option_id = $sponsor_id;
             //dupecheck
             $dupe = new Facility();
             $select = $dupe->select()->where('location_id =' . $facilityRow->location_id . ' and facility_name = "' . $facilityRow->facility_name . '"');
             if (!$facilityRow->id && $dupe->fetchRow($select)) {
                 $status->status = '';
                 $status->setStatusMessage(t('The facility could not be saved. A facility with this name already exists in that location.'));
                 return false;
             }
             $obj_id = $facilityRow->save();
             $_SESSION['status'] = t('The facility was saved.');
             if ($obj_id) {
                 if (!Facility::saveSponsors($obj_id, $sponsor_array, $sponsor_date_array, $sponsor_end_date_array)) {
                     $status->setStatusMessage(t('There was an error saving sponsor data though.'));
                     return false;
                 }
                 $status->setStatusMessage(t('The facility was saved.'));
                 $status->setRedirect('/facility/view/id/' . $obj_id);
                 return $obj_id;
             } else {
                 unset($_SESSION['status']);
                 $status->setStatusMessage(t('ERROR: The facility could not be saved.'));
             }
         }
     }
     return false;
 }
 /**
  * returns an validator for settings params or error array
  *
  * @return Zend_Filter_Input|array on success data on error message array
  * @param array $data current data for validation
  */
 public function validate($data)
 {
     // define filter
     $filterTrim = new Zend_Filter_StringTrim();
     $filter = array('deleteItems' => $filterTrim, 'imagesPosition' => $filterTrim, 'imagesHeight' => $filterTrim, 'language' => $filterTrim, 'refresh' => $filterTrim, 'lastrefresh' => $filterTrim, 'view' => $filterTrim, 'offset' => $filterTrim, 'itemsperpage' => $filterTrim, 'selected' => $filterTrim, 'dateFilter' => $filterTrim, 'dateStart' => $filterTrim, 'dateEnd' => $filterTrim, 'search' => $filterTrim, 'unread' => $filterTrim, 'starred' => $filterTrim, 'currentPriorityStart' => $filterTrim, 'currentPriorityEnd' => $filterTrim, 'saveOpenCategories' => $filterTrim, 'openCategories' => $filterTrim, 'firstUnread' => $filterTrim, 'newWindow' => $filterTrim, 'public' => $filterTrim, 'anonymizer' => $filterTrim, 'sort' => $filterTrim, 'openitems' => $filterTrim, 'iconcache' => $filterTrim);
     // define validators
     $validatorType = new Zend_Validate_InArray(array("both", "multimedia", "messages"));
     $validatorType->setMessage(Zend_Registry::get('language')->translate('Only both, multimedia, message allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validatorNotEmpty = new Zend_Validate_NotEmpty();
     $validatorNotEmpty->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_NotEmpty::IS_EMPTY);
     $validatorNum = new Zend_Validate_Int(Zend_Registry::get('session')->language);
     $validatorNum->setLocale(Zend_Registry::get('session')->language);
     $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::NOT_INT);
     $validatorInArray = new Zend_Validate_InArray(array("top", "bottom"));
     $validatorInArray->setMessage(Zend_Registry::get('language')->translate('Only top or bottom allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validatorLanguage = new Zend_Validate_InArray(Zend_Registry::get('language')->getList());
     $validatorLanguage->setMessage(Zend_Registry::get('language')->translate('Language is not available'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validatorDate = new Zend_Validate_Date();
     $validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::INVALID);
     $validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::FALSEFORMAT);
     $validatorBiggerThanZero = new Zend_Validate_GreaterThan(0);
     $validatorBiggerThanZero->setMessage(Zend_Registry::get('language')->translate('Value must be bigger than 0'), Zend_Validate_GreaterThan::NOT_GREATER);
     $validatorBetweenDays = new Zend_Validate_Between(0, 2000);
     $validatorBetweenDays->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 2000 days'), Zend_Validate_Between::NOT_BETWEEN);
     $validatorBetweenItemsperpage = new Zend_Validate_Between(0, 200);
     $validatorBetweenItemsperpage->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 200 items per page'), Zend_Validate_Between::NOT_BETWEEN);
     $validatorSort = new Zend_Validate_InArray(array("date", "dateasc", "priority", "priorityasc"));
     $validatorSort->setMessage(Zend_Registry::get('language')->translate('Only date or rating allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validators = array('deleteItems' => array($validatorNum, $validatorBetweenDays, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'imagesPosition' => array($validatorInArray, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'language' => array($validatorLanguage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'refresh' => array($validatorNum, $validatorBiggerThanZero, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'lastrefresh' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'view' => array($validatorType, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'offset' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'itemsperpage' => array($validatorNum, $validatorBetweenItemsperpage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'selected' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'dateFilter' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'search' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'unread' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'starred' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityStart' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityEnd' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'saveOpenCategories' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'openCategories' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'firstUnread' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'newWindow' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'public' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'anonymizer' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'sort' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, $validatorSort), 'openitems' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'iconcache' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL));
     // optional check date
     if (isset($data['dateFilter']) && $data['dateFilter'] == 1) {
         $validators['dateStart'] = $validatorDate;
         $validators['dateEnd'] = $validatorDate;
     } else {
         $validators['dateStart'] = array(Zend_Filter_Input::ALLOW_EMPTY => true);
         $validators['dateEnd'] = array(Zend_Filter_Input::ALLOW_EMPTY => true);
         $data['dateStart'] = '';
         $data['dateEnd'] = '';
     }
     // create validation main object
     $validator = new Zend_Filter_Input($filter, $validators, $data, array(Zend_Filter_Input::NOT_EMPTY_MESSAGE => Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Filter_Input::BREAK_CHAIN => false));
     // return filter input object
     return parent::validate($validator);
 }
Beispiel #26
0
 /**
  * Validate Web Search Options
  *
  * @param array $options
  */
 protected function _validateWebSearch($options)
 {
     $valid_options = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok', 'similar_ok', 'country', 'site', 'subscription', 'license');
     if (!is_array($options)) {
         return;
     }
     $this->_compareOptions($options, $valid_options);
     /**
      * @see Zend_Validate_Between
      */
     require_once 'Zend/Validate/Between.php';
     $between = new Zend_Validate_Between(1, 20, true);
     if (isset($options['results'])) {
         if (!$between->setMin(1)->setMax(20)->isValid($options['results'])) {
             throw new Zend_Service_Exception($options['results'] . ' is not valid for the "results" option.');
         }
     }
     if (isset($options['start'])) {
         if (!$between->setMin(1)->setMax(1000)->isValid($options['start'])) {
             throw new Zend_Service_Exception($options['start'] . ' is not valid for the "start" option.');
         }
     }
     $this->_validateLanguage($options['language']);
     $this->_validateInArray('query type', $options['type'], array('all', 'any', 'phrase'));
     $this->_validateInArray('format', $options['format'], array('any', 'html', 'msword', 'pdf', 'ppt', 'rss', 'txt', 'xls'));
     $this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial', 'cc_modifiable'));
 }
Beispiel #27
0
 /**
  * Validate Group Search Options
  *
  * @param  array $options
  * @throws Zend_Service_Exception
  * @return void
  */
 protected function _validateGroupPoolGetPhotos(array $options)
 {
     $validOptions = array('api_key', 'tags', 'method', 'group_id', 'per_page', 'page', 'extras', 'user_id');
     $this->_compareOptions($options, $validOptions);
     /**
      * @see Zend_Validate_Between
      */
     //$1 'Zend/Validate/Between.php';
     $between = new Zend_Validate_Between(1, 500, true);
     if (!$between->isValid($options['per_page'])) {
         /**
          * @see Zend_Service_Exception
          */
         //$1 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option');
     }
     /**
      * @see Zend_Validate_Int
      */
     //$1 'Zend/Validate/Int.php';
     $int = new Zend_Validate_Int();
     if (!$int->isValid($options['page'])) {
         /**
          * @see Zend_Service_Exception
          */
         //$1 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option');
     }
     // validate extras, which are delivered in csv format
     if (isset($options['extras'])) {
         $extras = explode(',', $options['extras']);
         $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');
         foreach ($extras as $extra) {
             /**
              * @todo The following does not do anything [yet], so it is commented out.
              */
             //in_array(trim($extra), $validExtras);
         }
     }
 }
Beispiel #28
0
 /**
  * Returns TRUE if value is greater than or equal to $min and less
  * than or equal to $max, FALSE otherwise. If $inc is set to
  * FALSE, then the value must be strictly greater than $min and
  * strictly less than $max.
  *
  * @deprecated since 0.8.0
  * @param      mixed $key
  * @param      mixed $min
  * @param      mixed $max
  * @param      boolean $inc
  * @return     boolean
  */
 public static function isBetween($value, $min, $max, $inc = true)
 {
     require_once 'Zend/Validate/Between.php';
     $validator = new Zend_Validate_Between($min, $max, $inc);
     return $validator->isValid($value);
 }