/** * Returns the value of the property $name. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @ignore */ public function __get( $name ) { switch ( $name ) { case 'dataMap': { if ( isset( $this->object ) ) return $this->object->dataMap(); else return array(); } break; default: { if ( isset( $this->dataMap[$name] ) ) { return $this->dataMap[$name]->content(); } if ( !$this->object instanceof eZContentObject ) throw new ezcBaseInvalidParentClassException( 'eZContentObject', $this->object ); if ( $this->object->hasAttribute( $name ) ) return $this->object->attribute( $name ); throw new ezcBasePropertyNotFoundException( '->object->attribute( ' . $name . ' )' ); } } }
/** * @param eZContentObject $object * @return bool */ public static function updateObjectSource($object) { /* @var $sourceAttribute eZContentObjectAttribute */ $dataMap = $object->dataMap(); $sourceAttribute = $dataMap['source']; $previousValue = $sourceAttribute->attribute('data_text'); $newValue = self::getSourceString($object); if($newValue && ($previousValue != $newValue)) { /* @var $version eZContentObjectVersion */ $version = $object->currentVersion(); $version->setAttribute( 'modified', time() ); $version->store(); $sourceAttribute->setAttribute('data_text', self::getSourceString($object)); $sourceAttribute->store(); eZOperationHandler::execute('content', 'publish', array( 'object_id' => $object->attribute('id'), 'version' => $object->attribute('current_version') ) ); } return true; }
/** * Retourne les éléments de sitemap image pour un content object $object donné * @param eZContentObject $object * @return array(xrowSitemapItemImage) */ private static function getSitemapImageItems(eZContentObject $object) { $images = array(); // D'abord depuis la datamap $images = array_merge($images, self::getSitemapImageItemFromDataMap($object->dataMap())); // Puis avec les related objects $aParamsRelated = array('object_id' => $object->attribute('id'), 'all_relations' => true); $aImageObjectIDs = array(); $relatedObjects = eZFunctionHandler::execute('content', 'related_objects', $aParamsRelated); $imagesRelated = array(); foreach ($relatedObjects as $relatedObject) { switch ($relatedObject->attribute('class_identifier')) { case 'image': $imagesRelated = array_merge($imagesRelated, self::getSitemapImageItemFromDataMap($relatedObject->dataMap())); break; } } // Puis les children (gallery) $imagesChildren = array(); $aParamsChildren = array('class_filter_type' => 'include', 'class_filter_array' => array('image'), 'parent_node_id' => $object->attribute('main_node_id')); $aChildren = eZFunctionHandler::execute('content', 'list', $aParamsChildren); foreach ($aChildren as $child) { $imagesChildren = array_merge($imagesChildren, self::getSitemapImageItemFromDataMap($child->object()->dataMap())); } return array_merge($images, $imagesRelated, $imagesChildren); }
/** * Check state of all medias related to the article * @param eZContentObject $articleContentObject * @return bool */ private static function checkMediaFromArticle( $articleContentObject ) { /* @type $mediaClassIdentifiers array */ $siteIni = eZINI::instance( 'site.ini' ); $mediaClassIdentifiers = $siteIni->variable( 'EventManager', 'MediaClassIdentifiers' ); //Retrieve all media related to the article /* @type $articleDataMap eZContentObjectAttribute[] */ $articleDataMap = $articleContentObject->dataMap(); if( !isset( $articleDataMap['media_content'] ) ) return true; $mediaContent = $articleDataMap['media_content']->content(); if( empty( $mediaContent['relation_list'] ) ) return true; foreach( $mediaContent['relation_list'] as $mediaData ) { if( !in_array( $mediaData['contentclass_identifier'], $mediaClassIdentifiers ) ) continue; if(!self::mediaIsCompleted($mediaData['contentobject_id'])) return false; } // retrieve all medias in core content related to the article $relatedCoreContentList = RelatedCoreContent::getMediasFromArticle($articleContentObject->attribute("id"), $articleContentObject->currentLanguage()); /** @var RelatedCoreContent $relatedCoreContent */ foreach($relatedCoreContentList as $relatedCoreContent) { if(!self::mediaIsCompleted($relatedCoreContent->attribute("media_object_id"))) return false; } return true; }
/** * Set content object attributes * * @private * @param eZContentObject $object * @param array( attributeIdentifier => attributeStringValue ) $attributesValues * @return void */ private function setObjectAttributes(eZContentObject $object, array $attributesValues) { $attributes = $object->dataMap(); foreach ($attributesValues as $identifier => $value) { if (isset($attributes[$identifier])) { $attribute = $attributes[$identifier]; switch ($attribute->attribute('data_type_string')) { case 'ezimage': $arr = explode('|', trim($value)); $source = str_replace(' ', '%20', $arr[0]); if (file_exists($source)) { // Handle local files $content = $attribute->attribute('content'); $content->initializeFromFile($source, isset($arr[1]) ? $arr[1] : null); $content->store($attribute); } else { // Handle remote files $filename = 'var/cache/' . md5(microtime()) . substr($source, strrpos($source, '.')); if (!empty($source)) { if (in_array('curl', get_loaded_extensions())) { $ch = curl_init(); $out = fopen($filename, 'w'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FILE, $out); curl_exec($ch); curl_close($ch); fclose($out); } else { copy($source, $filename); } } if (file_exists($filename)) { $content = $attribute->attribute('content'); $content->initializeFromFile($filename, isset($arr[1]) ? $arr[1] : null); $content->store($attribute); unlink($filename); } } break; case 'ezxmltext': $parser = new eZOEInputParser(); $value = '<div>' . trim($value) . '</div>'; $document = $parser->process($value); $urlIDArray = $parser->getUrlIDArray(); if (count($urlIDArray) > 0) { eZOEXMLInput::updateUrlObjectLinks($attribute, $urlIDArray); } $object->appendInputRelationList($parser->getLinkedObjectIDArray(), eZContentObject::RELATION_LINK); $object->appendInputRelationList($parser->getEmbeddedObjectIDArray(), eZContentObject::RELATION_EMBED); $value = $document ? eZXMLTextType::domString($document) : null; $attribute->fromString($value); break; default: if (is_callable(array($attribute, 'fromString'))) { $attribute->fromString($value); } else { $attribute->setAttribute('data_text', $value); } } $attribute->store(); } } }