Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Groessing committed Feb 6, 2018
2 parents f4ad383 + 0de4903 commit 8435197
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and starting with version 1.0.0 this project adheres to
[Semantic Versioning](http://semver.org/).

## [1.2.1] - 2018-02-06

### Added
- Fixed locale handling

## [1.2.0] - 2018-02-06

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ $lastmod = new DateTime('now');
craft()->sitemap->addUrl($loc, $lastmod, Sitemap_ChangeFrequency::Yearly, 0.1);
```

##### `addElement(BaseElementModel $element, [$changefreq, [$priority, [$allLocales, [$alternateUrls]]]])`
##### `addElement(BaseElementModel $element, [$changefreq, [$priority, [$currentLocaleOnly, [$alternateUrls]]]])`
Adds an element to the sitemap.

```php
$element = craft()->elements->getElementById(2);
craft()->sitemap->addElement($element, Sitemap_ChangeFrequency::Daily, 1.0);
```

##### `addSection(SectionModel $section, [$changefreq, [$priority, [$allLocales, [$alternateUrls]]]])`
##### `addSection(SectionModel $section, [$changefreq, [$priority, [$currentLocaleOnly, [$alternateUrls]]]])`
Adds all entries in the section to the sitemap.

```php
$section = craft()->sections->getSectionByHandle('homepage');
craft()->sitemap->addSection($section, Sitemap_ChangeFrequency::Weekly, 1.0);
```

##### `addCategoryGroup(CategoryGroupModel $categoryGroup, [$changefreq, [$priority, [$allLocales, [$alternateUrls]]]])`
##### `addCategoryGroup(CategoryGroupModel $categoryGroup, [$changefreq, [$priority, [$currentLocaleOnly, [$alternateUrls]]]])`
Adds all categories in the group to the sitemap.

```php
Expand Down
2 changes: 1 addition & 1 deletion SitemapPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getName()
*/
public function getVersion()
{
return '1.2.0';
return '1.2.1';
}

/**
Expand Down
8 changes: 8 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[
{
"version": "1.2.1",
"downloadUrl": "https://github.com/groe/craft-sitemap/archive/v1.2.1.zip",
"date": "2018-02-06T13:40:00+01:00",
"notes": [
"[Fixed] Locale handling"
]
},
{
"version": "1.2.0",
"downloadUrl": "https://github.com/groe/craft-sitemap/archive/v1.2.0.zip",
Expand Down
34 changes: 17 additions & 17 deletions services/SitemapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,26 @@ public function addUrl($loc, $lastmod, $changefreq = null, $priority = null)
* @param string $changefreq
* @param string $priority
*/
public function addElement(BaseElementModel $element, $changefreq = null, $priority = null, $allLocales = false, $alternateUrls = false)
public function addElement(BaseElementModel $element, $changefreq = null, $priority = null, $currentLocaleOnly = false, $alternateUrls = false)
{
$locales = craft()->elements->getEnabledLocalesForElement($element->id);
$locale_urls = array();
foreach ($locales as $locale) {
$locale_urls[$locale] = craft()->sitemap->getElementUrlForLocale($element, $locale);
}

if($allLocales) {
if($currentLocaleOnly) {
// Render sitemap for one specific locale only (single locale domain), e.g. example.de/sitemap.xml

$url = $this->addUrl($element->url, $element->dateUpdated, $changefreq, $priority);

if($alternateUrls) {
foreach ($locale_urls as $locale => $locale_url) {
$url->addAlternateUrl($locale, $locale_url);
}
}
}
else {
// Render sitemap for all locales (multi-locale domain), e.g. example.com/sitemap.xml

foreach ($locale_urls as $locale => $locale_url) {
Expand All @@ -137,17 +148,6 @@ public function addElement(BaseElementModel $element, $changefreq = null, $prior
}
}
}
else {
// Render sitemap for one specific locale only (single locale domain), e.g. example.de/sitemap.xml

$url = $this->addUrl($element->url, $element->dateUpdated, $changefreq, $priority);

if($alternateUrls) {
foreach ($locale_urls as $locale => $locale_url) {
$url->addAlternateUrl($locale, $locale_url);
}
}
}
}

/**
Expand All @@ -157,15 +157,15 @@ public function addElement(BaseElementModel $element, $changefreq = null, $prior
* @param string $changefreq
* @param string $priority
*/
public function addSection(SectionModel $section, $changefreq = null, $priority = null, $includeiffield = null, $allLocales = false, $alternateUrls = false)
public function addSection(SectionModel $section, $changefreq = null, $priority = null, $includeiffield = null, $currentLocaleOnly = false, $alternateUrls = false)
{
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = $section;
if($includeiffield != null && !empty($includeiffield)) {
$criteria->$includeiffield = 1;
}
foreach ($criteria->find(['limit' => -1]) as $element) {
$this->addElement($element, $changefreq, $priority, $allLocales, $alternateUrls);
$this->addElement($element, $changefreq, $priority, $currentLocaleOnly, $alternateUrls);
}
}

Expand All @@ -176,14 +176,14 @@ public function addSection(SectionModel $section, $changefreq = null, $priority
* @param string $changefreq
* @param string $priority
*/
public function addCategoryGroup(CategoryGroupModel $categoryGroup, $changefreq = null, $priority = null, $allLocales = false, $alternateUrls = false)
public function addCategoryGroup(CategoryGroupModel $categoryGroup, $changefreq = null, $priority = null, $currentLocaleOnly = false, $alternateUrls = false)
{
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->group = $categoryGroup->handle;

$categories = $criteria->find(['limit' => -1]);
foreach ($categories as $category) {
$this->addElement($category, $changefreq, $priority, $allLocales, $alternateUrls);
$this->addElement($category, $changefreq, $priority, $currentLocaleOnly, $alternateUrls);
}
}

Expand Down

0 comments on commit 8435197

Please sign in to comment.