From ec1eeac94dfe849749f7cac328cb5c1f9035110b Mon Sep 17 00:00:00 2001
From: secretr <m.yovchev@gmail.com>
Date: Thu, 21 Apr 2011 13:20:22 +0000
Subject: [PATCH] Various forum problems: - nextprev new parameters usage -
 outdate forum code cleanup (preventing sc parsing) - forum preferences fixes
 (maybe more to do)

---
 e107_core/shortcodes/single/nextprev.php       |  6 ++++--
 .../core/shortcodes/batch/post_shortcodes.php  | 18 +++++++++++-------
 e107_plugins/forum/forum_admin_class.php       |  4 ++--
 e107_plugins/forum/forum_class.php             |  2 +-
 e107_plugins/forum/forum_post.php              |  6 +++---
 e107_plugins/forum/forum_viewforum.php         |  6 ++++--
 e107_plugins/forum/forum_viewtopic.php         | 11 +++++++++--
 7 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/e107_core/shortcodes/single/nextprev.php b/e107_core/shortcodes/single/nextprev.php
index 6ed95aeab..93448d5e1 100644
--- a/e107_core/shortcodes/single/nextprev.php
+++ b/e107_core/shortcodes/single/nextprev.php
@@ -2,7 +2,7 @@
 /*
  * e107 website system
  *
- * Copyright (C) 2008-2010 e107 Inc (e107.org)
+ * Copyright (C) 2008-2011 e107 Inc (e107.org)
  * Released under the terms and conditions of the
  * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  *
@@ -47,6 +47,8 @@
  * WARNING: You have to do rawuldecode() on url, caption and title parameter values (before passing them to the shortcode)
  * or you'll break the whole script
  *
+ * TODO - add create URL support when new URL handler is ready
+ *
  * @param string $parm
  * @return string page navigation bar HTML
  */
