public function setUp() { parent::setUp(); eZINI::instance('ezfind.ini')->loadCache(true); eZINI::instance('solr.ini')->loadCache(true); ezpINIHelper::setINISetting('site.ini', 'SearchSettings', 'AllowEmptySearch', 'enabled'); ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', array('eng-GB')); $this->solrSearch = new eZSolr(); $this->testObj = eZContentObject::fetchByNodeID(2); $this->solrSearch->addObject($this->testObj); $this->fetchParams = array('SearchOffset' => 0, 'SearchLimit' => 10, 'Facet' => null, 'SortBy' => null, 'Filter' => null, 'SearchContentClassID' => null, 'SearchSectionID' => null, 'SearchSubTreeArray' => null, 'AsObjects' => null, 'SpellCheck' => null, 'IgnoreVisibility' => null, 'Limitation' => null, 'BoostFunctions' => null, 'QueryHandler' => 'ezpublish', 'EnableElevation' => null, 'ForceElevation' => null, 'SearchDate' => null, 'DistributedSearch' => null, 'FieldsToReturn' => null); }
<?php $Module = $Params['Module']; $tpl = eZTemplate::factory(); $newsletter_ini = eZINI::instance('jaj_newsletter.ini'); $newsletter_root_node_id = $newsletter_ini->variable('NewsletterSettings', 'RootFolderNodeId'); $node = eZContentObject::fetchByNodeID($newsletter_root_node_id); if (!$node || !$node->canRead()) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } switch (eZPreferences::value('admin_jaj_newsletter_newsletters_limit')) { case '25': $limit = 25; break; case '50': $limit = 50; break; default: $limit = 10; break; } $newsletter_content_class = eZContentClass::fetchByIdentifier('jaj_newsletter'); if ($newsletter_content_class) { $tpl->setVariable('newsletter_content_class_id', $newsletter_content_class->ID); } $viewParameters = array('offset' => $Params['Offset']); $tpl->setVariable('node', $node); $tpl->setVariable('set_limit', $limit); $tpl->setVariable('view_parameters', $viewParameters); $Result = array('content' => $tpl->fetch('design:jaj_newsletter/newsletters/index.tpl'), 'path' => array(array('url' => 'jaj_newsletter/index', 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletter')), array('url' => false, 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletters'))));
/** * Extracts ids of embedded/linked objects in an eZXML DOMNodeList * @param DOMNodeList $domNodeList * @return array */ private function getRelatedObjectList(DOMNodeList $domNodeList) { $embeddedObjectIdArray = array(); foreach ($domNodeList as $embed) { if ($embed->hasAttribute('object_id')) { $embeddedObjectIdArray[] = $embed->getAttribute('object_id'); } elseif ($embed->hasAttribute('node_id')) { if ($object = eZContentObject::fetchByNodeID($embed->getAttribute('node_id'))) { $embeddedObjectIdArray[] = $object->attribute('id'); } } } return $embeddedObjectIdArray; }
$rowsCount = 0; if (isset($countOfItems[0])) { $rowsCount = $countOfItems[0]['count']; } if ($rowsCount > 0) { // Select all elements having reverse relations. And ignore those items that don't relate to objects other than being removed. $rows = $db->arrayQuery("SELECT DISTINCT( tree.node_id )\n FROM ezcontentobject_tree tree, ezcontentobject obj,\n ezcontentobject_link link LEFT JOIN ezcontentobject_tree tree2\n ON link.from_contentobject_id = tree2.contentobject_id\n WHERE {$path_strings}\n and link.to_contentobject_id = tree.contentobject_id\n and obj.id = link.from_contentobject_id\n and obj.current_version = link.from_contentobject_version\n and not ( {$path_strings_where} )\n\n ", array('limit' => $pageLimit, 'offset' => $Offset)); } else { $rows = array(); } $childrenList = array(); // Contains children of Nodes from $deleteIDArray // Fetch number of reverse related objects for each of the items being removed. $reverselistCountChildrenArray = array(); foreach ($rows as $child) { $contentObject = eZContentObject::fetchByNodeID($child['node_id']); $contentObject_ID = $contentObject->attribute('id'); $reverseObjectCount = $contentObject->reverseRelatedObjectCount(false, false, 1); $reverselistCountChildrenArray[$contentObject_ID] = $reverseObjectCount; $childrenList[] = eZContentObjectTreeNode::fetch($child['node_id']); } $contentObjectName = $contentObjectTreeNode->attribute('name'); $viewParameters = array('offset' => $Offset); $tpl = eZTemplate::factory(); $tpl->setVariable('children_list', $childrenList); $tpl->setVariable('view_parameters', $viewParameters); $tpl->setVariable('children_count', $rowsCount); $tpl->setVariable('content_object_name', $contentObjectName); $tpl->setVariable('reverse_list_count_children_array', $reverselistCountChildrenArray); $tpl->setVariable('reverse_list_children_count', count($reverselistCountChildrenArray)); $tpl->setVariable('node_id', $NodeID);
/** * Unit test for {@link eZContentObject::fetchByNodeID()} * * @see http://issues.ez.no/17946 * @group issue17946 */ public function testFetchByNodeIDArrayAsRow() { $fetchedObjects = eZContentObject::fetchByNodeID(array(2), false); self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fetchedObjects, "eZContentObject::fetchByNodeID() must return an array of eZContentObject instances if an array of nodeIds is passed as param"); self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fetchedObjects[2], "eZContentObject::fetchByNodeID() must return an array indexed by nodeIds of eZContentObject array representation if an array of nodeIds is passed as param"); }
/** * Return the tags for a given node id or null if it fails * * @param integer $nodeID * @return */ static function fetchTagsByNodeID($iNodeID, $view_parameters = array()) { return is_numeric($iNodeID) ? MetatagFunctionCollection::fetchTagsByContentObject(eZContentObject::fetchByNodeID($iNodeID), $view_parameters) : null; }
$tpl->setVariable( 'elevatedObject', $elevatedObject ); $tpl->setVariable( 'elevateSearchQuery', '' ); } // back from browse else if ( $http->hasPostVariable( 'BrowseActionName' ) and ( $http->postVariable( 'BrowseActionName' ) == ( 'ezfind-elevate-browseforobject' ) or $http->postVariable( 'BrowseActionName' ) == ( 'ezfind-searchelevateconfigurations-browse' ) ) and $http->hasPostVariable( "SelectedNodeIDArray" ) ) { if ( !$http->hasPostVariable( 'BrowseCancelButton' ) ) { $selectedNodeID = $http->postVariable( "SelectedNodeIDArray" ); $selectedNodeID = $selectedNodeID[0]; $elevatedObject = eZContentObject::fetchByNodeID( $selectedNodeID ); // Browse was triggered to pick an object for elevation if ( $http->postVariable( 'BrowseActionName' ) == ( 'ezfind-elevate-browseforobject' ) ) { $tpl->setVariable( 'back_from_browse', true ); $tpl->setVariable( 'elevatedObject', $elevatedObject ); $tpl->setVariable( 'elevateSearchQuery', $http->postVariable( 'elevateSearchQuery' ) ); } else { // Browsing for an object, the elevate configuration of which we would like to inspect. $objectID = $elevatedObject->attribute( 'id' ); // Redirect the to detail page for the object's elevation configuration $module->redirectToView( 'elevation_detail', array( $objectID ) ); }
/** * Returns a node data for given object / node id * * Following parameters are supported: * ezjscnode::load::embed_id[::attribute[::load_image_size]] * * eg: ezjscnode::load::ezobject_46::image::large * eg: ezjscnode::load::eznode_44::summary *eg: ezjscnode::load::44::summary (44 is in this case node id) * * @since 1.2 * @param mixed $args * @throws InvalidArgumentException * @return array */ public static function load($args) { $embedObject = false; if (isset($args[0]) && $args[0]) { $embedType = 'eznode'; if (is_numeric($args[0])) { $embedId = $args[0]; } else { list($embedType, $embedId) = explode('_', $args[0]); } if ($embedType === 'eznode' || strcasecmp($embedType, 'eznode') === 0) { $embedObject = eZContentObject::fetchByNodeID($embedId); } else { $embedObject = eZContentObject::fetch($embedId); } } if (!$embedObject instanceof eZContentObject) { throw new InvalidArgumentException("Argument 1: '{$embedType}\\_{$embedId}' does not map to a valid content object"); } else { if (!$embedObject->canRead()) { throw new InvalidArgumentException("Argument 1: '{$embedType}\\_{$embedId}' is not available"); } } // Params for node to json encoder $params = array('loadImages' => true); $params['imagePreGenerateSizes'] = array('small', 'original'); // look for attribute parameter ( what attribute we should load ) if (isset($args[1]) && $args[1]) { $params['dataMap'] = array($args[1]); } // what image sizes we want returned with full data ( url++ ) if (isset($args[2]) && $args[2]) { $params['imagePreGenerateSizes'][] = $args[2]; } // Simplify and load data in accordance to $params return ezjscAjaxContent::simplify($embedObject, $params); }
/** * Update current empty paex fields with values get from paex object of * parent of current main node. * * @param bool $forceUpdate * @return true */ function updateFromParent($forceUpdate = false) { $mainNode = eZContentObjectTreeNode::findMainNode($this->attribute('contentobject_id'), true); if (!is_object($mainNode)) { eZDebug::writeDebug('mainNode not found', 'eZPaEx::updateFromParent'); } elseif ($mainNode->attribute('depth') > 1) { $parentMainNodeID = $mainNode->attribute('parent_node_id'); $parentContentObject = eZContentObject::fetchByNodeID($parentMainNodeID); $parentPaex = eZPaEx::getPaEx($parentContentObject->attribute('id')); if ($parentPaex instanceof eZPaEx) { $paexUpdated = false; if (!$this->hasRegexp() || $forceUpdate) { $this->setAttribute('passwordvalidationregexp', $parentPaex->attribute('passwordvalidationregexp')); $paexUpdated = true; } if (!$this->hasLifeTime() || $forceUpdate) { $this->setAttribute('passwordlifetime', $parentPaex->attribute('passwordlifetime')); $paexUpdated = true; } if (!$this->hasNotification() || $forceUpdate) { $this->setAttribute('expirationnotification', $parentPaex->attribute('expirationnotification')); $paexUpdated = true; } if ($paexUpdated) { eZDebug::writeDebug('Paex updated from parent', 'eZPaEx::updateFromParent'); $this->store(); } } } return true; }
function execute($process, $event) { $processParameters = $process->attribute('parameter_list'); $storeProcessParameters = false; $classID = false; $object = false; $sectionID = false; $languageID = 0; if (isset($processParameters['object_id'])) { $object = eZContentObject::fetch($processParameters['object_id']); } else { if (isset($processParameters['node_id'])) { $object = eZContentObject::fetchByNodeID($processParameters['node_id']); } } if ($object instanceof eZContentObject) { // Examine if the published version contains one of the languages we // match for. if (isset($processParameters['version'])) { $versionID = $processParameters['version']; $version = $object->version($versionID); if (is_object($version)) { $version_option = $event->attribute('version_option'); if ($version_option == eZMultiplexerType::VERSION_OPTION_FIRST_ONLY and $processParameters['version'] > 1 or $version_option == eZMultiplexerType::VERSION_OPTION_EXCEPT_FIRST and $processParameters['version'] == 1) { return eZWorkflowType::STATUS_ACCEPTED; } // If the language ID is part of the mask the result is non-zero. $languageID = (int) $version->attribute('initial_language_id'); } } $sectionID = $object->attribute('section_id'); $class = $object->attribute('content_class'); if ($class) { $classID = $class->attribute('id'); } } $userArray = explode(',', $event->attribute('data_text2')); $classArray = explode(',', $event->attribute('data_text5')); $languageMask = $event->attribute('data_int2'); if (!isset($processParameters['user_id'])) { $user = eZUser::currentUser(); $userID = $user->id(); $processParameters['user_id'] = $userID; $storeProcessParameters = true; } else { $userID = $processParameters['user_id']; $user = eZUser::fetch($userID); if (!$user instanceof eZUser) { $user = eZUser::currentUser(); $userID = $user->id(); $processParameters['user_id'] = $userID; $storeProcessParameters = true; } } $userGroups = $user->attribute('groups'); $inExcludeGroups = count(array_intersect($userGroups, $userArray)) != 0; if ($storeProcessParameters) { $process->setParameters($processParameters); $process->store(); } // All languages match by default $hasLanguageMatch = true; if ($languageMask != 0) { // Match ID with mask. $hasLanguageMatch = (bool) ($languageMask & $languageID); } if ($hasLanguageMatch && !$inExcludeGroups && (in_array(-1, $classArray) || in_array($classID, $classArray))) { $sectionArray = explode(',', $event->attribute('data_text1')); if (in_array($sectionID, $sectionArray) || in_array(-1, $sectionArray)) { $workflowToRun = $event->attribute('data_int1'); $childParameters = array_merge($processParameters, array('workflow_id' => $workflowToRun, 'user_id' => $userID, 'parent_process_id' => $process->attribute('id'))); $childProcessKey = eZWorkflowProcess::createKey($childParameters); $childProcessArray = eZWorkflowProcess::fetchListByKey($childProcessKey); $childProcess =& $childProcessArray[0]; if ($childProcess == null) { $childProcess = eZWorkflowProcess::create($childProcessKey, $childParameters); $childProcess->store(); } $workflow = eZWorkflow::fetch($childProcess->attribute("workflow_id")); $workflowEvent = null; if ($childProcess->attribute("event_id") != 0) { $workflowEvent = eZWorkflowEvent::fetch($childProcess->attribute("event_id")); } $childStatus = $childProcess->run($workflow, $workflowEvent, $eventLog); $childProcess->store(); if ($childStatus == eZWorkflow::STATUS_DEFERRED_TO_CRON) { $this->setActivationDate($childProcess->attribute('activation_date')); $childProcess->setAttribute("status", eZWorkflow::STATUS_WAITING_PARENT); $childProcess->store(); return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; } else { if ($childStatus == eZWorkflow::STATUS_FETCH_TEMPLATE or $childStatus == eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT) { $process->Template =& $childProcess->Template; return eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT; } else { if ($childStatus == eZWorkflow::STATUS_REDIRECT) { $process->RedirectUrl =& $childProcess->RedirectUrl; return eZWorkflowType::STATUS_REDIRECT_REPEAT; } else { if ($childStatus == eZWorkflow::STATUS_DONE) { $childProcess->removeThis(); return eZWorkflowType::STATUS_ACCEPTED; } else { if ($childStatus == eZWorkflow::STATUS_CANCELLED) { $childProcess->removeThis(); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } else { if ($childStatus == eZWorkflow::STATUS_FAILED) { $childProcess->removeThis(); return eZWorkflowType::STATUS_REJECTED; } } } } } } return $childProcess->attribute('event_status'); } } return eZWorkflowType::STATUS_ACCEPTED; }
function addNodeAssignment($content_object, $parent_node_id, $set_as_main_node = false) { $main_node_id = $content_object->attribute('main_node_id'); $insertedNode = $content_object->addLocation($parent_node_id, true); // Now set it as published and fix main_node_id $insertedNode->setAttribute('contentobject_is_published', 1); $parentContentObject = eZContentObject::fetchByNodeID($parent_node_id); if ($set_as_main_node) { $main_node_id = $insertedNode->attribute('node_id'); $insertedNode->updateMainNodeID($main_node_id, $content_object->attribute('id'), false, $parent_node_id); } $insertedNode->setAttribute('main_node_id', $main_node_id); $insertedNode->setAttribute('contentobject_version', $content_object->attribute('current_version')); // Make sure the path_identification_string is set correctly. $insertedNode->updateSubTreePath(); $insertedNode->sync(); return $insertedNode->attribute('node_id'); }
/** * Called when two nodes are swapped. * Simply re-index for now. * * @todo when Solr supports it: update fields only * * @param $nodeID * @param $selectedNodeID * @param $nodeIdList * @return void */ public function swapNode( $nodeID, $selectedNodeID, $nodeIdList = array() ) { $contentObject1 = eZContentObject::fetchByNodeID( $nodeID ); $contentObject2 = eZContentObject::fetchByNodeID( $selectedNodeID ); $this->addObject( $contentObject1 ); $this->addObject( $contentObject2 ); }
/** * Visualizza l'immagine contenuta nell'attirbuto header_image * della classe frotpage posizionata come RootNode */ $module = $Params['Module']; // Root Node ID $ini = eZINI::instance('content.ini'); $root_node_id = $ini->variable('NodeSettings', 'RootNode'); // Cluster $file_ini = eZINI::instance('file.ini'); $mount_point = $file_ini->variable('eZDFSClusteringSettings', 'MountPointPath'); // Default imagepath $imagepath = 'extension/pat_base/design/itbase/images/header-ittemplate.jpg'; // Immagine personalizzata $frontpage = eZContentObject::fetchByNodeID($root_node_id); if ($frontpage instanceof eZContentObject) { if (strcmp($frontpage->className(), 'Frontpage') == 0) { $dataMap =& $frontpage->attribute('data_map'); if (array_key_exists('header_image', $dataMap)) { $image =& $dataMap['header_image']->content(); $list =& $image->aliasList(); if (!empty($list['original']['url'])) { $imagepath = $mount_point . '/' . $list['original']['url']; } } } } header("Content-Type: image/jpeg"); echo file_get_contents($imagepath); eZExecution::cleanExit();
/** * @param string $path * @param MerckManualShowcase $app * @return bool|eZContentObjectTreeNode */ public static function findNodeFromPath( $path, &$app ) { /* We remove the publisher folder id at the beginning of the url as we already have it */ $path = preg_replace('#^/\d+/#', '/', $path ); $manualAppNode = eZContentObjectTreeNode::fetch( self::rootNodeId() ); $manualAppNodePathName = $manualAppNode->pathWithNames(); $tabNodePath = explode('/', substr($path, 1)); $remoteId = end($tabNodePath); if(preg_match('/^[a-f0-9]{32}$/', $remoteId)) { $nodeRemote = eZContentObjectTreeNode::fetchByRemoteID($remoteId); if($nodeRemote instanceof eZContentObjectTreeNode) { $app->fullContext = 'topic'; return $nodeRemote; } } $pathParts = explode('/', substr($path, 1)); if ( $pathParts[0] == 'table' ) { $app->fullContext = 'table'; return eZContentObjectTreeNode::fetch($pathParts[1]); } // Url with topic list($sectionName, $chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts; // Url without topic $matches = array(); if ( preg_match('/media-([a-z]+)/', $topicName, $matches) ) { list($sectionName, $chapterName, $mediaType, $mediaName, $other) = $pathParts; $topicName = null; } // Full section if ( $sectionName != null && is_null( $chapterName ) && is_null( $topicName ) ) { $app->fullContext = 'section'; $app->section = MerckManualFunctionCollection::fetchSection('url', $sectionName); return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId()); } if ( $sectionName == 'about-us' ) { list($chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts; } $path = $manualAppNodePathName; // Full of chapter if ( $chapterName ) { $app->fullContext = 'chapter'; $path .= '/' . $chapterName; } // Full of topic if ( $topicName ) { $app->fullContext = 'topic'; $path .= '/' . $topicName; } $nodeId = eZURLAliasML::fetchNodeIDByPath($path); if ( $nodeId ) { if ( $mediaName ) { $mediaType = str_replace('media-', '', $mediaType); // Get media node // Full of html table image // /topic_name/(media-image-file)/oscar2/filename if ( $mediaType == 'image-file' ) { $app->fullContext = $mediaType; $app->oscarFolder = $mediaName; $app->mediaName = $other; } // Full of inline audio, video, image elseif ( $mediaType ) { // Construct the remote_id of the media folder /* @type $dataMap eZContentObjectAttribute[] */ $contentObject = eZContentObject::fetchByNodeID($nodeId); $dataMap = $contentObject->dataMap(); $publisherAttrContent = $dataMap['publisher']->content(); if ( isset($publisherAttrContent['relation_list'][0]['contentobject_remote_id']) ) { // Get media folder $mediaFolderRemoteId = sprintf('%s_media_%s', $publisherAttrContent['relation_list'][0]['contentobject_remote_id'], $mediaType); $mediaFolder = eZContentObject::fetchByRemoteID($mediaFolderRemoteId); if ( $mediaFolder ) { // Get media $mediaFolderPathName = $mediaFolder->mainNode()->pathWithNames(); $nodeId = eZURLAliasML::fetchNodeIDByPath($mediaFolderPathName . '/' . $mediaName); $app->fullContext = $mediaType; } } } } } if ( $nodeId ) { // Full of chapter must not be accessible, show first topic if ( $app->fullContext == 'chapter' ) { $params = array( 'Depth' => 1, 'DepthOperator' => 'eq', 'SortBy' => array(array('priority', 'asc')), 'Limit' => 1 ); $children = eZContentObjectTreeNode::subTreeByNodeID($params, $nodeId); if ( isset($children[0]) && $children[0] instanceof eZContentObjectTreeNode ) { $node = $children[0]; $app->fullContext = 'topic'; } else $node = null; } else { $node = eZContentObjectTreeNode::fetch($nodeId); } return $node; } return false; }
static function updateMainNodeID($mainNodeID, $objectID, $version = false, $parentMainNodeID, $updateSection = true) { $mainNodeID = (int) $mainNodeID; $parentMainNodeID = (int) $parentMainNodeID; $objectID = (int) $objectID; $version = (int) $version; $db = eZDB::instance(); $db->begin(); $db->query("UPDATE ezcontentobject_tree SET main_node_id={$mainNodeID} WHERE contentobject_id={$objectID}"); if (!$version) { $rows = $db->arrayQuery("SELECT current_version FROM ezcontentobject WHERE id={$objectID}"); $version = $rows[0]['current_version']; } $db->query("UPDATE eznode_assignment SET is_main=1 WHERE contentobject_id={$objectID} AND contentobject_version={$version} AND parent_node={$parentMainNodeID}"); $db->query("UPDATE eznode_assignment SET is_main=0 WHERE contentobject_id={$objectID} AND contentobject_version={$version} AND parent_node!={$parentMainNodeID}"); $contentObject = eZContentObject::fetch($objectID); $parentContentObject = eZContentObject::fetchByNodeID($parentMainNodeID); if ($updateSection && $contentObject->attribute('section_id') != $parentContentObject->attribute('section_id')) { $newSectionID = $parentContentObject->attribute('section_id'); eZContentObjectTreeNode::assignSectionToSubTree($mainNodeID, $newSectionID); } $db->commit(); }
/** * Update search index when two nodes are swapped * * @param int $nodeID * @param int $selectedNodeID * @param array $nodeIdList */ public function swapNode($nodeID, $selectedNodeID, $nodeIdList = array()) { $contentObject1 = eZContentObject::fetchByNodeID($nodeID); $contentObject2 = eZContentObject::fetchByNodeID($selectedNodeID); eZContentOperationCollection::registerSearchObject($contentObject1->attribute('id')); eZContentOperationCollection::registerSearchObject($contentObject2->attribute('id')); }
eZUserOperationCollection::activation($userID, $hash, true); } // execute operation to publish the user object $publishResult = eZOperationHandler::execute('user', 'register', array('user_id' => $userID)); if ($publishResult['status'] === eZModuleOperationInfo::STATUS_HALTED) { $isPending = true; } else { // Log in user $user = eZUser::fetch($userID); if ($user === null) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } $user->loginCurrent(); } } elseif ($mainNodeID) { $userContentObject = eZContentObject::fetchByNodeID($mainNodeID); if ($userContentObject instanceof eZContentObject) { $userSetting = eZUserSetting::fetch($userContentObject->attribute('id')); if ($userSetting !== null && $userSetting->attribute('is_enabled')) { $alreadyActive = true; } } } // Template handling $tpl = eZTemplate::factory(); $tpl->setVariable('module', $Module); $tpl->setVariable('account_activated', $accountActivated); $tpl->setVariable('already_active', $alreadyActive); $tpl->setVariable('is_pending', $isPending); // This line is deprecated, the correct name of the variable should // be 'account_activated' as shown above.
/** * Executes a custom action for an object attribute which was defined on the web page. * * @param eZHTTPTool $http * @param string $action * @param eZContentObjectAttribute $contentObjectAttribute * @param array $parameters */ function customObjectAttributeHTTPAction($http, $action, $contentObjectAttribute, $parameters) { $params = explode('-', $action); switch ($params[0]) { case 'new_zone_layout': if ($http->hasPostVariable('ContentObjectAttribute_ezpage_zone_allowed_type_' . $contentObjectAttribute->attribute('id'))) { $zoneMap = array(); if ($http->hasPostVariable('ContentObjectAttribute_ezpage_zone_map')) { $zoneMap = $http->postVariable('ContentObjectAttribute_ezpage_zone_map'); } $zoneINI = eZINI::instance('zone.ini'); $page = $contentObjectAttribute->content(); $zoneAllowedType = $http->postVariable('ContentObjectAttribute_ezpage_zone_allowed_type_' . $contentObjectAttribute->attribute('id')); if ($zoneAllowedType == $page->attribute('zone_layout')) { return false; } $allowedZones = $zoneINI->variable($zoneAllowedType, 'Zones'); $allowedZonesCount = count($allowedZones); $page->setAttribute('zone_layout', $zoneAllowedType); $existingZoneCount = $page->getZoneCount(); $zoneCountDiff = 0; if ($allowedZonesCount < $existingZoneCount) { $zoneCountDiff = $existingZoneCount - $allowedZonesCount; } if (count($zoneMap) > 0) { foreach ($page->attribute('zones') as $zoneIndex => $zone) { $zoneMapKey = array_search($zone->attribute('zone_identifier'), $zoneMap); if ($zoneMapKey) { $zone->setAttribute('action', 'modify'); $zone->setAttribute('zone_identifier', $zoneMapKey); } else { if ($zone->toBeAdded()) { $page->removeZone($zoneIndex); } else { $zone->setAttribute('action', 'remove'); } } } } else { foreach ($allowedZones as $index => $zoneIdentifier) { $existingZone = $page->getZone($index); if ($existingZone instanceof eZPageZone) { $existingZone->setAttribute('action', 'modify'); $existingZone->setAttribute('zone_identifier', $zoneIdentifier); } else { $newZone = $page->addZone(new eZPageZone()); $newZone->setAttribute('id', md5(mt_rand() . microtime() . $page->getZoneCount())); $newZone->setAttribute('zone_identifier', $zoneIdentifier); $newZone->setAttribute('action', 'add'); } } if ($zoneCountDiff > 0) { while ($zoneCountDiff != 0) { $existingZoneIndex = $existingZoneCount - $zoneCountDiff; $existingZone = $page->getZone($existingZoneIndex); if ($existingZone->toBeAdded()) { $page->removeZone($existingZoneIndex); } else { $existingZone->setAttribute('action', 'remove'); } $zoneCountDiff -= 1; } } } $page->sortZones(); } break; case 'set_rotation': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $rotationValue = $http->postVariable('RotationValue_' . $params[2]); $rotationUnit = $http->postVariable('RotationUnit_' . $params[2]); $rotationSuffle = $http->postVariable('RotationShuffle_' . $params[2]); if ($rotationValue == '') { $block->setAttribute('rotation', array('interval' => 0, 'type' => 0, 'value' => '', 'unit' => '')); } else { switch ($rotationUnit) { case '2': $rotationInterval = $rotationValue * 60; break; case '3': $rotationInterval = $rotationValue * 3600; break; case '4': $rotationInterval = $rotationValue * 86400; default: break; } $rotationType = 1; if ($rotationSuffle) { $rotationType = 2; } $block->setAttribute('rotation', array('interval' => $rotationInterval, 'type' => $rotationType, 'value' => $rotationValue, 'unit' => $rotationUnit)); } break; case 'remove_block': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); if ($block->toBeAdded()) { $zone->removeBlock($params[2]); } else { $block->setAttribute('action', 'remove'); } break; case 'new_block': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); if ($http->hasPostVariable('ContentObjectAttribute_ezpage_block_type_' . $contentObjectAttribute->attribute('id') . '_' . $params[1])) { $blockType = $http->postVariable('ContentObjectAttribute_ezpage_block_type_' . $contentObjectAttribute->attribute('id') . '_' . $params[1]); } if ($http->hasPostVariable('ContentObjectAttribute_ezpage_block_name_' . $contentObjectAttribute->attribute('id') . '_' . $params[1])) { $blockName = $http->postVariable('ContentObjectAttribute_ezpage_block_name_' . $contentObjectAttribute->attribute('id') . '_' . $params[1]); } $block = $zone->addBlock(new eZPageBlock($blockName)); $block->setAttribute('action', 'add'); $block->setAttribute('id', md5(mt_rand() . microtime() . $zone->getBlockCount())); $block->setAttribute('zone_id', $zone->attribute('id')); $block->setAttribute('type', $blockType); break; case 'move_block_up': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $zone->moveBlockUp($params[2]); break; case 'move_block_down': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $zone->moveBlockDown($params[2]); break; case 'new_item': if ($http->hasPostVariable('SelectedNodeIDArray')) { if (!$http->hasPostVariable('BrowseCancelButton')) { $selectedNodeIDArray = $http->postVariable('SelectedNodeIDArray'); $page = $contentObjectAttribute->content(); $zone = null; $block = null; if (isset($params[1]) && $page instanceof eZPage) { $zone = $page->getZone($params[1]); } if ($zone instanceof eZPageZone) { $block = $zone->getBlock($params[2]); } if ($block instanceof eZPageBlock) { foreach ($selectedNodeIDArray as $index => $nodeID) { $object = eZContentObject::fetchByNodeID($nodeID); if (!$object instanceof eZContentObject) { return false; } $objectID = $object->attribute('id'); //judge the list if there is a same item in history $itemAdded = false; $itemValid = false; $historyItems = $block->attribute('archived'); foreach ($historyItems as $historyItem) { if ($historyItem->attribute('object_id') == $objectID) { $itemAdded = $historyItem; } } $validItems = $block->attribute('valid'); foreach ($validItems as $validItem) { if ($validItem->attribute('object_id') == $objectID) { $itemValid = $validItem; } } //judge if the item will be removed $itemToBeRemoved = false; if ($block->getItemCount() > 0) { foreach ($block->attribute('items') as $itemID => $item) { if ($item->attribute('object_id') == $objectID) { if ($item->toBeRemoved()) { $itemToBeRemoved = true; $itemAdded = $item; } } } } if ($itemAdded || $itemToBeRemoved) { //if there is same item in history, or item to be removed (in history or valid), set the item in history to be modified // if item is not to be removed, add to the block since it's not in block ,but in history or valid if (!$itemToBeRemoved) { $block->addItem($itemAdded); } $itemAdded->setXMLStorable(true); $itemAdded->setAttribute('node_id', $nodeID); $itemAdded->setAttribute('priority', $block->getItemCount()); $itemAdded->setAttribute('ts_publication', time()); $itemAdded->setAttribute('ts_visible', '0'); $itemAdded->setAttribute('ts_hidden', '0'); $itemAdded->setAttribute('action', 'modify'); } else { if (!$itemValid) { //if there is no same item in history and valid, also the item is not to be removed, add new $item = $block->addItem(new eZPageBlockItem()); $item->setAttribute('object_id', $objectID); $item->setAttribute('node_id', $nodeID); $item->setAttribute('priority', $block->getItemCount()); $item->setAttribute('ts_publication', time()); $item->setAttribute('action', 'add'); } } } } $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); } } break; case 'new_item_browse': $module = $parameters['module']; $redirectionURI = $redirectionURI = $parameters['current-redirection-uri']; $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $type = $block->attribute('type'); $blockINI = eZINI::instance('block.ini'); $classArray = false; if ($blockINI->hasVariable($type, 'AllowedClasses')) { $classArray = $blockINI->variable($type, 'AllowedClasses'); } eZContentBrowse::browse(array('class_array' => $classArray, 'action_name' => 'AddNewBlockItem', 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_new_item-' . $params[1] . '-' . $params[2] . ']', 'value' => $contentObjectAttribute->attribute('id')), 'from_page' => $redirectionURI, 'cancel_page' => $redirectionURI, 'persistent_data' => array('HasObjectInput' => 0)), $module); break; case 'new_source': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); if ($http->hasPostVariable('SelectedNodeIDArray')) { $selectedNodeIDArray = $http->postVariable('SelectedNodeIDArray'); $blockINI = eZINI::instance('block.ini'); $fetchParametersSelectionType = $blockINI->variable($block->attribute('type'), 'FetchParametersSelectionType'); $fetchParams = unserialize($block->attribute('fetch_params')); if ($fetchParametersSelectionType['Source'] == 'single') { $fetchParams['Source'] = $selectedNodeIDArray[0]; } else { $fetchParams['Source'] = $selectedNodeIDArray; } $block->setAttribute('fetch_params', serialize($fetchParams)); $persBlockObject = eZFlowBlock::fetch($block->attribute('id')); if ($persBlockObject instanceof eZFlowBlock) { $persBlockObject->setAttribute('last_update', 0); $persBlockObject->store(); } } $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); break; case 'new_source_browse': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $blockINI = eZINI::instance('block.ini'); $fetchParametersSelectionType = $blockINI->variable($block->attribute('type'), 'FetchParametersSelectionType'); $module = $parameters['module']; $redirectionURI = $redirectionURI = $parameters['current-redirection-uri']; eZContentBrowse::browse(array('action_name' => 'AddNewBlockSource', 'selection' => $fetchParametersSelectionType['Source'], 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_new_source-' . $params[1] . '-' . $params[2] . ']', 'value' => $contentObjectAttribute->attribute('id')), 'from_page' => $redirectionURI, 'cancel_page' => $redirectionURI, 'persistent_data' => array('HasObjectInput' => 0)), $module); break; case 'custom_attribute': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); if (!$http->hasPostVariable('BrowseCancelButton')) { $customAttributes = $block->attribute('custom_attributes'); if ($http->hasPostVariable('SelectedNodeIDArray')) { $selectedNodeIDArray = $http->postVariable('SelectedNodeIDArray'); $customAttributes[$params[3]] = $selectedNodeIDArray[0]; } $block->setAttribute('custom_attributes', $customAttributes); $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); } break; case 'custom_attribute_browse': $module = $parameters['module']; $redirectionURI = $redirectionURI = $parameters['current-redirection-uri']; eZContentBrowse::browse(array('action_name' => 'CustomAttributeBrowse', 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_custom_attribute-' . $params[1] . '-' . $params[2] . '-' . $params[3] . ']', 'value' => $contentObjectAttribute->attribute('id')), 'from_page' => $redirectionURI, 'cancel_page' => $redirectionURI, 'persistent_data' => array('HasObjectInput' => 0)), $module); break; case 'remove_item': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $deleteItemIDArray = $http->postVariable('DeleteItemIDArray'); if ($block->getItemCount() > 0) { foreach ($block->attribute('items') as $itemID => $item) { foreach ($deleteItemIDArray as $index => $deleteItemID) { if ($item->attribute('object_id') == $deleteItemID) { if ($item->toBeAdded()) { $block->removeItem($itemID); unset($deleteItemIDArray[$index]); } elseif ($item->toBeModified()) { $block->removeItem($itemID); } } } } } foreach ($deleteItemIDArray as $deleteItemID) { $item = $block->addItem(new eZPageBlockItem()); $item->setAttribute('object_id', $deleteItemID); $item->setAttribute('action', 'remove'); } break; default: break; } }
$sql = "SELECT count(*) as count FROM ezcontentobject_tree WHERE node_id = {$defaultUserPlacement}"; $rows = $db->arrayQuery($sql); $count = $rows[0]['count']; if ($count < 1) { $errMsg = ezpI18n::tr('design/standard/user', 'The node (%1) specified in [UserSettings].DefaultUserPlacement setting in site.ini does not exist!', null, array($defaultUserPlacement)); $checkErrNodeId = true; eZDebug::writeError("{$errMsg}"); $tpl->setVariable('errMsg', $errMsg); $tpl->setVariable('checkErrNodeId', $checkErrNodeId); } $userClassID = $ini->variable("UserSettings", "UserClassID"); $class = eZContentClass::fetch($userClassID); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); if ($defaultSectionID == 0 && $count > 0) { $parentContentObject = eZContentObject::fetchByNodeID($defaultUserPlacement); $defaultSectionID = $parentContentObject->attribute('section_id'); } $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); $objectID = $contentObject->attribute('id'); // Store the ID in session variable $http->setSessionVariable("RegisterUserID", $objectID); $userID = $objectID; $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => 1, 'parent_node' => $defaultUserPlacement, 'is_main' => 1)); $nodeAssignment->store(); } else { if ($http->hasSessionVariable('StartedRegistration')) { eZDebug::writeWarning('Cancel module run to protect against multiple form submits', 'user/register'); $http->removeSessionVariable("RegisterUserID"); $http->removeSessionVariable('StartedRegistration'); $db->commit();
function getParentObject() { return eZContentObject::fetchByNodeID($this->attribute('parent_node')); }
// // // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## // /* For loading json data of a given object by object id */ $embedId = 0; $http = eZHTTPTool::instance(); if (isset($Params['EmbedID']) && $Params['EmbedID']) { $embedType = 'ezobject'; if (is_numeric($Params['EmbedID'])) { $embedId = $Params['EmbedID']; } else { list($embedType, $embedId) = explode('_', $Params['EmbedID']); } if (strcasecmp($embedType, 'eznode') === 0) { $embedObject = eZContentObject::fetchByNodeID($embedId); } else { $embedObject = eZContentObject::fetch($embedId); } } if (!$embedObject instanceof eZContentObject || !$embedObject->canRead()) { echo 'false'; eZExecution::cleanExit(); } // Params for node to json encoder $params = array('loadImages' => true); $params['imagePreGenerateSizes'] = array('small', 'original'); // look for datamap parameter ( what datamap attribute we should load ) if (isset($Params['DataMap']) && $Params['DataMap']) { $params['dataMap'] = array($Params['DataMap']); }
static function nodeListForObject($contentObject, $versionNum, $clearCacheType, &$nodeList, &$handledObjectList) { $contentObjectID = $contentObject->attribute('id'); if (isset($handledObjectList[$contentObjectID])) { $handledObjectList[$contentObjectID] |= $clearCacheType; } else { $handledObjectList[$contentObjectID] = $clearCacheType; } //self::writeDebugBits( $handledObjectList, self::CLEAR_SIBLINGS_CACHE ); $assignedNodes = $contentObject->assignedNodes(); // determine if $contentObject has dependent objects for which cache should be cleared too. $objectClassIdentifier = $contentObject->attribute('class_identifier'); $dependentClassInfo = eZContentCacheManager::dependencyInfo($objectClassIdentifier); if ($dependentClassInfo['clear_cache_type'] === self::CLEAR_NO_CACHE) { // BC: Allow smart cache clear setting to specify no caching setting $clearCacheType = self::CLEAR_NO_CACHE; } else { if ($dependentClassInfo['clear_cache_exclusive'] === true) { // use class specific smart cache rules exclusivly $clearCacheType = $dependentClassInfo['clear_cache_type']; } } if ($clearCacheType === self::CLEAR_NO_CACHE) { // when recursing we will never have to handle this object again for other cache types // because types of caches to clear will always be set to none $handledObjectList[$contentObjectID] = self::CLEAR_ALL_CACHE; } if ($clearCacheType & self::CLEAR_NODE_CACHE) { eZContentCacheManager::appendNodeIDs($assignedNodes, $nodeList); } if ($clearCacheType & self::CLEAR_PARENT_CACHE) { eZContentCacheManager::appendParentNodeIDs($contentObject, $versionNum, $nodeList); } if ($clearCacheType & self::CLEAR_RELATING_CACHE) { eZContentCacheManager::appendRelatingNodeIDs($contentObject, $nodeList); } if ($clearCacheType & self::CLEAR_KEYWORD_CACHE) { $keywordClearLimit = null; $viewcacheini = eZINI::instance('viewcache.ini'); if (is_numeric($viewcacheini->variable('ViewCacheSettings', 'KeywordNodesCacheClearLimit'))) { $keywordClearLimit = (int) $viewcacheini->variable('ViewCacheSettings', 'KeywordNodesCacheClearLimit'); } eZContentCacheManager::appendKeywordNodeIDs($contentObject, $versionNum, $nodeList, $keywordClearLimit); } if ($clearCacheType & self::CLEAR_SIBLINGS_CACHE) { eZContentCacheManager::appendSiblingsNodeIDs($assignedNodes, $nodeList); } if ($dependentClassInfo['clear_cache_type'] & self::CLEAR_SIBLINGS_CACHE) { if (!($clearCacheType & self::CLEAR_SIBLINGS_CACHE)) { eZContentCacheManager::appendSiblingsNodeIDs($assignedNodes, $nodeList); $handledObjectList[$contentObjectID] |= self::CLEAR_SIBLINGS_CACHE; } // drop 'siblings' bit and process parent nodes. // since 'sibling' mode is affected to the current object $dependentClassInfo['clear_cache_type'] &= ~self::CLEAR_SIBLINGS_CACHE; } if ($clearCacheType & self::CLEAR_CHILDREN_CACHE) { eZContentCacheManager::appendChildrenNodeIDs($assignedNodes, $nodeList); } if ($dependentClassInfo['clear_cache_type'] & self::CLEAR_CHILDREN_CACHE) { if (!($clearCacheType & self::CLEAR_CHILDREN_CACHE)) { eZContentCacheManager::appendChildrenNodeIDs($assignedNodes, $nodeList); $handledObjectList[$contentObjectID] |= self::CLEAR_CHILDREN_CACHE; } // drop 'children' bit and process parent nodes. // since 'children' mode is affected to the current object $dependentClassInfo['clear_cache_type'] &= ~self::CLEAR_CHILDREN_CACHE; } if (isset($dependentClassInfo['additional_objects'])) { foreach ($dependentClassInfo['additional_objects'] as $objectID) { // skip if cache type is already handled for this object if (isset($handledObjectList[$objectID]) && $handledObjectList[$objectID] & self::CLEAR_NODE_CACHE) { continue; } $object = eZContentObject::fetch($objectID); if ($object) { //eZDebug::writeDebug( 'adding additional object ' . $objectID, 'eZContentCacheManager::nodeListForObject() for object ' . $contentObjectID ); eZContentCacheManager::nodeListForObject($object, true, self::CLEAR_NODE_CACHE, $nodeList, $handledObjectList); } } } if (isset($dependentClassInfo['dependent_class_identifier'])) { $maxParents = $dependentClassInfo['max_parents']; $dependentClassIdentifiers = $dependentClassInfo['dependent_class_identifier']; $smartClearType = $dependentClassInfo['clear_cache_type']; // getting 'path_string's for all locations. $nodePathList = eZContentCacheManager::fetchNodePathString($assignedNodes); foreach ($nodePathList as $nodePath) { $step = 0; // getting class identifier and node ID for each node in the $nodePath, up to $maxParents $nodeInfoList = eZContentObjectTreeNode::fetchClassIdentifierListByPathString($nodePath, false, $maxParents); // for each node in $nodeInfoList determine if this node belongs to $dependentClassIdentifiers. If // so then clear cache for this node. foreach ($nodeInfoList as $item) { if (in_array($item['class_identifier'], $dependentClassIdentifiers)) { $object = eZContentObject::fetchByNodeID($item['node_id']); if (!$object instanceof eZContentObject) { continue; } $objectID = $object->attribute('id'); if (isset($handledObjectList[$objectID])) { // remove cache types that were already handled $smartClearType &= ~$handledObjectList[$objectID]; // if there are no cache types remaining, then skip if ($smartClearType == self::CLEAR_NO_CACHE) { continue; } } if (count($dependentClassInfo['object_filter']) > 0) { if (in_array($objectID, $dependentClassInfo['object_filter'])) { //eZDebug::writeDebug( 'adding parent ' . $objectID, 'eZContentCacheManager::nodeListForObject() for object ' . $contentObjectID ); eZContentCacheManager::nodeListForObject($object, true, $smartClearType, $nodeList, $handledObjectList); } } else { //eZDebug::writeDebug( 'adding parent ' . $objectID, 'eZContentCacheManager::nodeListForObject() for object ' . $contentObjectID ); eZContentCacheManager::nodeListForObject($object, true, $smartClearType, $nodeList, $handledObjectList); } } } } } //self::writeDebugBits( $handledObjectList, self::CLEAR_SIBLINGS_CACHE ); }
$node = eZContentObjectTreeNode::fetch($contentNodeID); $parentNodeID = $node->attribute('parent_node_id'); } $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') . '/'); }
/** * Do all time based operations on block pool such as rotation, updating * the queue, overflow as well as executes fetch interfaces. * * @static */ public static function update($nodeArray = array()) { // log in user as anonymous if another user is logged in $currentUser = eZUser::currentUser(); if ($currentUser->isLoggedIn()) { $loggedInUser = $currentUser; $anonymousUserId = eZUser::anonymousId(); $anonymousUser = eZUser::instance($anonymousUserId); eZUser::setCurrentlyLoggedInUser($anonymousUser, $anonymousUserId); unset($currentUser, $anonymousUser, $anonymousUserId); } include_once 'kernel/classes/ezcontentcache.php'; $ini = eZINI::instance('block.ini'); $db = eZDB::instance(); // Remove the blocks and items for the block if marked for removal $res = $db->arrayQuery("SELECT id\n FROM ezm_block\n WHERE is_removed=1"); foreach ($res as $row) { $blockID = $row['id']; $db->begin(); $db->query("DELETE FROM ezm_pool\n WHERE block_id='{$blockID}'"); $db->query("DELETE FROM ezm_block\n WHERE id='{$blockID}'"); $db->commit(); } if (!$nodeArray) { // Update pool and pages for all nodes $res = $db->arrayQuery("SELECT DISTINCT node_id FROM ezm_block"); foreach ($res as $row) { $nodeArray[] = $row['node_id']; } } foreach ($nodeArray as $nodeID) { $time = time() - 5; // a safety margin $nodeChanged = false; $blocks = $db->arrayQuery("SELECT *\n FROM ezm_block\n WHERE node_id={$nodeID}"); $blockByID = array(); // Determine the order of updating $correctOrder = array(); $next = array(); foreach ($blocks as $block) { $next[$block['id']] = trim($block['overflow_id']); // Make sure that block ID does not any have spaces $blockByID[$block['id']] = $block; } $nextIDs = array_keys($next); foreach ($nextIDs as $id) { if (in_array($id, $correctOrder, true)) { continue; } if (!$next[$id]) { $correctOrder[] = $id; continue; } $subCorrectOrder = array($id); $currentID = $id; while ($nextID = $next[$currentID]) { if (!in_array($nextID, $nextIDs, true)) { eZDebug::writeWarning("Overflow for {$currentID} is {$nextID}, but no such block was found for the given node", __METHOD__); break; } if (in_array($nextID, $subCorrectOrder, true)) { eZDebug::writeWarning("Loop detected, ignoring ({$nextID} should be after {$currentID} and vice versa)", __METHOD__); break; } if (in_array($nextID, $correctOrder, true)) { break; } $subCorrectOrder[] = $nextID; $currentID = $nextID; } if (!$nextID || !in_array($nextID, $correctOrder, true)) { foreach ($subCorrectOrder as $element) { $correctOrder[] = $element; } } else { $newCorrectOrder = array(); foreach ($correctOrder as $element) { if ($element === $nextID) { foreach ($subCorrectOrder as $element2) { $newCorrectOrder[] = $element2; } } $newCorrectOrder[] = $element; } $correctOrder = $newCorrectOrder; } } // Loop through all block in determined order foreach ($correctOrder as $blockID) { if ($blockByID[$blockID]) { $block = $blockByID[$blockID]; } else { continue; } // Do we need to update block? No, continue to process next block $ttl = 0; if ($ini->hasVariable($block['block_type'], 'TTL')) { $ttl = $ini->variable($block['block_type'], 'TTL'); } if ($ttl + $block['last_update'] >= $time) { continue; } // For "rotating blocks", does the rotation_interval has passed from the last update? if ($block['rotation_type'] != self::ROTATION_NONE && $block['last_update'] + $block['rotation_interval'] >= $time) { continue; } $blockChanged = false; // Fetch new objects and add them to the queue of the current block eZFlowOperations::updateBlockPoolByBlockID($block, $time); $db->begin(); // We need to find out if there are any items to move from the queue $movingFromQueue = $db->arrayQuery("SELECT object_id\n FROM ezm_pool\n WHERE block_id='{$blockID}'\n AND ts_visible=0\n AND ts_hidden=0\n AND ts_publication<={$time}\n ORDER BY ts_publication ASC, priority ASC"); if ($movingFromQueue) { $blockChanged = true; // Find out a number of items in "valid" state and the max. priority used $countMaxPriorityValid = $db->arrayQuery("SELECT count(*) AS count, max(priority) AS priority\n FROM ezm_pool\n WHERE block_id='{$blockID}'\n AND ts_visible>0\n AND ts_hidden=0"); $countValid = $countMaxPriorityValid[0]['count']; $maxPriorityValid = $countMaxPriorityValid[0]['priority']; if ($countValid == 0) { $maxPriorityValid = 0; } $priority = $maxPriorityValid + 1; // Move objects waiting in queue to the "valid ones" foreach ($movingFromQueue as $itemToMove) { $objectID = $itemToMove['object_id']; $db->query("UPDATE ezm_pool\n SET ts_visible={$time}, priority={$priority}\n WHERE block_id='{$blockID}'\n AND object_id={$objectID}"); $priority++; } $countValid += count($movingFromQueue); // Compare this number to the given and archive the oldest (order by ts_visible) $numberOfValidItems = $ini->variable($block['block_type'], 'NumberOfValidItems'); if (!$numberOfValidItems) { $numberOfValidItems = 20; eZDebug::writeWarning('Number of valid items for ' . $block['block_type'] . ' is not set; using the default value (' . $numberOfValidItems . ')', __METHOD__); } $countToRemove = $countValid - $numberOfValidItems; if ($countToRemove > 0) { $overflowID = $block['overflow_id']; $items = $db->arrayQuery("SELECT node_id, object_id, rotation_until\n FROM ezm_pool\n WHERE block_id='{$blockID}'\n AND ts_visible>0\n AND ts_hidden=0\n ORDER BY priority ASC", array('limit' => $countToRemove)); if ($items) { $itemArray = array(); $priority = 0; foreach ($items as $item) { $objectID = $item['object_id']; if ($block['rotation_type'] != self::ROTATION_NONE && ($item['rotation_until'] > $time || $item['rotation_until'] == 0)) { if ($block['rotation_type'] == self::ROTATION_SIMPLE) { // Simple rotation $newPublicationTS = -$time; $priority++; } else { // Random rotation/Shuffle $newPublicationTS = 0; $priority = mt_rand(); } // Move item back to queue $db->query("UPDATE ezm_pool\n SET ts_visible=0,\n ts_publication=-{$time},\n priority={$priority}\n WHERE block_id='{$blockID}'\n AND object_id={$objectID}"); } else { $itemArray[] = $objectID; } } if ($itemArray) { if ($overflowID) { // Put $itemArray items into pool of different block $priority = 0; foreach ($items as $item) { $itemObjectID = $item['object_id']; $itemNodeID = $item['node_id']; // Check if the object_id is not already in the new block $duplicityCheck = $db->arrayQuery("SELECT object_id\n FROM ezm_pool\n WHERE block_id='{$overflowID}'\n AND object_id={$itemObjectID}", array('limit' => 1)); if ($duplicityCheck) { eZDebug::writeNotice("Object {$itemObjectID} is already available in the block {$overflowID}.", __METHOD__); } else { $db->query("INSERT INTO ezm_pool(block_id,object_id,node_id,ts_publication,priority)\n VALUES ('{$overflowID}',{$itemObjectID},{$itemNodeID},{$time},{$priority})"); $priority++; } } $db->query("UPDATE ezm_pool\n SET ts_hidden={$time},\n moved_to='{$overflowID}',\n priority=0\n WHERE block_id='{$blockID}'\n AND " . $db->generateSQLINStatement($itemArray, 'object_id')); } else { $db->query("UPDATE ezm_pool\n SET ts_hidden={$time},\n priority=0\n WHERE block_id='{$blockID}'\n AND " . $db->generateSQLINStatement($itemArray, 'object_id')); } } } } // Cleanup in archived items $countArchived = $db->arrayQuery("SELECT count(*) AS count\n FROM ezm_pool\n WHERE block_id='{$blockID}'\n AND ts_hidden>0"); $countArchived = $countArchived[0]['count']; // Compare this number to the given and remove the oldest ones $numberOfArchivedItems = $ini->variable($block['block_type'], 'NumberOfArchivedItems'); if ($numberOfArchivedItems < 0) { $numberOfArchivedItems = 50; eZDebug::writeWarning('Number of archived items for ' . $block['block_type'] . ' is not set; using the default value (' . $numberOfArchivedItems . ')', __METHOD__); } $countToRemove = $countArchived - $numberOfArchivedItems; if ($countToRemove > 0) { $items = $db->arrayQuery("SELECT object_id\n FROM ezm_pool\n WHERE block_id='{$blockID}'\n AND ts_hidden>0\n ORDER BY ts_hidden ASC", array('limit' => $countToRemove)); if ($items) { $itemArray = array(); foreach ($items as $item) { $itemArray[] = $item['object_id']; } $db->query("DELETE FROM ezm_pool\n WHERE block_id='{$blockID}'\n AND " . $db->generateSQLINStatement($itemArray, 'object_id')); } } } // If the block changed, we need to update whole node if ($blockChanged) { $nodeChanged = true; } $db->commit(); } if ($nodeChanged) { $contentObject = eZContentObject::fetchByNodeID($nodeID); if ($contentObject) { eZContentCacheManager::clearContentCache($contentObject->attribute('id')); } } } // log the previously logged in user if it was changed to anonymous earlier if (isset($loggedInUser)) { eZUser::setCurrentlyLoggedInUser($loggedInUser, $loggedInUser->attribute('contentobject_id')); } }
public static function fetchPathByActionList($actionName, $actionValues, $locale = null) { if (!is_array($actionValues) || count($actionValues) == 0) { eZDebug::writeError("Action values array must not be empty", __METHOD__); return null; } $db = eZDB::instance(); $actionList = array(); foreach ($actionValues as $i => $value) { $actionList[] = "'" . $db->escapeString($actionName . ":" . $value) . "'"; } $actionStr = join(", ", $actionList); $filterSQL = trim(eZContentLanguage::languagesSQLFilter('ezurlalias_ml', 'lang_mask')); $query = "SELECT id, parent, lang_mask, text, action FROM ezurlalias_ml WHERE ( {$filterSQL} ) AND action in ( {$actionStr} ) AND is_original = 1 AND is_alias=0"; $rows = $db->arrayQuery($query); $objects = eZContentObject::fetchByNodeID($actionValues); $actionMap = array(); foreach ($rows as $row) { $action = $row['action']; if (!isset($actionMap[$action])) { $actionMap[$action] = array(); } $actionMap[$action][] = $row; } if ($locale !== null && is_string($locale) && !empty($locale)) { $selectedLanguage = eZContentLanguage::fetchByLocale($locale); $prioritizedLanguages = eZContentLanguage::prioritizedLanguages(); // Add $selectedLanguage on top of $prioritizedLanguages to take it into account with the highest priority if ($selectedLanguage instanceof eZContentLanguage) { array_unshift($prioritizedLanguages, $selectedLanguage); } } else { $prioritizedLanguages = eZContentLanguage::prioritizedLanguages(); } $path = array(); $lastID = false; foreach ($actionValues as $actionValue) { $action = $actionName . ":" . $actionValue; if (!isset($actionMap[$action])) { // eZDebug::writeError( "The action '{$action}' was not found in the database for the current language language filter, cannot calculate path." ); return null; } $actionRows = $actionMap[$action]; $defaultRow = null; foreach ($prioritizedLanguages as $language) { foreach ($actionRows as $row) { $langMask = (int) $row['lang_mask']; $wantedMask = (int) $language->attribute('id'); if (($wantedMask & $langMask) > 0) { $defaultRow = $row; break 2; } // If the 'always available' bit is set AND it corresponds to the main language, then choose it as the default if ($langMask & 1 && $objects[$actionValue]->attribute('initial_language_id') & $langMask) { $defaultRow = $row; } } } if ($defaultRow) { $id = (int) $defaultRow['id']; $paren = (int) $defaultRow['parent']; // If the parent is 0 it means the element is at the top, ie. reset the path and lastID if ($paren == 0) { $lastID = false; $path = array(); } $path[] = $defaultRow['text']; // Check for a valid path if ($lastID !== false && $lastID != $paren) { eZDebug::writeError("The parent ID {$paren} of element with ID {$id} does not point to the last entry which had ID {$lastID}, incorrect path would be calculated, aborting"); return null; } $lastID = $id; } else { // No row was found eZDebug::writeError("Fatal error, no row was chosen for action " . $actionName . ":" . $actionValue); return null; } } return join("/", $path); }
private function convertToContentObjectId($nodeId) { $object = eZContentObject::fetchByNodeID($nodeId, false); return $object["id"]; }