/** * test fetchByIdentifier function */ public function testFetchByIdentifier() { global $eZContentSectionObjectCache; $section = new eZSection(array()); $section->setAttribute('name', 'Test Section'); $section->setAttribute('identifier', 'test_section'); $section->store(); $sectionID = $section->attribute('id'); // assert that if the cache is set after fetching $section2 = eZSection::fetchByIdentifier('test_section'); $this->assertEquals($sectionID, $section2->attribute('id')); // assert that object is cached $this->assertNotNull($eZContentSectionObjectCache['test_section']); $this->assertNotNull($eZContentSectionObjectCache[$sectionID]); // assert that the two object refer to same object $this->assertSame($eZContentSectionObjectCache[$sectionID], $section2); $this->assertSame(eZSection::fetch($sectionID), $section2); // fetchByID and fetchByIdentifier, assert that the result is the same $section3 = new eZSection(array()); $section3->setAttribute('name', 'Test Section3'); $section3->setAttribute('identifier', 'test_section3'); $section3->store(); $objectByID = eZSection::fetch($section3->attribute('id')); $objectByIdentifier = eZSection::fetchByIdentifier('test_section3'); $this->assertSame($objectByID, $objectByIdentifier); $arrayByIdentifier = eZSection::fetch($section3->attribute('id'), false); $this->assertTrue(is_array($arrayByIdentifier)); }
/** * Fetch section object given either section id or section identifier. There should be one and only one parameter. * @param integer $sectionID * @param string $sectionIdentifier * @return object */ function fetchSectionObject( $sectionID = false, $sectionIdentifier = false ) { if( $sectionID !== false ) { if( $sectionIdentifier !== false ) { $sectionObject = null; } else { $sectionObject = eZSection::fetch( $sectionID ); } } else { if( $sectionIdentifier === false ) { $sectionObject = null; } else { $sectionObject = eZSection::fetchByIdentifier( $sectionIdentifier ); } } if ( $sectionObject === null ) return array( 'error' => array( 'error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND ) ); return array( 'result' => $sectionObject ); }
function sectionEditActionCheck( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) { if ( $module->isCurrentAction( 'SectionEdit' ) ) { $http = eZHTTPTool::instance(); if ( $http->hasPostVariable( 'SelectedSectionId' ) ) { $selectedSectionID = (int) $http->postVariable( 'SelectedSectionId' ); $selectedSection = eZSection::fetch( $selectedSectionID ); if ( is_object( $selectedSection ) ) { $currentUser = eZUser::currentUser(); if ( $currentUser->canAssignSectionToObject( $selectedSectionID, $object ) ) { $db = eZDB::instance(); $db->begin(); $assignedNodes = $object->attribute( 'assigned_nodes' ); if ( count( $assignedNodes ) > 0 ) { foreach ( $assignedNodes as $node ) { if ( eZOperationHandler::operationIsAvailable( 'content_updatesection' ) ) { $operationResult = eZOperationHandler::execute( 'content', 'updatesection', array( 'node_id' => $node->attribute( 'node_id' ), 'selected_section_id' => $selectedSectionID ), null, true ); } else { eZContentOperationCollection::updateSection( $node->attribute( 'node_id' ), $selectedSectionID ); } } } else { // If there are no assigned nodes we should update db for the current object. $objectID = $object->attribute( 'id' ); $db->query( "UPDATE ezcontentobject SET section_id='$selectedSectionID' WHERE id = '$objectID'" ); $db->query( "UPDATE ezsearch_object_word_link SET section_id='$selectedSectionID' WHERE contentobject_id = '$objectID'" ); } $object->expireAllViewCache(); $db->commit(); } else { eZDebug::writeError( "You do not have permissions to assign the section <" . $selectedSection->attribute( 'name' ) . "> to the object <" . $object->attribute( 'name' ) . ">." ); } $module->redirectToView( 'edit', array( $object->attribute( 'id' ), $editVersion, $editLanguage, $fromLanguage ) ); } } } }
function sectionEditActionCheck($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage) { if (!$module->isCurrentAction('SectionEdit')) { return; } $http = eZHTTPTool::instance(); if (!$http->hasPostVariable('SelectedSectionId')) { return; } $selectedSection = eZSection::fetch((int) $http->postVariable('SelectedSectionId')); if (!$selectedSection instanceof eZSection) { return; } $selectedSection->applyTo($object); eZContentCacheManager::clearContentCacheIfNeeded($object->attribute('id')); $module->redirectToView('edit', array($object->attribute('id'), $editVersion, $editLanguage, $fromLanguage)); }
$firstLoop = false; } $className = $class->attribute('name'); $limitation .= "'" . $className . "'"; } } } else { $limitation = ezpI18n::tr('kernel/shop', 'Any class'); } $sectionRuleValues = eZDiscountSubRuleValue::fetchBySubRuleID($discountRuleID, 1); if ($sectionRuleValues != null) { $limitation .= ' ' . ezpI18n::tr('kernel/shop', 'in sections') . ' '; $firstLoop = true; foreach ($sectionRuleValues as $sectionRuleValue) { $sectionID = $sectionRuleValue->attribute('value'); $section = eZSection::fetch($sectionID); if ($section) { if (!$firstLoop) { $limitation .= ', '; } else { $firstLoop = false; } $sectionName = $section->attribute('name'); $limitation .= "'" . $sectionName . "'"; } } } else { $limitation .= ' ' . ezpI18n::tr('kernel/shop', 'in any section'); } $productRuleValues = eZDiscountSubRuleValue::fetchBySubRuleID($discountRuleID, 2); if ($productRuleValues != null) {
* @version 2012.6 * @package kernel * @subpackage content */ $tpl = eZTemplate::factory(); $module = $Params['Module']; $http = eZHTTPTool::instance(); $pContentObjectId = $Params['ContentObjectID']; $pVersion = $Params['version']; $tpl->setVariable('contentObjectId', $pContentObjectId); $tpl->setVariable('version', $pVersion); $virtualNodeID = 0; $contentObject = eZContentObject::fetch($pContentObjectId); $contentObjectVersion = $contentObject->version($pVersion); $nodeAssignments = $contentObjectVersion->attribute('node_assignments'); $contentClass = eZContentClass::fetch($contentObject->attribute('contentclass_id')); $section = eZSection::fetch($contentObject->attribute('section_id')); $navigationPartIdentifier = $section->attribute('navigation_part_identifier'); $res = eZTemplateDesignResource::instance(); $designKeys = array(array('object', $contentObject->attribute('id')), array('node', $virtualNodeID), array('remote_id', $contentObject->attribute('remote_id')), array('class', $contentClass->attribute('id')), array('class_identifier', $contentClass->attribute('identifier')), array('class_group', $contentObject->attribute('match_ingroup_id_list')), array('state', $contentObject->attribute('state_id_array')), array('state_identifier', $contentObject->attribute('state_identifier_array')), array('section', $contentObject->attribute('section_id')), array('section_identifier', $section->attribute('identifier'))); $res->setKeys($designKeys); if ($http->hasSessionVariable('RedirectURIAfterPublish')) { $tpl->setVariable('redirect_uri', $http->sessionVariable('RedirectURIAfterPublish')); } $tpl->setVariable('content_object', $contentObject); $tpl->setVariable('content_object_version', $contentObjectVersion); $tpl->setVariable('content_class', $contentClass); $Result['path'] = array(array('text' => ezpI18n::tr('kernel/content', 'Content'), 'url' => false), array('text' => ezpI18n::tr('kernel/content', 'Publishing queue'), 'url' => false), array('text' => $contentObject->attribute('name'), 'url' => false)); $Result['content'] = $tpl->fetch('design:content/queued.tpl'); $Result['navigation_part'] = $navigationPartIdentifier; return $Result;
} $contentObjectID = $http->postVariable('ContentObjectID', 1); $hideRemoveConfirm = false; if ($http->hasPostVariable('HideRemoveConfirmation')) { $hideRemoveConfirm = $http->postVariable('HideRemoveConfirmation') ? true : false; } if ($contentNodeID != null) { $http->setSessionVariable('CurrentViewMode', $viewMode); $http->setSessionVariable('ContentNodeID', $parentNodeID); $http->setSessionVariable('HideRemoveConfirmation', $hideRemoveConfirm); $http->setSessionVariable('DeleteIDArray', array($contentNodeID)); $http->setSessionVariable('RedirectURIAfterRemove', $http->postVariable('RedirectURIAfterRemove', false)); $http->setSessionVariable('RedirectIfCancel', $http->postVariable('RedirectIfCancel', false)); $object = eZContentObject::fetchByNodeID($contentNodeID); if ($object instanceof eZContentObject) { $section = eZSection::fetch($object->attribute('section_id')); } if (isset($section) && $section) { $navigationPartIdentifier = $section->attribute('navigation_part_identifier'); } else { $navigationPartIdentifier = null; } if ($navigationPartIdentifier and $navigationPartIdentifier == 'ezusernavigationpart') { $module->redirectTo($module->functionURI('removeuserobject') . '/'); } elseif ($navigationPartIdentifier and $navigationPartIdentifier == 'ezmedianavigationpart') { $module->redirectTo($module->functionURI('removemediaobject') . '/'); } else { $module->redirectTo($module->functionURI('removeobject') . '/'); } } else { $module->redirectToView('view', array($viewMode, $parentNodeID));
/** * Function for simplifying a content object or node * * @param mixed $obj * @param array $params * @return array */ public static function simplify($obj, $params = array()) { if (!$obj) { return array(); } else { if ($obj instanceof eZContentObject) { $node = $obj->attribute('main_node'); $contentObject = $obj; } else { if ($obj instanceof eZContentObjectTreeNode || $obj instanceof eZFindResultNode) { $node = $obj; $contentObject = $obj->attribute('object'); } else { if (isset($params['fetchNodeFunction']) && method_exists($obj, $params['fetchNodeFunction'])) { // You can supply fetchNodeFunction parameter to be able to support other node related classes $node = call_user_func(array($obj, $params['fetchNodeFunction'])); if (!$node instanceof eZContentObjectTreeNode) { return ''; } $contentObject = $node->attribute('object'); } else { if (is_array($obj)) { return $obj; // Array is returned as is } else { return ''; // Other passed objects are not supported } } } } } $ini = eZINI::instance('site.ini'); $params = array_merge(array('dataMap' => array(), 'fetchPath' => false, 'fetchSection' => false, 'fetchChildrenCount' => false, 'dataMapType' => array(), 'loadImages' => false, 'imagePreGenerateSizes' => array('small')), $params); if (!isset($params['imageSizes'])) { $imageIni = eZINI::instance('image.ini'); $params['imageSizes'] = $imageIni->variable('AliasSettings', 'AliasList'); } if ($params['imageSizes'] === null || !isset($params['imageSizes'][0])) { $params['imageSizes'] = array(); } if (!isset($params['imageDataTypes'])) { $params['imageDataTypes'] = $ini->variable('ImageDataTypeSettings', 'AvailableImageDataTypes'); } $ret = array(); $attrtibuteArray = array(); $ret['name'] = htmlentities($contentObject->attribute('name'), ENT_QUOTES, "UTF-8"); $ret['contentobject_id'] = $ret['id'] = (int) $contentObject->attribute('id'); $ret['contentobject_remote_id'] = $contentObject->attribute('remote_id'); $ret['contentobject_state'] = implode(", ", $contentObject->attribute('state_identifier_array')); $ret['main_node_id'] = (int) $contentObject->attribute('main_node_id'); $ret['version'] = (int) $contentObject->attribute('current_version'); $ret['modified'] = $contentObject->attribute('modified'); $ret['published'] = $contentObject->attribute('published'); $ret['section_id'] = (int) $contentObject->attribute('section_id'); $ret['current_language'] = $contentObject->attribute('current_language'); $ret['owner_id'] = (int) $contentObject->attribute('owner_id'); $ret['class_id'] = (int) $contentObject->attribute('contentclass_id'); $ret['class_name'] = $contentObject->attribute('class_name'); $ret['path_identification_string'] = $node->attribute('path_identification_string'); $ret['translations'] = eZContentLanguage::decodeLanguageMask($contentObject->attribute('language_mask'), true); $ret['can_edit'] = $contentObject->attribute('can_edit'); if (isset($params['formatDate'])) { $ret['modified_date'] = self::formatLocaleDate($contentObject->attribute('modified'), $params['formatDate']); $ret['published_date'] = self::formatLocaleDate($contentObject->attribute('published'), $params['formatDate']); } if (isset($params['fetchCreator'])) { $creator = $contentObject->attribute('current')->attribute('creator'); if ($creator instanceof eZContentObject) { $ret['creator'] = array('id' => $creator->attribute('id'), 'name' => $creator->attribute('name')); } else { $ret['creator'] = array('id' => $contentObject->attribute('current')->attribute('creator_id'), 'name' => null); // user has been deleted } } if (isset($params['fetchClassIcon'])) { $operator = new eZWordToImageOperator(); $tpl = eZTemplate::instance(); $operatorValue = $contentObject->attribute('class_identifier'); $operatorParameters = array(array(array(1, 'small'))); $namedParameters = array(); $operatorName = 'class_icon'; $operator->modify($tpl, $operatorName, $operatorParameters, '', '', $operatorValue, $namedParameters, array()); $ret['class_icon'] = $operatorValue; } if (isset($params['fetchThumbPreview'])) { $thumbUrl = ''; $thumbWidth = 0; $thumbHeight = 0; $thumbDataType = isset($params['thumbDataType']) ? $params['thumbDataType'] : 'ezimage'; $thumbImageSize = isset($params['thumbImageSize']) ? $params['thumbImageSize'] : 'small'; foreach ($contentObject->attribute('data_map') as $key => $atr) { if ($atr->attribute('data_type_string') == $thumbDataType && $atr->attribute('has_content')) { $imageContent = $atr->attribute('content'); if ($imageContent->hasAttribute($thumbImageSize)) { $imageAlias = $imageContent->attribute($thumbImageSize); } else { eZDebug::writeError("Image alias does not exist: '{$thumbImageSize}', missing from image.ini?", __METHOD__); } $thumbUrl = isset($imageAlias['full_path']) ? $imageAlias['full_path'] : ''; $thumbWidth = isset($imageAlias['width']) ? (int) $imageAlias['width'] : 0; $thumbHeight = isset($imageAlias['height']) ? (int) $imageAlias['height'] : 0; if ($thumbUrl !== '') { eZURI::transformURI($thumbUrl, true); } break; } } $ret['thumbnail_url'] = $thumbUrl; $ret['thumbnail_width'] = $thumbWidth; $ret['thumbnail_height'] = $thumbHeight; } if ($params['fetchSection']) { $section = eZSection::fetch($ret['section_id']); if ($section instanceof eZSection) { $ret['section'] = array('id' => $section->attribute('id'), 'name' => $section->attribute('name'), 'navigation_part_identifier' => $section->attribute('navigation_part_identifier'), 'locale' => $section->attribute('locale')); } else { $ret['section'] = null; } } if ($node) { // optimization for eZ Publish 4.1 (avoid fetching class) if ($node->hasAttribute('is_container')) { $ret['class_identifier'] = $node->attribute('class_identifier'); $ret['is_container'] = (int) $node->attribute('is_container'); } else { $class = $contentObject->attribute('content_class'); $ret['class_identifier'] = $class->attribute('identifier'); $ret['is_container'] = (int) $class->attribute('is_container'); } $ret['node_id'] = (int) $node->attribute('node_id'); $ret['parent_node_id'] = (int) $node->attribute('parent_node_id'); $ret['node_remote_id'] = $node->attribute('remote_id'); $ret['url_alias'] = $node->attribute('url_alias'); $ret['url'] = $node->url(); // force system url on empty urls (root node) if ($ret['url'] === '') { $ret['url'] = 'content/view/full/' . $node->attribute('node_id'); } eZURI::transformURI($ret['url']); $ret['depth'] = (int) $node->attribute('depth'); $ret['priority'] = (int) $node->attribute('priority'); $ret['hidden_status_string'] = $node->attribute('hidden_status_string'); if ($params['fetchPath']) { $ret['path'] = array(); foreach ($node->attribute('path') as $n) { $ret['path'][] = self::simplify($n); } } else { $ret['path'] = false; } if ($params['fetchChildrenCount']) { $ret['children_count'] = $ret['is_container'] ? (int) $node->attribute('children_count') : 0; } else { $ret['children_count'] = false; } } else { $class = $contentObject->attribute('content_class'); $ret['class_identifier'] = $class->attribute('identifier'); $ret['is_container'] = (int) $class->attribute('is_container'); } $ret['image_attributes'] = array(); if (is_array($params['dataMap']) && is_array($params['dataMapType'])) { $dataMap = $contentObject->attribute('data_map'); $datatypeBlacklist = array_fill_keys($ini->variable('ContentSettings', 'DatatypeBlackListForExternal'), true); foreach ($dataMap as $key => $atr) { $dataTypeString = $atr->attribute('data_type_string'); //if ( in_array( $dataTypeString, $params['imageDataTypes'], true) !== false ) if (!in_array('all', $params['dataMap'], true) && !in_array($key, $params['dataMap'], true) && !in_array($dataTypeString, $params['dataMapType'], true) && !($params['loadImages'] && in_array($dataTypeString, $params['imageDataTypes'], true))) { continue; } $attrtibuteArray[$key]['id'] = $atr->attribute('id'); $attrtibuteArray[$key]['type'] = $dataTypeString; $attrtibuteArray[$key]['identifier'] = $key; if (isset($datatypeBlacklist[$dataTypeString])) { $attrtibuteArray[$key]['content'] = null; } else { $attrtibuteArray[$key]['content'] = $atr->toString(); } // images if (in_array($dataTypeString, $params['imageDataTypes'], true) && $atr->hasContent()) { $content = $atr->attribute('content'); $imageArray = array(); if ($content != null) { foreach ($params['imageSizes'] as $size) { $imageArray[$size] = false; if (in_array($size, $params['imagePreGenerateSizes'], true)) { if ($content->hasAttribute($size)) { $imageArray[$size] = $content->attribute($size); } else { eZDebug::writeError("Image alias does not exist: '{$size}', missing from image.ini?", __METHOD__); } } } $ret['image_attributes'][] = $key; } if (!isset($imageArray['original'])) { $imageArray['original'] = $content->attribute('original'); } array_walk_recursive($imageArray, function (&$element, $key) { // json_encode/xmlEncode need UTF8 encoded strings // (exif) metadata might not be for instance // see https://jira.ez.no/browse/EZP-19929 if (!mb_check_encoding($element, 'UTF-8')) { $element = mb_convert_encoding((string) $element, 'UTF-8'); } }); $attrtibuteArray[$key]['content'] = $imageArray; } } } $ret['data_map'] = $attrtibuteArray; return $ret; }
/** * Generate result data for a node view * * @param eZTemplate $tpl * @param eZContentObjectTreeNode $node * @param eZContentObject $object * @param bool|string $languageCode * @param string $viewMode * @param int $offset * @param array $viewParameters * @param bool|array $collectionAttributes * @param bool $validation * @return array Result array for view */ static function generateNodeViewData(eZTemplate $tpl, eZContentObjectTreeNode $node, eZContentObject $object, $languageCode, $viewMode, $offset, array $viewParameters = array('offset' => 0, 'year' => false, 'month' => false, 'day' => false), $collectionAttributes = false, $validation = false) { $section = eZSection::fetch($object->attribute('section_id')); if ($section) { $navigationPartIdentifier = $section->attribute('navigation_part_identifier'); $sectionIdentifier = $section->attribute('identifier'); } else { $navigationPartIdentifier = null; $sectionIdentifier = null; } $keyArray = array(array('object', $object->attribute('id')), array('node', $node->attribute('node_id')), array('parent_node', $node->attribute('parent_node_id')), array('class', $object->attribute('contentclass_id')), array('class_identifier', $node->attribute('class_identifier')), array('view_offset', $offset), array('viewmode', $viewMode), array('remote_id', $object->attribute('remote_id')), array('node_remote_id', $node->attribute('remote_id')), array('navigation_part_identifier', $navigationPartIdentifier), array('depth', $node->attribute('depth')), array('url_alias', $node->attribute('url_alias')), array('class_group', $object->attribute('match_ingroup_id_list')), array('state', $object->attribute('state_id_array')), array('state_identifier', $object->attribute('state_identifier_array')), array('section', $object->attribute('section_id')), array('section_identifier', $sectionIdentifier)); $parentClassID = false; $parentClassIdentifier = false; $parentNodeRemoteID = false; $parentObjectRemoteID = false; $parentNode = $node->attribute('parent'); if (is_object($parentNode)) { $parentNodeRemoteID = $parentNode->attribute('remote_id'); $keyArray[] = array('parent_node_remote_id', $parentNodeRemoteID); $parentObject = $parentNode->attribute('object'); if (is_object($parentObject)) { $parentObjectRemoteID = $parentObject->attribute('remote_id'); $keyArray[] = array('parent_object_remote_id', $parentObjectRemoteID); $parentClass = $parentObject->contentClass(); if (is_object($parentClass)) { $parentClassID = $parentClass->attribute('id'); $parentClassIdentifier = $parentClass->attribute('identifier'); $keyArray[] = array('parent_class', $parentClassID); $keyArray[] = array('parent_class_identifier', $parentClassIdentifier); } } } $res = eZTemplateDesignResource::instance(); $res->setKeys($keyArray); if ($languageCode) { $oldLanguageCode = $node->currentLanguage(); $node->setCurrentLanguage($languageCode); } $tpl->setVariable('node', $node); $tpl->setVariable('viewmode', $viewMode); $tpl->setVariable('language_code', $languageCode); if (isset($viewParameters['_custom'])) { foreach ($viewParameters['_custom'] as $customVarName => $customValue) { $tpl->setVariable($customVarName, $customValue); } unset($viewParameters['_custom']); } $tpl->setVariable('view_parameters', $viewParameters); $tpl->setVariable('collection_attributes', $collectionAttributes); $tpl->setVariable('validation', $validation); $tpl->setVariable('persistent_variable', false); $parents = $node->attribute('path'); $path = array(); $titlePath = array(); foreach ($parents as $parent) { $path[] = array('text' => $parent->attribute('name'), 'url' => '/content/view/full/' . $parent->attribute('node_id'), 'url_alias' => $parent->attribute('url_alias'), 'node_id' => $parent->attribute('node_id')); } $titlePath = $path; $path[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false, 'node_id' => $node->attribute('node_id')); $titlePath[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false); $tpl->setVariable('node_path', $path); $event = ezpEvent::getInstance(); $event->notify('content/pre_rendering', array($node, $tpl, $viewMode)); $Result = array(); $Result['content'] = $tpl->fetch('design:node/view/' . $viewMode . '.tpl'); $Result['view_parameters'] = $viewParameters; $Result['path'] = $path; $Result['title_path'] = $titlePath; $Result['section_id'] = $object->attribute('section_id'); $Result['node_id'] = $node->attribute('node_id'); $Result['navigation_part'] = $navigationPartIdentifier; $contentInfoArray = array(); $contentInfoArray['object_id'] = $object->attribute('id'); $contentInfoArray['node_id'] = $node->attribute('node_id'); $contentInfoArray['parent_node_id'] = $node->attribute('parent_node_id'); $contentInfoArray['class_id'] = $object->attribute('contentclass_id'); $contentInfoArray['class_identifier'] = $node->attribute('class_identifier'); $contentInfoArray['remote_id'] = $object->attribute('remote_id'); $contentInfoArray['node_remote_id'] = $node->attribute('remote_id'); $contentInfoArray['offset'] = $offset; $contentInfoArray['viewmode'] = $viewMode; $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier; $contentInfoArray['node_depth'] = $node->attribute('depth'); $contentInfoArray['url_alias'] = $node->attribute('url_alias'); $contentInfoArray['current_language'] = $object->attribute('current_language'); $contentInfoArray['language_mask'] = $object->attribute('language_mask'); $contentInfoArray['main_node_id'] = $node->attribute('main_node_id'); $contentInfoArray['main_node_url_alias'] = false; // Add url alias for main node if it is not current node and user has access to it if (!$node->isMain()) { $mainNode = $object->mainNode(); if ($mainNode->canRead()) { $contentInfoArray['main_node_url_alias'] = $mainNode->attribute('url_alias'); } } $contentInfoArray['persistent_variable'] = false; if ($tpl->variable('persistent_variable') !== false) { $contentInfoArray['persistent_variable'] = $tpl->variable('persistent_variable'); $keyArray[] = array('persistent_variable', $contentInfoArray['persistent_variable']); $res->setKeys($keyArray); } $contentInfoArray['class_group'] = $object->attribute('match_ingroup_id_list'); $contentInfoArray['state'] = $object->attribute('state_id_array'); $contentInfoArray['state_identifier'] = $object->attribute('state_identifier_array'); $contentInfoArray['parent_class_id'] = $parentClassID; $contentInfoArray['parent_class_identifier'] = $parentClassIdentifier; $contentInfoArray['parent_node_remote_id'] = $parentNodeRemoteID; $contentInfoArray['parent_object_remote_id'] = $parentObjectRemoteID; $Result['content_info'] = $contentInfoArray; // Store which templates were used to make this cache. $Result['template_list'] = $tpl->templateFetchList(); // Check if time to live is set in template if ($tpl->hasVariable('cache_ttl')) { $cacheTTL = $tpl->variable('cache_ttl'); } if (!isset($cacheTTL)) { $cacheTTL = -1; } $Result['cache_ttl'] = $cacheTTL; // if cache_ttl is set to 0 from the template, we need to add a no-cache advice // to the node's data. That way, the retrieve callback on the next calls // will be able to determine earlier that no cache generation should be started // for this node if ($cacheTTL == 0) { $Result['no_cache'] = true; } if ($languageCode) { $node->setCurrentLanguage($oldLanguageCode); } return $Result; }
static function assignSectionToSubTree($nodeID, $sectionID, $oldSectionID = false) { $db = eZDB::instance(); $node = eZContentObjectTreeNode::fetch($nodeID); $nodePath = $node->attribute('path_string'); $sectionID = (int) $sectionID; $pathString = " path_string like '{$nodePath}%' AND "; // fetch the object id's which needs to be updated $objectIDArray = $db->arrayQuery("SELECT\n ezcontentobject.id\n FROM\n ezcontentobject_tree, ezcontentobject\n WHERE\n {$pathString}\n ezcontentobject_tree.contentobject_id=ezcontentobject.id AND\n ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id"); if (count($objectIDArray) == 0) { return; } // Who assigns which section at which node should be logged. $section = eZSection::fetch($sectionID); $object = $node->object(); eZAudit::writeAudit('section-assign', array('Section ID' => $sectionID, 'Section name' => $section->attribute('name'), 'Node ID' => $nodeID, 'Content object ID' => $object->attribute('id'), 'Content object name' => $object->attribute('name'), 'Comment' => 'Assigned a section to the current node and all child objects: eZContentObjectTreeNode::assignSectionToSubTree()')); $objectSimpleIDArray = array(); foreach ($objectIDArray as $objectID) { $objectSimpleIDArray[] = $objectID['id']; } $filterPart = ''; if ($oldSectionID !== false) { $oldSectionID = (int) $oldSectionID; $filterPart = " section_id = '{$oldSectionID}' and "; } $db->begin(); foreach (array_chunk($objectSimpleIDArray, 100) as $pagedObjectIDs) { $db->query("UPDATE ezcontentobject SET section_id='{$sectionID}' WHERE {$filterPart} " . $db->generateSQLINStatement($pagedObjectIDs, 'id', false, true, 'int')); eZSearch::updateObjectsSection($pagedObjectIDs, $sectionID); } $db->commit(); // clear caches for updated objects eZContentObject::clearCache($objectSimpleIDArray); }
/** * Returns object's section identifier * * @return string|bool */ public function sectionIdentifier() { $section = eZSection::fetch( $this->attribute( 'section_id' ) ); if( $section instanceof eZSection ) { return $section->attribute( 'identifier' ); } return false; }
/** * Serialize the eZContentObject to be used to build the result in * JavaScript * * @param eZContentObject $object * @return array */ public function serializeObject(eZContentObject $contentObject) { $section = eZSection::fetch($contentObject->attribute('section_id')); return array('object_info' => array('id' => $contentObject->attribute('id'), 'name' => $contentObject->attribute('name'), 'class_name' => $contentObject->attribute('class_name'), 'section_name' => $section->attribute('name'), 'published' => ezpI18n::tr('design/standard/content/datatype', 'Yes'))); }
/** * Create Object element. * * @param DOMDocument Owner DOMDocument * @param eZContentObject eZContentObject object. * * @return DOMElement Object DOMDocument, example: * * <Object ID="153" mainNodeID="123" initialLanguage="eng-GB" published="123213412" modified="1251231542"> * <Class ID="12" primaryLanguage="eng-GB"> * <NameList> * <Name locale="eng-GB">eZ Publish rocks</Name> * </NameList> * </Class> * <NameList> * <Name locale="eng-GB">eZ Publish rocks</Name> * <Name locale="nor-NO">eZ Publish rokker</Name> * </NameList> * <Owner objectID="135" primaryLanguage="nor-NO"> * <NameList> * <Name locale="nor-NO">Balle Klorin</Name> * </NameList> * </Owner> * <Section ID="2" name="News" /> * </Object> */ protected function createObjectDOMElement(DOMDocument $domDocument, eZContentObject $object) { $objectElement = $domDocument->createElement('Object'); // Set attributs. $objectElement->setAttribute('mainNodeID', $object->attribute('main_node_id')); $objectElement->setAttribute('initialLanguage', $object->attribute('initial_language_code')); $objectElement->setAttribute('published', $object->attribute('published')); $objectElement->setAttribute('modified', $object->attribute('modified')); // Add Class element. $objectElement->appendChild($this->createClassDOMElement($domDocument, $object->attribute('content_class'))); // Add language list. $objectElement->appendChild($this->createNameListDOMElementFromContentObject($domDocument, $object)); // Add owner element. $objectElement->appendChild($this->createOwnerDOMElement($domDocument, $object->attribute('owner'))); // Add Section element. $objectElement->appendChild($this->createSectionDOMElement($domDocument, eZSection::fetch($object->attribute('section_id')))); return $objectElement; }
static function unserialize( $package, $domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' ) { if ( $domNode->localName != 'object' ) { $retValue = false; return $retValue; } $initialLanguage = eZContentObject::mapLanguage( $domNode->getAttribute( 'initial_language' ), $options ); if( $initialLanguage === 'skip' ) { $retValue = true; return $retValue; } $sectionID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'section_id' ); if ( $ownerID === false ) { $ownerID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'owner_id' ); } $remoteID = $domNode->getAttribute( 'remote_id' ); $name = $domNode->getAttribute( 'name' ); $classRemoteID = $domNode->getAttribute( 'class_remote_id' ); $classIdentifier = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'class_identifier' ); $alwaysAvailable = ( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'always_available' ) == '1' ); $contentClass = eZContentClass::fetchByRemoteID( $classRemoteID ); if ( !$contentClass ) { $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier ); } if ( !$contentClass ) { $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_NO_CLASS, 'element_id' => $remoteID, 'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." ); $retValue = false; return $retValue; } $versionListNode = $domNode->getElementsByTagName( 'version-list' )->item( 0 ); $importedLanguages = array(); foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode ) { foreach ( $versionDOMNode->getElementsByTagName( 'object-translation' ) as $versionDOMNodeChild ) { $importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->getAttribute( 'language' ), $options ); $language = eZContentLanguage::fetchByLocale( $importedLanguage ); // Check if the language is allowed in this setup. if ( $language ) { $hasTranslation = true; } else { if ( $importedLanguage == 'skip' ) continue; // if there is no needed translation in system then add it $locale = eZLocale::instance( $importedLanguage ); $translationName = $locale->internationalLanguageName(); $translationLocale = $locale->localeCode(); if ( $locale->isValid() ) { eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() ); $hasTranslation = true; } else $hasTranslation = false; } if ( $hasTranslation ) { $importedLanguages[] = $importedLanguage; $importedLanguages = array_unique( $importedLanguages ); } } } // If object exists we return a error. // Minimum install element is an object now. $contentObject = eZContentObject::fetchByRemoteID( $remoteID ); // Figure out initial language if ( !$initialLanguage || !in_array( $initialLanguage, $importedLanguages ) ) { $initialLanguage = false; foreach ( eZContentLanguage::prioritizedLanguages() as $language ) { if ( in_array( $language->attribute( 'locale' ), $importedLanguages ) ) { $initialLanguage = $language->attribute( 'locale' ); break; } } } if ( !$contentObject ) { $firstVersion = true; $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); } else { $firstVersion = false; $description = "Object '$name' already exists."; $choosenAction = eZPackageHandler::errorChoosenAction( self::PACKAGE_ERROR_EXISTS, $options, $description, $handlerType, false ); switch( $choosenAction ) { case eZPackage::NON_INTERACTIVE: case self::PACKAGE_UPDATE: { // Keep existing contentobject. } break; case self::PACKAGE_REPLACE: { eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) ); unset( $contentObject ); $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); $firstVersion = true; } break; case self::PACKAGE_SKIP: { $retValue = true; return $retValue; } break; case self::PACKAGE_NEW: { $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) ); $contentObject->store(); unset( $contentObject ); $contentObject = $contentClass->instantiate( $ownerID, $sectionID ); $firstVersion = true; } break; default: { $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_EXISTS, 'element_id' => $remoteID, 'description' => $description, 'actions' => array( self::PACKAGE_REPLACE => ezpI18n::tr( 'kernel/classes', 'Replace existing object' ), self::PACKAGE_SKIP => ezpI18n::tr( 'kernel/classes', 'Skip object' ), self::PACKAGE_NEW => ezpI18n::tr( 'kernel/classes', 'Keep existing and create a new one' ), self::PACKAGE_UPDATE => ezpI18n::tr( 'kernel/classes', 'Update existing object' ) ) ); $retValue = false; return $retValue; } break; } } $db = eZDB::instance(); $db->begin(); if ( $alwaysAvailable ) { // Make sure always available bit is set. $contentObject->setAttribute( 'language_mask', (int)$contentObject->attribute( 'language_mask' ) | 1 ); } $contentObject->setAttribute( 'section_id', $sectionID ); $contentObject->store(); $activeVersion = false; $lastVersion = false; $versionListActiveVersion = $versionListNode->getAttribute( 'active_version' ); $contentObject->setAttribute( 'remote_id', $remoteID ); $contentObject->setAttribute( 'contentclass_id', $contentClass->attribute( 'id' ) ); $contentObject->store(); $sectionObject = eZSection::fetch( $sectionID ); if ( $sectionObject instanceof eZSection ) { $updateWithParentSection = false; } else { $updateWithParentSection = true; } $options['language_array'] = $importedLanguages; $versionList = array(); foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode ) { unset( $nodeList ); $nodeList = array(); $contentObjectVersion = eZContentObjectVersion::unserialize( $versionDOMNode, $contentObject, $ownerID, $sectionID, $versionListActiveVersion, $firstVersion, $nodeList, $options, $package ); if ( !$contentObjectVersion ) { $db->commit(); $retValue = false; return $retValue; } $versionStatus = $versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'status' ); $versionList[$versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'version' )] = array( 'node_list' => $nodeList, 'status' => $versionStatus ); unset( $versionStatus ); $firstVersion = false; $lastVersion = $contentObjectVersion->attribute( 'version' ); if ( $versionDOMNode->getAttribute( 'version' ) == $versionListActiveVersion ) { $activeVersion = $contentObjectVersion->attribute( 'version' ); } eZNodeAssignment::setNewMainAssignment( $contentObject->attribute( 'id' ), $lastVersion ); eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => $lastVersion ) ); $mainNodeInfo = null; foreach ( $nodeList as $nodeInfo ) { if ( $nodeInfo['is_main'] ) { $mainNodeInfo =& $nodeInfo; break; } } if ( $mainNodeInfo ) { $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $mainNodeInfo['parent_remote_id'], false ); if ( $existingMainNode ) { eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'], $mainNodeInfo['contentobject_id'], $mainNodeInfo['contentobject_version'], $mainNodeInfo['parent_node'], $updateWithParentSection ); } } unset( $mainNodeInfo ); // Refresh $contentObject from DB. $contentObject = eZContentObject::fetch( $contentObject->attribute( 'id' ) ); } if ( !$activeVersion ) { $activeVersion = $lastVersion; } /* $contentObject->setAttribute( 'current_version', $activeVersion ); */ $contentObject->setAttribute( 'name', $name ); if ( isset( $options['use_dates_from_package'] ) && $options['use_dates_from_package'] ) { $contentObject->setAttribute( 'published', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'published' ) ) ); $contentObject->setAttribute( 'modified', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ) ); } $contentObject->store(); $versions = $contentObject->versions(); $objectName = $contentObject->name(); $objectID = $contentObject->attribute( 'id' ); foreach ( $versions as $version ) { $versionNum = $version->attribute( 'version' ); $oldVersionStatus = $version->attribute( 'status' ); $newVersionStatus = isset( $versionList[$versionNum] ) ? $versionList[$versionNum]['status'] : null; // set the correct status for non-published versions if ( isset( $newVersionStatus ) && $oldVersionStatus != $newVersionStatus && $newVersionStatus != eZContentObjectVersion::STATUS_PUBLISHED ) { $version->setAttribute( 'status', $newVersionStatus ); $version->store( array( 'status' ) ); } // when translation does not have object name set then we copy object name from the current object version $translations = $version->translations( false ); if ( !$translations ) continue; foreach ( $translations as $translation ) { if ( ! $contentObject->name( $versionNum, $translation ) ) { eZDebug::writeNotice( "Setting name '$objectName' for version ($versionNum) of the content object ($objectID) in language($translation)" ); $contentObject->setName( $objectName, $versionNum, $translation ); } } } foreach ( $versionList[$versionListActiveVersion]['node_list'] as $nodeInfo ) { unset( $parentNode ); $parentNode = eZContentObjectTreeNode::fetchNode( $contentObject->attribute( 'id' ), $nodeInfo['parent_node'] ); if ( is_object( $parentNode ) ) { $parentNode->setAttribute( 'priority', $nodeInfo['priority'] ); $parentNode->store( array( 'priority' ) ); } } $db->commit(); return $contentObject; }
function checkRelationActions($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage) { $http = eZHTTPTool::instance(); if ($module->isCurrentAction('BrowseForObjects')) { $objectID = $object->attribute('id'); $assignedNodes = $object->attribute('assigned_nodes'); $assignedNodesIDs = array(); foreach ($assignedNodes as $node) { $assignedNodesIDs = $node->attribute('node_id'); } unset($assignedNodes); eZContentBrowse::browse(array('action_name' => 'AddRelatedObject', 'description_template' => 'design:content/browse_related.tpl', 'content' => array('object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage), 'keys' => array('class' => $class->attribute('id'), 'class_id' => $class->attribute('identifier'), 'classgroup' => $class->attribute('ingroup_id_list'), 'section' => $object->attribute('section_id')), 'ignore_nodes_select' => $assignedNodesIDs, 'from_page' => $module->redirectionURI('content', 'edit', array($objectID, $editVersion, $editLanguage, $fromLanguage))), $module); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ($module->isCurrentAction('UploadFileRelation')) { $objectID = $object->attribute('id'); $section = eZSection::fetch($object->attribute('section_id')); $navigationPart = false; if ($section) { $navigationPart = $section->attribute('navigation_part_identifier'); } $location = false; if ($module->hasActionParameter('UploadRelationLocation')) { $location = $module->actionParameter('UploadRelationLocation'); } // We only do direct uploading if we have the uploaded HTTP file // if not we need to go to the content/upload page. if (eZHTTPFile::canFetch('UploadRelationFile')) { $upload = new eZContentUpload(); if ($upload->handleUpload($result, 'UploadRelationFile', $location, false)) { $relatedObjectID = $result['contentobject_id']; if ($relatedObjectID) { $db = eZDB::instance(); $db->begin(); $object->addContentObjectRelation($relatedObjectID, $editVersion); $db->commit(); } } } else { eZContentUpload::upload(array('action_name' => 'RelatedObjectUpload', 'description_template' => 'design:content/upload_related.tpl', 'navigation_part_identifier' => $navigationPart, 'content' => array('object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage), 'keys' => array('class' => $class->attribute('id'), 'class_id' => $class->attribute('identifier'), 'classgroup' => $class->attribute('ingroup_id_list'), 'section' => $object->attribute('section_id')), 'result_action_name' => 'UploadedFileRelation', 'ui_context' => 'edit', 'result_module' => array('content', 'edit', array($objectID, $editVersion, $editLanguage, $fromLanguage))), $module); return eZModule::HOOK_STATUS_CANCEL_RUN; } } if ($module->isCurrentAction('DeleteRelation')) { $objectID = $object->attribute('id'); if ($http->hasPostVariable('DeleteRelationIDArray')) { $relationObjectIDs = $http->postVariable('DeleteRelationIDArray'); } else { $relationObjectIDs = array(); } $db = eZDB::instance(); $db->begin(); foreach ($relationObjectIDs as $relationObjectID) { $object->removeContentObjectRelation($relationObjectID, $editVersion); } $db->commit(); } if ($module->isCurrentAction('NewObject')) { if ($http->hasPostVariable('ClassID')) { if ($http->hasPostVariable('SectionID')) { $sectionID = $http->postVariable('SectionID'); } else { $sectionID = 0; /* Will be changed later */ } $contentClassID = $http->postVariable('ClassID'); $class = eZContentClass::fetch($contentClassID); $db = eZDB::instance(); $db->begin(); $relatedContentObject = $class->instantiate(false, $sectionID); $db->commit(); $newObjectID = $relatedContentObject->attribute('id'); $relatedContentVersion = $relatedContentObject->attribute('current'); if ($relatedContentObject->attribute('can_edit')) { $db = eZDB::instance(); $db->begin(); $assignmentHandler = new eZContentObjectAssignmentHandler($relatedContentObject, $relatedContentVersion); $sectionID = (int) $assignmentHandler->setupAssignments(array('group-name' => 'RelationAssignmentSettings', 'default-variable-name' => 'DefaultAssignment', 'specific-variable-name' => 'ClassSpecificAssignment', 'section-id-wanted' => true, 'fallback-node-id' => $object->attribute('main_node_id'))); $http->setSessionVariable('ParentObject', array($object->attribute('id'), $editVersion, $editLanguage)); $http->setSessionVariable('NewObjectID', $newObjectID); /* Change section ID to the same one as the main node placement */ $db->query("UPDATE ezcontentobject SET section_id = {$sectionID} WHERE id = {$newObjectID}"); $db->commit(); $module->redirectToView('edit', array($relatedContentObject->attribute('id'), $relatedContentObject->attribute('current_version'), false)); } else { $db = eZDB::instance(); $db->begin(); $relatedContentObject->purge(); $db->commit(); } return; } } }