@@ -274,7 +276,7 @@ function nextprev_shortcode($parm = '')
 
 			if($show_last && !empty($tmpl[$tprefix.'nav_last']))
 			{
-				$e_vars->url = str_replace('[FROM]', $last_page, $url);
+				$e_vars->url = str_replace('[FROM]', $total_pages, $url);//$last_page
 				$e_vars->label = LAN_NP_LAST;
 				$e_vars->url_label = LAN_NP_URLLAST;
 				$ret_array[] = $tp->simpleParse($tmpl[$tprefix.'nav_last'], $e_vars);
diff --git a/e107_plugins/forum/core/shortcodes/batch/post_shortcodes.php b/e107_plugins/forum/core/shortcodes/batch/post_shortcodes.php
index 926d358e1..5b265e269 100644
--- a/e107_plugins/forum/core/shortcodes/batch/post_shortcodes.php
+++ b/e107_plugins/forum/core/shortcodes/batch/post_shortcodes.php
@@ -100,7 +100,7 @@ class plugin_forum_post_shortcodes extends e_shortcode
 
 	function sc_fileattach()
 	{
-		global $forum, $pref, $fileattach, $fileattach_alert;
+		global $forum, $fileattach, $fileattach_alert;
 
 		if ($forum->prefs->get('attach') && (check_class($pref['upload_class']) || getperms('0')))
 		{
@@ -115,7 +115,7 @@ class plugin_forum_post_shortcodes extends e_shortcode
 				{
 					if(!$fileattach_alert)
 					{
-						$fileattach_alert = "<tr><td colspan='2' class='nforumcaption2'>".($pref['image_post'] ? LAN_390 : LAN_416)."</td></tr><tr><td colspan='2' class='forumheader3'>".LAN_FORUM_1."</td></tr>\n";
+						$fileattach_alert = "<tr><td colspan='2' class='nforumcaption2'>".(e107::getPref('image_post') ? LAN_390 : LAN_416)."</td></tr><tr><td colspan='2' class='forumheader3'>".LAN_FORUM_1."</td></tr>\n";
 					}
 					return $fileattach_alert;
 				}
@@ -126,6 +126,7 @@ class plugin_forum_post_shortcodes extends e_shortcode
 	function sc_postthreadas()
 	{
 		global $action, $thread_info;
+		e_dump(MODERATOR);
 		if (MODERATOR && $action == "nt")
 		{
 			$thread_sticky = (isset($_POST['threadtype']) ? $_POST['threadtype'] : $thread_info['head']['thread_sticky']);
@@ -150,13 +151,16 @@ class plugin_forum_post_shortcodes extends e_shortcode
 
 	function sc_emailnotify()
 	{
-		global $pref, $thread_info, $action, $eaction;
+		global $thread_info, $action, $eaction;
+
+		$pref = e107::getPlugPref('forum');
+
 		if($eaction == true) { return ; }
-		if ($pref['email_notify'] && $action == 'nt' && USER)
+		if ($pref['notify'] && $action == 'nt' && USER)
 		{
 			if(isset($_POST['fpreview']))
 			{
-				$chk = ($_POST['email_notify'] ? "checked = 'checked'" : '');
+				$chk = ($_POST['notify'] ? "checked = 'checked'" : '');
 			}
 			else
 			{
@@ -166,10 +170,10 @@ class plugin_forum_post_shortcodes extends e_shortcode
 				}
 				else
 				{
-					$chk = ($pref['email_notify_on'] ? "checked='checked'" : '');
+					$chk = ($pref['notify_on'] ? "checked='checked'" : '');
 				}
 			}
-			return "<br /><input type='checkbox' name='email_notify' value='1' {$chk} />&nbsp;<span class='defaulttext'>".LAN_380."</span>";
+			return "<br /><input type='checkbox' name='notify' value='1' {$chk} />&nbsp;<span class='defaulttext'>".LAN_380."</span>";
 		}
 		return '';
 	}
diff --git a/e107_plugins/forum/forum_admin_class.php b/e107_plugins/forum/forum_admin_class.php
index 0ca51bb88..892286627 100755
--- a/e107_plugins/forum/forum_admin_class.php
+++ b/e107_plugins/forum/forum_admin_class.php
@@ -664,12 +664,12 @@ class forumAdmin
 
 		<tr>
 		<td style='width:75%' class='forumheader3'>".FORLAN_47."<br /><span class='smalltext'>".FORLAN_48."</span></td>
-		<td style='width:25%;text-align:center' class='forumheader3' >".($fPref->get('email_notify') ? "<input type='checkbox' name='email_notify' value='1' checked='checked' />" : "<input type='checkbox' name='email_notify' value='1' />")."</td>
+		<td style='width:25%;text-align:center' class='forumheader3' >".($fPref->get('notify') ? "<input type='checkbox' name='email_notify' value='1' checked='checked' />" : "<input type='checkbox' name='email_notify' value='1' />")."</td>
 		</tr>
 
 		<tr>
 		<td style='width:75%' class='forumheader3'>".FORLAN_177."<br /><span class='smalltext'>".FORLAN_178."</span></td>
-		<td style='width:25%;text-align:center' class='forumheader3' >".($fPref->get('email_notify_on') ? "<input type='checkbox' name='email_notify_on' value='1' checked='checked' />" : "<input type='checkbox' name='email_notify_on' value='1' />")."</td>
+		<td style='width:25%;text-align:center' class='forumheader3' >".($fPref->get('notify_on') ? "<input type='checkbox' name='email_notify_on' value='1' checked='checked' />" : "<input type='checkbox' name='email_notify_on' value='1' />")."</td>
 		</tr>
 
 		<tr>
diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php
index 7b1ed5544..16821c22f 100644
--- a/e107_plugins/forum/forum_class.php
+++ b/e107_plugins/forum/forum_class.php
@@ -699,7 +699,7 @@ class e107forum
 
 	function isModerator($uid)
 	{
-		return ($uid && in_array($uid, array_keys($this->modArray)));
+		return ($uid && in_array($uid, array_keys($this->forumGetMods())));
 	}
 
 	function forumGetForumList($all=false)
diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php
index e131e2850..fa4e05744 100644
--- a/e107_plugins/forum/forum_post.php
+++ b/e107_plugins/forum/forum_post.php
@@ -14,7 +14,7 @@
 
 require_once('../../class2.php');
 $e107 = e107::getInstance();
-if (!$e107->isInstalled('forum')) 
+if (!$e107->isInstalled('forum'))
 {
 	header('Location: '.e_BASE.'index.php');
 	exit;
@@ -29,7 +29,7 @@ if (isset($_POST['fjsubmit']))
 }
 
 require_once(e_PLUGIN.'forum/forum_class.php');
-$forum = new e107forum;
+$forum = new e107forum();
 
 if (!e_QUERY || !isset($_GET['id']))
 {
@@ -325,7 +325,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
 		$e107cache->clear('newforumposts');
 		$threadLink = $e107->url->getUrl('forum', 'thread', array('func' => 'last', 'id' => $threadId));
 		$forumLink = $e107->url->getUrl('forum', 'forum', array('func' => 'view', 'id' => $forumId));
-		if ($forum->prefs->get('forum_redirect'))
+		if ($forum->prefs->get('redirect'))
 		{
 			header('location:'.$threadLink);
 			exit;
diff --git a/e107_plugins/forum/forum_viewforum.php b/e107_plugins/forum/forum_viewforum.php
index 8e08316de..b18225136 100644
--- a/e107_plugins/forum/forum_viewforum.php
+++ b/e107_plugins/forum/forum_viewforum.php
@@ -15,7 +15,7 @@
 
 require_once('../../class2.php');
 $e107 = e107::getInstance();
-if (!$e107->isInstalled('forum')) 
+if (!$e107->isInstalled('forum'))
 {
 	header('Location: '.e_BASE.'index.php');
 	exit;
@@ -129,7 +129,9 @@ if ($pages)
 {
 	if(strpos($FORUM_VIEW_START, 'THREADPAGES') !== false || strpos($FORUM_VIEW_END, 'THREADPAGES') !== false)
 	{
-		$parms = "{$pages},1,{$page},url::forum::forum::func=view&id={$forumId}&page=[FROM], off";
+		if(!$page) $page = 1;
+		$url = rawurlencode(e107::getUrl()->getUrl('forum', 'forum', array('func' => 'view', 'id' => $forumId, 'page' => '[FROM]')));
+		$parms = "total={$pages}&type=page&current={$page}&url=".$url."&caption=off";
 		$fVars->THREADPAGES = $e107->tp->parseTemplate("{NEXTPREV={$parms}}");
 	}
 }
diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php
index aea7605f7..6d6349d5d 100644
--- a/e107_plugins/forum/forum_viewtopic.php
+++ b/e107_plugins/forum/forum_viewtopic.php
@@ -15,7 +15,9 @@
 
 require_once ('../../class2.php');
 $e107 = e107::getInstance();
-if (!$e107->isInstalled('forum')) 
+$tp = e107::getParser();
+
+if (!$e107->isInstalled('forum'))
 {
 	header('Location: '.e_BASE.'index.php');
 	exit;
@@ -178,8 +180,13 @@ $tVars->THREADSTATUS = (!$thread->threadInfo['thread_active'] ? LAN_66 : '');
 
 if ($thread->pages > 1)
 {
-	$parms = ($thread->pages).",1,{$thread->page},url::forum::thread::func=view&id={$thread->threadId}&page=[FROM],off";
+	if(!$thread->page) $thread->page = 1;
+	$url = rawurlencode(e107::getUrl()->getUrl('forum', 'thread', array('func' => 'view', 'id' => $thread->threadId, 'page' => '[FROM]')));
+	$parms = "total={$thread->pages}&type=page&current={$thread->page}&url=".$url."&caption=off";
 	$tVars->GOTOPAGES = $tp->parseTemplate("{NEXTPREV={$parms}}");
+/*
+	$parms = ($thread->pages).",1,{$thread->page},url::forum::thread::func=view&id={$thread->threadId}&page=[FROM],off";
+	$tVars->GOTOPAGES = $tp->parseTemplate("{NEXTPREV={$parms}}");*/
 }
 
 $tVars->BUTTONS = '';