Esempio n. 1
0
 /**
  * Список опубликованых топиков в открытых блогах (с кешированием)
  *
  * @param int $iPage
  *
  * @return array
  */
 public function getTopicsForSitemap($iPage = 0)
 {
     $sCacheKey = "sitemap_topics_{$iPage}_" . C::Get('plugin.sitemap.items_per_page');
     if (false === ($aData = E::ModuleCache()->Get($sCacheKey))) {
         $aFilter = $this->GetNamedFilter('sitemap');
         $aTopics = E::ModuleTopic()->GetTopicsByFilter($aFilter, $iPage, C::Get('plugin.sitemap.items_per_page'), array('blog' => array('owner' => array())));
         $aData = array();
         $iIndex = 0;
         $aPriority = F::Array_Str2Array(C::Get('plugin.sitemap.type.topics.priority'));
         $nPriority = sizeof($aPriority) ? reset($aPriority) : null;
         $aChangeFreq = F::Array_Str2Array(C::Get('plugin.sitemap.type.topics.changefreq'));
         $sChangeFreq = sizeof($aChangeFreq) ? reset($aChangeFreq) : null;
         /** @var ModuleTopic_EntityTopic $oTopic */
         foreach ($aTopics['collection'] as $oTopic) {
             if ($aPriority) {
                 if (isset($aPriority[$iIndex])) {
                     $nPriority = $aPriority[$iIndex];
                 }
             }
             if ($aChangeFreq) {
                 if (isset($aChangeFreq[$iIndex])) {
                     $sChangeFreq = $aChangeFreq[$iIndex];
                 }
             }
             $aData[] = E::ModuleSitemap()->GetDataForSitemapRow($oTopic->getLink(), $oTopic->getDateLastMod(), $sChangeFreq, $nPriority);
             $iIndex += 1;
         }
         // тег 'blog_update' т.к. при редактировании блога его тип может измениться
         // с открытого на закрытый или наоборот
         E::ModuleCache()->Set($aData, $sCacheKey, array('topic_new', 'topic_update', 'blog_update'), C::Get('plugin.sitemap.type.topics.cache_lifetime'));
     }
     return $aData;
 }
Esempio n. 2
0
 public function getComments($iTopicId, $iPageNum, $iPageSize)
 {
     $sCacheKey = 'api_topic_' . $iTopicId;
     $oTopic = E::ModuleCache()->GetTmp($sCacheKey);
     if (!$oTopic) {
         $oTopic = E::ModuleTopic()->GetTopicById($iTopicId);
     }
     if (!$oTopic || !($oBlog = $oTopic->getBlog())) {
         return array();
     }
     $oBlogType = $oBlog->GetBlogType();
     if ($oBlogType) {
         $bCloseBlog = !$oBlog->CanReadBy(E::User());
     } else {
         // if blog type not defined then it' open blog
         $bCloseBlog = false;
     }
     if ($bCloseBlog) {
         return array();
     }
     $aComments = E::ModuleComment()->GetCommentsByTargetId($oTopic, 'topic', $iPageNum, $iPageSize);
     $aResult = array('total' => $oTopic->getCountComment(), 'list' => array());
     foreach ($aComments['comments'] as $oComment) {
         $aResult['list'][] = $oComment->getApiData();
     }
     return $aResult;
 }
 public function EventShutdown()
 {
     parent::EventShutdown();
     if ($this->oCurrentBlog) {
         $iCountSandboxBlogNew = E::ModuleTopic()->GetCountTopicsSandboxNew(array('blog_id' => $this->oCurrentBlog->getId()));
         E::ModuleViewer()->Assign('iCountSandboxBlogNew', $iCountSandboxBlogNew);
     }
 }
Esempio n. 4
0
 public function GetUserProfileStats($xUser)
 {
     $aUserPublicationStats = parent::GetUserProfileStats($xUser);
     $iCountTopicsSandbox = E::ModuleTopic()->GetCountTopicsSandboxByUser($xUser);
     $aUserPublicationStats['count_sandbox'] = $iCountTopicsSandbox;
     $aUserPublicationStats['count_created'] += $iCountTopicsSandbox;
     return $aUserPublicationStats;
 }
 /**
  * Get all additional fields of the content type
  *
  * @return ModuleTopic_EntityField[]
  */
 public function getFields()
 {
     if (is_null($this->aFields)) {
         $aFilter = array();
         $aFilter['content_id'] = $this->getContentId();
         $this->aFields = E::ModuleTopic()->GetContentFields($aFilter);
     }
     return $this->aFields;
 }
