Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'] = 'Сниппет с таким именем уже существует!';
23 changes: 21 additions & 2 deletions core/components/console/processors/savefile.class.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
<?php

class ConsoleSaveFileProcessor extends modProcessor{

public $permission = 'console.save_file';

public function checkPermissions() {
return !empty($this->permission) ? $this->modx->hasPermission($this->permission) : true;
}

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)) 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();
}
}

return 'ConsoleSaveFileProcessor';
return 'ConsoleSaveFileProcessor';
117 changes: 55 additions & 62 deletions manager/components/console/js/widgets/console.panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,67 +110,60 @@ ModConsole.panel.CodeEditor = function(config) {
}
,value: this.getCodeEditorValue()
},{
bodyCssClass: 'panel-desc'
,border: false
,items: [{
xtype: 'button'
, text: _('console_exec')
, listeners: {
click: function () {
this.request();
}
, scope: this
}
},{
xtype: 'button'
,text: _('console_save')
,style: 'marginLeft:10px; float:right'
,menu: {
items: [{
text: _('console_save_to_file'),
handler: function() {
this.saveFile();
},
scope: this
}, {
text: _('console_save_snippet'),
handler: function() {
this.saveSnippet();
},
scope: this
}]
}
,handler: function(){return false;}
}, {
xtype: 'button'
, text: _('console_load')
, style: 'marginLeft:10px; float:right'
, menu: {
items: [{
text: _('console_load_from_file'),
handler: function () {
this.getFiles();
},
scope: this
}, {
text: _('console_load_from_snippet'),
handler: function () {
this.getSnippets();
},
scope: this
}]
}
, handler: function () {
return false;
}
}, {
xtype: 'button'
, text: _('console_clear')
, style: 'float:right'
, handler: function () {
Ext.getCmp('mod-console-codeeditor').setValue('<?php\n');
}
}]
xtype: 'toolbar'
,items: [
{
text: _('console_exec')
,listeners: {
click: function () {
this.request();
}
,scope: this
}
}
,'->'
,{
text: _('console_save')
,menu: {
items: [{
text: _('console_save_to_file'),
handler: function() {
this.saveFile();
},
scope: this
},{
text: _('console_save_snippet'),
handler: function() {
this.saveSnippet();
},
scope: this
}]
}
}
,{
text: _('console_load')
,menu: {
items: [{
text: _('console_load_from_file'),
handler: function () {
this.getFiles();
},
scope: this
},{
text: _('console_load_from_snippet'),
handler: function () {
this.getSnippets();
},
scope: this
}]
}
},{
text: _('console_clear')
,handler: function () {
Ext.getCmp('mod-console-codeeditor').setValue('<?php\n');
}
}
]
},{
xtype: 'modx-vtabs'
,defaults: {
Expand Down Expand Up @@ -513,4 +506,4 @@ ModConsole.combo.Objects = function(config) {
ModConsole.combo.Objects.superclass.constructor.call(this,config);
};
Ext.extend(ModConsole.combo.Objects,MODx.combo.ComboBox);
Ext.reg('console-combo-objects',ModConsole.combo.Objects);
Ext.reg('console-combo-objects',ModConsole.combo.Objects);