Skip to content

Commit

Permalink
Редактор конфигов. В отличие от customconfigs - использует встроенную…
Browse files Browse the repository at this point in the history
… систему управления конфигами, что делает ее более простой для обычного обывателя
  • Loading branch information
esclkm committed Dec 5, 2015
0 parents commit 822bfb7
Show file tree
Hide file tree
Showing 14 changed files with 793 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
@@ -0,0 +1,12 @@
# Пользовательские конфиги
Плагин является заменой слотам меню.
Позваляет быстро создавать произольные пользовательские настройки и использовать в ваших шаблонах

# Установка
Просто скачайте и установите плагин

# Использование
Вставьте в ваши шаблоны код

{PHP.cfg.:configname}

39 changes: 39 additions & 0 deletions configeditor.config.first.php
@@ -0,0 +1,39 @@
<?php

/**
* [BEGIN_COT_EXT]
* Hooks=admin.config.first
* [END_COT_EXT]
*/

/**
* plugin Config Editor for Cotonti Siena
*
* @package configeditor
* @version 1.0.0
* @author esclkm
* @copyright
* @license BSD
* */
// Generated by Cotonti developer tool (littledev.ru)
defined('COT_CODE') or die('Wrong URL.');
/* @var $db CotDB */
/* @var $cache Cache */
/* @var $t Xtemplate */
require_once cot_incfile('configeditor', 'plug');

$sql = $db->query("SELECT * FROM $db_configeditor");
while($row = $sql->fetch())
{
$name = $row['configcat_name'];
$L['core_'.$name] = $row['configcat_title'];
$L['core_'.$name.'_desc'] = $row['configcat_desc'];
}

$sql = $db->query("SELECT * FROM $db_config WHERE config_owner = 'core' AND config_donor='configeditor'");
while($row = $sql->fetch())
{
$name = $row['config_name'];
$L['cfg_'.$name] = $row['config_text'];
$L['cfg_'.$name.'_hint'] = $row['config_desc'];
}
Binary file added configeditor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions configeditor.setup.php
@@ -0,0 +1,32 @@
<?php


/**
* [BEGIN_COT_EXT]
* Code=configeditor
* Name=Config Editor
* Category=misc-ext
* Description=Admin tool for creating and modifying custom configs
* Version=1.0.0
* Date=2015-05-18
* Author=esclkm
* Auth_guests=R
* Lock_guests=12345A
* Auth_members=RW
* [END_COT_EXT]
*
* */

/**
* plugin Config Editor for Cotonti Siena
*
* @package configeditor
* @version 1.0.0
* @author esclkm
* @copyright
* @license BSD
* */
// Generated by Cotonti developer tool (littledev.ru)
defined('COT_CODE') or die('Wrong URL');

?>
40 changes: 40 additions & 0 deletions configeditor.tools.php
@@ -0,0 +1,40 @@
<?php

/**
* [BEGIN_COT_EXT]
* Hooks=tools
* [END_COT_EXT]
*/

/**
* plugin Config Editor for Cotonti Siena
*
* @package configeditor
* @version 1.0.0
* @author esclkm
* @copyright
* @license BSD
* */
// Generated by Cotonti developer tool (littledev.ru)
defined('COT_CODE') or die('Wrong URL.');

require_once cot_incfile('configeditor', 'plug');

if (!in_array($n, array('edit')))
{
$n = 'editcat';
}

if (file_exists(cot_incfile('configeditor', 'plug', 'admin.'.$n)))
{
$t = new XTemplate(cot_tplfile('configeditor.admin.'.$n, 'plug'));
require_once cot_incfile('configeditor', 'plug', 'admin.'.$n);
$t->parse('MAIN');
$adminmain = $t->text('MAIN');
}
else
{
// Error page
cot_die_message(404);
exit;
}
143 changes: 143 additions & 0 deletions inc/configeditor.admin.edit.php
@@ -0,0 +1,143 @@
<?php

/**
* plugin Config Editor for Cotonti Siena
*
* @package configeditor
* @version 1.0.0
* @author esclkm
* @copyright
* @license BSD
* */
// Generated by Cotonti developer tool (littledev.ru)
defined('COT_CODE') or die('Wrong URL.');
/* @var $db CotDB */
/* @var $cache Cache */
/* @var $t Xtemplate */
$c = cot_import('c', 'G', 'ALP');
if(!$c)
{
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor'), '', true));
}
$info = cfg_editor::cat_info($c);
if(!$info)
{
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor'), '', true));
}

$adminpath[] = array(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'set', 'c' => $c)), $info['configcat_title']);
$adminpath[] = $L['edit_cat'];

$types_array = array(
COT_CONFIG_TYPE_TEXT => $L['ccfg_type_text'],
COT_CONFIG_TYPE_STRING => $L['ccfg_type_string'],
COT_CONFIG_TYPE_SELECT => $L['ccfg_type_select'],
COT_CONFIG_TYPE_RADIO => $L['ccfg_type_radio'],
COT_CONFIG_TYPE_CALLBACK => $L['ccfg_type_callback'],
COT_CONFIG_TYPE_HIDDEN => $L['ccfg_type_hidden'],
COT_CONFIG_TYPE_SEPARATOR => $L['ccfg_type_separator'],
COT_CONFIG_TYPE_RANGE => $L['ccfg_type_range'],
COT_CONFIG_TYPE_CUSTOM => $L['ccfg_type_custom'],
);


