Kervinou

forum post.php

Jan 18th, 2016
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 37.17 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Copyright (C) 2008-2012 FluxBB
  5.  * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  6.  * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  7.  */
  8.  
  9. define('PUN_ROOT', dirname(__FILE__).'/');
  10. require PUN_ROOT.'include/common.php';
  11. require PUN_ROOT.'include/poll.php';
  12.  
  13.  
  14. if ($pun_user['g_read_board'] == '0')
  15.     message($lang_common['No view'], false, '403 Forbidden');
  16.  
  17.  
  18. $tid = isset($_GET['tid']) ? intval($_GET['tid']) : 0;
  19. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0;
  20. if ($tid < 1 && $fid < 1 || $tid > 0 && $fid > 0)
  21.     message($lang_common['Bad request'], false, '404 Not Found');
  22.  
  23. // Fetch some info about the topic and/or the forum
  24. if ($tid)
  25.     $result = $db->query('SELECT f.id, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.subject, t.closed, s.user_id AS is_subscribed FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') LEFT JOIN '.$db->prefix.'topic_subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$tid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  26. else
  27.     $result = $db->query('SELECT f.id, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  28.  
  29. if (!$db->num_rows($result))
  30.     message($lang_common['Bad request'], false, '404 Not Found');
  31.  
  32. $cur_posting = $db->fetch_assoc($result);
  33. $is_subscribed = $tid && $cur_posting['is_subscribed'];
  34.  
  35. // Is someone trying to post into a redirect forum?
  36. if ($cur_posting['redirect_url'] != '')
  37.     message($lang_common['Bad request'], false, '404 Not Found');
  38.  
  39. // Sort out who the moderators are and if we are currently a moderator (or an admin)
  40. $mods_array = ($cur_posting['moderators'] != '') ? unserialize($cur_posting['moderators']) : array();
  41. $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
  42.  
  43. if ($tid && $pun_config['o_censoring'] == '1')
  44.     $cur_posting['subject'] = censor_words($cur_posting['subject']);
  45.  
  46. // Do we have permission to post?
  47. if ((($tid && (($cur_posting['post_replies'] == '' && $pun_user['g_post_replies'] == '0') || $cur_posting['post_replies'] == '0')) ||
  48.     ($fid && (($cur_posting['post_topics'] == '' && $pun_user['g_post_topics'] == '0') || $cur_posting['post_topics'] == '0')) ||
  49.     (isset($cur_posting['closed']) && $cur_posting['closed'] == '1')) &&
  50.     !$is_admmod)
  51.     message($lang_common['No permission'], false, '403 Forbidden');
  52.  
  53. // [modif oto] - mod VSABR Very Simple AntiBot Registration - Add language file
  54. if(file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/mod_very_simple_antibot.php'))
  55.   require PUN_ROOT.'lang/'.$pun_user['language'].'/mod_very_simple_antibot.php';
  56. else
  57.   require PUN_ROOT.'lang/English/mod_very_simple_antibot.php';
  58. $mod_vsabr_index = rand(0,count($mod_vsabr_questions)-1);
  59. // [modif oto] - End mod VSABR
  60. // Load the post.php language file
  61. require PUN_ROOT.'lang/'.$pun_user['language'].'/post.php';
  62.  
  63. // Start with a clean slate
  64. $errors = array();
  65.  
  66.  
  67. // Did someone just hit "Submit" or "Preview"?
  68. if (isset($_POST['form_sent']))
  69. {
  70. //[modif oto] - mod VSABR Very Simple AntiBot Registration - Validate  answer to the question
  71. if($pun_user['is_guest']) {
  72.     $mod_vsabr_p_question = isset($_POST['captcha_q']) ? trim($_POST['captcha_q']) : '';
  73.     $mod_vsabr_p_answer = isset($_POST['captcha']) ? trim($_POST['captcha']) : '';
  74.     $mod_vsabr_questions_array = array();
  75.     foreach ($mod_vsabr_questions as $k => $v)
  76.     $mod_vsabr_questions_array[md5($k)] = $v;
  77.     if (empty($mod_vsabr_questions_array[$mod_vsabr_p_question]) || $mod_vsabr_questions_array[$mod_vsabr_p_question] != $mod_vsabr_p_answer)
  78.     $errors[] = $lang_mod_vsabr['Robot test fail'];
  79. }
  80. //[modif oto] - End mod VSABR
  81.     // Flood protection
  82.     if (!isset($_POST['preview']) && $pun_user['last_post'] != '' && (time() - $pun_user['last_post']) < $pun_user['g_post_flood'])
  83.         $errors[] = sprintf($lang_post['Flood start'], $pun_user['g_post_flood'], $pun_user['g_post_flood'] - (time() - $pun_user['last_post']));
  84.  
  85.     // If it's a new topic
  86.     if ($fid)
  87.     {
  88.         $subject = pun_trim($_POST['req_subject']);
  89.  
  90.         if ($pun_config['o_censoring'] == '1')
  91.             $censored_subject = pun_trim(censor_words($subject));
  92.  
  93.         if ($subject == '')
  94.             $errors[] = $lang_post['No subject'];
  95.         else if ($pun_config['o_censoring'] == '1' && $censored_subject == '')
  96.             $errors[] = $lang_post['No subject after censoring'];
  97.         else if (pun_strlen($subject) > 70)
  98.             $errors[] = $lang_post['Too long subject'];
  99.         else if ($pun_config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$pun_user['is_admmod'])
  100.             $errors[] = $lang_post['All caps subject'];
  101.     }
  102.  
  103.     // If the user is logged in we get the username and email from $pun_user
  104.     if (!$pun_user['is_guest'])
  105.     {
  106.         $username = $pun_user['username'];
  107.         $email = $pun_user['email'];
  108.     }
  109.     // Otherwise it should be in $_POST
  110.     else
  111.     {
  112.         $username = pun_trim($_POST['req_username']);
  113.         $email = strtolower(pun_trim(($pun_config['p_force_guest_email'] == '1') ? $_POST['req_email'] : $_POST['email']));
  114.         $banned_email = false;
  115.  
  116.         // Load the register.php/prof_reg.php language files
  117.         require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
  118.         require PUN_ROOT.'lang/'.$pun_user['language'].'/jeminscrit.php';
  119.  
  120.         // It's a guest, so we have to validate the username
  121.         check_username($username);
  122.  
  123.         if ($pun_config['p_force_guest_email'] == '1' || $email != '')
  124.         {
  125.             require PUN_ROOT.'include/email.php';
  126.             if (!is_valid_email($email))
  127.                 $errors[] = $lang_common['Invalid email'];
  128.  
  129.             // Check if it's a banned email address
  130.             // we should only check guests because members' addresses are already verified
  131.             if ($pun_user['is_guest'] && is_banned_email($email))
  132.             {
  133.                 if ($pun_config['p_allow_banned_email'] == '0')
  134.                     $errors[] = $lang_prof_reg['Banned email'];
  135.  
  136.                 $banned_email = true; // Used later when we send an alert email
  137.             }
  138.         }
  139.     }
  140.  
  141.     // Clean up message from POST
  142.     $orig_message = $message = pun_linebreaks(pun_trim($_POST['req_message']));
  143.  
  144.     // Here we use strlen() not pun_strlen() as we want to limit the post to PUN_MAX_POSTSIZE bytes, not characters
  145.     if (strlen($message) > PUN_MAX_POSTSIZE)
  146.         $errors[] = sprintf($lang_post['Too long message'], forum_number_format(PUN_MAX_POSTSIZE));
  147.     else if ($pun_config['p_message_all_caps'] == '0' && is_all_uppercase($message) && !$pun_user['is_admmod'])
  148.         $errors[] = $lang_post['All caps message'];
  149.  
  150.     // Validate BBCode syntax
  151.     if ($pun_config['p_message_bbcode'] == '1')
  152.     {
  153.         require PUN_ROOT.'include/parser.php';
  154.         $message = preparse_bbcode($message, $errors);
  155.     }
  156.  
  157.     if (empty($errors))
  158.     {
  159.         if ($message == '')
  160.             $errors[] = $lang_post['No message'];
  161.         else if ($pun_config['o_censoring'] == '1')
  162.         {
  163.             // Censor message to see if that causes problems
  164.             $censored_message = pun_trim(censor_words($message));
  165.  
  166.             if ($censored_message == '')
  167.                 $errors[] = $lang_post['No message after censoring'];
  168.         }
  169.     }
  170.  
  171.     $hide_smilies = isset($_POST['hide_smilies']) ? '1' : '0';
  172.     $subscribe = isset($_POST['subscribe']) ? '1' : '0';
  173.     $stick_topic = isset($_POST['stick_topic']) && $is_admmod ? '1' : '0';
  174.  
  175.     // Replace four-byte characters (MySQL cannot handle them)
  176.     $message = strip_bad_multibyte_chars($message);
  177.  
  178.     $now = time();
  179.  
  180.     poll_form_validate($tid, $errors);
  181.  
  182.     // Did everything go according to plan?
  183.     if (empty($errors) && !isset($_POST['preview']))
  184.     {
  185.         require PUN_ROOT.'include/search_idx.php';
  186.  
  187.         // If it's a reply
  188.         if ($tid)
  189.         {
  190.             if (!$pun_user['is_guest'])
  191.             {
  192.                 $new_tid = $tid;
  193.  
  194.                 // Insert the new post
  195.                 $db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.$db->escape(get_remote_address()).'\', \''.$db->escape($message).'\', '.$hide_smilies.', '.$now.', '.$tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
  196.                 $new_pid = $db->insert_id();
  197.  
  198.                 // To subscribe or not to subscribe, that ...
  199.                 if ($pun_config['o_topic_subscriptions'] == '1')
  200.                 {
  201.                     if ($subscribe && !$is_subscribed)
  202.                         $db->query('INSERT INTO '.$db->prefix.'topic_subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
  203.                     else if (!$subscribe && $is_subscribed)
  204.                         $db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$tid) or error('Unable to remove subscription', __FILE__, __LINE__, $db->error());
  205.                 }
  206.             }
  207.             else
  208.             {
  209.                 // It's a guest. Insert the new post
  210.                 $email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$db->escape($email).'\'' : 'NULL';
  211.                 $db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', \''.$db->escape(get_remote_address()).'\', '.$email_sql.', \''.$db->escape($message).'\', '.$hide_smilies.', '.$now.', '.$tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
  212.                 $new_pid = $db->insert_id();
  213.             }
  214.  
  215.             // Update topic
  216.             $db->query('UPDATE '.$db->prefix.'topics SET num_replies=num_replies+1, last_post='.$now.', last_post_id='.$new_pid.', last_poster=\''.$db->escape($username).'\' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  217.  
  218.             update_search_index('post', $new_pid, $message);
  219.  
  220.             update_forum($cur_posting['id']);
  221.  
  222.             // Should we send out notifications?
  223.             if ($pun_config['o_topic_subscriptions'] == '1')
  224.             {
  225.                 // Get the post time for the previous post in this topic
  226.                 $result = $db->query('SELECT posted FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1, 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  227.                 $previous_post_time = $db->result($result);
  228.  
  229.                 // Get any subscribed users that should be notified (banned users are excluded)
  230.                 $result = $db->query('SELECT u.id, u.email, u.notify_with_post, u.language FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'topic_subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id='.$cur_posting['id'].' AND fp.group_id=u.group_id) LEFT JOIN '.$db->prefix.'online AS o ON u.id=o.user_id LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND COALESCE(o.logged, u.last_visit)>'.$previous_post_time.' AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id='.$tid.' AND u.id!='.$pun_user['id']) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
  231.                 if ($db->num_rows($result))
  232.                 {
  233.                     require_once PUN_ROOT.'include/email.php';
  234.  
  235.                     $notification_emails = array();
  236.  
  237.                     if ($pun_config['o_censoring'] == '1')
  238.                         $cleaned_message = bbcode2email($censored_message, -1);
  239.                     else
  240.                         $cleaned_message = bbcode2email($message, -1);
  241.  
  242.                     // Loop through subscribed users and send emails
  243.                     while ($cur_subscriber = $db->fetch_assoc($result))
  244.                     {
  245.                         // Is the subscription email for $cur_subscriber['language'] cached or not?
  246.                         if (!isset($notification_emails[$cur_subscriber['language']]))
  247.                         {
  248.                             if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'))
  249.                             {
  250.                                 // Load the "new reply" template
  251.                                 $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'));
  252.  
  253.                                 // Load the "new reply full" template (with post included)
  254.                                 $mail_tpl_full = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply_full.tpl'));
  255.  
  256.                                 // The first row contains the subject (it also starts with "Subject:")
  257.                                 $first_crlf = strpos($mail_tpl, "\n");
  258.                                 $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
  259.                                 $mail_message = trim(substr($mail_tpl, $first_crlf));
  260.  
  261.                                 $first_crlf = strpos($mail_tpl_full, "\n");
  262.                                 $mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf-8));
  263.                                 $mail_message_full = trim(substr($mail_tpl_full, $first_crlf));
  264.  
  265.                                 $mail_subject = str_replace('<topic_subject>', $cur_posting['subject'], $mail_subject);
  266.                                 $mail_message = str_replace('<topic_subject>', $cur_posting['subject'], $mail_message);
  267.                                 $mail_message = str_replace('<replier>', $username, $mail_message);
  268.                                 $mail_message = str_replace('<post_url>', get_base_url().'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message);
  269.                                 $mail_message = str_replace('<unsubscribe_url>', get_base_url().'/misc.php?action=unsubscribe&tid='.$tid, $mail_message);
  270.                                 $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message);
  271.  
  272.                                 $mail_subject_full = str_replace('<topic_subject>', $cur_posting['subject'], $mail_subject_full);
  273.                                 $mail_message_full = str_replace('<topic_subject>', $cur_posting['subject'], $mail_message_full);
  274.                                 $mail_message_full = str_replace('<replier>', $username, $mail_message_full);
  275.                                 $mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full);
  276.                                 $mail_message_full = str_replace('<post_url>', get_base_url().'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message_full);
  277.                                 $mail_message_full = str_replace('<unsubscribe_url>', get_base_url().'/misc.php?action=unsubscribe&tid='.$tid, $mail_message_full);
  278.                                 $mail_message_full = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message_full);
  279.  
  280.                                 $notification_emails[$cur_subscriber['language']][0] = $mail_subject;
  281.                                 $notification_emails[$cur_subscriber['language']][1] = $mail_message;
  282.                                 $notification_emails[$cur_subscriber['language']][2] = $mail_subject_full;
  283.                                 $notification_emails[$cur_subscriber['language']][3] = $mail_message_full;
  284.  
  285.                                 $mail_subject = $mail_message = $mail_subject_full = $mail_message_full = null;
  286.                             }
  287.                         }
  288.  
  289.                         // We have to double check here because the templates could be missing
  290.                         if (isset($notification_emails[$cur_subscriber['language']]))
  291.                         {
  292.                             if ($cur_subscriber['notify_with_post'] == '0')
  293.                                 pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][0], $notification_emails[$cur_subscriber['language']][1]);
  294.                             else
  295.                                 pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][2], $notification_emails[$cur_subscriber['language']][3]);
  296.                         }
  297.                     }
  298.  
  299.                     unset($cleaned_message);
  300.                 }
  301.             }
  302.         }
  303.         // If it's a new topic
  304.         else if ($fid)
  305.         {
  306.             // Create the topic
  307.             $db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, last_poster, sticky, forum_id) VALUES(\''.$db->escape($username).'\', \''.$db->escape($subject).'\', '.$now.', '.$now.', \''.$db->escape($username).'\', '.$stick_topic.', '.$fid.')') or error('Unable to create topic', __FILE__, __LINE__, $db->error());
  308.             $new_tid = $db->insert_id();
  309.  
  310.             if (!$pun_user['is_guest'])
  311.             {
  312.                 // To subscribe or not to subscribe, that ...
  313.                 if ($pun_config['o_topic_subscriptions'] == '1' && $subscribe)
  314.                     $db->query('INSERT INTO '.$db->prefix.'topic_subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$new_tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
  315.  
  316.                 // Create the post ("topic post")
  317.                 $db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.$db->escape(get_remote_address()).'\', \''.$db->escape($message).'\', '.$hide_smilies.', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
  318.             }
  319.             else
  320.             {
  321.                 // Create the post ("topic post")
  322.                 $email_sql = ($pun_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$db->escape($email).'\'' : 'NULL';
  323.                 $db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_ip, poster_email, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', \''.$db->escape(get_remote_address()).'\', '.$email_sql.', \''.$db->escape($message).'\', '.$hide_smilies.', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
  324.             }
  325.             $new_pid = $db->insert_id();
  326.  
  327.             // Update the topic with last_post_id
  328.             $db->query('UPDATE '.$db->prefix.'topics SET last_post_id='.$new_pid.', first_post_id='.$new_pid.' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  329.  
  330.             update_search_index('post', $new_pid, $message, $subject);
  331.             update_forum($fid);
  332.             poll_save($new_tid);
  333.  
  334.            
  335.             // Should we send out notifications?
  336.             if ($pun_config['o_forum_subscriptions'] == '1')
  337.             {
  338.                 // Get any subscribed users that should be notified (banned users are excluded)
  339.                 $result = $db->query('SELECT u.id, u.email, u.notify_with_post, u.language FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'forum_subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id='.$cur_posting['id'].' AND fp.group_id=u.group_id) LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.forum_id='.$cur_posting['id'].' AND u.id!='.$pun_user['id']) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
  340.                 if ($db->num_rows($result))
  341.                 {
  342.                     require_once PUN_ROOT.'include/email.php';
  343.  
  344.                     $notification_emails = array();
  345.  
  346.                     if ($pun_config['o_censoring'] == '1')
  347.                         $cleaned_message = bbcode2email($censored_message, -1);
  348.                     else
  349.                         $cleaned_message = bbcode2email($message, -1);
  350.  
  351.                     // Loop through subscribed users and send emails
  352.                     while ($cur_subscriber = $db->fetch_assoc($result))
  353.                     {
  354.                         // Is the subscription email for $cur_subscriber['language'] cached or not?
  355.                         if (!isset($notification_emails[$cur_subscriber['language']]))
  356.                         {
  357.                             if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_topic.tpl'))
  358.                             {
  359.                                 // Load the "new topic" template
  360.                                 $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_topic.tpl'));
  361.  
  362.                                 // Load the "new topic full" template (with post included)
  363.                                 $mail_tpl_full = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_topic_full.tpl'));
  364.  
  365.                                 // The first row contains the subject (it also starts with "Subject:")
  366.                                 $first_crlf = strpos($mail_tpl, "\n");
  367.                                 $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
  368.                                 $mail_message = trim(substr($mail_tpl, $first_crlf));
  369.  
  370.                                 $first_crlf = strpos($mail_tpl_full, "\n");
  371.                                 $mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf-8));
  372.                                 $mail_message_full = trim(substr($mail_tpl_full, $first_crlf));
  373.  
  374.                                 $mail_subject = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject);
  375.                                 $mail_message = str_replace('<topic_subject>', $pun_config['o_censoring'] == '1' ? $censored_subject : $subject, $mail_message);
  376.                                 $mail_message = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message);
  377.                                 $mail_message = str_replace('<poster>', $username, $mail_message);
  378.                                 $mail_message = str_replace('<topic_url>', get_base_url().'/viewtopic.php?id='.$new_tid, $mail_message);
  379.                                 $mail_message = str_replace('<unsubscribe_url>', get_base_url().'/misc.php?action=unsubscribe&fid='.$cur_posting['id'], $mail_message);
  380.                                 $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message);
  381.  
  382.                                 $mail_subject_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject_full);
  383.                                 $mail_message_full = str_replace('<topic_subject>', $pun_config['o_censoring'] == '1' ? $censored_subject : $subject, $mail_message_full);
  384.                                 $mail_message_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message_full);
  385.                                 $mail_message_full = str_replace('<poster>', $username, $mail_message_full);
  386.                                 $mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full);
  387.                                 $mail_message_full = str_replace('<topic_url>', get_base_url().'/viewtopic.php?id='.$new_tid, $mail_message_full);
  388.                                 $mail_message_full = str_replace('<unsubscribe_url>', get_base_url().'/misc.php?action=unsubscribe&fid='.$cur_posting['id'], $mail_message_full);
  389.                                 $mail_message_full = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message_full);
  390.  
  391.                                 $notification_emails[$cur_subscriber['language']][0] = $mail_subject;
  392.                                 $notification_emails[$cur_subscriber['language']][1] = $mail_message;
  393.                                 $notification_emails[$cur_subscriber['language']][2] = $mail_subject_full;
  394.                                 $notification_emails[$cur_subscriber['language']][3] = $mail_message_full;
  395.  
  396.                                 $mail_subject = $mail_message = $mail_subject_full = $mail_message_full = null;
  397.                             }
  398.                         }
  399.  
  400.                         // We have to double check here because the templates could be missing
  401.                         if (isset($notification_emails[$cur_subscriber['language']]))
  402.                         {
  403.                             if ($cur_subscriber['notify_with_post'] == '0')
  404.                                 pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][0], $notification_emails[$cur_subscriber['language']][1]);
  405.                             else
  406.                                 pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][2], $notification_emails[$cur_subscriber['language']][3]);
  407.                         }
  408.                     }
  409.  
  410.                     unset($cleaned_message);
  411.                 }
  412.             }
  413.         }
  414.  
  415.         // If we previously found out that the email was banned
  416.         if ($pun_user['is_guest'] && $banned_email && $pun_config['o_mailing_list'] != '')
  417.         {
  418.             // Load the "banned email post" template
  419.             $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/banned_email_post.tpl'));
  420.  
  421.             // The first row contains the subject
  422.             $first_crlf = strpos($mail_tpl, "\n");
  423.             $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
  424.             $mail_message = trim(substr($mail_tpl, $first_crlf));
  425.  
  426.             $mail_message = str_replace('<username>', $username, $mail_message);
  427.             $mail_message = str_replace('<email>', $email, $mail_message);
  428.             $mail_message = str_replace('<post_url>', get_base_url().'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message);
  429.             $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message);
  430.  
  431.             pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
  432.         }
  433.  
  434.         // If the posting user is logged in, increment his/her post count
  435.         if (!$pun_user['is_guest'])
  436.         {
  437.             $db->query('UPDATE '.$db->prefix.'users SET num_posts=num_posts+1, last_post='.$now.' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
  438.  
  439.             // Promote this user to a new group if enabled
  440.             if ($pun_user['g_promote_next_group'] != 0 && $pun_user['num_posts'] + 1 >= $pun_user['g_promote_min_posts'])
  441.             {
  442.                 $new_group_id = $pun_user['g_promote_next_group'];
  443.                 $db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$pun_user['id']) or error('Unable to promote user to new group', __FILE__, __LINE__, $db->error());
  444.             }
  445.  
  446.             // Topic tracking stuff...
  447.             $tracked_topics = get_tracked_topics();
  448.             $tracked_topics['topics'][$new_tid] = time();
  449.             set_tracked_topics($tracked_topics);
  450.         }
  451.         else
  452.         {
  453.             $db->query('UPDATE '.$db->prefix.'online SET last_post='.$now.' WHERE ident=\''.$db->escape(get_remote_address()).'\'' ) or error('Unable to update user', __FILE__, __LINE__, $db->error());
  454.         }
  455.  
  456.         redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect']);
  457.     }
  458. }
  459.  
  460.  
  461. // If a topic ID was specified in the url (it's a reply)
  462. if ($tid)
  463. {
  464.     $action = $lang_post['Post a reply'];
  465.     $form = '<form id="post" method="post" action="post.php?action=post&amp;tid='.$tid.'" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';
  466.  
  467.     // If a quote ID was specified in the url
  468.     if (isset($_GET['qid']))
  469.     {
  470.         $qid = intval($_GET['qid']);
  471.         if ($qid < 1)
  472.             message($lang_common['Bad request'], false, '404 Not Found');
  473.  
  474.         $result = $db->query('SELECT poster, message FROM '.$db->prefix.'posts WHERE id='.$qid.' AND topic_id='.$tid) or error('Unable to fetch quote info', __FILE__, __LINE__, $db->error());
  475.         if (!$db->num_rows($result))
  476.             message($lang_common['Bad request'], false, '404 Not Found');
  477.  
  478.         list($q_poster, $q_message) = $db->fetch_row($result);
  479.  
  480.         // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
  481.         if (strpos($q_message, '[code]') !== false && strpos($q_message, '[/code]') !== false)
  482.         {
  483.             list($inside, $outside) = split_text($q_message, '[code]', '[/code]');
  484.  
  485.             $q_message = implode("\1", $outside);
  486.         }
  487.  
  488.         // Remove [img] tags from quoted message
  489.         $q_message = preg_replace('%\[img(?:=(?:[^\[]*?))?\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%U', '\1\3', $q_message);
  490.  
  491.         // If we split up the message before we have to concatenate it together again (code tags)
  492.         if (isset($inside))
  493.         {
  494.             $outside = explode("\1", $q_message);
  495.             $q_message = '';
  496.  
  497.             $num_tokens = count($outside);
  498.             for ($i = 0; $i < $num_tokens; ++$i)
  499.             {
  500.                 $q_message .= $outside[$i];
  501.                 if (isset($inside[$i]))
  502.                     $q_message .= '[code]'.$inside[$i].'[/code]';
  503.             }
  504.  
  505.             unset($inside);
  506.         }
  507.  
  508.         if ($pun_config['o_censoring'] == '1')
  509.             $q_message = censor_words($q_message);
  510.  
  511.         $q_message = pun_htmlspecialchars($q_message);
  512.  
  513.         if ($pun_config['p_message_bbcode'] == '1')
  514.         {
  515.             // If username contains a square bracket, we add "" or '' around it (so we know when it starts and ends)
  516.             if (strpos($q_poster, '[') !== false || strpos($q_poster, ']') !== false)
  517.             {
  518.                 if (strpos($q_poster, '\'') !== false)
  519.                     $q_poster = '"'.$q_poster.'"';
  520.                 else
  521.                     $q_poster = '\''.$q_poster.'\'';
  522.             }
  523.             else
  524.             {
  525.                 // Get the characters at the start and end of $q_poster
  526.                 $ends = substr($q_poster, 0, 1).substr($q_poster, -1, 1);
  527.  
  528.                 // Deal with quoting "Username" or 'Username' (becomes '"Username"' or "'Username'")
  529.                 if ($ends == '\'\'')
  530.                     $q_poster = '"'.$q_poster.'"';
  531.                 else if ($ends == '""')
  532.                     $q_poster = '\''.$q_poster.'\'';
  533.             }
  534.  
  535.             $quote = '[quote='.$q_poster.']'.$q_message.'[/quote]'."\n";
  536.         }
  537.         else
  538.             $quote = '> '.$q_poster.' '.$lang_common['wrote']."\n\n".'> '.$q_message."\n";
  539.     }
  540. }
  541. // If a forum ID was specified in the url (new topic)
  542. else if ($fid)
  543. {
  544.     $action = $lang_post['Post new topic'];
  545.     $form = '<form id="post" method="post" action="post.php?action=post&amp;fid='.$fid.'" onsubmit="return process_form(this)">';
  546. }
  547. else
  548.     message($lang_common['Bad request'], false, '404 Not Found');
  549.  
  550.  
  551. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $action);
  552. $required_fields = array('req_email' => $lang_common['Email'], 'req_subject' => $lang_common['Subject'], 'req_message' => $lang_common['Message']);
  553. $focus_element = array('post');
  554.  
  555. if (!$pun_user['is_guest'])
  556.     $focus_element[] = ($fid) ? 'req_subject' : 'req_message';
  557. else
  558. {
  559.     $required_fields['req_username'] = $lang_post['Guest name'];
  560.     //[modif oto] - mod VSABR Very Simple AntiBot Registration - Line added
  561.     $required_fields['captcha'] = $lang_mod_vsabr['Robot title'];
  562.     $focus_element[] = 'req_username';
  563. }
  564.  
  565. define('PUN_ACTIVE_PAGE', 'index');
  566. require PUN_ROOT.'header.php';
  567.  
  568. ?>
  569. <div class="linkst">
  570.     <div class="inbox">
  571.         <ul class="crumbs">
  572.             <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  573.             <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $cur_posting['id'] ?>"><?php echo pun_htmlspecialchars($cur_posting['forum_name']) ?></a></li>
  574. <?php if (isset($cur_posting['subject'])): ?>           <li><span>»&#160;</span><a href="viewtopic.php?id=<?php echo $tid ?>"><?php echo pun_htmlspecialchars($cur_posting['subject']) ?></a></li>
  575. <?php endif; ?>         <li><span>»&#160;</span><strong><?php echo $action ?></strong></li>
  576.         </ul>
  577.     </div>
  578. </div>
  579.  
  580. <?php
  581.  
  582. // If there are errors, we display them
  583. if (!empty($errors))
  584. {
  585.  
  586. ?>
  587. <div id="posterror" class="block">
  588.     <h2><span><?php echo $lang_post['Post errors'] ?></span></h2>
  589.     <div class="box">
  590.         <div class="inbox error-info">
  591.             <p><?php echo $lang_post['Post errors info'] ?></p>
  592.             <ul class="error-list">
  593. <?php
  594.  
  595.     foreach ($errors as $cur_error)
  596.         echo "\t\t\t\t".'<li><strong>'.$cur_error.'</strong></li>'."\n";
  597. ?>
  598.             </ul>
  599.         </div>
  600.     </div>
  601. </div>
  602.  
  603. <?php
  604.  
  605. }
  606. else if (isset($_POST['preview']))
  607. {
  608.     require_once PUN_ROOT.'include/parser.php';
  609.     $preview_message = parse_message($message, $hide_smilies);
  610.  
  611. ?>
  612. <div id="postpreview" class="blockpost">
  613.     <h2><span><?php echo $lang_post['Post preview'] ?></span></h2>
  614.     <div class="box">
  615.         <div class="inbox">
  616.             <div class="postbody">
  617.                 <div class="postright">
  618.                     <div class="postmsg">
  619.                         <?php echo $preview_message."\n" ?>
  620. <?php if ($fid) poll_display_post($tid, $pun_user['id']); ?>
  621.                     </div>
  622.                 </div>
  623.             </div>
  624.         </div>
  625.     </div>
  626. </div>
  627.  
  628. <?php
  629.  
  630. }
  631.  
  632.  
  633. $cur_index = 1;
  634.  
  635. ?>
  636. <div id="postform" class="blockform">
  637.     <h2><span><?php echo $action ?></span></h2>
  638.     <div class="box">
  639.         <?php echo $form."\n" ?>
  640.             <div class="inform">
  641.                 <fieldset>
  642.                     <legend><?php echo $lang_common['Write message legend'] ?></legend>
  643.                     <div class="infldset txtarea">
  644.                         <input type="hidden" name="form_sent" value="1" />
  645. <?php
  646.  
  647. if ($pun_user['is_guest'])
  648. {
  649.     $email_label = ($pun_config['p_force_guest_email'] == '1') ? '<strong>'.$lang_common['Email'].' <span>'.$lang_common['Required'].'</span></strong>' : $lang_common['Email'];
  650.     $email_form_name = ($pun_config['p_force_guest_email'] == '1') ? 'req_email' : 'email';
  651.  
  652. ?>
  653.                         <label class="conl required"><strong><?php echo $lang_post['Guest name'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input type="text" name="req_username" value="<?php if (isset($_POST['req_username'])) echo pun_htmlspecialchars($username); ?>" size="25" maxlength="25" tabindex="<?php echo $cur_index++ ?>" /><br /></label>
  654.                         <label class="conl<?php echo ($pun_config['p_force_guest_email'] == '1') ? ' required' : '' ?>"><?php echo $email_label ?><br /><input type="text" name="<?php echo $email_form_name ?>" value="<?php if (isset($_POST[$email_form_name])) echo pun_htmlspecialchars($email); ?>" size="50" maxlength="80" tabindex="<?php echo $cur_index++ ?>" /><br /></label>
  655.                         <div class="clearer"></div>
  656. <?php
  657.  
  658. }
  659.  
  660. if ($fid): ?>
  661.                         <label class="required"><strong><?php echo $lang_common['Subject'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input class="longinput" type="text" name="req_subject" value="<?php if (isset($_POST['req_subject'])) echo pun_htmlspecialchars($subject); ?>" size="80" maxlength="70" tabindex="<?php echo $cur_index++ ?>" /><br /></label>
  662. <?php endif; ?>                     <label class="required"><strong><?php echo $lang_common['Message'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br />
  663.                         <textarea name="req_message" rows="20" cols="95" tabindex="<?php echo $cur_index++ ?>"><?php echo isset($_POST['req_message']) ? pun_htmlspecialchars($orig_message) : (isset($quote) ? $quote : ''); ?></textarea><br />
  664.                        
  665.                        
  666.                         <iframe src="http://www.hostingpics.net/iframe_mini.php?module=1864&iduni=5614ed440a657e4cdbfe8a5459810996" width="400" height="100" scrolling="no" frameborder="0" allowtransparency="true"></iframe>
  667.                        
  668.                         </label>
  669.                         <ul class="bblinks">
  670.                             <li><span><a href="help.php#bbcode" onclick="window.open(this.href); return false;"><?php echo $lang_common['BBCode'] ?></a> <?php echo ($pun_config['p_message_bbcode'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
  671.                             <li><span><a href="help.php#url" onclick="window.open(this.href); return false;"><?php echo $lang_common['url tag'] ?></a> <?php echo ($pun_config['p_message_bbcode'] == '1' && $pun_user['g_post_links'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
  672.                             <li><span><a href="help.php#img" onclick="window.open(this.href); return false;"><?php echo $lang_common['img tag'] ?></a> <?php echo ($pun_config['p_message_bbcode'] == '1' && $pun_config['p_message_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
  673.                             <li><span><a href="help.php#smilies" onclick="window.open(this.href); return false;"><?php echo $lang_common['Smilies'] ?></a> <?php echo ($pun_config['o_smilies'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
  674.                         </ul>
  675.                     </div>
  676.                 </fieldset>
  677. <?php
  678.  
  679. $checkboxes = array();
  680. if ($fid && $is_admmod)
  681.     $checkboxes[] = '<label><input type="checkbox" name="stick_topic" value="1" tabindex="'.($cur_index++).'"'.(isset($_POST['stick_topic']) ? ' checked="checked"' : '').' />'.$lang_common['Stick topic'].'<br /></label>';
  682.  
  683. if (!$pun_user['is_guest'])
  684. {
  685.  
  686.     if ($pun_config['o_topic_subscriptions'] == '1')
  687.     {
  688.         $subscr_checked = false;
  689.  
  690.         // If it's a preview
  691.         if (isset($_POST['preview']))
  692.             $subscr_checked = isset($_POST['subscribe']) ? true : false;
  693.         // If auto subscribed
  694.         else if ($pun_user['auto_notify'])
  695.             $subscr_checked = true;
  696.         // If already subscribed to the topic
  697.         else if ($is_subscribed)
  698.             $subscr_checked = true;
  699.  
  700.         $checkboxes[] = '<label><input type="checkbox" name="subscribe" value="1" tabindex="'.($cur_index++).'"'.($subscr_checked ? ' checked="checked"' : '').' />'.($is_subscribed ? $lang_post['Stay subscribed'] : $lang_post['Subscribe']).'<br /></label>';
  701.     }
  702. }
  703.  
  704. if (!empty($checkboxes))
  705. {
  706.  
  707. ?>
  708.             </div>
  709.             <div class="inform">
  710.                 <fieldset>
  711.                     <legend><?php echo $lang_common['Options'] ?></legend>
  712.                     <div class="infldset">
  713.                         <div class="rbox">
  714.                             <?php echo implode("\n\t\t\t\t\t\t\t", $checkboxes)."\n" ?>
  715.                         </div>
  716.                     </div>
  717.                 </fieldset>
  718. <?php
  719.  
  720. }
  721.  
  722. ?>
  723.             </div>
  724.             <?php //[modif oto] - mod VSABR Very Simple AntiBot Registration
  725. if($pun_user['is_guest']) : ?>
  726. <div class="inform">
  727.     <fieldset>
  728.         <legend><?php   echo $lang_mod_vsabr['Robot title'] ?></legend>
  729.         <div class="infldset">
  730.             <p><?php echo   $lang_mod_vsabr['Robot info']   ?></p>
  731.             <label class="required"><strong><?php
  732.                  $question = array_keys($mod_vsabr_questions);
  733.                  $qencoded = md5($question[$mod_vsabr_index]);
  734.                  echo   sprintf($lang_mod_vsabr['Robot question'],$question[$mod_vsabr_index]);?>
  735.                  <span><?php echo   $lang_common['Required'] ?></span></strong>
  736.                  <input name="captcha" id="captcha" type="text" size="10"   maxlength="30" /><input name="captcha_q"    value="<?php echo   $qencoded   ?>" type="hidden"   /><br   />
  737.             </label>
  738.         </div>
  739.     </fieldset>
  740. </div>
  741. <?php endif; //[modif oto] - End mod VSABR ?>
  742. <?php poll_form_post($tid); ?>
  743. <p class="buttons"><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" onclick="this.form.submit();this.disabled=true;this.value='En cours'" tabindex="<?php echo $cur_index++ ?>" accesskey="s" /> <input type="submit" name="preview" value="<?php echo $lang_post['Preview'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="p" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  744.         </form>
  745.     </div>
  746. </div>
  747.  
  748. <?php
  749.  
  750. // Check to see if the topic review is to be displayed
  751. if ($tid && $pun_config['o_topic_review'] != '0')
  752. {
  753.     require_once PUN_ROOT.'include/parser.php';
  754.  
  755.     $result = $db->query('SELECT p.poster, p.message, p.hide_smilies, p.posted, u.group_id FROM '.$db->prefix.'posts AS p LEFT JOIN '.$db->prefix.'users AS u ON (p.poster=u.username) WHERE p.topic_id='.$tid.' ORDER BY p.id DESC LIMIT '.$pun_config['o_topic_review']) or error('Unable to fetch topic review', __FILE__, __LINE__, $db->error());
  756.  
  757. ?>
  758.  
  759. <div id="postreview">
  760.     <h2><span><?php echo $lang_post['Topic review'] ?></span></h2>
  761. <?php
  762.  
  763.     // Set background switching on
  764.     $post_count = 0;
  765.  
  766.     while ($cur_post = $db->fetch_assoc($result))
  767.     {
  768.         $post_count++;
  769.  
  770.         $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  771.  
  772. ?>
  773.     <div class="blockpost">
  774.         <div class="box<?php echo ($post_count % 2 == 0) ? ' roweven' : ' rowodd' ?>">
  775.             <div class="inbox">
  776.                 <div class="postbody">
  777.                     <div class="postleft">
  778.                         <dl>
  779.                             <dt><strong><?php echo colorize_group($cur_post['poster'], $cur_post['group_id']) ?></strong></dt>
  780.                             <dd><span><?php echo format_time($cur_post['posted']) ?></span></dd>
  781.                         </dl>
  782.                     </div>
  783.                     <div class="postright">
  784.                         <div class="postmsg">
  785.                             <?php echo $cur_post['message']."\n" ?>
  786.                         </div>
  787.                     </div>
  788.                 </div>
  789.                 <div class="clearer"></div>
  790.             </div>
  791.         </div>
  792.     </div>
  793. <?php
  794.  
  795.     }
  796.  
  797. ?>
  798. </div>
  799. <?php
  800.  
  801. }
  802.  
  803. require PUN_ROOT.'footer.php';
Advertisement
Add Comment
Please, Sign In to add comment