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);
 }
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case 'ngurl':
             if (empty($namedParameters['siteaccess'])) {
                 return;
             }
             $ini = eZSiteAccess::getIni($namedParameters['siteaccess'], 'site.ini');
             $destinationLocale = $ini->variable('RegionalSettings', 'ContentObjectLocale');
             $siteLanguageList = $ini->variable('RegionalSettings', 'SiteLanguageList');
             $nodeID = eZURLAliasML::fetchNodeIDByPath($operatorValue);
             $destinationElement = eZURLAliasML::fetchByAction('eznode', $nodeID, $destinationLocale, false);
             if (empty($destinationElement) || !isset($destinationElement[0]) && !$destinationElement[0] instanceof eZURLAliasML) {
                 if ($this->isModuleUrl($operatorValue) || $this->isCurrentLocaleAvailable($siteLanguageList)) {
                     $destinationUrl = $operatorValue;
                 } else {
                     $destinationUrl = '';
                 }
             } else {
                 $destinationUrl = $destinationElement[0]->getPath($destinationLocale, $siteLanguageList);
             }
             $siteaccessUrlMapping = eZINI::instance('nglanguageswitcher.ini')->variable('LanguageSwitcher', 'SiteAccessUrlMapping');
             $destinationUrl = eZURI::encodeURL($destinationUrl);
             $operatorValue = rtrim($siteaccessUrlMapping[$namedParameters['siteaccess']], '/') . '/' . ltrim($destinationUrl, '/');
             break;
     }
 }
 function runOperation(&$node)
 {
     $target_parent_node_id = $this->target_id;
     if (empty($target_parent_node_id)) {
         if ($this->move_to_depth >= $node->attribute('depth')) {
             return false;
         }
         // Find the correct target node for the specified depth
         $path_array = $node->attribute('path_array');
         $target_parent_node_id = $path_array[$this->move_to_depth - 1];
     }
     $assigned_nodes = $node->attribute('object')->attribute('assigned_nodes');
     // Find the target node
     foreach ($assigned_nodes as $target_node) {
         if ($target_node->attribute('parent_node_id') == $target_parent_node_id) {
             $target_node_id = $target_node->attribute('node_id');
             // Make sure target node is not us
             if ($node->attribute('node_id') == $target_node_id) {
                 return false;
             }
             $urlalias_list = eZURLAliasML::fetchByAction('eznode', $node->attribute('node_id'));
             $target_node_urlalias_list = eZURLAliasML::fetchByAction('eznode', $target_node_id);
             // Sanity check, this should never happen
             if (!isset($target_node_urlalias_list[0])) {
                 eZDebug::writeError('Found no url alias records for node with id ' . $target_node_id, 'batchtool/nodemerge');
                 return false;
             }
             $target_node_urlalias_id = $target_node_urlalias_list[0]->attribute('id');
             $target_parent_urlalias_id = $target_node_urlalias_list[0]->attribute('parent');
             $db = eZDB::instance();
             $db->begin();
             // Make sure any children nodes are moved to the new node
             foreach ($node->attribute('children') as $child) {
                 moveNode($child, $target_node_id);
             }
             // Make sure any bookmarks are moved to the new node
             $bookmark_list = eZPersistentObject::fetchObjectList(eZContentBrowseBookmark::definition(), null, array('node_id' => $node->attribute('node_id')));
             foreach ($bookmark_list as $bookmark) {
                 $bookmark->setAttribute('node_id', $target_node_id);
                 $bookmark->store();
             }
             // Remove the node in question
             $node->removeNodeFromTree(true);
             // Set up url alias redirects to the new node
             foreach ($urlalias_list as $url_alias) {
                 $url_alias->setAttribute('action', 'eznode:' . $target_node_id);
                 $url_alias->setAttribute('action_type', 'eznode');
                 $url_alias->setAttribute('link', $target_node_urlalias_id);
                 $url_alias->setAttribute('is_original', 0);
                 $url_alias->store();
             }
             $db->commit();
             return true;
         }
     }
     return false;
 }
 /**
  * Returns URL alias for the specified <var>$locale</var>
  *
  * @param string $url
  * @param string $locale
  * @return void
  */
 public function destinationUrl()
 {
     $nodeId = $this->origUrl;
     if (!is_numeric($this->origUrl)) {
         $nodeId = eZURLAliasML::fetchNodeIDByPath($this->origUrl);
     }
     $destinationElement = eZURLAliasML::fetchByAction('eznode', $nodeId, $this->destinationLocale, false);
     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 ($this->isUrlPointingToModule($this->origUrl) || $this->isLocaleAvailableAsFallback()) {
             // We have a module, we're keeping the orignal url.
             $urlAlias = $this->origUrl;
         } else {
             // We probably have an untranslated object, which is not
             // available with SiteLanguageList setting, we direct to root.
             $urlAlias = '';
         }
     } else {
         // Translated object found, forwarding to new URL.
         $saIni = $this->getSiteAccessIni();
         $siteLanguageList = $saIni->variable('RegionalSettings', 'SiteLanguageList');
         $urlAlias = $destinationElement[0]->getPath($this->destinationLocale, $siteLanguageList);
         $urlAlias .= $this->userParamString;
     }
     $this->baseDestinationUrl = rtrim($this->baseDestinationUrl, '/');
     if ($GLOBALS['eZCurrentAccess']['type'] === eZSiteAccess::TYPE_URI) {
         $finalUrl = $this->baseDestinationUrl . '/' . $this->destinationSiteAccess . '/' . $urlAlias;
     } else {
         $finalUrl = $this->baseDestinationUrl . '/' . $urlAlias;
     }
     return $finalUrl;
 }
 public function testSetLangMaskAlwaysAvailable()
 {
     $nodeID = mt_rand();
     // Create an ezurlalias_ml entry
     $url = eZURLAliasML::create(__FUNCTION__ . $nodeID, "eznode:" . $nodeID, 0, 2);
     $url->store();
     // Update lang_mask by setting always available,
     eZURLAliasML::setLangMaskAlwaysAvailable(2, "eznode", $nodeID);
     // Verify that language mask was increased to 3.
     $urls = eZURLAliasML::fetchByAction('eznode', $nodeID);
     self::assertEquals(3, (int) $urls[0]->attribute('lang_mask'));
     // Update lang_mask by removing always available,
     eZURLAliasML::setLangMaskAlwaysAvailable(false, "eznode", $nodeID);
     // Verify that language mask was reduced back to 2.
     $urls = eZURLAliasML::fetchByAction('eznode', $nodeID);
     self::assertEquals(2, (int) $urls[0]->attribute('lang_mask'));
 }
 function updateSubTreePath($updateParent = true, $nodeMove = false)
 {
     $changeCount = 0;
     $nodeID = $this->attribute('node_id');
     $parentNodeID = $this->attribute('parent_node_id');
     // Avoid recursion due to database inconsistencies
     if ($nodeID === $parentNodeID) {
         eZDebug::writeError("Parent node ID equals node ID for node: {$nodeID}. The node cannot be a parent of itself!", __METHOD__);
         return false;
     }
     // Only set name if current node is not the content root
     $ini = eZINI::instance('content.ini');
     $contentRootID = $ini->variable('NodeSettings', 'RootNode');
     $obj = $this->object();
     $alwaysMask = $obj->attribute('language_mask') & 1;
     $languages = $obj->allLanguages();
     $nameList = array();
     $initialLanguageID = $obj->attribute('initial_language_id');
     $pathIdentificationName = false;
     foreach ($languages as $language) {
         $nodeName = '';
         if ($nodeID != $contentRootID) {
             $objClass = $obj->attribute('content_class');
             $nodeName = $objClass->urlAliasName($obj, false, $language->attribute('locale'));
             $nodeName = eZURLAliasFilter::processFilters($nodeName, $language, $this);
             $nodeName = eZURLAliasML::convertToAlias($nodeName, 'node_' . $nodeID);
             $nodeName = $this->adjustPathElement($nodeName, $nodeMove);
             // Compatibility mode:
             // Store name for the 'path_identification_string' column.
             if ($initialLanguageID == $language->attribute('id')) {
                 $pathIdentificationName = eZURLAliasML::convertToAliasCompat($nodeName, 'node_' . $nodeID);
             }
         }
         $nameList[] = array('text' => $nodeName, 'language' => $language);
     }
     $parentActionName = "eznode";
     $parentActionValue = $parentNodeID;
     $parentElementID = false;
     $existingElements = eZURLAliasML::fetchByAction("eznode", $nodeID);
     $existingElementID = null;
     if (count($existingElements) > 0) {
         $existingElementID = $existingElements[0]->attribute('id');
         $parentElementID = $existingElements[0]->attribute('parent');
     }
     // If we have parent element it means the node is already published
     // and we have to see if it has been moved
     if ($parentNodeID != 1 and $updateParent) {
         $parents = eZURLAliasML::fetchByAction("eznode", $parentNodeID);
         if (count($parents) == 0) {
             $parentNode = $this->fetchParent();
             if (!$parentNode) {
                 return false;
             }
             $result = $parentNode->updateSubTreePath();
             if (!$result) {
                 return false;
             }
             $parents = eZURLAliasML::fetchByAction($parentActionName, $parentActionValue);
             if (count($parents) == 0) {
                 return false;
             }
             $oldParentElementID = $parentElementID;
             foreach ($parents as $paren) {
                 $parentElementID = 0;
                 if ($paren->attribute('text') != '') {
                     $parentElementID = (int) $paren->attribute('link');
                     break;
                 }
             }
         } else {
             $oldParentElementID = $parentElementID;
             $parentElementID = 0;
             foreach ($parents as $paren) {
                 if ($paren->attribute('text') != '') {
                     $parentElementID = (int) $paren->attribute('link');
                     break;
                 }
             }
         }
     } else {
     }
     $this->updatePathIdentificationString($pathIdentificationName);
     $languageID = $obj->attribute('initial_language_id');
     $cleanup = false;
     foreach ($nameList as $nameEntry) {
         $text = $nameEntry['text'];
         $language = $nameEntry['language'];
         $result = eZURLAliasML::storePath($text, 'eznode:' . $nodeID, $language, false, $alwaysMask, $parentElementID, $cleanup);
         if ($result['status'] === true) {
             $changeCount++;
         }
     }
     return $changeCount;
 }
Beispiel #7
0
     $newSourceWildcard = $rowsw[0]['destination_url'];
     if (!preg_match("#^(.*)\\{1\\}\$#", $newSourceWildcard, $matches)) {
         logError("Invalid destination wildcard '{$destinationWildcard}', item is skipped, URL entry ID is " . $rowsw[0]['id']);
         list($column, $counter) = displayProgress('E', $urlImportStartTime, $counter, $urlCount, $column);
         continue 2;
     }
     $newSourceWildcard = $matches[1];
     $sourceWildcard = $newSourceWildcard;
 }
 $toPathSQL = $db->escapeString($toPath);
 $query = "SELECT * FROM ezurlalias WHERE source_url = '{$toPathSQL}' AND is_wildcard = 0 AND forward_to_id = 0";
 $rowsw = $db->arrayQuery($query);
 if (count($rowsw) > 0) {
     list($action, $alwaysAvailable) = decodeAction($rowsw[0]['destination_url']);
     list($actionType, $actionValue) = explode(":", $action, 2);
     $elements = eZURLAliasML::fetchByAction($actionType, $actionValue);
     if ($elements) {
         $toPath = $elements[0]->getPath();
     }
 }
 $elements = eZURLAliasML::fetchByPath($toPath);
 if (count($elements) == 0) {
     // Referenced url does not exist
     logError("The referenced path '{$toPath}' can not be found among the new URL alias entries, url entry ID is " . $row['id']);
     list($column, $counter) = displayProgress('E', $urlImportStartTime, $counter, $urlCount, $column);
     continue;
 }
 // Fetch the ID of the element to redirect to.
 $linkID = $elements[0]->attribute('id');
 $action = $elements[0]->attribute('action');
 if ($action == 'nop:') {
    /**
     * Generates caches for all the urls of nodes in $nodeList.
     *
     * The associative array must have on of these entries:
     * - node_id - ID of the node
     * - path_identification_string - The path_identification_string from the node table, is used to fetch the node ID if node_id is missing.
     *
     * @param array $nodeList An array with node entries, each entry is either the node ID or an associative array.
     */
    public function generateNodeListCache( $nodeList )
    {
        $db = eZDB::instance();

        foreach ( $nodeList as $uri )
        {
            if ( is_array( $uri ) )
            {
                if ( !isset( $uri['node_id'] ) )
                {
                    eZDebug::writeError( "node_id is not set for uri entry " . var_export( $uri ) . ", will need to perform extra query to get node_id" );
                    $node = eZContentObjectTreeNode::fetchByURLPath( $uri['path_identification_string'] );
                    $nodeID = (int)$node->attribute( 'node_id' );
                }
                else
                {
                    $nodeID = (int)$uri['node_id'];
                }
            }
            else
            {
                $nodeID = (int)$uri;
            }
            $elements = eZURLAliasML::fetchByAction( 'eznode', $nodeID, true, true, true );
            foreach ( $elements as $element )
            {
                $path = $element->getPath();
                $this->cacheURL( '/' . $path );
            }
        }
    }
Beispiel #9
0
 /**
  * Test that store path does not reparent children of entries with same action
  * if they are custom aliases
  */
 public function testStorePathReparentAliasEntries()
 {
     // Create a real folder
     $r = mt_rand();
     $theRealFolder = new ezpObject("folder", 2);
     $theRealFolder->name = __FUNCTION__ . $r;
     $theRealFolder->publish();
     // Create a real article in real folder
     $myNode = new ezpObject("article", $theRealFolder->mainNode->node_id);
     $myNode->title = "MyNode";
     $myNode->publish();
     // We fetch the url path element of our real folder entry,
     // in order to create an alias to it
     $realFolderUrl = eZURLAliasML::fetchByAction("eznode", $theRealFolder->mainNode->node_id);
     $realFolderUrlId = $realFolderUrl[0]->attribute('id');
     $myNodeUrl = eZURLAliasML::fetchByAction("eznode", $myNode->mainNode->node_id);
     $myNodeUrlId = $myNodeUrl[0]->attribute('id');
     // We create a custom url alias for the real folder under $realFolderAliasPath
     // Note the first path element will be a virtual nop:
     $realFolderAliasPath = "VirtualPath/AliasToTheRealFolder{$r}";
     $action = "eznode:" . $theRealFolder->mainNode->node_id;
     $realFolderAlias = eZURLAliasML::storePath($realFolderAliasPath, $action, false, $realFolderUrlId);
     $realFolderAliasId = $realFolderAlias['element']->attribute('id');
     /*
                We create a custom url alias for MyNode, which is located underneath
                the alias for real folder, in the url path
        \
                |-- TheRealFolder                (node a)
                |   `-- MyNode                   (node b)
                `-- VirtualPath                  (nop:)
                    `-- AliasToTheRealFolder     (node a)
                        `-- AliasToMyNode        (node b)
     */
     // $myNodeAliasPath = "{$realFolderAliasPath}/AliasToMyNode{$r}";
     $myNodeAliasPath = "AliasToMyNode{$r}";
     $myNodeAction = "eznode:" . $myNode->mainNode->node_id;
     $myNodeAlias = eZURLAliasML::storePath($myNodeAliasPath, $myNodeAction, false, $myNodeUrlId, false, $realFolderAliasId);
     $myNodeAliasOriginalParent = $myNodeAlias['element']->attribute('parent');
     // We republish the real folder, not strictly necessary to change the
     // but it is more illustrative.
     $theRealFolder->name = __FUNCTION__ . $r . "Renamed";
     $theRealFolder->publish();
     // Assert that our alias to MyNode was indeed placed underneath $realFolderAliasPath
     self::assertEquals($realFolderAliasId, $myNodeAliasOriginalParent);
     $db = eZDB::instance();
     $q = self::buildSql(array($myNode->mainNode->node_id), false, array('is_alias' => 1, 'is_original' => 1));
     $myNodeAliasPostChange = $db->arrayQuery($q);
     $myNodeAliasPostChangeParent = $myNodeAliasPostChange[0]['parent'];
     // Make sure the the alias to MyNode have not been moved in the url path
     // after publishing the parent of the real node.
     self::assertEquals($myNodeAliasOriginalParent, $myNodeAliasPostChangeParent, "Parent have custom url alias have been changed inadvertently.");
 }
 /**
  * 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;
 }
 /**
  * Generates caches for all the urls of nodes in $nodeList.
  *
  * The associative array must have on of these entries:
  * - node_id - ID of the node
  * - path_identification_string - The path_identification_string from the node table, is used to fetch the node ID if node_id is missing.
  *
  * @param array $nodeList An array with node entries, each entry is either the node ID or an associative array.
  */
 public function generateNodeListCache($nodeList)
 {
     $delay = eZINI::instance('staticcache.ini')->variable('CacheSettings', 'CronjobCacheClear') == 'enabled';
     /*
     echo "\n\nNodeList:<br />\n\n";
     print_r($nodeList); //die();
     */
     /*
     foreach ($nodeList as $node)
     {
         $nodeID = (int)$node;
         $elements = eZURLAliasML::fetchByAction( 'eznode', $nodeID, true, true, true );
         foreach ( $elements as $element )
         {
             $path = $element->getPath();
             $nodeListUrls[]='/' . $path;
         }
     }
     echo '<pre>'; print_r($nodeListUrls); echo '</pre>'."\n\n\n";
     die();
     */
     $db = eZDB::instance();
     foreach ($nodeList as $uri) {
         if (is_array($uri)) {
             if (!isset($uri['node_id'])) {
                 eZDebug::writeError("node_id is not set for uri entry " . var_export($uri) . ", will need to perform extra query to get node_id");
                 $node = eZContentObjectTreeNode::fetchByURLPath($uri['path_identification_string']);
                 $nodeID = (int) $node->attribute('node_id');
             } else {
                 $nodeID = (int) $uri['node_id'];
             }
         } else {
             $nodeID = (int) $uri;
         }
         $elements = eZURLAliasML::fetchByAction('eznode', $nodeID, true, true, true);
         foreach ($elements as $element) {
             $path = $element->getPath();
             // print_r("cacheUrl: $path <hr/>\n\n");
             $this->cacheURL('/' . $path, false, false, $delay);
         }
     }
     //die();
 }
 private function nodeId2Urls($nodeId)
 {
     $return = array();
     $elements = eZURLAliasML::fetchByAction('eznode', $nodeId, false, false, true);
     foreach ($elements as $element) {
         $return[] = '/' . $element->getPath();
     }
     if ($this->purgeSystemUrls) {
         $return[] = '/content/view/full/' . $nodeId;
     }
     return $return;
 }