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

666 lines
23 KiB
PHP
Raw Normal View History

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() {
$this->AddEvent('add','EventAdd');
$this->AddEvent('saved','EventSaved');
$this->AddEvent('published','EventPublished');
$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);
if (!$oTopic=$this->Topic_GetTopicById($sTopicId,null,-1)) {
2008-09-21 09:36:57 +03:00
return parent::EventNotFound();
}
/**
* проверяем кто владелец топика, либо модератор и администратор блога
2008-09-21 09:36:57 +03:00
*/
$oBlogUser=$this->Blog_GetRelationBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$this->oUserCurrent->getId());
$bIsAdministratorBlog=$oBlogUser ? $oBlogUser->getIsAdministrator() : false;
$bIsModeratorBlog=$oBlogUser ? $oBlogUser->getIsModerator() : false;
if ($oTopic->getUserId()!=$this->oUserCurrent->getId() and !$this->oUserCurrent->isAdministrator() and !$bIsAdministratorBlog and !$bIsModeratorBlog and $oTopic->getBlogOwnerId()!=$this->oUserCurrent->getId()) {
2008-09-21 09:36:57 +03:00
return parent::EventNotFound();
}
/**
* Добавляем блок вывода информации о блоге
*/
$this->Viewer_AddBlocks('right',array('block.blogInfo.tpl'));
2008-09-21 09:36:57 +03:00
/**
* Получаем данные для отображения формы
* Если админ то делаем доступными все блоги
2008-09-21 09:36:57 +03:00
*/
$aAllowBlogsUser=array();
$aBlogsOwner=array();
if ($this->oUserCurrent->isAdministrator()) {
$aBlogsOwner=$this->Blog_GetBlogs();
} else {
$aBlogsOwner=$this->Blog_GetBlogsByOwnerId($this->oUserCurrent->getId());
$aBlogsUser=$this->Blog_GetRelationBlogUsersByUserId($this->oUserCurrent->getId());
foreach ($aBlogsUser as $oBlogUser) {
$oBlog=$this->Blog_GetBlogById($oBlogUser->getBlogId());
// делаем через "or" чтоб дать возможность юзеру отредактировать свой топик в блоге в котором он уже не может постить, т.е. для тех топиков что были запощены раньше и был доступ в блог
if ($this->ACL_CanAddTopic($this->oUserCurrent,$oBlog) or $oTopic->getBlogId()==$oBlog->getId()) {
$aAllowBlogsUser[]=$oBlogUser;
}
2008-09-21 09:36:57 +03:00
}
}
/**
* Вызов хуков
*/
$this->Hook_Run('topic_edit_show',array('oTopic'=>$oTopic));
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
$this->Viewer_Assign('aBlogsUser',$aAllowBlogsUser);
$this->Viewer_Assign('aBlogsOwner',$aBlogsOwner);
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() {
/**
* Получаем номер топика из УРЛ и проверяем существует ли он
*/
$sTopicId=$this->GetParam(0);
if (!$oTopic=$this->Topic_GetTopicById($sTopicId,null,-1)) {
return parent::EventNotFound();
}
/**
* проверяем есть ли право на удаление топика
*/
$oBlogUser=$this->Blog_GetRelationBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$this->oUserCurrent->getId());
$bIsAdministratorBlog=$oBlogUser ? $oBlogUser->getIsAdministrator() : false;
$bIsModeratorBlog=$oBlogUser ? $oBlogUser->getIsModerator() : false;
if (!$this->oUserCurrent->isAdministrator() and !$bIsAdministratorBlog and $oTopic->getBlogOwnerId()!=$this->oUserCurrent->getId()) {
return parent::EventNotFound();
}
/**
* Удаляем топик
*/
$this->Topic_DeleteTopic($oTopic->getId());
/**
* Перенаправляем на страницу со списком топиков из блога этого топика
*/
func_header_location($oTopic->getBlogUrlFull());
}
2008-09-21 09:36:57 +03:00
/**
* Добавление топика
*
* @return unknown
*/
protected function EventAdd() {
/**
* Меню
*/
$this->sMenuSubItemSelect='add';
/**
* Добавляем блок вывода информации о блоге
*/
$this->Viewer_AddBlocks('right',array('block.blogInfo.tpl'));
2008-09-21 09:36:57 +03:00
/**
* Получаем данные для отображения формы
*/
$aAllowBlogsUser=array();
$aBlogsOwner=array();
if ($this->oUserCurrent->isAdministrator()) {
$aBlogsOwner=$this->Blog_GetBlogs();
} else {
$aBlogsOwner=$this->Blog_GetBlogsByOwnerId($this->oUserCurrent->getId());
$aBlogsUser=$this->Blog_GetRelationBlogUsersByUserId($this->oUserCurrent->getId());
foreach ($aBlogsUser as $oBlogUser) {
$oBlog=$this->Blog_GetBlogById($oBlogUser->getBlogId());
if ($this->ACL_CanAddTopic($this->oUserCurrent,$oBlog)) {
$aAllowBlogsUser[]=$oBlogUser;
}
2008-09-21 09:36:57 +03:00
}
}
/**
* Вызов хуков
*/
$this->Hook_Run('topic_add_show');
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
$this->Viewer_Assign('aBlogsUser',$aAllowBlogsUser);
$this->Viewer_Assign('aBlogsOwner',$aBlogsOwner);
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();
}
/**
* Выводит список сохранёных топиков
*
*/
protected function EventSaved() {
/**
* Меню
*/
$this->sMenuSubItemSelect='saved';
/**
* Передан ли номер страницы
*/
if (preg_match("/^page(\d+)$/i",$this->getParam(0),$aMatch)) {
$iPage=$aMatch[1];
} else {
$iPage=1;
}
/**
* Получаем список топиков
*/
$iCount=0;
$aResult=$this->Topic_GetTopicsPersonalByUser($this->oUserCurrent->getId(),0,$iCount,$iPage,BLOG_TOPIC_PER_PAGE);
$aTopics=$aResult['collection'];
/**
* Формируем постраничность
*/
$aPaging=$this->Viewer_MakePaging($aResult['count'],$iPage,BLOG_TOPIC_PER_PAGE,4,DIR_WEB_ROOT.'/'.ROUTE_PAGE_TOPIC.'/saved');
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
$this->Viewer_Assign('aPaging',$aPaging);
$this->Viewer_Assign('aTopics',$aTopics);
2009-04-11 14:50:42 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('topic_menu_saved'));
2008-09-21 09:36:57 +03:00
}
/**
* Выводит список опубликованых топиков
*
*/
protected function EventPublished() {
/**
* Меню
*/
$this->sMenuSubItemSelect='published';
/**
* Передан ли номер страницы
*/
if (preg_match("/^page(\d+)$/i",$this->getParam(0),$aMatch)) {
$iPage=$aMatch[1];
} else {
$iPage=1;
}
/**
* Получаем список топиков
*/
$iCount=0;
$aResult=$this->Topic_GetTopicsPersonalByUser($this->oUserCurrent->getId(),1,$iCount,$iPage,BLOG_TOPIC_PER_PAGE);
$aTopics=$aResult['collection'];
/**
* Формируем постраничность
*/
$aPaging=$this->Viewer_MakePaging($aResult['count'],$iPage,BLOG_TOPIC_PER_PAGE,4,DIR_WEB_ROOT.'/'.ROUTE_PAGE_TOPIC.'/published');
2008-09-21 09:36:57 +03:00
/**
* Загружаем переменные в шаблон
*/
$this->Viewer_Assign('aPaging',$aPaging);
$this->Viewer_Assign('aTopics',$aTopics);
2009-04-11 14:50:42 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('topic_menu_published'));
2008-09-21 09:36:57 +03:00
}
/**
* Обработка добавлени топика
*
* @return unknown
*/
protected function SubmitAdd() {
/**
* Проверяем отправлена ли форма с данными(хотяб одна кнопка)
*/
if (!isset($_REQUEST['submit_topic_publish']) and !isset($_REQUEST['submit_topic_save'])) {
return false;
}
/**
* Проверка корректности полей формы
*/
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;
}
/**
* Проверка состоит ли юзер в блоге в который постит
*/
if (!$this->Blog_GetRelationBlogUserByBlogIdAndUserId($oBlog->getId(),$this->oUserCurrent->getId()) and !$this->oUserCurrent->isAdministrator()) {
2008-09-21 09:36:57 +03:00
if ($oBlog->getOwnerId()!=$this->oUserCurrent->getId()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_nojoin'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
}
/**
* Проверяем есть ли права на постинг топика в этот блог
*/
if (!$this->ACL_CanAddTopic($this->User_GetUserCurrent(),$oBlog) and !$this->oUserCurrent->isAdministrator()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noacl'),$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;
}
2008-09-21 09:36:57 +03:00
/**
* Теперь можно смело добавлять топик к блогу
*/
$oTopic=new TopicEntity_Topic();
$oTopic->setBlogId($oBlog->getId());
$oTopic->setUserId($this->oUserCurrent->getId());
$oTopic->setType('topic');
$oTopic->setTitle(getRequest('topic_title'));
$oTopic->setCutText(null);
$oTopic->setTextHash(md5(getRequest('topic_text')));
2008-09-21 09:36:57 +03:00
/**
* Парсим на предмет ХТМЛ тегов
*/
$sText=$this->Text_Parser(getRequest('topic_text'));
2009-05-09 22:41:52 +03:00
$sTextShort=$sText;
$sTextNew=$sText;
$sTextTemp=str_replace("\r\n",'[<rn>]',getRequest('topic_text'));
$sTextTemp=str_replace("\n",'[<n>]',$sTextTemp);
if (preg_match("/^(.*)<cut(.*)>(.*)$/Ui",$sTextTemp,$aMatch)) {
2009-05-09 22:41:52 +03:00
$aMatch[1]=str_replace('[<rn>]',"\r\n",$aMatch[1]);
$aMatch[1]=str_replace('[<n>]',"\r\n",$aMatch[1]);
$aMatch[3]=str_replace('[<rn>]',"\r\n",$aMatch[3]);
$aMatch[3]=str_replace('[<n>]',"\r\n",$aMatch[3]);
$sTextShort=$this->Text_Parser($aMatch[1]);
$sTextNew=$this->Text_Parser($aMatch[1].' '.$aMatch[3]);
if (preg_match('/^\s*name\s*=\s*"(.+)"\s*\/?$/Ui',$aMatch[2],$aMatchCut)) {
$oTopic->setCutText(trim($aMatchCut[1]));
}
}
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)) {
/**
* Получаем топик, чтоб подцепить связанные данные
*/
$oTopic=$this->Topic_GetTopicById($oTopic->getId(),null,-1);
//Делаем рассылку спама всем, кто состоит в этом блоге
if ($oTopic->getPublish()==1 and $oBlog->getType()!='personal') {
$aUsers=$this->Blog_GetBlogUsersByBlogId($oBlog->getId());
foreach ($aUsers as $oUser) {
if ($oUser->getId()==$this->oUserCurrent->getId()) {
continue;
}
$this->Notify_SendTopicNewToSubscribeBlog($oUser,$oTopic,$oBlog,$this->oUserCurrent);
}
//отправляем создателю блога
if ($oBlog->getOwnerId()!=$this->oUserCurrent->getId()) {
$oUser=$this->User_GetUserById($oBlog->getOwnerId());
$this->Notify_SendTopicNewToSubscribeBlog($oUser,$oTopic,$oBlog,$this->oUserCurrent);
}
}
func_header_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;
}
/**
* Определяем в какой блог делаем запись
*/
$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);
}
/**
* Если блог не определен выдаем предупреждение
*/
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
*/
$oBlogUser=$this->Blog_GetRelationBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$this->oUserCurrent->getId());
$bIsAdministratorBlog=$oBlogUser ? $oBlogUser->getIsAdministrator() : false;
$bIsModeratorBlog=$oBlogUser ? $oBlogUser->getIsModerator() : false;
if (!$this->Blog_GetRelationBlogUserByBlogIdAndUserId($oBlog->getId(),$this->oUserCurrent->getId()) and !$this->oUserCurrent->isAdministrator() and !$bIsAdministratorBlog and !$bIsModeratorBlog and $oTopic->getBlogOwnerId()!=$this->oUserCurrent->getId()) {
2008-09-21 09:36:57 +03:00
if ($oBlog->getOwnerId()!=$this->oUserCurrent->getId()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_nojoin'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
}
/**
* Проверяем есть ли права на постинг топика в этот блог
* Условие $oBlog->getId()!=$oTopic->getBlogId() для того чтоб разрешить отредактировать топик в блоге в который сейчас юзер не имеет права на постинг, но раньше успел в него запостить этот топик
*/
if (!$this->ACL_CanAddTopic($this->oUserCurrent,$oBlog) and $oBlog->getId()!=$oTopic->getBlogId() and !$this->oUserCurrent->isAdministrator()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noacl'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return false;
}
/**
* Проверяем топик на уникальность
*/
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;
}
}
2008-09-21 09:36:57 +03:00
/**
* Теперь можно смело редактировать топик
*/
$oTopic->setBlogId($oBlog->getId());
$oTopic->setTitle(getRequest('topic_title'));
$oTopic->setCutText(null);
$oTopic->setTextHash(md5(getRequest('topic_text')));
2008-09-21 09:36:57 +03:00
/**
* Парсим на предмет ХТМЛ тегов
*/
$sText=$this->Text_Parser(getRequest('topic_text'));
2009-05-09 22:41:52 +03:00
$sTextShort=$sText;
$sTextNew=$sText;
$sTextTemp=str_replace("\r\n",'[<rn>]',getRequest('topic_text'));
2008-09-30 07:31:24 +03:00
$sTextTemp=str_replace("\n",'[<n>]',$sTextTemp);
if (preg_match("/^(.*)<cut(.*)>(.*)$/Ui",$sTextTemp,$aMatch)) {
2009-05-09 22:41:52 +03:00
$aMatch[1]=str_replace('[<rn>]',"\r\n",$aMatch[1]);
$aMatch[1]=str_replace('[<n>]',"\r\n",$aMatch[1]);
$aMatch[3]=str_replace('[<rn>]',"\r\n",$aMatch[3]);
$aMatch[3]=str_replace('[<n>]',"\r\n",$aMatch[3]);
$sTextShort=$this->Text_Parser($aMatch[1]);
$sTextNew=$this->Text_Parser($aMatch[1].' '.$aMatch[3]);
if (preg_match('/^\s*name\s*=\s*"(.+)"\s*\/?$/Ui',$aMatch[2],$aMatchCut)) {
$oTopic->setCutText(trim($aMatchCut[1]));
}
}
2008-09-21 09:36:57 +03:00
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'));
$oTopic->setTags(getRequest('topic_tags'));
$oTopic->setUserIp(func_getIp());
/**
* Публикуем или сохраняем в черновиках
*/
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"));
}
2008-09-21 09:36:57 +03:00
} else {
$oTopic->setPublish(0);
}
/**
* Принудительный вывод на главную
*/
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
/**
* Сохраняем топик
*/
2008-11-04 23:46:28 +02:00
if ($this->Topic_UpdateTopic($oTopic)) {
if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId()!=$oTopic->getUserId()) {
func_header_location($oTopic->getBlogUrlFull());
}
func_header_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() {
$bOk=true;
/**
* Проверяем есть ли блог в кторый постим
*/
if (!func_check(getRequest('blog_id'),'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'),'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'),'text',2,15000)) {
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'),'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');
$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);
}
}
?>