if($a == 'add')
{
$name = cot_import('rname', 'P', "ALP");
$title = cot_import('rtitle', 'P', "TXT");
$desc = cot_import('rdesc', 'P', "HTM");
$order = cot_import('rorder', 'P', "INT");
$variants = cot_import('rvariants', 'P', "HTM");
$default = cot_import('rdefault', 'P', "HTM");
$type = cot_import('rtype', 'P', "INT");

if(empty($name))
{
cot_error($L['err_no_name']);
}
if(cfg_editor::config_exists($name))
{
cot_error($L['err_exists_name']);
}
if(!cot_error_found())
{
cfg_editor::config_add($c, $name, $order, $title, $desc, $type, $default, $variants);
cot_message('added_success');
}
$cache && $cache->clear();
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'c' => $c), '', true));
}
if($a == 'update')
{

$titles = cot_import('rtitle', 'P', "ARR");
$descs = cot_import('rdesc', 'P', "ARR");
$orders = cot_import('rorder', 'P', "ARR");
$variantss = cot_import('rvariants', 'P', "ARR");
$defaults = cot_import('rdefault', 'P', "ARR");
$types = cot_import('rtype', 'P', "ARR");
$names = array_keys($titles);
foreach($names as $name)
{
$name = cot_import($name, 'D', "ALP");
$title = cot_import($titles[$name], 'D', "TXT");
$desc = cot_import($descs[$name], 'D', "HTM");
$order = cot_import($orders[$name], 'D', "INT");
$variants = cot_import($variantss[$name], 'D', "HTM");
$default = cot_import($defaults[$name], 'D', "HTM");
$type = cot_import($types[$name], 'D', "INT");
cfg_editor::config_edit($c, $name, $order, $title, $desc, $type, $default, $variants);
}
cot_message('updated_success');
$cache && $cache->clear();
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'c' => $c), '', true));
}
if($a == 'delete')
{
cot_check_xg();
$name = cot_import('rname', 'G', "ALP");
cfg_editor::config_delete($c, $name);
cot_message('deleted_success');
$cache && $cache->clear();
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'c' => $c), '', true));
}
$rows = cfg_editor::config_list($c);
foreach ($rows as $row)
{
$readonly = array();
if($row['config_donor'] != 'configeditor')
{
$readonly = array(
'readonly' => 'readonly',
'disabled' => 'disabled'
);
}
$t->assign(array(
'FORM_EDIT_NAME' => $row['config_name'],
'FORM_EDIT_TITLE' => cot_inputbox('text', 'rtitle['.$row['config_name'].']', isset($L['cfg_'.$row['config_name']]) ? $L['cfg_'.$row['config_name']] : $row['config_text'], array('maxlength' => '255') + $readonly),
'FORM_EDIT_DESC' => cot_textarea('rdesc['.$row['config_name'].']', isset($L['cfg_'.$row['config_name'].'_hint']) ? $L['cfg_'.$row['config_name'].'_hint'] : $row['config_desc'], 2, 60, array('maxlength' => '255') + $readonly),
'FORM_EDIT_ORDER' => cot_inputbox('text', 'rorder['.$row['config_name'].']', $row['config_order'], array('maxlength' => '2') + $readonly),
'FORM_EDIT_VARIANTS' => cot_textarea('rvariants['.$row['config_name'].']', $row['config_variants'], 2, 60, array('maxlength' => '255') + $readonly),
'FORM_EDIT_DEFAULT' => cot_textarea('rdefault['.$row['config_name'].']', $row['config_default'], 2, 60, array('maxlength' => '255') + $readonly),
'FORM_EDIT_TYPE' => cot_selectbox($row['config_type'], 'rtype['.$row['config_name'].']', array_keys($types_array), array_values($types_array), false, $readonly),
'FORM_EDIT_DELETE_URL' => $row['config_donor'] != 'configeditor' ? '' : cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'c' => $c, 'a' => 'delete', 'rname' => $row['config_name'],'x' => $sys['xk'])),
));
$t->parse('MAIN.ROW');
}
if(!count($rows))
{
$t->parse('MAIN.NOROW');
}
$t->assign(array(
'FORM_EDIT_URL' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'a' => 'update', 'c' => $c)),
'FORM_ADD_URL' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'a' => 'add', 'c' => $c)),

