1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-02 22:45:02 +03:00
ifhub.club/classes/actions/ActionTopic.class.php

547 lines
17 KiB
PHP
Raw Normal View History

<?php
2008-09-21 09:36:57 +03:00
/*-------------------------------------------------------
*
* 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
*
---------------------------------------------------------
*/
/**
* Обработка УРЛа вида /topic/ - управление своими топиками
*
*/
class ActionTopic extends Action {
/**
* Главное меню
*
* @var unknown_type
*/
protected $sMenuHeadItemSelect='blog';
2008-09-21 09:36:57 +03:00
/**
* Меню
*
* @var unknown_type
*/
protected $sMenuItemSelect='topic';
/**
* СубМеню
*
* @var unknown_type
*/
protected $sMenuSubItemSelect='add';
/**
* Текущий юзер
*
* @var unknown_type
*/
protected $oUserCurrent=null;
/**
* Инициализация
*
* @return unknown
*/
public function Init() {
/**
* Проверяем авторизован ли юзер
*/
if (!$this->User_IsAuthorization()) {
2009-04-11 14:50:42 +03:00
return parent::EventNotFound();
2008-09-21 09:36:57 +03:00
}
$this->oUserCurrent=$this->User_GetUserCurrent();
$this->SetDefaultEvent('add');
2009-04-11 14:50:42 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('topic_title'));
2008-09-21 09:36:57 +03:00
}
/**
* Регистрируем евенты
*
*/
protected function RegisterEvent() {
2009-06-15 00:15:11 +03:00
$this->AddEvent('add','EventAdd');
$this->AddEventPreg('/^published$/i','/^(page(\d+))?$/i','EventShowTopics');
$this->AddEventPreg('/^saved$/i','/^(page(\d+))?$/i','EventShowTopics');
2008-09-21 09:36:57 +03:00
$this->AddEvent('edit','EventEdit');
$this->AddEvent('delete','EventDelete');
2008-09-21 09:36:57 +03:00
}
/**********************************************************************************
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
**********************************************************************************
*/
/**
* Редактирование топика
*
* @return unknown
*/
protected function EventEdit() {
/**
* Меню
*/
$this->sMenuSubItemSelect='';
2008-09-30 07:31:24 +03:00
$this->sMenuItemSelect='topic';
2008-09-21 09:36:57 +03:00
/**
* Получаем номер топика из УРЛ и проверяем существует ли он
*/
$sTopicId=$this->GetParam(0);
2009-07-03 23:48:44 +03:00
if (!($oTopic=$this->Topic_GetTopicById($sTopicId))) {
2008-09-21 09:36:57 +03:00
return parent::EventNotFound();
}
/**
2009-06-15 00:15:11 +03:00
* Если права на редактирование
*/
if (!$this->ACL_IsAllowEditTopic($oTopic,$this->oUserCurrent)) {
2008-09-21 09:36:57 +03:00
return parent::EventNotFound();
}
/**
* Вызов хуков
*/
$this->Hook_Run('topic_edit_show',array('oTopic'=>$oTopic));
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
2009-06-20 16:54:24 +03:00
$this->Viewer_Assign('aBlogsAllow',$this->Blog_GetBlogsAllowByUser($this->oUserCurrent));
2009-04-11 14:50:42 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('topic_topic_edit'));
2008-09-21 09:36:57 +03:00
/**
* Устанавливаем шаблон вывода
*/
$this->SetTemplateAction('add');
/**
* Проверяем отправлена ли форма с данными(хотяб одна кнопка)
*/
if (isset($_REQUEST['submit_topic_publish']) or isset($_REQUEST['submit_topic_save'])) {
/**
* Обрабатываем отправку формы
*/
return $this->SubmitEdit($oTopic);
} else {
/**
* Заполняем поля формы для редактирования
* Только перед отправкой формы!
*/
$_REQUEST['topic_title']=$oTopic->getTitle();
$_REQUEST['topic_text']=$oTopic->getTextSource();
$_REQUEST['topic_tags']=$oTopic->getTags();
$_REQUEST['blog_id']=$oTopic->getBlogId();
$_REQUEST['topic_id']=$oTopic->getId();
$_REQUEST['topic_publish_index']=$oTopic->getPublishIndex();
$_REQUEST['topic_forbid_comment']=$oTopic->getForbidComment();
2008-09-21 09:36:57 +03:00
}
}
/**
* Удаление топика
*
* @return unknown
*/
protected function EventDelete() {
$this->Security_ValidateSendForm();
/**
* Получаем номер топика из УРЛ и проверяем существует ли он
*/
$sTopicId=$this->GetParam(0);
2009-07-03 23:48:44 +03:00
if (!($oTopic=$this->Topic_GetTopicById($sTopicId))) {
return parent::EventNotFound();
}
/**
* проверяем есть ли право на удаление топика
2009-06-15 00:15:11 +03:00
*/
if (!$this->ACL_IsAllowDeleteTopic($oTopic,$this->oUserCurrent)) {
return parent::EventNotFound();
}
/**
* Удаляем топик
*/
$this->Topic_DeleteTopic($oTopic->getId());
/**
* Перенаправляем на страницу со списком топиков из блога этого топика
*/
2009-10-10 02:33:17 +03:00
Router::Location($oTopic->getBlog()->getUrlFull());
}
2008-09-21 09:36:57 +03:00
/**
* Добавление топика
*
* @return unknown
*/
protected function EventAdd() {
/**
* Меню
*/
$this->sMenuSubItemSelect='add';
/**
* Вызов хуков
*/
$this->Hook_Run('topic_add_show');
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
2009-06-15 00:15:11 +03:00
$this->Viewer_Assign('aBlogsAllow',$this->Blog_GetBlogsAllowByUser($this->oUserCurrent));
2009-04-11 14:50:42 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('topic_topic_create'));
2008-09-21 09:36:57 +03:00
/**
* Обрабатываем отправку формы
*/
return $this->SubmitAdd();
2009-06-15 00:15:11 +03:00
}
2008-09-21 09:36:57 +03:00
/**
2009-06-15 00:15:11 +03:00
* Выводит список топиков
2008-09-21 09:36:57 +03:00
*
*/
2009-06-15 00:15:11 +03:00
protected function EventShowTopics() {
2008-09-21 09:36:57 +03:00
/**
* Меню
*/
2009-06-15 00:15:11 +03:00
$this->sMenuSubItemSelect=$this->sCurrentEvent;
2008-09-21 09:36:57 +03:00
/**
* Передан ли номер страницы
*/
2009-06-15 00:15:11 +03:00
$iPage=$this->GetParamEventMatch(0,2) ? $this->GetParamEventMatch(0,2) : 1;
2008-09-21 09:36:57 +03:00
/**
* Получаем список топиков
2009-06-15 00:15:11 +03:00
*/
$aResult=$this->Topic_GetTopicsPersonalByUser($this->oUserCurrent->getId(),$this->sCurrentEvent=='published' ? 1 : 0,$iPage,Config::Get('module.topic.per_page'));
2008-09-21 09:36:57 +03:00
$aTopics=$aResult['collection'];
/**
* Формируем постраничность
*/
$aPaging=$this->Viewer_MakePaging($aResult['count'],$iPage,Config::Get('module.topic.per_page'),4,Router::GetPath('topic').$this->sCurrentEvent);
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
$this->Viewer_Assign('aPaging',$aPaging);
$this->Viewer_Assign('aTopics',$aTopics);
2009-06-15 00:15:11 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('topic_menu_'.$this->sCurrentEvent));
2008-09-21 09:36:57 +03:00
}
/**
* Обработка добавлени топика
*
* @return unknown
*/
protected function SubmitAdd() {
/**
* Проверяем отправлена ли форма с данными(хотяб одна кнопка)
*/
if (!isPost('submit_topic_publish') and !isPost('submit_topic_save')) {
2008-09-21 09:36:57 +03:00
return false;
}
2008-09-21 09:36:57 +03:00
/**
* Проверка корректности полей формы
*/
if (!$this->checkTopicFields()) {
return false;
}
/**
* Определяем в какой блог делаем запись
*/
$iBlogId=getRequest('blog_id');
if ($iBlogId==0) {
$oBlog=$this->Blog_GetPersonalBlogByUserId($this->oUserCurrent->getId());
2008-09-21 09:36:57 +03:00
} else {
$oBlog=$this->Blog_GetBlogById($iBlogId);
}
/**
* Если блог не определен выдаем предупреждение
*/
if (!$oBlog) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_unknown'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
/**
2009-06-20 16:54:24 +03:00
* Проверяем права на постинг в блог
2008-09-21 09:36:57 +03:00
*/
if (!$this->ACL_IsAllowBlog($oBlog,$this->oUserCurrent)) {
2009-06-20 16:54:24 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noallow'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
/**
* Проверяем топик на уникальность
*/
if ($oTopicEquivalent=$this->Topic_GetTopicUnique($this->oUserCurrent->getId(),md5(getRequest('topic_text')))) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_text_error_unique'),$this->Lang_Get('error'));
return false;
}
/**
* Проверяем разрешено ли постить топик по времени
*/
if (isPost('submit_topic_publish') and !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'),$this->Lang_Get('error'));
return;
}
2008-09-21 09:36:57 +03:00
/**
* Теперь можно смело добавлять топик к блогу
*/
$oTopic=Engine::GetEntity('Topic');
2008-09-21 09:36:57 +03:00
$oTopic->setBlogId($oBlog->getId());
$oTopic->setUserId($this->oUserCurrent->getId());
$oTopic->setType('topic');
$oTopic->setTitle(getRequest('topic_title'));
$oTopic->setTextHash(md5(getRequest('topic_text')));
2008-09-21 09:36:57 +03:00
/**
* Парсим на предмет ХТМЛ тегов
*/
$sText=$this->Text_Parser(getRequest('topic_text'));
/**
* Получаемый и устанавливаем разрезанный текст по тегу <cut>
*/
list($sTextShort,$sTextNew,$sTextCut) = $this->Text_Cut($sText);
2009-05-09 22:41:52 +03:00
$oTopic->setCutText($sTextCut);
2009-05-09 22:41:52 +03:00
$oTopic->setText($sTextNew);
$oTopic->setTextShort($sTextShort);
$oTopic->setTextSource(getRequest('topic_text'));
2008-09-21 09:36:57 +03:00
$oTopic->setTags(getRequest('topic_tags'));
$oTopic->setDateAdd(date("Y-m-d H:i:s"));
$oTopic->setUserIp(func_getIp());
/**
* Публикуем или сохраняем
*/
if (isset($_REQUEST['submit_topic_publish'])) {
$oTopic->setPublish(1);
$oTopic->setPublishDraft(1);
2008-09-21 09:36:57 +03:00
} else {
$oTopic->setPublish(0);
$oTopic->setPublishDraft(0);
}
/**
* Принудительный вывод на главную
*/
$oTopic->setPublishIndex(0);
if ($this->oUserCurrent->isAdministrator()) {
if (getRequest('topic_publish_index')) {
$oTopic->setPublishIndex(1);
}
}
/**
* Запрет на комментарии к топику
*/
$oTopic->setForbidComment(0);
if (getRequest('topic_forbid_comment')) {
$oTopic->setForbidComment(1);
}
2008-09-21 09:36:57 +03:00
/**
* Добавляем топик
*/
if ($this->Topic_AddTopic($oTopic)) {
/**
* Получаем топик, чтоб подцепить связанные данные
*/
2009-06-20 16:54:24 +03:00
$oTopic=$this->Topic_GetTopicById($oTopic->getId());
/**
* Делаем рассылку спама всем, кто состоит в этом блоге
*/
if ($oTopic->getPublish()==1 and $oBlog->getType()!='personal') {
2009-06-20 16:54:24 +03:00
$this->Topic_SendNotifyTopicNew($oBlog,$oTopic,$this->oUserCurrent);
}
Router::Location($oTopic->getUrl());
2008-09-21 09:36:57 +03:00
} else {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('system_error'));
2008-09-21 09:36:57 +03:00
return Router::Action('error');
}
}
/**
* Обработка редактирования топика
*
* @param unknown_type $oTopic
* @return unknown
*/
protected function SubmitEdit($oTopic) {
/**
* Проверка корректности полей формы
*/
if (!$this->checkTopicFields()) {
return false;
}
2008-09-21 09:36:57 +03:00
/**
* Определяем в какой блог делаем запись
*/
$iBlogId=getRequest('blog_id');
if ($iBlogId==0) {
$oBlog=$this->Blog_GetPersonalBlogByUserId($oTopic->getUserId());
2008-09-21 09:36:57 +03:00
} else {
$oBlog=$this->Blog_GetBlogById($iBlogId);
}
2008-09-21 09:36:57 +03:00
/**
* Если блог не определен выдаем предупреждение
*/
if (!$oBlog) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_unknown'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
2008-09-21 09:36:57 +03:00
/**
2009-06-20 16:54:24 +03:00
* Проверяем права на постинг в блог
2008-09-21 09:36:57 +03:00
*/
if (!$this->ACL_IsAllowBlog($oBlog,$this->oUserCurrent)) {
2009-06-20 16:54:24 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noallow'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
/**
* Проверяем топик на уникальность
*/
2009-06-24 00:35:20 +03:00
if ($oTopicEquivalent=$this->Topic_GetTopicUnique($oTopic->getUserId(),md5(getRequest('topic_text')))) {
if ($oTopicEquivalent->getId()!=$oTopic->getId()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_text_error_unique'),$this->Lang_Get('error'));
return false;
}
}
/**
* Сохраняем старое значение идентификатора блога
*/
$sBlogIdOld = $oTopic->getBlogId();
2008-09-21 09:36:57 +03:00
/**
* Теперь можно смело редактировать топик
*/
$oTopic->setBlogId($oBlog->getId());
$oTopic->setTitle(getRequest('topic_title'));
2009-12-04 18:11:07 +02:00
$oTopic->setTextHash(md5(getRequest('topic_text')));
2008-09-21 09:36:57 +03:00
/**
* Парсим на предмет ХТМЛ тегов
*/
2009-12-04 18:11:07 +02:00
$sText=$this->Text_Parser(getRequest('topic_text'));
/**
* Получаемый и устанавливаем разрезанный текст по тегу <cut>
*/
list($sTextShort,$sTextNew,$sTextCut) = $this->Text_Cut($sText);
2009-12-04 18:11:07 +02:00
$oTopic->setCutText($sTextCut);
2009-05-09 22:41:52 +03:00
$oTopic->setText($sTextNew);
$oTopic->setTextShort($sTextShort);
2008-09-21 09:36:57 +03:00
$oTopic->setTextSource(getRequest('topic_text'));
2009-12-04 18:11:07 +02:00
$oTopic->setTags(getRequest('topic_tags'));
2008-09-21 09:36:57 +03:00
$oTopic->setUserIp(func_getIp());
/**
* Публикуем или сохраняем в черновиках
*/
2009-06-20 16:54:24 +03:00
$bSendNotify=false;
2008-09-21 09:36:57 +03:00
if (isset($_REQUEST['submit_topic_publish'])) {
$oTopic->setPublish(1);
if ($oTopic->getPublishDraft()==0) {
$oTopic->setPublishDraft(1);
$oTopic->setDateAdd(date("Y-m-d H:i:s"));
2009-06-20 16:54:24 +03:00
$bSendNotify=true;
2009-12-04 18:11:07 +02:00
}
2008-09-21 09:36:57 +03:00
} else {
$oTopic->setPublish(0);
2009-12-04 18:11:07 +02:00
}
/**
* Принудительный вывод на главную
*/
if ($this->oUserCurrent->isAdministrator()) {
if (getRequest('topic_publish_index')) {
$oTopic->setPublishIndex(1);
} else {
$oTopic->setPublishIndex(0);
}
}
/**
* Запрет на комментарии к топику
*/
$oTopic->setForbidComment(0);
if (getRequest('topic_forbid_comment')) {
$oTopic->setForbidComment(1);
}
2008-09-21 09:36:57 +03:00
/**
* Сохраняем топик
*/
2009-12-04 18:11:07 +02:00
if ($this->Topic_UpdateTopic($oTopic)) {
/**
* Обновляем данные в комментариях, если топик был перенесен в новый блог
*/
if($sBlogIdOld!=$oTopic->getBlogId()) {
$this->Comment_UpdateTargetParentByTargetId($oTopic->getBlogId(), 'topic', $oTopic->getId());
$this->Comment_UpdateTargetParentByTargetIdOnline($oTopic->getBlogId(), 'topic', $oTopic->getId());
}
2009-06-20 16:54:24 +03:00
/**
* Рассылаем о новом топике подписчикам блога
*/
if ($bSendNotify) {
$this->Topic_SendNotifyTopicNew($oBlog,$oTopic,$this->oUserCurrent);
}
2008-11-04 23:46:28 +02:00
if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId()!=$oTopic->getUserId()) {
Router::Location($oBlog->getUrlFull());
2008-11-04 23:46:28 +02:00
}
Router::Location($oTopic->getUrl());
2008-09-21 09:36:57 +03:00
} else {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('system_error'));
2008-09-21 09:36:57 +03:00
return Router::Action('error');
}
}
/**
* Проверка полей формы
*
* @return unknown
*/
protected function checkTopicFields() {
2009-10-20 02:42:23 +03:00
$this->Security_ValidateSendForm();
2008-09-21 09:36:57 +03:00
$bOk=true;
/**
* Проверяем есть ли блог в кторый постим
*/
if (!func_check(getRequest('blog_id',null,'post'),'id')) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('topic_create_blog_error_unknown'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bOk=false;
}
/**
* Проверяем есть ли заголовок топика
*/
if (!func_check(getRequest('topic_title',null,'post'),'text',2,200)) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('topic_create_title_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bOk=false;
}
/**
* Проверяем есть ли содержание топика
*/
if (!func_check(getRequest('topic_text',null,'post'),'text',2,Config::Get('module.topic.max_length'))) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('topic_create_text_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bOk=false;
}
/**
* Проверяем есть ли теги(метки)
*/
if (!func_check(getRequest('topic_tags',null,'post'),'text',2,500)) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('topic_create_tags_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bOk=false;
}
/**
* проверяем ввод тегов
*/
$sTags=getRequest('topic_tags',null,'post');
2008-09-21 09:36:57 +03:00
$aTags=explode(',',$sTags);
$aTagsNew=array();
$aTagsNewLow=array();
2008-09-21 09:36:57 +03:00
foreach ($aTags as $sTag) {
$sTag=trim($sTag);
if (func_check($sTag,'text',2,50) and !in_array(mb_strtolower($sTag,'UTF-8'),$aTagsNewLow)) {
2008-09-21 09:36:57 +03:00
$aTagsNew[]=$sTag;
$aTagsNewLow[]=mb_strtolower($sTag,'UTF-8');
2008-09-21 09:36:57 +03:00
}
}
if (!count($aTagsNew)) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('topic_create_tags_error_bad'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bOk=false;
} else {
$_REQUEST['topic_tags']=join(',',$aTagsNew);
}
return $bOk;
}
/**
* При завершении экшена загружаем необходимые переменные
*
*/
public function EventShutdown() {
$this->Viewer_Assign('sMenuHeadItemSelect',$this->sMenuHeadItemSelect);
2008-09-21 09:36:57 +03:00
$this->Viewer_Assign('sMenuItemSelect',$this->sMenuItemSelect);
$this->Viewer_Assign('sMenuSubItemSelect',$this->sMenuSubItemSelect);
}
}
?>