public function setUp() { parent::setUp(); $this->xxx = eZContentLanguage::addLanguage('xxx-XX', 'XXXX'); ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', array('xxx-XX', 'eng-GB')); eZContentLanguage::clearPrioritizedLanguages(); }
function getPath($locale = null, $incomingLanguageList = null) { if ($this->Path !== null) { return $this->Path; } // Fetch path 'text' elements of correct parent path $path = array($this->Text); $id = (int) $this->Parent; $db = eZDB::instance(); while ($id != 0) { $query = "SELECT parent, lang_mask, text FROM ezurlalias_ml WHERE id={$id}"; if ($locale !== null && is_string($locale)) { // We also want to consider the prioritized language list for the // destination siteaccess, so that untranslated objects, are not // disregarded from the URL. if ($incomingLanguageList !== null) { eZContentLanguage::setPrioritizedLanguages($incomingLanguageList); } $langMask = trim(eZContentLanguage::languagesSQLFilter('ezurlalias_ml', 'lang_mask')); $query .= " AND ({$langMask})"; } $rows = $db->arrayQuery($query); if (count($rows) == 0) { if ($incomingLanguageList !== null) { eZContentLanguage::clearPrioritizedLanguages(); } break; } $result = eZURLAliasML::choosePrioritizedRow($rows); if ($incomingLanguageList !== null) { eZContentLanguage::clearPrioritizedLanguages(); } if (!$result) { $result = $rows[0]; } $id = (int) $result['parent']; array_unshift($path, $result['text']); } $this->Path = implode('/', $path); return $this->Path; }
public function testChoosePrioritizedRow() { // Make sure we can see all languages ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ShowUntranslatedObjects', 'enabled'); $action = "eznode:" . mt_rand(); $name = __FUNCTION__ . mt_rand(); $engGB = eZContentLanguage::fetchByLocale('eng-GB'); $norNO = eZContentLanguage::fetchByLocale('nor-NO'); // Create an english entry $url1 = eZURLAliasML::create($name . " en", $action, 0, $engGB->attribute('id')); $url1->store(); // Create a norwegian entry $url2 = eZURLAliasML::create($name . " no", $action, 0, $norNO->attribute('id')); $url2->store(); // Fetch the created entries. choosePrioritizedRow() wants rows from the // database so our eZURLAliasML objects wont work. $db = eZDB::instance(); $rows = $db->arrayQuery("SELECT * FROM ezurlalias_ml where action = '{$action}'"); // ------------------------------------------------------------------- // TEST PART 1 - NORMAL PRIORITIZATION ------------------------------- // The order of the language array also determines the prioritization. // In this case 'eng-GB' should be prioritized before 'nor-NO'. $languageList = array("eng-GB", "nor-NO"); ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', $languageList); eZContentLanguage::clearPrioritizedLanguages(); $row = eZURLAliasML::choosePrioritizedRow($rows); // The prioritzed language should be 'eng-GB' self::assertEquals($engGB->attribute('id'), $row["lang_mask"]); // ------------------------------------------------------------------- // TEST PART 2 - REVERSED PRIORITIZATION ----------------------------- // Reverse the order of the specified languages, this will also // reverse the priority. $languageList = array_reverse($languageList); ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', $languageList); eZContentLanguage::clearPrioritizedLanguages(); $row = eZURLAliasML::choosePrioritizedRow($rows); // The prioritzed language should be 'nor-NO' self::assertEquals($norNO->attribute('id'), $row["lang_mask"]); // ------------------------------------------------------------------- // TEST TEAR DOWN ---------------------------------------------------- ezpINIHelper::restoreINISettings(); // ------------------------------------------------------------------- }
static function subTreeCountByNodeID($params = array(), $nodeID) { if (!is_numeric($nodeID) and !is_array($nodeID)) { return null; } $language = isset($params['Language']) ? $params['Language'] : false; if ($language) { if (!is_array($language)) { $language = array($language); } eZContentLanguage::setPrioritizedLanguages($language); } $depth = isset($params['Depth']) && is_numeric($params['Depth']) ? $params['Depth'] : false; $depthOperator = isset($params['DepthOperator']) ? $params['DepthOperator'] : false; $pathStringCond = ''; $notEqParentString = ''; // If the node(s) doesn't exist we return null. if (!eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator)) { return null; } $db = eZDB::instance(); $ini = eZINI::instance(); // Check for class filtering $classCondition = ''; if (isset($params['ClassFilterType']) and isset($params['ClassFilterArray']) and ($params['ClassFilterType'] == 'include' or $params['ClassFilterType'] == 'exclude') and count($params['ClassFilterArray']) > 0) { $classCondition = ' '; $i = 0; $classCount = count($params['ClassFilterArray']); $classIDArray = array(); foreach ($params['ClassFilterArray'] as $classID) { $originalClassID = $classID; // Check if classes are recerenced by identifier if (is_string($classID) && !is_numeric($classID)) { $classID = eZContentClass::classIDByIdentifier($classID); } if (is_numeric($classID)) { $classIDArray[] = $classID; } else { eZDebugSetting::writeWarning('kernel-content-class', "Invalid class identifier in subTree() classfilterarray, classID : " . $originalClassID); } } if (count($classIDArray) > 0) { $classCondition .= " ezcontentobject.contentclass_id "; if ($params['ClassFilterType'] == 'include') { $classCondition .= " IN "; } else { $classCondition .= " NOT IN "; } $classIDString = implode(', ', $classIDArray); $classCondition .= ' ( ' . $classIDString . ' ) AND'; } } // Main node check $mainNodeOnlyCond = ''; if (isset($params['MainNodeOnly']) && $params['MainNodeOnly'] === true) { $mainNodeOnlyCond = 'ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id AND'; } $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $objectNameLanguageFilter = eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); if ($language) { eZContentLanguage::clearPrioritizedLanguages(); } $objectNameFilter = isset($params['ObjectNameFilter']) ? $params['ObjectNameFilter'] : false; $attributeFilterParam = isset($params['AttributeFilter']) ? $params['AttributeFilter'] : false; $sortingInfo = array('sortCount' => 0, 'attributeJoinCount' => 0); $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings($attributeFilterParam, $sortingInfo, $language); if ($attributeFilter === false) { return null; } $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString($objectNameFilter); $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['ExtendedAttributeFilter']); // Determine whether we should show invisible nodes. $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false; $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility); $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $query = "SELECT\n count( DISTINCT ezcontentobject_tree.node_id ) as count\n FROM\n ezcontentobject_tree\n INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_name ON (\n ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n )\n {$attributeFilter['from']}\n {$extendedAttributeFilter['tables']}\n {$sqlPermissionChecking['from']}\n WHERE {$pathStringCond}\n {$extendedAttributeFilter['joins']}\n {$mainNodeOnlyCond}\n {$classCondition}\n {$attributeFilter['where']}\n ezcontentclass.version=0 AND\n {$notEqParentString}\n {$objectNameLanguageFilter}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$objectNameFilterSQL}\n {$languageFilter} "; $server = count($sqlPermissionChecking['temp_tables']) > 0 ? eZDBInterface::SERVER_SLAVE : false; $nodeListArray = $db->arrayQuery($query, array(), $server); // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); return $nodeListArray[0]['count']; }
/** * Tests a problem which arose when a combined URL entry, * representing several translations are split up, by one translation being * changed to to an earlier history entry, of that same entry. * * Note: __FUNCTION__ will be appended to every name/title attribute in order * to ensure they will be unique to this test */ function testURLAliasSplitParentTranslation() { ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', array('eng-GB', 'nor-NO')); eZContentLanguage::clearPrioritizedLanguages(); $db = eZDB::instance(); // STEP 1: Add test folder $folder = new ezpObject("folder", 2); $folder->name = __FUNCTION__; $folder->publish(); // STEP 2: Add child below folder $child = new ezpObject("folder", $folder->mainNode->node_id); $child->name = "Child" . __FUNCTION__; $child->publish(); // Sub-sub children disabled for now, might be used in future, for // further assertions. // // STEP 2a: Add a sub-sub child // $subChild1 = new ezpObject( 'article', $child->mainNode->node_id ); // $subChild1->title = "SubChild"; // $subChild1->publish(); // // // STEP 2b: Add a sub-sub child // $subChild2 = new ezpObject( 'article', $child->mainNode->node_id ); // $subChild2->title = "SubChildOther"; // $subChild2->publish(); // // // STEP 2ba: Adding sub-sub child translation // $norSubChild2Trans = array( "title" => "SubChildOtherNor" ); // $subChild2->addTranslation( "nor-NO", $norSubChild2Trans ); // // // STEP 2c: Add a sub-sub child // $subChild3 = new ezpObject( 'article', $child->mainNode->node_id ); // $subChild3->title = "SubChildThird"; // $subChild3->publish(); // // // STEP 2ca: Addubg sub-sub child translation // $norSubChild3Trans = array( "title" => "SubChildThird" ); // $subChild3->addTranslation( "nor-NO", $norSubChild3Trans ); // STEP 3: Add translation to child with the same name $translationAttributes = array("name" => "Child" . __FUNCTION__); $child->addTranslation("nor-NO", $translationAttributes); // STEP 4: Update the translation $child->refresh(); $newVersion = $child->createNewVersion(false, true, 'nor-NO'); $norDataMap = $child->fetchDataMap($newVersion->attribute('version'), "nor-NO"); $norDataMap['name']->setAttribute('data_text', 'NorChildChanged' . __FUNCTION__); $norDataMap['name']->store(); ezpObject::publishContentObject($child->object, $newVersion); // STEP 5: $child->refresh(); $child->name = "Renamed child" . __FUNCTION__; $child->publish(); // STEP 6: $child->refresh(); $child->name = "Child changed" . __FUNCTION__; $child->publish(); // STEP 7: $child->refresh(); $newVersion = $child->createNewVersion(false, true, 'nor-NO'); $norDataMap = $child->fetchDataMap($newVersion->attribute('version'), "nor-NO"); $norDataMap['name']->setAttribute('data_text', 'NorChildChanged again' . __FUNCTION__); $norDataMap['name']->store(); ezpObject::publishContentObject($child->object, $newVersion); // STEP 8: $child->refresh(); $newVersion = $child->createNewVersion(false, true, 'nor-NO'); $norDataMap = $child->fetchDataMap($newVersion->attribute('version'), "nor-NO"); $norDataMap['name']->setAttribute('data_text', 'Child changed' . __FUNCTION__); $norDataMap['name']->store(); ezpObject::publishContentObject($child->object, $newVersion); // STEP 9: $child->refresh(); $newVersion = $child->createNewVersion(false, true, 'nor-NO'); $norDataMap = $child->fetchDataMap($newVersion->attribute('version'), "nor-NO"); $norDataMap['name']->setAttribute('data_text', 'NorChildChanged again' . __FUNCTION__); $norDataMap['name']->store(); ezpObject::publishContentObject($child->object, $newVersion); $query = self::buildSql(array($child->mainNode->node_id)); $result = $db->arrayQuery($query); $initialTranslationChild = self::urlEntryForName("Child-changed" . __FUNCTION__, $result); $translationChild = self::urlEntryForName('NorChildChanged-again' . __FUNCTION__, $result); self::assertEquals((int) $initialTranslationChild['id'], (int) $translationChild['id'], "Current translations of the same node need to have the same id."); ezpINIHelper::restoreINISettings(); }
/** * Fetches latest modified tags by specified parameters * * @static * * @param int|bool $parentTagID * @param int $limit * @param mixed $language * * @return array */ public static function fetchLatestTags($parentTagID = false, $limit = 0, $language = false) { $parentTagID = (int) $parentTagID; $filterArray = array(); $filterArray['main_tag_id'] = 0; $filterArray['id'] = array('!=', $parentTagID); if ($parentTagID > 0) { $filterArray['path_string'] = array('like', '%/' . $parentTagID . '/%'); } if ($language) { if (!is_array($language)) { $language = array($language); } eZContentLanguage::setPrioritizedLanguages($language); } $result = eZTagsObject::fetchList($filterArray, array('offset' => 0, 'limit' => $limit), array('modified' => 'desc')); if ($language) { eZContentLanguage::clearPrioritizedLanguages(); } if (is_array($result) && !empty($result)) { return array('result' => $result); } return array('result' => false); }
/** * Creates and returns SQL parts used in fetch functions * * @param array $params where 'tag_id' is an array of arrays; at least one tag ID from each array must match * * @return array */ public function createAndMultipleFilterSqlParts($params) { $returnArray = array('tables' => '', 'joins' => '', 'columns' => ''); if (!isset($params['tag_id'])) { return $returnArray; } if (is_array($params['tag_id'])) { $tagIDsArray = $params['tag_id']; } else { return $returnArray; } $returnArray['tables'] = " INNER JOIN eztags_attribute_link i1 ON (i1.object_id = ezcontentobject.id AND i1.objectattribute_version = ezcontentobject.current_version)\n INNER JOIN eztags i2 ON (i1.keyword_id = i2.id)\n INNER JOIN eztags_keyword i3 ON (i2.id = i3.keyword_id)"; $dbStrings = array(); $db = eZDB::instance(); foreach ($tagIDsArray as $tagIDGroup) { $tagIDGroup = (array) $tagIDGroup; if (!isset($params['include_synonyms']) || isset($params['include_synonyms']) && (bool) $params['include_synonyms'] == true) { /** @var eZTagsObject[] $tags */ $tags = eZTagsObject::fetchList(array('main_tag_id' => array($tagIDGroup))); if (is_array($tags)) { foreach ($tags as $tag) { $tagIDGroup[] = $tag->attribute('id'); } } } $dbStrings[] = "EXISTS (\n SELECT 1\n FROM\n eztags_attribute_link j1,\n ezcontentobject j2\n WHERE " . $db->generateSQLINStatement($tagIDGroup, 'j1.keyword_id', false, true, 'int') . " AND j1.object_id = j2.id\n AND j2.id = ezcontentobject.id\n AND j1.objectattribute_version = j2.current_version\n )"; } $dbString = implode(" AND ", $dbStrings); if (isset($params['language'])) { $language = $params['language']; if (!is_array($language)) { $language = array($language); } eZContentLanguage::setPrioritizedLanguages($language); } $returnArray['joins'] = " {$dbString}\n AND " . eZContentLanguage::languagesSQLFilter('i2') . " AND " . eZContentLanguage::sqlFilter('i3', 'i2') . " AND "; if (isset($params['language'])) { eZContentLanguage::clearPrioritizedLanguages(); } return $returnArray; }
/** * Returns URL alias for the specified <var>$locale</var> * * @param string $url * @param string $locale * @return void */ public function destinationUrl() { $nodeId = $this->origUrl; $urlAlias = ''; if (!is_numeric($this->origUrl)) { if (!$this->isUrlPointingToModule($this->origUrl)) { $this->origUrl = self::addPathPrefixIfNeeded($this->origUrl); } $nodeId = eZURLAliasML::fetchNodeIDByPath($this->origUrl); } $siteLanguageList = $this->getSiteAccessIni()->variable('RegionalSettings', 'SiteLanguageList'); // set prioritized languages of destination SA, and fetch corresponding (prioritized) URL alias eZContentLanguage::setPrioritizedLanguages($siteLanguageList); $destinationElement = eZURLAliasML::fetchByAction('eznode', $nodeId, false, true); eZContentLanguage::clearPrioritizedLanguages(); if (empty($destinationElement) || !isset($destinationElement[0]) && !$destinationElement[0] instanceof eZURLAliasML) { // If the return of fetchByAction is empty, it can mean a couple // of different things: // Either we are looking at a module, and we should pass the // original URL on // // Or we are looking at URL which does not exist in the // destination siteaccess, for instance an untranslated object. In // which case we will point to the root of the site, unless it is // available as a fallback. if ($nodeId) { $urlAlias = $this->origUrl; // if applicable, remove destination PathPrefix from url if (!self::removePathPrefixIfNeeded($this->getSiteAccessIni(), $urlAlias)) { // If destination siteaccess has a PathPrefix but url is not matched, // also check current SA's prefix, and remove if it matches. self::removePathPrefixIfNeeded(eZINI::instance('site.ini'), $urlAlias); } } else { if ($this->isUrlPointingToModule($this->origUrl)) { $urlAlias = $this->origUrl; } } } else { // Translated object found, forwarding to new URL. $urlAlias = $destinationElement[0]->getPath($this->destinationLocale, $siteLanguageList); // if applicable, remove destination PathPrefix from url self::removePathPrefixIfNeeded($this->getSiteAccessIni(), $urlAlias); $urlAlias .= $this->userParamString; } $this->baseDestinationUrl = rtrim($this->baseDestinationUrl, '/'); $ini = eZINI::instance(); if ($GLOBALS['eZCurrentAccess']['type'] === eZSiteAccess::TYPE_URI && !($ini->variable('SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess') === "enabled" && $ini->variable('SiteSettings', 'DefaultAccess') == $this->destinationSiteAccess)) { $finalUrl = $this->baseDestinationUrl . '/' . $this->destinationSiteAccess . '/' . $urlAlias; } else { $finalUrl = $this->baseDestinationUrl . '/' . $urlAlias; } if ($this->queryString != '') { $finalUrl .= '?' . $this->queryString; } return $finalUrl; }
public function testChoosePrioritizedRow() { // TEST SETUP -------------------------------------------------------- $ini = eZINI::instance(); // Make sure to preserve ini settings in case other tests depend on them $orgShowUntranslatedObjects = $ini->variable('RegionalSettings', 'ShowUntranslatedObjects'); $orgSiteLanguageList = $ini->variable('RegionalSettings', 'SiteLanguageList'); // Make sure we can see all languages $ini->setVariable('RegionalSettings', 'ShowUntranslatedObjects', 'enabled'); $action = "eznode:" . mt_rand(); $name = __FUNCTION__ . mt_rand(); // Create an english entry $url1 = eZURLAliasML::create($name . " en", $action, 0, 2); $url1->store(); // Create a norwegian entry $url2 = eZURLAliasML::create($name . " no", $action, 0, 4); $url2->store(); // Fetch the created entries. choosePrioritizedRow() wants rows from the // database so our eZURLAliasML objects wont work. $db = eZDB::instance(); $rows = $db->arrayQuery("SELECT * FROM ezurlalias_ml where action = '{$action}'"); // ------------------------------------------------------------------- // TEST PART 1 - NORMAL PRIORITIZATION ------------------------------- // The order of the language array also determines the prioritization. // In this case 'eng-GB' should be prioritized before 'nor-NO'. $languageList = array("eng-GB", "nor-NO"); $ini->setVariable('RegionalSettings', 'SiteLanguageList', $languageList); eZContentLanguage::clearPrioritizedLanguages(); $row = eZURLAliasML::choosePrioritizedRow($rows); // The prioritzed language should be 'eng-GB' (lang_mask = 2) self::assertEquals(2, $row["lang_mask"]); // ------------------------------------------------------------------- // TEST PART 2 - REVERSED PRIORITIZATION ----------------------------- // Reverse the order of the specified languages, this will also // reverse the priority. $languageList = array_reverse($languageList); $ini->setVariable('RegionalSettings', 'SiteLanguageList', $languageList); eZContentLanguage::clearPrioritizedLanguages(); $row = eZURLAliasML::choosePrioritizedRow($rows); // The prioritzed language should be 'nor-NO' (lang_mask = 4) self::assertEquals(4, $row["lang_mask"]); // ------------------------------------------------------------------- // TEST TEAR DOWN ---------------------------------------------------- $ini->setVariable('RegionalSettings', 'ShowUntranslatedObjects', $orgShowUntranslatedObjects); $ini->setVariable('RegionalSettings', 'SiteLanguageList', $orgSiteLanguageList); // ------------------------------------------------------------------- }