/** * Ajoute une discussion (avec le premier message) * * @author Christophe Beyer <*****@*****.**> * @since 2005/11/09 * @param integer $forum Id du forum * @param integer $auteur Id de l'utilisateur auteur de la discussion * @param string $message Corps du premier message de la discussion * @param string $format Format du premier message de la discussion * @return integer l'Id de la discussion démarrée ou NULL si erreur */ public function addForumTopic($forum, $auteur, $titre, $message, $format) { $res = NULL; if (1) { $daoTopics = _dao("forum_topics"); $newTopic = _record("forum_topics"); $newTopic->titre = $titre; $newTopic->forum = $forum; $newTopic->createur = $auteur; $newTopic->nb_messages = 0; $newTopic->nb_lectures = 0; $newTopic->status = 1; $newTopic->date_creation = date("Y-m-d H:i:s"); $daoTopics->insert($newTopic); if ($newTopic->id !== NULL) { $idMessage = ForumService::addForumMessage($newTopic->id, $forum, $auteur, $message, $format); if ($idMessage !== NULL) { ForumService::updateInfosTopics($newTopic->id); $res = $newTopic->id; } else { // Prob d'insertion du message } } } return $res; }
/** * @desc Return the categories manager. */ public static function get_categories_manager() { if (self::$categories_manager === null) { $categories_items_parameters = new CategoriesItemsParameters(); $categories_items_parameters->set_table_name_contains_items(ForumSetup::$forum_topics_table); $categories_items_parameters->set_field_name_id_category('idcat'); self::$categories_manager = new CategoriesManager(ForumCategoriesCache::load(), $categories_items_parameters); } return self::$categories_manager; }
public function get_search_request($args) { $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1; $search = $args['search']; $idcat = !empty($args['ForumIdcat']) ? NumberHelper::numeric($args['ForumIdcat']) : -1; $time = (!empty($args['ForumTime']) ? NumberHelper::numeric($args['ForumTime']) : 30000) * 3600 * 24; $where = !empty($args['ForumWhere']) ? TextHelper::strprotect($args['ForumWhere']) : 'all'; require_once PATH_TO_ROOT . '/forum/forum_defines.php'; $authorized_categories = ForumService::get_authorized_categories(Category::ROOT_CATEGORY); if ($where == 'all') { // All return "SELECT " . $args['id_search'] . " AS `id_search`,\n\t\t\t\tMIN(msg.id) AS `id_content`,\n\t\t\t\tt.title AS `title`,\n\t\t\t\tMAX(( 2 * FT_SEARCH_RELEVANCE(t.title, '" . $search . "') + FT_SEARCH_RELEVANCE(msg.contents, '" . $search . "') ) / 3) * " . $weight . " AS `relevance`,\n\t\t\t\tCONCAT('" . PATH_TO_ROOT . "/forum/topic.php?id=', t.id, '#m', msg.id) AS `link`\n\t\t\tFROM " . PREFIX . "forum_msg msg\n\t\t\tJOIN " . PREFIX . "forum_topics t ON t.id = msg.idtopic\n\t\t\tJOIN " . PREFIX . "forum_cats c ON c.id_parent != 0 AND c.id = t.idcat\n\t\t\tWHERE ( FT_SEARCH(t.title, '" . $search . "') OR FT_SEARCH(msg.contents, '" . $search . "') ) AND msg.timestamp > '" . (time() - $time) . "'\n\t\t\t" . ($idcat > 0 ? " AND c.id = " . $idcat : '') . " AND c.id IN (" . implode(',', $authorized_categories) . ")\n\t\t\tGROUP BY t.id\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT " . FORUM_MAX_SEARCH_RESULTS; } if ($where == 'contents') { // Contents return "SELECT " . $args['id_search'] . " AS `id_search`,\n\t\t\t\tMIN(msg.id) AS `id_content`,\n\t\t\t\tt.title AS `title`,\n\t\t\t\tMAX(FT_SEARCH_RELEVANCE(msg.contents, '" . $search . "')) * " . $weight . " AS `relevance`,\n\t\t\t\tCONCAT('" . PATH_TO_ROOT . "/forum/topic.php?id=', t.id, '#m', msg.id) AS `link`\n\t\t\tFROM " . PREFIX . "forum_msg msg\n\t\t\tJOIN " . PREFIX . "forum_topics t ON t.id = msg.idtopic\n\t\t\tJOIN " . PREFIX . "forum_cats c ON c.id_parent != 0 AND c.id = t.idcat\n\t\t\tWHERE FT_SEARCH(msg.contents, '" . $search . "') AND msg.timestamp > '" . (time() - $time) . "'\n\t\t\t" . ($idcat > 0 ? " AND c.id = " . $idcat : '') . " AND c.id IN (" . implode(',', $authorized_categories) . ")\n\t\t\tGROUP BY t.id\n\t\t\tLIMIT " . FORUM_MAX_SEARCH_RESULTS; } else { // Title only return "SELECT " . $args['id_search'] . " AS `id_search`,\n\t\t\t\tmsg.id AS `id_content`,\n\t\t\t\tt.title AS `title`,\n\t\t\t\tFT_SEARCH_RELEVANCE(t.title, '" . $search . "') * " . $weight . " AS `relevance`,\n\t\t\t\tCONCAT('" . PATH_TO_ROOT . "/forum/topic.php?id=', t.id, '#m', msg.id) AS `link`\n\t\t\tFROM " . PREFIX . "forum_msg msg\n\t\t\tJOIN " . PREFIX . "forum_topics t ON t.id = msg.idtopic\n\t\t\tJOIN " . PREFIX . "forum_cats c ON c.id_parent != 0 AND c.id = t.idcat\n\t\t\tWHERE FT_SEARCH(t.title, '" . $search . "') AND msg.timestamp > '" . (time() - $time) . "'\n\t\t\t" . ($idcat > 0 ? " AND c.id = " . $idcat : '') . " AND c.id IN (" . implode(',', $authorized_categories) . ")\n\t\t\tGROUP BY t.id\n\t\t\tLIMIT " . FORUM_MAX_SEARCH_RESULTS; } }
public function get_feed_data_struct($idcat = 0, $name = '') { $config = ForumConfig::load(); $category = ForumService::get_categories_manager()->get_categories_cache()->get_category($idcat); $data = new FeedData(); $data->set_title(LangLoader::get_message('xml_forum_desc', 'common', 'forum')); $data->set_date(new Date()); $data->set_link(DispatchManager::get_url('/syndication', '/rss/forum/' . $idcat . '/')); $data->set_host(HOST); $data->set_desc(LangLoader::get_message('xml_forum_desc', 'common', 'forum')); $data->set_lang(LangLoader::get_message('xml_lang', 'main')); $data->set_auth_bit(Category::READ_AUTHORIZATIONS); $categories = ForumService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true); $ids_categories = array_keys($categories); $results = PersistenceContext::get_querier()->select('SELECT t.id, t.idcat, t.title, t.last_timestamp, t.last_msg_id, t.display_msg, t.nbr_msg AS t_nbr_msg, msg.id mid, msg.contents FROM ' . PREFIX . 'forum_topics t LEFT JOIN ' . PREFIX . 'forum_msg msg ON msg.id = t.last_msg_id WHERE t.idcat IN :ids_categories ORDER BY t.last_timestamp DESC LIMIT :limit OFFSET 0', array('ids_categories' => $ids_categories, 'limit' => 2 * $config->get_number_messages_per_page())); foreach ($results as $row) { $item = new FeedItem(); //Link $last_page = ceil($row['t_nbr_msg'] / $config->get_number_messages_per_page()); $last_page_rewrite = $last_page > 1 ? '-' . $last_page : ''; $last_page = $last_page > 1 ? 'pt=' . $last_page . '&' : ''; $link = new Url('/forum/topic' . url('.php?' . $last_page . 'id=' . $row['id'], '-' . $row['id'] . $last_page_rewrite . '+' . Url::encode_rewrite($row['title']) . '.php') . '#m' . $row['last_msg_id']); $item->set_title(($config->is_message_before_topic_title_displayed() && !empty($row['display_msg']) ? TextHelper::html_entity_decode($config->get_message_before_topic_title(), ENT_NOQUOTES) . ' ' : '') . stripslashes($row['title'])); $item->set_link($link); $item->set_guid($link); $item->set_desc(FormatingHelper::second_parse($row['contents'])); $item->set_date(new Date($row['last_timestamp'], Timezone::SERVER_TIMEZONE)); $item->set_auth(ForumService::get_categories_manager()->get_heritated_authorizations($row['idcat'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY)); $data->add_item($item); } $results->dispose(); return $data; }
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ###################################################*/ require_once '../kernel/begin.php'; require_once '../forum/forum_begin.php'; require_once '../forum/forum_tools.php'; $alert = retrieve(GET, 'id', 0); $alert_post = retrieve(POST, 'id', 0); $topic_id = !empty($alert) ? $alert : $alert_post; try { $topic = PersistenceContext::get_querier()->select_single_row(PREFIX . 'forum_topics', array('idcat', 'title', 'subtitle'), 'WHERE id = :id', array('id' => $topic_id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } $category = ForumService::get_categories_manager()->get_categories_cache()->get_category($topic['idcat']); $topic_name = !empty($topic['title']) ? stripslashes($topic['title']) : ''; $Bread_crumb->add($config->get_forum_name(), 'index.php'); $Bread_crumb->add($category->get_name(), 'forum' . url('.php?id=' . $topic['idcat'], '-' . $topic['idcat'] . '+' . $category->get_rewrited_name() . '.php')); $Bread_crumb->add($topic['title'], 'topic' . url('.php?id=' . $alert, '-' . $alert . '-' . Url::encode_rewrite($topic_name) . '.php')); $Bread_crumb->add($LANG['alert_topic'], ''); define('TITLE', $LANG['alert_topic']); require_once '../kernel/header.php'; if (empty($alert) && empty($alert_post) || empty($topic['idcat'])) { AppContext::get_response()->redirect('/forum/index' . url('.php')); } if (!AppContext::get_current_user()->check_level(User::MEMBER_LEVEL)) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } $tpl = new FileTemplate('forum/forum_alert.tpl');
define('TITLE', $LANG['stats']); require_once '../kernel/header.php'; $tpl = new FileTemplate('forum/forum_stats.tpl'); $total_day = NumberHelper::round((time() - GeneralConfig::load()->get_site_install_date()->get_timestamp()) / (3600 * 24), 0); $timestamp_today = @mktime(0, 0, 1, Date::to_format(Date::DATE_NOW, 'm'), Date::to_format(Date::DATE_NOW, 'd'), Date::to_format(Date::DATE_NOW, 'y')); $total_topics = PersistenceContext::get_querier()->count(ForumSetup::$forum_topics_table); $total_messages = PersistenceContext::get_querier()->count(ForumSetup::$forum_message_table); $total_day = max(1, $total_day); $nbr_topics_day = NumberHelper::round($total_topics / $total_day, 1); $nbr_msg_day = NumberHelper::round($total_messages / $total_day, 1); $row = PersistenceContext::get_querier()->select_single_row_query("SELECT COUNT(*) as nbr_topics_today\nFROM " . ForumSetup::$forum_topics_table . " t\nJOIN " . ForumSetup::$forum_message_table . " m ON m.id = t.first_msg_id\nWHERE m.timestamp > :timestamp", array('timestamp' => $timestamp_today)); $nbr_topics_today = $row['nbr_topics_today']; $nbr_msg_today = PersistenceContext::get_querier()->count(ForumSetup::$forum_message_table, 'WHERE timestamp > :timestamp', array('timestamp' => $timestamp_today)); $vars_tpl = array('FORUM_NAME' => $config->get_forum_name(), 'NBR_TOPICS' => $total_topics, 'NBR_MSG' => $total_messages, 'NBR_TOPICS_DAY' => $nbr_topics_day, 'NBR_MSG_DAY' => $nbr_msg_day, 'NBR_TOPICS_TODAY' => $nbr_topics_today, 'NBR_MSG_TODAY' => $nbr_msg_today, 'L_FORUM_INDEX' => $LANG['forum_index'], 'L_FORUM' => $LANG['forum'], 'L_STATS' => $LANG['stats'], 'L_NBR_TOPICS' => $total_topics > 1 ? $LANG['topic_s'] : $LANG['topic'], 'L_NBR_MSG' => $total_messages > 1 ? $LANG['message_s'] : $LANG['message'], 'L_NBR_TOPICS_DAY' => $LANG['nbr_topics_day'], 'L_NBR_MSG_DAY' => $LANG['nbr_msg_day'], 'L_NBR_TOPICS_TODAY' => $LANG['nbr_topics_today'], 'L_NBR_MSG_TODAY' => $LANG['nbr_msg_today'], 'L_LAST_MSG' => $LANG['forum_last_msg'], 'L_POPULAR' => $LANG['forum_popular'], 'L_ANSWERS' => $LANG['forum_nbr_answers']); //Vérification des autorisations. $authorized_categories = ForumService::get_authorized_categories(Category::ROOT_CATEGORY); //Dernières réponses $result = PersistenceContext::get_querier()->select("SELECT t.id, t.title, c.id as cid, c.auth\nFROM " . PREFIX . "forum_topics t\nLEFT JOIN " . PREFIX . "forum_cats c ON c.id = t.idcat\nWHERE c.id_parent != 0 AND c.id IN :authorized_categories\nORDER BY t.last_timestamp DESC\nLIMIT 10", array('authorized_categories' => $authorized_categories)); while ($row = $result->fetch()) { $tpl->assign_block_vars('last_msg', array('U_TOPIC_ID' => url('.php?id=' . $row['id'], '-' . $row['id'] . '.php'), 'TITLE' => stripslashes($row['title']))); } $result->dispose(); //Les plus vus $result = PersistenceContext::get_querier()->select("SELECT t.id, t.title, c.id as cid, c.auth\nFROM " . PREFIX . "forum_topics t\nLEFT JOIN " . PREFIX . "forum_cats c ON c.id = t.idcat\nWHERE c.id_parent != 0 AND c.id IN :authorized_categories\nORDER BY t.nbr_views DESC\nLIMIT 10", array('authorized_categories' => $authorized_categories)); while ($row = $result->fetch()) { $tpl->assign_block_vars('popular', array('U_TOPIC_ID' => url('.php?id=' . $row['id'], '-' . $row['id'] . '.php'), 'TITLE' => stripslashes($row['title']))); } $result->dispose(); //Les plus répondus $result = PersistenceContext::get_querier()->select("SELECT t.id, t.title, c.id as cid, c.auth\nFROM " . PREFIX . "forum_topics t\nLEFT JOIN " . PREFIX . "forum_cats c ON c.id = t.idcat\nWHERE c.id_parent != 0 AND c.id IN :authorized_categories\nORDER BY t.nbr_msg DESC\nLIMIT 10", array('authorized_categories' => $authorized_categories)); while ($row = $result->fetch()) {
function update_last_topic_id($idcat) { $category = ForumService::get_categories_manager()->get_categories_cache()->get_category($idcat); $children = ForumService::get_categories_manager()->get_categories_cache()->get_children($idcat); //Récupération du timestamp du dernier message de la catégorie. $last_timestamp = 0; try { $last_timestamp = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_topics", 'MAX(last_timestamp)', 'WHERE idcat IN (' . implode(', ', array_keys($children)) . ')'); } catch (RowNotFoundException $e) { } $last_topic_id = 0; try { $last_topic_id = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_topics", 'id', 'WHERE last_timestamp = :timestamp', array('timestamp' => $last_timestamp)); } catch (RowNotFoundException $e) { } PersistenceContext::get_querier()->update(ForumSetup::$forum_cats_table, array('last_topic_id' => (int) $last_topic_id), 'WHERE id = :id', array('id' => $idcat)); if ($category->get_id_parent() != Category::ROOT_CATEGORY) { $this->Update_last_topic_id($category->get_id_parent()); //Appel recursif. } }
if ($nbr_topics == 0) { $tpl->put_all(array('C_NO_TOPICS' => true, 'L_NO_TOPICS' => '0 ' . $LANG['no_last_read'])); } //Listes les utilisateurs en lignes. list($users_list, $total_admin, $total_modo, $total_member, $total_visit, $total_online) = forum_list_user_online("AND s.location_script LIKE '%" . "/forum/lastread.php%'"); //Liste des catégories. $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS); $categories_tree = ForumService::get_categories_manager()->get_select_categories_form_field('cats', '', Category::ROOT_CATEGORY, $search_category_children_options); $method = new ReflectionMethod('AbstractFormFieldChoice', 'get_options'); $method->setAccessible(true); $categories_tree_options = $method->invoke($categories_tree); $cat_list = ''; foreach ($categories_tree_options as $option) { if ($option->get_raw_value()) { $cat = ForumService::get_categories_manager()->get_categories_cache()->get_category($option->get_raw_value()); if (!$cat->get_url()) { $cat_list .= $option->display()->render(); } } } $vars_tpl = array('C_USER_CONNECTED' => AppContext::get_current_user()->check_level(User::MEMBER_LEVEL), 'TOTAL_ONLINE' => $total_online, 'USERS_ONLINE' => $total_online - $total_visit == 0 ? '<em>' . $LANG['no_member_online'] . '</em>' : $users_list, 'ADMIN' => $total_admin, 'MODO' => $total_modo, 'MEMBER' => $total_member, 'GUEST' => $total_visit, 'SELECT_CAT' => $cat_list, 'L_USER' => $total_online > 1 ? $LANG['user_s'] : $LANG['user'], 'L_ADMIN' => $total_admin > 1 ? $LANG['admin_s'] : $LANG['admin'], 'L_MODO' => $total_modo > 1 ? $LANG['modo_s'] : $LANG['modo'], 'L_MEMBER' => $total_member > 1 ? $LANG['member_s'] : $LANG['member'], 'L_GUEST' => $total_visit > 1 ? $LANG['guest_s'] : $LANG['guest'], 'L_AND' => $LANG['and'], 'L_ONLINE' => strtolower($LANG['online']), 'C_PAGINATION' => $pagination->has_several_pages(), 'FORUM_NAME' => $config->get_forum_name(), 'PAGINATION' => $pagination->display(), 'U_CHANGE_CAT' => 'unread.php' . '&token=' . AppContext::get_session()->get_token(), 'U_ONCHANGE' => url(".php?id=' + this.options[this.selectedIndex].value + '", "forum-' + this.options[this.selectedIndex].value + '.php"), 'U_ONCHANGE_CAT' => url("index.php?id=' + this.options[this.selectedIndex].value + '", "cat-' + this.options[this.selectedIndex].value + '.php"), 'U_FORUM_CAT' => '<a href="' . PATH_TO_ROOT . '/forum/lastread.php' . '">' . $LANG['show_last_read'] . '</a>', 'U_POST_NEW_SUBJECT' => '', 'L_FORUM_INDEX' => $LANG['forum_index'], 'L_FORUM' => $LANG['forum'], 'L_AUTHOR' => $LANG['author'], 'L_TOPIC' => $nbr_topics > 1 ? $LANG['topic_s'] : $LANG['topic'], 'L_MESSAGE' => $LANG['replies'], 'L_ANSWERS' => $LANG['answers'], 'L_VIEW' => $LANG['views'], 'L_LAST_MESSAGE' => $LANG['last_message']); $tpl->put_all($vars_tpl); $tpl_top->put_all($vars_tpl); $tpl_bottom->put_all($vars_tpl); $tpl->put('forum_top', $tpl_top); $tpl->put('forum_bottom', $tpl_bottom); $tpl->display(); } else { AppContext::get_response()->redirect('/forum/index.php'); }
$error_controller = PHPBoostErrors::unexisting_element(); DispatchManager::redirect($error_controller); } $to = retrieve(POST, 'to', 0); //Catégorie cible. if (!ForumAuthorizationsService::check_authorizations($topic['idcat'])->moderation()) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } $id_first = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'MIN(id)', 'WHERE idtopic = :id', array('id' => $msg['idtopic'])); //Scindage du premier message interdite. if ($id_first == $id_post_msg) { $controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'), $LANG['e_unable_cut_forum']); DispatchManager::redirect($controller); } $category_to = ForumService::get_categories_manager()->get_categories_cache()->get_category($to); if (!empty($to) && $category_to->get_id_parent() != Category::ROOT_CATEGORY) { $title = retrieve(POST, 'title', ''); $subtitle = retrieve(POST, 'desc', ''); $contents = retrieve(POST, 'contents', '', TSTRING_PARSE); $type = retrieve(POST, 'type', 0); //Requête de "scindage" du topic. if (!empty($to) && !empty($contents) && !empty($title)) { //Instanciation de la class du forum. $Forumfct = new Forum(); $last_topic_id = $Forumfct->Cut_topic($id_post_msg, $msg['idtopic'], $topic['idcat'], $to, $title, $subtitle, $contents, $type, $msg['user_id'], $topic['last_user_id'], $topic['last_msg_id'], $topic['last_timestamp']); //Scindement du topic //Ajout d'un sondage en plus du topic. $question = retrieve(POST, 'question', ''); if (!empty($question)) { $poll_type = retrieve(POST, 'poll_type', 0);
protected function get_categories_manager() { return ForumService::get_categories_manager(); }
private function save() { $this->config->set_forum_name($this->form->get_value('forum_name')); $this->config->set_number_topics_per_page($this->form->get_value('number_topics_per_page')); $this->config->set_number_messages_per_page($this->form->get_value('number_messages_per_page')); $this->config->set_read_messages_storage_duration($this->form->get_value('read_messages_storage_duration')); $this->config->set_max_topic_number_in_favorite($this->form->get_value('max_topic_number_in_favorite')); if ($this->form->get_value('edit_mark_enabled')) { $this->config->enable_edit_mark(); } else { $this->config->disable_edit_mark(); } if ($this->form->get_value('multiple_posts_allowed')) { $this->config->allow_multiple_posts(); } else { $this->config->forbid_multiple_posts(); } if ($this->form->get_value('connexion_form_displayed')) { $this->config->display_connexion_form(); } else { $this->config->hide_connexion_form(); } if ($this->form->get_value('left_column_disabled')) { $this->config->disable_left_column(); } else { $this->config->enable_left_column(); } if ($this->form->get_value('right_column_disabled')) { $this->config->disable_right_column(); } else { $this->config->enable_right_column(); } if ($this->form->get_value('message_before_topic_title_displayed')) { $this->config->display_message_before_topic_title(); $this->config->set_message_before_topic_title($this->form->get_value('message_before_topic_title')); $this->config->set_message_when_topic_is_unsolved($this->form->get_value('message_when_topic_is_unsolved')); $this->config->set_message_when_topic_is_solved($this->form->get_value('message_when_topic_is_solved')); if ($this->form->get_value('message_before_topic_title_icon_displayed')) { $this->config->display_message_before_topic_title_icon(); } else { $this->config->hide_message_before_topic_title_icon(); } } else { $this->config->hide_message_before_topic_title(); } $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array()); ForumConfig::save(); ForumService::get_categories_manager()->regenerate_cache(); }
private function build_view() { global $LANG, $config, $nbr_msg_not_read, $tpl_top, $tpl_bottom; $id_get = retrieve(GET, 'id', 0); try { $this->category = ForumService::get_categories_manager()->get_categories_cache()->get_category($id_get); } catch (CategoryNotFoundException $e) { } require_once PATH_TO_ROOT . '/forum/forum_begin.php'; require_once PATH_TO_ROOT . '/forum/forum_tools.php'; $this->view = new FileTemplate('forum/forum_index.tpl'); //Affichage des sous-catégories de la catégorie. $display_cat = !empty($id_get); //Vérification des autorisations. $authorized_categories = ForumService::get_authorized_categories($id_get); //Calcul du temps de péremption, ou de dernière vue des messages par à rapport à la configuration. $max_time_msg = forum_limit_time_msg(); $is_guest = AppContext::get_current_user()->get_id() == -1; $total_topic = 0; $total_msg = 0; $i = 0; //On liste les catégories et sous-catégories. $result = PersistenceContext::get_querier()->select('SELECT @id_cat:= c.id, c.id AS cid, c.id_parent, c.name, c.rewrited_name, c.description as subname, c.url, c.last_topic_id, t.id AS tid, t.idcat, t.title, t.last_timestamp, t.last_user_id, t.last_msg_id, t.nbr_msg AS t_nbr_msg, t.display_msg, t.status, m.user_id, m.display_name as login, m.level as user_level, m.groups, v.last_view_id, (SELECT COUNT(*) FROM ' . ForumSetup::$forum_topics_table . ' WHERE idcat IN ( @id_cat, (SELECT GROUP_CONCAT(id SEPARATOR \',\') FROM ' . ForumSetup::$forum_cats_table . ' WHERE id_parent = @id_cat), (SELECT GROUP_CONCAT(childs.id SEPARATOR \',\') FROM ' . ForumSetup::$forum_cats_table . ' parents INNER JOIN ' . ForumSetup::$forum_cats_table . ' childs ON parents.id = childs.id_parent WHERE parents.id_parent = @id_cat) ) ) AS nbr_topic, (SELECT COUNT(*) FROM ' . ForumSetup::$forum_message_table . ' WHERE idtopic IN ( (SELECT GROUP_CONCAT(id SEPARATOR \',\') FROM ' . ForumSetup::$forum_topics_table . ' WHERE idcat = @id_cat), (SELECT GROUP_CONCAT(t.id SEPARATOR \',\') FROM ' . ForumSetup::$forum_topics_table . ' t LEFT JOIN ' . ForumSetup::$forum_cats_table . ' c ON t.idcat = c.id WHERE id_parent = @id_cat) ) ) AS nbr_msg FROM ' . ForumSetup::$forum_cats_table . ' c LEFT JOIN ' . ForumSetup::$forum_topics_table . ' t ON t.id = c.last_topic_id LEFT JOIN ' . ForumSetup::$forum_view_table . ' v ON v.user_id = :user_id AND v.idtopic = t.id LEFT JOIN ' . DB_TABLE_MEMBER . ' m ON m.user_id = t.last_user_id WHERE ' . ($display_cat ? 'c.id_parent = :id_cat AND ' : '') . 'c.id IN :authorized_categories ORDER BY c.id, c.id_parent, c.c_order', array('id_cat' => $id_get, 'user_id' => AppContext::get_current_user()->get_id(), 'authorized_categories' => $authorized_categories)); $categories = array(); while ($row = $result->fetch()) { $categories[] = $row; } $result->dispose(); $display_sub_cats = false; $is_sub_forum = array(); foreach ($categories as $row) { $this->view->assign_block_vars('forums_list', array()); if ($row['id_parent'] == Category::ROOT_CATEGORY && $i > 0 && $display_sub_cats) { $this->view->assign_block_vars('forums_list.endcats', array()); } $i++; if ($row['id_parent'] == Category::ROOT_CATEGORY) { $this->view->assign_block_vars('forums_list.cats', array('IDCAT' => $row['cid'], 'NAME' => $row['name'], 'U_FORUM_VARS' => ForumUrlBuilder::display_category($row['cid'], $row['rewrited_name'])->rel())); $display_sub_cats = true; } else { if (in_array($row['id_parent'], $is_sub_forum)) { $is_sub_forum[] = $row['cid']; } if (($display_sub_cats || !empty($id_get)) && !in_array($row['cid'], $is_sub_forum)) { if ($display_cat) { $this->view->assign_block_vars('forums_list.cats', array('IDCAT' => $this->category->get_id(), 'NAME' => $this->category->get_name(), 'U_FORUM_VARS' => PATH_TO_ROOT . '/forum/' . url('index.php?id=' . $this->category->get_id(), 'cat-' . $this->category->get_id() . '+' . $this->category->get_rewrited_name() . '.php'))); $display_cat = false; } $subforums = ''; $this->view->put_all(array('C_FORUM_ROOT_CAT' => false, 'C_FORUM_CHILD_CAT' => true, 'C_END_S_CATS' => false)); $children = ForumService::get_categories_manager()->get_categories_cache()->get_childrens($row['cid']); if ($children) { foreach ($children as $id => $child) { if ($child->get_id_parent() == $row['cid'] && ForumAuthorizationsService::check_authorizations($child->get_id())->read()) { $is_sub_forum[] = $child->get_id(); $link = $child->get_url() ? '<a href="' . $child->get_url() . '" class="small">' : '<a href="forum' . url('.php?id=' . $child->get_id(), '-' . $child->get_id() . '+' . $child->get_rewrited_name() . '.php') . '" class="small">'; $subforums .= !empty($subforums) ? ', ' . $link . $child->get_name() . '</a>' : $link . $child->get_name() . '</a>'; } } $subforums = '<strong>' . $LANG['subforum_s'] . '</strong>: ' . $subforums; } if (!empty($row['last_topic_id'])) { //Si le dernier message lu est présent on redirige vers lui, sinon on redirige vers le dernier posté. if (!empty($row['last_view_id'])) { $last_msg_id = $row['last_view_id']; $last_page = 'idm=' . $row['last_view_id'] . '&'; $last_page_rewrite = '-0-' . $row['last_view_id']; } else { $last_msg_id = $row['last_msg_id']; $last_page = ceil($row['t_nbr_msg'] / $config->get_number_messages_per_page()); $last_page_rewrite = $last_page > 1 ? '-' . $last_page : ''; $last_page = $last_page > 1 ? 'pt=' . $last_page . '&' : ''; } $last_topic_title = ($config->is_message_before_topic_title_displayed() && $row['display_msg'] ? $config->get_message_before_topic_title() : '') . ' ' . $row['title']; $last_topic_title = stripslashes(strlen(TextHelper::html_entity_decode($last_topic_title)) > 20 ? TextHelper::substr_html($last_topic_title, 0, 20) . '...' : $last_topic_title); $row['login'] = !empty($row['login']) ? $row['login'] : $LANG['guest']; $group_color = User::get_group_color($row['groups'], $row['user_level']); $last = '<a href="' . PATH_TO_ROOT . '/forum/topic' . url('.php?id=' . $row['tid'], '-' . $row['tid'] . '+' . Url::encode_rewrite($row['title']) . '.php') . '" class="small">' . $last_topic_title . '</a><br /> <a href="' . PATH_TO_ROOT . '/forum/topic' . url('.php?' . $last_page . 'id=' . $row['tid'], '-' . $row['tid'] . $last_page_rewrite . '+' . Url::encode_rewrite($row['title']) . '.php') . '#m' . $last_msg_id . '"><i class="fa fa-hand-o-right"></i></a> ' . $LANG['on'] . ' ' . Date::to_format($row['last_timestamp'], Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) . '<br />' . $LANG['by'] . ' ' . ($row['last_user_id'] != '-1' ? '<a href="' . UserUrlBuilder::profile($row['last_user_id'])->rel() . '" class="small ' . UserService::get_level_class($row['user_level']) . '"' . (!empty($group_color) ? ' style="color:' . $group_color . '"' : '') . '>' . $row['login'] . '</a>' : '<em>' . $LANG['guest'] . '</em>'); } else { $row['last_timestamp'] = ''; $last = '<br />' . $LANG['no_message'] . '<br /><br />'; } //Vérifications des topics Lu/non Lus. $img_announce = 'fa-announce'; $blink = false; if (!$is_guest) { if ($row['last_view_id'] != $row['last_msg_id'] && $row['last_timestamp'] >= $max_time_msg) { $img_announce = $img_announce . '-new'; //Image affiché aux visiteurs. $blink = true; } } $img_announce .= $row['status'] == '0' ? '-lock' : ''; $total_topic += $row['nbr_topic']; $total_msg += $row['nbr_msg']; $this->view->assign_block_vars('forums_list.subcats', array('C_BLINK' => $blink, 'IMG_ANNOUNCE' => $img_announce, 'NAME' => $row['name'], 'DESC' => FormatingHelper::second_parse($row['subname']), 'SUBFORUMS' => !empty($subforums) && !empty($row['subname']) ? '<br />' . $subforums : $subforums, 'NBR_TOPIC' => $row['nbr_topic'], 'NBR_MSG' => $row['nbr_msg'], 'U_FORUM_URL' => $row['url'], 'U_FORUM_VARS' => ForumUrlBuilder::display_forum($row['cid'], $row['rewrited_name'])->rel(), 'U_LAST_TOPIC' => $last)); } } } if ($i > 0) { $this->view->assign_block_vars('forums_list', array()); $this->view->assign_block_vars('forums_list.endcats', array()); } $site_path = GeneralConfig::get_default_site_path(); if (GeneralConfig::load()->get_module_home_page() == 'forum') { list($users_list, $total_admin, $total_modo, $total_member, $total_visit, $total_online) = forum_list_user_online("AND s.location_script = '" . $site_path . "/forum/' OR s.location_script = '" . $site_path . "/forum/index.php' OR s.location_script = '" . $site_path . "/index.php' OR s.location_script = '" . $site_path . "/'"); } else { $where = "AND s.location_script LIKE '%" . $site_path . "/forum/%'"; if (!empty($id_get)) { $where = "AND s.location_script LIKE '%" . $site_path . url('/forum/index.php?id=' . $id_get, '/forum/cat-' . $id_get . ($this->category !== false && $id_get != Category::ROOT_CATEGORY ? '+' . $this->category->get_rewrited_name() : '') . '.php') . "'"; } list($users_list, $total_admin, $total_modo, $total_member, $total_visit, $total_online) = forum_list_user_online($where); } //Liste des catégories. $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS); $categories_tree = ForumService::get_categories_manager()->get_select_categories_form_field('cats', '', $id_get, $search_category_children_options); $method = new ReflectionMethod('AbstractFormFieldChoice', 'get_options'); $method->setAccessible(true); $categories_tree_options = $method->invoke($categories_tree); $cat_list = ''; foreach ($categories_tree_options as $option) { if ($option->get_raw_value()) { $cat = ForumService::get_categories_manager()->get_categories_cache()->get_category($option->get_raw_value()); if (!$cat->get_url()) { $cat_list .= $option->display()->render(); } } } $vars_tpl = array('FORUM_NAME' => $config->get_forum_name(), 'NBR_MSG' => $total_msg, 'NBR_TOPIC' => $total_topic, 'C_USER_CONNECTED' => AppContext::get_current_user()->check_level(User::MEMBER_LEVEL), 'TOTAL_ONLINE' => $total_online, 'USERS_ONLINE' => $total_online - $total_visit == 0 ? '<em>' . $LANG['no_member_online'] . '</em>' : $users_list, 'ADMIN' => $total_admin, 'MODO' => $total_modo, 'MEMBER' => $total_member, 'GUEST' => $total_visit, 'SELECT_CAT' => !empty($id_get) ? $cat_list : '', 'C_TOTAL_POST' => true, 'U_ONCHANGE' => PATH_TO_ROOT . "/forum/" . url("index.php?id=' + this.options[this.selectedIndex].value + '", "forum-' + this.options[this.selectedIndex].value + '.php"), 'U_ONCHANGE_CAT' => PATH_TO_ROOT . "/forum/" . url("/index.php?id=' + this.options[this.selectedIndex].value + '", "cat-' + this.options[this.selectedIndex].value + '.php"), 'L_FORUM_INDEX' => $LANG['forum_index'], 'L_FORUM' => $LANG['forum'], 'L_TOPIC' => $total_topic > 1 ? $LANG['topic_s'] : $LANG['topic'], 'L_MESSAGE' => $total_msg > 1 ? $LANG['message_s'] : $LANG['message'], 'L_LAST_MESSAGE' => $LANG['last_message'], 'L_STATS' => $LANG['stats'], 'L_DISPLAY_UNREAD_MSG' => $LANG['show_not_reads'], 'L_MARK_AS_READ' => $LANG['mark_as_read'], 'L_TOTAL_POST' => $LANG['nbr_message'], 'L_DISTRIBUTED' => strtolower($LANG['distributed']), 'L_AND' => $LANG['and'], 'L_USER' => $total_online > 1 ? $LANG['user_s'] : $LANG['user'], 'L_ADMIN' => $total_admin > 1 ? $LANG['admin_s'] : $LANG['admin'], 'L_MODO' => $total_modo > 1 ? $LANG['modo_s'] : $LANG['modo'], 'L_MEMBER' => $total_member > 1 ? $LANG['member_s'] : $LANG['member'], 'L_GUEST' => $total_visit > 1 ? $LANG['guest_s'] : $LANG['guest'], 'L_AND' => $LANG['and'], 'L_ONLINE' => strtolower($LANG['online'])); $this->view->put_all($vars_tpl); $tpl_top->put_all($vars_tpl); $tpl_bottom->put_all($vars_tpl); $this->view->put('forum_top', $tpl_top); $this->view->put('forum_bottom', $tpl_bottom); return $this->view; }