Example #1
0
 /**
  * Выводит список топиков
  *
  */
 protected function EventShowTopics()
 {
     /**
      * Меню
      */
     $this->sMenuSubItemSelect = $this->sCurrentEvent;
     /*
      * Получаем тип контента
      */
     if (!($this->oType = E::ModuleTopic()->GetContentType($this->sCurrentEvent))) {
         return parent::EventNotFound();
     }
     /**
      * Устанавливаем title страницы
      */
     E::ModuleViewer()->AddHtmlTitle($this->oType->getContentTitleDecl());
     /**
      * Передан ли номер страницы
      */
     $iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1;
     /**
      * Получаем список топиков
      */
     $aResult = E::ModuleTopic()->GetTopicsByType($iPage, Config::Get('module.topic.per_page'), $this->oType->getContentUrl());
     $aTopics = $aResult['collection'];
     /**
      * Формируем постраничность
      */
     $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), R::GetPath('filter') . $this->sCurrentEvent);
     /**
      * Загружаем переменные в шаблон
      */
     E::ModuleViewer()->Assign('aPaging', $aPaging);
     E::ModuleViewer()->Assign('aTopics', $aTopics);
     $this->SetTemplateAction('index');
 }
Example #2
0
 /**
  * Обновляет топик
  *
  * @param ModuleTopic_EntityContentType $oContentType    Объект типа контента
  *
  * @return bool
  */
 public function DeleteContentType($oContentType)
 {
     $aFilter = array('topic_type' => $oContentType->getContentUrl());
     $iCount = $this->GetCountTopicsByFilter($aFilter);
     if (!$iCount && $this->oMapper->DeleteContentType($oContentType->getId())) {
         //чистим зависимые кеши
         E::ModuleCache()->CleanByTags(array('content_new', 'content_update', 'topic_update'));
         E::ModuleCache()->Delete("content_type_{$oContentType->getId()}");
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Обновляет тип контента
  *
  * @param ModuleTopic_EntityContentType $oContentType    Объект типа контента
  *
  * @return bool
  */
 public function UpdateContentType($oContentType)
 {
     $sql = "UPDATE ?_content\n\t\t\tSET\n\t\t\t\tcontent_title=?,\n\t\t\t\tcontent_title_decl=?,\n\t\t\t\tcontent_url=?,\n\t\t\t\tcontent_sort=?d,\n\t\t\t\tcontent_candelete=?d,\n\t\t\t\tcontent_active=?d,\n\t\t\t\tcontent_access=?d,\n\t\t\t\tcontent_config=?\n\t\t\tWHERE\n\t\t\t\tcontent_id = ?d\n\t\t";
     $bResult = $this->oDb->query($sql, $oContentType->getContentTitle(), $oContentType->getContentTitleDecl(), $oContentType->getContentUrl(), $oContentType->getContentSort(), $oContentType->getContentCandelete(), $oContentType->getContentActive(), $oContentType->getContentAccess(), $oContentType->getExtra(), $oContentType->getContentId());
     return $bResult !== false;
 }
Example #4
0
 /**
  * Обработка редактирования топика
  *
  * @param ModuleTopic_EntityTopic $oTopic
  *
  * @return mixed
  */
 protected function SubmitEdit($oTopic)
 {
     $oTopic->_setValidateScenario('topic');
     // * Сохраняем старое значение идентификатора блога
     $iBlogIdOld = $oTopic->getBlogId();
     // * Заполняем поля для валидации
     $iBlogId = F::GetRequestStr('blog_id');
     // if blog_id is empty then save blog not changed
     if (is_numeric($iBlogId)) {
         $oTopic->setBlogId($iBlogId);
     }
     // issue 151 (https://github.com/altocms/altocms/issues/151)
     // Некорректная обработка названия блога
     // $oTopic->setTitle(strip_tags(F::GetRequestStr('topic_title')));
     $oTopic->setTitle(E::ModuleTools()->RemoveAllTags(F::GetRequestStr('topic_title')));
     $oTopic->setTextSource(F::GetRequestStr('topic_text'));
     if ($this->oContentType->isAllow('link')) {
         $oTopic->setSourceLink(F::GetRequestStr('topic_field_link'));
     }
     $oTopic->setTags(F::GetRequestStr('topic_field_tags'));
     $oTopic->setUserIp(F::GetUserIp());
     if ($this->oUserCurrent && ($this->oUserCurrent->isAdministrator() || $this->oUserCurrent->isModerator())) {
         if (F::GetRequestStr('topic_url') && $oTopic->getTopicUrl() != F::GetRequestStr('topic_url')) {
             $sTopicUrl = E::ModuleTopic()->CorrectTopicUrl(F::TranslitUrl(F::GetRequestStr('topic_url')));
             $oTopic->setTopicUrl($sTopicUrl);
         }
     }
     // * Проверка корректности полей формы
     if (!$this->checkTopicFields($oTopic)) {
         return false;
     }
     // * Определяем в какой блог делаем запись
     $nBlogId = $oTopic->getBlogId();
     if ($nBlogId == 0) {
         $oBlog = E::ModuleBlog()->GetPersonalBlogByUserId($oTopic->getUserId());
     } else {
         $oBlog = E::ModuleBlog()->GetBlogById($nBlogId);
     }
     // * Если блог не определен выдаем предупреждение
     if (!$oBlog) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_create_blog_error_unknown'), E::ModuleLang()->Get('error'));
         return false;
     }
     // * Проверяем права на постинг в блог
     if (!E::ModuleACL()->IsAllowBlog($oBlog, $this->oUserCurrent)) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_create_blog_error_noallow'), E::ModuleLang()->Get('error'));
         return false;
     }
     // * Проверяем разрешено ли постить топик по времени
     if (isPost('submit_topic_publish') && !$oTopic->getPublishDraft() && !E::ModuleACL()->CanPostTopicTime($this->oUserCurrent)) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_time_limit'), E::ModuleLang()->Get('error'));
         return;
     }
     $oTopic->setBlogId($oBlog->getId());
     // * Получаемый и устанавливаем разрезанный текст по тегу <cut>
     list($sTextShort, $sTextNew, $sTextCut) = E::ModuleText()->Cut($oTopic->getTextSource());
     $oTopic->setCutText($sTextCut);
     $oTopic->setText(E::ModuleText()->Parser($sTextNew));
     // Получаем ссылки, полученные при парсинге текста
     $oTopic->setTextLinks(E::ModuleText()->GetLinks());
     $oTopic->setTextShort(E::ModuleText()->Parser($sTextShort));
     // * Изменяем вопрос/ответы, только если еще никто не голосовал
     if ($this->oContentType->isAllow('poll') && F::GetRequestStr('topic_field_question') && F::GetRequest('topic_field_answers', array()) && $oTopic->getQuestionCountVote() == 0) {
         $oTopic->setQuestionTitle(strip_tags(F::GetRequestStr('topic_field_question')));
         $oTopic->clearQuestionAnswer();
         $aAnswers = F::GetRequest('topic_field_answers', array());
         foreach ($aAnswers as $sAnswer) {
             $sAnswer = trim((string) $sAnswer);
             if ($sAnswer) {
                 $oTopic->addQuestionAnswer($sAnswer);
             }
         }
     }
     $aPhotoSetData = E::ModuleMresource()->GetPhotosetData('photoset', $oTopic->getId());
     $oTopic->setPhotosetCount($aPhotoSetData['count']);
     $oTopic->setPhotosetMainPhotoId($aPhotoSetData['cover']);
     // * Publish or save as a draft
     $bSendNotify = false;
     if (isset($_REQUEST['submit_topic_publish'])) {
         // If the topic has not been published then sets date of show (publication date)
         if (!$oTopic->getPublish() && !$oTopic->getDateShow()) {
             $oTopic->setDateShow(F::Now());
         }
         $oTopic->setPublish(1);
         if ($oTopic->getPublishDraft() == 0) {
             $oTopic->setPublishDraft(1);
             $oTopic->setDateAdd(F::Now());
             $bSendNotify = true;
         }
     } else {
         $oTopic->setPublish(0);
     }
     // * Принудительный вывод на главную
     if (E::ModuleACL()->IsAllowPublishIndex($this->oUserCurrent)) {
         if (F::GetRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         } else {
             $oTopic->setPublishIndex(0);
         }
     }
     // * Запрет на комментарии к топику
     $oTopic->setForbidComment(F::GetRequest('topic_forbid_comment', 0));
     // Если запрет на индексацию не устанавливался вручную, то задаем, как у блога
     $oBlogType = $oBlog->GetBlogType();
     if ($oBlogType && !$oTopic->getIndexIgnoreLock()) {
         $oTopic->setTopicIndexIgnore($oBlogType->GetIndexIgnore());
     } else {
         $oTopic->setTopicIndexIgnore(false);
     }
     $oTopic->setShowPhotoset(F::GetRequest('topic_show_photoset', 0));
     E::ModuleHook()->Run('topic_edit_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     // * Сохраняем топик
     if ($this->_updateTopic($oTopic)) {
         E::ModuleHook()->Run('topic_edit_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog, 'bSendNotify' => &$bSendNotify));
         // * Обновляем данные в комментариях, если топик был перенесен в новый блог
         if ($iBlogIdOld != $oTopic->getBlogId()) {
             E::ModuleComment()->UpdateTargetParentByTargetId($oTopic->getBlogId(), 'topic', $oTopic->getId());
             E::ModuleComment()->UpdateTargetParentByTargetIdOnline($oTopic->getBlogId(), 'topic', $oTopic->getId());
         }
         // * Обновляем количество топиков в блоге
         if ($iBlogIdOld != $oTopic->getBlogId()) {
             E::ModuleBlog()->RecalculateCountTopicByBlogId($iBlogIdOld);
         }
         E::ModuleBlog()->RecalculateCountTopicByBlogId($oTopic->getBlogId());
         // * Добавляем событие в ленту
         E::ModuleStream()->Write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && (!$oBlogType || !$oBlog->getBlogType()->IsPrivate()));
         // * Рассылаем о новом топике подписчикам блога
         if ($bSendNotify) {
             E::ModuleTopic()->SendNotifyTopicNew($oBlog, $oTopic, $oTopic->getUser());
         }
         if (!$oTopic->getPublish() && !$this->oUserCurrent->isAdministrator() && !$this->oUserCurrent->isModerator() && $this->oUserCurrent->getId() != $oTopic->getUserId()) {
             R::Location($oBlog->getUrlFull());
         }
         R::Location($oTopic->getUrl());
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'));
         F::SysWarning('System Error');
         return R::Action('error');
     }
 }
