AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

677 lines
17 KiB

7 years ago
<?php
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2017 AVE.cms, http://www.ave-cms.ru
*
*/
5 years ago
class Sysblocks
7 years ago
{
5 years ago
/*
|--------------------------------------------------------------------------------------
| aliasValidate
|--------------------------------------------------------------------------------------
|
| Проверка алиаса на валидность и уникальность
|
*/
public static function aliasValidate ($alias = '', $id = 0)
7 years ago
{
global $AVE_DB;
//-- Соответствие требованиям
if (empty ($alias) || preg_match('/^[A-Za-z0-9-_]{1,20}$/i', $alias) !== 1 || is_numeric($alias))
return 'syn';
5 years ago
$sql = "
SELECT
1
7 years ago
FROM
" . PREFIX . "_sysblocks
WHERE
sysblock_alias = '" . $alias . "'
5 years ago
AND
7 years ago
id != '" . $id . "'
5 years ago
";
//-- Уникальность
return !(bool)$AVE_DB->Query($sql)->GetCell();
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| getGroups
|--------------------------------------------------------------------------------------
|
| Получаем список групп
|
*/
public static function getGroups ()
{
global $AVE_DB;
$sql = "
SELECT
*
FROM
" . PREFIX . "_sysblocks_groups
";
$query = $AVE_DB->Query($sql);
$groups = [];
while ($row = $query->FetchRow())
array_push($groups, $row);
return $groups;
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| startPage
|--------------------------------------------------------------------------------------
|
| Гланая страница
|
*/
5 years ago
public static function startPage ()
5 years ago
{
global $AVE_DB, $AVE_Template;
//-- Группы
$groups = [];
$sql = "
SELECT
*
FROM
" . PREFIX . "_sysblocks_groups
ORDER BY
position ASC
";
$query = $AVE_DB->Query($sql);
while ($row = $query->FetchAssocArray())
{
$row['count'] = 0;
$groups[$row['id']] = $row;
}
//-- Блоки
$sysblocks = [];
$sql = "
SELECT
a.*,
a.sysblock_group_id
FROM
" . PREFIX . "_sysblocks AS a
LEFT JOIN
" . PREFIX . "_sysblocks_groups AS b
ON a.sysblock_group_id = b.id
ORDER BY
b.position ASC, a.id ASC
";
$query = $AVE_DB->Query($sql);
while ($row = $query->FetchAssocArray())
{
$row['author'] = get_username_by_id($row['sysblock_author_id']);
$sysblocks[$row['sysblock_group_id']][] = $row;
}
foreach ($sysblocks AS $_k => $_v)
{
if ($_k == 0)
$groups[$_k]['position'] = 0;
$groups[$_k]['count'] = count($sysblocks[$_k]);
}
$AVE_Template->assign('groups', $groups);
$AVE_Template->assign('sysblocks', $sysblocks);
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/start.tpl'));
7 years ago
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| listBlocks
|--------------------------------------------------------------------------------------
|
| Список системных блоков
|
*/
5 years ago
public static function listBlocks ()
7 years ago
{
global $AVE_DB, $AVE_Template;
5 years ago
$sysblocks = [];
7 years ago
5 years ago
$sql = "
7 years ago
SELECT
*
FROM
" . PREFIX . "_sysblocks
ORDER BY
id
5 years ago
";
$query = $AVE_DB->Query($sql);
7 years ago
// Формируем массив из полученных данных
5 years ago
while ($row = $query->FetchRow())
7 years ago
{
$row->sysblock_author_id = get_username_by_id($row->sysblock_author_id);
array_push($sys_blocks, $row);
}
$AVE_Template->assign('sid', 0);
5 years ago
$AVE_Template->assign('sysblocks', $sysblocks);
7 years ago
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/list.tpl'));
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| listGroups
|--------------------------------------------------------------------------------------
|
| Список групп системных блоков
|
*/
5 years ago
public static function listGroups ()
5 years ago
{
global $AVE_DB, $AVE_Template;
$groups = [];
$sql = "
SELECT
*
FROM
" . PREFIX . "_sysblocks_groups
ORDER BY
5 years ago
position
5 years ago
";
$query = $AVE_DB->Query($sql);
// Формируем массив из полученных данных
while ($row = $query->FetchAssocArray())
array_push($groups, $row);
$AVE_Template->assign('sid', 0);
$AVE_Template->assign('groups', $groups);
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/groups.tpl'));
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| groupsSort
|--------------------------------------------------------------------------------------
|
| Сортировка групп
|
*/
public static function groupsSort ()
{
global $AVE_DB, $AVE_Template;
foreach ($_REQUEST['sort'] AS $position => $group_id)
{
$position++;
$sql = "
UPDATE
" . PREFIX . "_sysblocks_groups
SET
position = '" . (int)$position . "'
WHERE
id = '" . (int)$group_id . "'
";
$AVE_DB->Query($sql);
}
if (isAjax())
{
$message = $AVE_Template->get_config_vars('RUBRIK_SORTED');
$header = $AVE_Template->get_config_vars('RUBRIK_FILDS_SUCCESS');
$theme = 'accept';
echo json_encode(['message' => $message, 'header' => $header, 'theme' => $theme]);
exit;
}
}
/*
|--------------------------------------------------------------------------------------
| newGroup
|--------------------------------------------------------------------------------------
|
| Новая группа
|
*/
public static function newGroup ()
{
global $AVE_DB;
$sql = "
SELECT
MAX(position)
FROM
" . PREFIX . "_sysblocks_groups
";
$position = $AVE_DB->Query($sql)->GetCell();
$position++;
$sql = "
INSERT
" . PREFIX . "_sysblocks_groups
SET
position = '" . $position . "',
title = '" . $_REQUEST['title'] . "',
description = '" . $_REQUEST['description'] . "'
";
$AVE_DB->Query($sql);
header('Location:index.php?do=sysblocks&action=groups&cp=' . SESSION);
exit;
}
/*
|--------------------------------------------------------------------------------------
| delGroup
|--------------------------------------------------------------------------------------
|
| Удалить группу
|
*/
public static function delGroup ()
{
global $AVE_DB;
$id = (int)$_REQUEST['id'];
$sql = "
DELETE FROM
" . PREFIX . "_sysblocks_groups
WHERE
id = '" . $id . "'
";
$AVE_DB->Query($sql);
header('Location:index.php?do=sysblocks&action=groups&cp=' . SESSION);
exit;
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| newBlock
|--------------------------------------------------------------------------------------
|
| Создание системного блока
|
*/
public static function newBlock ()
{
global $AVE_Template;
$row['sysblock_name'] = '';
$row['sysblock_alias'] = '';
$row['sysblock_text'] = '';
5 years ago
$row['sysblock_eval'] = '1';
5 years ago
$row['sysblock_visual'] = (isset($_REQUEST['sysblock_visual']) && $_REQUEST['sysblock_visual'] != 0) ? $_REQUEST['sysblock_visual'] : '';
$AVE_Template->assign('sid', 0);
5 years ago
$AVE_Template->assign('groups', self::getGroups());
5 years ago
if ((isset($_REQUEST['sysblock_visual']) && $_REQUEST['sysblock_visual'] == 1) || $row['sysblock_visual'] == 1)
{
$oCKeditor = new CKeditor();
$oCKeditor->returnOutput = true;
$oCKeditor->config['customConfig'] = 'sysblock.js';
$oCKeditor->config['toolbar'] = 'Big';
$oCKeditor->config['height'] = 400;
5 years ago
$config = [];
5 years ago
$row['sysblock_text'] = $oCKeditor->editor('sysblock_text', $row['sysblock_text'], $config);
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/form_visual.tpl'));
}
else
5 years ago
{
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/form.tpl'));
}
5 years ago
}
/*
|--------------------------------------------------------------------------------------
| editBlock
|--------------------------------------------------------------------------------------
|
| Редактирование системного блока
|
*/
public static function editBlock ()
7 years ago
{
global $AVE_DB, $AVE_Template;
$sysblock_id = $_REQUEST['id'];
5 years ago
5 years ago
$sql = "
5 years ago
SELECT
*
FROM
" . PREFIX . "_sysblocks
WHERE
id = '" . $sysblock_id . "'
OR
sysblock_alias = '" . $sysblock_id . "'
5 years ago
";
$row = $AVE_DB->Query($sql)->FetchAssocArray();
5 years ago
$AVE_Template->assign('sid', $row['id']);
5 years ago
$AVE_Template->assign('groups', self::getGroups());
5 years ago
if ((isset($_REQUEST['sysblock_visual']) && $_REQUEST['sysblock_visual'] == 1) || $row['sysblock_visual'] == 1)
{
$oCKeditor = new CKeditor();
$oCKeditor->returnOutput = true;
$oCKeditor->config['customConfig'] = 'sysblock.js';
$oCKeditor->config['toolbar'] = 'Big';
$oCKeditor->config['height'] = 400;
5 years ago
$config = [];
5 years ago
$row['sysblock_text'] = $oCKeditor->editor('sysblock_text', $row['sysblock_text'], $config);
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/form_visual.tpl'));
}
else
{
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/form.tpl'));
}
}
/*
|--------------------------------------------------------------------------------------
| editBlock
|--------------------------------------------------------------------------------------
|
| Сохранение системного блока
|
*/
5 years ago
public static function saveBlock ()
5 years ago
{
global $AVE_DB, $AVE_Template;
$sysblock_id = $_REQUEST['id']
? (int)$_REQUEST['id']
: null;
7 years ago
if (is_numeric($sysblock_id))
{
$_REQUEST['sysblock_external'] = (isset($_REQUEST['sysblock_external'])) ? $_REQUEST['sysblock_external'] : 0;
$_REQUEST['sysblock_ajax'] = (isset($_REQUEST['sysblock_ajax'])) ? $_REQUEST['sysblock_ajax'] : 0;
5 years ago
$_REQUEST['sysblock_eval'] = (isset($_REQUEST['sysblock_eval'])) ? $_REQUEST['sysblock_eval'] : 0;
7 years ago
$_REQUEST['sysblock_visual'] = (isset($_REQUEST['sysblock_visual'])) ? $_REQUEST['sysblock_visual'] : 0;
5 years ago
$_REQUEST['sysblock_alias'] = isset($_REQUEST['sysblock_alias']) ? $_REQUEST['sysblock_alias'] : '';
7 years ago
5 years ago
$sql = "
7 years ago
UPDATE
" . PREFIX . "_sysblocks
SET
5 years ago
sysblock_group_id = '" . (int)$_REQUEST['sysblock_group_id'] . "',
7 years ago
sysblock_name = '" . $_REQUEST['sysblock_name'] . "',
sysblock_description = '" . addslashes($_REQUEST['sysblock_description']) . "',
sysblock_alias = '" . $_REQUEST['sysblock_alias'] . "',
sysblock_text = '" . $_REQUEST['sysblock_text'] . "',
5 years ago
sysblock_eval = '" . (int)$_REQUEST['sysblock_eval'] . "',
7 years ago
sysblock_external = '" . (int)$_REQUEST['sysblock_external'] . "',
sysblock_ajax = '" . (int)$_REQUEST['sysblock_ajax'] . "',
sysblock_visual = '" . (int)$_REQUEST['sysblock_visual'] . "'
WHERE
id = '" . $sysblock_id . "'
5 years ago
";
7 years ago
5 years ago
$query = $AVE_DB->Query($sql);
if ($query->_result === false)
7 years ago
{
$message = $AVE_Template->get_config_vars('SYSBLOCK_SAVED_ERR');
$header = $AVE_Template->get_config_vars('SYSBLOCK_ERROR');
$theme = 'error';
}
else
{
$message = $AVE_Template->get_config_vars('SYSBLOCK_SAVED');
$header = $AVE_Template->get_config_vars('SYSBLOCK_SUCCESS');
$theme = 'accept';
//-- Стираем кеш сисблока
5 years ago
self::clearCache($sysblock_id, $_REQUEST['sysblock_alias']);
7 years ago
//-- Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('SYSBLOCK_SQLUPDATE') . " (" . stripslashes($_REQUEST['sysblock_name']) . ") (id: $sysblock_id)");
}
if (isAjax())
{
5 years ago
echo json_encode(['message' => $message, 'header' => $header, 'theme' => $theme]);
7 years ago
}
else
{
$AVE_Template->assign('message', $message);
header('Location:index.php?do=sysblocks&cp=' . SESSION);
}
exit;
}
else
5 years ago
{
5 years ago
$sql = "
INSERT INTO
" . PREFIX . "_sysblocks
SET
sysblock_group_id = '" . (int)$_REQUEST['sysblock_group_id'] . "',
sysblock_name = '" . $_REQUEST['sysblock_name'] . "',
sysblock_description = '" . addslashes($_REQUEST['sysblock_description']) . "',
sysblock_alias = '" . $_REQUEST['sysblock_alias'] . "',
sysblock_text = '" . $_REQUEST['sysblock_text'] . "',
sysblock_author_id = '" . (int)$_SESSION['user_id'] . "',
sysblock_eval = '" . (int)$_REQUEST['sysblock_eval'] . "',
sysblock_external = '" . (int)$_REQUEST['sysblock_external'] . "',
sysblock_ajax = '" . (int)$_REQUEST['sysblock_ajax'] . "',
sysblock_visual = '" . (int)$_REQUEST['sysblock_visual'] . "',
sysblock_created = '" . time() . "'
";
$AVE_DB->Query($sql);
7 years ago
5 years ago
$sysblock_id = $AVE_DB->InsertId();
7 years ago
5 years ago
//-- Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('SYSBLOCK_SQLNEW') . " (" . stripslashes($_REQUEST['sysblock_name']) . ") (id: $sysblock_id)");
}
7 years ago
if (! isset($_REQUEST['next_edit']))
header('Location:index.php?do=sysblocks&cp=' . SESSION);
else
header('Location:index.php?do=sysblocks&action=edit&&id=' . $sysblock_id . '&cp=' . SESSION);
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| delBlock
|--------------------------------------------------------------------------------------
|
| Удаление системного блока
|
*/
public static function delBlock ()
7 years ago
{
global $AVE_DB, $AVE_Template;
5 years ago
$sysblock_id = $_REQUEST['id'];
7 years ago
if (is_numeric($sysblock_id))
{
5 years ago
$sysblock = $AVE_DB->Query("
7 years ago
SELECT
*
FROM
" . PREFIX . "_sysblocks
WHERE
id = '" . $sysblock_id . "'
")->FetchRow();
$AVE_DB->Query("
DELETE FROM
" . PREFIX . "_sysblocks
WHERE
id = '" . $sysblock_id . "'
");
//-- Стираем кеш сисблока
5 years ago
self::clearCache($sysblock_id, $sysblock->sysblock_alias);
7 years ago
//-- Сохраняем системное сообщение в журнал
5 years ago
reportLog($AVE_Template->get_config_vars('SYSBLOCK_SQLDEL') . " (" . stripslashes($sysblock->sysblock_name) . ") (id: $sysblock_id)");
7 years ago
}
header('Location:index.php?do=sysblocks&cp=' . SESSION);
}
7 years ago
5 years ago
/*
|--------------------------------------------------------------------------------------
| editBlock
|--------------------------------------------------------------------------------------
|
| Очистка кеша системного блока
|
*/
public static function clearCache ($id, $alias = null)
7 years ago
{
7 years ago
$from_id = BASE_DIR . '/tmp/cache/sql/sysblocks/' . $id;
rrmdir($from_id);
7 years ago
7 years ago
if ($alias)
{
$from_alias = BASE_DIR . '/tmp/cache/sql/sysblocks/' . $alias;
rrmdir($from_alias);
}
7 years ago
}
5 years ago
/*
|--------------------------------------------------------------------------------------
| multiBlock
|--------------------------------------------------------------------------------------
|
| Копирование системного блока
|
*/
public static function multiBlock ()
{
global $AVE_DB, $AVE_Template;
$_REQUEST['sub'] = (!isset($_REQUEST['sub']))
? ''
: $_REQUEST['sub'];
$errors = [];
switch ($_REQUEST['sub'])
{
case 'save':
$ok = true;
5 years ago
$sql = "
5 years ago
SELECT
sysblock_name
FROM
" . PREFIX . "_sysblocks
WHERE
sysblock_name = '" . $_REQUEST['sysblock_name'] . "'
5 years ago
";
$row = $AVE_DB->Query($sql)->FetchRow();
5 years ago
if (@$row->sysblock_name != '')
{
array_push($errors, $AVE_Template->get_config_vars('SYSBLOCK_EXIST'));
$AVE_Template->assign('errors', $errors);
$ok = false;
}
if ($_REQUEST['sysblock_name'] == '')
{
array_push($errors, $AVE_Template->get_config_vars('SYSBLOCK_COPY_TIP'));
$AVE_Template->assign('errors', $errors);
$ok = false;
}
if ($ok)
{
5 years ago
$sql = "
SELECT
sysblock_text
FROM
" . PREFIX . "_sysblocks
WHERE
id = '" . (int)$_REQUEST['id'] . "'
";
$row = $AVE_DB->Query($sql)->FetchRow();
$sql = "
INSERT INTO
" . PREFIX . "_sysblocks
5 years ago
SET
Id = '',
sysblock_name = '" . $_REQUEST['sysblock_name'] . "',
sysblock_text = '" . addslashes($row->sysblock_text) . "',
sysblock_author_id = '" . $_SESSION['user_id'] . "',
sysblock_created = '" . time() . "'
5 years ago
";
$AVE_DB->Query($sql);
5 years ago
5 years ago
reportLog($_SESSION['user_name'] . ' - ' . $AVE_Template->get_config_vars('SYSBLOCK_COPY_LOG') .' (' . (int)$_REQUEST['id'] . ')', 2, 2);
5 years ago
header('Location:index.php?do=sysblocks'.'&cp=' . SESSION);
}
$AVE_Template->assign('content', $AVE_Template->fetch('sysblocks/multi.tpl'));
break;
}
}
7 years ago
}
?>