public function Init() { E::ModuleViewer()->SetResponseAjax('json'); if (!E::IsAdmin()) { Router::Location('error/404/'); } $this->oUserCurrent = E::User(); }
public function RegisterHook() { if (E::IsAdmin()) { if (Config::Get('plugin.drafts.show_blog')) { $this->AddHook('template_menu_blog_blog_item', 'InjectBlogLink'); } if (Config::Get('plugin.drafts.show_personal') || Config::Get('plugin.drafts.show_blog')) { $this->AddHook('template_menu_blog_index_item', 'InjectIndexLink'); } if (Config::Get('plugin.drafts.show_profile')) { $this->AddHook('template_menu_profile_created_item', 'InjectProfileLink'); } } }
/** * Компилирует тему * * @param array $aParams Передаваемые параметры * @return bool */ public function CompileTheme($aParams, $bDownload = FALSE) { if (!E::User()) { return FALSE; } $sCompiledStyle = E::ModuleLess()->CompileFile(array(C::Get('path.skins.dir') . 'experience-simple/themes/custom/less/theme.less' => C::Get('path.root.web')), __DIR__ . '/../../../cache/', C::Get('path.skins.dir') . 'experience-simple/themes/custom/css/theme.custom.css.map', $aParams, $bDownload); if ($sCompiledStyle) { if (!$bDownload || E::IsAdmin()) { F::File_PutContents(C::Get('path.skins.dir') . 'experience-simple/themes/custom/css/theme.custom.css', $sCompiledStyle); } else { $sPath = C::Get('plugin.estheme.path_for_download') . E::UserId() . '/theme.custom.css'; F::File_PutContents($sPath, $sCompiledStyle); } } }
/** * Регистрируем хуки */ public function RegisterHook() { if (F::AjaxRequest()) { return; } $xShowStats = Config::Get('general.show.stats'); // if is null then show to admins only if (is_null($xShowStats) && E::IsAdmin() || $xShowStats === true || is_array($xShowStats) && in_array(E::UserId(), $xShowStats)) { $xShowStats = R::GetIsShowStats(); } else { $xShowStats = false; } if ($xShowStats) { $this->AddHook('template_layout_body_end', 'Statistics', __CLASS__, -1000); // LS-compatibility $this->AddHook('template_body_end', 'Statistics', __CLASS__, -1000); } }
/** * Получить ленту топиков по подписке * * @param int $iUserId ID пользователя, для которого получаем ленту * @param int $iCount Число получаемых записей (если null, из конфига) * @param int $iFromId Получить записи, начиная с указанной * * @return array */ public function Read($iUserId, $iCount = null, $iFromId = null) { if (!$iCount) { $iCount = Config::Get('module.userfeed.count_default'); } $aUserSubscribes = $this->oMapper->getUserSubscribes($iUserId); if (E::IsAdmin()) { $aFilter = array(); } else { $aOpenBlogTypes = E::ModuleBlog()->GetOpenBlogTypes(); $aFilter = array('include_types' => $aOpenBlogTypes); } $aTopicsIds = $this->oMapper->readFeed($aUserSubscribes, $iCount, $iFromId, $aFilter); if ($aTopicsIds) { return E::ModuleTopic()->GetTopicsAdditionalData($aTopicsIds); } return array(); }
/** * Список черновиков пользователя */ protected function EventCreatedDrafts() { if (!$this->CheckUserProfile()) { return parent::EventNotFound(); } if (!E::IsAdmin()) { return parent::EventNotFound(); } $this->sMenuSubItemSelect = 'draft'; /** * Передан ли номер страницы */ $iPage = $this->GetParamEventMatch(2, 2) ? $this->GetParamEventMatch(2, 2) : 1; /** * Получаем список топиков */ $aResult = E::ModuleTopic()->GetDraftsPersonalByUser($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/draft'); /** * Загружаем переменные в шаблон */ 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('user_menu_publication_blog')); E::ModuleViewer()->SetHtmlRssAlternate(Router::GetPath('rss') . 'personal_blog/' . $this->oUserProfile->getLogin() . '/', $this->oUserProfile->getLogin()); /** * Устанавливаем шаблон вывода */ $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'); }
/** * Возвращает true если текущий пользователь администратор * @see ModuleUser::GetUserCurrent * @see ModuleUser_EntityUser::isAdministrator * * @return bool */ public static function Adm() { return E::IsAdmin(); }
/** * Получает список топиков из избранного * * @param int $nUserId ID пользователя * @param int $iCurrPage Номер текущей страницы * @param int $iPerPage Количество элементов на страницу * * @return array('collection'=>array,'count'=>int) */ public function GetTopicsFavouriteByUserId($nUserId, $iCurrPage, $iPerPage) { $aCloseTopics = array(); /** * Получаем список идентификаторов избранных записей */ $data = $this->oUserCurrent && $nUserId == $this->oUserCurrent->getId() ? E::ModuleFavourite()->GetFavouritesByUserId($nUserId, 'topic', $iCurrPage, $iPerPage, $aCloseTopics) : E::ModuleFavourite()->GetFavouriteOpenTopicsByUserId($nUserId, $iCurrPage, $iPerPage); // * Получаем записи по переданому массиву айдишников if ($data['collection']) { $data['collection'] = $this->GetTopicsAdditionalData($data['collection']); } if ($data['collection'] && !E::IsAdmin()) { $aAllowBlogTypes = E::ModuleBlog()->GetOpenBlogTypes(); if ($this->oUserCurrent) { $aClosedBlogs = E::ModuleBlog()->GetAccessibleBlogsByUser($this->oUserCurrent); } else { $aClosedBlogs = array(); } foreach ($data['collection'] as $iId => $oTopic) { $oBlog = $oTopic->getBlog(); if ($oBlog) { if (!in_array($oBlog->getType(), $aAllowBlogTypes) && !in_array($oBlog->getId(), $aClosedBlogs)) { $oTopic->setTitle('...'); $oTopic->setText(E::ModuleLang()->Get('acl_cannot_show_content')); $oTopic->setTextShort(E::ModuleLang()->Get('acl_cannot_show_content')); } } } } return $data; }
/** * Регистрация хуков */ public function RegisterHook() { if (E::IsAdmin()) { $this->AddHook('template_admin_menu_tools', 'AdminMenuInject'); } }
/** * Вызывается по строке "is_admin" * @return bool */ public function IsAdmin() { return E::IsAdmin(); }
public function EventAjaxSetProfile() { // * Устанавливаем формат ответа E::ModuleViewer()->SetResponseAjax('json'); if (!E::IsAdmin()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error')); return; } $nUserId = intval($this->GetPost('user_id')); if ($nUserId && ($oUser = E::ModuleUser()->GetUserById($nUserId))) { $sData = $this->GetPost('profile_about'); if (!is_null($sData)) { $oUser->setProfileAbout($sData); } $sData = $this->GetPost('profile_site'); if (!is_null($sData)) { $oUser->setUserProfileSite(trim($sData)); } $sData = $this->GetPost('profile_email'); if (!is_null($sData)) { $oUser->setMail(trim($sData)); } if (E::ModuleUser()->Update($oUser) !== false) { E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('action.admin.saved_ok')); } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('action.admin.saved_err')); } } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_not_found'), E::ModuleLang()->Get('error')); } }
/** * Загрузка дерева изображений пользователя */ protected function EventImageManagerLoadTree() { // Менеджер изображений может запускаться в том числе и из админки // Если передано название скина админки, то используем его, если же // нет, то ту тему, которая установлена для сайта if (($sAdminTheme = F::GetRequest('admin')) && E::IsAdmin()) { C::Set('view.skin', $sAdminTheme); } $sPath = ($iUserId = (int) F::GetRequest('profile', FALSE)) ? 'actions/profile/created_photos/' : 'modals/insert_img/'; if ($iUserId && E::ModuleUser()->GetUserById($iUserId)) { C::Set('menu.data.profile_images.uid', $iUserId); } else { $iUserId = false; } if ($iUserId) { $aVars = array('iUserId' => $iUserId); $sCategories = E::ModuleViewer()->GetLocalViewer()->Fetch("{$sPath}inject.categories.tpl", $aVars); } else { $sCategories = E::ModuleViewer()->GetLocalViewer()->Fetch("{$sPath}inject.categories.tpl"); } E::ModuleViewer()->AssignAjax('categories', $sCategories); return FALSE; }
/** * Вывод топиков из определенного блога * */ protected function EventShowBlog() { $sShowType = $this->GetParamEventMatch(0, 0); if ($sShowType != 'draft') { return parent::EventShowBlog(); } if (!E::IsAdmin()) { return parent::EventNotFound(); } $sBlogUrl = $this->sCurrentEvent; /** * Проверяем есть ли блог с таким УРЛ */ if (!($oBlog = E::ModuleBlog()->GetBlogByUrl($sBlogUrl))) { return parent::EventNotFound(); } /** * Определяем права на отображение закрытого блога */ if ($oBlog->getType() == 'close' and (!$this->oUserCurrent or !in_array($oBlog->getId(), E::ModuleBlog()->GetAccessibleBlogsByUser($this->oUserCurrent)))) { $bCloseBlog = true; } else { $bCloseBlog = false; } /** * Меню */ $this->sMenuSubItemSelect = $sShowType; $this->sMenuSubBlogUrl = $oBlog->getUrlFull(); /** * Передан ли номер страницы */ $iPage = $this->GetParamEventMatch(1, 2) ? $this->GetParamEventMatch(1, 2) : 1; if (!$bCloseBlog) { /** * Получаем список топиков */ $aResult = E::ModuleTopic()->GetTopicsByBlog($oBlog, $iPage, Config::Get('module.topic.per_page'), $sShowType, null); $aTopics = $aResult['collection']; /** * Формируем постраничность */ $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), $oBlog->getUrlFull() . $sShowType, array()); /** * Получаем число новых топиков в текущем блоге */ $this->iCountTopicsBlogNew = E::ModuleTopic()->GetCountTopicsByBlogNew($oBlog); E::ModuleViewer()->Assign('aPaging', $aPaging); E::ModuleViewer()->Assign('aTopics', $aTopics); } /** * Выставляем SEO данные */ $sTextSeo = strip_tags($oBlog->getDescription()); E::ModuleViewer()->SetHtmlDescription(func_text_words($sTextSeo, Config::Get('seo.description_words_count'))); /** * Получаем список юзеров блога */ $aBlogUsersResult = E::ModuleBlog()->GetBlogUsersByBlogId($oBlog->getId(), ModuleBlog::BLOG_USER_ROLE_USER, 1, Config::Get('module.blog.users_per_page')); $aBlogUsers = $aBlogUsersResult['collection']; $aBlogModeratorsResult = E::ModuleBlog()->GetBlogUsersByBlogId($oBlog->getId(), ModuleBlog::BLOG_USER_ROLE_MODERATOR); $aBlogModerators = $aBlogModeratorsResult['collection']; $aBlogAdministratorsResult = E::ModuleBlog()->GetBlogUsersByBlogId($oBlog->getId(), ModuleBlog::BLOG_USER_ROLE_ADMINISTRATOR); $aBlogAdministrators = $aBlogAdministratorsResult['collection']; /** * Для админов проекта получаем список блогов и передаем их во вьювер */ if ($this->oUserCurrent and $this->oUserCurrent->isAdministrator()) { $aBlogs = E::ModuleBlog()->GetBlogs(); unset($aBlogs[$oBlog->getId()]); E::ModuleViewer()->Assign('aBlogs', $aBlogs); } /** * Вызов хуков */ E::ModuleHook()->Run('blog_collective_show', array('oBlog' => $oBlog, 'sShowType' => $sShowType)); /** * Загружаем переменные в шаблон */ E::ModuleViewer()->Assign('aBlogUsers', $aBlogUsers); E::ModuleViewer()->Assign('aBlogModerators', $aBlogModerators); E::ModuleViewer()->Assign('aBlogAdministrators', $aBlogAdministrators); E::ModuleViewer()->Assign('iCountBlogUsers', $aBlogUsersResult['count']); E::ModuleViewer()->Assign('iCountBlogModerators', $aBlogModeratorsResult['count']); E::ModuleViewer()->Assign('iCountBlogAdministrators', $aBlogAdministratorsResult['count'] + 1); E::ModuleViewer()->Assign('oBlog', $oBlog); E::ModuleViewer()->Assign('bCloseBlog', $bCloseBlog); /** * Устанавливаем title страницы */ E::ModuleViewer()->AddHtmlTitle($oBlog->getTitle()); E::ModuleViewer()->SetHtmlRssAlternate(Router::GetPath('rss') . 'blog/' . $oBlog->getUrl() . '/', $oBlog->getTitle()); /** * Устанавливаем шаблон вывода */ $this->SetTemplateAction('blog'); }
protected function _filterBlogUsers($aBlogUsers) { if (!$aBlogUsers || E::IsAdmin() || E::UserId() == $this->oUserProfile->getId()) { return $aBlogUsers; } else { // Blog types for guest and all users $aBlogTypes = E::ModuleBlog()->GetOpenBlogTypes(); foreach ($aBlogUsers as $n => $oBlogUser) { if (!in_array($oBlogUser->getBlog()->getType(), $aBlogTypes)) { unset($aBlogUsers[$n]); } } } return $aBlogUsers; }
/** * Список черновиков из всех блогов * * @param int $iPage Номер страницы * @param int $iPerPage Количество элементов на страницу * @return array */ public function GetTopicsDraftAll($iPage, $iPerPage) { if (E::IsAdmin()) { $aFilter = array('blog_type' => array(), 'topic_publish' => 0); if (Config::Get('plugin.drafts.show_personal')) { $aFilter['blog_type'][] = 'personal'; } if (Config::Get('plugin.drafts.show_blog')) { $aFilter['blog_type'][] = 'open'; } /** * Если пользователь авторизирован, то добавляем в выдачу * закрытые блоги в которых он состоит */ if ($this->oUserCurrent) { $aOpenBlogs = E::ModuleBlog()->GetAccessibleBlogsByUser($this->oUserCurrent); if (count($aOpenBlogs)) { $aFilter['blog_type']['close'] = $aOpenBlogs; } } return $this->GetTopicsByFilter($aFilter, $iPage, $iPerPage); } return array(); }
/** * Условия показа виджета * * @return bool */ public function isCondition() { $bResult = $this->getProp('_is_condition'); if (is_null($bResult)) { $bResult = true; $sCondition = $this->GetCondition(); if (is_string($sCondition) && $sCondition > '') { try { extract($this->GetParams(), EXTR_SKIP); $bResult = (bool) eval('return ' . $sCondition . ';'); } catch (Exception $oException) { $bResult = false; } } if ($bResult && ($sVisitors = $this->GetVisitors())) { if ($sVisitors == 'users') { $bResult = E::IsUser(); } elseif ($sVisitors == 'admins') { $bResult = E::IsAdmin(); } } $this->setProp('_is_condition', $bResult); } return $bResult; }