public static function fetchByAction($actionName, $actionValue, $maskLanguages = false, $onlyPrioritized = false, $includeRedirections = false) { $action = $actionName . ":" . $actionValue; $db = eZDB::instance(); $actionStr = $db->escapeString($action); $langMask = ''; if ($maskLanguages === true) { $langMask = "(" . trim(eZContentLanguage::languagesSQLFilter('ezurlalias_ml', 'lang_mask')) . ") AND "; } else { if (is_string($maskLanguages) || is_array($maskLanguages)) { // maskByLocale can support array input, here we only want one item. $mask = eZContentLanguage::maskByLocale((array) $maskLanguages); $langFilter = $db->bitAnd('lang_mask', $mask); $langMask = "({$langFilter} > 0) AND"; } } $query = "SELECT * FROM ezurlalias_ml WHERE {$langMask} action = '{$actionStr}'"; if (!$includeRedirections) { $query .= " AND is_original = 1 AND is_alias = 0"; } $rows = $db->arrayQuery($query); if (count($rows) == 0) { return array(); } $rows = eZURLAliasML::filterRows($rows, $onlyPrioritized); $objectList = eZPersistentObject::handleRows($rows, 'eZURLAliasML', true); return $objectList; }
public static function setObjectStatusPublished($objectID, $versionNum) { $object = eZContentObject::fetch($objectID); $version = $object->version($versionNum); $db = eZDB::instance(); $db->begin(); $object->publishContentObjectRelations($versionNum); $object->setAttribute('status', eZContentObject::STATUS_PUBLISHED); $version->setAttribute('status', eZContentObjectVersion::STATUS_PUBLISHED); $object->setAttribute('current_version', $versionNum); $objectIsAlwaysAvailable = $object->isAlwaysAvailable(); $object->setAttribute('language_mask', eZContentLanguage::maskByLocale($version->translationList(false, false), $objectIsAlwaysAvailable)); if ($object->attribute('published') == 0) { $object->setAttribute('published', time()); } $object->setAttribute('modified', time()); $classID = $object->attribute('contentclass_id'); $class = eZContentClass::fetch($classID); $objectName = $class->contentObjectName($object); $object->setName($objectName, $versionNum); $existingTranslations = $version->translations(false); foreach ($existingTranslations as $translation) { $translatedName = $class->contentObjectName($object, $versionNum, $translation); $object->setName($translatedName, $versionNum, $translation); } if ($objectIsAlwaysAvailable) { $initialLanguageID = $object->attribute('initial_language_id'); $object->setAlwaysAvailableLanguageID($initialLanguageID); } $version->store(); $object->store(); eZContentObjectTreeNode::setVersionByObjectID($objectID, $versionNum); $nodes = $object->assignedNodes(); foreach ($nodes as $node) { $node->setName($object->attribute('name')); $node->updateSubTreePath(); } $db->commit(); /* Check if current class is the user class, and if so, clean up the user-policy cache */ if (in_array($classID, eZUser::contentClassIDs())) { eZUser::purgeUserCacheByUserId($object->attribute('id')); } }
function checkAccess($functionName, $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false) { $classID = $originalClassID; $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); // Fetch the ID of the language if we get a string with a language code // e.g. 'eng-GB' $originalLanguage = $language; if (is_string($language) && strlen($language) > 0) { $language = eZContentLanguage::idByLocale($language); } else { $language = false; } // This will be filled in with the available languages of the object // if a Language check is performed. $languageList = false; // This will be filled if parent object is needed. $parentObject = false; $origFunctionName = $functionName; // The 'move' function simply reuses 'edit' for generic access // but adds another top-level check below // The original function is still available in $origFunctionName if ($functionName == 'move') { $functionName = 'edit'; } // Manage locations depends if it's removal or not. if ($functionName == 'can_add_location' || $functionName == 'can_remove_location') { $functionName = 'manage_locations'; } $accessResult = $user->hasAccessTo('content', $functionName); $accessWord = $accessResult['accessWord']; if ($origFunctionName == 'can_remove_location') { if ($this->ParentNodeID <= 1) { return 0; } $currentNode = eZContentObjectTreeNode::fetch($this->ParentNodeID); if (!$currentNode instanceof eZContentObjectTreeNode) { return 0; } $contentObject = $currentNode->attribute('object'); } else { $currentNode = $this; $contentObject = $this->attribute('object'); } /* // Uncomment this part if 'create' permissions should become implied 'edit'. // Merges in 'create' policies with 'edit' if ( $functionName == 'edit' && !in_array( $accessWord, array( 'yes', 'no' ) ) ) { // Add in create policies. $accessExtraResult = $user->hasAccessTo( 'content', 'create' ); if ( $accessExtraResult['accessWord'] != 'no' ) { $accessWord = $accessExtraResult['accessWord']; if ( isset( $accessExtraResult['policies'] ) ) { $accessResult['policies'] = array_merge( $accessResult['policies'], $accessExtraResult['policies'] ); } if ( isset( $accessExtraResult['accessList'] ) ) { $accessResult['accessList'] = array_merge( $accessResult['accessList'], $accessExtraResult['accessList'] ); } } } */ if ($origFunctionName == 'remove' or $origFunctionName == 'move' or $origFunctionName == 'can_remove_location') { // We do not allow these actions on top-level nodes // - remove // - move if ($this->ParentNodeID <= 1) { return 0; } } if ($classID === false) { $classID = $contentObject->attribute('contentclass_id'); } if ($accessWord == 'yes') { return 1; } else { if ($accessWord == 'no') { if ($functionName == 'edit') { // Check if we have 'create' access under the main parent $object = $currentNode->object(); if ($object && $object->attribute('current_version') == 1 && !$object->attribute('status')) { $mainNode = eZNodeAssignment::fetchForObject($object->attribute('id'), $object->attribute('current_version')); $parentObj = $mainNode[0]->attribute('parent_contentobject'); if ($parentObj instanceof eZContentObject) { $result = $parentObj->checkAccess('create', $object->attribute('contentclass_id'), $parentObj->attribute('contentclass_id'), false, $originalLanguage); return $result; } else { eZDebug::writeError("Error retrieving parent object of main node for object id: " . $object->attribute('id'), __METHOD__); } } } return 0; } else { $policies = $accessResult['policies']; $access = 'denied'; foreach ($policies as $pkey => $limitationArray) { if ($access == 'allowed') { break; } $limitationList = array(); if (isset($limitationArray['Subtree'])) { $checkedSubtree = false; } else { $checkedSubtree = true; $accessSubtree = false; } if (isset($limitationArray['Node'])) { $checkedNode = false; } else { $checkedNode = true; $accessNode = false; } foreach ($limitationArray as $key => $valueList) { $access = 'denied'; switch ($key) { case 'Class': if ($functionName == 'create' and !$originalClassID) { $access = 'allowed'; } else { if ($functionName == 'create' and in_array($classID, $valueList)) { $access = 'allowed'; } else { if ($functionName != 'create' and in_array($contentObject->attribute('contentclass_id'), $valueList)) { $access = 'allowed'; } else { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } } } break; case 'ParentClass': if (in_array($contentObject->attribute('contentclass_id'), $valueList)) { $access = 'allowed'; } else { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } break; case 'Section': case 'User_Section': if (in_array($contentObject->attribute('section_id'), $valueList)) { $access = 'allowed'; } else { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } break; case 'Language': $languageMask = 0; // If we don't have a language list yet we need to fetch it // and optionally filter out based on $language. if ($functionName == 'create') { // If the function is 'create' we do not use the language_mask for matching. if ($language !== false) { $languageMask = $language; } else { // If the create is used and no language specified then // we need to match against all possible languages (which // is all bits set, ie. -1). $languageMask = -1; } } else { if ($language !== false) { if ($languageList === false) { $languageMask = $contentObject->attribute('language_mask'); // We are restricting language check to just one language $languageMask &= $language; // If the resulting mask is 0 it means that the user is trying to // edit a language which does not exist, ie. translating. // The mask will then become the language trying to edit. if ($languageMask == 0) { $languageMask = $language; } } } else { $languageMask = -1; } } // Fetch limit mask for limitation list $limitMask = eZContentLanguage::maskByLocale($valueList); if (($languageMask & $limitMask) != 0) { $access = 'allowed'; } else { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } break; case 'Owner': case 'ParentOwner': // if limitation value == 2, anonymous limited to current session. if (in_array(2, $valueList) && $user->isAnonymous()) { $createdObjectIDList = eZPreferences::value('ObjectCreationIDList'); if ($createdObjectIDList && in_array($contentObject->attribute('id'), unserialize($createdObjectIDList))) { $access = 'allowed'; } } else { if ($contentObject->attribute('owner_id') == $userID || $contentObject->attribute('id') == $userID) { $access = 'allowed'; } } if ($access != 'allowed') { $access = 'denied'; $limitationList = array('Limitation' => $key); } break; case 'Group': case 'ParentGroup': $access = $contentObject->checkGroupLimitationAccess($valueList, $userID); if ($access != 'allowed') { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } break; case 'State': if (count(array_intersect($valueList, $contentObject->attribute('state_id_array'))) == 0) { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } else { $access = 'allowed'; } break; case 'ParentDepth': if (in_array($currentNode->attribute('depth'), $valueList)) { $access = 'allowed'; } else { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } break; case 'Node': $accessNode = false; $mainNodeID = $currentNode->attribute('main_node_id'); foreach ($valueList as $nodeID) { $node = eZContentObjectTreeNode::fetch($nodeID, false, false); $limitationNodeID = $node['main_node_id']; if ($mainNodeID == $limitationNodeID) { $access = 'allowed'; $accessNode = true; break; } } if ($access != 'allowed' && $checkedSubtree && !$accessSubtree) { $access = 'denied'; // ??? TODO: if there is a limitation on Subtree, return two limitations? $limitationList = array('Limitation' => $key, 'Required' => $valueList); } else { $access = 'allowed'; } $checkedNode = true; break; case 'Subtree': $accessSubtree = false; $path = $currentNode->attribute('path_string'); $subtreeArray = $valueList; foreach ($subtreeArray as $subtreeString) { if (strstr($path, $subtreeString)) { $access = 'allowed'; $accessSubtree = true; break; } } if ($access != 'allowed' && $checkedNode && !$accessNode) { $access = 'denied'; // ??? TODO: if there is a limitation on Node, return two limitations? $limitationList = array('Limitation' => $key, 'Required' => $valueList); } else { $access = 'allowed'; } $checkedSubtree = true; break; case 'User_Subtree': $path = $currentNode->attribute('path_string'); $subtreeArray = $valueList; foreach ($subtreeArray as $subtreeString) { if (strstr($path, $subtreeString)) { $access = 'allowed'; } } if ($access != 'allowed') { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } break; default: if (strncmp($key, 'StateGroup_', 11) === 0) { if (count(array_intersect($valueList, $contentObject->attribute('state_id_array'))) == 0) { $access = 'denied'; $limitationList = array('Limitation' => $key, 'Required' => $valueList); } else { $access = 'allowed'; } } } if ($access == 'denied') { break; } } $policyList[] = array('PolicyID' => $pkey, 'LimitationList' => $limitationList); } if ($access == 'denied') { $accessList = array('FunctionRequired' => array('Module' => 'content', 'Function' => $origFunctionName, 'ClassID' => $classID, 'MainNodeID' => $currentNode->attribute('main_node_id')), 'PolicyList' => $policyList); return 0; } else { return 1; } } } }
function updateLanguageMask( $mask = false, $forceStore = true ) { if ( $mask == false ) { $mask = eZContentLanguage::maskByLocale( $this->translationList( false, false ), true ); } $this->setAttribute( 'language_mask', $mask ); if ( $forceStore ) { $this->store(); } }
if (!$language instanceof eZContentLanguage) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } $error = ''; if ($http->hasPostVariable('SaveButton')) { $newKeyword = trim($http->postVariable('TagEditKeyword', '')); if (empty($newKeyword)) { $error = ezpI18n::tr('extension/eztags/errors', 'Name cannot be empty.'); } if (empty($error) && eZTagsObject::exists(0, $newKeyword, $parentTag instanceof eZTagsObject ? $parentTag->attribute('id') : 0)) { $error = ezpI18n::tr('extension/eztags/errors', 'Tag/synonym with that translation already exists in selected location.'); } if (empty($error)) { $db = eZDB::instance(); $db->begin(); $languageMask = eZContentLanguage::maskByLocale(array($language->attribute('locale')), $http->hasPostVariable('AlwaysAvailable')); $tag = new eZTagsObject(array('parent_id' => $parentTagID, 'main_tag_id' => 0, 'depth' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('depth') + 1 : 1, 'path_string' => $parentTag instanceof eZTagsObject ? $parentTag->attribute('path_string') : '/', 'main_language_id' => $language->attribute('id'), 'language_mask' => $languageMask), $language->attribute('locale')); $tag->store(); $translation = new eZTagsKeyword(array('keyword_id' => $tag->attribute('id'), 'language_id' => $language->attribute('id'), 'keyword' => $newKeyword, 'locale' => $language->attribute('locale'), 'status' => eZTagsKeyword::STATUS_PUBLISHED)); if ($http->hasPostVariable('AlwaysAvailable')) { $translation->setAttribute('language_id', $translation->attribute('language_id') + 1); } $translation->store(); $tag->setAttribute('path_string', $tag->attribute('path_string') . $tag->attribute('id') . '/'); $tag->store(); $tag->updateModified(); /* Extended Hook */ if (class_exists('ezpEvent', false)) { ezpEvent::getInstance()->filter('tag/add', array('tag' => $tag, 'parentTag' => $parentTag)); } $db->commit();
/** * Updates language mask of the tag based on current translations or provided language mask * * @param mixed $mask */ public function updateLanguageMask($mask = false) { if ($mask === false) { $locales = array(); foreach ($this->getTranslations() as $translation) { $locales[] = $translation->attribute('locale'); } $mask = eZContentLanguage::maskByLocale($locales, $this->isAlwaysAvailable()); } $this->setAttribute('language_mask', $mask); $this->store(); }