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 6dc9d26 + 4d6e218 commit 8a830f2
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 110 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.3.0"></a>
# [1.3.0](https://github.com/flextype-plugins/themes-admin/compare/v1.2.0...v1.3.0) (2020-08-19)

### Features

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

<a name="1.2.0"></a>
# [1.2.0](https://github.com/flextype-plugins/themes-admin/compare/v1.1.0...v1.2.0) (2020-08-06)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Themes Admin 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/themes-admin.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/themes-admin"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/themes-admin"><img src="https://img.shields.io/github/downloads/flextype-plugins/themes-admin/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="https://crowdin.com/project/flextype-plugin-themes-admin"><img src="https://d322cqt584bo4o.cloudfront.net/flextype-plugin-themes-admin/localized.svg?color=black" alt="Crowdin"></a> <a href="https://scrutinizer-ci.com/g/flextype-plugins/themes-admin?branch=dev&color=black"><img src="https://img.shields.io/scrutinizer/g/flextype-plugins/themes-admin.svg?branch=dev" alt="Quality Score"></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/themes-admin.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/themes-admin"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/themes-admin"><img src="https://img.shields.io/github/downloads/flextype-plugins/themes-admin/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="https://crowdin.com/project/flextype-plugin-themes-admin"><img src="https://d322cqt584bo4o.cloudfront.net/flextype-plugin-themes-admin/localized.svg?color=black" alt="Crowdin"></a> <a href="https://scrutinizer-ci.com/g/flextype-plugins/themes-admin?branch=dev&color=black"><img src="https://img.shields.io/scrutinizer/g/flextype-plugins/themes-admin.svg?branch=dev" alt="Quality Score"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
</p>

Themes Admin plugin to manage site themes for the website frontend.
Expand All @@ -12,7 +12,7 @@ The following dependencies need to be installed for Themes Admin Plugin.

| 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) |
| [admin](https://github.com/flextype-plugins/icon) | >=1.0.0 | [download](https://github.com/flextype-plugins/admin/releases) |
| [form](https://github.com/flextype-plugins/form) | >=1.0.0 | [download](https://github.com/flextype-plugins/form/releases) |
Expand Down
101 changes: 52 additions & 49 deletions app/Controllers/TemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
use function date;
use function Flextype\Component\I18n\__;

use Flextype\App\Foundation\Container;

/**
* @property twig $twig
* @property Router $router
* @property Cache $cache
* @property Themes $themes
* @property Slugify $slugify
* @property Flash $flash
*/
class TemplatesController extends Container
class TemplatesController
{
/**
* Flextype Application
*/
protected $flextype;

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

/**
* Index page
*
Expand All @@ -33,29 +36,29 @@ public function index(/** @scrutinizer ignore-unused */ Request $request, Respon
// Get theme from request query params
$theme = $request->getQueryParams()['theme'];

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/themes-admin/templates/extends/themes/templates/index.html',
[
'menu_item' => 'themes',
'theme' => $theme,
'templates_list' => $this->themes->getTemplates($theme),
'partials_list' => $this->themes->getPartials($theme),
'templates_list' => $this->flextype->container('themes')->getTemplates($theme),
'partials_list' => $this->flextype->container('themes')->getPartials($theme),
'links' => [
'themes' => [
'link' => $this->router->pathFor('admin.themes.index'),
'link' => $this->flextype->container('router')->pathFor('admin.themes.index'),
'title' => __('themes_admin_themes'),

],
'templates' => [
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme,
'title' => __('themes_admin_templates'),
'active' => true
],
],
'buttons' => [
'templates_create' => [
'link' => $this->router->pathFor('admin.templates.add') . '?theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.add') . '?theme=' . $theme,
'title' => __('themes_admin_create_new_template'),

],
Expand All @@ -75,25 +78,25 @@ public function add(/** @scrutinizer ignore-unused */ Request $request, Response
// Get theme from request query params
$theme = $request->getQueryParams()['theme'];

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/themes-admin/templates/extends/themes/templates/add.html',
[
'menu_item' => 'themes',
'theme' => $theme,
'links' => [
'themes' => [
'link' => $this->router->pathFor('admin.themes.index'),
'link' => $this->flextype->container('router')->pathFor('admin.themes.index'),
'title' => __('themes_admin_themes'),

],
'templates' => [
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme,
'title' => __('themes_admin_templates'),

],
'templates_add' => [
'link' => $this->router->pathFor('admin.templates.add') . '?theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.add') . '?theme=' . $theme,
'title' => __('themes_admin_create_new_template'),
'active' => true
],
Expand All @@ -117,26 +120,26 @@ public function addProcess(Request $request, Response $response) : Response
$type = $post_data['type'];
$theme = $post_data['theme'];

$file = PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $this->slugify->slugify($id) . '.html';
$file = PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $this->flextype->container('slugify')->slugify($id) . '.html';

if (! Filesystem::has($file)) {
if (Filesystem::write(
$file,
''
)) {
$this->flash->addMessage('success', __('themes_admin_message_' . $type . '_created'));
$this->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_created'));
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_created'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_created'));
}
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_created'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_created'));
}

if (isset($post_data['create-and-edit'])) {
return $response->withRedirect($this->router->pathFor('admin.templates.edit') . '?theme=' . $theme . '&type=' . $type . '&id=' . $id);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.templates.edit') . '?theme=' . $theme . '&type=' . $type . '&id=' . $id);
}

return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme);
}

