2010-01-08 22:01:40 +02:00
|
|
|
|
<?php
|
|
|
|
|
/*-------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* LiveStreet Engine Social Networking
|
|
|
|
|
* Copyright © 2008 Mzhelskiy Maxim
|
|
|
|
|
*
|
|
|
|
|
*--------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* Official site: www.livestreet.ru
|
|
|
|
|
* Contact e-mail: rus.engine@gmail.com
|
|
|
|
|
*
|
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
|
*
|
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-29 17:58:36 +03:00
|
|
|
|
* Экшен обработки УРЛа вида /admin/
|
2010-01-08 22:01:40 +02:00
|
|
|
|
*
|
2012-04-29 17:58:36 +03:00
|
|
|
|
* @package actions
|
|
|
|
|
* @since 1.0
|
2010-01-08 22:01:40 +02:00
|
|
|
|
*/
|
2011-06-22 12:11:05 +03:00
|
|
|
|
class ActionAdmin extends Action {
|
2012-04-29 17:58:36 +03:00
|
|
|
|
/**
|
|
|
|
|
* Текущий пользователь
|
|
|
|
|
*
|
|
|
|
|
* @var ModuleUser_EntityUser|null
|
|
|
|
|
*/
|
|
|
|
|
protected $oUserCurrent=null;
|
2010-01-08 22:01:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* Главное меню
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $sMenuHeadItemSelect='admin';
|
2011-06-22 12:11:05 +03:00
|
|
|
|
|
2012-04-29 17:58:36 +03:00
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-02-06 02:09:44 +02:00
|
|
|
|
public function Init() {
|
2012-04-29 17:58:36 +03:00
|
|
|
|
/**
|
|
|
|
|
* Если нет прав доступа - перекидываем на 404 страницу
|
|
|
|
|
*/
|
2010-01-08 22:01:40 +02:00
|
|
|
|
if(!$this->User_IsAuthorization() or !$oUserCurrent=$this->User_GetUserCurrent() or !$oUserCurrent->isAdministrator()) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
2011-08-28 19:08:23 +03:00
|
|
|
|
$this->SetDefaultEvent('index');
|
2011-06-22 12:11:05 +03:00
|
|
|
|
|
2010-01-08 22:01:40 +02:00
|
|
|
|
$this->oUserCurrent=$oUserCurrent;
|
|
|
|
|
}
|
2012-04-29 17:58:36 +03:00
|
|
|
|
/**
|
|
|
|
|
* Регистрация евентов
|
|
|
|
|
*/
|
2011-06-22 12:11:05 +03:00
|
|
|
|
protected function RegisterEvent() {
|
2011-07-08 10:42:23 +03:00
|
|
|
|
$this->AddEvent('index','EventIndex');
|
2010-09-19 13:09:31 +03:00
|
|
|
|
$this->AddEvent('plugins','EventPlugins');
|
|
|
|
|
$this->AddEvent('restorecomment','EventRestoreComment');
|
2011-06-22 12:11:05 +03:00
|
|
|
|
$this->AddEvent('userfields','EventUserfields');
|
2011-10-09 20:23:38 +03:00
|
|
|
|
$this->AddEvent('recalcfavourite','EventRecalculateFavourite');
|
2012-03-10 07:45:19 +02:00
|
|
|
|
$this->AddEvent('recalcvote','EventRecalculateVote');
|
2012-03-10 09:02:55 +02:00
|
|
|
|
$this->AddEvent('recalctopic','EventRecalculateTopic');
|
2010-01-08 22:01:40 +02:00
|
|
|
|
}
|
2011-06-22 12:11:05 +03:00
|
|
|
|
|
|
|
|
|
|
2010-01-08 22:01:40 +02:00
|
|
|
|
/**********************************************************************************
|
|
|
|
|
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
|
|
|
|
|
**********************************************************************************
|
2011-06-22 12:11:05 +03:00
|
|
|
|
*/
|
2012-04-10 09:31:15 +03:00
|
|
|
|
|
2012-04-29 17:58:36 +03:00
|
|
|
|
/**
|
|
|
|
|
* Отображение главной страницы админки
|
|
|
|
|
* Нет никакой логики, просто отображение дефолтного шаблона евента index.tpl
|
|
|
|
|
*/
|
2011-08-28 19:08:23 +03:00
|
|
|
|
protected function EventIndex() {
|
|
|
|
|
|
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Перестроение дерева комментариев, актуально при $config['module']['comment']['use_nested'] = true;
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-09-19 13:09:31 +03:00
|
|
|
|
protected function EventRestoreComment() {
|
2012-06-10 10:37:22 +03:00
|
|
|
|
$this->Security_ValidateSendForm();
|
2010-09-19 13:36:17 +03:00
|
|
|
|
set_time_limit(0);
|
2010-09-19 13:09:31 +03:00
|
|
|
|
$this->Comment_RestoreTree();
|
2010-09-19 13:36:17 +03:00
|
|
|
|
$this->Cache_Clean();
|
2012-04-10 09:31:15 +03:00
|
|
|
|
|
2011-08-28 19:08:23 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('admin_comment_restore_tree'),$this->Lang_Get('attention'));
|
|
|
|
|
$this->SetTemplateAction('index');
|
2010-09-19 13:09:31 +03:00
|
|
|
|
}
|
2012-04-10 09:31:15 +03:00
|
|
|
|
/**
|
2012-03-10 07:45:19 +02:00
|
|
|
|
* Пересчет счетчика избранных
|
2011-10-09 20:23:38 +03:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventRecalculateFavourite() {
|
2012-06-10 10:37:22 +03:00
|
|
|
|
$this->Security_ValidateSendForm();
|
2011-10-09 20:23:38 +03:00
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$this->Comment_RecalculateFavourite();
|
|
|
|
|
$this->Topic_RecalculateFavourite();
|
|
|
|
|
$this->Cache_Clean();
|
2012-04-10 09:31:15 +03:00
|
|
|
|
|
2011-10-09 20:23:38 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('admin_favourites_recalculated'),$this->Lang_Get('attention'));
|
|
|
|
|
$this->SetTemplateAction('index');
|
|
|
|
|
}
|
2012-03-10 07:45:19 +02:00
|
|
|
|
/**
|
|
|
|
|
* Пересчет счетчика голосований
|
|
|
|
|
*/
|
|
|
|
|
protected function EventRecalculateVote() {
|
2012-06-10 10:37:22 +03:00
|
|
|
|
$this->Security_ValidateSendForm();
|
2012-03-10 07:45:19 +02:00
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$this->Topic_RecalculateVote();
|
|
|
|
|
$this->Cache_Clean();
|
|
|
|
|
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('admin_votes_recalculated'),$this->Lang_Get('attention'));
|
|
|
|
|
$this->SetTemplateAction('index');
|
|
|
|
|
}
|
2012-03-10 09:02:55 +02:00
|
|
|
|
/**
|
|
|
|
|
* Пересчет количества топиков в блогах
|
|
|
|
|
*/
|
|
|
|
|
protected function EventRecalculateTopic() {
|
2012-06-10 10:37:22 +03:00
|
|
|
|
$this->Security_ValidateSendForm();
|
2012-03-10 09:02:55 +02:00
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$this->Blog_RecalculateCountTopic();
|
|
|
|
|
$this->Cache_Clean();
|
|
|
|
|
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('admin_topics_recalculated'),$this->Lang_Get('attention'));
|
|
|
|
|
$this->SetTemplateAction('index');
|
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Страница со списком плагинов
|
|
|
|
|
*
|
|
|
|
|
*/
|
2011-06-22 12:11:05 +03:00
|
|
|
|
protected function EventPlugins() {
|
2010-01-08 22:01:40 +02:00
|
|
|
|
$this->sMenuHeadItemSelect='plugins';
|
|
|
|
|
/**
|
|
|
|
|
* Обработка удаления плагинов
|
|
|
|
|
*/
|
|
|
|
|
if (isPost('submit_plugins_del')) {
|
|
|
|
|
$this->Security_ValidateSendForm();
|
2011-06-22 12:11:05 +03:00
|
|
|
|
|
2010-05-02 11:45:46 +03:00
|
|
|
|
$aPluginsDelete=getRequest('plugin_del');
|
2010-01-08 22:01:40 +02:00
|
|
|
|
if (is_array($aPluginsDelete)) {
|
2010-01-12 21:02:29 +02:00
|
|
|
|
$this->Plugin_Delete(array_keys($aPluginsDelete));
|
2010-01-08 22:01:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-12 21:02:29 +02:00
|
|
|
|
/**
|
|
|
|
|
* Получаем название плагина и действие
|
|
|
|
|
*/
|
2010-01-08 22:01:40 +02:00
|
|
|
|
if($sPlugin=getRequest('plugin',null,'get') and $sAction=getRequest('action',null,'get')) {
|
|
|
|
|
return $this->SubmitManagePlugin($sPlugin,$sAction);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получаем список блогов
|
|
|
|
|
*/
|
2012-04-10 09:31:15 +03:00
|
|
|
|
$aPlugins=$this->Plugin_GetList(array('order'=>'name'));
|
2010-01-08 22:01:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
2011-06-22 12:11:05 +03:00
|
|
|
|
*/
|
2010-01-08 22:01:40 +02:00
|
|
|
|
$this->Viewer_Assign("aPlugins",$aPlugins);
|
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('plugins_administartion_title'));
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем шаблон вывода
|
|
|
|
|
*/
|
|
|
|
|
$this->SetTemplateAction('plugins');
|
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Управление полями пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventUserFields()
|
|
|
|
|
{
|
|
|
|
|
switch(getRequest('action')) {
|
|
|
|
|
/**
|
2012-04-10 09:31:15 +03:00
|
|
|
|
* Создание нового поля
|
|
|
|
|
*/
|
2011-08-28 21:49:01 +03:00
|
|
|
|
case 'add':
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем как ajax запрос (json)
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
if (!$this->checkUserField()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$oField = Engine::GetEntity('User_Field');
|
|
|
|
|
$oField->setName(getRequest('name'));
|
|
|
|
|
$oField->setTitle(getRequest('title'));
|
|
|
|
|
$oField->setPattern(getRequest('pattern'));
|
2012-03-15 11:05:27 +02:00
|
|
|
|
if (in_array(getRequest('type'),$this->User_GetUserFieldTypes())) {
|
|
|
|
|
$oField->setType(getRequest('type'));
|
2012-04-19 21:04:25 +03:00
|
|
|
|
} else {
|
|
|
|
|
$oField->setType('');
|
2012-03-15 11:05:27 +02:00
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
|
|
|
|
|
$iId = $this->User_addUserField($oField);
|
|
|
|
|
if(!$iId) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Прогружаем переменные в ajax ответ
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_AssignAjax('id', $iId);
|
|
|
|
|
$this->Viewer_AssignAjax('lang_delete', $this->Lang_Get('user_field_delete'));
|
|
|
|
|
$this->Viewer_AssignAjax('lang_edit', $this->Lang_Get('user_field_update'));
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('user_field_added'),$this->Lang_Get('attention'));
|
|
|
|
|
break;
|
|
|
|
|
/**
|
|
|
|
|
* Удаление поля
|
|
|
|
|
*/
|
|
|
|
|
case 'delete':
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем как ajax запрос (json)
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
if (!getRequest('id')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->User_deleteUserField(getRequest('id'));
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('user_field_deleted'),$this->Lang_Get('attention'));
|
|
|
|
|
break;
|
|
|
|
|
/**
|
|
|
|
|
* Изменение поля
|
|
|
|
|
*/
|
|
|
|
|
case 'update':
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем как ajax запрос (json)
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
if (!getRequest('id')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!$this->User_userFieldExistsById(getRequest('id'))) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!$this->checkUserField()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$oField = Engine::GetEntity('User_Field');
|
|
|
|
|
$oField->setId(getRequest('id'));
|
|
|
|
|
$oField->setName(getRequest('name'));
|
|
|
|
|
$oField->setTitle(getRequest('title'));
|
|
|
|
|
$oField->setPattern(getRequest('pattern'));
|
2012-03-15 11:05:27 +02:00
|
|
|
|
if (in_array(getRequest('type'),$this->User_GetUserFieldTypes())) {
|
|
|
|
|
$oField->setType(getRequest('type'));
|
|
|
|
|
} else {
|
|
|
|
|
$oField->setType('');
|
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
|
|
|
|
|
if ($this->User_updateUserField($oField)) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('user_field_updated'),$this->Lang_Get('attention'));
|
|
|
|
|
break;
|
|
|
|
|
/**
|
|
|
|
|
* Показываем страницу со списком полей
|
|
|
|
|
*/
|
|
|
|
|
default:
|
|
|
|
|
/**
|
2011-07-24 14:48:08 +03:00
|
|
|
|
* Загружаем в шаблон JS текстовки
|
|
|
|
|
*/
|
2011-08-28 21:49:01 +03:00
|
|
|
|
$this->Lang_AddLangJs(array('user_field_delete_confirm'));
|
|
|
|
|
/**
|
|
|
|
|
* Получаем список всех полей
|
|
|
|
|
*/
|
2012-03-15 11:05:27 +02:00
|
|
|
|
$this->Viewer_Assign('aUserFields',$this->User_getUserFields());
|
|
|
|
|
$this->Viewer_Assign('aUserFieldTypes',$this->User_GetUserFieldTypes());
|
2011-08-28 21:49:01 +03:00
|
|
|
|
$this->SetTemplateAction('user_fields');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
2012-04-29 17:58:36 +03:00
|
|
|
|
* Проверка поля пользователя на корректность из реквеста
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*
|
2012-04-29 17:58:36 +03:00
|
|
|
|
* @return bool
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
|
|
|
|
public function checkUserField()
|
|
|
|
|
{
|
|
|
|
|
if (!getRequest('title')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_field_error_add_no_title'),$this->Lang_Get('error'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!getRequest('name')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_field_error_add_no_name'),$this->Lang_Get('error'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Не допускаем дубликатов по имени
|
|
|
|
|
*/
|
|
|
|
|
if ($this->User_userFieldExistsByName(getRequest('name'), getRequest('id'))) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_field_error_name_exists'),$this->Lang_Get('error'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-01-08 22:01:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* Активация\деактивация плагина
|
|
|
|
|
*
|
2012-04-29 17:58:36 +03:00
|
|
|
|
* @param string $sPlugin Имя плагина
|
|
|
|
|
* @param string $sAction Действие
|
2010-01-08 22:01:40 +02:00
|
|
|
|
*/
|
|
|
|
|
protected function SubmitManagePlugin($sPlugin,$sAction) {
|
2011-04-10 20:04:18 +03:00
|
|
|
|
$this->Security_ValidateSendForm();
|
2010-01-08 22:01:40 +02:00
|
|
|
|
if(!in_array($sAction,array('activate','deactivate'))) {
|
2010-01-12 21:02:29 +02:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('plugins_unknown_action'),$this->Lang_Get('error'),true);
|
2010-01-08 22:01:40 +02:00
|
|
|
|
Router::Location(Router::GetPath('plugins'));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Активируем\деактивируем плагин
|
|
|
|
|
*/
|
|
|
|
|
if($bResult=$this->Plugin_Toggle($sPlugin,$sAction)) {
|
2011-06-22 12:11:05 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('plugins_action_ok'),$this->Lang_Get('attention'),true);
|
2010-01-08 22:01:40 +02:00
|
|
|
|
} else {
|
2011-06-22 12:11:05 +03:00
|
|
|
|
if(!($aMessages=$this->Message_GetErrorSession()) or !count($aMessages)) $this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'),true);
|
2010-01-08 22:01:40 +02:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Возвращаем на страницу управления плагинами
|
|
|
|
|
*/
|
|
|
|
|
Router::Location(Router::GetPath('admin').'plugins/');
|
|
|
|
|
}
|
2012-04-10 09:31:15 +03:00
|
|
|
|
/**
|
2010-01-08 22:01:40 +02:00
|
|
|
|
* Выполняется при завершении работы экшена
|
|
|
|
|
*
|
|
|
|
|
*/
|
2011-06-22 12:11:05 +03:00
|
|
|
|
public function EventShutdown() {
|
2010-01-08 22:01:40 +02:00
|
|
|
|
/**
|
|
|
|
|
* Загружаем в шаблон необходимые переменные
|
|
|
|
|
*/
|
2010-02-06 02:09:44 +02:00
|
|
|
|
$this->Viewer_Assign('sMenuHeadItemSelect',$this->sMenuHeadItemSelect);
|
2010-01-08 22:01:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|