Example #5
0
 /**
  * @param ModuleTopic_EntityContentType $oContentType
  *
  * @return bool
  */
 protected function _eventContentTypesEditSubmit($oContentType)
 {
     // * Проверяем отправлена ли форма с данными
     if (!F::isPost('submit_type_add')) {
         return false;
     }
     // * Проверка корректности полей формы
     if (!$this->CheckContentFields()) {
         return false;
     }
     $sTypeOld = $oContentType->getContentUrl();
     $oContentType->setContentTitle(F::GetRequest('content_title'));
     $oContentType->setContentTitleDecl(F::GetRequest('content_title_decl'));
     $oContentType->setContentUrl(F::GetRequest('content_url'));
     $oContentType->setContentAccess(F::GetRequest('content_access'));
     $aConfig = F::GetRequest('config');
     if (is_array($aConfig)) {
         $oContentType->setExtraValue('photoset', isset($aConfig['photoset']) ? 1 : 0);
         $oContentType->setExtraValue('link', isset($aConfig['link']) ? 1 : 0);
         $oContentType->setExtraValue('question', isset($aConfig['question']) ? 1 : 0);
     } else {
         $oContentType->setExtra('');
     }
     if (E::ModuleTopic()->UpdateContentType($oContentType)) {
         if ($oContentType->getContentUrl() != $sTypeOld) {
             //меняем у уже созданных топиков системный тип
             E::ModuleTopic()->ChangeType($sTypeOld, $oContentType->getContentUrl());
         }
         E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('action.admin.contenttypes_success_edit'), null, true);
         R::Location('admin/settings-contenttypes/');
     }
     return false;
 }