Ejemplo n.º 1
0
 /**
  * Validates the data structure and returns true if it is valid for this datatype
  *
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @param string $idString
  * @param string $keywordString
  * @param string $parentString
  * @param string $localeString
  *
  * @return bool
  */
 private function validateObjectAttribute($contentObjectAttribute, $idString, $keywordString, $parentString, $localeString)
 {
     $classAttribute = $contentObjectAttribute->contentClassAttribute();
     // we cannot use empty() here as there can be cases where $parentString or $idString can be "0",
     // which evaluates to false with empty(), which is wrong for our use case
     if (strlen($keywordString) == 0 && strlen($parentString) == 0 && strlen($idString) == 0 && strlen($localeString) == 0) {
         if ($contentObjectAttribute->validateIsRequired()) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'At least one tag is required to be added.'));
             return eZInputValidator::STATE_INVALID;
         }
     } else {
         if (strlen($keywordString) == 0 || strlen($parentString) == 0 || strlen($idString) == 0 || strlen($localeString) == 0) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'Attribute contains invalid data.'));
             return eZInputValidator::STATE_INVALID;
         } else {
             $idArray = explode('|#', $idString);
             $keywordArray = explode('|#', $keywordString);
             $parentArray = explode('|#', $parentString);
             $localeArray = explode('|#', $localeString);
             if (count($keywordArray) != count($idArray) || count($parentArray) != count($idArray) || count($localeArray) != count($idArray)) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'Attribute contains invalid data.'));
                 return eZInputValidator::STATE_INVALID;
             }
             $maxTags = (int) $classAttribute->attribute(self::MAX_TAGS_FIELD);
             if ($maxTags > 0 && (count($idArray) > $maxTags || count($keywordArray) > $maxTags || count($parentArray) > $maxTags || count($localeArray) > $maxTags)) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'Up to %1 tags are allowed to be added.', null, array('%1' => $maxTags)));
                 return eZInputValidator::STATE_INVALID;
             }
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
    /**
     * Validate post data, these are then used by
     * {@link eZGmapLocationType::fetchObjectAttributeHTTPInput()}
     *
     * @param eZHTTPTool $http
     * @param string $base
     * @param eZContentObjectAttribute $contentObjectAttribute
     */
    function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        $latitude = '';
        $longitude = '';
        $classAttribute = $contentObjectAttribute->contentClassAttribute();
    	if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) &&
             $http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {

            $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
            $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
        }

        if ( $latitude === '' || $longitude === '' )
        {
            if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
            {
                $contentObjectAttribute->setValidationError( ezpI18n::tr( 'extension/ezgmaplocation/datatype',
                                                                     'Missing Latitude/Longitude input.' ) );
                return eZInputValidator::STATE_INVALID;
            }
        }
        else if ( !is_numeric( $latitude ) || !is_numeric( $longitude ) )
        {
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'extension/ezgmaplocation/datatype',
                                                                 'Invalid Latitude/Longitude input.' ) );
            return eZInputValidator::STATE_INVALID;
        }

        return eZInputValidator::STATE_ACCEPTED;
    }