Esempio n. 6
0
 public function EventDownloadFile()
 {
     $this->SetTemplate(false);
     $sTopicId = $this->GetParam(0);
     $sFieldId = $this->GetParam(1);
     E::ModuleSecurity()->ValidateSendForm();
     if (!($oTopic = E::ModuleTopic()->GetTopicById($sTopicId))) {
         return parent::EventNotFound();
     }
     if (!($this->oType = E::ModuleTopic()->GetContentType($oTopic->getType()))) {
         return parent::EventNotFound();
     }
     if (!($oField = E::ModuleTopic()->GetContentFieldById($sFieldId))) {
         return parent::EventNotFound();
     }
     if ($oField->getContentId() != $this->oType->getContentId()) {
         return parent::EventNotFound();
     }
     //получаем объект файла
     $oFile = $oTopic->getFieldFile($oField->getFieldId());
     //получаем объект поля топика, содержащий данные о файле
     $oValue = $oTopic->getField($oField->getFieldId());
     if ($oFile && $oValue) {
         if (preg_match("/^(http:\\/\\/)/i", $oFile->getFileUrl())) {
             $sFullPath = $oFile->getFileUrl();
             R::Location($sFullPath);
         } else {
             $sFullPath = Config::Get('path.root.dir') . $oFile->getFileUrl();
         }
         $sFilename = $oFile->getFileName();
         /*
          * Обновляем данные
          */
         $aFileObj = array();
         $aFileObj['file_name'] = $oFile->getFileName();
         $aFileObj['file_url'] = $oFile->getFileUrl();
         $aFileObj['file_size'] = $oFile->getFileSize();
         $aFileObj['file_extension'] = $oFile->getFileExtension();
         $aFileObj['file_downloads'] = $oFile->getFileDownloads() + 1;
         $sText = serialize($aFileObj);
         $oValue->setValue($sText);
         $oValue->setValueSource($sText);
         //сохраняем
         E::ModuleTopic()->UpdateContentFieldValue($oValue);
         /*
          * Отдаем файл
          */
         header('Content-type: ' . $oFile->getFileExtension());
         header('Content-Disposition: attachment; filename="' . $sFilename . '"');
         F::File_PrintChunked($sFullPath);
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('content_download_file_error'));
         return R::Action('error');
     }
 }
Esempio n. 7
0
 public function EventIndex()
 {
     if ($nTopicId = intval($this->sCurrentEvent)) {
         $oTopic = E::ModuleTopic()->GetTopicById($nTopicId);
         if ($oTopic) {
             F::HttpRedirect($oTopic->getUrl());
             exit;
         }
     }
     return $this->EventNotFound();
 }
 /**
  * Выполняется при завершении работы экшена
  */
 public function EventShutdown()
 {
     parent::EventShutdown();
     if (!$this->oUserProfile) {
         return;
     }
     /**
      * Загружаем в шаблон необходимые переменные
      */
     $iCountDraftUser = E::ModuleTopic()->GetCountDraftsPersonalByUser($this->oUserProfile->getId());
     E::ModuleViewer()->Assign('iCountDraftUser', $iCountDraftUser);
 }
 /**
  * Обработка получения последних топиков
  * Используется в блоке "Прямой эфир"
  *
  */
 protected function EventStreamTopicSandbox()
 {
     $aVars = array();
     $aFilter = E::ModuleTopic()->GetNamedFilter('default', array('accessible' => true, 'sandbox' => true));
     $aTopics = E::ModuleTopic()->GetTopicsByFilter($aFilter, 1, Config::Get('widgets.stream.params.limit'));
     if ($aTopics) {
         $aVars['aTopics'] = $aTopics['collection'];
         // LS-compatibility
         $aVars['oTopics'] = $aTopics['collection'];
     }
     $sTextResult = E::ModuleViewer()->FetchWidget('stream_topic.tpl', $aVars);
     E::ModuleViewer()->AssignAjax('sText', $sTextResult);
 }
Esempio n. 10
0
 /**
  * @param array     $aTags
  * @param array|int $aExcludeTopics
  * @param int       $iLimit
  *
  * @return array
  */
 public function GetSimilarTopicsByTags($aTags, $aExcludeTopics = array(), $iLimit = null)
 {
     if (is_null($iLimit)) {
         $iLimit = 10;
     }
     $aTopicsId = $this->GetSimilarTopicsIdByTags($aTags, $aExcludeTopics, $iLimit);
     if ($aTopicsId) {
         $aTopics = E::ModuleTopic()->GetTopicsAdditionalData($aTopicsId);
     } else {
         $aTopics = array();
     }
     return $aTopics;
 }
