default_hreflang_menu.php
3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @package JMAP::SITEMAP::components::com_jmap
* @subpackage views
* @subpackage sitemap
* @subpackage tmpl
* @author Joomla! Extensions Store
* @copyright (C) 2015 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$includeExternalLinks = $this->sourceparams->get ( 'include_external_links', 1 );
$trailingSlash = '/';
$removeHomeSlash = $this->cparams->get('remove_home_slash', 0);
// Get menus object
$menusArray = $this->application->getMenu()->getMenu();
if (count ( $this->source->data )) {
foreach ( $this->source->data as $elm ) {
// Skip menu external links
if($elm->type == 'url' && !$includeExternalLinks) {
continue;
}
// Avoid place link for separator, alias, heading, external url
if(in_array($elm->type, array('url', 'separator', 'alias', 'heading'))) {
continue;
}
// Get language associations for this content, if not found skip and go on
$associatedMenus = JMapHelpersAssociations::getMenuAssociations($elm->id);
if(count($associatedMenus) <= 1) {
continue;
}
$link = $elm->link;
if (isset ( $elm->id )) {
if (strpos ( $link, 'Itemid=' ) === FALSE) {
$link .= '&Itemid=' . $elm->id;
}
}
if (strcasecmp ( substr ( $link, 0, 9 ), 'index.php' ) === 0) {
$link = JRoute::_ ( $link );
}
// SEF patch for better match uri con $link override
if ($elm->type == 'component' && array_key_exists($elm->id, $menusArray)) {
$link = 'index.php?Itemid=' . $elm->id;
$link = JRoute::_ ( $link );
}
if ($elm->home && $removeHomeSlash) { // HOME
$link = rtrim($link, '/');
$trailingSlash = '';
}
// Skip outputting
if(array_key_exists($link, $this->outputtedLinksBuffer)) {
continue;
}
// Else store to prevent duplication
$this->outputtedLinksBuffer[$link] = true;
$link = htmlspecialchars($link, null, 'UTF-8', false);
?>
<url>
<loc><?php echo preg_match('/^http/i', $link) ? $link : $this->liveSite . (strpos($link, '/') === 0 ? $link : $trailingSlash . $link) ; ?></loc>
<?php foreach ($associatedMenus as $alternate):
$alternateLink = htmlspecialchars(JRoute::_ ( 'index.php?Itemid=' . $alternate->id . '&lang=' . $alternate->sef ), null, 'UTF-8', false);
$alternateLink = preg_match('/^http/i', $alternateLink) ? $alternateLink : $this->liveSite . (strpos($alternateLink, '/') === 0 ? $alternateLink : '/'.$alternateLink);
?>
<xhtml:link rel="alternate" hreflang="<?php echo $alternate->sef?>" href="<?php echo $alternateLink;?>" />
<?php endforeach;?>
</url>
<?php
foreach ($associatedMenus as $repetition) {
// Skip the main default url already added
if((int)$repetition->id == $elm->id) {
continue;
}
$repetitionLink = htmlspecialchars(JRoute::_ ( 'index.php?Itemid=' . $repetition->id . '&lang=' . $repetition->sef ), null, 'UTF-8', false);
$repetitionLink = preg_match('/^http/i', $repetitionLink) ? $repetitionLink : $this->liveSite . (strpos($repetitionLink, '/') === 0 ? $repetitionLink : '/'.$repetitionLink);
?>
<url>
<loc><?php echo $repetitionLink; ?></loc>
<?php foreach ($associatedMenus as $subalternate):
$alternateLink = htmlspecialchars(JRoute::_ ( 'index.php?Itemid=' . $subalternate->id . '&lang=' . $subalternate->sef ), null, 'UTF-8', false);
$alternateLink = preg_match('/^http/i', $alternateLink) ? $alternateLink : $this->liveSite . (strpos($alternateLink, '/') === 0 ? $alternateLink : '/'.$alternateLink);
?>
<xhtml:link rel="alternate" hreflang="<?php echo $subalternate->sef?>" href="<?php echo $alternateLink;?>" />
<?php endforeach;?>
</url>
<?php
}
}
}