Exemplo n.º 1
0
/**
 * Строит дерево форумов
 *
 * @param	array	$aForums
 * @param	array	$aList
 * @param	string	$sDepthGuide
 * @param	integer $iLevel
 * @return	array
 */
function forum_create_list($aForums = array(), $aList = array(), $sDepthGuide = "", $iLevel = 0)
{
    if (is_array($aForums) && !empty($aForums)) {
        foreach ($aForums as $oForum) {
            $aList[] = array('id' => $oForum->getId(), 'title' => $sDepthGuide . $oForum->getTitle(), 'level' => $iLevel);
            if ($aSubForums = $oForum->getChildren()) {
                $aList = forum_create_list($aSubForums, $aList, $sDepthGuide . PluginForum_ModuleForum::DEPTH_GUIDE, $iLevel + 1);
            }
        }
    }
    return $aList;
}
Exemplo n.º 2
0
 /**
  * Удаление форума
  * TODO: Проверить необходимость пересчета счетчиков
  */
 protected function _adminForumDelete()
 {
     $sForumId = $this->GetParam(2);
     if (!($oForumDelete = $this->PluginForum_Forum_GetForumById($sForumId))) {
         return parent::EventNotFound();
     }
     /**
      * Получаем список форумов
      */
     $aForums = $this->PluginForum_Forum_LoadTreeOfForum(array('#order' => array('forum_sort' => 'asc')));
     /**
      * Дерево форумов
      */
     $aForumsList = forum_create_list($aForums);
     /**
      * Загружаем переменные в шаблон
      */
     $this->Viewer_Assign('oForum', $oForumDelete);
     $this->Viewer_Assign('aForums', $aForums);
     $this->Viewer_Assign('aForumsList', $aForumsList);
     /**
      * Вызов хуков
      */
     $this->Hook_Run('forum_delete_show');
     /**
      * Устанавливаем шаблон вывода
      */
     $this->SetTemplateAction('admin/forum_delete');
     /**
      * Обрабатываем создание форума
      */
     if (isPost('submit_forum_delete')) {
         /**
          * Получаем топики форума
          */
         $aTopics = $this->PluginForum_Forum_GetTopicItemsByForumId($sForumId);
         /**
          * Получаем подфорумы
          */
         $aSubForums = $oForumDelete->getChildren();
         /**
          * Получаем всех потомков форума
          */
         $aDescendantsIds = array();
         $aDescendants = $this->PluginForum_Forum_GetDescendantsOfForum($oForumDelete);
         foreach ($aDescendants as $oDescendant) {
             $aDescendantsIds[] = $oDescendant->getId();
         }
         /**
          * Если указан идентификатор форума для перемещения, то делаем попытку переместить топики.
          *
          * (-1) - выбран пункт меню "удалить топики".
          */
         if ($sForumIdNew = getRequestStr('forum_move_id_topics') and $sForumIdNew != -1 and is_array($aTopics) and count($aTopics)) {
             if (!($oForumNew = $this->PluginForum_Forum_GetForumById($sForumIdNew))) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_error'), $this->Lang_Get('error'));
                 return;
             }
             /**
              * Если выбранный форум является удаляемым форум
              */
             if ($sForumIdNew == $sForumId) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_items_error_self'), $this->Lang_Get('error'));
                 return;
             }
             /**
              * Если выбранный форум является одним из подфорумов удаляемого форум
              */
             if (in_array($sForumIdNew, $aDescendantsIds)) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_items_error_descendants'), $this->Lang_Get('error'));
                 return;
             }
             /**
              * Если выбранный форум является категорией, возвращаем ошибку
              */
             if ($oForumNew->getCanPost()) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_items_error_category'), $this->Lang_Get('error'));
                 return;
             }
         }
         /**
          * Если указан идентификатор форума для перемещения, то делаем попытку переместить подфорумы.
          */
         if ($sForumIdNew = getRequestStr('forum_delete_move_childrens') and is_array($aSubForums) and count($aSubForums)) {
             if (!($oForumNew = $this->PluginForum_Forum_GetForumById($sForumIdNew))) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_error'), $this->Lang_Get('error'));
                 return;
             }
             /**
              * Если выбранный форум является удаляемым форум
              */
             if ($sForumIdNew == $sForumId) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_childrens_error_self'), $this->Lang_Get('error'));
                 return;
             }
             /**
              * Если выбранный форум является одним из подфорумов удаляемого форум
              */
             if (in_array($sForumIdNew, $aDescendantsIds)) {
                 $this->Message_AddError($this->Lang_Get('plugin.forum.delete_move_childrens_error_descendants'), $this->Lang_Get('error'));
                 return;
             }
         }
         /**
          * Перемещаем топики
          */
         if ($sForumIdNew = getRequestStr('forum_move_id_topics') and $sForumIdNew != -1 and is_array($aTopics) and count($aTopics)) {
             $this->PluginForum_Forum_MoveTopics($sForumId, $sForumIdNew);
         }
         /**
          * Перемещаем подфорумы
          */
         if ($sForumIdNew = getRequestStr('forum_delete_move_childrens') and is_array($aSubForums) and count($aSubForums)) {
             $this->PluginForum_Forum_MoveForums($sForumId, $sForumIdNew);
         }
         /**
          * Вызов хуков
          */
         $this->Hook_Run('forum_delete_before', array('oForum' => $oForumDelete));
         /**
          * Удаляем форум и перенаправляем админа к списку форумов
          */
         if ($this->PluginForum_Forum_DeleteForum($oForumDelete)) {
             $this->Hook_Run('forum_delete_after', array('oForum' => $oForumDelete));
             $this->Message_AddNoticeSingle($this->Lang_Get('plugin.forum.delete_success'), $this->Lang_Get('attention'), true);
             Router::Location(Router::GetPath('forum') . 'admin/forums/');
         } else {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             //Router::Location(Router::GetPath('forum').'admin/forums/');
         }
     }
 }