/** * @param string $path * @param MerckManualSection $app * @return eZContentObjectTreeNode */ public static function findNodeFromPath( $path, $app ) { if( preg_match('#^/\d+/(?P<section>.*?)[/\?]?#', $path, $match) ) { foreach ( array('url', 'remote', 'name') as $attribute ) { $section = MerckManualFunctionCollection::fetchSection( $attribute, $match['section'] ); if ( $section ) { $app->section = $section; break; } } return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId()); } else return false; }
/** * @param string $path * @param MerckManualShowcase $app * @return bool|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 ); $manualAppNode = eZContentObjectTreeNode::fetch( self::rootNodeId() ); $manualAppNodePathName = $manualAppNode->pathWithNames(); $tabNodePath = explode('/', substr($path, 1)); $remoteId = end($tabNodePath); if(preg_match('/^[a-f0-9]{32}$/', $remoteId)) { $nodeRemote = eZContentObjectTreeNode::fetchByRemoteID($remoteId); if($nodeRemote instanceof eZContentObjectTreeNode) { $app->fullContext = 'topic'; return $nodeRemote; } } $pathParts = explode('/', substr($path, 1)); if ( $pathParts[0] == 'table' ) { $app->fullContext = 'table'; return eZContentObjectTreeNode::fetch($pathParts[1]); } // Url with topic list($sectionName, $chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts; // Url without topic $matches = array(); if ( preg_match('/media-([a-z]+)/', $topicName, $matches) ) { list($sectionName, $chapterName, $mediaType, $mediaName, $other) = $pathParts; $topicName = null; } // Full section if ( $sectionName != null && is_null( $chapterName ) && is_null( $topicName ) ) { $app->fullContext = 'section'; $app->section = MerckManualFunctionCollection::fetchSection('url', $sectionName); return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId()); } if ( $sectionName == 'about-us' ) { list($chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts; } $path = $manualAppNodePathName; // Full of chapter if ( $chapterName ) { $app->fullContext = 'chapter'; $path .= '/' . $chapterName; } // Full of topic if ( $topicName ) { $app->fullContext = 'topic'; $path .= '/' . $topicName; } $nodeId = eZURLAliasML::fetchNodeIDByPath($path); if ( $nodeId ) { if ( $mediaName ) { $mediaType = str_replace('media-', '', $mediaType); // Get media node // Full of html table image // /topic_name/(media-image-file)/oscar2/filename if ( $mediaType == 'image-file' ) { $app->fullContext = $mediaType; $app->oscarFolder = $mediaName; $app->mediaName = $other; } // Full of inline audio, video, image elseif ( $mediaType ) { // Construct the remote_id of the media folder /* @type $dataMap eZContentObjectAttribute[] */ $contentObject = eZContentObject::fetchByNodeID($nodeId); $dataMap = $contentObject->dataMap(); $publisherAttrContent = $dataMap['publisher']->content(); if ( isset($publisherAttrContent['relation_list'][0]['contentobject_remote_id']) ) { // Get media folder $mediaFolderRemoteId = sprintf('%s_media_%s', $publisherAttrContent['relation_list'][0]['contentobject_remote_id'], $mediaType); $mediaFolder = eZContentObject::fetchByRemoteID($mediaFolderRemoteId); if ( $mediaFolder ) { // Get media $mediaFolderPathName = $mediaFolder->mainNode()->pathWithNames(); $nodeId = eZURLAliasML::fetchNodeIDByPath($mediaFolderPathName . '/' . $mediaName); $app->fullContext = $mediaType; } } } } } if ( $nodeId ) { // Full of chapter must not be accessible, show first topic if ( $app->fullContext == 'chapter' ) { $params = array( 'Depth' => 1, 'DepthOperator' => 'eq', 'SortBy' => array(array('priority', 'asc')), 'Limit' => 1 ); $children = eZContentObjectTreeNode::subTreeByNodeID($params, $nodeId); if ( isset($children[0]) && $children[0] instanceof eZContentObjectTreeNode ) { $node = $children[0]; $app->fullContext = 'topic'; } else $node = null; } else { $node = eZContentObjectTreeNode::fetch($nodeId); } return $node; } return false; }