Browse Source

Version 1.0

master
M@d D3n 4 years ago
parent
commit
d39e8b5d15
  1. 18
      README.md
  2. 104
      admin/main.tpl
  3. 455
      class/snippets.php
  4. 13
      data/fragment.php
  5. 4
      index.php
  6. 20
      info.php
  7. 381
      js/snippets.js
  8. 34
      lang/ru.txt
  9. 69
      module.php
  10. 19
      sql.php

18
README.md

@ -1,2 +1,18 @@
# module-snippets # Модуль - Сниппеты PHP
###### Позволяет хранить и выполнять произвольный php-код.
## Примеры кода
```php
<?php
// Посмотреть все данные документа
Debug::_echo(get_document(1));
?>
```
## Changelog:
05.07.2020 - Дата создания
---
Copyright © 2007-2020 [Ave-Cms.Ru](https://ave-cms.ru)

104
admin/main.tpl

@ -0,0 +1,104 @@
<script language="Javascript" type="text/javascript">
var session = '{$sess}';
var new_title = '{#CONSOLE_NEW_TITLE#}';
var new_text = '{#CONSOLE_NEW_TEXT#}';
var select_option = '{#CONSOLE_SELECT_FRAGMENT#}';
var del_confirm = '{#CONSOLE_DELETE_CONFIRM#}';
var del_title = '{#CONSOLE_DELETE#}';
var result_dialog = '{#CONSOLE_PERFORMED#}';
</script>
<div class="title">
<h5>{#CONSOLE_MODULE_NAME#}</h5>
</div>
<div class="widget" style="margin-top: 0px;">
<div class="body">
{#CONSOLE_EDIT_TIP#}
</div>
</div>
<div class="breadCrumbHolder module">
<div class="breadCrumb module">
<ul>
<li class="firstB"><a href="index.php" title="{#MAIN_PAGE#}">{#MAIN_PAGE#}</a></li>
<li><a href="index.php?do=modules&amp;cp={$sess}">{#MODULES_SUB_TITLE#}</a></li>
<li><strong class="code">{#CONSOLE_MODULE_NAME#}</strong></li>
</ul>
</div>
</div>
<form id="code" action="index.php?do=modules&action=modedit&mod=snippets&moduleaction=execute&cp={$sess}" method="post" class="mainForm">
<input id="fragmentKey" type="hidden" name="fragment_key" value="">
<div class="widget first">
<div class="head">
<h5 class="iFrames">
{#CONSOLE_MODULE_NAME#}
</h5>
</div>
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="250"/>
<col />
<thead>
<tr>
<td colspan="4">
{#CONSOLE_SETTINGS#}
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
{#CONSOLE_SAVED_FRAGMENTS#}
</td>
<td>
<select id="fargmentNames" name="names" data-search="true" data-search-limit="10">
<option value="">{#CONSOLE_SELECT_FRAGMENT#}</option>
{foreach from=$fragments item=fragment}
<option value="{$fragment.fragment_id}">{$fragment.fragment_name}</option>
{/foreach}
</select>
</td>
<td>
{#CONSOLE_REPORT_EXECUTION#}
</td>
<td>
<input id="profilingCheck" type="checkbox" name="profiling" value="1" />
</td>
</tr>
</tbody>
</table>
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<thead>
<tr>
<td>
{#CONSOLE_MODULE_NAME#}
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<textarea class="mousetrap" id="code_text" name="code_text" style="width:100%; height:400px"></textarea>
</td>
</tr>
</tbody>
</table>
<div class="rowElem" id="saveBtn">
<div class="saveBtn">
<a href="javascript:void(0);" class="button basicBtn Execute">{#CONSOLE_BUTTON_ENTER#}</a>&nbsp;
<a href="javascript:void(0);" class="button greenBtn SaveFragment">{#CONSOLE_BUTTON_SAVE#}</a>&nbsp;
<a href="javascript:void(0);" class="button blackBtn Clear">{#CONSOLE_BUTTON_CLEAR#}</a>&nbsp;
<a href="javascript:void(0);" class="button redBtn Delete hidden">{#CONSOLE_DELETE_FRAGMENT#}</a>
</div>
</div>
</div>
</form>
<script src="{$ABS_PATH}modules/snippets/js/snippets.js" language="Javascript" type="text/javascript"></script>
{include file="$codemirror_connect"}
{include file="$codemirror_editor" textarea_id='code_text' ctrls='ModuleSnippets.saveFragment();' height='300'}

455
class/snippets.php

@ -0,0 +1,455 @@
<?php
/**
* Класс работы с модулем
*
* @package AVE.cms
* @subpackage
* @filesource
*/
class Snippets {
//-- Templates directory
public static $tpl_dir;
//-- Fragment directory
public static $fragmentdir;
//-- Fragment filename
public static $fragmentfile;
//-- Fragments limit
public static $limit = 1000;
/* ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::_json
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function _json ($data, $exit = false)
{
header("Content-Type: application/json;charset=utf-8");
$json = json_encode($data);
if ($json === false)
{
$json = json_encode(array("jsonError", json_last_error_msg()));
if ($json === false)
$json = '{"jsonError": "unknown"}';
http_response_code(500);
}
echo $json;
if ($exit)
exit;
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::_fragment
|-----------------------------------------------------------------------------------------------------------------------
|
*/
private static function _fragment ($key = null)
{
global $AVE_Template;
$fragment_name = (isset($_POST['fragment_name'])
? $_POST['fragment_name']
: $AVE_Template->get_config_vars('CONSOLE_SAVE_NO_NAME'));
$fragment_code = (isset($_POST['fragment_code'])
? base64_encode($_POST['fragment_code'])
: '');
$fragmentdata = [
'fragment_id' => $key,
'fragment_time' => time(),
'fragment_ip' => $_SERVER['REMOTE_ADDR'],
'fragment_user_id' => (isset($_SESSION['user_id']) ? $_SESSION['user_id'] : '0'),
'fragment_name' => $fragment_name,
'fragment_code' => $fragment_code
];
return $fragmentdata;
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::show
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function show ()
{
global $AVE_Template;
$fragmentdata = [];
if (file_exists(self::$fragmentdir . self::$fragmentfile))
include self::$fragmentdir . self::$fragmentfile;
$fragmentdata = msort($fragmentdata, 'fragment_name');
$AVE_Template->assign('fragments', $fragmentdata);
$AVE_Template->assign('content', $AVE_Template->fetch(self::$tpl_dir . 'main.tpl'));
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::execute
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function fragmentExecute ()
{
global $AVE_DB, $AVE_Template;
error_reporting(E_ALL);
ini_set('display_errors', 1);
$profiler = false;
if (isset($_POST['fragment_profiling']) && $_POST['fragment_profiling'] == 1) {
static $list, $time, $count;
$profiler = true;
}
$code = stripslashes($_POST['fragment_code']);
ob_start();
Debug::startMemory('Eval');
Debug::startTime('Eval');
$result = eval(' ?>' . $code . '<?' . 'php ');
$memoryUsage = Debug::endMemory('Eval');
$totalTime = Debug::endTime('Eval');
$out = ob_get_contents();
ob_end_clean();
if ($result)
$out = $result;
if ($profiler)
{
$result_profiler = $AVE_DB->Query("SHOW PROFILES");
$list = "<table width=\"100%\" class=\"tableStatic\" style=\"font-size: 11px; font-family: Consolas, Verdana, Arial;\">"
. "\n\t<col width=\"20\">\n\t<col width=\"70\">";
while ($row = $result_profiler->FetchRow()) {
$time += $row->Duration;
$row->Query = preg_replace('/\t+/', '', $row->Query);
$list .= "\n\t<tr>\n\t\t<td><strong>"
. $row->Query_ID
. "</strong></td>\n\t\t<td><strong>"
. number_format($row->Duration * 1, 6, ',', '')
. "</strong></td>\n\t\t<td style=\"white-space: pre\"><strong>"
. $row->Query
. "</strong></td>\n\t</tr>";
}
$list .= "\n</table>";
$time = number_format($time * 1, 6, ',', '');
$count = $result_profiler->NumRows();
$AVE_DB->Query("SET PROFILING = 0");
$out .= '<ul class="messages"><li class="highlight yellow">';
$out .= "\nВремя выполнения: " . $totalTime;
$out .= "\n<br>Использовано памяти: " . $memoryUsage;
$out .= "\n<br>Количество запросов: " . $count . ' шт. за ' . $time . ' сек.';
$out .= '</li></ul>';
$out .= "\n<br>" . $list;
}
else
{
$out .= '<ul class="messages"><li class="highlight yellow">';
$out .= "\nВремя выполнения: " . $totalTime;
$out .= "\n<br>Использовано памяти: " . $memoryUsage;
$out .= '</li></ul>';
}
echo $out;
exit;
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::fragmentInsert
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function fragmentInsert ()
{
global $AVE_Template;
$fragment_code = '';
$fragmentdata = [];
$fragment_key = (isset($_POST['fragment_key']) && is_numeric($_POST['fragment_key']) OR $_POST['fragment_key'] != '')
? (int) $_POST['fragment_key']
: null;
if (file_exists(self::$fragmentdir . self::$fragmentfile))
include self::$fragmentdir . self::$fragmentfile;
if (isset($fragmentdata[$fragment_key]))
$fragment_code = stripslashes(base64_decode($fragmentdata[$fragment_key]['fragment_code']));
if (isAjax())
{
$success = $fragment_code
? true
: false;
$return = [
'success' => $success,
'fragment_code' => $fragment_code,
'fragment_key' => $fragment_key,
'message' => $success ? $AVE_Template->get_config_vars('CONSOLE_DOWNLOAD_SAVED') : $AVE_Template->get_config_vars('CONSOLE_DOWNLOAD_FALSE'),
'header' => $success ? $AVE_Template->get_config_vars('CONSOLE_SUCCESS') : $AVE_Template->get_config_vars('CONSOLE_ERROR'),
'theme' => $success ? 'accept' : 'error'
];
self::_json($return, true);
} else {
header('Location:index.php?do=modules&action=modedit&mod=snippets&moduleaction=1&cp=' . SESSION);
exit;
}
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::fragmentNew
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function fragmentNew ()
{
global $AVE_Template;
$fragmentdata = [];
$fragmentfile = self::$fragmentdir . self::$fragmentfile;
if (file_exists(self::$fragmentdir . self::$fragmentfile))
include self::$fragmentdir . self::$fragmentfile;
if (empty($fragmentdata))
$_key = 0;
else
$_key = array_pop(array_keys($fragmentdata)) + 1;
$fragmentdata[] = self::_fragment($_key);
$fragmentdata = array_slice($fragmentdata, -1 * self::$limit);
end($fragmentdata);
$fragment_key = key($fragmentdata);
$save_data = '<?php';
$save_data .= PHP_EOL;
$save_data .= '$fragmentdata = ' . var_export($fragmentdata, true);
$save_data .= PHP_EOL;
$save_data .= '?>';
file_put_contents($fragmentfile, $save_data);
$fragmentdata = msort($fragmentdata, 'fragment_name');
$fragments = [];
foreach ($fragmentdata AS $k => $v)
{
if ($v['fragment_id'] == $_key)
$_fragment_key = $v['fragment_id'];
$fragments[$k] = [
'fragment_key' => $v['fragment_id'],
'fragment_name' => $v['fragment_name']
];
}
unset ($fragmentdata, $save_data);
if (isAjax()) {
$return = [
'success' => true,
'key' => $_fragment_key,
'fragments' => $fragments,
'message' => $AVE_Template->get_config_vars('CONSOLE_SAVED'),
'header' => $AVE_Template->get_config_vars('CONSOLE_SUCCESS'),
'theme' => 'accept'
];
self::_json($return, true);
} else {
header('Location:index.php?do=modules&action=modedit&mod=snippets&moduleaction=1&cp=' . SESSION);
exit;
}
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::fragmentSave
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function fragmentSave ()
{
global $AVE_Template;
$fragment_key = (int)$_POST['fragment_key'];
$fragmentdata = [];
$fragmentfile = self::$fragmentdir . self::$fragmentfile;
if (file_exists(self::$fragmentdir . self::$fragmentfile))
include self::$fragmentdir . self::$fragmentfile;
$fragmentdata[$fragment_key]['fragment_code'] = base64_encode($_POST['fragment_code']);
$fragmentdata[$fragment_key]['fragment_changed'] = time();
$fragmentdata = array_slice ($fragmentdata, -1 * self::$limit);
$save_data = '<?php';
$save_data .= PHP_EOL;
$save_data .= '$fragmentdata = ' . var_export($fragmentdata, true);
$save_data .= PHP_EOL;
$save_data .= '?>';
file_put_contents ($fragmentfile, $save_data);
unset ($fragmentdata, $save_data);
if (isAjax())
{
$return = [
'success' => true,
'key' => $fragment_key,
'message' => $AVE_Template->get_config_vars('CONSOLE_SAVED'),
'header' => $AVE_Template->get_config_vars('CONSOLE_SUCCESS'),
'theme' => 'accept'
];
self::_json($return, true);
}
else
{
header('Location:index.php?do=modules&action=modedit&mod=snippets&moduleaction=1&cp=' . SESSION);
exit;
}
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::fragmentDelete
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function fragmentDelete ()
{
global $AVE_Template;
$fragment_key = (int) $_POST['fragment_key'];
$fragmentdata = [];
$fragmentfile = self::$fragmentdir . self::$fragmentfile;
if (file_exists(self::$fragmentdir . self::$fragmentfile))
include self::$fragmentdir . self::$fragmentfile;
foreach ($fragmentdata AS $k => $v)
{
if ($fragment_key == $v['fragment_id'])
unset ($fragmentdata[$k]);
}
$fragmentdata = array_slice($fragmentdata, -1 * self::$limit);
foreach ($fragmentdata AS $k => $v)
{
$v['fragment_id'] = $k;
$fragmentdata[$k] = $v;
}
$save_data = '<?php';
$save_data .= PHP_EOL;
$save_data .= '$fragmentdata = ' . var_export($fragmentdata, true);
$save_data .= PHP_EOL;
$save_data .= '?>';
file_put_contents ($fragmentfile, $save_data);
$fragmentdata = msort($fragmentdata, 'fragment_name');
$fragments = [];
foreach ($fragmentdata AS $k => $v)
$fragments[] = [
'fragment_key' => $v['fragment_id'],
'fragment_name' => $v['fragment_name']
];
unset ($fragmentdata, $save_data);
if (isAjax()) {
$return = [
'success' => true,
'fragments' => $fragments,
'message' => $AVE_Template->get_config_vars('CONSOLE_DEL_SAVED'),
'header' => $AVE_Template->get_config_vars('CONSOLE_SUCCESS'),
'theme' => 'accept'
];
self::_json($return, true);
} else {
header('Location:index.php?do=modules&action=modedit&mod=snippets&moduleaction=1&cp=' . SESSION);
exit;
}
}
/*
|-----------------------------------------------------------------------------------------------------------------------
| self::fragmentsShow
|-----------------------------------------------------------------------------------------------------------------------
|
*/
public static function fragmentsShow ()
{
//ToDo
}
}
?>

13
data/fragment.php

@ -0,0 +1,13 @@
<?php
$fragmentdata = array (
0 =>
array (
'fragment_id' => 0,
'fragment_time' => 1596529593,
'fragment_ip' => '::1',
'fragment_user_id' => 1,
'fragment_name' => 'Данные документа',
'fragment_code' => 'PD9waHAKCURlYnVnOjpfZWNobyhnZXRfZG9jdW1lbnQoMSkpOwo/Pg==',
),
)
?>

4
index.php

@ -0,0 +1,4 @@
<?php
header('Location:/');
exit;
?>

20
info.php

@ -0,0 +1,20 @@
<?php
if (! defined('BASE_DIR'))
exit;
$module = [
'ModuleSysName' => 'snippets',
'ModuleVersion' => '1.0',
'ModuleAutor' => 'AVE.cms',
'ModuleCopyright' => '&copy; 2007-' . date('Y') . ' AVE.cms',
'ModuleStatus' => 1,
'ModuleIsFunction' => 0,
'ModuleTemplate' => 0,
'ModuleAdminEdit' => 1,
'ModuleFunction' => 'mod_snippets',
'ModuleTag' => null,
'ModuleTagLink' => null,
'ModuleAveTag' => null,
'ModulePHPTag' => null
];
?>

381
js/snippets.js

@ -0,0 +1,381 @@
var ModuleSnippets = {
initialized: false,
init: function () {
if (this.initialized)
return;
this.initialized = true;
this.build(); // Main functions
this.events(); // Events functions
},
// Main functions
build: function () {
this.executeBtn();
this.saveBtn();
this.clearBtn();
this.deleteBtn();
this.nameSelection();
},
// Events functions
events: function () {
this.MouseTrap();
},
//
MouseTrap: function () {
Mousetrap.bind(['ctrl+enter', 'command+enter'], function (event) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
ModuleSnippets.executeRun();
return false;
});
Mousetrap.bind(['ctrl+s', 'command+s'], function (event) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
ModuleSnippets.saveFragment();
return false;
});
},
//
saveFragment: function () {
let key_fragment = $('#fragmentKey').val();
if (key_fragment.length == '') {
jPrompt(new_text, '', new_title, function (name) {
if (name) {
ModuleSnippets.saveNew(name);
}
});
}
else {
ModuleSnippets.saveExist(key_fragment);
}
},
//
saveNew: function (name) {
let code = $("#code_text").val();
$.ajax({
type: "POST",
url: "index.php?do=modules&action=modedit&mod=snippets&moduleaction=new&cp=" + session,
data: {
"fragment_name": name,
"fragment_code": code
},
dataType: "json",
beforeSend: function () {
$.alerts._overlay('show');
},
success: function (data) {
$.alerts._overlay('hide');
$.jGrowl(data['message'], {
header: data['header'],
theme: data['theme']
});
ModuleSnippets.changeSelect(data['fragments'], data['key']);
$('#fragmentKey').val(data['key']);
ModuleSnippets.showHideDeleteBtn();
}
});
},
//
saveExist: function (key) {
let code = $("#code_text").val();
$.ajax({
type: "POST",
url: "index.php?do=modules&action=modedit&mod=snippets&moduleaction=save&cp=" + session,
data: {
"fragment_key": key,
"fragment_code": code
},
dataType: "json",
beforeSend: function () {
$.alerts._overlay('show');
},
success: function (data) {
$.alerts._overlay('hide');
$.jGrowl(data['message'], {
header: data['header'],
theme: data['theme']
});
}
});
},
//
executeRun: function () {
let code = $("#code_text").val();
let profiling = $("#profilingCheck").is(':checked') ? 1 : 0;
var Dialog = $('<div id="ajax-dialog-result" style="display:none;" class="ajax-dialog"></div>').appendTo('body');
var dialogWidth = $(window).width() * 0.9;
var dialogHeight = $(window).height() * 0.8;
$.ajax({
type: "POST",
url: "index.php?do=modules&action=modedit&mod=snippets&moduleaction=execute&cp=" + session,
data: {
'fragment_code': code,
'fragment_profiling': profiling
},
beforeSend: function () {
$.alerts._overlay('show');
},
success: function (data) {
$.alerts._overlay('hide');
Dialog.html(data);
}
});
Dialog.dialog({
autoOpen: false,
modal: true,
dialogClass: 'fixed-dialog',
close: function (event, ui) {
$(this).dialog('destroy').remove();
}
});
Dialog.dialog("option", "title", result_dialog);
Dialog.dialog("option", "width", dialogWidth);
Dialog.dialog("option", "height", dialogHeight);
Dialog.dialog("open");
},
//
executeBtn: function () {
$('.Execute').on('click', function (event) {
event.preventDefault();
ModuleSnippets.executeRun();
});
},
//
saveBtn: function () {
$('.SaveFragment').on('click', function (event) {
event.preventDefault();
ModuleSnippets.saveFragment();
});
},
//
clearBtn: function () {
$('.Clear').on('click', function (event) {
event.preventDefault();
$.alerts._overlay('show');
$('#fragmentKey').val('');
$('#fargmentNames option').prop('selected', false);
$('#fargmentNames option:first').prop('selected', true);
$("#code_text").text(ModuleSnippets.insertCodeMirror(''));
$('#fargmentNames').trigger('refresh');
$('a.Delete').addClass('hidden');
$.alerts._overlay('hide');
});
},
//
deleteBtn: function () {
$('.Delete').on('click', function (event) {
jConfirm(
del_confirm,
del_title,
function (succes) {
if (succes) {
$.alerts._overlay('show');
ModuleSnippets.deleteFragment();
}
}
);
});
},
//
deleteFragment: function () {
let key_fragment = $('#fragmentKey').val();
if (key_fragment != '') {
$.ajax({
type: "POST",
url: "index.php?do=modules&action=modedit&mod=snippets&moduleaction=delete&cp=" + session,
data: {
'fragment_key': key_fragment
},
dataType: "json",
beforeSend: function () {
$.alerts._overlay('show');
},
success: function(data) {
$.alerts._overlay('hide');
$.jGrowl(data['message'], {
header: data['header'],
theme: data['theme']
});
$('#fragmentKey').val('');
$("#code_text").text(ModuleSnippets.insertCodeMirror(''));
ModuleSnippets.showHideDeleteBtn();
ModuleSnippets.changeSelect(data['fragments']);
}
});
}
},
//
nameSelection: function () {
$('#fargmentNames').on('change', function (event) {
event.preventDefault();
let selected = $($(this), 'option:selected').val();
if (selected === '')
{
$('#fragmentKey').val('');
ModuleSnippets.showHideDeleteBtn();
return false;
}
$.ajax({
type: "POST",
url: "index.php?do=modules&action=modedit&mod=snippets&moduleaction=insert&cp=" + session,
data: {
'fragment_key': selected
},
dataType: "json",
beforeSend: function () {
$.alerts._overlay('show');
},
success: function (data) {
$.alerts._overlay('hide');
if (data.fragment_key == null)
{
$('#fragmentKey').val('');
ModuleSnippets.showHideDeleteBtn();
return false;
}
$.jGrowl(data['message'], {
header: data['header'],
theme: data['theme']
});
if (data['success'])
{
$("#code_text").text(ModuleSnippets.insertCodeMirror(data['fragment_code']));
$('#fragmentKey').val(data['fragment_key']);
}
// ToDo ELSE
ModuleSnippets.showHideDeleteBtn();
}
});
return false;
});
},
//
insertCodeMirror: function (data) {
var cm = $('.CodeMirror')[0].CodeMirror;
var doc = cm.getDoc();
var cursor = doc.getCursor();
var line = doc.getLine(cursor.line);
var pos = {
line: cursor.line,
ch: line.length - 1
};
doc.setValue('');
doc.replaceRange(data, pos);
},
//
showHideDeleteBtn: function () {
let key_fragment = $('#fragmentKey').val();
(key_fragment == '')
? $('a.Delete').addClass('hidden')
: $('a.Delete').removeClass('hidden');
return false;
},
//
changeSelect: function (data, key) {
let select = $('#fargmentNames');
select.html('');
select.append('<option value="">' + select_option + '</option>')
$.each(data, function () {
select.append('<option value="' + this.fragment_key + '">' + this.fragment_name + '</option>')
});
if (key !== undefined)
select.children('option[value=' + key + ']').prop('selected', true);
$('select').trigger('refresh');
}
};
jQuery(function ($) {
"use strict";
ModuleSnippets.init();
});

34
lang/ru.txt

@ -0,0 +1,34 @@
[name]
MODULE_NAME = "Сниппеты PHP"
MODULE_DESCRIPTION = "Позволяет хранить и выполнять произвольный php-код."
[admin]
CONSOLE_MODULE_NAME = "Сниппеты PHP"
CONSOLE_EDIT_TIP = "Позволяет хранить и выполнять произвольный php-код."
CONSOLE_BUTTON_ENTER = "Выполнить"
CONSOLE_BUTTON_SAVE = "Сохранить"
CONSOLE_BUTTON_DOWNLOAD = "Загрузить"
CONSOLE_BUTTON_CLEAR = "Очистить"
CONSOLE_BUTTON_CLOSE = "Закрыть"
CONSOLE_PERFORMED = "Результат"
CONSOLE_SETTINGS = "Настройки"
CONSOLE_REPORT_EXECUTION = "Отчет выполнения"
CONSOLE_SUCCESS = "Выполнено"
CONSOLE_ERROR = "Ошибка"
CONSOLE_CLEAR = "Консоль очищена"
CONSOLE_SELECT_FRAGMENT = "-- Выберите сниппет --"
CONSOLE_DOWNLOAD_FRAGMENT = "Загрузить"
CONSOLE_DELETE_FRAGMENT = "Удалить"
CONSOLE_CLOSE_FRAGMENT = "Закрыть"
CONSOLE_SAVED = "Сниппет успешно добавлен"
CONSOLE_DEL_SAVED = "Сниппет успешно удален"
CONSOLE_DOWNLOAD_SAVED = "Сниппет успешно загружен в консоль"
CONSOLE_DOWNLOAD_FALSE = "Сниппет не был загружен в консоль"
CONSOLE_EDIT = "Редактировать сниппет"
CONSOLE_DELETE = "Удалить сниппет"
CONSOLE_DELETE_CONFIRM = "Вы уверенны, что хотите удалить сниппет"
CONSOLE_NEW_TITLE = "Создание нового сниппета"
CONSOLE_NEW_TEXT = "Пожалуйста, укажите наименование сниппета"
CONSOLE_DATA_TITLE = "Сниппеты кода"
CONSOLE_HELP = "<strong>Сочетание клавиш</strong><br>&nbsp;&nbsp; Сохранить (CTRL+S) <br>&nbsp;&nbsp; Загрузить (CTRL+D)<br>&nbsp;&nbsp; Очистить (CTRL+С)"
CONSOLE_SAVED_FRAGMENTS = "Сохраненные сниппеты"

69
module.php

@ -0,0 +1,69 @@
<?php
/**
* AVE.cms - Модуль Консоль
*
* @package AVE.cms
* @subpackage module_Console
* @since 1.0
* @filesource
*/
if (! defined('BASE_DIR'))
exit;
//=======================================================
// The control module in the admin panel
//=======================================================
if (
defined('ACP')
&& (isset($_REQUEST['moduleaction']) && !empty($_REQUEST['moduleaction']))
&& (isset($_REQUEST['mod']) && $_REQUEST['mod'] == 'snippets')
)
{
require_once(BASE_DIR . '/modules/snippets/class/snippets.php');
new Snippets;
Snippets::$tpl_dir = BASE_DIR . '/modules/snippets/admin/';
Snippets::$fragmentdir = BASE_DIR . '/modules/snippets/data/';
Snippets::$fragmentfile = 'fragment.php';
$lang_file = BASE_DIR . '/modules/snippets/lang/' . $_SESSION['admin_language'] . '.txt';
$AVE_Template->config_load($lang_file, 'admin');
//-- Actions
switch ($_REQUEST['moduleaction'])
{
case '1':
Snippets::show();
break;
case 'execute':
Snippets::fragmentExecute();
break;
case 'insert':
Snippets::fragmentInsert();
break;
case 'new':
Snippets::fragmentNew();
break;
case 'save':
Snippets::fragmentSave();
break;
case 'delete':
Snippets::fragmentDelete();
break;
case 'fragments':
Snippets::fragmentsShow();
break;
}
}
?>

19
sql.php

@ -0,0 +1,19 @@
<?php
$module_sql_install = [];
$module_sql_deinstall = [];
$module_sql_update = [];
//-- Update module -------------------------------------------------------------------------
$module_sql_update[] = "
UPDATE
`%%PRFX%%_module`
SET
ModuleAveTag = '" . $module['ModuleAveTag'] . "',
ModulePHPTag = '" . $module['ModulePHPTag'] . "',
ModuleVersion = '" . $module['ModuleVersion'] . "'
WHERE
ModuleSysName = '" . $module['ModuleSysName'] . "'
LIMIT 1;
";
?>
Loading…
Cancel
Save