'FORM_ADD_TITLE' => cot_inputbox('text', 'rtitle', '', array('maxlength' => '255')),
'FORM_ADD_NAME' => cot_inputbox('text', 'rname', '', array('size' => '20', 'maxlength' => '32')),
'FORM_ADD_DESC' => cot_textarea('rdesc', '', 2, 60),
'FORM_ADD_ORDER' => cot_inputbox('text', 'rorder', '', array('maxlength' => '2')),
'FORM_ADD_VARIANTS' => cot_textarea('rvariants', '', 2, 60),
'FORM_ADD_DEFAULT' => cot_textarea('rdefault', '', 2, 60),
'FORM_ADD_TYPE' => cot_selectbox(0, 'rtype', array_keys($types_array), array_values($types_array), false),
));
cot_display_messages($t);
104 changes: 104 additions & 0 deletions inc/configeditor.admin.editcat.php
@@ -0,0 +1,104 @@
<?php

/**
* plugin Config Editor for Cotonti Siena
*
* @package configeditor
* @version 1.0.0
* @author esclkm
* @copyright
* @license BSD
* */
// Generated by Cotonti developer tool (littledev.ru)
defined('COT_CODE') or die('Wrong URL.');
/* @var $db CotDB */
/* @var $cache Cache */
/* @var $t Xtemplate */

//$adminpath[] = array(cot_url('admin', array('m' => 'other', 'p' => 'configeditor')), $L['Custom_configs']);
$adminpath[] = $L['edit_cats'];

if($a == 'add')
{
$name = cot_import('rname', 'P', "ALP");
$title = cot_import('rtitle', 'P', "TXT");
$desc = cot_import('rdesc', 'P', "HTM");
if(empty($name))
{
cot_error($L['err_no_name']);
}
if(in_array($name, cfg_editor::cat_exists_list()))
{
cot_error($L['err_exists_name']);
}
if(!cot_error_found())
{
cfg_editor::cat_add($name, $title, $desc);
cot_message('added_success');
}
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'editcat'), '', true));
}
if($a == 'update')
{

$titles = cot_import('rtitle', 'P', "ARR");
$descs = cot_import('rdesc', 'P', "ARR");
$names = array_keys($titles);
foreach($names as $name)
{
$name = cot_import($name, 'D', "ALP");
$title = cot_import($titles[$name], 'D', "TXT");
$desc = cot_import($descs[$name], 'D', "HTM");

cfg_editor::cat_edit($name, $title, $desc);

}
cot_message('updated_success');
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'editcat'), '', true));
}
if($a == 'delete')
{
cot_check_xg();
$name = cot_import('rname', 'G', "ALP");
cfg_editor::cat_delete($name);
cot_message('deleted_success');
cot_redirect(cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'editcat'), '', true));
}
$system_cats = cfg_editor::cat_system_list();
foreach ($system_cats as $cat)
{
$t->assign(array(
'FORM_EDIT_TITLE' => cot_inputbox('text', '_rtitle['.$cat.']', $L['core_'.$cat], array('maxlength' => '255', 'readonly'=>'readonly')),
'FORM_EDIT_DESC' => cot_textarea('_rdesc['.$cat.']', $L['core_'.$cat.'_desc'], 1, 60, array('maxlength' => '255', 'readonly'=>'readonly')),
'FORM_EDIT_NAME' => $cat,
'FORM_EDIT_HREF' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'c' => $cat)),
'FORM_EDIT_CONFIG_HREF' => cot_url('admin', array('m' => 'config', 'n'=> 'edit', 'o' => 'core', 'p' => $cat)),
'FORM_EDIT_DELETE_URL' => '',
));
$t->parse('MAIN.ROW');
}
$rows = cfg_editor::cat_list();
foreach ($rows as $row)
{
$t->assign(array(
'FORM_EDIT_TITLE' => cot_inputbox('text', 'rtitle['.$row['configcat_name'].']', $row['configcat_title'], array('maxlength' => '255')),
'FORM_EDIT_DESC' => cot_textarea('rdesc['.$row['configcat_name'].']', $row['configcat_desc'], 1, 60),
'FORM_EDIT_NAME' => $row['configcat_name'],
'FORM_EDIT_HREF' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'edit', 'c' => $row['configcat_name'])),
'FORM_CONFIG_HREF' => cot_url('admin', array('m' => 'config', 'n'=> 'edit', 'o' => 'core', 'p' => $row['configcat_name'])),
'FORM_EDIT_DELETE_URL' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'editcat', 'a' => 'delete', 'rname' => $row['configcat_name'],'x' => $sys['xk'])),
));
$t->parse('MAIN.ROW');
}
if(!count($rows) && !count($system_cats))
{
$t->parse('MAIN.NOROW');
}
$t->assign(array(
'FORM_EDIT_URL' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'editcat', 'a' => 'update')),
'FORM_ADD_URL' => cot_url('admin', array('m' => 'other', 'p' => 'configeditor', 'n' => 'editcat', 'a' => 'add')),
'FORM_ADD_TITLE' => cot_inputbox('text', 'rtitle', '', array('maxlength' => '255')),
'FORM_ADD_NAME' => cot_inputbox('text', 'rname', '', array('size' => '20', 'maxlength' => '32')),
'FORM_ADD_DESC' => cot_textarea('rdesc', '', 1, 60),
));
cot_display_messages($t);

0 comments on commit 822bfb7

Please sign in to comment.