diff --git a/core/components/googlesitemap/elements/chunks/gcontainer.chunk.tpl b/core/components/googlesitemap/elements/chunks/gcontainer.chunk.tpl index b192006..fa30fae 100644 --- a/core/components/googlesitemap/elements/chunks/gcontainer.chunk.tpl +++ b/core/components/googlesitemap/elements/chunks/gcontainer.chunk.tpl @@ -1,3 +1,3 @@ - + [[+items]] \ No newline at end of file diff --git a/core/components/googlesitemap/elements/chunks/gitem.chunk.tpl b/core/components/googlesitemap/elements/chunks/gitem.chunk.tpl index 7826883..2690476 100644 --- a/core/components/googlesitemap/elements/chunks/gitem.chunk.tpl +++ b/core/components/googlesitemap/elements/chunks/gitem.chunk.tpl @@ -3,4 +3,5 @@ [[+date]] [[+update]] [[+priority]] + [[+links]] \ No newline at end of file diff --git a/core/components/googlesitemap/elements/chunks/gitemlink.chunk.tpl b/core/components/googlesitemap/elements/chunks/gitemlink.chunk.tpl new file mode 100644 index 0000000..3bbd14e --- /dev/null +++ b/core/components/googlesitemap/elements/chunks/gitemlink.chunk.tpl @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/core/components/googlesitemap/model/googlesitemap/googlesitemap.class.php b/core/components/googlesitemap/model/googlesitemap/googlesitemap.class.php index 2a935f4..5f76126 100755 --- a/core/components/googlesitemap/model/googlesitemap/googlesitemap.class.php +++ b/core/components/googlesitemap/model/googlesitemap/googlesitemap.class.php @@ -53,6 +53,7 @@ function __construct(modX &$modx,array $config = array()) { 'templateFilter' => 'id', 'itemSeparator' => "\n", 'itemTpl' => 'gItem', + 'itemLinkTpl' => 'gItemLink', 'chunksPath' => $corePath.'elements/chunks/', 'maxDepth' => 0, 'excludeResources' => '', @@ -60,6 +61,8 @@ function __construct(modX &$modx,array $config = array()) { 'excludeChildrenOf' => '', 'showHidden' => false, 'priorityTV' => 0, + 'includeUrlProto' => false, + 'includeBabelLinks' => false, ),$config); } @@ -100,7 +103,7 @@ public function run($currentParent,$selfId = -1,$depth = 0) { } if ($canParse) { - $url = $this->modx->makeUrl($id,'','','full'); + $url = $this->makeUrl($id); $date = $child->get('editedon') ? $child->get('editedon') : $child->get('createdon'); $date = date("Y-m-d", strtotime($date)); @@ -126,12 +129,17 @@ public function run($currentParent,$selfId = -1,$depth = 0) { $priority = $priorityTV; } } + $links = ''; + if ($this->config['includeBabelLinks']) { + $links = $this->getBabelLinks($child); + } /* add item to output */ $output .= $this->getChunk($this->config['itemTpl'],array( 'url' => $url, 'date' => $date, 'update' => $update, 'priority' => $priority, + 'links' => $links )).$this->config['itemSeparator']; } @@ -274,6 +282,53 @@ private function _getTplChunk($name,$postFix = '.chunk.tpl') { } return $chunk; } + + private function makeUrl($id) { + $url = $this->modx->makeUrl($id, '', '', 'full'); + if ($this->config['includeUrlProto'] && strpos($url, '//') === 0) { + $proto = 'http:'; + if ((isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) || $_SERVER['SERVER_PORT'] == 443) { + $proto = 'https:'; + } + $url = $proto . $url; + } + return $url; + } + + private function getBabelTvName() { + $babelTvName = null; + $babelNamespace = $this->modx->getObject('modNamespace', array('name' => 'babel')); + if (!empty($babelNamespace)) { + $babelTvName = $this->modx->getOption('babel.babelTvName'); + } + return $babelTvName; + } + + private function getBabelLinks($doc) { + $output = ''; + $babelTvName = $this->getBabelTvName(); + if (!empty($babelTvName)) { + $babelLinks = $doc->getTVValue($babelTvName); + if (!empty($babelLinks)) { + $output = array(); + $babelLinks = explode(';', $babelLinks); + foreach ($babelLinks as $babelLink) { + list($babelLinkContext, $babelLinkId) = explode(':', $babelLink); + $babelLinkContext = $this->modx->getContext($babelLinkContext); + if (!empty($babelLinkContext)) { + $babelLinkLang = $babelLinkContext->getOption('cultureKey'); + $babelLinkUrl = $this->makeUrl($babelLinkId); + $output[] = $this->getChunk($this->config['itemLinkTpl'], array( + 'hreflang' => $babelLinkLang, + 'href' => $babelLinkUrl, + )); + } + } + $output = (!empty($output) ? implode("\n\t", $output) : ''); + } + } + return $output; + } }