From 87d254582ceeb09190e789fae115bde3913fa7ad Mon Sep 17 00:00:00 2001
From: mcfly <mcfly@e107.org>
Date: Thu, 11 Dec 2008 21:50:18 +0000
Subject: [PATCH] edit and quote progress

---
 e107_plugins/forum/forum_class.php            | 45 ++++++----
 e107_plugins/forum/forum_post.php             | 84 +++++++++----------
 e107_plugins/forum/forum_post_shortcodes.php  |  5 +-
 e107_plugins/forum/forum_shortcodes.php       | 13 +++
 e107_plugins/forum/forum_sql.php              |  1 +
 e107_plugins/forum/forum_viewtopic.php        | 12 +--
 .../templates/forum_viewtopic_template.php    | 49 ++++++++++-
 7 files changed, 141 insertions(+), 68 deletions(-)

diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php
index 2fd47f945..c14d15c60 100644
--- a/e107_plugins/forum/forum_class.php
+++ b/e107_plugins/forum/forum_class.php
@@ -11,8 +11,8 @@
 |     GNU General Public License (http://gnu.org).
 |
 |     $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
-|     $Revision: 1.23 $
-|     $Date: 2008-12-11 16:02:05 $
+|     $Revision: 1.24 $
+|     $Date: 2008-12-11 21:50:18 $
 |     $Author: mcfly_e107 $
 +----------------------------------------------------------------------------+
 */
@@ -293,23 +293,35 @@ class e107forum
 		return false;
 	}
 
-	function postGet($threadId, $start, $num)
+	function postGet($id, $start, $num)
 	{
+		$id = (int)$id;
 		$ret = false;
 		$e107 = e107::getInstance();
-		$qry = '
-		SELECT p.*,
-		u.user_name, u.user_customtitle, u.user_hideemail, u.user_email, u.user_signature,
-		u.user_admin, u.user_image, u.user_join, ue.user_plugin_forum_posts,
-		eu.user_name AS edit_name
-		FROM `#forum_post` AS p
-		LEFT JOIN `#user` AS u ON p.post_user = u.user_id
-		LEFT JOIN `#user` AS eu ON p.post_edit_user IS NOT NULL AND p.post_edit_user = eu.user_id
-		LEFT JOIN `#user_extended` AS ue ON ue.user_extended_id = p.post_user
-		WHERE p.post_thread = '.$threadId."
-		ORDER BY p.post_datestamp ASC
-		LIMIT {$start}, {$num}
-		";
+		if('post' === $start)
+		{
+			$qry = '
+			SELECT u.user_name, t.thread_active, t.thread_datestamp, t.thread_name, p.* FROM `#forum_post` AS p
+			LEFT JOIN `#forum_thread` AS t ON t.thread_id = p.post_thread
+			LEFT JOIN `#user` AS u ON u.user_id = p.post_user
+			WHERE p.post_id = '.$id;
+		}
+		else
+		{
+			$qry = "
+				SELECT p.*,
+				u.user_name, u.user_customtitle, u.user_hideemail, u.user_email, u.user_signature,
+				u.user_admin, u.user_image, u.user_join, ue.user_plugin_forum_posts,
+				eu.user_name AS edit_name
+				FROM `#forum_post` AS p
+				LEFT JOIN `#user` AS u ON p.post_user = u.user_id
+				LEFT JOIN `#user` AS eu ON p.post_edit_user IS NOT NULL AND p.post_edit_user = eu.user_id
+				LEFT JOIN `#user_extended` AS ue ON ue.user_extended_id = p.post_user
+				WHERE p.post_thread = {$id}
+				ORDER BY p.post_datestamp ASC
+				LIMIT {$start}, {$num}
+			";
+		}
 		if($e107->sql->db_Select_gen($qry))
 		{
 			$ret = array();
@@ -318,6 +330,7 @@ class e107forum
 				$ret[] = $row;
 			}
 		}
+		if('post' === $start) { return $ret[0]; }
 		return $ret;
 	}
 
diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php
index fd22763c6..d34be908d 100644
--- a/e107_plugins/forum/forum_post.php
+++ b/e107_plugins/forum/forum_post.php
@@ -11,8 +11,8 @@
 |     GNU General Public License (http://gnu.org).
 |
 |     $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $
-|     $Revision: 1.29 $
-|     $Date: 2008-12-11 16:02:05 $
+|     $Revision: 1.30 $
+|     $Date: 2008-12-11 21:50:18 $
 |     $Author: mcfly_e107 $
 +----------------------------------------------------------------------------+
 */
@@ -22,27 +22,23 @@ $e_wysiwyg = 'post';
 $lan_file = e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_post.php';
 include(file_exists($lan_file) ? $lan_file : e_PLUGIN.'forum/languages/English/lan_forum_post.php');
 
-//var_dump($_POST);
-//exit;
-
 if (isset($_POST['fjsubmit']))
 {
 	header('location:'.$e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id'=>$_POST['forumjump'])));
 	exit;
 }
 
-//$_POST['forumjump']
 require_once(e_PLUGIN.'forum/forum_class.php');
 $forum = new e107forum;
 
-if (!e_QUERY || !isset($_REQUEST['id']))
+if (!e_QUERY || !isset($_GET['id']))
 {
 	header('Location:'.$e107->url->getUrl('forum', 'forum', array('func' => 'main')));
 	exit;
 }
 
-$action = trim($_REQUEST['f']);
-$id = (int)$_REQUEST['id'];
+$action = trim($_GET['f']);
+$id = (int)$_GET['id'];
 
 switch($action)
 {
@@ -58,13 +54,13 @@ switch($action)
 
 	case 'quote':
 	case 'edit':
-		$thread_info = $forum->thread_get_postinfo($id, true);
-		$forum_info = $forum->forum_get($thread_info['head']['thread_forum_id']);
-		if($_REQUST['f'] == 'quote')
-		{
-			$id = $thread_info['head']['thread_id'];
-		}
-		$forumId = $forum_info['forum_id'];
+		$postInfo = $forum->postGet($id, 'post');
+		$threadInfo = $postInfo;
+		$forumId = $postInfo['post_forum'];
+//		print_a($postInfo);
+//		exit;
+//		$forum_info = $forum->forum_get($thread_info['head']['thread_forum_id']);
+//		$forumId = $forum_info['forum_id'];
 		break;
 
 	default:
@@ -73,6 +69,7 @@ switch($action)
 
 }
 
+echo "forumId = $forumId <br />";
 // check if user can post to this forum ...
 if (!$forum->checkPerm($forumId, 'post'))
 {
@@ -419,45 +416,45 @@ if ($error)
 
 if ($action == 'edit' || $action == 'quote')
 {
- 	if ($action == "edit")
+ 	if ($action == 'edit')
 	{
 		if (!isAuthor())
 		{
-			$ns->tablerender(LAN_95, "<div style='text-align:center'>".LAN_96."</div>");
+			$ns->tablerender(LAN_95, "<div style='text-align:center'>".LAN_96.'</div>');
 			require_once(FOOTERF);
 			exit;
 		}
 	}
 
-	if(!is_array($thread_info[0]))
-	{
-		 $ns -> tablerender(LAN_20, "<div style='text-align:center'>".LAN_96."</div>");
-		 require_once(FOOTERF);
-		exit;
-	}
-
-	$thread_info[0]['user_name'] = $forum->thread_user($thread_info[0]);
 	if (!isset($_POST['fpreview']))
 	{
-		$subject = $thread_info['0']['thread_name'];
-		$post = $tp->toForm($thread_info[0]['thread_thread']);
+		$post = $e107->tp->toForm($postInfo['post_entry']);
+		if($postInfo['post_datestamp'] == $postInfo['thread_datestamp'])
+		{
+			$subject = $e107->tp->toForm($postInfo['thread_name']);
+		}
 	}
-	$post = preg_replace("/&lt;span class=&#39;smallblacktext&#39;.*\span\>/", "", $post);
 
-	if ($action == 'quote') {
-		$post = preg_replace("#\[hide].*?\[/hide]#s", "", $post);
-		$tmp = explode(chr(1), $thread_info[0]['user_name']);
-		$timeStamp = time();
-		$post = "[quote{$timeStamp}={$tmp[0]}]\n".$post."\n[/quote{$timeStamp}]\n";
-		$eaction = FALSE;
+	if ($action == 'quote')
+	{
+		//remote [hide] bbcode, or else it doesn't hide stuff too well :)
+		$post = preg_replace('#\[hide].*?\[/hide]#s', '', $post);
+		$quoteName = ($postInfo['user_name'] ? $postInfo['user_name'] : $postInfo['post_user_anon']);
+		$post = "[quote={$quoteName}]\n".$post."\n[/quote]\n";
+//		$eaction = true;
 		$action = 'reply';
-	} else {
-		$eaction = TRUE;
-		if ($thread_info['0']['thread_parent']) {
-			$action = "reply";
-		} else {
-			$action = "nt";
-			$sact = "canc";	// added to override the bugtracker query below
+	}
+	else
+	{
+		$eaction = true;
+		if($postInfo['post_datestamp'] != $postInfo['thread_datestamp'])
+		{
+			$action = 'reply';
+		}
+		else
+		{
+			$action = 'nt';
+			$sact = 'canc';	// added to override the bugtracker query below
 		}
 	}
 }
@@ -526,7 +523,8 @@ else
 
 function isAuthor()
 {
-	global $threadInfo;
+	global $postInfo;
+	print_a($postInfo);
 	return ((USERID === $postInfo['post_user']) || MODERATOR);
 }
 
diff --git a/e107_plugins/forum/forum_post_shortcodes.php b/e107_plugins/forum/forum_post_shortcodes.php
index 048a8241a..1d43ad82d 100644
--- a/e107_plugins/forum/forum_post_shortcodes.php
+++ b/e107_plugins/forum/forum_post_shortcodes.php
@@ -47,7 +47,7 @@ SC_END
 
 SC_BEGIN SUBJECTBOX
 global $subjectbox, $action;
-return ($action == "nt" ? $subjectbox : "");
+return ($action == 'nt' ? $subjectbox : '');
 SC_END
 
 SC_BEGIN POSTTYPE
@@ -121,7 +121,8 @@ return $BREADCRUMB;
 SC_END
 
 SC_BEGIN EMAILNOTIFY
-global $pref, $thread_info, $action;
+global $pref, $thread_info, $action, $eaction;
+if($eaction == true) { return ; }
 if ($pref['email_notify'] && $action == 'nt' && USER)
 {
 	if(isset($_POST['fpreview']))
diff --git a/e107_plugins/forum/forum_shortcodes.php b/e107_plugins/forum/forum_shortcodes.php
index 546aa6c1d..8e59f020f 100644
--- a/e107_plugins/forum/forum_shortcodes.php
+++ b/e107_plugins/forum/forum_shortcodes.php
@@ -27,6 +27,19 @@ $e107 = e107::getInstance();
 return $e107->tp->toHTML($postInfo['post_entry'], true, 'USER_BODY', 'class:'.$post_info['user_class']);
 SC_END
 
+SC_BEGIN POSTDELETED
+global $postInfo;
+if($postInfo['post_s'])
+{
+	$info = unserialize($postInfo['post_options']);
+	return  "
+	Post delete on: {$info['deldate']}<br />
+	reason: {$info['delreason']}
+	";
+	$ret = '<pre>'.print_r($info, true).'</pre>';
+}
+SC_END
+
 SC_BEGIN ATTACHMENTS
 global $postInfo;
 $e107 = e107::getInstance();
diff --git a/e107_plugins/forum/forum_sql.php b/e107_plugins/forum/forum_sql.php
index 732cbeae6..176c2e125 100644
--- a/e107_plugins/forum/forum_sql.php
+++ b/e107_plugins/forum/forum_sql.php
@@ -47,6 +47,7 @@ CREATE TABLE forum_post (
   `post_entry` text NOT NULL,
   `post_thread` int(10) unsigned default NULL,
   `post_forum` int(10) unsigned default NULL,
+  `post_s` tinyint(1) unsigned NOT NULL default '0',
   `post_datestamp` int(10) unsigned NOT NULL default '0',
   `post_user` int(10) unsigned NOT NULL,
   `post_edit_datestamp` int(10) unsigned NOT NULL default '0',
diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php
index 313834b76..eb8f69d57 100644
--- a/e107_plugins/forum/forum_viewtopic.php
+++ b/e107_plugins/forum/forum_viewtopic.php
@@ -12,8 +12,8 @@
 |     GNU General Public License (http://gnu.org).
 |
 |     $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $
-|     $Revision: 1.12 $
-|     $Date: 2008-12-11 16:02:05 $
+|     $Revision: 1.13 $
+|     $Date: 2008-12-11 21:50:18 $
 |     $Author: mcfly_e107 $
 +----------------------------------------------------------------------------+
 */
@@ -208,14 +208,16 @@ foreach ($postList as $postInfo)
 	{
 		$postInfo['thread_start'] = false;
 		$alt = !$alt;
-		if (isset($FORUMREPLYSTYLE_ALT) && $alt)
+
+		if($postInfo['post_s'])
 		{
-			$forrep .= $e107->tp->parseTemplate($FORUMREPLYSTYLE_ALT, true, $forum_shortcodes) . "\n";
+			$_style = (isset($FORUMDELETEDSTYLE_ALT) && $alt ? $FORUMDELETEDSTYLE_ALT : $FORUMDELETEDSTYLE);
 		}
 		else
 		{
-			$forrep .= $e107->tp->parseTemplate($FORUMREPLYSTYLE, true, $forum_shortcodes) . "\n";
+			$_style = (isset($FORUMREPLYSTYLE_ALT) && $alt ? $FORUMREPLYSTYLE_ALT : $FORUMREPLYSTYLE);
 		}
+		$forrep .= $e107->tp->parseTemplate($_style, true, $forum_shortcodes) . "\n";
 	}
 	else
 	{
diff --git a/e107_plugins/forum/templates/forum_viewtopic_template.php b/e107_plugins/forum/templates/forum_viewtopic_template.php
index 5d724f909..148d5355b 100644
--- a/e107_plugins/forum/templates/forum_viewtopic_template.php
+++ b/e107_plugins/forum/templates/forum_viewtopic_template.php
@@ -11,8 +11,8 @@
 |     GNU General Public License (http://gnu.org).
 |
 |     $Source: /cvs_backup/e107_0.8/e107_plugins/forum/templates/forum_viewtopic_template.php,v $
-|     $Revision: 1.3 $
-|     $Date: 2008-12-08 02:33:34 $
+|     $Revision: 1.4 $
+|     $Date: 2008-12-11 21:50:18 $
 |     $Author: mcfly_e107 $
 +----------------------------------------------------------------------------+
 */
@@ -246,6 +246,51 @@ $FORUMREPLYSTYLE = "<tr>
 	</td>
 	</tr>";
 
+$FORUMDELETEDSTYLE = "<tr>
+	<td class='forumheader' style='vertical-align:middle'>
+	{POSTER}
+	{ANON_IP}
+	</td>
+	<td class='forumheader' style='vertical-align:middle'>
+	<table cellspacing='0' cellpadding='0' style='width:100%'>
+	<tr>
+	<td class='smallblacktext'>
+	{THREADDATESTAMP}
+	</td>
+	<td style='text-align:right'>
+	</td>
+	</tr>
+	</table>
+	</td>
+	</tr>
+	<tr>
+	<td class='forumheader3' style='vertical-align:top' colspan='2'>
+	{POSTDELETED}
+	</td>
+	</tr>
+	<tr>
+	<td class='finfobar'>
+	<span class='smallblacktext'>
+	</span>
+	</td>
+	<td class='finfobar' style='vertical-align:top' colspan='2'>
+	<table cellspacing='0' cellpadding='0' style='width:100%'>
+	<tr>
+	<td>
+	</td>
+	<td style='text-align:right'>
+	{MODOPTIONS}
+	</td>
+	</tr>
+	</table>
+	</td>
+	</tr>
+	<tr>
+	<td colspan='2'>
+	</td>
+	</tr>";
+
+
 $FORUM_CRUMB['sitename']['value'] = "<a class='forumlink' {SITENAME_HREF}>{SITENAME}</a>";
 $FORUM_CRUMB['sitename']['sep'] = " :: ";