/**
Expand All @@ -151,7 +154,7 @@ public function edit(Request $request, Response $response) : Response
$type = $request->getQueryParams()['type'];
$theme = $request->getQueryParams()['theme'];

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/themes-admin/templates/extends/themes/templates/edit.html',
[
Expand All @@ -162,17 +165,17 @@ public function edit(Request $request, Response $response) : Response
'type' => ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template'),
'links' => [
'themes' => [
'link' => $this->router->pathFor('admin.themes.index'),
'link' => $this->flextype->container('router')->pathFor('admin.themes.index'),
'title' => __('themes_admin_themes'),

],
'templates' => [
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme,
'title' => __('themes_admin_templates'),

],
'templates_editor' => [
'link' => $this->router->pathFor('admin.templates.edit') . '?id=' . $request->getQueryParams()['id'] . '&type=' . ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template') . '&theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.edit') . '?id=' . $request->getQueryParams()['id'] . '&type=' . ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template') . '&theme=' . $theme,
'title' => __('admin_editor'),
'active' => true
],
Expand Down Expand Up @@ -202,12 +205,12 @@ public function editProcess(Request $request, Response $response) : Response
$type = $request->getParsedBody()['type'];

if (Filesystem::write(PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html', $request->getParsedBody()['data'])) {
$this->flash->addMessage('success', __('themes_admin_message_' . $type . '_saved'));
$this->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_saved'));
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_saved'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_saved'));
}

return $response->withRedirect($this->router->pathFor('admin.templates.edit') . '?id=' . $id . '&type=' . $type . '&theme=' . $theme);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.templates.edit') . '?id=' . $id . '&type=' . $type . '&theme=' . $theme);
}

/**
Expand All @@ -221,7 +224,7 @@ public function rename(Request $request, Response $response) : Response
// Get theme from request query params
$theme = $request->getQueryParams()['theme'];

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/themes-admin/templates/extends/themes/templates/rename.html',
[
Expand All @@ -232,17 +235,17 @@ public function rename(Request $request, Response $response) : Response
'type_current' => ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template'),
'links' => [
'themes' => [
'link' => $this->router->pathFor('admin.themes.index'),
'link' => $this->flextype->container('router')->pathFor('admin.themes.index'),
'title' => __('themes_admin_themes'),

],
'templates' => [
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme,
'title' => __('themes_admin_templates'),

],
'templates_rename' => [
'link' => $this->router->pathFor('admin.templates.rename') . '?id=' . $request->getQueryParams()['id'] . '&type=' . ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template') . '&theme=' . $theme,
'link' => $this->flextype->container('router')->pathFor('admin.templates.rename') . '?id=' . $request->getQueryParams()['id'] . '&type=' . ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template') . '&theme=' . $theme,
'title' => __('admin_rename'),
'active' => true
],
Expand All @@ -263,21 +266,21 @@ public function renameProcess(Request $request, Response $response) : Response
$theme = $request->getParsedBody()['theme'];
$type = $request->getParsedBody()['type_current'];

if (! Filesystem::has(PATH['project'] . '/themes/' . $this->registry->get('plugins.site.settings.theme') . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html')) {
if (! Filesystem::has(PATH['project'] . '/themes/' . $this->flextype->container('registry')->get('plugins.site.settings.theme') . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html')) {
if (Filesystem::rename(
PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()['id_current'] . '.html',
PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html'
)
) {
$this->flash->addMessage('success', __('themes_admin_message_' . $type . '_renamed'));
$this->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_renamed'));
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
}
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
}

return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme);
}

/**
Expand All @@ -295,12 +298,12 @@ public function deleteProcess(Request $request, Response $response) : Response
$file_path = PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '.html';

if (Filesystem::delete($file_path)) {
$this->flash->addMessage('success', __('themes_admin_message_' . $type . '_deleted'));
$this->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_deleted'));
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_deleted'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_deleted'));
}

return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme);
}

/**
Expand All @@ -319,12 +322,12 @@ public function duplicateProcess(Request $request, Response $response) : Respons
$file_path_new = PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '-duplicate-' . date('Ymd_His') . '.html';

if (Filesystem::copy($file_path, $file_path_new)) {
$this->flash->addMessage('success', __('themes_admin_message_' . $type . '_duplicated'));
$this->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_duplicated'));
} else {
$this->flash->addMessage('error', __('themes_admin_message_' . $type . '_was_not_duplicated'));
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_duplicated'));
}

return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.templates.index') . '?theme=' . $theme);
}

private function _type_location($type)
Expand Down
Loading

0 comments on commit 8a830f2

Please sign in to comment.