Advertisement
Guest User

0-MODED-post.php

a guest
Jan 11th, 2019
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 45.58 KB | None | 0 0
  1. <?php
  2. /*##################################################
  3.  *                                post.php
  4.  *                            -------------------
  5.  *   begin                : October 27, 2005
  6.  *   copyright            : (C) 2005 Viarre Régis
  7.  *   email                : crowkait@phpboost.com
  8.  *
  9.  *
  10.  ###################################################
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software
  24.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  25.  *
  26.  ###################################################*/
  27.  
  28. require_once('../kernel/begin.php');
  29. require_once('../forum/forum_begin.php');
  30. require_once('../forum/forum_tools.php');
  31.  
  32. $id_get = retrieve(GET, 'id', 0);
  33.  
  34. $is_modo = ForumAuthorizationsService::check_authorizations($id_get)->moderation();
  35.  
  36. //Existance de la catégorie.
  37. if ($id_get != Category::ROOT_CATEGORY && !ForumService::get_categories_manager()->get_categories_cache()->category_exists($id_get))
  38. {
  39.     $controller = PHPBoostErrors::unexisting_page();
  40.     DispatchManager::redirect($controller);
  41. }
  42.  
  43. if (AppContext::get_current_user()->get_delay_readonly() > time()) //Lecture seule.
  44. {
  45.     $controller = PHPBoostErrors::user_in_read_only();
  46.     DispatchManager::redirect($controller);
  47. }
  48.  
  49. try {
  50.     $category = ForumService::get_categories_manager()->get_categories_cache()->get_category($id_get);
  51. } catch (CategoryNotFoundException $e) {
  52.     $error_controller = PHPBoostErrors::unexisting_page();
  53.     DispatchManager::redirect($error_controller);
  54. }
  55.  
  56. $locked_cat = ($category->get_status() == ForumCategory::STATUS_LOCKED && !AppContext::get_current_user()->is_admin());
  57.  
  58. //Récupération de la barre d'arborescence.
  59. $Bread_crumb->add($config->get_forum_name(), 'index.php');
  60. $categories = array_reverse(ForumService::get_categories_manager()->get_parents($id_get, true));
  61. foreach ($categories as $id => $cat)
  62. {
  63.     if ($cat->get_id() != Category::ROOT_CATEGORY)
  64.         $Bread_crumb->add($cat->get_name(), 'forum' . url('.php?id=' . $cat->get_id(), '-' . $cat->get_id() . '+' . $cat->get_rewrited_name() . '.php'));
  65. }
  66. $Bread_crumb->add($LANG['title_post'], '');
  67. define('TITLE', $LANG['title_forum']);
  68. require_once('../kernel/header.php');
  69.  
  70. $new_get = retrieve(GET, 'new', '');
  71. $idt_get = retrieve(GET, 'idt', '');
  72. $error_get = retrieve(GET, 'error', '');
  73. $previs = retrieve(POST, 'prw', false); //Prévisualisation des messages.
  74. $post_topic = retrieve(POST, 'post_topic', false);
  75. $preview_topic = retrieve(POST, 'prw_t', '');
  76.  
  77. $editor = AppContext::get_content_formatting_service()->get_default_editor();
  78. $editor->set_identifier('contents');
  79.    
  80. //Niveau d'autorisation de la catégorie
  81. if (ForumAuthorizationsService::check_authorizations($id_get)->read())
  82. {
  83.     $Forumfct = new Forum();
  84.  
  85.     //Mod anti-flood
  86.     $check_time = false;
  87.    
  88.     if (ContentManagementConfig::load()->is_anti_flood_enabled() && AppContext::get_current_user()->get_id() != -1)
  89.     {
  90.         try {
  91.             $check_time = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'MAX(timestamp) as timestamp', 'WHERE user_id = :user_id', array('user_id' => AppContext::get_current_user()->get_id()));
  92.         } catch (RowNotFoundException $e) {}
  93.     }
  94.  
  95.     //Affichage de l'arborescence des catégories.
  96.     $i = 0;
  97.     $forum_cats = '';
  98.     $Bread_crumb->remove_last();
  99.     foreach ($Bread_crumb->get_links() as $key => $array)
  100.     {
  101.         if ($i == 2)
  102.             $forum_cats .= '<a href="' . $array[1] . '">' . $array[0] . '</a>';
  103.         elseif ($i > 2)
  104.             $forum_cats .= ' &raquo; <a href="' . $array[1] . '">' . $array[0] . '</a>';
  105.         $i++;
  106.     }
  107.  
  108.     if ($previs) //Prévisualisation des messages
  109.     {
  110.         if (!ForumAuthorizationsService::check_authorizations($id_get)->write() || $locked_cat)
  111.             AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_write&id=' . $id_get, '', '&') . '#message_helper');
  112.  
  113.         try {
  114.             $topic = PersistenceContext::get_querier()->select_single_row_query('SELECT idcat, title, subtitle
  115.             FROM ' . PREFIX . 'forum_topics
  116.             WHERE id=:id', array(
  117.                 'id' => $idt_get
  118.             ));
  119.         } catch (RowNotFoundException $e) {
  120.             $controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'), $LANG['e_unexist_topic_forum']);
  121.             DispatchManager::redirect($controller);
  122.         }
  123.  
  124.         $tpl = new FileTemplate('forum/forum_edit_msg.tpl');
  125.  
  126.         $contents = retrieve(POST, 'contents', '', TSTRING);
  127.         $post_update = retrieve(POST, 'p_update', '', TSTRING_UNCHANGE);
  128.  
  129.         $update = !empty($post_update) ? $post_update : url('?new=n_msg&amp;idt=' . $idt_get . '&amp;id=' . $id_get . '&amp;token=' . AppContext::get_session()->get_token());
  130.         $submit = !empty($post_update) ? $LANG['update'] : $LANG['submit'];
  131.  
  132.         $vars_tpl = array(
  133.             'P_UPDATE' => $post_update,
  134.             'FORUM_NAME' => $config->get_forum_name(),
  135.             'KERNEL_EDITOR' => $editor->display(),
  136.             'DESC' => stripslashes($topic['subtitle']),
  137.             'CONTENTS' => $contents,
  138.             'DATE' => $LANG['on'] . ' ' . Date::to_format(Date::DATE_NOW, Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE),
  139.             'CONTENTS_PREVIEW' => FormatingHelper::second_parse(stripslashes(FormatingHelper::strparse($contents))),
  140.             'C_FORUM_PREVIEW_MSG' => true,
  141.             'U_ACTION' => 'post.php' . $update . '&amp;token=' . AppContext::get_session()->get_token(),
  142.             'U_FORUM_CAT' => $forum_cats,
  143.             'U_TITLE_T' => '<a href="topic' . url('.php?id=' . $idt_get, '-' . $idt_get . '.php') . '">' . stripslashes($topic['title']) . '</a>',
  144.             'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  145.             'L_REQUIRE_TEXT' => $LANG['require_text'],
  146.             'L_REQUIRE_TITLE' => $LANG['require_title'],
  147.             'L_FORUM_INDEX' => $LANG['forum_index'],
  148.             'L_EDIT_MESSAGE' => $LANG['preview'],
  149.             'L_MESSAGE' => $LANG['message'],
  150.             'L_SUBMIT' => $submit,
  151.             'L_PREVIEW' => $LANG['preview'],
  152.             'L_RESET' => $LANG['reset']
  153.         );
  154.  
  155.         $tpl->put_all($vars_tpl);
  156.        
  157.         $tpl->put('forum_top', $tpl_top->display());
  158.         $tpl->display();
  159.         $tpl->put('forum_bottom', $tpl_bottom->display());
  160.     }
  161.     elseif ($new_get === 'topic' && empty($error_get)) //Nouveau topic.
  162.     {
  163.         if ($post_topic && !empty($id_get))
  164.         {
  165.             if (!ForumAuthorizationsService::check_authorizations($id_get)->write() || $locked_cat)
  166.                 AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_write&id=' . $id_get, '', '&') . '#message_helper');
  167.  
  168.             if ($is_modo)
  169.                 $type = retrieve(POST, 'type', 0);
  170.             else
  171.                 $type = 0;
  172.  
  173.             //Verrouillé?
  174.             $check_status = $category->get_status();
  175.             //Déverrouillé pour admin et modo dans tous les cas
  176.             if ($is_modo)
  177.                 $check_status = ForumCategory::STATUS_UNLOCKED;
  178.  
  179.             $contents = retrieve(POST, 'contents', '', TSTRING_UNCHANGE);
  180.             $title = retrieve(POST, 'title', '');
  181.             $subtitle = retrieve(POST, 'desc', '');
  182.  
  183.             //Mod anti Flood
  184.             if ($check_time !== false && $check_status == ForumCategory::STATUS_UNLOCKED)
  185.             {
  186.                 $delay_flood = ContentManagementConfig::load()->get_anti_flood_duration(); //On recupère le delai de flood.
  187.                 $delay_expire = time() - $delay_flood; //On calcul la fin du delai.
  188.  
  189.                 //Droit de flooder?.
  190.                 if ($check_time >= $delay_expire && !ForumAuthorizationsService::check_authorizations()->flood()) //Flood
  191.                     AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=flood_t&id=' . $id_get, '', '&') . '#message_helper');
  192.             }
  193.  
  194.             if ($check_status == ForumCategory::STATUS_UNLOCKED)
  195.             {
  196.                 if (!empty($contents) && !empty($title)) //Insertion nouveau topic.
  197.                 {
  198.                     list($last_topic_id, $last_msg_id) = $Forumfct->Add_topic($id_get, $title, $subtitle, $contents, $type); //Insertion nouveau topic.
  199.  
  200.                     //Ajout d'un sondage en plus du topic.
  201.                     $question = retrieve(POST, 'question', '');
  202.                     if (!empty($question))
  203.                     {
  204.                         $poll_type = retrieve(POST, 'poll_type', 0);
  205.                         $poll_type = ($poll_type == 0 || $poll_type == 1) ? $poll_type : 0;
  206.  
  207.                         $answers = array();
  208.                         $nbr_votes = 0;
  209.                         for ($i = 0; $i < 20; $i++)
  210.                         {
  211.                             $answer = str_replace('|', '', retrieve(POST, 'a'.$i, ''));
  212.                             if (!empty($answer))
  213.                             {
  214.                                 $answers[$i] = $answer;
  215.                                 $nbr_votes++;
  216.                             }
  217.                         }
  218.                         $Forumfct->Add_poll($last_topic_id, $question, $answers, $nbr_votes, $poll_type); //Ajout du sondage.
  219.                     }
  220.  
  221.                     AppContext::get_response()->redirect('/forum/topic' . url('.php?id=' . $last_topic_id, '-' . $last_topic_id . '.php', '&') . '#m' . $last_msg_id);
  222.                 }
  223.                 else
  224.                     AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=incomplete_t&id=' . $id_get, '', '&') . '#message_helper');
  225.             }
  226.             else //Verrouillé
  227.                 AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_locked&id=' . $id_get, '', '&') . '#message_helper');
  228.         }
  229.         elseif (!empty($preview_topic) && !empty($id_get))
  230.         {
  231.             if (!ForumAuthorizationsService::check_authorizations($id_get)->write() || $locked_cat)
  232.                 AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_write&id=' . $id_get, '', '&') . '#message_helper');
  233.  
  234.             $tpl = new FileTemplate('forum/forum_post.tpl');
  235.  
  236.             $title = retrieve(POST, 'title', '', TSTRING_UNCHANGE);
  237.             $subtitle = retrieve(POST, 'desc', '', TSTRING_UNCHANGE);
  238.             $contents = retrieve(POST, 'contents', '', TSTRING_UNCHANGE);
  239.             $question = retrieve(POST, 'question', '', TSTRING_UNCHANGE);
  240.  
  241.             $type = retrieve(POST, 'type', 0);
  242.  
  243.             if (!$is_modo)
  244.                 $type = ( $type == 1 || $type == 0 ) ? $type : 0;
  245.             else
  246.             {
  247.                 $tpl->put_all(array(
  248.                     'C_FORUM_POST_TYPE' => true,
  249.                     'CHECKED_NORMAL' => (($type == '0') ? 'checked="ckecked"' : ''),
  250.                     'CHECKED_POSTIT' => (($type == '1') ? 'checked="ckecked"' : ''),
  251.                     'CHECKED_ANNONCE' => (($type == '2') ? 'checked="ckecked"' : ''),
  252.                     'L_TYPE' => '* ' . $LANG['type'],
  253.                     'L_DEFAULT' => $LANG['default'],
  254.                     'L_POST_IT' => $LANG['forum_postit'],
  255.                     'L_ANOUNCE' => $LANG['forum_announce']
  256.                 ));
  257.             }
  258.  
  259.             //Liste des choix des sondages => 20 maxi
  260.             $nbr_poll_field = 0;
  261.             for ($i = 0; $i < 20; $i++)
  262.             {
  263.                 $answer = retrieve(POST, 'a'.$i, '');
  264.                 if (!empty($answer))
  265.                 {
  266.                     $tpl->assign_block_vars('answers_poll', array(
  267.                         'ID' => $i,
  268.                         'ANSWER' => stripslashes($answer)
  269.                     ));
  270.                     $nbr_poll_field++;
  271.                 }
  272.             }
  273.             for ($i = $nbr_poll_field; $i < 5; $i++) //On complète s'il y a moins de 5 réponses.
  274.             {
  275.                 $tpl->assign_block_vars('answers_poll', array(
  276.                     'ID' => $i,
  277.                     'ANSWER' => ''
  278.                 ));
  279.                 $nbr_poll_field++;
  280.             }
  281.  
  282.             //Type de réponses du sondage.
  283.             $poll_type = retrieve(POST, 'poll_type', 0);
  284.  
  285.             $vars_tpl = array(
  286.                 'FORUM_NAME' => $config->get_forum_name(),
  287.                 'TITLE' => stripslashes($title),
  288.                 'DESC' => stripslashes($subtitle),
  289.                 'CONTENTS' => $contents,
  290.                 'KERNEL_EDITOR' => $editor->display(),
  291.                 'POLL_QUESTION' => $question,
  292.                 'IDTOPIC' => 0,
  293.                 'SELECTED_SIMPLE' => ($poll_type == 0) ? 'checked="ckecked"' : '',
  294.                 'SELECTED_MULTIPLE' => ($poll_type == 1) ? 'checked="ckecked"' : '',
  295.                 'NO_DISPLAY_POLL' => 'true',
  296.                 'NBR_POLL_FIELD' => $nbr_poll_field,
  297.                 'DATE' => $LANG['on'] . ' ' . Date::to_format(Date::DATE_NOW, Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE),
  298.                 'CONTENTS_PREVIEW' => FormatingHelper::second_parse(stripslashes(FormatingHelper::strparse($contents))),
  299.                 'C_FORUM_PREVIEW_MSG' => true,
  300.                 'C_ADD_POLL_FIELD' => $nbr_poll_field <= 19,
  301.                 'U_ACTION' => 'post.php' . url('?new=topic&amp;id=' . $id_get . '&amp;token=' . AppContext::get_session()->get_token()),
  302.                 'U_FORUM_CAT' => $forum_cats,
  303.                 'U_TITLE_T' => '<a href="post' . url('.php?new=topic&amp;id=' . $id_get) . '">' . $title . '</a>',
  304.                 'L_ACTION' => $LANG['forum_edit_subject'],
  305.                 'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  306.                 'L_REQUIRE_TEXT' => $LANG['require_text'],
  307.                 'L_REQUIRE_TITLE' => $LANG['require_title'],
  308.                 'L_REQUIRE_TITLE_POLL' => $LANG['require_title_poll'],
  309.                 'L_FORUM_INDEX' => $LANG['forum_index'],
  310.                 'L_TITLE' => $LANG['title'],
  311.                 'L_DESC' => $LANG['description'],
  312.                 'L_MESSAGE' => $LANG['message'],
  313.                 'L_SUBMIT' => $LANG['submit'],
  314.                 'L_PREVIEW' => $LANG['preview'],
  315.                 'L_RESET' => $LANG['reset'],
  316.                 'L_POLL' => $LANG['poll'],
  317.                 'L_OPEN_MENU_POLL' => $LANG['open_menu_poll'],
  318.                 'L_QUESTION' => $LANG['question'],
  319.                 'L_POLL_TYPE' => $LANG['poll_type'],
  320.                 'L_ANSWERS' => $LANG['answers'],
  321.                 'L_SINGLE' => $LANG['simple_answer'],
  322.                 'L_MULTIPLE' => $LANG['multiple_answer']
  323.             );
  324.  
  325.             $tpl->put_all($vars_tpl);
  326.            
  327.             $tpl->put('forum_top', $tpl_top->display());
  328.             $tpl->display();
  329.             $tpl->put('forum_bottom', $tpl_bottom->display());
  330.         }
  331.         else
  332.         {
  333.             if (!ForumAuthorizationsService::check_authorizations($id_get)->write() || $locked_cat)
  334.             {
  335.                 $controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'), $locked_cat ? $LANG['e_cat_lock_forum'] : $LANG['e_cat_write']);
  336.                 DispatchManager::redirect($controller);
  337.             }
  338.            
  339.             $tpl = new FileTemplate('forum/forum_post.tpl');
  340.  
  341.             if (ForumAuthorizationsService::check_authorizations($id_get)->moderation())
  342.             {
  343.                 $tpl->put_all(array(
  344.                     'C_FORUM_POST_TYPE' => true,
  345.                     'CHECKED_NORMAL' => 'checked="ckecked"',
  346.                     'L_TYPE' => '* ' . $LANG['type'],
  347.                     'L_DEFAULT' => $LANG['default'],
  348.                     'L_POST_IT' => $LANG['forum_postit'],
  349.                     'L_ANOUNCE' => $LANG['forum_announce']
  350.                 ));
  351.             }
  352.  
  353.             //Liste des choix des sondages => 20 maxi
  354.             $nbr_poll_field = 0;
  355.             for ($i = 0; $i < 5; $i++)
  356.             {
  357.                 $tpl->assign_block_vars('answers_poll', array(
  358.                     'ID' => $i,
  359.                     'ANSWER' => ''
  360.                 ));
  361.                 $nbr_poll_field++;
  362.             }
  363.  
  364.             $vars_tpl = array(
  365.                 'FORUM_NAME' => $config->get_forum_name(),
  366.                 'TITLE' => '',
  367.                 'DESC' => '',
  368.                 'SELECTED_SIMPLE' => 'checked="ckecked"',
  369.                 'IDTOPIC' => 0,
  370.                 'KERNEL_EDITOR' => $editor->display(),
  371.                 'NO_DISPLAY_POLL' => 'true',
  372.                 'NBR_POLL_FIELD' => $nbr_poll_field,
  373.                 'C_ADD_POLL_FIELD' => true,
  374.                 'U_ACTION' => 'post.php' . url('?new=topic&amp;id=' . $id_get . '&amp;token=' . AppContext::get_session()->get_token()),
  375.                 'U_FORUM_CAT' => $forum_cats,
  376.                 'U_TITLE_T' => '<a href="post' . url('.php?new=topic&amp;id=' . $id_get) . '" class="basic-button">' . $LANG['post_new_subject'] . '</a>',
  377.                 'L_ACTION' => $LANG['forum_new_subject'],
  378.                 'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  379.                 'L_REQUIRE_TEXT' => $LANG['require_text'],
  380.                 'L_REQUIRE_TITLE' => $LANG['require_title'],
  381.                 'L_REQUIRE_TITLE_POLL' => $LANG['require_title_poll'],
  382.                 'L_FORUM_INDEX' => $LANG['forum_index'],
  383.                 'L_TITLE' => $LANG['title'],
  384.                 'L_DESC' => $LANG['description'],
  385.                 'L_MESSAGE' => $LANG['message'],
  386.                 'L_SUBMIT' => $LANG['submit'],
  387.                 'L_PREVIEW' => $LANG['preview'],
  388.                 'L_RESET' => $LANG['reset'],
  389.                 'L_POLL' => $LANG['poll'],
  390.                 'L_OPEN_MENU_POLL' => $LANG['open_menu_poll'],
  391.                 'L_QUESTION' => $LANG['question'],
  392.                 'L_POLL_TYPE' => $LANG['poll_type'],
  393.                 'L_ANSWERS' => $LANG['answers'],
  394.                 'L_SINGLE' => $LANG['simple_answer'],
  395.                 'L_MULTIPLE' => $LANG['multiple_answer']
  396.             );
  397.  
  398.             $tpl->put_all($vars_tpl);
  399.            
  400.             $tpl->put('forum_top', $tpl_top->display());
  401.             $tpl->display();
  402.             $tpl->put('forum_bottom', $tpl_bottom->display());
  403.         }
  404.     }
  405.     elseif ($new_get === 'n_msg' && empty($error_get)) //Nouveau message
  406.     {
  407.         if (!ForumAuthorizationsService::check_authorizations($id_get)->write())
  408.             AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_write&id=' . $id_get, '', '&') . '#message_helper');
  409.        
  410.         try {
  411.             $topic = PersistenceContext::get_querier()->select_single_row_query('SELECT user_id, idcat, title, nbr_msg, last_user_id, last_msg_id, status
  412.            FROM ' . PREFIX . 'forum_topics
  413.            WHERE id=:id', array(
  414.                 'id' => $idt_get
  415.             ));
  416.  
  417.         } catch (RowNotFoundException $e) {
  418.             $controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'), $LANG['e_topic_lock_forum']);
  419.             DispatchManager::redirect($controller);
  420.         }
  421.  
  422.         //Catégorie verrouillée?
  423.         $check_status = $category->get_status();
  424.         //Déverrouillé pour admin et modo dans tous les cas
  425.         if ($is_modo)
  426.             $check_status = ForumCategory::STATUS_UNLOCKED;
  427.  
  428.         if ($check_status == ForumCategory::STATUS_LOCKED) //Verrouillée
  429.             AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_locked&id=' . $id_get, '', '&') . '#message_helper');
  430.            
  431.         //Mod anti Flood
  432.         if ($check_time !== false)
  433.         {
  434.             $delay_expire = time() - ContentManagementConfig::load()->get_anti_flood_duration(); //On calcul la fin du delai.
  435.             //Droit de flooder?
  436.             if ($check_time >= $delay_expire && !ForumAuthorizationsService::check_authorizations()->flood()) //Ok
  437.                 AppContext::get_response()->redirect( url(HOST . SCRIPT . '?error=flood&id=' . $id_get . '&idt=' . $idt_get, '', '&') . '#message_helper');
  438.         }
  439.  
  440.         $contents = retrieve(POST, 'contents', '', TSTRING_AS_RECEIVED);
  441.  
  442.         //Si le topic n'est pas vérrouilé on ajoute le message.
  443.         if ($topic['status'] != 0 || $is_modo)
  444.         {
  445.             if (!empty($contents) && !empty($idt_get) && empty($update)) //Nouveau message.
  446.             {
  447.                 $last_page = ceil( ($topic['nbr_msg'] + 1) / $config->get_number_messages_per_page() );
  448.                 $last_page_rewrite = ($last_page > 1) ? '-' . $last_page : '';
  449.                 $last_page = ($last_page > 1) ? '&pt=' . $last_page : '';
  450.  
  451.                 if (!$config->are_multiple_posts_allowed() && $topic['last_user_id'] == AppContext::get_current_user()->get_id())
  452.                 {
  453.                     $last_page = ceil( $topic['nbr_msg'] / $config->get_number_messages_per_page() );
  454.                     $last_page_rewrite = ($last_page > 1) ? '-' . $last_page : '';
  455.                     $last_page = ($last_page > 1) ? '&pt=' . $last_page : '';
  456.                    
  457.                     $last_message_content = '';
  458.                     try {
  459.                         $last_message_content = PersistenceContext::get_querier()->get_column_value(PREFIX . 'forum_msg', 'contents', 'WHERE id = :id', array('id' => $topic['last_msg_id']));
  460.                     } catch (RowNotFoundException $e) {}
  461.                    
  462.                     $now = new Date();
  463.                    
  464.                     if (AppContext::get_current_user()->get_editor() == 'TinyMCE')
  465.                     {
  466.                         $new_content = $last_message_content . '<br /><br />-------------------------------------------<br /><em>' . $LANG['edit_on'] . ' ' . $now->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE_TEXT) . '</em><br /><br />' . $contents;
  467.                     }
  468.                     else
  469.                     {
  470.                         $new_content = $last_message_content . '
  471.  
  472. -------------------------------------------
  473. <em>' . $LANG['edit_on'] . ' ' . $now->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE_TEXT) . '</em>
  474.  
  475. ' . $contents;
  476.                     }
  477.                    
  478.                     $Forumfct->Update_msg($idt_get, $topic['last_msg_id'], FormatingHelper::unparse(addslashes($new_content)), $topic['last_user_id']); //Mise à jour du topic.
  479.                     $last_msg_id = $topic['last_msg_id'];
  480.                    
  481.                     $last_timestamp = time();
  482.                     //Mise à jour de la date du dernier message du topic pour marquer le message comme non lu chez les autres membres
  483.                     PersistenceContext::get_querier()->update(PREFIX . "forum_topics", array('last_timestamp' => $last_timestamp), 'WHERE id = :idtopic', array('idtopic' => $idt_get));
  484.                    
  485.                     //On met à jour le last_topic_id dans la catégorie dans le lequel le message a été posté et ses parents
  486.                     $categories = array_keys(ForumService::get_categories_manager()->get_parents($topic['idcat'], true));
  487.                     PersistenceContext::get_querier()->update(ForumSetup::$forum_cats_table, array('last_topic_id' => $idt_get), 'WHERE id IN :categories_id', array('categories_id' => $categories));
  488.                    
  489.                     //On supprime les marqueurs de messages lus pour ce message.
  490.                     PersistenceContext::get_querier()->delete(PREFIX . 'forum_view', 'WHERE idtopic=:id AND last_view_id=:id_message', array('id' => $idt_get, 'id_message' => $last_msg_id));
  491.                    
  492.                     //On marque le topic comme lu pour le posteur
  493.                     mark_topic_as_read($idt_get, $last_msg_id, $last_timestamp);
  494.                 }
  495.                 else
  496.                     $last_msg_id = $Forumfct->Add_msg($idt_get, $topic['idcat'], $contents, $topic['title'], $last_page, $last_page_rewrite);
  497.                     if($topic['user_id'] != AppContext::get_current_user()->get_id())
  498.                     {
  499.                     $notify = New Notifications();
  500.                     $notify->set_sender_id(AppContext::get_current_user()->get_id());
  501.                     $notify->set_recipient_id($topic['user_id']);
  502.                     $notify->set_reading(0);
  503.                     $notify->set_date(time());
  504.                     $notify->set_content("a répondu à votre sujet <a href=\" ".PATH_TO_ROOT."/forum/topic". url('.php?id=' . $idt_get . $last_page, '-' . $idt_get . $last_page_rewrite . '.php', '&') . '#m' . $last_msg_id."\">".$topic['title']."</a> sur le forum");
  505.                     Notifications::add_notification($notify);
  506.                     }
  507.                    
  508.                 //Redirection après post.
  509.                 AppContext::get_response()->redirect('/forum/topic' . url('.php?id=' . $idt_get . $last_page, '-' . $idt_get . $last_page_rewrite . '.php', '&') . '#m' . $last_msg_id);
  510.             }
  511.             else
  512.                 AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=incomplete&id=' . $id_get . '&idt=' . $idt_get, '', '&') . '#message_helper');
  513.         }
  514.         else
  515.             AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=locked&id=' . $id_get . '&idt=' . $idt_get, '', '&') . '#message_helper');
  516.     }
  517.     elseif ($new_get === 'msg' && empty($error_get)) //Edition d'un message/topic.
  518.     {
  519.         if (!ForumAuthorizationsService::check_authorizations($id_get)->write())
  520.             AppContext::get_response()->redirect(url(HOST . SCRIPT . '?error=c_write&id=' . $id_get, '', '&') . '#message_helper');
  521.  
  522.         $id_m = retrieve(GET, 'idm', 0);
  523.         $update = retrieve(GET, 'update', false);
  524.        
  525.         try {
  526.             $id_first = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'MIN(id)', 'WHERE idtopic = :idtopic', array('idtopic' => $idt_get));
  527.         } catch (RowNotFoundException $e) {
  528.             $error_controller = PHPBoostErrors::unexisting_element();
  529.             DispatchManager::redirect($error_controller);
  530.         }
  531.        
  532.         if (empty($id_get) || empty($id_first)) //Topic/message inexistant.
  533.         {
  534.             $controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'), $LANG['e_unexist_topic_forum']);
  535.             DispatchManager::redirect($controller);
  536.         }
  537.        
  538.         try {
  539.             $topic = PersistenceContext::get_querier()->select_single_row(PREFIX . 'forum_topics', array('title', 'subtitle', 'type', 'user_id', 'display_msg'), 'WHERE id=:id', array('id' => $idt_get));
  540.         } catch (RowNotFoundException $e) {
  541.             $error_controller = PHPBoostErrors::unexisting_element();
  542.             DispatchManager::redirect($error_controller);
  543.         }
  544.  
  545.         //Edition du topic complet
  546.         if ($id_first == $id_m)
  547.         {
  548.             //User_id du message correspondant à l'utilisateur connecté => autorisation.
  549.             $user_id_msg = 0;
  550.             try {
  551.                 $user_id_msg = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'user_id', 'WHERE id = :id', array('id' => $id_m));
  552.             } catch (RowNotFoundException $e) {}
  553.            
  554.             $check_auth = false;
  555.             if ($user_id_msg == AppContext::get_current_user()->get_id())
  556.                 $check_auth = true;
  557.             elseif ($is_modo)
  558.                 $check_auth = true;
  559.  
  560.             if (!$check_auth)
  561.             {
  562.                 $error_controller = PHPBoostErrors::user_not_authorized();
  563.                 DispatchManager::redirect($error_controller);
  564.             }
  565.  
  566.             if ($update && $post_topic)
  567.             {
  568.                 $title = retrieve(POST, 'title', '');
  569.                 $subtitle = retrieve(POST, 'desc', '');
  570.                 $contents = retrieve(POST, 'contents', '', TSTRING_AS_RECEIVED);
  571.                 $type = $is_modo ? retrieve(POST, 'type', 0) : 0;
  572.  
  573.                 if (!empty($title) && !empty($contents))
  574.                 {
  575.                     $Forumfct->Update_topic($idt_get, $id_m, $title, $subtitle, addslashes($contents), $type, $user_id_msg); //Mise à jour du topic.
  576.  
  577.                     //Mise à jour du sondage en plus du topic.
  578.                     $del_poll = retrieve(POST, 'del_poll', false);
  579.                     $question = retrieve(POST, 'question', '');
  580.                     if (!empty($question) && !$del_poll) //Enregistrement du sondage.
  581.                     {
  582.                         //Mise à jour si le sondage existe, sinon création.
  583.                         $check_poll = PersistenceContext::get_querier()->count(PREFIX . 'forum_poll', 'WHERE idtopic=:idtopic', array('idtopic' => $idt_get));
  584.  
  585.                         $poll_type = retrieve(POST, 'poll_type', 0);
  586.                         $poll_type = ($poll_type == 0 || $poll_type == 1) ? $poll_type : 0;
  587.  
  588.                         $answers = array();
  589.                         $nbr_votes = 0;
  590.                         for ($i = 0; $i < 20; $i++)
  591.                         {
  592.                             $answer = str_replace('|', '', retrieve(POST, 'a'.$i, ''));
  593.                             if (!empty($answer))
  594.                             {
  595.                                 $answers[$i] = $answer;
  596.                                 $nbr_votes++;
  597.                             }
  598.                         }
  599.  
  600.                         if ($check_poll == 1) //Mise à jour.
  601.                             $Forumfct->Update_poll($idt_get, $question, $answers, $poll_type);
  602.                         elseif ($check_poll == 0) //Ajout du sondage.
  603.                             $Forumfct->Add_poll($idt_get, $question, $answers, $nbr_votes, $poll_type);
  604.                     }
  605.                     elseif ($del_poll && ForumAuthorizationsService::check_authorizations($id_get)->moderation()) //Suppression du sondage, admin et modo seulement biensûr...
  606.                         $Forumfct->Del_poll($idt_get);
  607.  
  608.                     //Redirection après post.
  609.                     AppContext::get_response()->redirect('/forum/topic' . url('.php?id=' . $idt_get, '-' . $idt_get . '.php', '&'));
  610.                 }
  611.                 else
  612.                     AppContext::get_response()->redirect('/forum/post' . url('.php?new=msg&idm=' . $id_m . '&id=' . $id_get . '&idt=' . $idt_get . '&errore=incomplete_t', '', '&') . '#message_helper');
  613.             }
  614.             elseif (!empty($preview_topic))
  615.             {
  616.                 $tpl = new FileTemplate('forum/forum_post.tpl');
  617.                
  618.                 $title = retrieve(POST, 'title', '', TSTRING_UNCHANGE);
  619.                 $subtitle = retrieve(POST, 'desc', '', TSTRING_UNCHANGE);
  620.                 $contents = retrieve(POST, 'contents', '', TSTRING_UNCHANGE);
  621.                 $question = retrieve(POST, 'question', '', TSTRING_UNCHANGE);
  622.  
  623.                 $type = retrieve(POST, 'type', 0);
  624.                 if (!$is_modo)
  625.                     $type = ($type == 1 || $type == 0) ? $type : 0;
  626.                 else
  627.                 {
  628.                     $tpl->put_all(array(
  629.                         'C_FORUM_POST_TYPE' => true,
  630.                         'CHECKED_NORMAL' => (($type == 0) ? 'checked="ckecked"' : ''),
  631.                         'CHECKED_POSTIT' => (($type == 1) ? 'checked="ckecked"' : ''),
  632.                         'CHECKED_ANNONCE' => (($type == 2) ? 'checked="ckecked"' : ''),
  633.                         'L_TYPE' => '* ' . $LANG['type'],
  634.                         'L_DEFAULT' => $LANG['default'],
  635.                         'L_POST_IT' => $LANG['forum_postit'],
  636.                         'L_ANOUNCE' => $LANG['forum_announce']
  637.                     ));
  638.                 }
  639.  
  640.                 //Liste des choix des sondages => 20 maxi
  641.                 $nbr_poll_field = 0;
  642.                 for ($i = 0; $i < 20; $i++)
  643.                 {
  644.                     $answer = retrieve(POST, 'a'.$i, '');
  645.                     if (!empty($anwser))
  646.                     {
  647.                         $tpl->assign_block_vars('answers_poll', array(
  648.                             'ID' => $i,
  649.                             'ANSWER' => stripslashes($anwser)
  650.                         ));
  651.                         $nbr_poll_field++;
  652.                     }
  653.                 }
  654.                 for ($i = $nbr_poll_field; $i < 5; $i++) //On complète s'il y a moins de 5 réponses.
  655.                 {
  656.                     $tpl->assign_block_vars('answers_poll', array(
  657.                         'ID' => $i,
  658.                         'ANSWER' => ''
  659.                     ));
  660.                     $nbr_poll_field++;
  661.                 }
  662.  
  663.                 //Type de réponses du sondage.
  664.                 $poll_type = retrieve(POST, 'poll_type', 0);
  665.  
  666.                 $vars_tpl = array(
  667.                     'FORUM_NAME' => $config->get_forum_name(),
  668.                     'TITLE' => stripslashes($title),
  669.                     'DESC' => stripslashes($subtitle),
  670.                     'CONTENTS' => $contents,
  671.                     'KERNEL_EDITOR' => $editor->display(),
  672.                     'POLL_QUESTION' => $question,
  673.                     'IDTOPIC' => 0,
  674.                     'SELECTED_SIMPLE' => 'checked="ckecked"',
  675.                     'NO_DISPLAY_POLL' => !empty($question) ? 'false' : 'true',
  676.                     'NBR_POLL_FIELD' => $nbr_poll_field,
  677.                     'SELECTED_SIMPLE' => ($poll_type == 0) ? 'checked="ckecked"' : '',
  678.                     'SELECTED_MULTIPLE' => ($poll_type == 1) ? 'checked="ckecked"' : '',
  679.                     'DATE' => $LANG['on'] . ' ' . Date::to_format(Date::DATE_NOW, Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE),
  680.                     'CONTENTS_PREVIEW' => FormatingHelper::second_parse(stripslashes(FormatingHelper::strparse($contents))),
  681.                     'C_FORUM_PREVIEW_MSG' => true,
  682.                     'C_DELETE_POLL' => $is_modo, //Suppression d'un sondage => modo uniquement.
  683.                     'C_ADD_POLL_FIELD' => $nbr_poll_field <= 19,
  684.                     'U_ACTION' => 'post.php' . url('?update=1&amp;new=msg&amp;id=' . $id_get . '&amp;idt=' . $idt_get . '&amp;idm=' . $id_m . '&amp;token=' . AppContext::get_session()->get_token()),
  685.                     'U_FORUM_CAT' => '<a href="forum' . url('.php?id=' . $id_get, '-' . $id_get . '.php') . '">' . $category->get_name() . '</a>',
  686.                     'U_TITLE_T' => '<a href="topic' . url('.php?id=' . $idt_get, '-' . $idt_get . '.php') . '">' . $title . '</a>',
  687.                     'L_ACTION' => $LANG['forum_edit_subject'],
  688.                     'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  689.                     'L_REQUIRE_TEXT' => $LANG['require_text'],
  690.                     'L_REQUIRE_TITLE' => $LANG['require_title'],
  691.                     'L_REQUIRE_TITLE_POLL' => $LANG['require_title_poll'],
  692.                     'L_FORUM_INDEX' => $LANG['forum_index'],
  693.                     'L_TITLE' => $LANG['title'],
  694.                     'L_DESC' => $LANG['description'],
  695.                     'L_MESSAGE' => $LANG['message'],
  696.                     'L_SUBMIT' => $LANG['update'],
  697.                     'L_PREVIEW' => $LANG['preview'],
  698.                     'L_RESET' => $LANG['reset'],
  699.                     'L_POLL' => $LANG['poll'],
  700.                     'L_OPEN_MENU_POLL' => $LANG['open_menu_poll'],
  701.                     'L_QUESTION' => $LANG['question'],
  702.                     'L_POLL_TYPE' => $LANG['poll_type'],
  703.                     'L_ANSWERS' => $LANG['answers'],
  704.                     'L_SINGLE' => $LANG['simple_answer'],
  705.                     'L_MULTIPLE' => $LANG['multiple_answer'],
  706.                     'L_DELETE_POLL' => $LANG['delete_poll']
  707.                 );
  708.  
  709.                 $tpl->put_all($vars_tpl);
  710.                
  711.                 $tpl->put('forum_top', $tpl_top->display());
  712.                 $tpl->display();
  713.                 $tpl->put('forum_bottom', $tpl_bottom->display());
  714.             }
  715.             else
  716.             {
  717.                 $tpl = new FileTemplate('forum/forum_post.tpl');
  718.  
  719.                 $contents = '';
  720.                 try {
  721.                     $contents = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'contents', 'WHERE id = :id', array('id' => $id_first));
  722.                 } catch (RowNotFoundException $e) {}
  723.                
  724.                 //Gestion des erreurs à l'édition.
  725.                 $get_error_e = retrieve(GET, 'errore', '');
  726.                 if ($get_error_e == 'incomplete_t')
  727.                     $tpl->put('message_helper', MessageHelper::display($LANG['e_incomplete'], MessageHelper::NOTICE));
  728.  
  729.                 if ($is_modo)
  730.                 {
  731.                     $tpl->put_all(array(
  732.                         'C_FORUM_POST_TYPE' => true,
  733.                         'CHECKED_NORMAL' => (($topic['type'] == '0') ? 'checked="ckecked"' : ''),
  734.                         'CHECKED_POSTIT' => (($topic['type'] == '1') ? 'checked="ckecked"' : ''),
  735.                         'CHECKED_ANNONCE' => (($topic['type'] == '2') ? 'checked="ckecked"' : ''),
  736.                         'L_TYPE' => '* ' . $LANG['type'],
  737.                         'L_DEFAULT' => $LANG['default'],
  738.                         'L_POST_IT' => $LANG['forum_postit'],
  739.                         'L_ANOUNCE' => $LANG['forum_announce']
  740.                     ));
  741.                 }
  742.  
  743.                 //Récupération des infos du sondage associé si il existe
  744.                 $poll = array('question' => '', 'answers' => '', 'votes' => '', 'type' => '');
  745.                 try {
  746.                     $poll = PersistenceContext::get_querier()->select_single_row(PREFIX . 'forum_poll', array('question', 'answers', 'votes', 'type'), 'WHERE idtopic=:id', array('id' => $idt_get));
  747.                 } catch (RowNotFoundException $e) {}
  748.                
  749.                 $array_answer = explode('|', $poll['answers']);
  750.                 $array_votes = explode('|', $poll['votes']);
  751.  
  752.                 $TmpTemplate = new FileTemplate('forum/forum_generic_results.tpl');
  753.                 $module_data_path = $TmpTemplate->get_pictures_data_path();
  754.                
  755.                 //Affichage du lien pour changer le display_msg du topic et autorisation d'édition.
  756.                 if ($config->is_message_before_topic_title_displayed() && ($is_modo || AppContext::get_current_user()->get_id() == $topic['user_id']))
  757.                 {
  758.                     $img_display = $topic['display_msg'] ? 'fa-msg-not-display' : 'fa-msg-display';
  759.                     $tpl_bottom->put_all(array(
  760.                         'C_DISPLAY_MSG' => true,
  761.                         'ICON_DISPLAY_MSG' => $config->is_message_before_topic_title_icon_displayed() ? '<i class="fa ' . $img_display . '"></i>' : '',
  762.                         'L_EXPLAIN_DISPLAY_MSG_DEFAULT' => $topic['display_msg'] ? $config->get_message_when_topic_is_solved() : $config->get_message_when_topic_is_unsolved(),
  763.                         'L_EXPLAIN_DISPLAY_MSG' => $config->get_message_when_topic_is_unsolved(),
  764.                         'L_EXPLAIN_DISPLAY_MSG_BIS' => $config->get_message_when_topic_is_solved()
  765.                     ));
  766.                     $tpl->put_all(array(
  767.                         'C_DISPLAY_MSG' => true,
  768.                         'ICON_DISPLAY_MSG' => $config->is_message_before_topic_title_icon_displayed() ? '<i class="fa ' . $img_display . '"></i>' : '',
  769.                         'L_EXPLAIN_DISPLAY_MSG_DEFAULT' => $topic['display_msg'] ? $config->get_message_when_topic_is_solved() : $config->get_message_when_topic_is_unsolved(),
  770.                         'L_EXPLAIN_DISPLAY_MSG' => $config->get_message_when_topic_is_unsolved(),
  771.                         'L_EXPLAIN_DISPLAY_MSG_BIS' => $config->get_message_when_topic_is_solved()
  772.                     ));
  773.                 }
  774.  
  775.                 //Liste des choix des sondages => 20 maxi
  776.                 $nbr_poll_field = 0;
  777.                 foreach ($array_answer as $key => $answer)
  778.                 {
  779.                     if (!empty($answer))
  780.                     {
  781.                         $nbr_votes = isset($array_votes[$key]) ? $array_votes[$key] : 0;
  782.                         $tpl->assign_block_vars('answers_poll', array(
  783.                             'ID' => $nbr_poll_field,
  784.                             'ANSWER' => stripslashes($answer),
  785.                             'NBR_VOTES' => $nbr_votes,
  786.                             'L_VOTES' => ($nbr_votes > 1) ? $LANG['votes'] : $LANG['vote']
  787.                         ));
  788.                         $nbr_poll_field++;
  789.                     }
  790.                 }
  791.                 for ($i = $nbr_poll_field; $i < 5; $i++) //On complète s'il y a moins de 5 réponses.
  792.                 {
  793.                     $tpl->assign_block_vars('answers_poll', array(
  794.                         'ID' => $i,
  795.                         'ANSWER' => ''
  796.                     ));
  797.                     $nbr_poll_field++;
  798.                 }
  799.                
  800.                 $vars_tpl = array(
  801.                     'FORUM_NAME' => $config->get_forum_name(),
  802.                     'TITLE' => stripslashes($topic['title']),
  803.                     'DESC' => stripslashes($topic['subtitle']),
  804.                     'CONTENTS' => FormatingHelper::unparse($contents),
  805.                     'POLL_QUESTION' => !empty($poll['question']) ? stripslashes($poll['question']) : '',
  806.                     'SELECTED_SIMPLE' => 'checked="ckecked"',
  807.                     'MODULE_DATA_PATH' => $module_data_path,
  808.                     'IDTOPIC' => $idt_get,
  809.                     'KERNEL_EDITOR' => $editor->display(),
  810.                     'NBR_POLL_FIELD' => $nbr_poll_field,
  811.                     'NO_DISPLAY_POLL' => !empty($poll['question']) ? 'false' : 'true',
  812.                     'C_DELETE_POLL' => $is_modo, //Suppression d'un sondage => modo uniquement.
  813.                     'C_ADD_POLL_FIELD' => ($nbr_poll_field <= 19),
  814.                     'U_ACTION' => 'post.php' . url('?update=1&amp;new=msg&amp;id=' . $id_get . '&amp;idt=' . $idt_get . '&amp;idm=' . $id_m . '&amp;token=' . AppContext::get_session()->get_token()),
  815.                     'U_FORUM_CAT' => '<a href="forum' . url('.php?id=' . $id_get, '-' . $id_get . '.php') . '">' . $category->get_name() . '</a>',
  816.                     'U_TITLE_T' => '<a href="topic' . url('.php?id=' . $idt_get, '-' . $idt_get . '.php') . '">' . stripslashes($topic['title']) . '</a>',
  817.                     'L_ACTION' => $LANG['forum_edit_subject'],
  818.                     'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  819.                     'L_REQUIRE_TEXT' => $LANG['require_text'],
  820.                     'L_REQUIRE_TITLE' => $LANG['require_title'],
  821.                     'L_REQUIRE_TITLE_POLL' => $LANG['require_title_poll'],
  822.                     'L_FORUM_INDEX' => $LANG['forum_index'],
  823.                     'L_TITLE' => $LANG['title'],
  824.                     'L_DESC' => $LANG['description'],
  825.                     'L_MESSAGE' => $LANG['message'],
  826.                     'L_SUBMIT' => $LANG['update'],
  827.                     'L_PREVIEW' => $LANG['preview'],
  828.                     'L_RESET' => $LANG['reset'],
  829.                     'L_POLL' => $LANG['poll'],
  830.                     'L_OPEN_MENU_POLL' => $LANG['open_menu_poll'],
  831.                     'L_QUESTION' => $LANG['question'],
  832.                     'L_POLL_TYPE' => $LANG['poll_type'],
  833.                     'L_ANSWERS' => $LANG['answers'],
  834.                     'L_SINGLE' => $LANG['simple_answer'],
  835.                     'L_MULTIPLE' => $LANG['multiple_answer'],
  836.                     'L_DELETE_POLL' => $LANG['delete_poll']
  837.                 );
  838.  
  839.                 //Type de réponses du sondage.
  840.                 if (isset($poll['type']) && $poll['type'] == '0')
  841.                 {
  842.                     $tpl->put_all(array(
  843.                         'SELECTED_SIMPLE' => 'checked="ckecked"'
  844.                     ));
  845.                 }
  846.                 elseif (isset($poll['type']) && $poll['type'] == '1')
  847.                 {
  848.                     $tpl->put_all(array(
  849.                         'SELECTED_MULTIPLE' => 'checked="ckecked"'
  850.                     ));
  851.                 }
  852.  
  853.                 $tpl->put_all($vars_tpl);
  854.                
  855.                 $tpl->put('forum_top', $tpl_top->display());
  856.                 $tpl->display();
  857.                 $tpl->put('forum_bottom', $tpl_bottom->display());
  858.             }
  859.         }
  860.         //Sinon on édite simplement le message
  861.         elseif ($id_m > $id_first)
  862.         {
  863.             //User_id du message correspondant à l'utilisateur connecté => autorisation.
  864.             $user_id_msg = 0;
  865.             try {
  866.                 $user_id_msg = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'user_id', 'WHERE id = :id', array('id' => $id_m));
  867.             } catch (RowNotFoundException $e) {}
  868.            
  869.             $check_auth = false;
  870.             if ($user_id_msg == AppContext::get_current_user()->get_id())
  871.                 $check_auth = true;
  872.             elseif ($is_modo)
  873.                 $check_auth = true;
  874.  
  875.             if (!$check_auth) //Non autorisé!
  876.             {
  877.                 $error_controller = PHPBoostErrors::user_not_authorized();
  878.                 DispatchManager::redirect($error_controller);
  879.             }
  880.  
  881.             if ($update && retrieve(POST, 'edit_msg', false))
  882.             {
  883.                 $contents = retrieve(POST, 'contents', '', TSTRING_AS_RECEIVED);
  884.                 if (!empty($contents))
  885.                 {
  886.                     $nbr_msg_before = $Forumfct->Update_msg($idt_get, $id_m, addslashes($contents), $user_id_msg);
  887.  
  888.                     //Calcul de la page sur laquelle se situe le message.
  889.                     $msg_page = ceil( ($nbr_msg_before + 1) / $config->get_number_messages_per_page() );
  890.                     $msg_page_rewrite = ($msg_page > 1) ? '-' . $msg_page : '';
  891.                     $msg_page = ($msg_page > 1) ? '&pt=' . $msg_page : '';
  892.  
  893.                     //Redirection après édition.
  894.                     AppContext::get_response()->redirect('/forum/topic' . url('.php?id=' . $idt_get . $msg_page, '-' . $idt_get .  $msg_page_rewrite . '.php', '&') . '#m' . $id_m);
  895.                 }
  896.                 else
  897.                     AppContext::get_response()->redirect('/forum/post' . url('.php?new=msg&idm=' . $id_m . '&id=' . $id_get . '&idt=' . $idt_get . '&errore=incomplete', '', '&') . '#message_helper');
  898.             }
  899.             else
  900.             {
  901.                 $tpl = new FileTemplate('forum/forum_edit_msg.tpl');
  902.                
  903.                 $contents = '';
  904.                 try {
  905.                     $contents = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'contents', 'WHERE id = :id', array('id' => $id_m));
  906.                 } catch (RowNotFoundException $e) {}
  907.                
  908.                 //Gestion des erreurs à l'édition.
  909.                 $get_error_e = retrieve(GET, 'errore', '');
  910.                 if ($get_error_e == 'incomplete')
  911.                     $tpl->put('message_helper', MessageHelper::display($LANG['e_incomplete'], MessageHelper::NOTICE));
  912.  
  913.                 $vars_tpl = array(
  914.                     'P_UPDATE' => url('?update=1&amp;new=msg&amp;id=' . $id_get . '&amp;idt=' . $idt_get . '&amp;idm=' . $id_m),
  915.                     'FORUM_NAME' => $config->get_forum_name(),
  916.                     'DESC' => stripslashes($topic['subtitle']),
  917.                     'CONTENTS' => FormatingHelper::unparse($contents),
  918.                     'KERNEL_EDITOR' => $editor->display(),
  919.                     'U_ACTION' => 'post.php' . url('?update=1&amp;new=msg&amp;id=' . $id_get . '&amp;idt=' . $idt_get . '&amp;idm=' . $id_m . '&amp;token=' . AppContext::get_session()->get_token()),
  920.                     'U_FORUM_CAT' => '<a href="forum' . url('.php?id=' . $id_get, '-' . $id_get . '.php') . '">' . $category->get_name() . '</a>',
  921.                     'U_TITLE_T' => '<a href="topic' . url('.php?id=' . $idt_get, '-' . $idt_get . '.php') . '">' . stripslashes($topic['title']) . '</a>',
  922.                     'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  923.                     'L_REQUIRE_TEXT' => $LANG['require_text'],
  924.                     'L_FORUM_INDEX' => $LANG['forum_index'],
  925.                     'L_EDIT_MESSAGE' => $LANG['edit_message'],
  926.                     'L_MESSAGE' => $LANG['message'],
  927.                     'L_SUBMIT' => $LANG['update'],
  928.                     'L_PREVIEW' => $LANG['preview'],
  929.                     'L_RESET' => $LANG['reset'],
  930.                 );
  931.  
  932.                 $tpl->put_all($vars_tpl);
  933.                
  934.                 $tpl->put('forum_top', $tpl_top->display());
  935.                 $tpl->display();
  936.                 $tpl->put('forum_bottom', $tpl_bottom->display());
  937.             }
  938.         }
  939.     }
  940.     elseif (!empty($error_get) && (!empty($idt_get) || !empty($id_get)))
  941.     {
  942.         if (!empty($id_get) && !empty($idt_get) && ($error_get === 'flood' || $error_get === 'incomplete' || $error_get === 'locked'))
  943.         {
  944.             try {
  945.                 $topic = PersistenceContext::get_querier()->select_single_row(PREFIX . 'forum_topics', array('idcat', 'title', 'subtitle'), 'WHERE id=:id', array('id' => $idt_get));
  946.             } catch (RowNotFoundException $e) {
  947.                 $error_controller = PHPBoostErrors::unexisting_element();
  948.                 DispatchManager::redirect($error_controller);
  949.             }
  950.             if (empty($topic['idcat'])) //Topic inexistant.
  951.             {
  952.                 $controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'),
  953.                     $LANG['e_unexist_topic_forum']);
  954.                 DispatchManager::redirect($controller);
  955.             }
  956.  
  957.             $tpl = new FileTemplate('forum/forum_edit_msg.tpl');
  958.            
  959.  
  960.             //Gestion erreur.
  961.             switch ($error_get)
  962.             {
  963.                 case 'flood':
  964.                 $errstr = $LANG['e_flood'];
  965.                 $type = MessageHelper::WARNING;
  966.                 break;
  967.                 case 'incomplete':
  968.                 $errstr = $LANG['e_incomplete'];
  969.                 $type = MessageHelper::NOTICE;
  970.                 break;
  971.                 case 'locked':
  972.                 $errstr = $LANG['e_topic_lock_forum'];
  973.                 $type = MessageHelper::WARNING;
  974.                 break;
  975.                 default:
  976.                 $errstr = '';
  977.             }
  978.             if (!empty($errstr))
  979.                 $tpl->put('message_helper', MessageHelper::display($errstr, $type));
  980.  
  981.             $vars_tpl = array(
  982.                 'P_UPDATE' => '',
  983.                 'FORUM_NAME' => $config->get_forum_name(),
  984.                 'DESC' => stripslashes($topic['subtitle']),
  985.                 'KERNEL_EDITOR' => $editor->display(),
  986.                 'U_ACTION' => 'post.php' . url('?new=n_msg&amp;idt=' . $idt_get . '&amp;id=' . $id_get . '&amp;token=' . AppContext::get_session()->get_token()),
  987.                 'U_FORUM_CAT' => '<a href="forum' . url('.php?id=' . $id_get, '-' . $id_get . '.php') . '">' . $category->get_name() . '</a>',
  988.                 'U_TITLE_T' => '<a href="topic' . url('.php?id=' . $idt_get, '-' . $idt_get . '.php') . '">' . stripslashes($topic['title']) . '</a>',
  989.                 'L_ACTION' => $LANG['respond'],
  990.                 'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  991.                 'L_REQUIRE_TEXT' => $LANG['require_text'],
  992.                 'L_FORUM_INDEX' => $LANG['forum_index'],
  993.                 'L_EDIT_MESSAGE' => $LANG['respond'],
  994.                 'L_MESSAGE' => $LANG['message'],
  995.                 'L_SUBMIT' => $LANG['submit'],
  996.                 'L_PREVIEW' => $LANG['preview'],
  997.                 'L_RESET' => $LANG['reset']
  998.             );
  999.         }
  1000.         elseif (!empty($id_get) && ($error_get === 'c_locked' || $error_get === 'c_write' || $error_get === 'incomplete_t' || $error_get === 'false_t'))
  1001.         {
  1002.             $tpl = new FileTemplate('forum/forum_post.tpl');
  1003.            
  1004.  
  1005.             if (ForumAuthorizationsService::check_authorizations($id_get)->moderation())
  1006.             {
  1007.                 $tpl->put_all(array(
  1008.                     'C_FORUM_POST_TYPE' => true,
  1009.                     'CHECKED_NORMAL' => 'checked="ckecked"',
  1010.                     'L_TYPE' => '* ' . $LANG['type'],
  1011.                     'L_DEFAULT' => $LANG['default'],
  1012.                     'L_POST_IT' => $LANG['forum_postit'],
  1013.                     'L_ANOUNCE' => $LANG['forum_announce']
  1014.                 ));
  1015.             }
  1016.  
  1017.             //Gestion erreur.
  1018.             switch ($error_get)
  1019.             {
  1020.                 case 'flood_t':
  1021.                 $errstr = $LANG['e_flood'];
  1022.                 $type = MessageHelper::WARNING;
  1023.                 break;
  1024.                 case 'incomplete_t':
  1025.                 $errstr = $LANG['e_incomplete'];
  1026.                 $type = MessageHelper::NOTICE;
  1027.                 break;
  1028.                 case 'c_locked':
  1029.                 $errstr = $LANG['e_cat_lock_forum'];
  1030.                 $type = MessageHelper::WARNING;
  1031.                 break;
  1032.                 case 'c_write':
  1033.                 $errstr = $LANG['e_cat_write'];
  1034.                 $type = MessageHelper::WARNING;
  1035.                 break;
  1036.                 default:
  1037.                 $errstr = '';
  1038.             }
  1039.             if (!empty($errstr))
  1040.                 $tpl->put('message_helper', MessageHelper::display($errstr, $type));
  1041.  
  1042.             //Liste des choix des sondages => 20 maxi
  1043.             $nbr_poll_field = 0;
  1044.             for ($i = 0; $i < 5; $i++)
  1045.             {
  1046.                 $tpl->assign_block_vars('answers_poll', array(
  1047.                     'ID' => $i,
  1048.                     'ANSWER' => ''
  1049.                 ));
  1050.                 $nbr_poll_field++;
  1051.             }
  1052.  
  1053.             $vars_tpl = array(
  1054.                 'FORUM_NAME' => $config->get_forum_name(),
  1055.                 'TITLE' => '',
  1056.                 'SELECTED_SIMPLE' => 'checked="checked"',
  1057.                 'IDTOPIC' => 0,
  1058.                 'KERNEL_EDITOR' => $editor->display(),
  1059.                 'NO_DISPLAY_POLL' => 'true',
  1060.                 'NBR_POLL_FIELD' => $nbr_poll_field,
  1061.                 'C_ADD_POLL_FIELD' => true,
  1062.                 'U_ACTION' => 'post.php' . url('?new=topic&amp;id=' . $id_get . '&amp;token=' . AppContext::get_session()->get_token()),
  1063.                 'U_FORUM_CAT' => '<a href="forum' . url('.php?id=' . $id_get, '-' . $id_get . '.php') . '">' . $category->get_name() . '</a>',
  1064.                 'U_TITLE_T' => '<a href="post' . url('.php?new=topic&amp;id=' . $id_get) . '" class="basic-button">' . $LANG['post_new_subject'] . '</a>',
  1065.                 'L_ACTION' => $LANG['forum_new_subject'],
  1066.                 'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'),
  1067.                 'L_REQUIRE_TEXT' => $LANG['require_text'],
  1068.                 'L_REQUIRE_TITLE' => $LANG['require_title'],
  1069.                 'L_REQUIRE_TITLE_POLL' => $LANG['require_title_poll'],
  1070.                 'L_FORUM_INDEX' => $LANG['forum_index'],
  1071.                 'L_TITLE' => $LANG['title'],
  1072.                 'L_DESC' => $LANG['description'],
  1073.                 'L_MESSAGE' => $LANG['message'],
  1074.                 'L_SUBMIT' => $LANG['submit'],
  1075.                 'L_PREVIEW' => $LANG['preview'],
  1076.                 'L_RESET' => $LANG['reset'],
  1077.                 'L_POLL' => $LANG['poll'],
  1078.                 'L_OPEN_MENU_POLL' => $LANG['open_menu_poll'],
  1079.                 'L_QUESTION' => $LANG['question'],
  1080.                 'L_POLL_TYPE' => $LANG['poll_type'],
  1081.                 'L_ANSWERS' => $LANG['answers'],
  1082.                 'L_SINGLE' => $LANG['simple_answer'],
  1083.                 'L_MULTIPLE' => $LANG['multiple_answer']
  1084.             );
  1085.         }
  1086.         else
  1087.         {
  1088.             $controller = PHPBoostErrors::unknow();
  1089.             DispatchManager::redirect($controller);
  1090.         }
  1091.  
  1092.         $tpl->put_all($vars_tpl);
  1093.        
  1094.         $tpl->put('forum_top', $tpl_top->display());
  1095.         $tpl->display();
  1096.         $tpl->put('forum_bottom', $tpl_bottom->display());
  1097.     }
  1098.     else
  1099.     {
  1100.         $controller = PHPBoostErrors::unknow();
  1101.         DispatchManager::redirect($controller);
  1102.     }
  1103. }
  1104. else
  1105. {
  1106.     $error_controller = PHPBoostErrors::user_not_authorized();
  1107.     DispatchManager::redirect($error_controller);
  1108. }
  1109.  
  1110. include('../kernel/footer.php');
  1111.  
  1112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement