/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @return array for further processing */ public static function getAttributeData ( eZContentObjectAttribute $contentObjectAttribute ) { $dataTypeIdentifier = $contentObjectAttribute->attribute( 'data_type_string' ); $contentClassAttribute = eZContentClassAttribute::fetch( $contentObjectAttribute->attribute( 'contentclassattribute_id' ) ); $attributeHandler = $dataTypeIdentifier . 'SolrStorage'; // prefill the array with generic metadata first $target = array ( 'data_type_identifier' => $dataTypeIdentifier, 'version_format' => self::STORAGE_VERSION_FORMAT, 'attribute_identifier' => $contentClassAttribute->attribute( 'identifier' ), 'has_content' => $contentObjectAttribute->hasContent(), ); if ( class_exists( $attributeHandler ) ) { $attributeContent = call_user_func( array( $attributeHandler, 'getAttributeContent' ), $contentObjectAttribute, $contentClassAttribute ); return array_merge( $target, $attributeContent, array( 'content_method' => self::CONTENT_METHOD_CUSTOM_HANDLER ) ); } else { $target = array_merge( $target, array( 'content_method' => self::CONTENT_METHOD_TOSTRING, 'content' => $contentObjectAttribute->toString(), 'has_rendered_content' => false, 'rendered' => null )); return $target; } }
/** * (called for each obj attribute) */ public function checkObjectAttribute(array $contentObjectAttribute) { // we adopt the ez api instead of acting on raw data $contentObjectAttribute = new eZContentObjectAttribute($contentObjectAttribute); $binaryFile = $contentObjectAttribute->attribute('content'); $warnings = array(); // do not check attributes which do not even contain images if ($binaryFile) { // get path to original file $filePath = $binaryFile->attribute('filepath'); // check if it is on fs (remember, images are clusterized) $file = eZClusterFileHandler::instance($filePath); if (!$file->exists()) { $warnings[] = "Binary file not found: {$filePath}" . $this->postfixErrorMsg($contentObjectAttribute); } else { // if it is, check its size as well if ($this->maxSize > 0) { $maxSize = $this->maxSize * 1024 * 1024; if ($file->size() > $maxSize) { $warnings[] = "Binary file larger than {$maxSize} bytes : " . $file->size() . $this->postfixErrorMsg($contentObjectAttribute); } } } } else { if (!$this->nullable) { $warnings[] = "Attribute is null and it should not be" . $this->postfixErrorMsg($contentObjectAttribute); } } return $warnings; }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $content = $contentObjectAttribute->attribute( 'content' ); $multioptionArray = array( 'name' => $content->attribute( 'name' ), ); foreach ( $content->attribute( 'multioption_list' ) as $option ) { $optionArray = array( 'name' => $option['name'], 'default_option_id' => $option['default_option_id'] ); foreach ( $option['optionlist'] as $value ) { $optionArray['optionlist'][] = array( 'value' => $value['value'], 'additional_price' => $value['additional_price'] ); } $multioptionArray['multioption_list'][] = $optionArray; } return array( 'content' => $multioptionArray, 'has_rendered_content' => false, 'rendered' => null, ); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $authorList = array(); foreach ($contentObjectAttribute->attribute('content')->attribute('author_list') as $author) { $authorList[] = array('id' => $author['id'], 'name' => $author['name'], 'email' => $author['email']); } return array('content' => $authorList, 'has_rendered_content' => false, 'rendered' => null); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $availableEnumerations = array(); foreach ($contentObjectAttribute->content()->ObjectEnumerations as $enumeration) { $availableEnumerations[] = array('id' => $enumeration->EnumID, 'element' => $enumeration->EnumElement, 'value' => $enumeration->EnumValue); } return array('content' => $availableEnumerations, 'has_rendered_content' => false, 'rendered' => null); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { return array( 'content' => $contentObjectAttribute->content()->KeywordArray, 'has_rendered_content' => false, 'rendered' => null, ); }
/** * Returns the content of the matrix to be stored in Solr * * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $rows = $contentObjectAttribute->content()->attribute('rows'); $target = array('has_rendered_content' => false, 'rendered' => null, 'content' => array()); foreach ($rows['sequential'] as $elt) { $target['content'][] = $elt['columns']; } return $target; }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $content = $contentObjectAttribute->attribute('content'); $optionArray = array('name' => $content->attribute('name')); foreach ($content->attribute('option_list') as $value) { $optionArray['option_list'][] = array('id' => $value['id'], 'value' => $value['value'], 'additional_price' => $value['additional_price'], 'is_default' => $value['is_default']); } return array('content' => $optionArray, 'has_rendered_content' => false, 'rendered' => null); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $objectAttributeContent = $contentObjectAttribute->attribute('content'); $objectIDList = array(); foreach ($objectAttributeContent['relation_list'] as $objectInfo) { $objectIDList[] = $objectInfo['contentobject_id']; } return array('content' => $objectIDList, 'has_rendered_content' => false, 'rendered' => null); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $dateTime = new DateTime( '@' . $contentObjectAttribute->attribute( 'data_int' ) ); return array( 'content' => $dateTime->format( 'c' ), 'has_rendered_content' => false, 'rendered' => null, ); }
/** * Initializes the object attribute with some data. * @param eZContentObjectAttribute $objectAttribute * @param int $currentVersion * @param eZContentObjectAttribute $originalContentObjectAttribute */ function initializeObjectAttribute($objectAttribute, $currentVersion, $originalContentObjectAttribute) { if (NULL === $currentVersion) { $data = ''; } else { $data = $originalContentObjectAttribute->attribute("data_text"); } $objectAttribute->setAttribute("data_text", $data); }
/** * (non-PHPdoc) * @see extension/sqliimport/classes/content/diffhandlers/ISQLIDiffHandler::contentIsModified() */ public static function contentIsModified($data, eZContentObjectAttribute $attribute) { $isModified = false; $originalFilename = $attribute->attribute('content')->attribute('original_filename'); $newFilename = basename((string) $data); if ($newFilename != $originalFilename) { $isModified = true; } return $isModified; }
/** * Validates $data with the constraints defined on the class attribute * * @param $data * @param eZContentObjectAttribute $contentObjectAttribute * @param eZContentClassAttribute $classAttribute * * @return int */ function validateStringHTTPInput($data, $contentObjectAttribute, $classAttribute) { $maxLen = $classAttribute->attribute(self::MAX_LEN_FIELD); $textCodec = eZTextCodec::instance(false); if ($textCodec->strlen($data) > $maxLen and $maxLen > 0) { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input text is too long. The maximum number of characters allowed is %1.'), $maxLen); return eZInputValidator::STATE_INVALID; } return eZInputValidator::STATE_ACCEPTED; }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array with keys 'content', 'has_rendered_content', 'rendered' * required first level elements 'method', 'version_format', 'data_type_identifier', 'content' * optional first level element is 'rendered' which should store (template) rendered xhtml snippets */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $target = array( 'content' => $contentObjectAttribute->content(), 'has_rendered_content' =>false, 'rendered' => null ); return $target ; }
/** * Gets the instance of Open Graph attribute handler for the attribute * * @param eZContentObjectAttribute $objectAttribute * * @return ngOpenGraphBase */ static function getInstance(eZContentObjectAttribute $objectAttribute) { $datatypeString = $objectAttribute->attribute('data_type_string'); $dataTypeHandlers = self::$ogIni->variable('OpenGraph', 'DataTypeHandlers'); if (array_key_exists($datatypeString, $dataTypeHandlers)) { if (class_exists($dataTypeHandlers[$datatypeString])) { return new $dataTypeHandlers[$datatypeString]($objectAttribute); } } return new ngOpenGraphBase($objectAttribute); }
/** * (called for each obj attribute) */ public function checkObjectAttribute(array $contentObjectAttribute) { if ($this->nullable) { return array(); } $contentObjectAttribute = new eZContentObjectAttribute($contentObjectAttribute); if (!$contentObjectAttribute->attribute('has_content')) { return array("Attribute is null and it should not be" . $this->postfixErrorMsg($contentObjectAttribute)); } return array(); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return json encoded string for further processing * required first level elements 'method', 'version_format', 'data_type_identifier', 'content' * optional first level element is 'rendered' which should store (template) rendered xhtml snippets */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $dataTypeIdentifier = $contentObjectAttribute->attribute('data_type_string'); $attributeContents = $contentObjectAttribute->content(); $doc = new DOMDocument('1.0'); $doc->loadXML($attributeContents->attribute('xml_data')); $xpath = new DOMXPath($doc); $content = $doc->saveXML($xpath->query('/*')->item(0)); $target = array('content' => $content, 'has_rendered_content' => $contentObjectAttribute->hasContent(), 'rendered' => $attributeContents->attribute('output')->attribute('output_text')); return $target; }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent(eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute) { $selectedOptionsList = array_fill_keys($contentObjectAttribute->content(), true); $availableOptionsArray = $contentObjectAttribute->attribute('class_content'); $finalAvailableOptions = array(); foreach ($availableOptionsArray['options'] as $availableOption) { if (isset($selectedOptionsList[$availableOption['id']])) { $finalAvailableOptions[] = array('name' => $availableOption['name'], 'id' => $availableOption['id']); } } return array('content' => $finalAvailableOptions, 'has_rendered_content' => false, 'rendered' => null); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $url = eZURL::fetch( $contentObjectAttribute->attribute( 'data_int' ) ); return array( 'content' => array( 'url' => ( $url instanceof eZURL ) ? $url->attribute( 'url' ) : null, 'text' => $contentObjectAttribute->attribute( 'data_text' ), ), 'has_rendered_content' => false, 'rendered' => null, ); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $category = $contentObjectAttribute->attribute( 'content' ); return array( 'content' => array( 'name' => $category ? $category->attribute( 'name' ) : null, 'id' => $category ? $category->attribute( 'id' ) : null, ), 'has_rendered_content' => false, 'rendered' => null, ); }
function normalizeValue($newValue, $currentValue, eZContentObjectAttribute $attribute) { switch ($attribute->attribute('data_type_string')) { case 'eztime': $parts = explode(':', $newValue); if (count($parts) == 2) { $parts[] = '00'; //seconds $newValue = implode(':', $parts); } } return $newValue; }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $user = eZUser::fetch( $contentObjectAttribute->attribute( "contentobject_id" ) ); return array( 'content' => array( 'id' => $user->attribute( 'id' ), 'login' => $user->attribute( 'login' ), 'email' => $user->attribute( 'email' ), ), 'has_rendered_content' => false, 'rendered' => null, ); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $price = $contentObjectAttribute->attribute( 'content' ); return array( 'content' => array( 'price' => $price->attribute( 'price' ), 'selected_vat_type' => $price->attribute( 'selected_vat_type' )->attribute( 'id' ), 'is_vat_included' => (bool)$price->attribute( 'is_vat_included' ), ), 'has_rendered_content' => false, 'rendered' => null, ); }
/** * @param eZContentObjectAttribute $contentObjectAttribute the attribute to serialize * @param eZContentClassAttribute $contentClassAttribute the content class of the attribute to serialize * @return array */ public static function getAttributeContent( eZContentObjectAttribute $contentObjectAttribute, eZContentClassAttribute $contentClassAttribute ) { $option = $contentObjectAttribute->attribute( 'content' ); return array( 'content' => array( 'name' => $option->attribute( 'name' ), 'start_value' => $option->attribute( 'start_value' ), 'stop_value' => $option->attribute( 'stop_value' ), 'step_value' => $option->attribute( 'step_value' ), ), 'has_rendered_content' => false, 'rendered' => null, ); }
/** * Creates the eZContentObject from the uploaded file * * @param eZHTTPFile $file * @param eZContentObjectTreeNode $location * @param string $name * @return eZContentObject * @throw InvalidArgumentException if the parent location does not exists * @throw RuntimeException if the object can not be created */ public function createObject( $file, $parentNodeId, $name = '' ) { $result = array(); $parentNode = eZContentObjectTreeNode::fetch( $parentNodeId ); if ( !$parentNode instanceof eZContentObjectTreeNode ) { throw new InvalidArgumentException( ezpI18n::tr( 'extension/ezjscore/ajaxuploader', 'Location not found.' ) ); } $upload = new eZContentUpload(); $r = $upload->handleLocalFile( $result, $file, $parentNodeId, null, $name, $this->attribute->attribute( 'language_code' ) ); if ( !$r || !$result['contentobject'] instanceof eZContentObject ) { throw new RuntimeException( ezpI18n::tr( 'extension/ezjscore/ajaxuploader', 'Unable to create the content object to add to the relation: %detail', null, array( '%detail', $result['errors'][0]['description'] ) ) ); } return $result['contentobject']; }
/** * Store the modification made to an eZContentClass. * * @param eZContentClass Content class to be stored. * @param array[eZContentClassAttribute] Attributes of the new content class. * @param array Unordered view parameters */ public function store(eZContentClass $class, array $attributes, array &$unorderedParameters) { $oldClassAttributes = $class->fetchAttributes($class->attribute('id'), true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExists = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($class->fetchAttributes() as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExists = true; break; } } if (!$attributeExists) { foreach (eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID) as $objectAttribute) { $objectAttribute->removeThis($objectAttribute->attribute('id')); } } } $class->storeDefined($attributes); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExists = false; $newClassAttributeID = $newClassAttribute->attribute('id'); foreach ($oldClassAttributes as $oldClassAttribute) { if ($newClassAttributeID == $oldClassAttribute->attribute('id')) { $attributeExists = true; break; } } if (!$attributeExists) { $newClassAttribute->initializeObjectAttributes($objects); } } }
/** * Looks up ezcontentobjectattribute entries matching an image filepath and * a contentobjectattribute ID * * @param string $filePath file path to look up as URL in the XML string * @param int $contentObjectAttributeID * * @return array An array with a series of ezcontentobject_attribute's id, version and language_code */ static function fetchImageAttributesByFilepath($filepath, $contentObjectAttributeID) { $db = eZDB::instance(); $contentObjectAttributeID = (int) $contentObjectAttributeID; $cond = array('id' => $contentObjectAttributeID); $fields = array('contentobject_id', 'contentclassattribute_id'); $limit = array('offset' => 0, 'length' => 1); $rows = eZPersistentObject::fetchObjectList(eZContentObjectAttribute::definition(), $fields, $cond, null, $limit, false); if (count($rows) != 1) { return array(); } $contentObjectID = (int) $rows[0]['contentobject_id']; $contentClassAttributeID = (int) $rows[0]['contentclassattribute_id']; // Transform ", &, < and > to entities since they are being transformed in entities by DOM // See eZImageAliasHandler::initialize() // Ref https://jira.ez.no/browse/EZP-20090 $filepath = $db->escapeString(htmlspecialchars($filepath, version_compare(PHP_VERSION, '5.4.0', '>=') ? ENT_COMPAT | ENT_HTML401 : ENT_COMPAT, 'UTF-8')); // Escape _ in like to avoid it to act as a wildcard ! $filepath = addcslashes($filepath, "_"); $query = "SELECT id, version, language_code\n FROM ezcontentobject_attribute\n WHERE contentobject_id = {$contentObjectID} AND\n contentclassattribute_id = {$contentClassAttributeID} AND\n data_text LIKE '%url=\"{$filepath}\"%'"; if ($db->databaseName() == 'oracle') { $query .= " ESCAPE '\\'"; } $rows = $db->arrayQuery($query); return $rows; }
/** * (called for each obj attribute) */ public function checkObjectAttribute(array $contentObjectAttribute) { // we adopt the ez api instead of acting on raw data $contentObjectAttribute = new eZContentObjectAttribute($contentObjectAttribute); // for ezuser datatype, the user is always created even if attribute is set to nullable... $warnings = array(); $userid = $contentObjectAttribute->attribute('contentobject_id'); $user = $contentObjectAttribute->attribute('content'); if (!$user) { $warnings[] = "No ezuser {$userid} found" . $this->postfixErrorMsg($contentObjectAttribute); } $settings = eZUserSetting::fetch($userid); if (!$settings) { $warnings[] = "No settings found for user {$userid}" . $this->postfixErrorMsg($contentObjectAttribute); } return $warnings; }
/** * Makes the 'contentclass_attribute' attribute a 'field' instead * of a function attribute, for testing purposes. * * @return the overridden definition array */ public static function definition() { $definitionOverride = array('fields' => array('contentclass_attribute' => array('name' => "ContentClassAttribute", 'datatype' => 'mixed'))); $definition = array_merge_recursive(parent::definition(), $definitionOverride); $definition['class_name'] = __CLASS__; unset($definition['function_attributes']['contentclass_attribute']); return $definition; }
/** * Validates $data with the constraints defined on the class attribute * * @param $data * @param eZContentObjectAttribute $contentObjectAttribute * @param eZContentClassAttribute $classAttribute * * @return int */ function validateIntegerHTTPInput($data, $contentObjectAttribute, $classAttribute) { $min = $classAttribute->attribute(self::MIN_VALUE_FIELD); $max = $classAttribute->attribute(self::MAX_VALUE_FIELD); $input_state = $classAttribute->attribute(self::INPUT_STATE_FIELD); switch ($input_state) { case self::NO_MIN_MAX_VALUE: $this->IntegerValidator->setRange(false, false); $state = $this->IntegerValidator->validate($data); if ($state === eZInputValidator::STATE_INVALID || $state === eZInputValidator::STATE_INTERMEDIATE) { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input is not a valid integer.')); } else { return $state; } break; case self::HAS_MIN_VALUE: $this->IntegerValidator->setRange($min, false); $state = $this->IntegerValidator->validate($data); if ($state === eZInputValidator::STATE_ACCEPTED) { return eZInputValidator::STATE_ACCEPTED; } else { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The number must be greater than %1'), $min); } break; case self::HAS_MAX_VALUE: $this->IntegerValidator->setRange(false, $max); $state = $this->IntegerValidator->validate($data); if ($state === 1) { return eZInputValidator::STATE_ACCEPTED; } else { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The number must be less than %1'), $max); } break; case self::HAS_MIN_MAX_VALUE: $this->IntegerValidator->setRange($min, $max); $state = $this->IntegerValidator->validate($data); if ($state === 1) { return eZInputValidator::STATE_ACCEPTED; } else { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The number is not within the required range %1 - %2'), $min, $max); } break; } return eZInputValidator::STATE_INVALID; }