Esempio n. 11
0
 /**
  * Получает список топиков по регулярному выражению (поиск)
  *
  * @param $sRegexp
  * @param $iPage
  * @param $iPerPage
  * @param array $aParams
  * @param bool $bAccessible
  *
  * @return array
  */
 public function GetTopicsIdByRegexp($sRegexp, $iPage, $iPerPage, $aParams = array(), $bAccessible = false)
 {
     $s = md5(serialize($sRegexp) . serialize($aParams));
     $sCacheKey = 'search_topics_' . $s . '_' . $iPage . '_' . $iPerPage;
     if (false === ($data = E::ModuleCache()->Get($sCacheKey))) {
         if ($bAccessible) {
             $aParams['aFilter'] = E::ModuleTopic()->GetNamedFilter(FALSE, array('accessible' => true));
         }
         $data = array('collection' => $this->oMapper->GetTopicsIdByRegexp($sRegexp, $iCount, $iPage, $iPerPage, $aParams), 'count' => $iCount);
         E::ModuleCache()->Set($data, $sCacheKey, array('topic_update', 'topic_new'), 'PT1H');
     }
     return $data;
 }
 /**
  * @param string $sCssClass
  *
  * @return int|string
  */
 public function newSandboxCount($sCssClass = '')
 {
     $iCount = E::ModuleTopic()->GetCountTopicsSandboxNew();
     if ($iCount) {
         if ($sCssClass) {
             $sData = '<span class="' . $sCssClass . '"> +' . $iCount . '</span>';
         } else {
             $sData = $iCount;
         }
     } else {
         $sData = '';
     }
     return $sData;
 }
 public function getApiData($aProps = array())
 {
     $aData = array();
     if (!empty($aProps)) {
         foreach ($aProps as $sProp => $sKey) {
             if (is_numeric($sProp)) {
                 $sProp = $sKey;
             }
             $aData[$sKey] = $this->getProp($sProp);
         }
     } else {
         $aData = array('id' => $this->getId(), 'title' => $this->getTitle(), 'annotation' => $this->getDescription(), 'date' => $this->getDateAdd(), 'avatar' => $this->getAvatarUrl(), 'author' => $this->getOwner()->getApiData(), 'count_topics' => $this->getCountTopic(), 'new_topics' => E::ModuleTopic()->GetCountTopicsByBlogNew($this));
     }
     return $aData;
 }
 public function EventSandbox()
 {
     // * Меню
     $this->sMenuSubItemSelect = 'sandbox';
     // * Передан ли номер страницы
     $iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1;
     // * Получаем список топиков
     $aResult = E::ModuleTopic()->GetTopicsNewAll($iPage, Config::Get('module.topic.per_page'));
     $aTopics = $aResult['collection'];
     // * Вызов хуков
     E::ModuleHook()->Run('topics_list_show', array('aTopics' => $aTopics));
     // * Формируем постраничность
     $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), R::GetPath('index/sandbox'));
     E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('plugin.sandbox.menu_text') . ($iPage > 1 ? ' (' . $iPage . ')' : ''));
     // * Загружаем переменные в шаблон
     E::ModuleViewer()->Assign('aTopics', $aTopics);
     E::ModuleViewer()->Assign('aPaging', $aPaging);
     // * Устанавливаем шаблон вывода
     $this->SetTemplateAction('index');
 }
Esempio n. 15
0
 /**
  * Запуск обработки
  */
 public function Exec()
 {
     $iLimit = C::Val('widgets.tags.params.limit', 70);
     // * Получаем список тегов
     $aTags = E::ModuleTopic()->GetOpenTopicTags($iLimit);
     // * Расчитываем логарифмическое облако тегов
     if ($aTags) {
         E::ModuleTools()->MakeCloud($aTags);
         // * Устанавливаем шаблон вывода
         E::ModuleViewer()->Assign('aTags', $aTags);
     }
     // * Теги пользователя
     if ($oUserCurrent = E::ModuleUser()->GetUserCurrent()) {
         $aTags = E::ModuleTopic()->GetOpenTopicTags($iLimit, $oUserCurrent->getId());
         // * Расчитываем логарифмическое облако тегов
         if ($aTags) {
             E::ModuleTools()->MakeCloud($aTags);
             // * Устанавливаем шаблон вывода
             E::ModuleViewer()->Assign('aTagsUser', $aTags);
         }
     }
 }
