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 8a830f2 + 0a35787 commit 419d495
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 101 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/themes-admin/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/themes-admin/compare/v1.2.0...v1.3.0) (2020-08-19)

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.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>
<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.11-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.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) |
| [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
87 changes: 41 additions & 46 deletions app/Controllers/TemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@

class TemplatesController
{
/**
* Flextype Application
*/
protected $flextype;

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

}

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

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

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

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

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

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

],
'templates_add' => [
'link' => $this->flextype->container('router')->pathFor('admin.templates.add') . '?theme=' . $theme,
'link' => flextype('router')->pathFor('admin.templates.add') . '?theme=' . $theme,
'title' => __('themes_admin_create_new_template'),
'active' => true
],
Expand All @@ -120,26 +115,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->flextype->container('slugify')->slugify($id) . '.html';
$file = PATH['project'] . '/themes/' . $theme . '/' . $this->_type_location($type) . flextype('slugify')->slugify($id) . '.html';

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

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

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

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

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

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

],
'templates_editor' => [
'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,
'link' => flextype('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 @@ -205,12 +200,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->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_saved'));
flextype('flash')->addMessage('success', __('themes_admin_message_' . $type . '_saved'));
} else {
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_saved'));
flextype('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_saved'));
}

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

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

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

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

],
'templates_rename' => [
'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,
'link' => flextype('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 @@ -266,21 +261,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->flextype->container('registry')->get('plugins.site.settings.theme') . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html')) {
if (! Filesystem::has(PATH['project'] . '/themes/' . flextype('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->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_renamed'));
flextype('flash')->addMessage('success', __('themes_admin_message_' . $type . '_renamed'));
} else {
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
flextype('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
}
} else {
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
flextype('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_renamed'));
}

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

/**
Expand All @@ -298,12 +293,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->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_deleted'));
flextype('flash')->addMessage('success', __('themes_admin_message_' . $type . '_deleted'));
} else {
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_deleted'));
flextype('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_deleted'));
}

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

/**
Expand All @@ -322,12 +317,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->flextype->container('flash')->addMessage('success', __('themes_admin_message_' . $type . '_duplicated'));
flextype('flash')->addMessage('success', __('themes_admin_message_' . $type . '_duplicated'));
} else {
$this->flextype->container('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_duplicated'));
flextype('flash')->addMessage('error', __('themes_admin_message_' . $type . '_was_not_duplicated'));
}

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

private function _type_location($type)
Expand Down
Loading

0 comments on commit 419d495

Please sign in to comment.