Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'remotes/zf2/master' into test/feed-entr…
Browse files Browse the repository at this point in the history
…y-type-detection
  • Loading branch information
Fritz Gerneth committed Jul 5, 2012
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 425 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

194 changes: 0 additions & 194 deletions src/Helper/FormElement.php

This file was deleted.

7 changes: 2 additions & 5 deletions src/Helper/HtmlList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class HtmlList extends FormElement
class HtmlList extends AbstractHtmlElement
{
/**
* Generates a 'List' element.
Expand Down Expand Up @@ -68,10 +68,7 @@ public function __invoke(array $items, $ordered = false, $attribs = false, $esca
$attribs = '';
}

$tag = 'ul';
if ($ordered) {
$tag = 'ol';
}
$tag = ($ordered) ? 'ol' : 'ul';

return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL;
}
Expand Down
49 changes: 32 additions & 17 deletions src/Helper/Navigation/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class Sitemap extends AbstractHelper
*/
protected $serverUrl;

/**
* List of urls in the sitemap
*
* @var array
*/
protected $urls = array();

/**
* Helper entry point
*
Expand Down Expand Up @@ -284,11 +291,17 @@ public function url(AbstractPage $page)
$curDoc = $basePathHelper();
$curDoc = ('/' == $curDoc) ? '' : trim($curDoc, '/');
$url = rtrim($this->getServerUrl(), '/') . '/'
. $curDoc
. (empty($curDoc) ? '' : '/') . $href;
. $curDoc
. (empty($curDoc) ? '' : '/') . $href;
}

return $this->xmlEscape($url);
if (! in_array($url, $this->urls)) {

$this->urls[] = $url;
return $this->xmlEscape($url);
}

return null;
}

/**
Expand All @@ -309,6 +322,9 @@ public function url(AbstractPage $page)
*/
public function getDomSitemap(AbstractContainer $container = null)
{
// Reset the urls
$this->urls = array();

if (null === $container) {
$container = $this->getContainer();
}
Expand Down Expand Up @@ -353,6 +369,7 @@ public function getDomSitemap(AbstractContainer $container = null)
// get absolute url from page
if (!$url = $this->url($page)) {
// skip page if it has no url (rare case)
// or already is in the sitemap
continue;
}

Expand All @@ -364,14 +381,14 @@ public function getDomSitemap(AbstractContainer $container = null)
&& !$locValidator->isValid($url)
) {
throw new Exception\RuntimeException(sprintf(
'Encountered an invalid URL for Sitemap XML: "%s"',
$url
'Encountered an invalid URL for Sitemap XML: "%s"',
$url
));
}

// put url in 'loc' element
$urlNode->appendChild($dom->createElementNS(self::SITEMAP_NS,
'loc', $url));
'loc', $url));

// add 'lastmod' element if a valid lastmod is set in page
if (isset($page->lastmod)) {
Expand All @@ -386,7 +403,7 @@ public function getDomSitemap(AbstractContainer $container = null)
$lastmodValidator->isValid($lastmod)) {
$urlNode->appendChild(
$dom->createElementNS(self::SITEMAP_NS, 'lastmod',
$lastmod)
$lastmod)
);
}
}
Expand All @@ -398,7 +415,7 @@ public function getDomSitemap(AbstractContainer $container = null)
$changefreqValidator->isValid($changefreq)) {
$urlNode->appendChild(
$dom->createElementNS(self::SITEMAP_NS, 'changefreq',
$changefreq)
$changefreq)
);
}
}
Expand All @@ -410,7 +427,7 @@ public function getDomSitemap(AbstractContainer $container = null)
$priorityValidator->isValid($priority)) {
$urlNode->appendChild(
$dom->createElementNS(self::SITEMAP_NS, 'priority',
$priority)
$priority)
);
}
}
Expand All @@ -420,8 +437,8 @@ public function getDomSitemap(AbstractContainer $container = null)
if ($this->getUseSchemaValidation()) {
if (!@$dom->schemaValidate(self::SITEMAP_XSD)) {
throw new Exception\RuntimeException(sprintf(
'Sitemap is invalid according to XML Schema at "%s"',
self::SITEMAP_XSD
'Sitemap is invalid according to XML Schema at "%s"',
self::SITEMAP_XSD
));
}
}
Expand All @@ -437,19 +454,17 @@ public function getDomSitemap(AbstractContainer $container = null)
* Implements {@link HelperInterface::render()}.
*
* @param link|AbstractContainer $container [optional] container to render. Default is
* to render the container registered in the
* to render the container registered in the
* helper.
* @return string helper output
*/
public function render($container = null)
{
$dom = $this->getDomSitemap($container);
$xml = $this->getUseXmlDeclaration() ?
$dom->saveXML() :
$dom->saveXML($dom->documentElement);
$dom->saveXML() :
$dom->saveXML($dom->documentElement);

// DOMDocument ends lines with a "\n" character. We want this to be the PHP_EOL character
// in order to keep unit tests working.
return str_replace("\n", PHP_EOL, rtrim($xml, PHP_EOL) );
return rtrim($xml, PHP_EOL);
}
}
Loading

0 comments on commit 59b30de

Please sign in to comment.