Esempio n. 16
0
 /**
  * Отображение топиков
  *
  */
 protected function EventTags()
 {
     // * Gets tag from URL
     $sTag = F::UrlDecode(R::Url('event'), true);
     // * Check page number
     $iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1;
     // * Gets topics list
     $aResult = E::ModuleTopic()->GetTopicsByTag($sTag, $iPage, Config::Get('module.topic.per_page'));
     $aTopics = $aResult['collection'];
     // * Calls hooks
     E::ModuleHook()->Run('topics_list_show', array('aTopics' => $aTopics));
     // * Makes pages
     $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), R::GetPath('tag') . htmlspecialchars($sTag));
     // * Loads variables to template
     E::ModuleViewer()->Assign('aPaging', $aPaging);
     E::ModuleViewer()->Assign('aTopics', $aTopics);
     E::ModuleViewer()->Assign('sTag', $sTag);
     E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('tag_title'));
     E::ModuleViewer()->AddHtmlTitle($sTag);
     E::ModuleViewer()->SetHtmlRssAlternate(R::GetPath('rss') . 'tag/' . $sTag . '/', $sTag);
     // * Sets template for display
     $this->SetTemplateAction('index');
 }
 public function EventCreatedSandbox()
 {
     if (!$this->CheckUserProfile()) {
         return parent::EventNotFound();
     }
     $this->sMenuSubItemSelect = 'sandbox';
     // * Передан ли номер страницы
     $iPage = $this->GetParamEventMatch(2, 2) ? $this->GetParamEventMatch(2, 2) : 1;
     // * Получаем список топиков
     $aResult = E::ModuleTopic()->GetTopicsSandboxByUser($this->oUserProfile->getId(), $iPage, Config::Get('module.topic.per_page'));
     $aTopics = $aResult['collection'];
     // * Вызов хуков
     E::ModuleHook()->Run('topics_list_show', array('aTopics' => $aTopics));
     // * Формируем постраничность
     $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), $this->oUserProfile->getUserUrl() . 'created/sandbox');
     // * Загружаем переменные в шаблон
     E::ModuleViewer()->Assign('aPaging', $aPaging);
     E::ModuleViewer()->Assign('aTopics', $aTopics);
     E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('user_menu_publication') . ' ' . $this->oUserProfile->getLogin());
     E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('plugin.sandbox.menu_text'));
     // * Устанавливаем шаблон вывода
     $this->SetTemplateAction('created_topics');
 }
 /**
  * Вывод всех черновиков
  */
 protected function EventDraft()
 {
     if (!E::IsAdmin()) {
         return parent::EventNotFound();
     }
     E::ModuleViewer()->SetHtmlRssAlternate(Router::GetPath('rss') . 'draft/', Config::Get('view.name'));
     /**
      * Меню
      */
     $this->sMenuSubItemSelect = 'draft';
     /**
      * Передан ли номер страницы
      */
     $iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1;
     /**
      * Получаем список топиков
      */
     $aResult = E::ModuleTopic()->GetTopicsDraftAll($iPage, Config::Get('module.topic.per_page'));
     $aTopics = $aResult['collection'];
     /**
      * Вызов хуков
      */
     E::ModuleHook()->Run('topics_list_show', array('aTopics' => $aTopics));
     /**
      * Формируем постраничность
      */
     $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), Router::GetPath('index') . 'draft');
     /**
      * Загружаем переменные в шаблон
      */
     E::ModuleViewer()->Assign('aTopics', $aTopics);
     E::ModuleViewer()->Assign('aPaging', $aPaging);
     /**
      * Устанавливаем шаблон вывода
      */
     $this->SetTemplateAction('index');
 }
Esempio n. 19
0
 /**
  * Вызывается по строке "no_new_topics"
  * @internal param $iParam
  * @internal param $sParamData
  * @return bool
  */
 public function NoNewTopics()
 {
     $sKeyString = 'menu_no_new_topics';
     if (FALSE === ($xData = E::ModuleCache()->GetTmp($sKeyString))) {
         $iCountTopicsCollectiveNew = E::ModuleTopic()->GetCountTopicsCollectiveNew();
         $iCountTopicsPersonalNew = E::ModuleTopic()->GetCountTopicsPersonalNew();
         $xData = $iCountTopicsCollectiveNew + $iCountTopicsPersonalNew == 0;
         E::ModuleCache()->SetTmp($xData, $sKeyString);
     }
     return $xData;
 }
Esempio n. 20
0
 /**
  * Returns stats of user publications and favourites
  *
  * @param int|object $xUser
  *
  * @return int[]
  */
 public function GetUserProfileStats($xUser)
 {
     if (is_object($xUser)) {
         $iUserId = $xUser->getId();
     } else {
         $iUserId = intval($xUser);
     }
     $iCountTopicFavourite = E::ModuleTopic()->GetCountTopicsFavouriteByUserId($iUserId);
     $iCountCommentFavourite = E::ModuleComment()->GetCountCommentsFavouriteByUserId($iUserId);
     $iCountTopics = E::ModuleTopic()->GetCountTopicsPersonalByUser($iUserId, 1);
     $iCountComments = E::ModuleComment()->GetCountCommentsByUserId($iUserId, 'topic');
     $iCountWallRecords = E::ModuleWall()->GetCountWall(array('wall_user_id' => $iUserId, 'pid' => null));
     $iImageCount = E::ModuleMresource()->GetCountImagesByUserId($iUserId);
     $iCountUserNotes = $this->GetCountUserNotesByUserId($iUserId);
     $iCountUserFriends = $this->GetCountUsersFriend($iUserId);
     $aUserPublicationStats = array('favourite_topics' => $iCountTopicFavourite, 'favourite_comments' => $iCountCommentFavourite, 'count_topics' => $iCountTopics, 'count_comments' => $iCountComments, 'count_usernotes' => $iCountUserNotes, 'count_wallrecords' => $iCountWallRecords, 'count_images' => $iImageCount, 'count_friends' => $iCountUserFriends);
     $aUserPublicationStats['count_created'] = $aUserPublicationStats['count_topics'] + $aUserPublicationStats['count_comments'] + $aUserPublicationStats['count_images'];
     if ($iUserId == E::UserId()) {
         $aUserPublicationStats['count_created'] += $aUserPublicationStats['count_usernotes'];
     }
     $aUserPublicationStats['count_favourites'] = $aUserPublicationStats['favourite_topics'] + $aUserPublicationStats['favourite_comments'];
     return $aUserPublicationStats;
 }