Ejemplo n.º 3
0
 /**
  * Validates the input and returns true if the input was valid for this datatype
  *
  * @param eZHTTPTool $http
  * @param string $base
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @return bool
  */
 function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     $classAttribute = $contentObjectAttribute->contentClassAttribute();
     if ($http->hasPostVariable($base . '_eztags_data_text_' . $contentObjectAttribute->attribute('id')) && $http->hasPostVariable($base . '_eztags_data_text2_' . $contentObjectAttribute->attribute('id')) && $http->hasPostVariable($base . '_eztags_data_text3_' . $contentObjectAttribute->attribute('id'))) {
         $data = trim($http->postVariable($base . '_eztags_data_text_' . $contentObjectAttribute->attribute('id')));
         $data2 = trim($http->postVariable($base . '_eztags_data_text2_' . $contentObjectAttribute->attribute('id')));
         $data3 = trim($http->postVariable($base . '_eztags_data_text3_' . $contentObjectAttribute->attribute('id')));
         if (strlen($data) == 0 && strlen($data2) == 0 && strlen($data3) == 0) {
             if ($contentObjectAttribute->validateIsRequired()) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
                 return eZInputValidator::STATE_INVALID;
             }
         } else {
             if (!(strlen($data) > 0 && strlen($data2) > 0 && strlen($data3) > 0)) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
                 return eZInputValidator::STATE_INVALID;
             } else {
                 $dataArray = explode('|#', $data);
                 $data2Array = explode('|#', $data2);
                 $data3Array = explode('|#', $data3);
                 if (count($data2Array) != count($dataArray) || count($data3Array) != count($dataArray)) {
                     $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
                     return eZInputValidator::STATE_INVALID;
                 }
                 $maxTags = (int) $classAttribute->attribute(self::MAX_TAGS_FIELD);
                 if ($maxTags > 0 && (count($dataArray) > $maxTags || count($data2Array) > $maxTags || count($data3Array) > $maxTags)) {
                     $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
                     return eZInputValidator::STATE_INVALID;
                 }
             }
         }
     } else {
         if ($contentObjectAttribute->validateIsRequired()) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
             return eZInputValidator::STATE_INVALID;
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
Ejemplo n.º 4
0
 /**
  * Validates the input and returns the validity status code
  *
  * @param eZHTTPTool $http
  * @param string $base
  * @param eZContentObjectAttribute $contentObjectAttribute
  *
  * @return int
  */
 function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     $classList = $http->postVariable($base . self::CLASS_LIST_VARIABLE . $contentObjectAttribute->attribute("id"), array());
     $classList = !is_array($classList) ? array() : $classList;
     if (empty($classList) && $contentObjectAttribute->validateIsRequired()) {
         $contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
         return eZInputValidator::STATE_INVALID;
     }
     $invalidClassIdentifiers = array();
     foreach ($classList as $classIdentifier) {
         if (!eZContentClass::exists($classIdentifier, eZContentClass::VERSION_STATUS_DEFINED, false, true)) {
             $invalidClassIdentifiers[] = $classIdentifier;
         }
     }
     if (!empty($invalidClassIdentifiers)) {
         if (count($invalidClassIdentifiers) == 1) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr("extension/ngclasslist/datatypes", "Class with identifier '%identifier%' does not exist", null, array("%identifier%" => $invalidClassIdentifiers[0])));
         } else {
             $contentObjectAttribute->setValidationError(ezpI18n::tr("extension/ngclasslist/datatypes", "Classes with '%identifiers%' identifiers do not exist", null, array("%identifiers%" => implode(", ", $invalidClassIdentifiers))));
         }
         return eZInputValidator::STATE_INVALID;
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
Ejemplo n.º 5
0
 /**
  * Validates the input for collection attribute and returns the validity status code
  *
  * @param eZHTTPTool $http
  * @param string $base
  * @param eZContentObjectAttribute $contentObjectAttribute
  *
  * @return int
  */
 function validateCollectionAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     if ($http->hasPostVariable($base . self::OIB_VARIABLE . $contentObjectAttribute->attribute("id"))) {
         $data = trim($http->postVariable($base . self::OIB_VARIABLE . $contentObjectAttribute->attribute("id")));
         if (empty($data)) {
             if ($contentObjectAttribute->validateIsRequired()) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
                 return eZInputValidator::STATE_INVALID;
             }
         } else {
             if (!$this->validateOib($data)) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr("extension/ngoib/datatypes", "Personal identification number is not valid."));
                 return eZInputValidator::STATE_INVALID;
             }
         }
     } else {
         $contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
         return eZInputValidator::STATE_INVALID;
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
 /**
  * Validates content object attribute HTTP input
  *
  * @param eZHTTPTool $http
  * @param string $base
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @param bool $isInformationCollection
  *
  * @return int
  */
 protected function validateAttributeHTTPInput($http, $base, $contentObjectAttribute, $isInformationCollection = false)
 {
     /** @var eZContentClassAttribute $classAttribute */
     $classAttribute = $contentObjectAttribute->contentClassAttribute();
     $classContent = $classAttribute->content();
     $infoCollectionCheck = $isInformationCollection == $classAttribute->attribute('is_information_collector');
     $isRequired = $contentObjectAttribute->validateIsRequired();
     $selectionName = join('_', array($base, 'sckenhancedselection_selection', $contentObjectAttribute->attribute('id')));
     if ($http->hasPostVariable($selectionName)) {
         $selection = $http->postVariable($selectionName);
         if ($infoCollectionCheck) {
             switch (true) {
                 case $isRequired === true && count($selection) == 0:
                 case $isRequired === true && count($selection) == 1 && empty($selection[0]):
                     $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'This is a required field.'));
                     return eZInputValidator::STATE_INVALID;
             }
         }
     } else {
         if ($infoCollectionCheck && $isRequired && $classContent['is_multiselect'] == 1) {
             $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'This is a required field.'));
         } else {
             if ($infoCollectionCheck && $isRequired) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'No POST variable. Please check your configuration.'));
             } else {
                 return eZInputValidator::STATE_ACCEPTED;
             }
         }
         return eZInputValidator::STATE_INVALID;
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
Ejemplo n.º 7
0
 /**
  * Validates the input for collection attribute and returns the validity status code
  *
  * @param eZHTTPTool $http
  * @param string $base
  * @param eZContentObjectAttribute $contentObjectAttribute
  *
  * @return int
  */
 function validateCollectionAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     if ($http->hasPostVariable($base . self::FMCP_VAR . $contentObjectAttribute->attribute("id"))) {
         $data = trim($http->postVariable($base . self::FMCP_VAR . $contentObjectAttribute->attribute("id")));
         if (empty($data)) {
             if ($contentObjectAttribute->validateIsRequired()) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
                 return eZInputValidator::STATE_INVALID;
             }
         } else {
             if (!$this->validateColor($data)) {
                 $contentObjectAttribute->setValidationError(ezpI18n::tr("extension/fmColorpicker/datatypes", "the color code is not valid."));
                 return eZInputValidator::STATE_INVALID;
             }
         }
     } else {
         $contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
         return eZInputValidator::STATE_INVALID;
     }
     return eZInputValidator::STATE_ACCEPTED;
 }