punbb/edit.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
equal deleted inserted replaced
1:8f6143115bf5 2:a8a21e1c7afa
    21   MA  02111-1307  USA
    21   MA  02111-1307  USA
    22 
    22 
    23 ************************************************************************/
    23 ************************************************************************/
    24 
    24 
    25 
    25 
    26 define('PUN_ROOT', './');
    26 //define('PUN_ROOT', './');
    27 require PUN_ROOT.'include/common.php';
    27 //require PUN_ROOT.'include/common.php';
       
    28 
       
    29 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    30 
    28 
    31 
    29 
    32 
    30 if ($pun_user['g_read_board'] == '0')
    33 if ($pun_user['g_read_board'] == '0')
    31 	message($lang_common['No view']);
    34 	message($lang_common['No view']);
    32 
    35 
    34 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
    37 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
    35 if ($id < 1)
    38 if ($id < 1)
    36 	message($lang_common['Bad request']);
    39 	message($lang_common['Bad request']);
    37 
    40 
    38 // Fetch some info about the post, the topic and the forum
    41 // Fetch some info about the post, the topic and the forum
    39 $result = $db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.posted, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id 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'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    42 $result = $pun_db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.posted, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies FROM '.$pun_db->prefix.'posts AS p INNER JOIN '.$pun_db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$pun_db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$pun_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 p.id='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
    40 if (!$db->num_rows($result))
    43 if (!$pun_db->num_rows($result))
    41 	message($lang_common['Bad request']);
    44 	message($lang_common['Bad request']);
    42 
    45 
    43 $cur_post = $db->fetch_assoc($result);
    46 $cur_post = $pun_db->fetch_assoc($result);
    44 
    47 
    45 // Sort out who the moderators are and if we are currently a moderator (or an admin)
    48 // Sort out who the moderators are and if we are currently a moderator (or an admin)
    46 $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
    49 $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
    47 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
    50 $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
    48 
    51 
    49 // Determine whether this post is the "topic post" or not
    52 // Determine whether this post is the "topic post" or not
    50 $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['tid'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    53 $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id='.$cur_post['tid'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
    51 $topic_post_id = $db->result($result);
    54 $topic_post_id = $pun_db->result($result);
    52 
    55 
    53 $can_edit_subject = ($id == $topic_post_id && (($pun_user['g_edit_subjects_interval'] == '0' || (time() - $cur_post['posted']) < $pun_user['g_edit_subjects_interval']) || $is_admmod)) ? true : false;
    56 $can_edit_subject = ($id == $topic_post_id && (($pun_user['g_edit_subjects_interval'] == '0' || (time() - $cur_post['posted']) < $pun_user['g_edit_subjects_interval']) || $is_admmod)) ? true : false;
    54 
    57 
    55 // Do we have permission to edit this post?
    58 // Do we have permission to edit this post?
    56 if (($pun_user['g_edit_posts'] == '0' ||
    59 if (($pun_user['g_edit_posts'] == '0' ||
    78 
    81 
    79 		if ($subject == '')
    82 		if ($subject == '')
    80 			$errors[] = $lang_post['No subject'];
    83 			$errors[] = $lang_post['No subject'];
    81 		else if (pun_strlen($subject) > 70)
    84 		else if (pun_strlen($subject) > 70)
    82 			$errors[] = $lang_post['Too long subject'];
    85 			$errors[] = $lang_post['Too long subject'];
    83 		else if ($pun_config['p_subject_all_caps'] == '0' && strtoupper($subject) == $subject && $pun_user['g_id'] > PUN_MOD)
    86 		else if ($pun_config['p_subject_all_caps'] == '0' && strtoupper($subject) == $subject && $pun_user['g_id'] < PUN_MOD)
    84 			$subject = ucwords(strtolower($subject));
    87 			$subject = ucwords(strtolower($subject));
    85 	}
    88 	}
    86 
    89 
    87 	// Clean up message from POST
    90 	// Clean up message from POST
    88 	$message = pun_linebreaks(pun_trim($_POST['req_message']));
    91 	$message = pun_linebreaks(pun_trim($_POST['req_message']));
    89 
    92 
    90 	if ($message == '')
    93 	if ($message == '')
    91 		$errors[] = $lang_post['No message'];
    94 		$errors[] = $lang_post['No message'];
    92 	else if (strlen($message) > 65535)
    95 	else if (strlen($message) > 65535)
    93 		$errors[] = $lang_post['Too long message'];
    96 		$errors[] = $lang_post['Too long message'];
    94 	else if ($pun_config['p_message_all_caps'] == '0' && strtoupper($message) == $message && $pun_user['g_id'] > PUN_MOD)
    97 	else if ($pun_config['p_message_all_caps'] == '0' && strtoupper($message) == $message && $pun_user['g_id'] < PUN_MOD)
    95 		$message = ucwords(strtolower($message));
    98 		$message = ucwords(strtolower($message));
    96 
    99 
    97 	// Validate BBCode syntax
   100 	// Validate BBCode syntax
    98 	if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)
   101 	if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)
    99 	{
   102 	{
   106 	if ($hide_smilies != '1') $hide_smilies = '0';
   109 	if ($hide_smilies != '1') $hide_smilies = '0';
   107 
   110 
   108 	// Did everything go according to plan?
   111 	// Did everything go according to plan?
   109 	if (empty($errors) && !isset($_POST['preview']))
   112 	if (empty($errors) && !isset($_POST['preview']))
   110 	{
   113 	{
   111 		$edited_sql = (!isset($_POST['silent']) || !$is_admmod) ? $edited_sql = ', edited='.time().', edited_by=\''.$db->escape($pun_user['username']).'\'' : '';
   114 		$edited_sql = (!isset($_POST['silent']) || !$is_admmod) ? $edited_sql = ', edited='.time().', edited_by=\''.$pun_db->escape($pun_user['username']).'\'' : '';
   112 
   115 
   113 		require PUN_ROOT.'include/search_idx.php';
   116 		require PUN_ROOT.'include/search_idx.php';
   114 
   117 
   115 		if ($can_edit_subject)
   118 		if ($can_edit_subject)
   116 		{
   119 		{
   117 			// Update the topic and any redirect topics
   120 			// Update the topic and any redirect topics
   118 			$db->query('UPDATE '.$db->prefix.'topics SET subject=\''.$db->escape($subject).'\' WHERE id='.$cur_post['tid'].' OR moved_to='.$cur_post['tid']) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
   121 			$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET subject=\''.$pun_db->escape($subject).'\' WHERE id='.$cur_post['tid'].' OR moved_to='.$cur_post['tid']) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
   119 
   122 
   120 			// We changed the subject, so we need to take that into account when we update the search words
   123 			// We changed the subject, so we need to take that into account when we update the search words
   121 			update_search_index('edit', $id, $message, $subject);
   124 			update_search_index('edit', $id, $message, $subject);
   122 		}
   125 		}
   123 		else
   126 		else
   124 			update_search_index('edit', $id, $message);
   127 			update_search_index('edit', $id, $message);
   125 
   128 
   126 		// Update the post
   129 		// Update the post
   127 		$db->query('UPDATE '.$db->prefix.'posts SET message=\''.$db->escape($message).'\', hide_smilies=\''.$hide_smilies.'\''.$edited_sql.' WHERE id='.$id) or error('Unable to update post', __FILE__, __LINE__, $db->error());
   130 		$pun_db->query('UPDATE '.$pun_db->prefix.'posts SET message=\''.$pun_db->escape($message).'\', hide_smilies=\''.$hide_smilies.'\''.$edited_sql.' WHERE id='.$id) or error('Unable to update post', __FILE__, __LINE__, $pun_db->error());
   128 
   131 
   129 		redirect('viewtopic.php?pid='.$id.'#p'.$id, $lang_post['Edit redirect']);
   132 		pun_redirect('viewtopic.php?pid='.$id.'#p'.$id, $lang_post['Edit redirect']);
   130 	}
   133 	}
   131 }
   134 }
   132 
   135 
   133 
   136 
   134 
   137