Skip to content

Commit

Permalink
=
Browse files Browse the repository at this point in the history
  • Loading branch information
arikaim committed Jan 29, 2022
1 parent 1cd8773 commit 3f91ffc
Show file tree
Hide file tree
Showing 31 changed files with 582 additions and 582 deletions.
24 changes: 12 additions & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: arikaim-cms
ko_fi: arikaim
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: arikaim-cms
ko_fi: arikaim
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
2 changes: 1 addition & 1 deletion arikaim-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "user",
"description": "Theme editor.",
"short-description": "Theme editor.",
"version": "1.2.5",
"version": "1.2.6",
"repository": "https://github.com/arikaim/theme-editor-extension.git",
"position": "10",
"require": {
Expand Down
232 changes: 116 additions & 116 deletions controllers/FilesControlPanel.php
Original file line number Diff line number Diff line change
@@ -1,116 +1,116 @@
<?php
/**
* Arikaim
*
* @link http://www.arikaim.com
* @copyright Copyright (c) Konstantin Atanasov <info@arikaim.com>
* @license http://www.arikaim.com/license
*
*/
namespace Arikaim\Extensions\Editor\Controllers;

use Arikaim\Core\Utils\File;
use Arikaim\Core\Controllers\ControlPanelApiController;

/**
* Files control panel controller
*/
class FilesControlPanel extends ControlPanelApiController
{
/**
* Init controller
*
* @return void
*/
public function init()
{
$this->loadMessages('editor::admin.messages');
}

/**
* Load template file (css,js)
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param Validator $data
* @return Psr\Http\Message\ResponseInterface
*/
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();
}

/**
* Save template file (css,js)
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param Validator $data
* @return Psr\Http\Message\ResponseInterface
*/
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();
}
}
<?php
/**
* Arikaim
*
* @link http://www.arikaim.com
* @copyright Copyright (c) Konstantin Atanasov <info@arikaim.com>
* @license http://www.arikaim.com/license
*
*/
namespace Arikaim\Extensions\Editor\Controllers;

use Arikaim\Core\Utils\File;
use Arikaim\Core\Controllers\ControlPanelApiController;

/**
* Files control panel controller
*/
class FilesControlPanel extends ControlPanelApiController
{
/**
* Init controller
*
* @return void
*/
public function init()
{
$this->loadMessages('editor::admin.messages');
}

/**
* Load template file (css,js)
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param Validator $data
* @return Psr\Http\Message\ResponseInterface
*/
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();
}

/**
* Save template file (css,js)
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param Validator $data
* @return Psr\Http\Message\ResponseInterface
*/
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();
}
}
Loading

0 comments on commit 3f91ffc

Please sign in to comment.