From a691dcb8be259139a681b90c6a88c825a9701c98 Mon Sep 17 00:00:00 2001 From: xinyuexrow Date: Mon, 15 Aug 2016 16:58:27 +0200 Subject: [PATCH] add a new attribute "ExcludeSiteaccess", Code optimization --- classes/xrowsitemaptools.php | 38 ++++++++++++++++++++++++++--- cronjobs/sitemap.php | 12 +++++++++ settings/xrowsitemap.ini.append.php | 5 ++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/classes/xrowsitemaptools.php b/classes/xrowsitemaptools.php index dd9903e..0babbd5 100644 --- a/classes/xrowsitemaptools.php +++ b/classes/xrowsitemaptools.php @@ -261,10 +261,15 @@ public static function addNode( xrowSitemap $sitemap, eZContentObjectTreeNode $n $urlAlias = $url; //Ticket #10114 - correction URLs - if (strpos($GLOBALS['eZCurrentAccess']['name'], 'hi_') !== false) { - $cur_access = explode('_', $GLOBALS['eZCurrentAccess']['name']); - $language_code = $cur_access[1]; - $url = $language_code . '/' . $url; + if ( $ini->hasVariable( 'SitemapSettings', 'HostUriMatchMapItems' ) ) + { + $host_uri = self::getUri($ini->variable( 'SitemapSettings', 'HostUriMatchMapItems' )); + } elseif ( $site_ini->hasVariable( 'SiteAccessSettings', 'HostUriMatchMapItems' )) + { + $host_uri = self::getUri($site_ini->variable( 'SiteAccessSettings', 'HostUriMatchMapItems' )); + } + if ( $host_uri !== '') { + $url = $host_uri . '/' . $url; } // $urlAlias is kept 'as is' to be able to generate these links @@ -1679,6 +1684,31 @@ public static function checkAccess( eZContentObject $contentobject, eZUser $user } } } + + /*! + get URI for the current object + return the URI + */ + public static function getUri( $urimatchMapitems ) + { + foreach ( $urimatchMapitems as $hostUriMap ) + { + $hostUri = explode( ';', $hostUriMap ); + if ( count( $hostUri ) < 3 ) + { + $accessname = $hostUri[1]; + $uri = ''; + } else { + $accessname = $hostUri[2]; + $uri = $hostUri[1]; + } + if ( $accessname == $GLOBALS['eZCurrentAccess']['name'] ) + { + break; + } + } + return $uri; + } } ?> diff --git a/cronjobs/sitemap.php b/cronjobs/sitemap.php index 02d4040..94f39a3 100644 --- a/cronjobs/sitemap.php +++ b/cronjobs/sitemap.php @@ -16,6 +16,18 @@ ); } +if ( $xrowsitemapINI->hasVariable( 'Settings', 'ExcludeSiteaccess' ) ) +{ + $exclude_array = $xrowsitemapINI->variable( 'Settings', 'ExcludeSiteaccess' ); + foreach ($siteAccessArray as $key=>$siteaccess_item) + { + if (in_array($siteaccess_item, $exclude_array)) + { + unset($siteAccessArray[$key]); + } + } +} + if ( $xrowsitemapINI->hasVariable( 'SitemapSettings', 'HostUriMatchMapItems' ) ) { $hostArrays = $xrowsitemapINI->variable( 'SitemapSettings', 'HostUriMatchMapItems' ); diff --git a/settings/xrowsitemap.ini.append.php b/settings/xrowsitemap.ini.append.php index e868d75..fe57ee9 100644 --- a/settings/xrowsitemap.ini.append.php +++ b/settings/xrowsitemap.ini.append.php @@ -40,9 +40,10 @@ # AvailableSiteAccessList[] # AvailableSiteAccessList[]=ger # AvailableSiteAccessList[]=eng +# Each entry consists of the hostname;uri;accessname[;start|end|part|strict] #HostUriMatchMapItems[] -#HostUriMatchMapItems[]=www.xxxxxxxx.de;x_de -#HostUriMatchMapItems[]=www.xxxxxxxx.de;xx_de +#HostUriMatchMapItems[]=www.xxxxxxxx.de;de;x_de +#HostUriMatchMapItems[]=www.xxxxxxxx.de;;xx_de MainNodeOnly=false # include or exclude objects of classes listed in ClassFilterArray