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.

266 lines
6.9 KiB

8 years ago
<?php
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2017 AVE.cms, http://www.ave-cms.ru
*
*/
class AVE_Block
{
/**
* Проверка алиаса тега на валидность и уникальность
*/
function blockValidate ($alias = '', $id = 0)
{
global $AVE_DB;
//-- Соответствие требованиям
if (empty ($alias) || preg_match('/^[A-Za-z0-9-_]{1,20}$/i', $alias) !== 1 || is_numeric($alias))
return 'syn';
//-- Уникальность
return !(bool)$AVE_DB->Query("
SELECT 1
FROM
" . PREFIX . "_blocks
WHERE
block_alias = '" . $alias . "'
AND
id != '" . $id . "'
")->GetCell();
}
/**
* Вывод списка системных блоков
*/
function blockList()
{
global $AVE_DB, $AVE_Template;
$vis_blocks = array();
$sql = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_blocks
ORDER BY
id
");
// Формируем массив из полученных данных
while ($row = $sql->FetchRow())
{
$row->block_author_id = get_username_by_id($row->block_author_id);
array_push($vis_blocks, $row);
}
$AVE_Template->assign('sid', 0);
$AVE_Template->assign('vis_blocks', $vis_blocks);
$AVE_Template->assign('content', $AVE_Template->fetch('blocks/list.tpl'));
}
/**
* Сохранение системного блока
*
* @param int $block_id идентификатор системного блока
*/
2 years ago
function blockSave ($block_id = null)
8 years ago
{
global $AVE_DB, $AVE_Template;
if (is_numeric($block_id))
{
$_REQUEST['block_visual'] = (isset($_REQUEST['block_visual'])) ? $_REQUEST['block_visual'] : 0;
7 years ago
$block_alias = isset($_REQUEST['block_alias'])
? $_REQUEST['block_alias']
: '';
8 years ago
$sql = $AVE_DB->Query("
UPDATE
" . PREFIX . "_blocks
SET
block_name = '" . $_REQUEST['block_name'] . "',
block_description = '" . addslashes($_REQUEST['block_description']) . "',
block_alias = '" . $_REQUEST['block_alias'] . "',
block_text = '" . $_REQUEST['block_text'] . "'
WHERE
id = '" . $block_id . "'
");
if ($sql->_result === false)
{
$message = $AVE_Template->get_config_vars('BLOCK_SAVED_ERR');
$header = $AVE_Template->get_config_vars('BLOCK_ERROR');
$theme = 'error';
}
else
{
$message = $AVE_Template->get_config_vars('BLOCK_SAVED');
$header = $AVE_Template->get_config_vars('BLOCK_SUCCESS');
$theme = 'accept';
//-- Стираем кеш блока
7 years ago
$this->clearCache($block_id, $block_alias);
8 years ago
//-- Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('BLOCK_SQLUPDATE') . " (" . stripslashes($_REQUEST['block_name']) . ") (id: $block_id)");
}
if (isAjax())
{
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
}
else
{
$AVE_Template->assign('message', $message);
header('Location:index.php?do=blocks&cp=' . SESSION);
}
exit;
}
else
{
$AVE_DB->Query("
INSERT INTO
" . PREFIX . "_blocks
SET
block_name = '" . $_REQUEST['block_name'] . "',
block_description = '" . addslashes($_REQUEST['block_description']) . "',
block_alias = '" . $_REQUEST['block_alias'] . "',
block_text = '" . $_REQUEST['block_text'] . "',
block_author_id = '" . (int)$_SESSION['user_id'] . "',
block_created = '" . time() . "'
");
$block_id = $AVE_DB->InsertId();
//-- Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('BLOCK_SQLNEW') . " (" . stripslashes($_REQUEST['block_name']) . ") (id: $block_id)");
}
if (! isset($_REQUEST['next_edit']))
header('Location:index.php?do=blocks&cp=' . SESSION);
else
header('Location:index.php?do=blocks&action=edit&&id=' . $block_id . '&cp=' . SESSION);
}
/**
* Редактирование системного блока
*
* @param int $block_id идентификатор системного блока
*/
2 years ago
function blockEdit ($block_id)
8 years ago
{
global $AVE_DB, $AVE_Template;
$row = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_blocks
WHERE
id = '" . $block_id . "'
2 years ago
OR
block_alias = '" . $block_id . "'
8 years ago
")->FetchAssocArray();
2 years ago
$AVE_Template->assign('sid', $row['id']);
8 years ago
7 years ago
$oCKeditor = new CKeditor();
$oCKeditor->returnOutput = true;
$oCKeditor->config['customConfig'] = 'block.js';
$oCKeditor->config['toolbar'] = 'Big';
$oCKeditor->config['height'] = 400;
$config = array();
$row['block_text'] = $oCKeditor->editor('block_text', $row['block_text'], $config);
8 years ago
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch('blocks/form.tpl'));
}
/**
* Создание блока
*/
function blockNew()
{
global $AVE_DB, $AVE_Template;
$row['block_name'] = '';
$row['block_alias'] = '';
$row['block_text'] = '';
$AVE_Template->assign('sid', 0);
7 years ago
$oCKeditor = new CKeditor();
$oCKeditor->returnOutput = true;
$oCKeditor->config['customConfig'] = 'block.js';
$oCKeditor->config['toolbar'] = 'Big';
$oCKeditor->config['height'] = 400;
$config = array();
$row['block_text'] = $oCKeditor->editor('block_text', $row['block_text'], $config);
8 years ago
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch('blocks/form.tpl'));
}
/**
* Удаление блока
*
* @param int $block_id идентификатор блока
*/
function blockDelete($block_id)
{
global $AVE_DB, $AVE_Template;
if (is_numeric($block_id))
{
$row = $AVE_DB->Query("
SELECT
*
FROM
" . PREFIX . "_blocks
WHERE
id = '" . $block_id . "'
")->FetchRow();
$AVE_DB->Query("
DELETE FROM
" . PREFIX . "_blocks
WHERE
id = '" . $block_id . "'
");
7 years ago
//-- Стираем кеш блока
$this->clearCache($block_id, $row->block_alias);
8 years ago
//-- Сохраняем системное сообщение в журнал
reportLog($AVE_Template->get_config_vars('BLOCK_SQLDEL') . " (" . stripslashes($row->block_name) . ") (id: $block_id)");
}
header('Location:index.php?do=blocks&cp=' . SESSION);
}
7 years ago
function clearCache ($id, $alias = null)
{
$cache_id = md5('block' . $id);
$cache_alias = md5('block' . $alias);
$cache_id_file = BASE_DIR . '/tmp/cache/sql/block/' . $cache_id . '.cache';
$cache_alias_file = BASE_DIR . '/tmp/cache/sql/block/' . $cache_alias . '.cache';
if (file_exists($cache_id_file))
unlink($cache_id_file);
if (file_exists($cache_alias_file))
unlink($cache_alias_file);
}
8 years ago
}
?>