Esempio n. 21
0
 /**
  * Выполняется при завершении работы экшена
  *
  */
 public function EventShutdown()
 {
     $iCountTopicFavourite = E::ModuleTopic()->GetCountTopicsFavouriteByUserId($this->oUserCurrent->getId());
     $iCountTopicUser = E::ModuleTopic()->GetCountTopicsPersonalByUser($this->oUserCurrent->getId(), 1);
     $iCountCommentUser = E::ModuleComment()->GetCountCommentsByUserId($this->oUserCurrent->getId(), 'topic');
     $iCountCommentFavourite = E::ModuleComment()->GetCountCommentsFavouriteByUserId($this->oUserCurrent->getId());
     $iCountNoteUser = E::ModuleUser()->GetCountUserNotesByUserId($this->oUserCurrent->getId());
     E::ModuleViewer()->Assign('oUserProfile', $this->oUserCurrent);
     E::ModuleViewer()->Assign('iCountWallUser', E::ModuleWall()->GetCountWall(array('wall_user_id' => $this->oUserCurrent->getId(), 'pid' => null)));
     // * Общее число публикация и избранного
     E::ModuleViewer()->Assign('iCountTopicUser', $iCountTopicUser);
     E::ModuleViewer()->Assign('iCountCommentUser', $iCountCommentUser);
     E::ModuleViewer()->Assign('iCountTopicFavourite', $iCountTopicFavourite);
     E::ModuleViewer()->Assign('iCountCommentFavourite', $iCountCommentFavourite);
     E::ModuleViewer()->Assign('iCountNoteUser', $iCountNoteUser);
     E::ModuleViewer()->Assign('iCountCreated', $iCountNoteUser + $iCountTopicUser + $iCountCommentUser);
     E::ModuleViewer()->Assign('iCountFavourite', $iCountCommentFavourite + $iCountTopicFavourite);
     E::ModuleViewer()->Assign('iCountFriendsUser', E::ModuleUser()->GetCountUsersFriend($this->oUserCurrent->getId()));
     // * Загружаем в шаблон необходимые переменные
     E::ModuleViewer()->Assign('sMenuItemSelect', $this->sMenuItemSelect);
     E::ModuleViewer()->Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect);
     E::ModuleHook()->Run('action_shutdown_settings');
 }
Esempio n. 22
0
 /**
  * Return total number of pages of the sitemap type
  *
  * @param string $sType
  *
  * @return int
  */
 protected function _getSitemapCount($sType)
 {
     $iPerPage = C::Get('plugin.sitemap.items_per_page');
     switch ($sType) {
         case 'general':
             $iCount = 1;
             break;
         case 'topics':
             $iCount = (int) ceil(E::ModuleTopic()->GetTopicsCountForSitemap() / $iPerPage);
             break;
         case 'blogs':
             $iCount = (int) ceil(E::ModuleBlog()->GetBlogsCountForSitemap() / $iPerPage);
             break;
         case 'users':
             $iCount = (int) ceil(E::ModuleUser()->GetUsersCountForSitemap() / C::Get('plugin.sitemap.users_per_page'));
             break;
         default:
             $iCount = 1;
     }
     return $iCount;
 }
Esempio n. 23
0
 /**
  * Получение сведений о рейтинге топика
  * @param string $aParams Идентификатор пользователя
  * @return bool|array
  */
 public function ApiTopicIdRating($aParams)
 {
     /** @var ModuleTopic_EntityTopic $oTopic */
     if (!($oTopic = E::ModuleTopic()->GetTopicById($aParams['tid']))) {
         return FALSE;
     }
     return $this->_PrepareResult(array('oTopic' => $oTopic), array('id' => $oTopic->getId(), 'vote' => $oTopic->getVote(), 'count' => $oTopic->getCountVote(), 'up' => $oTopic->getCountVoteUp(), 'down' => $oTopic->getCountVoteDown(), 'abstain' => $oTopic->getCountVoteAbstain()));
 }
Esempio n. 24
0
 public function CountSimilarTopics()
 {
     return E::ModuleTopic()->CountSimilarTopics($this);
 }
