Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from Dolphiq/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
johanzandstra authored Jan 18, 2018
2 parents b8df180 + f30a78c commit d69b940
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# sitemap Changelog
## 1.0.7 - 2018-01-18

### Fixed
- Fixed bug with multi-site setup configured in de config files

### Changed
- Make more use of the Craft framework for future compatibility

## 1.0.6 - 2018-01-18
### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ To install the plugin, follow these instructions.


## XML-sitemap Roadmap
- Settings to enable /disable and split the entries in the xml on a site basis (for multi site setup)
- User (custom) url entry section
- Provide a way hide entries from the list
- Add a Ping for search engines
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dolphiq/sitemap",
"description": "Craft 3 plugin that provides an easy way to provide and manage a XML sitemap for search engines like Google and Bing",
"type": "craft-plugin",
"version": "1.0.6",
"version": "1.0.7",
"keywords": [
"craft",
"cms",
Expand Down
40 changes: 22 additions & 18 deletions src/controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Craft;
use craft\db\Query;
use craft\web\Controller;
use craft\helpers\UrlHelper;

use Jaybizzle\CrawlerDetect\CrawlerDetect;

Expand Down Expand Up @@ -48,6 +49,20 @@ class SitemapController extends Controller
// Public Methods
// =========================================================================


/**
* @inheritdoc
*/
private function getUrl($uri, $siteId)
{
if ($uri !== null) {
$path = ($uri === '__home__') ? '' : $uri;
return UrlHelper::siteUrl($path, null, null, $siteId);
}

return null;
}

/**
* Handle a request going to our plugin's index action URL,
* e.g.: actions/sitemap/default
Expand Down Expand Up @@ -82,15 +97,10 @@ public function actionIndex()
$urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$dom->appendChild($urlset);

$siteurl = isset(Craft::$app->config->general)
&& isset(Craft::$app->config->general->siteUrl)
? Craft::$app->config->general->siteUrl
: null;

foreach($this->_createEntrySectionQuery()->all() as $item) {
$baseurl = rtrim($siteurl ?: $item['baseurl'], '/') . '/';
$loc = $baseurl . ($item['uri'] === '__home__' ? '' : $item['uri']);

$loc = $this->getUrl($item['uri'], $item['siteId']);
if($loc === null) continue;
$url = $dom->createElement('url');
$urlset->appendChild($url);
$url->appendChild($dom->createElement('loc', $loc));
Expand All @@ -102,8 +112,8 @@ public function actionIndex()
}

foreach($this->_createEntryCategoryQuery()->all() as $item) {
$baseurl = rtrim($siteurl ?: $item['baseurl'], '/') . '/';
$loc = $baseurl . ($item['uri'] === '__home__' ? '' : $item['uri']);
$loc = $this->getUrl($item['uri'], $item['siteId']);
if($loc === null) continue;

$url = $dom->createElement('url');
$urlset->appendChild($url);
Expand All @@ -123,9 +133,7 @@ private function _createEntrySectionQuery(): Query
->select([
'elements_sites.uri uri',
'elements_sites.dateUpdated dateUpdated',
'sites.baseurl',

'sitemap_entries.id sitemapEntryId',
'elements_sites.siteId',
'sitemap_entries.changefreq changefreq',
'sitemap_entries.priority priority',
])
Expand All @@ -148,9 +156,7 @@ private function _createEntryCategoryQuery(): Query

'elements_sites.uri uri',
'elements_sites.dateUpdated dateUpdated',
'sites.baseurl',

'sitemap_entries.id sitemapEntryId',
'elements_sites.siteId',
'sitemap_entries.changefreq changefreq',
'sitemap_entries.priority priority',
])
Expand All @@ -160,11 +166,9 @@ private function _createEntryCategoryQuery(): Query
->innerJoin('{{%elements}} elements', '[[elements.id]] = [[categories.id]] AND [[elements.enabled]] = 1')
->innerJoin('{{%elements_sites}} elements_sites', '[[elements_sites.elementId]] = [[elements.id]] AND [[elements_sites.enabled]] = 1')
->innerJoin('{{%sites}} sites', '[[elements_sites.siteId]] = [[sites.id]]')

->groupBy(['elements_sites.id']);
}


}

?>

0 comments on commit d69b940

Please sign in to comment.