Skip to content

Commit

Permalink
=
Browse files Browse the repository at this point in the history
  • Loading branch information
arikaim committed May 2, 2024
1 parent ca816e3 commit 8efaf99
Show file tree
Hide file tree
Showing 36 changed files with 136 additions and 392 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: arikaim
patreon: # Replace with a single Patreon username
open_collective: arikaim-cms
ko_fi: arikaim
Expand Down
6 changes: 2 additions & 4 deletions Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Arikaim\Core\Extension\Extension;

/**
* Theme editor extension
* Template editor extension
*/
class Editor extends Extension
{
Expand All @@ -22,9 +22,7 @@ class Editor extends Extension
* @return void
*/
public function install()
{
// Editor page
$this->addPageRoute('/admin/editor/{theme}/{page}','EditorPage','showEditor','editor::page-editor',null,'editorPage',false);
{
// Control Panel
$this->addApiRoute('PUT','/api/admin/editor/load/component/file','EditorControlPanel','loadComponentFile','session');
$this->addApiRoute('PUT','/api/admin/editor/save/component/file','EditorControlPanel','saveComponentFile','session');
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Arikaim CMS Theme Editor Extension
## Arikaim CMS Template Editor Extension
![version: 1.0.0](https://img.shields.io/github/release/arikaim/theme-editor-extension.svg)
![license: GPL3](https://img.shields.io/badge/License-GPLv3-blue.svg)



Arikaim CMS theme editor extension
Arikaim CMS template editor extension


#### Requirements
Expand Down
12 changes: 6 additions & 6 deletions arikaim-package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"title": "Theme Editor",
"title": "Template Editor",
"name": "editor",
"package-type": "extension",
"type": "user",
"description": "Theme editor.",
"short-description": "Theme editor.",
"version": "1.3.0",
"description": "Template editor.",
"short-description": "Template editor.",
"version": "1.3.1",
"repository": "https://github.com/arikaim/theme-editor-extension.git",
"position": "10",
"require": {
Expand All @@ -17,9 +17,9 @@
]
},
"admin-menu": {
"title": "Theme Editor",
"title": "Editor",
"icon": "edit",
"page-title": "Theme Editor",
"page-title": "Template Editor",
"page-icon": "edit",
"component": "editor::admin"
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "arikaim/theme-editor-extension",
"description": "Arikaim CMS theme editor extension",
"keywords": ["Extension", "Arikaim CMS theme editor extension","Theme Editor","Arikaim","CMS"],
"description": "Arikaim CMS template editor extension",
"keywords": ["Extension", "Arikaim CMS template editor extension","Template Editor","Arikaim","CMS"],
"type": "arikaim-extension",
"license": "GPL-3.0-or-later",
"authors": [{
Expand Down
112 changes: 55 additions & 57 deletions controllers/FilesControlPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,34 @@ public function init()
*/
public function loadFileController($request, $response, $data)
{
$this->onDataValid(function($data) {
$theme = $data->get('theme');
$type = $data->get('type','css');
$fileName = $data->get('name');

$packageManager = $this->get('packages')->create('template');
$package = $packageManager->createPackage($theme);
if (\is_object($package) == false) {
$this->error('errors.theme_name');
return false;
}
$properties = $package->getProperties(true);
$filePath = $properties['path'] . $type . DIRECTORY_SEPARATOR . $fileName;

$fileContent = File::read($filePath);

$this->setResponse(($fileContent != null),function() use($fileName,$theme,$fileContent,$type) {
$this
->message('file.load')
->field('theme',$theme)
->field('type',$type)
->field('file_name',$fileName)
->field('content',$fileContent);
},'errors.load');
});
$data
->addRule('text:min=2','theme')
->addRule('text:min=1','file_name')
->validate();
->validate(true);

$theme = $data->get('theme');
$type = $data->get('type','css');
$fileName = $data->get('name');

$packageManager = $this->get('packages')->create('template');
$package = $packageManager->createPackage($theme);
if (\is_object($package) == false) {
$this->error('errors.theme_name');
return false;
}
$properties = $package->getProperties(true);
$filePath = $properties['path'] . $type . DIRECTORY_SEPARATOR . $fileName;

$fileContent = File::read($filePath);

$this->setResponse(($fileContent != null),function() use($fileName,$theme,$fileContent,$type) {
$this
->message('file.load')
->field('theme',$theme)
->field('type',$type)
->field('file_name',$fileName)
->field('content',$fileContent);
},'errors.load');
}

/**
Expand All @@ -78,39 +77,38 @@ public function loadFileController($request, $response, $data)
*/
public function saveFileController($request, $response, $data)
{
$this->onDataValid(function($data) {
$theme = $data->get('theme');
$type = $data->get('type','css');
$fileName = $data->get('file_name');
$content = $data->get('content','');

$packageManager = $this->get('packages')->create('template');
$package = $packageManager->createPackage($theme);
if (\is_object($package) == false) {
$this->error('errors.theme_name');
return false;
}
$properties = $package->getProperties(true);
$filePath = $properties['path'] . $type . DIRECTORY_SEPARATOR . $fileName;

if (File::isWritable($filePath) == false) {
File::setWritable($filePath);
}

$result = File::write($filePath,$content);

$this->setResponse($result,function() use($fileName,$theme,$content,$type) {
$this
->message('file.save')
->field('theme',$theme)
->field('type',$type)
->field('file_name',$fileName)
->field('content',$content);
},'errors.file.save');
});
$data
->addRule('text:min=2','theme')
->addRule('text:min=1','file_name')
->validate();
->validate(true);

$theme = $data->get('theme');
$type = $data->get('type','css');
$fileName = $data->get('file_name');
$content = $data->get('content','');

$packageManager = $this->get('packages')->create('template');
$package = $packageManager->createPackage($theme);
if (\is_object($package) == false) {
$this->error('errors.theme_name');
return false;
}
$properties = $package->getProperties(true);
$filePath = $properties['path'] . $type . DIRECTORY_SEPARATOR . $fileName;

if (File::isWritable($filePath) == false) {
File::setWritable($filePath);
}

$result = File::write($filePath,$content);

$this->setResponse($result,function() use($fileName,$theme,$content,$type) {
$this
->message('file.save')
->field('theme',$theme)
->field('type',$type)
->field('file_name',$fileName)
->field('content',$content);
},'errors.file.save');
}
}
77 changes: 39 additions & 38 deletions controllers/PagesControlPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,51 @@ public function init()
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param Validator $data
* @return Psr\Http\Message\ResponseInterface
* @return mixed
*/
public function saveMetatagsController($request, $response, $data)
{
$this->onDataValid(function($data) {
$theme = $data->get('theme');
$language = $data->get('language');
$componentName = $data->get('component_name');
$component = \str_replace('_','.',$componentName);

$packageManager = $this->get('packages')->create('template');
$template = $packageManager->createPackage($theme);
if (\is_object($template) == false) {
$this->error('errors.theme_name');
return false;
}

$translation = $template->readTranslation($component,$language,'pages');
if ($translation === false) {
$this->error('errors.translation.file');
return false;
}

$translation['head']['title'] = $data->get('title','');
$translation['head']['description'] = $data->get('description','');
$translation['head']['keywords'] = $data->get('keywords','');

$path = $template->getComponentPath($componentName,'pages');
$fileName = $template->resolveTranslationFileName($path,$language);

$result = File::write($fileName,Utils::jsonEncode($translation));

$this->setResponse($result,function() use($language,$theme,$componentName) {
$this
->message('metatags.save')
->field('theme',$theme)
->field('component',$componentName)
->field('language',$language);
},'errors.metatags.save');
});
$data
->addRule('text:min=2','theme')
->addRule('text:min=2','language')
->addRule('text:min=1','component_name')
->validate();
->validate(true);

$theme = $data->get('theme');
$language = $data->get('language');
$componentName = $data->get('component_name');
$component = \str_replace('_','.',$componentName);

$packageManager = $this->get('packages')->create('template');
$template = $packageManager->createPackage($theme);
if (\is_object($template) == false) {
$this->error('errors.theme_name');
return false;
}

$translation = $template->readTranslation($component,$language,'pages');
if ($translation === false) {
$this->error('errors.translation.file');
return false;
}

$translation['head']['title'] = $data->get('title','');
$translation['head']['description'] = $data->get('description','');
$translation['head']['keywords'] = $data->get('keywords','');

$path = $template->getComponentPath($componentName,'pages');
$fileName = $template->resolveTranslationFileName($path,$language);

File::setWritable($fileName);

$result = File::write($fileName,Utils::jsonEncode($translation));

$this->setResponse($result,function() use($language,$theme,$componentName) {
$this
->message('metatags.save')
->field('theme',$theme)
->field('component',$componentName)
->field('language',$language);
},'errors.metatags.save');
}
}
File renamed without changes.
5 changes: 2 additions & 3 deletions view/components/admin/admin.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{ component('semantic~tabs',{
items: [
{ id: 'editor_tab', title: labels.editor, icon: 'edit', component: 'editor::admin.editor', active: true },
{ id: 'cpde_tab', title: labels.code, icon: 'code', component: 'editor::admin.code'}
{ id: 'editor_tab', title: labels.editor, icon: 'edit', component: 'editor::admin.code', active: true }
],
menu: { component: 'system:admin.extensions.menu.actions', extension: 'editor' },
content: { component: 'editor::admin.editor' }
content: { component: 'editor::admin.code' }
})
}}
3 changes: 1 addition & 2 deletions view/components/admin/admin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"labels": {
"editor": "Editor",
"code": "Code"
"editor": "Editor"
}
}
4 changes: 1 addition & 3 deletions view/components/admin/code/code.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"labels": {
"theme": "Theme",
"theme": "Template",
"mode": "Mode",
"simple": "Simple",
"advanced": "Advanced",
"text": "Text",
"languages": "Languages"
}
Expand Down
2 changes: 1 addition & 1 deletion view/components/admin/code/content/emails/emails.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"translations": "Language translations"
},
"messages": {
"empty": "No emails in theme."
"empty": "No emails in template."
}
}
35 changes: 20 additions & 15 deletions view/components/admin/code/content/images/help/help.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{{ component('semantic~segment-title',{ title: title, icon: 'info' }) }}
<div class="mt-8">
<div class="flex flex-col">
<div>
<img class="image rounded bordered" src="{{ template_url }}/images/{{ file_name }}">
</div>
<div class="font-bold">
{{ file_name }}
</div>
<div class="ui two column grid">
<div class="column">
{% component 'semantic~panel' %}
<div class="mt-2">
<div class="flex flex-col">
<div>
<img class="image rounded bordered" src="{{ template_url }}/images/{{ file_name }}">
</div>
<div class="font-bold">
{{ file_name }}
</div>
</div>
<h4>{{ labels.code }}</h4>
{{ component('semantic~code',{
language: 'twig',
content: ' <img src="{{ template_url }}/images/' ~ file_name ~ '">'
})
}}
</div>
{% endcomponent %}
</div>
<h4>{{ labels.code }}</h4>
{{ component('semantic~code',{
language: 'twig',
content: ' <img src="{{ template_url }}/images/' ~ file_name ~ '">'
})
}}
</div>
1 change: 1 addition & 0 deletions view/components/admin/code/content/images/help/help.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Image Details",
"icon": "info",
"labels": {
"code": "Template Code"
}
Expand Down
Loading

0 comments on commit 8efaf99

Please sign in to comment.