Esempio n. 25
0
 /**
  * Поиск топиков
  */
 public function EventTopics()
 {
     $this->aReq = $this->_prepareRequest('topics');
     $this->OutLog();
     if ($this->aReq['regexp']) {
         $aResult = E::ModuleSearch()->GetTopicsIdByRegexp($this->aReq['regexp'], $this->aReq['iPage'], $this->nItemsPerPage, $this->aReq['params']);
         $aTopics = array();
         if ($aResult['count'] > 0) {
             $aTopicsFound = E::ModuleTopic()->GetTopicsAdditionalData($aResult['collection']);
             // * Подсветка поисковой фразы в тексте или формирование сниппета
             foreach ($aTopicsFound as $oTopic) {
                 if ($oTopic && $oTopic->getBlog()) {
                     if ($this->nModeOutList == 'short') {
                         $oTopic->setTextShort($this->_textHighlite($oTopic->getTextShort()));
                     } elseif ($this->nModeOutList == 'full') {
                         $oTopic->setTextShort($this->_textHighlite($oTopic->getText()));
                     } else {
                         $oTopic->setTextShort($this->_makeSnippet($oTopic->getText()));
                     }
                     $oTopic->setBlogTitle($oTopic->getBlog()->getTitle());
                     $aTopics[] = $oTopic;
                 }
             }
         }
     } else {
         $aResult['count'] = 0;
         $aTopics = array();
     }
     if ($this->bLogEnable) {
         $this->oLogs->RecordAdd('search', array('q' => $this->aReq['q'], 'result' => 'topics:' . $aResult['count']));
         $this->oLogs->RecordEnd('search', true);
     }
     $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $this->aReq['iPage'], $this->nItemsPerPage, 4, Config::Get('path.root.url') . '/search/topics', array('q' => $this->aReq['q']));
     $this->SetTemplateAction('results');
     $aRes = array('aCounts' => array('topics' => $aResult['count'], 'comments' => null));
     // *  Отправляем данные в шаблон
     E::ModuleViewer()->AddHtmlTitle($this->aReq['q']);
     E::ModuleViewer()->Assign('bIsResults', !empty($aResult['count']));
     E::ModuleViewer()->Assign('aRes', $aRes);
     E::ModuleViewer()->Assign('aTopics', $aTopics);
     E::ModuleViewer()->Assign('aPaging', $aPaging);
 }
Esempio n. 26
0
 /**
  * Получает список топиков
  *
  * @param array $aIds    Список  ID топиков
  *
  * @return array
  */
 protected function loadRelatedTopic($aIds)
 {
     return E::ModuleTopic()->GetTopicsAdditionalData($aIds);
 }
Esempio n. 27
0
 protected function CheckFieldsField($oContentType = null)
 {
     E::ModuleSecurity()->ValidateSendForm();
     $bOk = true;
     if (!F::CheckVal(F::GetRequest('field_name', null, 'post'), 'text', 2, 100)) {
         E::ModuleMessage()->AddError(E::ModuleLang()->Get('action.admin.contenttypes_field_name_error'), E::ModuleLang()->Get('error'));
         $bOk = false;
     }
     if (!F::CheckVal(F::GetRequest('field_description', null, 'post'), 'text', 2, 200)) {
         E::ModuleMessage()->AddError(E::ModuleLang()->Get('action.admin.contenttypes_field_description_error'), E::ModuleLang()->Get('error'));
         $bOk = false;
     }
     if (R::GetActionEvent() == 'fieldadd') {
         if ($oContentType == 'photoset' && (F::GetRequest('field_type', null, 'post') == 'photoset' || $oContentType->isPhotosetEnable())) {
             E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error'));
             $bOk = false;
         }
         if (!in_array(F::GetRequest('field_type', null, 'post'), E::ModuleTopic()->GetAvailableFieldTypes())) {
             E::ModuleMessage()->AddError(E::ModuleLang()->Get('action.admin.contenttypes_field_type_error'), E::ModuleLang()->Get('error'));
             $bOk = false;
         }
     }
     // * Выполнение хуков
     E::ModuleHook()->Run('check_admin_content_fields', array('bOk' => &$bOk));
     return $bOk;
 }
