/** * Attempts to fetch a possible node by translating the provided * string/path to a node-number. * * The last section of the path is removed before the actual * translation: hence, the PARENT node is returned. * * @param string $nodePathString Eg. 'Folder1/file1.txt' * @return eZContentObject Eg. the node of 'Folder1' */ protected function fetchParentNodeByTranslation($nodePathString) { // Strip extensions. E.g. .jpg $nodePathString = $this->fileBasename($nodePathString); // Strip away last slash if (strlen($nodePathString) > 0 and $nodePathString[strlen($nodePathString) - 1] === '/') { $nodePathString = substr($nodePathString, 0, strlen($nodePathString) - 1); } $nodePathString = $this->splitLastPathElement($nodePathString, $element); if (strlen($nodePathString) === 0) { $nodePathString = '/'; } $nodePathString = eZURLAliasML::convertPathToAlias($nodePathString); // Attempt to translate the URL to something like "/content/view/full/84". $translateResult = eZURLAliasML::translate($nodePathString); // handle redirects while ($nodePathString === 'error/301') { $nodePathString = $translateResult; $translateResult = eZURLAliasML::translate($nodePathString); } // Get the ID of the node (which is the last part of the translated path). if (preg_match("#^content/view/full/([0-9]+)\$#", $nodePathString, $matches)) { $nodeID = $matches[1]; } else { $ini = eZINI::instance('webdav.ini'); if ($ini->hasVariable('GeneralSettings', 'StartNode')) { $nodeID = $ini->variable('GeneralSettings', 'StartNode'); } } // Attempt to fetch the node. $node = eZContentObjectTreeNode::fetch($nodeID); // Return the node. return $node; }
function fetchParentNodeByTranslation( $nodePathString ) { // Strip extensions. E.g. .jpg $nodePathString = $this->fileBasename( $nodePathString ); // Strip away last slash if ( strlen( $nodePathString ) > 0 and $nodePathString[strlen( $nodePathString ) - 1] == '/' ) { $nodePathString = substr( $nodePathString, 0, strlen( $nodePathString ) - 1 ); } $nodePathString = $this->splitLastPathElement( $nodePathString, $element ); if ( strlen( $nodePathString ) == 0 ) $nodePathString = '/'; $nodePathString = eZURLAliasML::convertPathToAlias( $nodePathString ); // Attempt to translate the URL to something like "/content/view/full/84". $translateResult = eZURLAliasML::translate( $nodePathString ); // handle redirects while ( $nodePathString == 'error/301' ) { $nodePathString = $translateResult; $translateResult = eZURLAliasML::translate( $nodePathString ); } // Get the ID of the node (which is the last part of the translated path). if ( preg_match( "#^content/view/full/([0-9]+)$#", $nodePathString, $matches ) ) { $nodeID = $matches[1]; $this->appendLogEntry( "NodeID: $nodeID", 'CS:fetchParentNodeByTranslation' ); } else { $this->appendLogEntry( "Root node", 'CS:fetchParentNodeByTranslation' ); $nodeID = 2; } // Attempt to fetch the node. $node = eZContentObjectTreeNode::fetch( $nodeID ); // Return the node. return $node; }