/** * Ensures that eZURLAliasML::fetchPathByActionList() always uses prioritized languages, * even if a locale is enforced (3rd param) and always available flag is false. * * @see http://issues.ez.no/19055 * @group issue19055 * @covers eZURLAliasML::fetchPathByActionList */ public function testFetchPathByActionListWithFallback() { $frenchLocale = $this->frenchLanguage->attribute('locale'); ezpINIHelper::setINISettings(array(array('site.ini', 'RegionalSettings', 'ContentObjectLocale', $frenchLocale), array('site.ini', 'RegionalSettings', 'Locale', $frenchLocale), array('site.ini', 'RegionalSettings', 'SiteLanguageList', array($frenchLocale, 'eng-GB')), array('site.ini', 'RegionalSettings', 'ShowUntranslatedObjects', 'disabled'))); eZContentOperationCollection::updateAlwaysAvailable(1, false); /* * - Create a content object in Norsk * - Remove AlwaysAvailable flag * - Add a translation in english * - Try to fetch path for this content in French (fallback is eng-GB as configured above) */ $folder = new ezpObject('folder', 2, 14, 1, $this->norskLanguage->attribute('locale')); $folder->name = 'norsk folder'; $folder->publish(); eZContentOperationCollection::updateAlwaysAvailable($folder->object->attribute('id'), false); $folder->refresh(); $folder->addTranslation('eng-GB', array('name' => 'english translation')); $folder->publish(); $generatedPath = eZURLAliasML::fetchPathByActionList('eznode', array($folder->mainNode->node_id), $frenchLocale); self::assertNotNull($generatedPath); self::assertEquals('english-translation', $generatedPath); eZContentOperationCollection::updateAlwaysAvailable(1, true); ezpINIHelper::restoreINISettings(); $folder->remove(); }
/** * Test FetchByContentObjectList */ public function testFetchByContentObjectIDList() { $language = eZContentLanguage::fetchByLocale('eng-GB'); $languageID = $language->attribute('id'); $time = time(); $comment1 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time, 'modified' => $time, 'text' => 'comment1', 'user_id' => 15); $comment2 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time + 1, 'modified' => $time + 1, 'text' => 'comment2', 'user_id' => 15); $comment3 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time + 2, 'modified' => $time + 2, 'text' => 'comment3', 'user_id' => 15); $comment4 = array('contentobject_id' => 14, 'language_id' => $languageID, 'created' => $time + 3, 'modified' => $time + 3, 'text' => 'comment4', 'user_id' => 14); $comment = ezcomComment::create($comment1); $comment->store(); $comment = ezcomComment::create($comment2); $comment->store(); $comment = ezcomComment::create($comment3); $comment->store(); $comment = ezcomComment::create($comment4); $comment->store(); // test null contentobject id and user id $result = ezcomComment::fetchByContentObjectIDList(null, 15, 'eng-GB', null, array('modified' => 'desc'), 0); $this->assertEquals('comment3', $result[0]->attribute('text')); $this->assertEquals('comment1', $result[2]->attribute('text')); // test null contentobject id array and empty user_id $result = ezcomComment::fetchByContentObjectIDList(null, null, 'eng-GB', null, array('modified' => 'desc'), 0); $this->assertEquals('comment1', $result[3]->attribute('text')); // test one contentobject id array $result = ezcomComment::fetchByContentObjectIDList(array(14), null, 'eng-GB', null, array('modified' => 'desc'), 0); $this->assertEquals('comment4', $result[0]->attribute('text')); // test many contentobjects array and sort $result = ezcomComment::fetchByContentObjectIDList(array(14, 15), null, 'eng-GB', null, array('modified' => 'asc'), 0); $this->assertEquals('comment3', $result[2]->attribute('text')); // test length with all null $result = ezcomComment::fetchByContentObjectIDList(null, null, null, null, null, null, 3); $this->assertEquals(3, count($result)); }
public function fetchUrlAlias($nodeId = null, $path = null, $locale) { if (!$nodeId && !$path) { return array('result' => false); } if (empty($locale) || !is_string($locale)) { return array('result' => false); } if (is_numeric($nodeId)) { $destinationElement = eZURLAliasML::fetchByAction('eznode', $nodeId, $locale, false); } else { if (is_string($path)) { $nodeId = eZURLAliasML::fetchNodeIDByPath($path); $destinationElement = eZURLAliasML::fetchByAction('eznode', $nodeId, $locale, false); } } if (empty($destinationElement) || !isset($destinationElement[0]) && !$destinationElement[0] instanceof eZURLAliasML) { // Either no translation exists for $locale or $path was not pointing to a node return array('result' => false); } $currentLanguageCodes = eZContentLanguage::prioritizedLanguageCodes(); array_unshift($currentLanguageCodes, $locale); $currentLanguageCodes = array_unique($currentLanguageCodes); $urlAlias = $destinationElement[0]->getPath($locale, $currentLanguageCodes); return array('result' => $urlAlias); }
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(); }
/** * Return valid items for block with given $blockID * * @static * @param string $blockID * @param bool $asObject * @return array(eZContentObjectTreeNode) */ static function validNodes($blockID, $asObject = true) { if (isset($GLOBALS['eZFlowPool']) === false) { $GLOBALS['eZFlowPool'] = array(); } if (isset($GLOBALS['eZFlowPool'][$blockID])) { return $GLOBALS['eZFlowPool'][$blockID]; } $visibilitySQL = ""; if (eZINI::instance('site.ini')->variable('SiteAccessSettings', 'ShowHiddenNodes') !== 'true') { $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 "; } $db = eZDB::instance(); $validNodes = $db->arrayQuery("SELECT ezm_pool.node_id\n FROM ezm_pool, ezcontentobject_tree, ezcontentobject\n WHERE ezm_pool.block_id='{$blockID}'\n AND ezm_pool.ts_visible>0\n AND ezm_pool.ts_hidden=0\n AND ezcontentobject_tree.node_id = ezm_pool.node_id\n AND ezcontentobject.id = ezm_pool.object_id\n AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject') . "\n {$visibilitySQL}\n ORDER BY ezm_pool.priority DESC"); if ($asObject && !empty($validNodes)) { $validNodesObjects = array(); foreach ($validNodes as $node) { $validNodeObject = eZContentObjectTreeNode::fetch($node['node_id']); if ($validNodeObject instanceof eZContentObjectTreeNode && $validNodeObject->canRead()) { $validNodesObjects[] = $validNodeObject; } } $GLOBALS['eZFlowPool'][$blockID] = $validNodesObjects; return $validNodesObjects; } else { return $validNodes; } }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $parentNodeID = $namedParameters['parent_node_id']; switch ($operatorName) { case 'ezkeywordlist': include_once 'lib/ezdb/classes/ezdb.php'; $db = eZDB::instance(); if ($parentNodeID) { $node = eZContentObjectTreeNode::fetch($parentNodeID); if ($node) { $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'"; } $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $versionNameJoins = " AND ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND\n ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version AND "; $languageFilter = " AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); $quotedClassIdentifiers = array(); foreach ((array) $namedParameters['class_identifier'] as $classIdentifier) { $quotedClassIdentifiers[] = "'" . $db->escapeString($classIdentifier) . "'"; } $rs = $db->arrayQuery("SELECT DISTINCT ezkeyword.keyword\n FROM ezkeyword_attribute_link,\n ezkeyword,\n ezcontentobject,\n ezcontentobject_name,\n ezcontentobject_attribute,\n ezcontentobject_tree,\n ezcontentclass\n {$sqlPermissionChecking['from']}\n WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND ezcontentobject_tree.contentobject_id = ezcontentobject_attribute.contentobject_id\n AND ezkeyword.class_id = ezcontentclass.id\n AND " . $db->generateSQLINStatement($quotedClassIdentifiers, 'ezcontentclass.identifier') . "\n {$pathString}\n {$parentNodeIDSQL} " . ($namedParameters['depth'] > 0 ? "AND ezcontentobject_tree.depth=" . (int) $namedParameters['depth'] : '') . "\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n {$versionNameJoins}\n ORDER BY ezkeyword.keyword ASC"); $operatorValue = $rs; break; } }
/** * Test for regression #13497: * attribute operator throws a PHP fatal error on a node without parent in a displayable language * * Situation: * - siteaccess with one language (fre-FR) and ShowUntranslatedObjects disabled * - parent content node in another language (eng-GB) with always available disabled * - content node in the siteaccess' language (fre-FR) * - fetch this fre-FR node from anywhere, and call attribute() on it * * Result: * - Fatal error: Call to a member function attribute() on a non-object in * kernel/classes/ezcontentobjecttreenode.php on line 4225 * * Explanation: the error actually comes from the can_remove_location attribute **/ public function testIssue13497() { // Create a folder in english only $folder = new ezpObject("folder", 2, 14, 1, 'eng-GB'); $folder->setAlwaysAvailableLanguageID(false); $folder->name = "Parent for " . __FUNCTION__; $folder->publish(); $locale = eZLocale::instance('fre-FR'); $translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName()); // Create an article in french only, as a subitem of the previously created folder $article = new ezpObject("article", $folder->attribute('main_node_id'), 14, 1, 'fre-FR'); $article->title = "Object for " . __FUNCTION__; $article->short_description = "Description of test for " . __FUNCTION__; $article->publish(); $articleNodeID = $article->attribute('main_node_id'); // INi changes: set language to french only, untranslatedobjects disabled ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ContentObjectLocale', 'fre-FR'); ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', array('fre-FR')); ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ShowUntranslatedObjects', 'disabled'); eZContentLanguage::expireCache(); // This should crash eZContentObjectTreeNode::fetch($articleNodeID)->attribute('can_remove_location'); ezpINIHelper::restoreINISettings(); // re-expire cache for further tests eZContentLanguage::expireCache(); }
/** * Test that fetching the language listing, works after languages * have been altered in database, and then later refetched. * * @link http://issues.ez.no/15484 */ public function testMapLanguage() { $db = eZDB::instance(); eZContentLanguage::addLanguage('nno-NO', 'Nynorsk'); $localeToChangeInto = 'dan-DK'; $languageNameToChangeInto = 'Danish'; $langObject = eZContentLanguage::fetchByLocale('nno-NO'); $langId = (int) $langObject->attribute('id'); $updateSql = <<<END UPDATE ezcontent_language SET locale='{$localeToChangeInto}', name='{$languageNameToChangeInto}' WHERE id={$langId} END; $db->query($updateSql); eZContentLanguage::expireCache(); $newLangObject = eZContentLanguage::fetchByLocale($localeToChangeInto); if (!$newLangObject instanceof eZContentLanguage) { self::fail("Language object not returned. Old version provided by cache?"); } $newLangId = (int) $newLangObject->attribute('id'); self::assertEquals($langId, $newLangId, "New language not mapped to existing language"); }
/** * Regression test for issue {@see #19174 http://issues.ez.no/19174} */ public function testIssue19174() { $bkpLanguages = eZContentLanguage::prioritizedLanguageCodes(); // add a secondary language $locale = eZLocale::instance('fre-FR'); $translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName()); // create related objects $relatedObjectsIds = array($this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation()); $xmlTextEn = "<embed href=\"ezobject://{$relatedObjectsIds[0]}\" /><link href=\"ezobject://{$relatedObjectsIds[1]}\">link</link>"; $xmlTextFr = "<embed href=\"ezobject://{$relatedObjectsIds[2]}\" /><link href=\"ezobject://{$relatedObjectsIds[3]}\">link</link>"; // Create an article in eng-GB, and embed related object one in the intro $article = new ezpObject('article', 2, 14, 1, 'eng-GB'); $article->title = __METHOD__ . ' eng-GB'; $article->intro = $xmlTextEn; $articleId = $article->publish(); // Workaround as setting folder->name directly doesn't produce the expected result $article->addTranslation('fre-FR', array('title' => __METHOD__ . ' fre-FR', 'intro' => $xmlTextFr)); $relatedObjects = eZContentObject::fetch($articleId)->relatedObjects(false, false, 0, false, array('AllRelations' => eZContentObject::RELATION_LINK | eZContentObject::RELATION_EMBED)); self::assertEquals(4, count($relatedObjects)); $expectedRelations = array_flip($relatedObjectsIds); foreach ($relatedObjects as $relatedObject) { if (isset($expectedRelations[$relatedObject->ID])) { unset($expectedRelations[$relatedObject->ID]); } } self::assertEquals(0, count($expectedRelations)); $article->remove(); $translation->removeThis(); eZContentLanguage::setPrioritizedLanguages($bkpLanguages); }
static function sqlAppendFilter($languageTable = 'ezcontentclass') { $def = eZContentClassName::definition(); $languageListTable = $def['name']; $sqlFilter = array('nameField' => ", {$languageListTable}.name", 'from' => ", {$languageListTable}", 'where' => "AND {$languageTable}.id = {$languageListTable}.contentclass_id AND\n {$languageTable}.version = {$languageListTable}.contentclass_version AND " . eZContentLanguage::sqlFilter($languageListTable, $languageTable), 'orderBy' => "{$languageListTable}.name"); return $sqlFilter; }
/** * Code taken from content/urlalias module */ static function addUrlALias($node, $aliasText, $languageId, $aliasRedirects = false, $parentIsRoot = false) { $infoCode = 'no-errors'; $language = eZContentLanguage::fetch($languageId); if (!$language) { $infoCode = "error-invalid-language"; $infoData['language'] = $languageCode; } else { $parentID = 0; $linkID = 0; $filter = new eZURLAliasQuery(); $filter->actions = array('eznode:' . $node->attribute('node_id')); $filter->type = 'name'; $filter->limit = false; $existingElements = $filter->fetchAll(); // TODO: add error handling when $existingElements is empty if (count($existingElements) > 0) { $parentID = (int) $existingElements[0]->attribute('parent'); $linkID = (int) $existingElements[0]->attribute('id'); } if ($parentIsRoot) { $parentID = 0; // Start from the top } $mask = $language->attribute('id'); $obj = $node->object(); $alwaysMask = $obj->attribute('language_mask') & 1; $mask |= $alwaysMask; $origAliasText = $aliasText; $result = eZURLAliasML::storePath($aliasText, 'eznode:' . $node->attribute('node_id'), $language, $linkID, $alwaysMask, $parentID, true, false, false, $aliasRedirects); if ($result['status'] === eZURLAliasML::LINK_ALREADY_TAKEN) { $lastElements = eZURLAliasML::fetchByPath($result['path']); if (count($lastElements) > 0) { $lastElement = $lastElements[0]; $infoCode = "feedback-alias-exists"; $infoData['new_alias'] = $aliasText; $infoData['url'] = $lastElement->attribute('path'); $infoData['action_url'] = $lastElement->actionURL(); //$aliasText = $origAliasText; } } else { if ($result['status'] === true) { $aliasText = $result['path']; if (strcmp($aliasText, $origAliasText) != 0) { $infoCode = "feedback-alias-cleanup"; $infoData['orig_alias'] = $origAliasText; $infoData['new_alias'] = $aliasText; } else { $infoData['new_alias'] = $aliasText; } if ($infoCode == 'no-errors') { $infoCode = "feedback-alias-created"; } //$aliasText = false; } } } return array('infoCode' => $infoCode, 'infoData' => $infoData); }
public function tearDown() { $this->folder->remove(); $this->article->remove(); eZPendingActions::removeByAction('index_object'); $this->nodeIds = array(); $this->objectIds = array(); $anonymousUser = eZUser::fetchByName('anonymous'); eZUser::setCurrentlyLoggedInUser($anonymousUser, $anonymousUser->attribute('contentobject_id')); eZContentLanguage::expireCache(); parent::tearDown(); }
/** * Regression test for issue #18613 : * Empty ezcontentlanguage_cache.php not being regenerated. * This cache file should always exist, but if for some reason it's empty (lost sync with cluster for instance), * it should be at least properly regenerated * * @link http://issues.ez.no/18613 * @group issue18613 */ public function testFetchListWithBlankCacheFile() { // First simulate a problem generating the language cache file (make it blank) $cachePath = eZSys::cacheDirectory() . '/ezcontentlanguage_cache.php'; $clusterFileHandler = eZClusterFileHandler::instance($cachePath); $clusterFileHandler->storeContents('', 'content', 'php'); unset($GLOBALS['eZContentLanguageList']); // Language list should never be empty self::assertNotEmpty(eZContentLanguage::fetchList()); // Remove the test language cache file $clusterFileHandler->delete(); $clusterFileHandler->purge(); }
function createSqlParts($params) { $sqlJoins = ''; if (isset($params['locales'])) { $language_mask = 0; $locales = eZContentLanguage::fetchList(); foreach ($locales as $locale) { if (in_array($locale->attribute('locale'), $params['locales'])) { $language_mask |= $locale->attribute('id'); } } if ($language_mask) { $sqlJoins = " ezcontentobject.language_mask & {$language_mask} AND "; } } return array('tables' => '', 'joins' => $sqlJoins, 'columns' => ''); }
function attribute($attr) { switch ($attr) { case 'sections': $sections = eZSection::fetchList(false); foreach ($sections as $key => $section) { $sections[$key]['Name'] = $section['name']; $sections[$key]['value'] = $section['id']; } return $sections; break; case 'languages': return eZContentLanguage::fetchList(); break; } return eZWorkflowEventType::attribute($attr); }
function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters) { $ret = ''; switch ($operatorName) { case 'get_url_alias_by_lang': $node = eZContentObjectTreeNode::fetch($namedParameters['node_id'], $namedParameters['lang_code']); $originalPrioritizedLanguages = eZContentLanguage::prioritizedLanguageCodes(); eZContentLanguage::setPrioritizedLanguages(array($namedParameters['lang_code'])); $urlAlias = ''; if (is_object($node)) { $urlAlias = '/' . $node->urlAlias(); } eZContentLanguage::setPrioritizedLanguages($originalPrioritizedLanguages); $ret = $urlAlias; break; } $operatorValue = $ret; }
public function __construct($theClass = '', $name = '') { parent::__construct($theClass, $name); if (!self::$script instanceof eZScript) { self::$script = eZScript::instance(array('description' => "eZ Publish Test Runner\n\nsets up an eZ Publish testing environment\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true)); // Override INI override folder from settings/override to // tests/settings to not read local override settings $ini = eZINI::instance(); $ini->setOverrideDirs(array(array('tests/settings', true)), 'override'); $ini->loadCache(); // Be sure to have clean content language data eZContentLanguage::expireCache(); self::$script->startup(); self::$script->initialize(); // Avoids Fatal error: eZ Publish did not finish its request if die() is used. eZExecution::setCleanExit(); } }
public function execute($process, $event) { $processParameters = $process->attribute('parameter_list'); $object = eZContentObject::fetch($processParameters['object_id']); $node = $object->mainNode(); $href = '/push/node/' . $node->attribute('node_id'); $version = eZContentObjectVersion::fetchVersion($processParameters['version'], $processParameters['object_id']); if ($version instanceof eZContentObjectVersion) { $language = eZContentLanguage::fetch($version->attribute('initial_language_id')); if ($language instanceof eZContentLanguage) { $href .= '/' . $language->attribute('locale'); } } eZURI::transformURI($href, false, 'full'); $http = eZHTTPTool::instance(); $http->setSessionVariable('RedirectURIAfterPublish', $href); return eZWorkflowType::STATUS_ACCEPTED; }
/** * Initialize ezpClass object * * @param string $name * @param string $identifier * @param string $contentObjectName * @param int $creatorID * @param string $language * @param int $groupID * @param string $groupName */ public function __construct($name = 'Test class', $identifier = 'test_class', $contentObjectName = '<test_attribute>', $creatorID = 14, $language = 'eng-GB', $groupID = 1, $groupName = 'Content') { if (eZContentLanguage::fetchByLocale($language) === false) { $topPriorityLanguage = eZContentLanguage::topPriorityLanguage(); if ($topPriorityLanguage) { $language = $topPriorityLanguage->attribute('locale'); } } $this->language = $language; $this->class = eZContentClass::create($creatorID, array(), $this->language); $this->class->setName($name, $this->language); $this->class->setAttribute('contentobject_name', $contentObjectName); $this->class->setAttribute('identifier', $identifier); $this->class->store(); $languageID = eZContentLanguage::idByLocale($this->language); $this->class->setAlwaysAvailableLanguageID($languageID); $this->classGroup = eZContentClassClassGroup::create($this->id, $this->version, $groupID, $groupName); $this->classGroup->store(); }
/** * Parses the XML for the attributes in $classAttributeIdentifiers, and fixes the relations for $object * @param eZContentObject $object * @param array $classAttributeIdentifiers * @return int The number of created relations */ function restoreXmlRelations(eZContentObject $object, array $classAttributeIdentifiers) { $currentVersion = $object->currentVersion(); $langMask = $currentVersion->attribute('language_mask'); $languageList = eZContentLanguage::decodeLanguageMask($langMask, true); $languageList = $languageList['language_list']; // nothing to do if the object isn't translated if (count($languageList) < 2) { return 0; } $attributeArray = $object->fetchAttributesByIdentifier($classAttributeIdentifiers, $currentVersion->attribute('version'), $languageList); $embedRelationsCount = $object->relatedContentObjectCount(false, 0, array('AllRelations' => eZContentObject::RELATION_EMBED)); $linkRelationsCount = $object->relatedContentObjectCount(false, 0, array('AllRelations' => eZContentObject::RELATION_LINK)); $embeddedObjectIdArray = $linkedObjectIdArray = array(); foreach ($attributeArray as $attribute) { $xmlText = eZXMLTextType::rawXMLText($attribute); $dom = new DOMDocument('1.0', 'utf-8'); if (!$dom->loadXML($xmlText)) { continue; } // linked objects $linkedObjectIdArray = array_merge($linkedObjectIdArray, getRelatedObjectList($dom->getElementsByTagName('link'))); // embedded objects $embeddedObjectIdArray = array_merge($embeddedObjectIdArray, getRelatedObjectList($dom->getElementsByTagName('embed')), getRelatedObjectList($dom->getElementsByTagName('embed-inline'))); } $doCommit = false; $restoredRelations = 0; if (!empty($embeddedObjectIdArray)) { $object->appendInputRelationList($embeddedObjectIdArray, eZContentObject::RELATION_EMBED); $restoredRelations += count($embeddedObjectIdArray) - $embedRelationsCount; $doCommit = true; } if (!empty($linkedObjectIdArray)) { $object->appendInputRelationList($linkedObjectIdArray, eZContentObject::RELATION_LINK); $restoredRelations += count($linkedObjectIdArray) - $linkRelationsCount; $doCommit = true; } if ($doCommit) { $object->commitInputRelations($currentVersion->attribute('version')); } return $restoredRelations; }
public static function checkContentRequirements($module, $http) { // Check that the object params are 'ok' if (!$http->hasPostVariable('ContentObjectID')) { eZDebug::writeError('No content object id is provided', 'ezcomments'); return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $contentObjectId = (int) $http->postVariable('ContentObjectID'); // Either use provided language code, or fallback on siteaccess default if ($http->hasPostVariable('CommentLanguageCode')) { $languageCode = $http->postVariable('CommentLanguageCode'); $language = eZContentLanguage::fetchByLocale($languageCode); if ($language === false) { eZDebug::writeError("The language code [{$languageCode}] given is not valid in the system.", 'ezcomments'); return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } } else { $defaultLanguage = eZContentLanguage::topPriorityLanguage(); $languageCode = $defaultLanguage->attribute('locale'); } // Check that our object is actually a valid holder of comments $contentObject = eZContentObject::fetch($contentObjectId); if (!$contentObject instanceof eZContentObject) { eZDebug::writeError('No content object exists for the given id.', 'ezcomments'); return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $dataMap = $contentObject->fetchDataMap(false, $languageCode); $foundCommentAttribute = false; foreach ($dataMap as $attr) { if ($attr->attribute('data_type_string') === 'ezcomcomments') { $foundCommentAttribute = $attr; break; } } // if there is no ezcomcomments attribute inside the content, return if (!$foundCommentAttribute) { eZDebug::writeError("Content object with id [{$contentObjectId}], does not contain an ezcomments attribute.", 'ezcomments'); return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } return compact('contentObjectId', 'languageCode', 'contentObject', 'foundCommentAttribute'); }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $parentNodeID = $namedParameters['parent_node_id']; switch ($operatorName) { case 'ezkeywordlist': include_once 'lib/ezdb/classes/ezdb.php'; $db = eZDB::instance(); if ($parentNodeID) { $node = eZContentObjectTreeNode::fetch($parentNodeID); if ($node) { $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'"; } $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID; } $limitation = false; $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL(eZContentObjectTreeNode::getLimitationList($limitation)); // eZContentObjectTreeNode::classIDByIdentifier() might need to be used for eZ Publish < 4.1 $classIDs = eZContentClass::classIDByIdentifier($namedParameters['class_identifier']); $operatorValue = $db->arrayQuery("SELECT DISTINCT ezkeyword.keyword\n FROM ezkeyword\n JOIN ezkeyword_attribute_link ON ezkeyword.id = ezkeyword_attribute_link.keyword_id\n JOIN ezcontentobject_attribute ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n JOIN ezcontentobject ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id\n JOIN ezcontentobject_name ON ezcontentobject.id = ezcontentobject_name.contentobject_id\n JOIN ezcontentobject_tree ON ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n {$sqlPermissionChecking['from']}\n WHERE " . eZContentLanguage::languagesSQLFilter('ezcontentobject') . "\n AND " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . (empty($classIDs) ? '' : ' AND ' . $db->generateSQLINStatement($classIDs, 'ezkeyword.class_id')) . "\n {$pathString}\n {$parentNodeIDSQL} " . ($namedParameters['depth'] > 0 ? "AND ezcontentobject_tree.depth=" . (int) $namedParameters['depth'] : '') . "\n " . eZContentObjectTreeNode::createShowInvisibleSQLString(true, false) . "\n {$sqlPermissionChecking['where']}\n ORDER BY ezkeyword.keyword ASC"); break; } }
function checkPermission($comment) { // check permission $contentObject = $comment->contentObject(); $contentNode = $contentObject->mainNode(); $languageID = $comment->attribute('language_id'); $languageCode = eZContentLanguage::fetch($languageID)->attribute('locale'); $canDeleteResult = ezcomPermission::hasAccessToFunction('delete', $contentObject, $languageCode, $comment, null, $contentNode); $objectAttributes = $contentObject->fetchDataMap(false, $languageCode); $objectAttribute = null; foreach ($objectAttributes as $attribute) { if ($attribute->attribute('data_type_string') === 'ezcomcomments') { $objectAttribute = $attribute; break; } } $commentContent = $objectAttribute->content(); if (!$canDeleteResult['result'] || !$commentContent['show_comments']) { return ezpI18n::tr('ezcomments/comment/delete', 'You don\'t have' . ' access to delete comment' . ' or the comment is hidden!'); } else { return true; } }
function setParameters($parm_array) { if (!isset($parm_array['remove_locale'])) { return 'Missing locale identifier to be removed'; } if (!isset($parm_array['alternative_locale'])) { return 'Missing alternative locale identifier'; } $this->remLocale = $parm_array['remove_locale']; $language = eZContentLanguage::fetchByLocale($this->remLocale); if ($language) { $this->remLangID = $language->attribute('id'); } else { return 'Missing locale to be removed in database'; } $this->altLocale = $parm_array['alternative_locale']; $language = eZContentLanguage::fetchByLocale($this->altLocale); if ($language) { $this->altLangID = $language->attribute('id'); } else { return 'Missing alternative locale in database'; } return true; }
function setParameters($parm_array) { if (!isset($parm_array['original_locale'])) { return 'Missing locale identifier of original'; } if (!isset($parm_array['new_locale'])) { return 'Missing new locale identifier'; } $this->orgLocale = $parm_array['original_locale']; $language = eZContentLanguage::fetchByLocale($this->orgLocale); if ($language) { $this->orgLangID = $language->attribute('id'); } else { return 'Missing original locale to be copied in database'; } $this->newLocale = $parm_array['new_locale']; $language = eZContentLanguage::fetchByLocale($this->newLocale); if ($language) { $this->newLangID = $language->attribute('id'); } else { return 'Missing alternative locale in database'; } return true; }
/** * Regression test for issue {@see #17632 http://issues.ez.no/17632} * * In a multi language environment, a node fetched with a language other than the prioritized one(s) will return the * URL alias in the prioritized language */ public function testIssue17632() { $bkpLanguages = eZContentLanguage::prioritizedLanguageCodes(); $strNameEngGB = __FUNCTION__ . " eng-GB"; $strNameFreFR = __FUNCTION__ . " fre-FR"; // add a secondary language $locale = eZLocale::instance( 'fre-FR' ); $translation = eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() ); // set the prioritize language list to contain english // ezpINIHelper::setINISetting( 'site.ini', 'RegionalSettings', 'SiteLanguageList', array( 'fre-FR' ) ); eZContentLanguage::setPrioritizedLanguages( array( 'fre-FR' ) ); // Create an object with data in fre-FR and eng-GB $folder = new ezpObject( 'folder', 2, 14, 1, 'eng-GB' ); $folder->publish(); // Workaround as setting folder->name directly doesn't produce the expected result $folder->addTranslation( 'eng-GB', array( 'name' => $strNameEngGB ) ); $folder->addTranslation( 'fre-FR', array( 'name' => $strNameFreFR ) ); $nodeId = $folder->main_node_id; // fetch the node with no default parameters. Should return the french URL Alias $node = eZContentObjectTreeNode::fetch( $nodeId ); self::assertEquals( 'testIssue17632-fre-FR' , $node->attribute( 'url_alias' ) ); // fetch the node in english. Should return the english URL Alias $node = eZContentObjectTreeNode::fetch( $nodeId, 'eng-GB' ); self::assertEquals( 'testIssue17632-eng-GB' , $node->attribute( 'url_alias' ) ); ezpINIHelper::restoreINISettings(); eZContentLanguage::setPrioritizedLanguages( $bkpLanguages ); }
private static function languageScore($mask) { $prioritizedLanguages = eZContentLanguage::prioritizedLanguages(); $scores = array(); $score = 1; $mask = (int) $mask; krsort($prioritizedLanguages); foreach ($prioritizedLanguages as $prioritizedLanguage) { $id = (int) $prioritizedLanguage->attribute('id'); if ($id & $mask) { $scores[] = $score; } ++$score; } if (count($scores) > 0) { return max($scores); } else { return 0; } }
$limit = 25; $filter->prepare(); // Reset SQLs from previous calls $filter->actions = array('eznode:' . $node->attribute('node_id')); $filter->type = 'alias'; $filter->offset = $Offset; $filter->limit = $limit; $count = $filter->count(); $aliasList = $filter->fetchAll(); $path = array(); $nodePath = $node->attribute('path'); foreach ($nodePath as $pathEntry) { $url = $pathEntry->attribute('url_alias'); if (strlen($url) == 0) { $url = 'content/view/full/' . $pathEntry->attribute('node_id'); } $path[] = array('url' => $url, 'text' => $pathEntry->attribute('name')); } $path[] = array('url' => false, 'text' => $node->attribute('name')); $languages = eZContentLanguage::prioritizedLanguages(); $tpl->setVariable('node', $node); $tpl->setVariable('filter', $filter); $tpl->setVariable('elements', $elements); $tpl->setVariable('languages', $languages); $tpl->setVariable('info_code', $infoCode); $tpl->setVariable('info_data', $infoData); $tpl->setVariable('aliasText', $aliasText); $tpl->setVariable('view_parameters', $viewParameters); $Result = array(); $Result['content'] = $tpl->fetch('design:content/urlalias.tpl'); $Result['path'] = $path;
/** * Updates an contentobject's initial language * * @param int $objectID * @param int $newInitialLanguageID * * @return array An array with operation status, always true */ public static function updateInitialLanguage($objectID, $newInitialLanguageID) { $object = eZContentObject::fetch($objectID); $language = eZContentLanguage::fetch($newInitialLanguageID); if ($language and !$language->attribute('disabled')) { $object->setAttribute('initial_language_id', $newInitialLanguageID); $objectName = $object->name(false, $language->attribute('locale')); $object->setAttribute('name', $objectName); $object->store(); if ($object->isAlwaysAvailable()) { $object->setAlwaysAvailableLanguageID($newInitialLanguageID); } $nodes = $object->assignedNodes(); foreach ($nodes as $node) { $node->updateSubTreePath(); } } eZContentCacheManager::clearContentCacheIfNeeded($objectID); return array('status' => true); }
return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' ); } } else { return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' ); } $obj->cleanupInternalDrafts(); } else { // No version so we investigate further. $obj->cleanupInternalDrafts(); // Check number of languages $languages = eZContentLanguage::fetchList(); // If there is only one language we choose it for the user and goes to version choice screen. if ( count( $languages ) == 1 ) { $firstLanguage = array_shift( $languages ); return $Module->redirectToView( 'edit', array( $ObjectID, 'f', $firstLanguage->attribute( 'locale' ) ) ); } $canCreateLanguageList = $obj->attribute( 'can_create_languages' ); $canEditLanguageList = $obj->attribute( 'can_edit_languages' ); if ( count( $canCreateLanguageList ) == 0 && count( $canEditLanguageList ) == 1 ) { $firstLanguage = array_shift( $canEditLanguageList ); return $Module->redirectToView( 'edit', array( $ObjectID, 'f', $firstLanguage->attribute( 'locale' ) ) ); }