Esempio n. 28
0
 /**
  * Обработка дополнительных полей топика
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @param string $sType
  *
  * @return bool
  */
 public function processTopicFields($oTopic, $sType = 'add')
 {
     /** @var ModuleTopic_EntityContentValues $aValues */
     $aValues = array();
     if ($sType == 'update') {
         // * Получаем существующие значения
         if ($aData = $this->GetTopicValuesByArrayId(array($oTopic->getId()))) {
             $aValues = $aData[$oTopic->getId()];
         }
         // * Чистим существующие значения
         E::ModuleTopic()->DeleteTopicValuesByTopicId($oTopic->getId());
     }
     if ($oType = E::ModuleTopic()->GetContentTypeByUrl($oTopic->getType())) {
         //получаем поля для данного типа
         if ($aFields = $oType->getFields()) {
             foreach ($aFields as $oField) {
                 $sData = null;
                 if (isset($_REQUEST['fields'][$oField->getFieldId()]) || isset($_FILES['fields_' . $oField->getFieldId()]) || $oField->getFieldType() == 'single-image-uploader') {
                     //текстовые поля
                     if (in_array($oField->getFieldType(), array('input', 'textarea', 'select'))) {
                         $sData = E::ModuleText()->Parser($_REQUEST['fields'][$oField->getFieldId()]);
                     }
                     //поле ссылки
                     if ($oField->getFieldType() == 'link') {
                         $sData = $_REQUEST['fields'][$oField->getFieldId()];
                     }
                     //поле даты
                     if ($oField->getFieldType() == 'date') {
                         if (isset($_REQUEST['fields'][$oField->getFieldId()])) {
                             if (F::CheckVal($_REQUEST['fields'][$oField->getFieldId()], 'text', 6, 10) && substr_count($_REQUEST['fields'][$oField->getFieldId()], '.') == 2) {
                                 list($d, $m, $y) = explode('.', $_REQUEST['fields'][$oField->getFieldId()]);
                                 if (@checkdate($m, $d, $y)) {
                                     $sData = $_REQUEST['fields'][$oField->getFieldId()];
                                 }
                             }
                         }
                     }
                     //поле с файлом
                     if ($oField->getFieldType() == 'file') {
                         //если указано удаление файла
                         if (F::GetRequest('topic_delete_file_' . $oField->getFieldId())) {
                             if ($oTopic->getFieldFile($oField->getFieldId())) {
                                 @unlink(Config::Get('path.root.dir') . $oTopic->getFieldFile($oField->getFieldId())->getFileUrl());
                                 //$oTopic->setValueField($oField->getFieldId(),'');
                                 $sData = null;
                             }
                         } else {
                             //если удаление файла не указано, уже ранее залит файл^ и нового файла не загружалось
                             if ($sType == 'update' && isset($aValues[$oField->getFieldId()])) {
                                 $sData = $aValues[$oField->getFieldId()]->getValueSource();
                             }
                         }
                         if (isset($_FILES['fields_' . $oField->getFieldId()]) && is_uploaded_file($_FILES['fields_' . $oField->getFieldId()]['tmp_name'])) {
                             $iMaxFileSize = F::MemSize2Int(Config::Get('module.uploader.files.default.file_maxsize'));
                             $aFileExtensions = Config::Get('module.uploader.files.default.file_extensions');
                             if (!$iMaxFileSize || filesize($_FILES['fields_' . $oField->getFieldId()]['tmp_name']) <= $iMaxFileSize) {
                                 $aPathInfo = pathinfo($_FILES['fields_' . $oField->getFieldId()]['name']);
                                 if (!$aFileExtensions || in_array(strtolower($aPathInfo['extension']), $aFileExtensions)) {
                                     $sFileTmp = $_FILES['fields_' . $oField->getFieldId()]['tmp_name'];
                                     $sDirSave = Config::Get('path.uploads.root') . '/files/' . E::ModuleUser()->GetUserCurrent()->getId() . '/' . F::RandomStr(16);
                                     mkdir(Config::Get('path.root.dir') . $sDirSave, 0777, true);
                                     if (is_dir(Config::Get('path.root.dir') . $sDirSave)) {
                                         $sFile = $sDirSave . '/' . F::RandomStr(10) . '.' . strtolower($aPathInfo['extension']);
                                         $sFileFullPath = Config::Get('path.root.dir') . $sFile;
                                         if (copy($sFileTmp, $sFileFullPath)) {
                                             //удаляем старый файл
                                             if ($oTopic->getFieldFile($oField->getFieldId())) {
                                                 $sOldFile = Config::Get('path.root.dir') . $oTopic->getFieldFile($oField->getFieldId())->getFileUrl();
                                                 F::File_Delete($sOldFile);
                                             }
                                             $aFileObj = array();
                                             $aFileObj['file_hash'] = F::RandomStr(32);
                                             $aFileObj['file_name'] = E::ModuleText()->Parser($_FILES['fields_' . $oField->getFieldId()]['name']);
                                             $aFileObj['file_url'] = $sFile;
                                             $aFileObj['file_size'] = $_FILES['fields_' . $oField->getFieldId()]['size'];
                                             $aFileObj['file_extension'] = $aPathInfo['extension'];
                                             $aFileObj['file_downloads'] = 0;
                                             $sData = serialize($aFileObj);
                                             F::File_Delete($sFileTmp);
                                         }
                                     }
                                 } else {
                                     $sTypes = implode(', ', $aFileExtensions);
                                     E::ModuleMessage()->AddError(E::ModuleLang()->Get('topic_field_file_upload_err_type', array('types' => $sTypes)), null, true);
                                 }
                             } else {
                                 E::ModuleMessage()->AddError(E::ModuleLang()->Get('topic_field_file_upload_err_size', array('size' => $iMaxFileSize)), null, true);
                             }
                             F::File_Delete($_FILES['fields_' . $oField->getFieldId()]['tmp_name']);
                         }
                     }
                     // Поле с изображением
                     if ($oField->getFieldType() == 'single-image-uploader') {
                         $sTargetType = $oField->getFieldType() . '-' . $oField->getFieldId();
                         $iTargetId = $oTopic->getId();
                         // 1. Удалить значение target_tmp
                         // Нужно затереть временный ключ в ресурсах, что бы в дальнейшем картнка не
                         // воспринималась как временная.
                         if ($sTargetTmp = E::ModuleSession()->GetCookie(ModuleUploader::COOKIE_TARGET_TMP)) {
                             // 2. Удалить куку.
                             // Если прозошло сохранение вновь созданного топика, то нужно
                             // удалить куку временной картинки. Если же сохранялся уже существующий топик,
                             // то удаление куки ни на что влиять не будет.
                             E::ModuleSession()->DelCookie(ModuleUploader::COOKIE_TARGET_TMP);
                             // 3. Переместить фото
                             $sNewPath = E::ModuleUploader()->GetUserImageDir(E::UserId(), true, false);
                             $aMresourceRel = E::ModuleMresource()->GetMresourcesRelByTargetAndUser($sTargetType, 0, E::UserId());
                             if ($aMresourceRel) {
                                 $oResource = array_shift($aMresourceRel);
                                 $sOldPath = $oResource->GetFile();
                                 $oStoredFile = E::ModuleUploader()->Store($sOldPath, $sNewPath);
                                 /** @var ModuleMresource_EntityMresource $oResource */
                                 $oResource = E::ModuleMresource()->GetMresourcesByUuid($oStoredFile->getUuid());
                                 if ($oResource) {
                                     $oResource->setUrl(E::ModuleMresource()->NormalizeUrl(E::ModuleUploader()->GetTargetUrl($sTargetType, $iTargetId)));
                                     $oResource->setType($sTargetType);
                                     $oResource->setUserId(E::UserId());
                                     // 4. В свойство поля записать адрес картинки
                                     $sData = $oResource->getMresourceId();
                                     $oResource = array($oResource);
                                     E::ModuleMresource()->UnlinkFile($sTargetType, 0, $oTopic->getUserId());
                                     E::ModuleMresource()->AddTargetRel($oResource, $sTargetType, $iTargetId);
                                 }
                             }
                         } else {
                             // Топик редактируется, просто обновим поле
                             $aMresourceRel = E::ModuleMresource()->GetMresourcesRelByTargetAndUser($sTargetType, $iTargetId, E::UserId());
                             if ($aMresourceRel) {
                                 $oResource = array_shift($aMresourceRel);
                                 $sData = $oResource->getMresourceId();
                             } else {
                                 $sData = false;
                                 //                                    $this->DeleteField($oField);
                             }
                         }
                     }
                     E::ModuleHook()->Run('content_field_proccess', array('sData' => &$sData, 'oField' => $oField, 'oTopic' => $oTopic, 'aValues' => $aValues, 'sType' => &$sType));
                     //Добавляем поле к топику.
                     if ($sData) {
                         /** @var ModuleTopic_EntityContentValues $oValue */
                         $oValue = E::GetEntity('Topic_ContentValues');
                         $oValue->setTargetId($oTopic->getId());
                         $oValue->setTargetType('topic');
                         $oValue->setFieldId($oField->getFieldId());
                         $oValue->setFieldType($oField->getFieldType());
                         $oValue->setValue($sData);
                         $oValue->setValueSource(in_array($oField->getFieldType(), array('file', 'single-image-uploader')) ? $sData : $_REQUEST['fields'][$oField->getFieldId()]);
                         $this->AddTopicValue($oValue);
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 29
0
 /**
  * @return ModuleTopic_EntityContentType
  */
 public function getContentType()
 {
     $oContentType = $this->getProp('_content_type');
     if (is_null($oContentType)) {
         $oContentType = E::ModuleTopic()->GetContentType($this->getType());
         $this->setProp('_content_type', $oContentType);
     }
     return $oContentType;
 }
Esempio n. 30
0
 /**
  * Get sitemap data for the sitemap data and page
  *
  * @param string $sType
  * @param int    $iPage
  *
  * @return array
  */
 public function GetDataFor($sType, $iPage)
 {
     if ($iPage < 1) {
         $iPage = 1;
     }
     switch ($sType) {
         case 'general':
             $aData = $this->getDataForGeneral();
             break;
         case 'topics':
             $aData = E::ModuleTopic()->GetTopicsForSitemap($iPage);
             break;
         case 'blogs':
             $aData = E::ModuleBlog()->GetBlogsForSitemap($iPage);
             break;
         case 'users':
             $aData = $this->PluginSitemap_User_GetUsersForSitemap($iPage);
             break;
         default:
             $aData = array();
     }
     return $aData;
 }