Inheritance: implements Symfony\Cmf\Component\Routing\ChainedRouterInterface, implements Symfony\Component\Routing\Matcher\RequestMatcherInterface
Exemplo n.º 1
0
 /**
  * Converts internal links (ezcontent:// and ezlocation://) to URLs.
  *
  * @param \DOMDocument $document
  *
  * @return \DOMDocument
  */
 public function convert(DOMDocument $document)
 {
     $document = clone $document;
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace("docbook", "http://docbook.org/ns/docbook");
     $linkAttributeExpression = "starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )";
     $xpathExpression = "//docbook:link[{$linkAttributeExpression}]|//docbook:ezlink";
     /** @var \DOMElement $link */
     foreach ($xpath->query($xpathExpression) as $link) {
         // Set resolved href to number character as a default if it can't be resolved
         $hrefResolved = "#";
         $href = $link->getAttribute("xlink:href");
         $location = null;
         preg_match("~^(.+://)?([^#]*)?(#.*|\\s*)?\$~", $href, $matches);
         list(, $scheme, $id, $fragment) = $matches;
         if ($scheme === "ezcontent://") {
             try {
                 $contentInfo = $this->contentService->loadContentInfo($id);
                 $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
                 $hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning("While generating links for richtext, could not locate " . "Content object with ID " . $id);
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice("While generating links for richtext, unauthorized to load " . "Content object with ID " . $id);
                 }
             }
         } else {
             if ($scheme === "ezlocation://") {
                 try {
                     $location = $this->locationService->loadLocation($id);
                     $hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
                 } catch (APINotFoundException $e) {
                     if ($this->logger) {
                         $this->logger->warning("While generating links for richtext, could not locate " . "Location with ID " . $id);
                     }
                 } catch (APIUnauthorizedException $e) {
                     if ($this->logger) {
                         $this->logger->notice("While generating links for richtext, unauthorized to load " . "Location with ID " . $id);
                     }
                 }
             } else {
                 $hrefResolved = $href;
             }
         }
         $hrefAttributeName = "xlink:href";
         // For embeds set the resolved href to the separate attribute
         // Original href needs to be preserved in order to generate link parameters
         // This will need to change with introduction of UrlService and removal of URL link
         // resolving in external storage
         if ($link->localName === "ezlink") {
             $hrefAttributeName = "href_resolved";
         }
         $link->setAttribute($hrefAttributeName, $hrefResolved);
     }
     return $document;
 }
 /**
  * Will return the right UrlAlias in regards to configured root location.
  *
  * @param string $pathinfo
  * @return \eZ\Publish\API\Repository\Values\Content\URLAlias
  */
 protected function getUrlAlias($pathinfo)
 {
     if ($this->rootLocationId === null || $this->generator->isUriPrefixExcluded($pathinfo)) {
         return parent::getUrlAlias($pathinfo);
     }
     return $this->urlAliasService->lookup($this->generator->getPathPrefixByRootLocationId($this->rootLocationId) . $pathinfo);
 }
 /**
  * @expectedException \LogicException
  */
 public function testGenerateWithContentIdWithMissingMainLocation()
 {
     $contentId = 456;
     $contentInfo = new ContentInfo(array('id' => $contentId, 'mainLocationId' => null));
     $parameters = array('some' => 'thing');
     $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH;
     $this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo));
     $this->router->generate(UrlAliasRouter::URL_ALIAS_ROUTE_NAME, $parameters + array('contentId' => $contentId), $referenceType);
 }
 /**
  * @covers eZ\Publish\Core\MVC\Symfony\Routing\UrlAliasRouter::__construct
  * @covers eZ\Publish\Core\MVC\Symfony\Routing\UrlAliasRouter::generate
  */
 public function testGenerateWithLocationAsParameter()
 {
     $locationId = 123;
     $location = new Location(array('id' => $locationId));
     $parameters = array('some' => 'thing');
     $absolute = false;
     $generatedLink = '/foo/bar';
     $this->urlALiasGenerator->expects($this->once())->method('generate')->with($location, $parameters, $absolute)->will($this->returnValue($generatedLink));
     $this->assertSame($generatedLink, $this->router->generate(UrlAliasRouter::URL_ALIAS_ROUTE_NAME, $parameters + array('location' => $location), $absolute));
 }
 /**
  * Converts internal links (eznode:// and ezobject://) to URLs.
  *
  * @param \DOMDocument $xmlDoc
  *
  * @return string|null
  */
 public function convert(DOMDocument $xmlDoc)
 {
     foreach ($xmlDoc->getElementsByTagName("link") as $link) {
         $location = null;
         if ($link->hasAttribute('object_id')) {
             try {
                 $contentInfo = $this->contentService->loadContentInfo($link->getAttribute('object_id'));
                 $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning("While generating links for xmltext, could not locate " . "Content object with ID " . $link->getAttribute('object_id'));
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice("While generating links for xmltext, unauthorized to load " . "Content object with ID " . $link->getAttribute('object_id'));
                 }
             }
         }
         if ($link->hasAttribute('node_id')) {
             try {
                 $location = $this->locationService->loadLocation($link->getAttribute('node_id'));
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning("While generating links for xmltext, could not locate " . "Location with ID " . $link->getAttribute('node_id'));
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice("While generating links for xmltext, unauthorized to load " . "Location with ID " . $link->getAttribute('node_id'));
                 }
             }
         }
         if ($location !== null) {
             $link->setAttribute('url', $this->urlAliasRouter->generate($location));
         }
         if ($link->hasAttribute('anchor_name')) {
             $link->setAttribute('url', $link->getAttribute('url') . "#" . $link->getAttribute('anchor_name'));
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Converts internal links (eznode:// and ezobject://) to URLs.
  *
  * @param \DOMDocument $xmlDoc
  *
  * @return string|null
  */
 public function convert(DOMDocument $xmlDoc)
 {
     $xpath = new DOMXPath($xmlDoc);
     $elements = $xpath->query('//link|//embed|//embed-inline');
     /** @var \DOMElement $element */
     foreach ($elements as $element) {
         $location = null;
         if ($this->elementHasAttribute($element, 'object_id')) {
             try {
                 $contentInfo = $this->contentService->loadContentInfo($this->getElementAttribute($element, 'object_id'));
                 $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning('While generating links for xmltext, could not locate ' . 'Content object with ID ' . $this->getElementAttribute($element, 'object_id'));
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice('While generating links for xmltext, unauthorized to load ' . 'Content object with ID ' . $this->getElementAttribute($element, 'object_id'));
                 }
             }
         }
         if ($this->elementHasAttribute($element, 'node_id')) {
             try {
                 $location = $this->locationService->loadLocation($this->getElementAttribute($element, 'node_id'));
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning('While generating links for xmltext, could not locate ' . 'Location with ID ' . $this->getElementAttribute($element, 'node_id'));
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice('While generating links for xmltext, unauthorized to load ' . 'Location with ID ' . $this->getElementAttribute($element, 'node_id'));
                 }
             }
         }
         if ($location !== null) {
             $element->setAttribute('url', $this->urlAliasRouter->generate($location));
         }
         // Copy temporary URL if it exists and is not set at this point
         if (!$element->hasAttribute('url') && $element->hasAttribute(EmbedLinking::TEMP_PREFIX . 'url')) {
             $element->setAttribute('url', $element->getAttribute(EmbedLinking::TEMP_PREFIX . 'url'));
         }
         if ($this->elementHasAttribute($element, 'anchor_name')) {
             $element->setAttribute('url', $element->getAttribute('url') . '#' . $this->getElementAttribute($element, 'anchor_name'));
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Converts internal links (ezcontent:// and ezlocation://) to URLs.
  *
  * @param \DOMDocument $document
  *
  * @return \DOMDocument
  */
 public function convert(DOMDocument $document)
 {
     $document = clone $document;
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace("docbook", "http://docbook.org/ns/docbook");
     $xpathExpression = "//docbook:link[starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )]";
     /** @var \DOMElement $link */
     foreach ($xpath->query($xpathExpression) as $link) {
         $location = null;
         preg_match("~^(.+)://([^#]*)?(#.*|\\s*)?\$~", $link->getAttribute("xlink:href"), $matches);
         list(, $scheme, $id, $fragment) = $matches;
         if ($scheme === "ezcontent") {
             try {
                 $contentInfo = $this->contentService->loadContentInfo($id);
                 $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning("While generating links for richtext, could not locate " . "Content object with ID " . $id);
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice("While generating links for richtext, unauthorized to load " . "Content object with ID " . $id);
                 }
             }
         }
         if ($scheme === "ezlocation") {
             try {
                 $location = $this->locationService->loadLocation($id);
             } catch (APINotFoundException $e) {
                 if ($this->logger) {
                     $this->logger->warning("While generating links for richtext, could not locate " . "Location with ID " . $id);
                 }
             } catch (APIUnauthorizedException $e) {
                 if ($this->logger) {
                     $this->logger->notice("While generating links for richtext, unauthorized to load " . "Location with ID " . $id);
                 }
             }
         }
         if ($location !== null) {
             $link->setAttribute('xlink:href', $this->urlAliasRouter->generate($location) . $fragment);
         }
     }
     return $document;
 }