/** * @param string $sectionRemote * @param int|eZContentObjectTreeNode $chapterNode * @param int|eZContentObjectTreeNode $topicNode * @param string $linkType * @return array */ public static function fetchUnifiedUrl( $sectionRemote, $chapterNode, $topicNode, $linkType ) { $error = false; if ( !in_array($linkType, array('section', 'chapter', 'topic')) ) { $error = true; } else { if ( is_numeric($chapterNode) && $chapterNode ) $chapterNode = eZContentObjectTreeNode::fetch($chapterNode); if ( is_numeric($topicNode) && $topicNode ) $topicNode = eZContentObjectTreeNode::fetch($topicNode); switch ( true ) { case ( $topicNode instanceof eZContentObjectTreeNode ): $chapterNode = $topicNode->fetchParent(); case ( $chapterNode instanceof eZContentObjectTreeNode ): if ( !$sectionRemote ) { /* @type $chapterDM eZContentObjectAttribute[] */ $chapterDM = $chapterNode->dataMap(); if ( isset($chapterDM['serialized_taxonomies']) ) { $chapterSerial = $chapterDM['serialized_taxonomies']->content(); if ( isset($chapterSerial['section']) && count($chapterSerial['section']) > 0 ) $sectionRemote = $chapterSerial['section'][0]; } } case ( $sectionRemote != "" ): $sectionUrl = false; $section = self::fetchSection('remote', $sectionRemote); if ( $section['result'] ) { $sectionUrl = '/' . $section['result']['url']; } else { $error = true; } break; default: $error = true; break; } } if ( !$error ) { /* @type $sectionUrl string */ $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByIdentifier(MerckManualShowcase::mainApplicationIdentifier()); $publisherFolderNodeId = MerckManualShowcase::rootNodeId(); $publisherFolderNode = eZContentObjectTreeNode::fetch($publisherFolderNodeId); $publisherFolderInfo = PublisherFolderTool::getNodeIdToPathMapping( $publisherFolderNodeId ); $publisherFolderId = $publisherFolderInfo['pfid']; // Link in about page $AboutChapterNodeID = MerckManualAbout::rootNodeId(); if ( $topicNode && in_array($AboutChapterNodeID, $topicNode->pathArray()) ) { $topicUrl = end(explode('/', $topicNode->attribute('url_alias'))); return array('result' => CacheApplicationTool::buildLocalizedApplicationByIdentifier(MerckManualAbout::mainApplicationIdentifier())->url . '/' . $topicUrl); } $url = null; $applicationObject = $applicationLocalized->applicationObject(); $forceExternalLink = $applicationObject->hasExternalLinkHandler(); switch ( $linkType ) { case 'topic': if ( !( $topicNode instanceof eZContentObjectTreeNode ) ) { $error = true; break; } $urlParts = explode('/', $topicNode->attribute('url_alias')); $urlParts = array_slice($urlParts, $publisherFolderNode->attribute('depth') - $topicNode->attribute('depth')); $url = $applicationLocalized->applicationUrl($forceExternalLink) . '/' . $publisherFolderId . $sectionUrl . '/' . implode('/', $urlParts); break; case 'chapter': if ( !( $chapterNode instanceof eZContentObjectTreeNode ) ) { $error = true; break; } $urlParts = explode('/', $chapterNode->attribute('url_alias')); $urlParts = array_slice($urlParts, $publisherFolderNode->attribute('depth') - $chapterNode->attribute('depth')); $url = $applicationLocalized->applicationUrl( $forceExternalLink ) . '/' . $publisherFolderId . $sectionUrl . '/' . implode('/', $urlParts); break; case 'section': $url = $applicationLocalized->applicationUrl() . '/' . $publisherFolderId . $sectionUrl; break; default: $url = ''; $error = true; break; } } return array('result' => !$error ? $url : null); }
/** * @param string $path * @param MerckManualAbout $app * @return eZContentObjectTreeNode */ public static function findNodeFromPath( $path, $app ) { /* We remove the publisher folder id at the beginning of the url as we already have it */ $path = preg_replace('#^/\d+/#', '/', $path ); $aboutNode = eZContentObjectTreeNode::fetch( $app->rootNodeId() ); $pathParts = explode( '/', substr( $path, 1 ) ); $path = $aboutNode->attribute( 'url_alias' ) . '/' . $pathParts[0]; $nodeId = eZURLAliasML::fetchNodeIDByPath( $path ); if ( $nodeId ) { $app->fullContext = 'topic'; return eZContentObjectTreeNode::fetch( $nodeId ); } }