Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 19, 2020
2 parents 851bfde + f9d9639 commit 8493f9a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="2.3.0"></a>
# [2.3.0](https://github.com/flextype-plugins/sitemap/compare/v2.2.0...v2.3.0) (2020-08-19)

### Features

* **core** update code base for new Flextype 0.9.10

<a name="2.2.0"></a>
# [2.2.0](https://github.com/flextype-plugins/sitemap/compare/v2.1.0...v2.2.0) (2020-08-05)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Sitemap Plugin for <a href="https://flextype.org/">Flextype</a></h1>

<p align="center">
<a href="https://github.com/flextype-plugins/themes-admin/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/sitemap.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/sitemap"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/sitemap"><img src="https://img.shields.io/github/downloads/flextype-plugins/sitemap/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.9-green.svg?color=black" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
<a href="https://github.com/flextype-plugins/themes-admin/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/sitemap.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/sitemap"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/sitemap"><img src="https://img.shields.io/github/downloads/flextype-plugins/sitemap/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.10-green.svg?color=black" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
</p>

Sitemap plugin provide automatically generated XML sitemap for Flextype.
Expand All @@ -12,7 +12,7 @@ The following dependencies need to be downloaded and installed for Sitemap Plugi

| Item | Version | Download |
|---|---|---|
| [flextype](https://github.com/flextype/flextype) | 0.9.9 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
| [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |

## Installation
Expand Down Expand Up @@ -65,7 +65,7 @@ sitemap:
```yaml
additions:
-
location: something-special
loc: something-special
lastmod: '2020-04-16'
changefreq: hourly
priority: 0.3
Expand All @@ -74,7 +74,7 @@ additions:
### Dynamically adding entry(entries) to the sitemap
```php
$flextype->emitter->addListener('onSitemapAfterInitialized', function() use ($flextype) {
$flextype->container('emitter')->addListener('onSitemapAfterInitialized', function() use ($flextype) {
$flextype->SitemapController->sitemap[] = ['loc' => 'something-special-to-add',
'lastmod' => '03-07-2020 09:46',
'changefreq' => 'daily',
Expand Down
38 changes: 24 additions & 14 deletions app/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use Flextype\Component\Arrays\Arrays;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Flextype\App\Foundation\Container;

/**
* @property Twig $twig
* @property Entries $entries
*/
class SitemapController extends Container {
class SitemapController {

/**
* Flextype Application
*/
protected $flextype;

/**
* Current $sitemap data array
Expand All @@ -21,6 +21,16 @@ class SitemapController extends Container {
*/
public $sitemap = [];

/**
* Constructor
*
* @access public
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}

/**
* Index page
*
Expand All @@ -32,7 +42,7 @@ public function index(Request $request, Response $response) : Response
{
$sitemap = [];

$entries = collect($this->entries->fetchCollection('', ['depth' => '>0']))->orderBy('modified_at', 'ASC')->all();
$entries = collect($this->flextype->container('entries')->fetchCollection('', ['depth' => '>0']))->orderBy('modified_at', 'ASC')->all();

foreach ($entries as $entry) {

Expand All @@ -55,23 +65,23 @@ public function index(Request $request, Response $response) : Response
if (isset($entry['sitemap']['changefreq'])) {
$entry['changefreq'] = $entry['sitemap']['changefreq'];
} else {
$entry['changefreq'] = $this->registry->get('plugins.sitemap.settings.default.changefreq');
$entry['changefreq'] = $this->flextype->container('registry')->get('plugins.sitemap.settings.default.changefreq');
}

// Check entry priority field
if (isset($entry['sitemap']['priority'])) {
$entry['priority'] = $entry['sitemap']['priority'];
} else {
$entry['priority'] = $this->registry->get('plugins.sitemap.settings.default.priority');
$entry['priority'] = $this->flextype->container('registry')->get('plugins.sitemap.settings.default.priority');
}

// Check ignore list
if (in_array($entry['slug'], (array) $this->registry->get('plugins.sitemap.settings.ignore'))) {
if (in_array($entry['id'], (array) $this->flextype->container('registry')->get('plugins.sitemap.settings.ignore'))) {
continue;
}

// Prepare data
$entry_to_add['loc'] = $entry['slug'];
$entry_to_add['loc'] = $entry['id'];
$entry_to_add['lastmod'] = $entry['modified_at'];
$entry_to_add['changefreq'] = $entry['changefreq'];
$entry_to_add['priority'] = $entry['priority'];
Expand All @@ -81,7 +91,7 @@ public function index(Request $request, Response $response) : Response
}

// Additions
$additions = (array) $this->registry->get('plugins.sitemap.settings.additions');
$additions = (array) $this->flextype->container('registry')->get('plugins.sitemap.settings.additions');
foreach ($additions as $addition) {
$sitemap[] = $addition;
}
Expand All @@ -90,12 +100,12 @@ public function index(Request $request, Response $response) : Response
$this->sitemap = $sitemap;

// Run event onSitemapAfterInitialized
$this->emitter->emit('onSitemapAfterInitialized');
$this->flextype->container('emitter')->emit('onSitemapAfterInitialized');

// Set response header
$response = $response->withHeader('Content-Type', 'application/xml');

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/sitemap/templates/index.html',
[
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"issues": "https://github.com/flextype-plugins/sitemap/issues"
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3.0",
"ext-json": "*"
},
"config": {
"apcu-autoloader": true,
"optimize-autoloader": true,
"platform": {
"php": "7.2.5"
"php": "7.3.0"
}
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

use Flextype\Plugin\Sitemap\Controllers\SitemapController;

$flextype['SitemapController'] = function ($container) {
return new SitemapController($container);
$flextype->container()['SitemapController'] = function () use ($flextype) {
return new SitemapController($flextype);
};
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Sitemap
version: 2.2.0
version: 2.3.0
description: Provide automatically generated XML sitemap.
author:
name: Sergey Romanenko
Expand All @@ -14,5 +14,5 @@ keywords: sitemap, plugin, xml, map, index
license: MIT

dependencies:
flextype: 0.9.9
flextype: 0.9.10
twig: '>=1.0.0'
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Flextype;

$app->get('/' . $flextype->registry->get('plugins.sitemap.settings.route'), 'SitemapController:index')->setName('sitemap.index');
$flextype->get('/' . $flextype->container('registry')->get('plugins.sitemap.settings.route'), 'SitemapController:index')->setName('sitemap.index');

0 comments on commit 8493f9a

Please sign in to comment.