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 25, 2020
2 parents 49c0c19 + 1aed03b commit 45713c2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 57 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="1.4.0"></a>
# [1.4.0](https://github.com/flextype-plugins/site/compare/v1.3.0...v1.4.0) (2020-08-25)

### Features

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

<a name="1.3.0"></a>
# [1.3.0](https://github.com/flextype-plugins/site/compare/v1.2.0...v1.3.0) (2020-08-19)

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

<p align="center">
<a href="https://github.com/flextype-plugins/site/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/site.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/site"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/site"><img src="https://img.shields.io/github/downloads/flextype-plugins/site/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" 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/site/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/site.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/site"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/site"><img src="https://img.shields.io/github/downloads/flextype-plugins/site/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.11-green.svg" 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>

Site plugin to display entries content on the website frontend.
Expand All @@ -14,7 +14,7 @@ The following dependencies need to be downloaded and installed for Site Plugin.

| Item | Version | Download |
|---|---|---|
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [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) |
| [noir](https://github.com/flextype-themes/noir) | >=1.0.0 | [download](https://github.com/flextype-themes/noir/releases) |

Expand Down Expand Up @@ -92,8 +92,8 @@ You can also reach these same values from a Flextype theme(s) with PHP syntax:
Usage:

```php
$theme_name = $flextype->container('registry')->get('themes.noir.manifest.name');
$theme_version = $flextype->container('registry')->get('themes.noir.manifest.version');
$theme_name = flextype('registry')->get('themes.noir.manifest.name');
$theme_version = flextype('registry')->get('themes.noir.manifest.version');
```

### Accessing Theme Configuration
Expand Down Expand Up @@ -131,7 +131,7 @@ Result:
In PHP you can access the current theme configuration like this:

```php
$highlight = $flextype->container('registry')->get('themes.noir.settings.highlight');
$highlight = flextype('registry')->get('themes.noir.settings.highlight');
```

## LICENSE
Expand Down
39 changes: 13 additions & 26 deletions app/Controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ class SiteController
*/
public $entry = [];

/**
* Flextype
*/
protected $flextype;

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

/**
* Index page
*
Expand All @@ -61,13 +48,13 @@ public function index(Request $request, Response $response, array $args) : Respo

// If uri is empty then it is main entry else use entry uri
if ($uri === '/') {
$entry_uri = $this->flextype->container('registry')->get('plugins.site.settings.entries.main');
$entry_uri = flextype('registry')->get('plugins.site.settings.entries.main');
} else {
$entry_uri = ltrim($uri, '/');
}

// Get entry body
$entry_body = $this->flextype->container('entries')->fetch($entry_uri);
$entry_body = flextype('entries')->fetch($entry_uri);

// is entry not found
$is_entry_not_found = false;
Expand All @@ -91,7 +78,7 @@ public function index(Request $request, Response $response, array $args) : Respo
$this->entry = $entry;

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

// Return in JSON Format
if ($is_json) {
Expand All @@ -103,24 +90,24 @@ public function index(Request $request, Response $response, array $args) : Respo
}

// Set template path for current entry
$path = 'themes/' . $this->flextype->container('registry')->get('plugins.site.settings.theme') . '/' . (empty($this->entry['template']) ? 'templates/default' : 'templates/' . $this->entry['template']) . '.html';
$path = 'themes/' . flextype('registry')->get('plugins.site.settings.theme') . '/' . (empty($this->entry['template']) ? 'templates/default' : 'templates/' . $this->entry['template']) . '.html';

self::includeCurrentThemeBootstrap($this->flextype);
self::includeCurrentThemeBootstrap();

if (! Filesystem::has(PATH['project'] . '/' . $path)) {
return $response->write("Template {$this->entry['template']} not found");
}

if ($is_entry_not_found) {
return $this->flextype->container('twig')->render($response->withStatus(404), $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
return flextype('twig')->render($response->withStatus(404), $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
}

return $this->flextype->container('twig')->render($response, $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
return flextype('twig')->render($response, $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
}

private static function includeCurrentThemeBootstrap($flextype)
private static function includeCurrentThemeBootstrap()
{
$bootstrap_path = 'themes/' . $flextype->container('registry')->get('plugins.site.settings.theme') . '/bootstrap.php';
$bootstrap_path = 'themes/' . flextype('registry')->get('plugins.site.settings.theme') . '/bootstrap.php';

if (Filesystem::has(PATH['project'] . '/' . $bootstrap_path)) {
include_once PATH['project'] . '/' . $bootstrap_path;
Expand All @@ -137,10 +124,10 @@ private static function includeCurrentThemeBootstrap($flextype)
public function error404() : array
{
return [
'title' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.title'),
'description' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.description'),
'content' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.content'),
'template' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.template'),
'title' => flextype('registry')->get('plugins.site.settings.entries.error404.title'),
'description' => flextype('registry')->get('plugins.site.settings.entries.error404.description'),
'content' => flextype('registry')->get('plugins.site.settings.entries.error404.content'),
'template' => flextype('registry')->get('plugins.site.settings.entries.error404.template'),
];
}
}
29 changes: 12 additions & 17 deletions app/Models/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,23 @@

class Themes
{
/**
*
*/
protected $flextype;

/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
* Init themes
*/
public function init($flextype) : void
public function init() : void
{
// Set empty themes list item
$this->flextype->container('registry')->set('themes', []);
flextype('registry')->set('themes', []);

// Get themes list
$themes_list = $this->getThemes();
Expand All @@ -55,8 +50,8 @@ public function init($flextype) : void
$themes_cache_id = $this->getThemesCacheID($themes_list);

// Get themes list from cache or scan themes folder and create new themes cache item in the registry
if ($this->flextype->container('cache')->contains($themes_cache_id)) {
$this->flextype->container('registry')->set('themes', $this->flextype->container('cache')->fetch($themes_cache_id));
if (flextype('cache')->contains($themes_cache_id)) {
flextype('registry')->set('themes', flextype('cache')->fetch($themes_cache_id));
} else {
$themes = [];
$themes_settings = [];
Expand Down Expand Up @@ -91,7 +86,7 @@ public function init($flextype) : void
if (trim($default_theme_settings_file_content) === '') {
$default_theme_settings = [];
} else {
$default_theme_settings = $this->flextype->container('yaml')->decode($default_theme_settings_file_content);
$default_theme_settings = flextype('yaml')->decode($default_theme_settings_file_content);
}

// Create custom theme settings file
Expand All @@ -102,7 +97,7 @@ public function init($flextype) : void
if (trim($custom_theme_settings_file_content) === '') {
$custom_theme_settings = [];
} else {
$custom_theme_settings = $this->flextype->container('yaml')->decode($custom_theme_settings_file_content);
$custom_theme_settings = flextype('yaml')->decode($custom_theme_settings_file_content);
}

// Check if default theme manifest file exists
Expand All @@ -112,7 +107,7 @@ public function init($flextype) : void

// Get default theme manifest content
$default_theme_manifest_file_content = Filesystem::read($default_theme_manifest_file);
$default_theme_manifest = $this->flextype->container('yaml')->decode($default_theme_manifest_file_content);
$default_theme_manifest = flextype('yaml')->decode($default_theme_manifest_file_content);

// Merge theme settings and manifest data
$themes[$theme['dirname']]['manifest'] = $default_theme_manifest;
Expand All @@ -121,14 +116,14 @@ public function init($flextype) : void
}

// Save parsed themes list in the registry themes
$this->flextype->container('registry')->set('themes', $themes);
flextype('registry')->set('themes', $themes);

// Save parsed themes list in the cache
$this->flextype->container('cache')->save($themes_cache_id, $themes);
flextype('cache')->save($themes_cache_id, $themes);
}

// Emit onThemesInitialized
$this->flextype->container('emitter')->emit('onThemesInitialized');
flextype('emitter')->emit('onThemesInitialized');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
/**
* Add themes service to Flextype container
*/
$flextype->container()['themes'] = static function () use ($flextype) {
return new Themes($flextype);
flextype()->container()['themes'] = static function () {
return new Themes();
};

/**
* Init themes
*/
$flextype->container()['themes']->init($flextype);
flextype()->container()['themes']->init();

/**
* Add site controller to Flextype container
*/
$flextype->container()['SiteController'] = static function () use ($flextype) {
return new SiteController($flextype);
flextype()->container()['SiteController'] = static function () {
return new SiteController();
};
2 changes: 1 addition & 1 deletion middlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
/**
* Add middleware TrailingSlash for all routes
*/
$flextype->add((new TrailingSlash(false))->redirect(true));
flextype()->add((new TrailingSlash(false))->redirect(true));
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Site
version: 1.3.0
version: 1.4.0
description: Site plugin to display entries content on the website frontend.
icon: fas fa-globe
author:
Expand All @@ -11,5 +11,5 @@ bugs: https://github.com/flextype-plugins/site/issues
license: MIT

dependencies:
flextype: 0.9.10
flextype: 0.9.11
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 @@ -9,4 +9,4 @@
* file that was distributed with this source code.
*/

$flextype->get('{uri:.+}', 'SiteController:index')->setName('site.index')->add('csrf');
flextype()->get('{uri:.+}', 'SiteController:index')->setName('site.index')->add('csrf');

0 comments on commit 45713c2

Please sign in to comment.