/** * Returns statistics about users which are currently online * * @param mixed $args * @return array */ public static function onlineUsers($args) { $result = array(); $result['logged_in_count'] = eZFunctionHandler::execute('user', 'logged_in_count', array()); $result['anonymous_count'] = eZFunctionHandler::execute('user', 'anonymous_count', array()); return $result; }
public function execute($process, $event) { $parameters = $process->attribute('parameter_list'); try { // WORKFLOW HERE if ($parameters['trigger_name'] == 'post_updateobjectstate') { $objectId = $parameters['object_id']; $object = eZContentObject::fetch($objectId); $parentStateIDArray = $object->stateIDArray(); $fetch_parameters = array('parent_node_id' => $object->mainNodeID()); $childs = eZFunctionHandler::execute('content', 'list', $fetch_parameters); $stateGroups = eZINI::instance('patbase.ini')->variable('ChildsPropagationState', 'StateGroupID'); foreach ($childs as $child) { $childStateIDArray = $child->object()->stateIDArray(); $stateChanged = FALSE; foreach ($stateGroups as $stateGroup) { if ($childStateIDArray[$stateGroup] !== $parentStateIDArray[$stateGroup]) { $stateChanged = TRUE; $childStateIDArray[$stateGroup] = $parentStateIDArray[$stateGroup]; } } if ($stateChanged) { eZOperationHandler::execute('content', 'updateobjectstate', array('object_id' => $child->ContentObjectID, 'state_id_list' => $childStateIDArray)); } } } else { if ($parameters['trigger_name'] == 'post_publish') { if ($parameters['version'] === '1') { $objectId = $parameters['object_id']; $object = eZContentObject::fetch($objectId); $objectStateIDArray = $object->stateIDArray(); $fetch_parameters = array('node_id' => $object->mainParentNodeID()); $parent = eZFunctionHandler::execute('content', 'node', $fetch_parameters); $stateGroups = eZINI::instance('patbase.ini')->variable('ChildsPropagationState', 'StateGroupID'); $parentStateIDArray = $parent->object()->stateIDArray(); $stateChanged = FALSE; foreach ($stateGroups as $stateGroup) { if ($objectStateIDArray[$stateGroup] !== $parentStateIDArray[$stateGroup]) { $stateChanged = TRUE; $objectStateIDArray[$stateGroup] = $parentStateIDArray[$stateGroup]; } } if ($stateChanged) { eZOperationHandler::execute('content', 'updateobjectstate', array('object_id' => $objectId, 'state_id_list' => $objectStateIDArray)); } } } } // return eZWorkflowType::STATUS_ACCEPTED; } catch (Exception $e) { eZDebug::writeError($e->getMessage(), __METHOD__); return eZWorkflowType::STATUS_REJECTED; } }
function getObjectList() { $parameters = array('parent_node_id' => $this->parent_node_id, 'class_filter_type' => 'include', 'class_filter_array' => $this->class_filter, 'offset' => $this->offset, 'depth' => $this->depth, 'ignore_visibility' => $this->ignore_visibility); if ($this->limit > 0) { $parameters['limit'] = $this->limit; } if (!empty($this->locales)) { $parameters['extended_attribute_filter'] = array('id' => 'TranslationsFilter', 'params' => array('locales' => $this->locales)); } return eZFunctionHandler::execute('content', 'list', $parameters); }
/** * {@inheritdoc} */ public function getMostPopular() { // Sanity check, we need eZ Publish classes. if (!class_exists('eZFunctionHandler') or !class_exists('eZViewCounter')) { throw new Exceptions\ProviderFailureException('Cannot use the EzPublishLegacyProvider without eZ Publish.', 404); } // Default to 'article'. $contentClasses = $this->contentClasses; if (empty($contentClasses)) { $contentClasses[] = 'article'; } $limit = $this->limit; if (0 !== $this->offset) { trigger_error('Offset is not supported by EzPublishLegacyProvider', E_USER_NOTICE); } if (0 > $this->offset) { trigger_error('Ascending sort is not supported by EzPublishLegacyProvider', E_USER_NOTICE); } // Retrieve content classes. $contentClasses = \eZFunctionHandler::execute('class', 'list', ['class_filter' => $contentClasses]); $mostPopularArray = []; $names = []; $sortedArray = []; foreach ($contentClasses as $contentClass) { $contentObjectArray = \eZFunctionHandler::execute('content', 'view_top_list', ['class_id' => $contentClass->ID, 'section_id' => $sectionId, 'limit' => $limit]); foreach ($contentObjectArray as $contentObject) { // Fetch view count of current node id. $mostPopularArray[$contentObject->NodeID] = $contentObject; $viewCount = \eZViewCounter::fetch($contentObject->NodeID); if (is_object($viewCount)) { $names[$contentObject->NodeID] = $contentObject->attribute('name'); $sortedArray[$contentObject->NodeID] = $viewCount->Count; // Use as index. } } } // Reverse sort so that things are in order of view count. arsort($sortedArray); $mostPopular = []; foreach ($sortedArray as $nodeId => $count) { if (array_key_exists($nodeId, $mostPopularArray)) { $mostPopular[] = $mostPopularArray[$nodeId]; } } // Finally return our results. return array_map(function ($node) use($names) { $name = $names[$node]; return new Results\Result($node, $name); }, array_slice($mostPopular, 0, $limit)); }
function getObjectList() { $result = eZFunctionHandler::execute('content', 'node', array('node_id' => $this->node_id_list)); if ($result && !is_array($result)) { $result = array($result); } if ($this->use_main_node) { foreach ($result as $key => $node) { if ($node->attribute('node_id') != $node->attribute('main_node_id')) { $result[$key] = eZFunctionHandler::execute('content', 'node', array('node_id' => $node->attribute('main_node_id'))); } } } return $result; }
public function fetch($parameters, $publishedAfter, $publishedBeforeOrAt) { $ini = eZINI::instance('block.ini'); $limit = 5; if ($ini->hasVariable('Keywords', 'NumberOfValidItems')) { $limit = $ini->variable('Keywords', 'NumberOfValidItems'); } if (isset($parameters['Source']) && $parameters['Source'] != '') { $nodeID = $parameters['Source']; $node = eZContentObjectTreeNode::fetch($nodeID, false, false); // not as an object if ($node && $node['modified_subnode'] <= $publishedAfter) { return array(); } } else { $nodeID = false; } $sortBy = array('published', false); $classIDs = array(); if (isset($parameters['Classes']) && $parameters['Classes'] != '') { $classIdentifiers = explode(',', $parameters['Classes']); foreach ($classIdentifiers as $classIdentifier) { $class = eZContentClass::fetchByIdentifier($classIdentifier, false); // not as an object if ($class) { $classIDs[] = $class['id']; } } } if (isset($parameters['Keywords'])) { $keywords = $parameters['Keywords']; } $result = eZFunctionHandler::execute('content', 'keyword', array('alphabet' => $keywords, 'classid' => $classIDs, 'offset' => 0, 'limit' => $limit, 'parent_node_id' => $nodeID, 'include_duplicates' => false, 'sort_by' => $sortBy, 'strict_matching' => false)); if ($result === null) { return array(); } $fetchResult = array(); foreach ($result as $item) { $fetchResult[] = array('object_id' => $item['link_object']->attribute('contentobject_id'), 'node_id' => $item['link_object']->attribute('node_id'), 'ts_publication' => $item['link_object']->object()->attribute('published')); } return $fetchResult; }
/** * Adds object $contentObject to the search database. * * @param eZContentObject $contentObject Object to add to search engine * @param bool $commit Whether to commit after adding the object. * If set, run optimize() as well every 1000nd time this function is run. * @param $commitWithin Commit within delay (see Solr documentation) * @param bool $softCommit perform a Solr soft commit, which is not flushed to disk * @return bool True if the operation succeed. */ function addObject($contentObject, $commit = true, $commitWithin = 0, $softCommit = null) { // Add all translations to the document list $docList = array(); // Check if we need to index this object after all // Exclude if class identifier is in the exclude list for classes $excludeClasses = $this->FindINI->variable('IndexExclude', 'ClassIdentifierList'); if ($excludeClasses && in_array($contentObject->attribute('class_identifier'), $excludeClasses)) { return true; } // Get global object values $mainNode = $contentObject->attribute('main_node'); if (!$mainNode) { eZDebug::writeError('Unable to fetch main node for object: ' . $contentObject->attribute('id'), __METHOD__); return false; } $mainNodePathArray = $mainNode->attribute('path_array'); $mainNodeID = $mainNode->attribute('node_id'); // initialize array of parent node path ids, needed for multivalued path field and subtree filters $nodePathArray = array(); //included in $nodePathArray //$pathArray = $mainNode->attribute( 'path_array' ); $currentVersion = $contentObject->currentVersion(); // Get object meta attributes. $metaAttributeValues = self::getMetaAttributesForObject($contentObject); // Get node attributes. $nodeAttributeValues = array(); foreach ($contentObject->attribute('assigned_nodes') as $contentNode) { $nodeID = $contentNode->attribute('node_id'); foreach (eZSolr::nodeAttributes() as $attributeName => $fieldType) { $nodeAttributeValues[$nodeID][] = array('name' => $attributeName, 'value' => $contentNode->attribute($attributeName), 'fieldType' => $fieldType); } $nodePathArray[] = $contentNode->attribute('path_array'); } // Check anonymous user access. if ($this->FindINI->variable('SiteSettings', 'IndexPubliclyAvailable') == 'enabled') { $anonymousUserID = $this->SiteINI->variable('UserSettings', 'AnonymousUserID'); $currentUserID = eZUser::currentUserID(); $user = eZUser::instance($anonymousUserID); eZUser::setCurrentlyLoggedInUser($user, $anonymousUserID, eZUser::NO_SESSION_REGENERATE); $anonymousAccess = $contentObject->attribute('can_read'); $user = eZUser::instance($currentUserID); eZUser::setCurrentlyLoggedInUser($user, $currentUserID, eZUser::NO_SESSION_REGENERATE); $anonymousAccess = $anonymousAccess ? 'true' : 'false'; } else { $anonymousAccess = 'false'; } // Load index time boost factors if any //$boostMetaFields = $this->FindINI->variable( "IndexBoost", "MetaField" ); $boostClasses = $this->FindINI->variable('IndexBoost', 'Class'); $boostAttributes = $this->FindINI->variable('IndexBoost', 'Attribute'); $boostDatatypes = $this->FindINI->variable('IndexBoost', 'Datatype'); $reverseRelatedScale = $this->FindINI->variable('IndexBoost', 'ReverseRelatedScale'); // Initialise default doc boost $docBoost = 1.0; $contentClassIdentifier = $contentObject->attribute('class_identifier'); // Just test if the boost factor is defined by checking if it has a numeric value if (isset($boostClasses[$contentClassIdentifier]) && is_numeric($boostClasses[$contentClassIdentifier])) { $docBoost += $boostClasses[$contentClassIdentifier]; } // Google like boosting, using eZ Publish reverseRelatedObjectCount $reverseRelatedObjectCount = $contentObject->reverseRelatedObjectCount(); $docBoost += $reverseRelatedScale * $reverseRelatedObjectCount; // Create the list of available languages for this version : $availableLanguages = $currentVersion->translationList(false, false); // Loop over each language version and create an eZSolrDoc for it foreach ($availableLanguages as $languageCode) { $doc = new eZSolrDoc($docBoost); // Set global unique object ID $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('guid'), $this->guid($contentObject, $languageCode)); // Set installation identifier $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('installation_id'), self::installationID()); $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('installation_url'), $this->FindINI->variable('SiteSettings', 'URLProtocol') . $this->SiteINI->variable('SiteSettings', 'SiteURL') . '/'); // Set Object attributes $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('name'), $contentObject->name(false, $languageCode)); // Also add value to the "sort_name" field as "name" is unsortable, due to Solr limitation (tokenized field) $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('sort_name'), $contentObject->name(false, $languageCode)); $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('anon_access'), $anonymousAccess); $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('language_code'), $languageCode); $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('available_language_codes'), $availableLanguages); if ($owner = $contentObject->attribute('owner')) { // Set owner name $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('owner_name'), $owner->name(false, $languageCode)); // Set owner group ID foreach ($owner->attribute('parent_nodes') as $groupID) { $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('owner_group_id'), $groupID); } } // from eZ Publish 4.1 only: object states // so let's check if the content object has it if (method_exists($contentObject, 'stateIDArray')) { $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('object_states'), $contentObject->stateIDArray()); } // Set content object meta attribute values. foreach ($metaAttributeValues as $metaInfo) { $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName($metaInfo['name']), ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType'])); } // Set content node meta attribute values. foreach ($nodeAttributeValues as $nodeID => $metaInfoArray) { foreach ($metaInfoArray as $metaInfo) { $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName($metaInfo['name']), ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType'])); } } // Main node gets single valued fields for sorting, using a dedicated prefix foreach ($nodeAttributeValues[$mainNodeID] as $metaInfo) { $fieldName = 'main_node_' . ezfSolrDocumentFieldBase::generateMetaFieldName($metaInfo['name']); $doc->addField($fieldName, ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType'])); } // Get url alias in specific language $urlAlias = eZFunctionHandler::execute('switchlanguage', 'url_alias', array('node_id' => $mainNodeID, 'locale' => $languageCode)); // Add main url_alias $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('main_url_alias'), $urlAlias); // Add main path_string $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('main_path_string'), $mainNode->attribute('path_string')); // add nodeid of all parent nodes path elements foreach ($nodePathArray as $pathArray) { foreach ($pathArray as $pathNodeID) { $doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('path'), $pathNodeID); } } // Since eZ Fnd 2.3 // cannot call metafield field bame constructor as we are creating multiple fields foreach ($mainNodePathArray as $key => $pathNodeID) { $doc->addField('meta_main_path_element_' . $key . '_si', $pathNodeID); } eZContentObject::recursionProtectionStart(); // Loop through all eZContentObjectAttributes and add them to the Solr document. // @since eZ Find 2.3: look for the attribute storage setting $doAttributeStorage = $this->FindINI->variable('IndexOptions', 'EnableSolrAttributeStorage') === 'true' ? true : false; if ($doAttributeStorage) { $allAttributeData = array(); } foreach ($currentVersion->contentObjectAttributes($languageCode) as $attribute) { $metaDataText = ''; $classAttribute = $attribute->contentClassAttribute(); $attributeIdentifier = $classAttribute->attribute('identifier'); $combinedIdentifier = $contentClassIdentifier . '/' . $attributeIdentifier; $boostAttribute = false; if (isset($boostAttributes[$attributeIdentifier]) && is_numeric($boostAttributes[$attributeIdentifier])) { $boostAttribute = $boostAttributes[$attributeIdentifier]; } if (isset($boostAttributes[$combinedIdentifier]) && is_numeric($boostAttributes[$combinedIdentifier])) { $boostAttribute += $boostAttributes[$combinedIdentifier]; } if ($classAttribute->attribute('is_searchable') == 1) { $documentFieldBase = ezfSolrDocumentFieldBase::getInstance($attribute); $this->addFieldBaseToDoc($documentFieldBase, $doc, $boostAttribute); } if ($doAttributeStorage) { $storageFieldName = ezfSolrStorage::getSolrStorageFieldName($attributeIdentifier); $attributeData = ezfSolrStorage::getAttributeData($attribute); $allAttributeData['data_map'][$attributeIdentifier] = $attributeData; $doc->addField($storageFieldName, ezfSolrStorage::serializeData($attributeData)); } } eZContentObject::recursionProtectionEnd(); if ($doAttributeStorage) { $doc->addField('as_all_bst', ezfSolrStorage::serializeData($allAttributeData)); } $docList[$languageCode] = $doc; } // Since eZFind 2.7: indexhooks $generalPlugins = $this->FindINI->variable('IndexPlugins', 'General'); $classPlugins = $this->FindINI->variable('IndexPlugins', 'Class'); if (!empty($generalPlugins)) { foreach ($generalPlugins as $pluginClassString) { if (!class_exists($pluginClassString)) { eZDebug::writeError("Unable to find the PHP class '{$pluginClassString}' defined for index time plugins for eZ Find", __METHOD__); continue; } $plugin = new $pluginClassString(); if ($plugin instanceof ezfIndexPlugin) { $plugin->modify($contentObject, $docList); } } } if (array_key_exists($contentObject->attribute('class_identifier'), $classPlugins)) { $pluginClassString = $classPlugins[$contentObject->attribute('class_identifier')]; if (class_exists($pluginClassString)) { $plugin = new $pluginClassString(); if ($plugin instanceof ezfIndexPlugin) { $plugin->modify($contentObject, $docList); } } } $optimize = false; if (!isset($softCommit) && $this->FindINI->variable('IndexOptions', 'EnableSoftCommits') === 'true') { $softCommit = true; } if ($this->FindINI->variable('IndexOptions', 'DisableDirectCommits') === 'true') { $commit = false; } if ($commitWithin === 0 && $this->FindINI->variable('IndexOptions', 'CommitWithin') > 0) { $commitWithin = $this->FindINI->variable('IndexOptions', 'CommitWithin'); } if ($commit && $this->FindINI->variable('IndexOptions', 'OptimizeOnCommit') === 'enabled') { $optimize = true; } if ($this->UseMultiLanguageCores === true) { $result = true; foreach ($availableLanguages as $languageCode) { $languageResult = $this->SolrLanguageShards[$languageCode]->addDocs(array($docList[$languageCode]), $commit, $optimize, $commitWithin); if (!$languageResult) { $result = false; } } return $result; } else { return $this->Solr->addDocs($docList, $commit, $optimize, $commitWithin, $softCommit); } }
static function execute($moduleName, $functionName, $functionParameters) { $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo($moduleName); if (!$moduleFunctionInfo->isValid()) { eZDebug::writeError("Cannot execute function '{$functionName}' in module '{$moduleName}', no valid data", __METHOD__); return null; } return $moduleFunctionInfo->execute($functionName, $functionParameters); }
/** * Returns search results based on given post params * * @param mixed $args Only used if post parameter is not set * 0 => SearchStr * 1 => SearchOffset * 2 => SearchLimit (10 by default, max 50) * @return array */ public static function search($args) { $http = eZHTTPTool::instance(); if ($http->hasPostVariable('SearchStr')) { $searchStr = trim($http->postVariable('SearchStr')); } else { if (isset($args[0])) { $searchStr = trim($args[0]); } } if ($http->hasPostVariable('SearchOffset')) { $searchOffset = (int) $http->postVariable('SearchOffset'); } else { if (isset($args[1])) { $searchOffset = (int) $args[1]; } else { $searchOffset = 0; } } if ($http->hasPostVariable('SearchLimit')) { $searchLimit = (int) $http->postVariable('SearchLimit'); } else { if (isset($args[2])) { $searchLimit = (int) $args[2]; } else { $searchLimit = 10; } } // Do not allow to search for more then x items at a time $ini = eZINI::instance(); $maximumSearchLimit = (int) $ini->variable('SearchSettings', 'MaximumSearchLimit'); if ($searchLimit > $maximumSearchLimit) { $searchLimit = $maximumSearchLimit; } // Prepare node encoding parameters $encodeParams = array(); if (self::hasPostValue($http, 'EncodingLoadImages')) { $encodeParams['loadImages'] = true; } if (self::hasPostValue($http, 'EncodingFetchChildrenCount')) { $encodeParams['fetchChildrenCount'] = true; } if (self::hasPostValue($http, 'EncodingFetchSection')) { $encodeParams['fetchSection'] = true; } if (self::hasPostValue($http, 'EncodingFormatDate')) { $encodeParams['formatDate'] = $http->postVariable('EncodingFormatDate'); } // Prepare search parameters $params = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SortArray' => array('published', 0), 'SortBy' => array('published' => 'desc')); if (self::hasPostValue($http, 'SearchContentClassAttributeID')) { $params['SearchContentClassAttributeID'] = self::makePostArray($http, 'SearchContentClassAttributeID'); } else { if (self::hasPostValue($http, 'SearchContentClassID')) { $params['SearchContentClassID'] = self::makePostArray($http, 'SearchContentClassID'); } else { if (self::hasPostValue($http, 'SearchContentClassIdentifier')) { $params['SearchContentClassID'] = eZContentClass::classIDByIdentifier(self::makePostArray($http, 'SearchContentClassIdentifier')); } } } if (self::hasPostValue($http, 'SearchSubTreeArray')) { $params['SearchSubTreeArray'] = self::makePostArray($http, 'SearchSubTreeArray'); } if (self::hasPostValue($http, 'SearchSectionID')) { $params['SearchSectionID'] = self::makePostArray($http, 'SearchSectionID'); } if (self::hasPostValue($http, 'SearchDate')) { $params['SearchDate'] = (int) $http->postVariable('SearchDate'); } else { if (self::hasPostValue($http, 'SearchTimestamp')) { $params['SearchTimestamp'] = self::makePostArray($http, 'SearchTimestamp'); if (!isset($params['SearchTimestamp'][1])) { $params['SearchTimestamp'] = $params['SearchTimestamp'][0]; } } } if (self::hasPostValue($http, 'EnableSpellCheck') || self::hasPostValue($http, 'enable-spellcheck', '0')) { $params['SpellCheck'] = array(true); } if (self::hasPostValue($http, 'GetFacets') || self::hasPostValue($http, 'show-facets', '0')) { $params['facet'] = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array()); } $result = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SearchResultCount' => 0, 'SearchCount' => 0, 'SearchResult' => array(), 'SearchString' => $searchStr, 'SearchExtras' => array()); // Possibility to keep track of callback reference for use in js callback function if ($http->hasPostVariable('CallbackID')) { $result['CallbackID'] = $http->postVariable('CallbackID'); } // Only search if there is something to search for if ($searchStr) { $searchList = eZSearch::search($searchStr, $params); $result['SearchResultCount'] = $searchList['SearchResult'] !== false ? count($searchList['SearchResult']) : 0; $result['SearchCount'] = (int) $searchList['SearchCount']; $result['SearchResult'] = ezjscAjaxContent::nodeEncode($searchList['SearchResult'], $encodeParams, false); // ezfind stuff if (isset($searchList['SearchExtras']) && $searchList['SearchExtras'] instanceof ezfSearchResultInfo) { if (isset($params['SpellCheck'])) { $result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck'); } if (isset($params['facet'])) { $facetInfo = array(); $retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields'); $baseSearchUrl = "/content/search/"; eZURI::transformURI($baseSearchUrl, false, 'full'); foreach ($params['facet'] as $key => $defaultFacet) { $facetData = $retrievedFacets[$key]; $facetInfo[$key] = array('name' => $defaultFacet['name'], 'list' => array()); if ($facetData !== null) { foreach ($facetData['nameList'] as $key2 => $facetName) { if ($key2 != '') { $tmp = array('value' => $facetName); $tmp['url'] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName; $tmp['count'] = $facetData['countList'][$key2]; $facetInfo[$key]['list'][] = $tmp; } } } } $result['SearchExtras']['facets'] = $facetInfo; } } //$searchList['SearchExtras'] instanceof ezfSearchResultInfo } // $searchStr return $result; }
/** * Regression test for issue #16299, where a fatal error would occur if an unknown sort_order parameter is given * @see http://issues.ez.no/16299 */ public function testIssue16299() { // Create a folder object that will be used as a target for relations $folder = new ezpObject("folder", 2); $folder->name = __FUNCTION__; $folder->short_description = __METHOD__; $folder->publish(); // Create two links & two articles that will be related to the folder created above foreach (array(1, 2) as $index) { $varName = "link{$index}"; ${$varName} = new ezpObject("link", 2); ${$varName}->name = "Link " . __FUNCTION__ . " #{$index}"; ${$varName}->location = 'http://ez.no/'; ${$varName}->addContentObjectRelation($folder->id); ${$varName}->publish(); } foreach (array(1, 2) as $index) { $varName = "article{$index}"; ${$varName} = new ezpObject("article", 2); ${$varName}->title = "Article " . __FUNCTION__ . " #{$index}"; ${$varName}->intro = __METHOD__; ${$varName}->addContentObjectRelation($folder->id); ${$varName}->publish(); } // Call the fetch reverse_related_objects fetch function // The array( 'foo', false ) sort_by item should be ignored $result = eZFunctionHandler::execute('content', 'reverse_related_objects', array('object_id' => $folder->id, 'sort_by' => array(array('name', true), array('foo', false)))); self::assertInternalType('array', $result); self::assertEquals(4, count($result), "Expecting 4 objects fetched"); // Sort by name: self::assertEquals($article1->id, $result[0]->attribute('id')); self::assertEquals($article2->id, $result[1]->attribute('id')); self::assertEquals($link1->id, $result[2]->attribute('id')); self::assertEquals($link2->id, $result[3]->attribute('id')); // Call the fetch reverse_related_objects fetch function // The array( 'foo', false ) sort_by item should be ignored, and random sorting should occur // This validates the behaviour with only one parameter, as the code's different $result = eZFunctionHandler::execute('content', 'reverse_related_objects', array('object_id' => $folder->id, 'sort_by' => array('foo', false))); self::assertInternalType('array', $result); self::assertEquals(4, count($result), "Expecting 4 objects fetched"); // Call the fetch reverse_related_objects fetch function // The array( 'foo', false ) sort_by item should be ignored, and random sorting should occur // This validates the behaviour with only one (correct) parameter $result = eZFunctionHandler::execute('content', 'reverse_related_objects', array('object_id' => $folder->id, 'sort_by' => array('class_identifier', true))); self::assertInternalType('array', $result); self::assertEquals(4, count($result), "Expecting 4 objects fetched"); }
/** * Retourne les éléments de sitemap image pour un content object $object donné * @param eZContentObject $object * @return array(xrowSitemapItemImage) */ private static function getSitemapImageItems(eZContentObject $object) { $images = array(); // D'abord depuis la datamap $images = array_merge($images, self::getSitemapImageItemFromDataMap($object->dataMap())); // Puis avec les related objects $aParamsRelated = array('object_id' => $object->attribute('id'), 'all_relations' => true); $aImageObjectIDs = array(); $relatedObjects = eZFunctionHandler::execute('content', 'related_objects', $aParamsRelated); $imagesRelated = array(); foreach ($relatedObjects as $relatedObject) { switch ($relatedObject->attribute('class_identifier')) { case 'image': $imagesRelated = array_merge($imagesRelated, self::getSitemapImageItemFromDataMap($relatedObject->dataMap())); break; } } // Puis les children (gallery) $imagesChildren = array(); $aParamsChildren = array('class_filter_type' => 'include', 'class_filter_array' => array('image'), 'parent_node_id' => $object->attribute('main_node_id')); $aChildren = eZFunctionHandler::execute('content', 'list', $aParamsChildren); foreach ($aChildren as $child) { $imagesChildren = array_merge($imagesChildren, self::getSitemapImageItemFromDataMap($child->object()->dataMap())); } return array_merge($images, $imagesRelated, $imagesChildren); }
function getObjectList() { $parameters = array('parent_node_id' => $this->parent_node_id, 'class_filter_type' => 'include', 'class_filter_array' => $this->class_filter, 'offset' => $this->offset, 'depth' => $this->depth, 'ignore_visibility' => $this->ignore_visibility); if ($this->limit > 0) { $parameters['limit'] = $this->limit; } if (!empty($this->attribute_filter)) { $parameters['attribute_filter'] = array($this->attribute_filter); } if (!empty($this->locales)) { $is_or_logic = true; if ($this->locales[0] == 'and' or $this->locales[0] == 'or') { $is_or_logic = !(array_shift($this->locales) == 'and'); } $parameters['extended_attribute_filter'] = array('id' => 'TranslationsFilter', 'params' => array('or' => $is_or_logic, 'locales' => $this->locales)); } $result = eZFunctionHandler::execute('content', 'list', $parameters); if ($this->use_main_node) { foreach ($result as $key => $node) { if ($node->attribute('node_id') != $node->attribute('main_node_id')) { $result[$key] = eZFunctionHandler::execute('content', 'node', array('node_id' => $node->attribute('main_node_id'))); } } } return $result; }
/** * @param $tpl eZTemplate * @param $operatorName array * @param $operatorParameters array * @param $rootNamespace string * @param $currentNamespace string * @param $operatorValue mixed * @param $namedParameters array * * @return mixed */ function modify(&$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $ini = eZINI::instance('ocoperatorscollection.ini'); $appini = eZINI::instance('app.ini'); switch ($operatorName) { case 'related_attribute_objects': $object = $operatorValue; $identifier = $namedParameters['identifier']; $dataMap = $object instanceof eZContentObject || $object instanceof eZContentObjectTreeNode ? $object->attribute('data_map') : array(); $data = array(); if (isset($dataMap[$identifier])) { $ids = $dataMap[$identifier] instanceof eZContentObjectAttribute ? explode('-', $dataMap[$identifier]->toString()) : array(); if (!empty($ids)) { $data = eZContentObject::fetchList(true, array("id" => array($ids))); } } $operatorValue = $data; break; case 'smart_override': $identifier = $namedParameters['identifier']; $view = $namedParameters['view']; $node = $operatorValue; $operatorValue = $this->findSmartTemplate($identifier, $view, $node); break; case 'parse_link_href': $href = $operatorValue; $hrefParts = explode(':', $href); $hrefFirst = array_shift($hrefParts); if (!in_array($hrefFirst, array('http', 'https', 'file', 'mailto', 'ftp'))) { if (!empty($hrefFirst)) { $nodeID = eZURLAliasML::fetchNodeIDByPath('/' . $hrefFirst); if ($nodeID) { $contentNode = eZContentObjectTreeNode::fetch($nodeID); if ($contentNode instanceof eZContentObjectTreeNode) { $keyArray = array(array('node', $contentNode->attribute('node_id')), array('object', $contentNode->attribute('contentobject_id')), array('class_identifier', $contentNode->attribute('class_identifier')), array('class_group', $contentNode->attribute('object')->attribute('content_class')->attribute('match_ingroup_id_list'))); $tpl = new eZTemplate(); $ini = eZINI::instance(); $autoLoadPathList = $ini->variable('TemplateSettings', 'AutoloadPathList'); $extensionAutoloadPath = $ini->variable('TemplateSettings', 'ExtensionAutoloadPath'); $extensionPathList = eZExtension::expandedPathList($extensionAutoloadPath, 'autoloads/'); $autoLoadPathList = array_unique(array_merge($autoLoadPathList, $extensionPathList)); $tpl->setAutoloadPathList($autoLoadPathList); $tpl->autoload(); $tpl->setVariable('node', $contentNode); $tpl->setVariable('object', $contentNode->attribute('object')); $tpl->setVariable('original_href', $href); $res = new eZTemplateDesignResource(); $res->setKeys($keyArray); $tpl->registerResource($res); $result = trim($tpl->fetch('design:link/href.tpl')); if (!empty($result)) { $href = $result; } } } } } return $operatorValue = $href; break; case 'gmap_static_image': try { $cacheFileNames = array(); //@todo $operatorValue = OCOperatorsCollectionsTools::gmapStaticImage($namedParameters['parameters'], $namedParameters['attribute'], $cacheFileNames); } catch (Exception $e) { eZDebug::writeError($e->getMessage(), 'gmap_static_image'); } break; case 'fa_class_icon': $faIconIni = eZINI::instance('fa_icons.ini'); $node = $operatorValue; $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : $faIconIni->variable('ClassIcons', '_fallback'); if ($node instanceof eZContentObjectTreeNode) { if ($faIconIni->hasVariable('ClassIcons', $node->attribute('class_identifier'))) { $data = $faIconIni->variable('ClassIcons', $node->attribute('class_identifier')); } } $operatorValue = $data; break; case 'fa_object_icon': $faIconIni = eZINI::instance('fa_icons.ini'); $object = $operatorValue; $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : ''; if ($object instanceof eZContentObject) { if ($faIconIni->hasVariable('ObjectIcons', $object->attribute('id'))) { $data = $faIconIni->variable('ObjectIcons', $object->attribute('id')); } } else { if ($faIconIni->hasVariable('ObjectIcons', $node)) { $data = $faIconIni->variable('ObjectIcons', $node); } } $operatorValue = $data; break; case 'fa_node_icon': $faIconIni = eZINI::instance('fa_icons.ini'); $node = $operatorValue; $data = $namedParameters['fallback'] != '' ? $namedParameters['fallback'] : ''; if ($node instanceof eZContentObjectTreeNode) { if ($faIconIni->hasVariable('NodeIcons', $node->attribute('node_id'))) { $data = $faIconIni->variable('NodeIcons', $node->attribute('node_id')); } } else { if ($faIconIni->hasVariable('NodeIcons', $node)) { $data = $faIconIni->variable('NodeIcons', $node); } } $operatorValue = $data; break; case 'children_class_identifiers': $node = $operatorValue; $data = array(); if ($node instanceof eZContentObjectTreeNode) { $search = eZFunctionHandler::execute('ezfind', 'search', array('subtree_array' => array($node->attribute('node_id')), 'limit' => 1, 'as_objects' => false, 'filter' => array('-meta_id_si:' . $node->attribute('contentobject_id')), 'facet' => array(array('field' => 'meta_class_identifier_ms', 'name' => 'class_identifier', 'limit' => 200)))); if (isset($search['SearchExtras'])) { $facets = $search['SearchExtras']->attribute('facet_fields'); $data = array_diff(array_values($facets[0]['nameList']), $namedParameters['exclude']); } } //eZDebug::writeNotice( $data, 'children_class_identifiers' ); $operatorValue = $data; break; case 'json_encode': $operatorValue = json_encode($operatorValue); break; case 'browse_template': $identifiers = array('image', 'image2', 'galleria', 'gallery', 'immagini'); if ($ini->hasVariable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers')) { $identifiers = $ini->variable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers'); } if ($operatorValue instanceof eZContentBrowse && $operatorValue->hasAttribute('type') && $operatorValue->attribute('type') == 'AddRelatedObjectListToDataType' && $operatorValue->hasAttribute('action_name')) { $currentAttributeId = str_replace('AddRelatedObject_', '', $operatorValue->attribute('action_name')); $currentAttribute = eZPersistentObject::fetchObject(eZContentObjectAttribute::definition(), null, array("id" => $currentAttributeId), false); if (isset($currentAttribute['contentclassattribute_id'])) { $contentClassAttribute = eZContentClassAttribute::fetch($currentAttribute['contentclassattribute_id']); if ($contentClassAttribute instanceof eZContentClassAttribute && ($contentClassAttribute->attribute('data_type_string') == 'mugoobjectrelationlist' || $contentClassAttribute->attribute('data_type_string') == 'ezobjectrelationlist') && in_array($contentClassAttribute->attribute('identifier'), $identifiers)) { return $operatorValue = 'multiupload.tpl'; } } } elseif ($operatorValue instanceof eZContentBrowse && $operatorValue->hasAttribute('action_name') && $operatorValue->attribute('action_name') == 'MultiUploadBrowse') { return $operatorValue = 'multiupload.tpl'; } $operatorValue = 'default.tpl'; break; case 'multiupload_file_types_string': $availableFileTypes = array(); $availableFileTypesString = ''; if (eZINI::instance('ezmultiupload.ini')->hasGroup('FileTypeSettings_' . $operatorValue)) { $availableFileTypes = eZINI::instance('ezmultiupload.ini')->variable('FileTypeSettings_' . $operatorValue, 'FileType'); } if (!empty($availableFileTypes)) { $availableFileTypesString = implode(';', $availableFileTypes); } $operatorValue = $availableFileTypesString; break; case 'multiupload_file_types_string_from_attribute': $availableFileTypesString = ''; $attribute = $operatorValue; if ($attribute instanceof eZContentObjectAttribute) { $identifiers = array(); if ($ini->hasVariable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers')) { $identifier = $attribute->attribute('contentclass_attribute_identifier'); $identifiers = $ini->variable('ObjectRelationsMultiupload', 'ClassAttributeIdentifiers'); if (in_array($identifier, $identifiers)) { $availableFileTypes = array(); $groups = $ini->group('ObjectRelationsMultiuploadFileTypesGroups'); foreach ($groups as $groupName => $fileType) { $groupIdentifiers = $ini->variable('ObjectRelationsMultiuploadFileTypes_' . $groupName, 'Identifiers'); if (in_array($identifier, $groupIdentifiers)) { $availableFileTypesString = $fileType; } } } } } $operatorValue = $availableFileTypesString; break; case 'session_id': $operatorValue = session_id(); break; case 'session_name': $operatorValue = session_name(); break; case 'user_session_hash': $operatorValue = ''; break; case 'developer_warning': $res = false; $user = eZUser::currentUser(); if ($user->attribute('login') == 'admin') { $templates = $tpl->templateFetchList(); $data = array_pop($templates); $res = '<div class="developer-warning alert alert-danger"><strong>Avviso per lo sviluppatore</strong>:<br /><code>' . $data . '</code><br />' . $namedParameters['text'] . '</div>'; } $operatorValue = $res; break; case 'editor_warning': $res = false; $user = eZUser::currentUser(); if ($user->hasAccessTo('content', 'dashboard')) { $res = '<div class="editor-warning alert alert-warning"><strong>Avviso per l\'editor</strong>: ' . $namedParameters['text'] . '</div>'; } $operatorValue = $res; break; case 'appini': if ($appini->hasVariable($namedParameters['block'], $namedParameters['setting'])) { $rs = $appini->variable($namedParameters['block'], $namedParameters['setting']); } else { $rs = $namedParameters['default']; } $operatorValue = $rs; break; case 'has_attribute': case 'attribute': if ($operatorName == 'attribute' && $namedParameters['show_values'] == 'show') { $legacy = new eZTemplateAttributeOperator(); $parameters = $legacy->namedParameterList(); if (isset($parameters['attribute'])) { $parameters = $parameters['attribute']; } $legacyParameters = array(); foreach (array_keys($parameters) as $key) { switch ($key) { case "as_html": $legacyParameters[$key] = true; break; default: $legacyParameters[$key] = isset($namedParameters[$key]) ? $namedParameters[$key] : false; } } $legacy->modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, $operatorValue, $legacyParameters, null); return $operatorValue; } return $operatorValue = $this->hasContentObjectAttribute($operatorValue, $namedParameters['show_values']); break; case 'set_defaults': if (is_array($namedParameters['variables'])) { foreach ($namedParameters['variables'] as $key => $value) { if (!$tpl->hasVariable($key, $currentNamespace)) { $tpl->setLocalVariable($key, $value, $currentNamespace); } } } break; case 'unset_defaults': foreach ($namedParameters['variables'] as $key) { $tpl->unsetLocalVariable($key, $currentNamespace); // if ( isset( $tpl->Variables[$rootNamespace] ) && // array_key_exists( $key, $tpl->Variables[$rootNamespace] ) ) // { // $tpl->unsetVariable( $key, $rootNamespace ); // } } break; //@todo add cache! //@todo add cache! case 'include_cache': $tpl = eZTemplate::factory(); foreach ($namedParameters['variables'] as $key => $value) { $tpl->setVariable($key, $value); } $operatorValue = $tpl->fetch('design:' . $namedParameters['template']); break; case 'find_global_layout': $result = false; $node = $operatorValue; if (is_numeric($node)) { $node = eZContentObjectTreeNode::fetch($node); } if (!$node) { return $operatorValue = $result; } $pathArray = $node->attribute('path_array'); $nodesParams = array(); foreach ($pathArray as $pathNodeID) { if ($pathNodeID < eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode') || $pathNodeID == $node->attribute('node_id')) { continue; } else { $nodesParams[] = array('ParentNodeID' => $pathNodeID, 'ResultID' => 'ezcontentobject_tree.node_id', 'ClassFilterType' => 'include', 'ClassFilterArray' => $ini->variable('GlobalLayout', 'Classes'), 'Depth' => 1, 'DepthOperator' => 'eq', 'AsObject' => false); } } //eZDebug::writeWarning( var_export($nodesParams,1), __METHOD__); $findNodes = eZContentObjectTreeNode::subTreeMultiPaths($nodesParams, array('SortBy' => array('node_id', false))); $sortByParentNodeID = array(); if (!empty($findNodes)) { foreach ($findNodes as $findNode) { $sortByParentNodeID[$findNode['parent_node_id']] = $findNode; } krsort($sortByParentNodeID); $result = array_shift($sortByParentNodeID); $result = eZContentObjectTreeNode::makeObjectsArray(array($result)); if (!empty($result)) { $result = $result[0]; } } return $operatorValue = $result; case 'redirect': $url = $namedParameters['url']; header('Location: ' . $url); break; case 'sort_nodes': $sortNodes = array(); if (!empty($operatorValue) && is_array($operatorValue)) { $nodes = $operatorValue; foreach ($nodes as $node) { if (!$node instanceof eZContentObjectTreeNode) { continue; } $object = $node->object(); switch ($namedParameters['by']) { case 'published': default: $sortby = $object->attribute('published'); break; } $sortNodes[$sortby] = $node; } ksort($sortNodes); if ($namedParameters['order'] == 'desc') { $sortNodes = array_reverse($sortNodes); } } return $operatorValue = $sortNodes; break; case 'to_query_string': if (!empty($namedParameters['param'])) { $value = $namedParameters['param']; } else { $value = $operatorValue; } $string = http_build_query($value); return $operatorValue = $string; break; case 'has_abstract': case 'abstract': $node = $operatorValue; if (!$node instanceof eZContentObjectTreeNode && isset($namedParameters['node'])) { $node = $namedParameters['node']; if (is_numeric($node)) { $node = eZContentObjectTreeNode::fetch($node); } } return $operatorValue = $this->getAbstract($node, $operatorName == 'has_abstract'); break; case 'subsite': $path = $this->getPath($tpl); $result = false; $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array(); $root = eZContentObjectTreeNode::fetch(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode')); if (in_array($root->attribute('class_identifier'), $identifiers)) { $result = $root; } foreach ($path as $item) { if (isset($item['node_id'])) { $node = eZContentObjectTreeNode::fetch($item['node_id']); if (in_array($node->attribute('class_identifier'), $identifiers)) { $result = $node; } } } return $operatorValue = $result; break; case 'in_subsite': $result = false; $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array(); $root = eZContentObjectTreeNode::fetch(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode')); if (in_array($root->attribute('class_identifier'), $identifiers)) { $result = $root; } $node = $operatorValue; if (is_numeric($node)) { $node = eZContentObjectTreeNode::fetch($node); } if (!$node) { return $operatorValue = $result; } foreach ($node->attribute('path') as $item) { if (in_array($item->attribute('class_identifier'), $identifiers)) { $result = $item; break; } } return $operatorValue = $result; break; case 'is_subsite': $identifiers = $ini->hasVariable('Subsite', 'Classes') ? $ini->variable('Subsite', 'Classes') : array(); $inSubsite = false; $node = $operatorValue; if (is_numeric($node)) { $node = eZContentObjectTreeNode::fetch($node); } if (!$node instanceof eZContentObjectTreeNode) { $inSubsite = false; } elseif (in_array($node->attribute('class_identifier'), $identifiers)) { $inSubsite = true; } return $operatorValue = $inSubsite; break; case 'is_in_subsite': if ($operatorValue instanceof eZContentObject) { $nodes = $operatorValue->attribute('assigned_nodes'); foreach ($nodes as $node) { if ($this->isNodeInCurrentSiteaccess($node)) { return $operatorValue; } } } elseif ($operatorValue instanceof eZContentObjectTreeNode) { if ($this->isNodeInCurrentSiteaccess($operatorValue)) { return $operatorValue; } } return $operatorValue = false; case 'section_color': $path = $this->getPath($tpl); $color = false; $attributesIdentifiers = $ini->hasVariable('Color', 'Attributes') ? $ini->variable('Color', 'Attributes') : array(); foreach ($path as $item) { if (isset($item['node_id'])) { $node = eZContentObjectTreeNode::fetch($item['node_id']); /** @var eZContentObjectAttribute[] $attributes */ $attributes = $node->attribute('object')->fetchAttributesByIdentifier($attributesIdentifiers); if (is_array($attributes)) { foreach ($attributes as $attribute) { if ($attribute->hasContent()) { $color = $attribute->content(); } } } } } return $operatorValue = $color; break; case 'oc_shorten': $search = array('@<script[^>]*?>.*?</script>@si', '@<style[^>]*?>.*?</style>@siU'); $operatorValue = preg_replace($search, '', $operatorValue); $operatorValue = strip_tags($operatorValue, $namedParameters['allowable_tags']); $operatorValue = preg_replace('!\\s+!', ' ', $operatorValue); $operatorValue = str_replace(' ', ' ', $operatorValue); $strlenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen'; $operatorLength = $strlenFunc($operatorValue); if ($operatorLength > $namedParameters['chars_to_keep']) { if ($namedParameters['trim_type'] === 'middle') { $appendedStrLen = $strlenFunc($namedParameters['str_to_append']); if ($namedParameters['chars_to_keep'] > $appendedStrLen) { $chop = $namedParameters['chars_to_keep'] - $appendedStrLen; $middlePos = (int) ($chop / 2); $leftPartLength = $middlePos; $rightPartLength = $chop - $middlePos; $operatorValue = trim($this->custom_substr($operatorValue, 0, $leftPartLength) . $namedParameters['str_to_append'] . $this->custom_substr($operatorValue, $operatorLength - $rightPartLength, $rightPartLength)); } else { $operatorValue = $namedParameters['str_to_append']; } } else { $chop = $namedParameters['chars_to_keep'] - $strlenFunc($namedParameters['str_to_append']); $operatorValue = $this->custom_substr($operatorValue, 0, $chop); $operatorValue = trim($operatorValue); if ($operatorLength > $chop) { $operatorValue = $operatorValue . $namedParameters['str_to_append']; } } } if ($namedParameters['allowable_tags'] !== '') { $operatorValue = $this->force_balance_tags($operatorValue); } break; case 'cookieset': $key = isset($namedParameters['cookie_name']) ? $namedParameters['cookie_name'] : false; $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix'); $key = "{$prefix}{$key}"; // Get our parameters: $value = $namedParameters['cookie_val']; $expire = $namedParameters['expiry_time']; // Check and calculate the expiry time: if ($expire > 0) { // It is a number of days: $expire = time() + 60 * 60 * 24 * $expire; } setcookie($key, $value, $expire, '/'); eZDebug::writeDebug('setcookie(' . $key . ', ' . $value . ', ' . $expire . ', "/")', __METHOD__); return $operatorValue = false; break; case 'cookieget': $key = isset($namedParameters['cookie_name']) ? $namedParameters['cookie_name'] : false; $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix'); $key = "{$prefix}{$key}"; $operatorValue = false; if (isset($_COOKIE[$key])) { $operatorValue = $_COOKIE[$key]; } return $operatorValue; break; case 'check_and_set_cookies': $prefix = $ini->variable('CookiesSettings', 'CookieKeyPrefix'); $http = eZHTTPTool::instance(); $return = array(); if ($ini->hasVariable('Cookies', 'Cookies')) { $cookies = $ini->variable('Cookies', 'Cookies'); foreach ($cookies as $key) { $_key = "{$prefix}{$key}"; $default = isset($_COOKIE[$_key]) ? $_COOKIE[$_key] : $ini->variable($key, 'Default'); $value = $http->variable($key, $default); setcookie($_key, $value, time() + 60 * 60 * 24 * 365, '/'); $return[$key] = $value; } } $operatorValue = $return; break; case 'checkbrowser': @(require 'extension/ocoperatorscollection/lib/browser_detection.php'); if (function_exists('browser_detection')) { $full = browser_detection('full_assoc', 2); $operatorValue = $full; } else { eZDebug::writeError("function browser_detection not found", __METHOD__); } break; case 'is_deprecated_browser': $browser = $namedParameters['browser_array']; if ($browser['browser_working'] == 'ie' && $browser['browser_number'] > '7.0') { $operatorValue = true; } $operatorValue = false; break; case 'slugize': $operatorValue = $this->sanitize_title_with_dashes($operatorValue); break; } return false; }
private function getInterviewImage($name) { $importINI = eZINI::instance('sqliimport.ini'); $params = array('parent_node_id' => $importINI->variable('mfmigrationinterviews-HandlerSettings', 'ImagesParentNodeID'), 'attribute_filter' => array(array('name', '=', $name))); $result = eZFunctionHandler::executeAlias('mfcompat_image', $params); if (count($result) == 0) { throw new RuntimeException(__METHOD__ . " => L'image \"{$name}\" introuvable"); } if (!$result[0] instanceof eZContentObjectTreeNode) { throw new RuntimeException(__METHOD__ . ' => Noeud invalide'); } $dm = $result[0]->dataMap(); $imageAlias = $dm['image']->content()->attribute('large'); return $imageAlias['url']; }
/** * Ritorna l'elenco delle classi di contenuto del sito attuale * * @return array */ public static function fetchClassList() { $result = eZFunctionHandler::execute('class', 'list', ''); return $result; }
private function testQuery($testQuery = null) { $query = "/select/?"; $query .= "fl=score,meta_main_url_alias_s&"; $query .= "start=0&"; $query .= "q=submeta_bisac_categories-main_node_id_si:2553"; $query .= "%20AND%20meta_path_si:1"; $query .= "%20AND%20meta_path_si:2"; $query .= "%20AND%20meta_path_si:93"; $query .= "%20AND%20meta_path_si:303"; $query .= "&"; $query .= "rows=10"; $result = eZFunctionHandler::execute('ezfind', 'rawSolrRequest', array('baseURL' => "", 'request' => $query)); var_dump($result); }
$node = eZFunctionHandler::execute('content', 'node', array('node_id' => $node_id)); if ($node) { if (empty($merge_node_master)) { $merge_node_master = $node_id; $http->setSessionVariable('MergeNodeMaster', $merge_node_master); } $object = $node->attribute('object'); $languages = $object->attribute('available_languages'); foreach ($languages as $language) { if (!in_array($language, $language_list)) { $language_list[] = $language; } } $update_translation_map = false; foreach ($language_list as $language) { $node = eZFunctionHandler::execute('content', 'node', array('node_id' => $node_id, 'language_code' => $language)); if ($node and in_array($language, $node->attribute('object')->attribute('available_languages'))) { $node_list[$node_id][$language] = $node; } // Set default values for translation map if (!isset($translation_map[$language])) { $translation_map[$language] = $node_id; $update_translation_map = true; } } if ($update_translation_map) { $http->setSessionVariable('MergeObjectTranslationMap', $translation_map); } } else { unset($selected_array[$key]); $http->setSessionVariable('MergeNodeSelectionList', array_values($selected_array));
public function getData() { try { $returnArray = array(); $dataAnalisiIni = $this->userParameters["dataAnalisiIni"]; $dataAnalisiFin = $this->userParameters["dataAnalisiFin"]; // // Verifica se le date passate sono corretta altrimenti mette il default $dataAnalisiIni = itobjectsutils::dataPerEzfetch($dataAnalisiIni, "INI"); $dataAnalisiFin = itobjectsutils::dataPerEzfetch($dataAnalisiFin, "FIN"); // Scommetare per controllare le date che vengono passate alla fetch // $dataAnalisiIni = "2015-09-01T11:40:00Z"; //echo("--->".$dataAnalisiIni."<---"); //echo("--->".$dataAnalisiFin."<---"); $this->ocLoggerUtil->addInfoMessage('DataAnalisiIni: ' . $dataAnalisiIni); $this->ocLoggerUtil->addInfoMessage('DataAnalisiFin: ' . $dataAnalisiFin); // recupero la lista delle classi gestite dal server $classiGestite = explode(',', $this->runtimeSettingsINI->variable('serverSyncClasses', 'serverSyncClassList')); $objectedreturned = count($classiGestite); // $fetch_parameters = array('query' => '', 'class_id' => $classiGestite, 'limit' => 1000, 'filter' => array('meta_modified_dt:[' . $dataAnalisiIni . ' TO ' . $dataAnalisiFin . ']')); // Fetch su un singolo ID //$result = eZFunctionHandler::execute( 'ezfind', // 'search', array( // 'query' => '', // 'class_id' => array( 'deliberazione' ), // 'filter' => array( 'meta_id_si: ( 43661 )' ) // ) //); $result = eZFunctionHandler::execute('ezfind', 'search', $fetch_parameters); // // Ciclo per recuperare gli array degli oggetti ritornati for ($i = 0; $i < $objectedreturned; $i++) { $returnArray[$i] = array(); } // // Ciclo nell'array degli oggetti ritornati foreach ($result["SearchResult"] as $objectSearchResult) { $identificatore = $objectSearchResult->ContentObject->ClassIdentifier; $ContentObject = $objectSearchResult->ContentObject->RemoteID; $PublishedDate = $objectSearchResult->ContentObject->Published; $ModifiedDate = $objectSearchResult->ContentObject->Modified; // Il RemoteID viene ritornato se la data Modifica è diversa della data Pubblicazione if ($PublishedDate != $ModifiedDate) { //print_r($objectSearchResult); // // Cicla sulle classi e mette gli ID in un array separato per ogni tipo classe for ($i = 0; $i < $objectedreturned; $i++) { if ($classiGestite[$i] == $identificatore) { array_push($returnArray[$i], $ContentObject); } } } } for ($i = 0; $i < $objectedreturned; $i++) { $response[$classiGestite[$i]] = $returnArray[$i]; $this->ocLoggerUtil->addInfoMessage('Numero elementi ritornati: ' . count($returnArray[$i]) . ' per ' . $classiGestite[$i] . " ."); } $this->ocLoggerUtil->addInfoMessage('-- objectController - Server - Exit--'); $this->ocLoggerUtil->writeLogs(); return $response; } catch (Exception $ex) { echo 'Got Exception on DataHandlerserverObjectsync - getData: ' . $e->getMessage() . "\n"; $this->ocLoggerUtil->addErrorMessage('Error in DataHandlerserverObjectsync - getData: ' . $e->getMessage()); $this->ocLoggerUtil->writeLogs(); } }
/** * @param eZContentObjectTreeNode $mediaNode * @return array */ public static function fetchMediaRelatedData( $mediaNode ) { $result = array(); $relatedNodes = array(); $parameters = array( 'object_id' => $mediaNode->attribute('contentobject_id'), 'all_relations' => true, ); /* @type $relatedObjects eZContentObject[] */ $relatedObjects = eZFunctionHandler::execute( 'content', 'reverse_related_objects', $parameters ); $publisherNodeId = MerckManualShowcase::rootNodeId(); foreach( $relatedObjects as $o ) { $an = $o->assignedNodes(); foreach( $an as $n ) { if( strpos( $n->attribute('path_string'), '/' . $publisherNodeId . '/' ) != false ) $relatedNodes[] = $n; } } foreach( $relatedNodes as $relatedNode ) { /* @type $parentNode eZContentObjectTreeNode */ $parentNode = eZFunctionHandler::execute( 'content', 'node', array( 'node_id' => $relatedNode->NodeID, ) ); if( $parentNode->attribute('parent_node_id') == $publisherNodeId ) { $section = self::fetchChapterSection( $relatedNode ); $section = $section['result']; $sectionTrigram = $section['trigram']; if( !array_key_exists( $sectionTrigram, $result ) ) $result[$sectionTrigram]['data'] = $section; $result[$sectionTrigram]['chapters'][$relatedNode->Name] = array( 'data' => $relatedNode, 'media' => $mediaNode ); } else { /* @type $chapterNode eZContentObjectTreeNode */ $chapterNode = $parentNode = eZFunctionHandler::execute( 'content', 'node', array( 'node_id' => $relatedNode->ParentNodeID, ) ); $chapterName = $chapterNode->attribute('name'); $section = self::fetchChapterSection( $chapterNode ); $section = $section['result']; $sectionTrigram = $section['trigram']; if( !array_key_exists( $sectionTrigram, $result ) ) { $result[$sectionTrigram]['data'] = $section; } if( !array_key_exists( $chapterName, $result[$sectionTrigram]['chapters'] ) ) { $result[$sectionTrigram]['chapters'][$chapterName]['data'] = $chapterNode; } $result[$sectionTrigram]['chapters'][$chapterName]['topics'][$relatedNode->Name] = array( 'data' => $relatedNode, 'media' => $mediaNode ); } } return array( 'result' => $result ); }
$name = $module->Module['name'] ? $module->Module['name'] : $identifier; $data[$name] = array('title' => $name, 'key' => $identifier, 'folder' => true, 'lazy' => true, 'icon' => 'glyphicon icon-default', 'type' => 'view'); } ksort($data, SORT_STRING); // remove keys foreach ($data as $entry) { $cleanData[] = $entry; } $content = json_encode($cleanData); } else { $data = array(); $parentNodeId = (int) $value; $parentNode = eZContentObjectTreeNode::fetch($parentNodeId); $params = array('parent_node_id' => $parentNodeId, 'limit' => 200, 'sort_by' => $parentNode->attribute('sort_array')); $list = eZFunctionHandler::execute('content', 'list', $params); $listCount = eZFunctionHandler::execute('content', 'list_count', $params); foreach ($list as $node) { $isContainer = isContainer($node); $entry = array('title' => $node->attribute('name'), 'key' => $node->attribute('node_id'), 'folder' => $isContainer, 'lazy' => $isContainer, 'icon' => 'glyphicon icon-default icon-' . $node->attribute('class_identifier'), 'node_id' => $node->attribute('node_id'), 'contentobject_id' => $node->attribute('contentobject_id'), 'class_identifier' => $node->attribute('class_identifier'), 'name' => $node->attribute('name'), 'href' => getLink($node)); $data[] = $entry; } $content = json_encode($data); } } function isContainer($node) { $isContainer = (bool) $node->attribute('is_container'); if (!$isContainer && in_array($node->attribute('class_identifier'), array('bookmark', 'saved_search'))) { $isContainer = true; } return $isContainer;
/** * @param $courseId * @return array */ protected static function fetchNodeAndAppFromCourseId( $courseId ) { $nodeList = eZFunctionHandler::execute( 'content', 'tree', array( 'parent_node_id' => 2, 'attribute_filter' => array( array( 'article/publisher_internal_id', '=', $courseId ) ), 'class_filter_type' => 'include', 'class_filter_array' => array( 'article' ), 'main_node_only' => false, ) ); foreach ( $nodeList as $node ) { $application = NodeTool::getApplicationFromNode($node); if ( $application ) { $isCertificate = SolrSafeOperatorHelper::getCustomParameter( $application, 'HasCertificates', 'application' ); if ( $isCertificate ) { eZContentObject::clearCache(); return array( 'application' => $application, 'node' => $node, ); } } } eZContentObject::clearCache(); return false; }
// generic info for all views: module name, extension name, ... $fetchList = array(); $modules = eZModuleLister::getModuleList(); if ($Params['modulename'] != '' && !array_key_exists($Params['modulename'], $modules)) { /// @todo } else { $classes = sysInfoTools::autoloadClasses(); foreach ($modules as $modulename => $path) { if ($Params['modulename'] == '' || $Params['modulename'] == $modulename) { $module = eZModule::exists($modulename); if ($module instanceof eZModule) { $extension = ''; if (preg_match('#extension/([^/]+)/modules/#', $path, $matches)) { $extension = $matches[1]; } $functions = eZFunctionHandler::moduleFunctionInfo($modulename); foreach ($functions->FunctionList as $fetchname => $fetch) { // merge empty array to facilitate life of templates $fetch = array_merge(array('name' => $fetchname, 'parameters' => array()), $fetch); // if fetch is done via class method and file to be included misses, calculate it using autoload if (isset($fetch['call_method']['class']) && !isset($fetch['call_method']['include_file'])) { if (isset($classes[$fetch['call_method']['class']])) { $fetch['call_method']['include_file'] = $classes[$fetch['call_method']['class']]; } else { eZDebug::writeWarning('Cannot find in autoloads php file for class ' . $fetch['call_method']['class'], __METHOD__); } } $fetchList[$fetchname . '_' . $modulename] = $fetch; $fetchList[$fetchname . '_' . $modulename]['module'] = $modulename; $fetchList[$fetchname . '_' . $modulename]['extension'] = $extension; }
* This is used to display all objects inside a class */ $Result = array(); $tpl = eZTemplate::factory(); $http = eZHTTPTool::instance(); $allowed_sort_by = array('name', 'node_id', 'published', 'modified'); $allowed_ascending = array('true', 'false'); if (isset($Params['class_id']) && $Params['class_id'] && is_int((int) $Params['class_id'])) { $tpl->setVariable('class_id', (int) $Params['class_id']); } if (isset($Params['offset']) && $Params['offset'] && is_int((int) $Params['offset'])) { $tpl->setVariable('offset', (int) $Params['offset']); } else { $tpl->setVariable('offset', 0); } if (isset($Params['sort_by']) && $Params['sort_by'] && in_array($Params['sort_by'], $allowed_sort_by)) { $tpl->setVariable('sort_by', $Params['sort_by']); } else { $tpl->setVariable('sort_by', 'modified'); } if (isset($Params['ascending']) && $Params['ascending'] && in_array($Params['ascending'], $allowed_ascending)) { $tpl->setVariable('ascending', $Params['ascending']); } else { $tpl->setVariable('ascending', 'false'); } //fetch variable from here $class_object = eZFunctionHandler::execute('content', 'class', array('class_id' => $Params['class_id'])); $tpl->setVariable('class_object', $class_object); $tpl->setVariable('view_parameters', $Params['UserParameters']); $Result['content'] = $tpl->fetch('design:contentclassmanager/view.tpl'); $Result['path'] = array(array('url' => 'contentclassmanager/main', 'text' => 'Objects by content class'), array('url' => false, 'text' => "View Class '" . $class_object->attribute('name') . "'"));
/** * Returns search results based on given params * * @param mixed $args * @return array * @deprecated Use ezjsc::search instead (in ezjscore) */ public static function search($args) { $http = eZHTTPTool::instance(); if ($http->hasPostVariable('SearchStr')) { $searchStr = trim($http->postVariable('SearchStr')); } $searchOffset = 0; if ($http->hasPostVariable('SearchOffset')) { $searchOffset = (int) $http->postVariable('SearchOffset'); } $searchLimit = 10; if ($http->hasPostVariable('SearchLimit')) { $searchLimit = (int) $http->postVariable('SearchLimit'); } if ($searchLimit > 30) { $searchLimit = 30; } if ($http->hasPostVariable('SearchSubTreeArray') && $http->postVariable('SearchSubTreeArray')) { $search_sub_tree_array = explode(',', $http->postVariable('SearchSubTreeArray')); } //Prepare the search params $param = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit + 1, 'SortArray' => array('score', 0), 'SearchSubTreeArray' => $search_sub_tree_array); if ($http->hasPostVariable('enable-spellcheck') and $http->postVariable('enable-spellcheck') == 1) { $param['SpellCheck'] = array(true); } if ($http->hasPostVariable('show-facets') and $http->postVariable('show-facets') == 1) { $defaultFacetFields = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array()); $param['facet'] = $defaultFacetFields; } $solr = new eZSolr(); $searchList = $solr->search($searchStr, $param); $result = array(); $result['SearchResult'] = eZFlowAjaxContent::nodeEncode($searchList['SearchResult'], array(), false); $result['SearchCount'] = $searchList['SearchCount']; $result['SearchOffset'] = $searchOffset; $result['SearchLimit'] = $searchLimit; $result['SearchExtras'] = array(); if (isset($param['SpellCheck'])) { $result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck'); } if (isset($param['facet'])) { $facetInfo = array(); $retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields'); $baseSearchUrl = "/content/search/"; eZURI::transformURI($baseSearchUrl, false, 'full'); foreach ($defaultFacetFields as $key => $defaultFacet) { $facetData = $retrievedFacets[$key]; $facetInfo[$key] = array(); $facetInfo[$key][] = $defaultFacet['name']; if ($facetData != null) { foreach ($facetData['nameList'] as $key2 => $facetName) { $tmp = array(); if ($key2 != '') { $tmp[] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName; $tmp[] = $facetName; $tmp[] = "(" . $facetData['countList'][$key2] . ")"; $facetInfo[$key][] = $tmp; } } } } $result['SearchExtras']['facets'] = $facetInfo; } return $result; }
$username = $http->postVariable('Username'); if ($http->hasPostVariable('Password')) { } $password = $http->postVariable('Password'); if ($http->hasPostVariable('NodeID')) { } $parentNodeID = $http->postVariable('NodeID'); // User authentication $user = eZUser::loginUser($username, $password); if ($user == false) { print 'problem:Authentication failed'; eZExecution::cleanExit(); } else { // Print the list of ID nodes.. //Structure : name, type, ID $nodes = eZFunctionHandler::execute('content', 'list', array('parent_node_id' => $parentNodeID)); $array = array(); foreach ($nodes as $node) { $tpl->setVariable('node', $node); $nodeID = $node->attribute('node_id'); $name = $node->attribute('name'); $className = $node->attribute('class_name'); $object =& $node->object(); $contentClass = $object->contentClass(); $isContainer = $contentClass->attribute('is_container'); preg_match('/\\/+[a-z0-9\\-\\._]+\\/?[a-z0-9_\\.\\-\\?\\+\\/~=&#;,]*[a-z0-9\\/]{1}/si', $tpl->fetch('design:ezodf/icon.tpl'), $matches); $iconPath = 'http://' . eZSys::hostname() . ':' . eZSys::serverPort() . $matches[0]; $array[] = array($nodeID, $name, $className, $isContainer, $iconPath); } //Test if not empty if (empty($array)) {
function updateReverseRelatedObjects($related_object, $new_related_object) { $related_object_id = $related_object->attribute('id'); $new_related_object_id = $new_related_object->attribute('id'); $reverse_related_list = eZFunctionHandler::execute('content', 'reverse_related_objects', array('object_id' => $related_object_id, 'all_relations' => true, 'group_by_attribute' => true, 'as_object' => true)); foreach ($reverse_related_list as $attribute_id => $reverse_related_sublist) { foreach ($reverse_related_sublist as $reverse_related_object) { // To get the different languages of the related object, we need to go through a node fetch $main_node_id = $reverse_related_object->attribute('main_node_id'); $language_list = $reverse_related_object->attribute('available_languages'); foreach ($language_list as $language) { $tmp_node = eZFunctionHandler::execute('content', 'node', array('node_id' => $main_node_id, 'language_code' => $language)); $reverse_related_object = $tmp_node->attribute('object'); $new_version = $reverse_related_object->createNewVersionIn($language); $new_version->setAttribute('modified', time()); $new_version->store(); $new_attributes = $new_version->contentObjectAttributes(); foreach ($new_attributes as $reverse_attribute) { if (empty($attribute_id) or $reverse_attribute->attribute('contentclassattribute_id') == $attribute_id) { switch ($reverse_attribute->attribute('data_type_string')) { case 'ezobjectrelationlist': $old_list = $reverse_attribute->toString(); $list = explode('-', $old_list); foreach ($list as $key => $object_id) { if ($object_id == $related_object_id) { $list[$key] = $new_related_object_id; } } $list = implode('-', array_unique($list)); if ($old_list != $list) { $reverse_attribute->fromString($list); $reverse_attribute->store(); } break; case 'ezobjectrelation': $old_relation = $reverse_attribute->toString(); if ($old_relation != $new_related_object_id) { $reverse_attribute->fromString($new_related_object_id); $reverse_attribute->store(); } break; case 'ezxmltext': $old_xml = $reverse_attribute->toString(); $xml = $old_xml; $xml = str_ireplace("object_id=\"{$related_object_id}\"", "object_id=\"{$new_related_object_id}\"", $xml); $related_node_array = $related_object->attribute('assigned_nodes'); $new_related_node_id = $new_related_object->attribute('main_node_id'); foreach ($related_node_array as $related_node) { $related_node_id = $related_node->attribute('node_id'); $xml = str_ireplace("node_id=\"{$related_node_id}\"", "node_id=\"{$new_related_node_id}\"", $xml); } if ($xml != $old_xml) { $reverse_attribute->fromString($xml); $reverse_attribute->store(); } break; default: } } } // Publish new version $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $reverse_related_object->attribute('id'), 'version' => $new_version->attribute('version'))); eZContentCacheManager::clearObjectViewCache($reverse_related_object->attribute('id'), $new_version->attribute('version')); } } } }
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) { $functionName = $namedParameters['function_name']; $functionParameters = $namedParameters['function_parameters']; if ( $operatorName == $this->Fetch ) { $moduleName = $namedParameters['module_name']; $result = eZFunctionHandler::execute( $moduleName, $functionName, $functionParameters ); $operatorValue = $result; } else if ( $operatorName == $this->FetchAlias ) { $result = eZFunctionHandler::executeAlias( $functionName, $functionParameters ); $operatorValue = $result; } }
/** * @param int $courseId * @return array */ static protected function fetchNodeAndAppFromCourseId( $courseId ) { $nodeList = eZFunctionHandler::execute( 'content', 'tree', array( 'parent_node_id' => 2, 'attribute_filter' => array( array( 'article/publisher_internal_id', '=', $courseId ) ), 'class_filter_type' => 'include', 'class_filter_array' => array( 'article' ), 'main_node_only' => false, ) ); foreach( array_keys($nodeList) as $key ) { $node = $nodeList[$key]; $application = NodeTool::getApplicationFromNode ( $node ); if( $application ) { eZContentObject::clearCache(); return array( 'application' => $application, 'node' => $node, ); } unset($nodeList[$key]); eZContentObject::clearCache(); } eZContentObject::clearCache(); return false; }