Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
Edit savefile processor
Browse files Browse the repository at this point in the history
  • Loading branch information
sergant210 committed Sep 3, 2015
1 parent a3038f5 commit c58536c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/components/console/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$_lang['console_err_file_nf'] = 'The file does not exist!';
$_lang['console_err_files_nf'] = 'Did not find any files!';
$_lang['console_err_file_ns'] = 'File is not specified!';
$_lang['console_err_file_nsp'] = 'Specify the file name!';
$_lang['console_err_snippet_ns'] = 'No snippet specified!';
$_lang['console_err_snippet_nf'] = 'Snippet not found!';
$_lang['console_err_snippet_ae'] = 'Snippet already exists!';
1 change: 1 addition & 0 deletions core/components/console/lexicon/ru/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$_lang['console_err_file_nf'] = 'Файл не найден!';
$_lang['console_err_files_nf'] = 'Файлы не найдены!';
$_lang['console_err_file_ns'] = 'Файл не выбран!';
$_lang['console_err_file_nsp'] = 'Укажите имя файла!';
$_lang['console_err_snippet_ns'] = 'Сниппет не выбран!';
$_lang['console_err_snippet_nf'] = 'Сниппет не найден!';
$_lang['console_err_snippet_ae'] = 'Сниппет с таким именем уже существует!';
18 changes: 15 additions & 3 deletions core/components/console/processors/savefile.class.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
<?php

class ConsoleSaveFileProcessor extends modProcessor{

public $permission = 'console.save_file';

public function process() {
$code = trim($this->getProperty('code',''));
$fileName = basename(trim($this->getProperty('name','')));
$fileName = $this->modx->sanitizeString($fileName);
if (empty($fileName)) {
$this->addFieldError('name',$this->modx->lexicon('console_err_file_nsp'));
return $this->failure($this->modx->lexicon('console_err_file_nsp'));
}

$path = $this->modx->getOption('console_core_path', NULL, $this->modx->getOption('core_path') . 'components/console/').'files/';
if (!is_dir($path) && !mkdir($path,0755)) $this->failure($this->modx->lexicon('console_err_path_nf'));
if (!empty($code) && $fileName) file_put_contents($path.$fileName.'.php', $code );

$file = $path . $fileName . '.php';
if (!empty($code)) {
file_put_contents($file, $code);
} else {
unlink($file);
}

return $this->success();
}
Expand Down
3 changes: 3 additions & 0 deletions manager/components/console/js/widgets/console.panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Ext.extend(ModConsole.panel.CodeEditor,MODx.Panel, {
}, {
xtype: 'textfield',
name: 'name',
allowBlank: false,
value: ModConsole.snippetName || 'test',
anchor: '100%'
}, {
Expand Down Expand Up @@ -356,6 +357,7 @@ Ext.extend(ModConsole.panel.CodeEditor,MODx.Panel, {
}, {
xtype: 'textfield',
name: 'name',
allowBlank: false,
fieldLabel: _('console_enter_file_name'),
value: ModConsole.fileName || 'test',
anchor: '100%'
Expand Down Expand Up @@ -385,6 +387,7 @@ ModConsole.window.SaveCode = function (config) {

Ext.applyIf(config, {
width: 300,
autoHeight: true,
modal: true,
url: 'components/console/connectors/console.php',
keys: [{
Expand Down

0 comments on commit c58536c

Please sign in to comment.