From 497f433bbf20225ef7b330d5806ceb1176172386 Mon Sep 17 00:00:00 2001 From: mcfly Date: Sun, 7 Dec 2008 00:21:21 +0000 Subject: [PATCH] Forum work --- e107_handlers/mysql_class.php | 10 +- e107_plugins/forum/forum_class.php | 14 +-- e107_plugins/forum/forum_post.php | 23 +++-- e107_plugins/forum/forum_viewtopic.php | 81 ++++++++++++---- e107_plugins/forum/newforumposts_menu.php | 96 +++++++++---------- .../forum/templates/forum_icons_template.php | 9 +- 6 files changed, 143 insertions(+), 90 deletions(-) diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 9c22ebcae..560f5a048 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -12,8 +12,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ -| $Revision: 1.31 $ -| $Date: 2008-11-29 18:47:39 $ +| $Revision: 1.32 $ +| $Date: 2008-12-07 00:21:20 $ | $Author: mcfly_e107 $ | +----------------------------------------------------------------------------+ @@ -30,7 +30,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s * MySQL Abstraction class * * @package e107 -* @version $Revision: 1.31 $ +* @version $Revision: 1.32 $ * @author $Author: mcfly_e107 $ */ class db { @@ -445,6 +445,10 @@ class db { return "'{$fieldValue}'"; break; + case 'escape': + return "'".mysql_real_escape_string($fieldValue)."'"; + break; + case 'todb': default: if($fieldValue == '') { return "''"; } diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 47fd05b41..770e055f1 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.18 $ -| $Date: 2008-12-05 20:28:05 $ +| $Revision: 1.19 $ +| $Date: 2008-12-07 00:21:21 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -31,16 +31,18 @@ class e107forum $this->fieldTypes['forum_post']['post_forum'] = 'int'; $this->fieldTypes['forum_post']['post_datestamp'] = 'int'; $this->fieldTypes['forum_post']['post_thread'] = 'int'; + $this->fieldTypes['forum_post']['post_options'] = 'escape'; $this->fieldTypes['forum_thread']['thread_user'] = 'int'; $this->fieldTypes['forum_thread']['thread_lastpost'] = 'int'; $this->fieldTypes['forum_thread']['thread_lastuser'] = 'int'; $this->fieldTypes['forum_thread']['thread_s'] = 'int'; $this->fieldTypes['forum_thread']['thread_forum_id'] = 'int'; - $this->fieldTypes['forum_thread']['thread_active'] = 'int'; - $this->fieldTypes['forum_thread']['thread_datestamp'] = 'int'; + $this->fieldTypes['forum_thread']['thread_active'] = 'int'; + $this->fieldTypes['forum_thread']['thread_datestamp'] = 'int'; $this->fieldTypes['forum_thread']['thread_views'] = 'int'; $this->fieldTypes['forum_thread']['thread_replies'] = 'int'; + $this->fieldTypes['forum_thread']['thread_options'] = 'escape'; $this->fieldTypes['forum']['forum_lastpost_user'] = 'int'; @@ -67,7 +69,6 @@ class e107forum function getForumPermList() { - global $e107; $this->permList = array(); @@ -253,6 +254,7 @@ class e107forum function threadGet($id, $joinForum = true, $uid = USERID) { + global $pref; $e107 = e107::getInstance(); $id = (int)$id; $uid = (int)$uid; @@ -281,7 +283,7 @@ class e107forum { if(trim($tmp['thread_options']) != '') { - $tmp['thread_options'] = inserialize($tmp['thread_options']); + $tmp['thread_options'] = unserialize($tmp['thread_options']); } return $tmp; } diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index 160014dde..5dce1af37 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.23 $ -| $Date: 2008-12-05 20:28:05 $ +| $Revision: 1.24 $ +| $Date: 2008-12-07 00:21:21 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -22,6 +22,9 @@ $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']))); @@ -162,11 +165,11 @@ if (isset($_POST['fpreview'])) $tsubject = $tp->post_toHTML($_POST['subject'], true); $tpost = $tp->post_toHTML($_POST['post'], true); - if ($_POST['poll_title'] != "" && $pref['forum_poll']) + if ($_POST['poll_title'] != '' && $pref['forum_poll']) { require_once(e_PLUGIN."poll/poll_class.php"); $poll = new poll; - $poll->render_poll($_POST, "forum", "notvoted"); + $poll->render_poll($_POST, 'forum', 'notvoted'); } if (!$FORUM_PREVIEW) @@ -216,6 +219,9 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) { $postInfo = array(); $threadInfo = array(); + $postOptions = array(); + $threadOptions = array(); + if ((isset($_POST['newthread']) && trim($_POST['subject']) == '') || trim($_POST['post']) == '') { message_handler('ALERT', 5); @@ -227,6 +233,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) echo "\n"; exit; } + $hasPoll = ($action == 'nt' && varset($_POST['poll_title']) && $_POST['poll_option'][0] != '' && $_POST['poll_option'][1] != ''); process_upload(); $postInfo['post_ip'] = $e107->getip(); @@ -258,7 +265,6 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) $postResult = $forum->postAdd($postInfo); break; - // New thread started. Add the thread info (with lastest post info), add the post. // Update forum with latest post info case 'nt': @@ -267,6 +273,11 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) $threadInfo['thread_forum_id'] = $forumId; $threadInfo['thread_active'] = 1; $threadInfo['thread_datestamp'] = $time; + if($hasPoll) + { + $threadOptions['poll'] = '1'; + } + $threadInfo['thread_options'] = serialize($threadOptions); $postResult = $forum->threadAdd($threadInfo, $postInfo); break; } @@ -294,7 +305,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) if ($action == 'nt' && varset($_POST['poll_title']) && $_POST['poll_option'][0] != '' && $_POST['poll_option'][1] != '') { require_once(e_PLUGIN.'poll/poll_class.php'); - $_POST['iid'] = $iid; + $_POST['iid'] = $threadId; $poll = new poll; $poll->submit_poll(2); } diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index a47e6ebea..c7530ff96 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.7 $ -| $Date: 2008-12-05 20:28:05 $ +| $Revision: 1.8 $ +| $Date: 2008-12-07 00:21:21 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -37,6 +37,7 @@ if (!e_QUERY) include_lan(e_PLUGIN . 'forum/languages/English/lan_forum_viewtopic.php'); include_once (e_PLUGIN . 'forum/forum_class.php'); +include_lan(e_PLUGIN . 'forum/templates/forum_icons_template.php'); $forum = new e107forum; $thread = new e107ForumThread; @@ -120,7 +121,8 @@ if (!$FORUMSTART) if (file_exists(THEME . 'forum_viewtopic_template.php')) { require_once (THEME . 'forum_viewtopic_template.php'); - } elseif (file_exists(THEME . 'forum_template.php')) + } + elseif (file_exists(THEME . 'forum_template.php')) { require_once (THEME . 'forum_template.php'); } @@ -130,8 +132,6 @@ if (!$FORUMSTART) } } -//$forum_info['forum_name'] = $e107->tp->toHTML($threadInfo['forum_name'], true, 'no_hook,emotes_off'); - // get info for main thread ------------------------------------------------------------------------------------------------------------------------------------------------------------------- $forum->set_crumb(true); // Set $BREADCRUMB (and BACKLINK) @@ -144,11 +144,50 @@ if ($pref['forum_track'] && USER) { if ($thread->threadInfo['track_userid']) { - $TRACK = " 'untrack', 'id' => $thread->threadId)) . "'>" . LAN_392 . ""; + $TRACK = " + + 'untrack', 'id' => $thread->threadId)) . "'>" . LAN_392 . " + "; + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'untrack', 'id' => $thread->threadId)); + $TRACK = " + + ".IMAGE_untrack." + + + + "; } else { - $TRACK = " 'track', 'id' => $thread->threadId)) . "'>" . LAN_391 . ""; + $TRACK = " + + 'track', 'id' => $thread->threadId)) . "'>" . LAN_391 . " + + "; + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'track', 'id' => $thread->threadId)); + $TRACK = " + + ".IMAGE_track." + + + + "; } } @@ -451,7 +490,7 @@ class e107ForumThread function processFunction() { - global $forum; + global $forum, $thread; $e107 = e107::getInstance(); if (!isset($_GET['f'])) { @@ -481,22 +520,26 @@ class e107ForumThread break; case 'track': - if (!USER || !isset($_GET['id'])) - { - return; - } + if (!USER || !isset($_GET['id'])) { return; } $forum->track('add', USERID, $_GET['id']); + + if(e_AJAX_REQUEST) + { + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'untrack', 'id' => $thread->threadId)); + echo "".IMAGE_untrack.""; + exit(); + } break; - // header("location:".e_SELF."?{$thread_id}.{$topic_from}"); - // exit; - case 'untrack': - if (!USER || !isset($_GET['id'])) - { - return; - } + if (!USER || !isset($_GET['id'])) { return; } $forum->track('del', USERID, $_GET['id']); + if(e_AJAX_REQUEST) + { + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'track', 'id' => $thread->threadId)); + echo "".IMAGE_track.""; + exit(); + } break; case 'last': diff --git a/e107_plugins/forum/newforumposts_menu.php b/e107_plugins/forum/newforumposts_menu.php index 3db2f8cd6..6a5ee9d64 100755 --- a/e107_plugins/forum/newforumposts_menu.php +++ b/e107_plugins/forum/newforumposts_menu.php @@ -11,90 +11,80 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/newforumposts_menu.php,v $ -| $Revision: 1.6 $ -| $Date: 2008-07-20 17:08:31 $ -| $Author: e107steved $ +| $Revision: 1.7 $ +| $Date: 2008-12-07 00:21:21 $ +| $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ if (!defined('e107_INIT')) { exit; } -global $tp; +$e107 = e107::getInstance(); $gen = new convert; -if (file_exists(e_PLUGIN."forum/languages/".e_LANGUAGE."/lan_newforumposts_menu.php")) -{ - include_once(e_PLUGIN."forum/languages/".e_LANGUAGE."/lan_newforumposts_menu.php"); -} -else -{ - include_once(e_PLUGIN."forum/languages/English/lan_newforumposts_menu.php"); -} +include_lan(e_PLUGIN.'forum/languages/English/lan_newforumposts_menu.php'); +include_once(e_PLUGIN.'forum/forum_class.php'); -$max_age = varset($menu_pref['newforumposts_maxage'],0); -$max_age = $max_age == 0 ? '' : "(t.thread_datestamp > ".intval(time()-$max_age*86400).") AND "; -$query2 = " -SELECT tp.thread_name AS parent_name, -t.thread_datestamp , t.thread_thread, t.thread_name, t.thread_id, t.thread_user, -f.forum_id, f.forum_name, f.forum_class, u.user_name, fp.forum_class FROM #forum_t AS t -LEFT JOIN #user AS u ON t.thread_user = u.user_id -LEFT JOIN #forum_t AS tp ON t.thread_parent = tp.thread_id -LEFT JOIN #forum AS f ON (f.forum_id = t.thread_forum_id AND f.forum_class IN (".USERCLASS_LIST.")) -LEFT JOIN #forum AS fp ON f.forum_parent = fp.forum_id -WHERE {$max_age} fp.forum_class IN (".USERCLASS_LIST.") -ORDER BY t.thread_datestamp DESC LIMIT 0, ".$menu_pref['newforumposts_display']; +$max_age = varset($menu_pref['newforumposts_maxage'], 0); +$max_age = $max_age == 0 ? '' : '(t.post_datestamp > '.(time()-(int)$max_age*86400).') AND '; +$forum = new e107forum; +$forumList = implode(',', $forum->permList['view']); -$results = $sql->db_Select_gen($query2); +$qry = " +SELECT + p.post_user, p.post_id, p.post_datestamp, p.post_user_anon, p.post_entry, + t.thread_id, t.thread_datestamp, t.thread_name, u.user_name +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 {$maxage} p.post_forum IN ({$forumList}) +ORDER BY p.post_datestamp DESC LIMIT 0, ".$menu_pref['newforumposts_display']; -if(!$results) +if($results = $e107->sql->db_Select_gen($qry)) { - // no posts yet .. - $text = NFP_2; -} -else -{ - $text = ""; - $forumArray = $sql->db_getList(); - foreach($forumArray as $fi) + while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { - $datestamp = $gen->convert_date($fi['thread_datestamp'], "short"); - $topic = ($fi['parent_name'] ? "Re: {$fi['parent_name']}" : "{$fi['thread_name']}"); - $topic = strip_tags($tp->toHTML($topic, TRUE, "emotes_off, no_make_clickable, parse_bb", "", $pref['menu_wordwrap'])); - $id = $fi['thread_id']; - - if($fi['user_name']) + $datestamp = $gen->convert_date($row['post_datestamp'], 'short'); + $id = $row['thread_id']; + $topic = ($row['thread_datestamp'] == $row['post_datestamp'] ? '' : 'Re:'); + $topic .= strip_tags($e107->tp->toHTML($row['thread_name'], true, 'emotes_off, no_make_clickable, parse_bb', '', $pref['menu_wordwrap'])); + if($row['post_user_anon']) { - $poster = $fi['user_name']; + $poster = $row['post_user_anon']; } else { - $x = explode(chr(1), $fi['thread_user']); - $tmp = explode(".", $x[0], 2); - if($tmp[1]) + if($row['user_name']) { - $poster = $tmp[1]; + $poster = " 'profile', 'id' => $row['post_user']))."'>{$row['user_name']}"; } else { - $poster = "[deleted]"; + $poster = '[deleted]'; } } - $fi['thread_thread'] = strip_tags($tp->toHTML($fi['thread_thread'], TRUE, "emotes_off, no_make_clickable", "", $pref['menu_wordwrap'])); - - $fi['thread_thread'] = $tp->text_truncate($fi['thread_thread'], $menu_pref['newforumposts_characters'], $menu_pref['newforumposts_postfix']); + $post = strip_tags($e107->tp->toHTML($row['post_entry'], true, 'emotes_off, no_make_clickable', '', $pref['menu_wordwrap'])); + $post = $e107->tp->text_truncate($post, $menu_pref['newforumposts_characters'], $menu_pref['newforumposts_postfix']); + $url = $e107->url->getUrl('forum', 'thread', array('func' => 'last', 'id' => $id)); + $bullet = ""; + + if ($menu_pref['newforumposts_title']) { - $text .= " ".$topic."
".$fi['thread_thread']."
".NFP_11." ".$poster."
".$datestamp."

"; + $text .= "{$topic}
{$post}
".NFP_11." {$poster}
{$datestamp}

"; } else { - $text .= " ".NFP_11." ".$poster."
".$fi['thread_thread']."
".$datestamp."

"; + $text .= "".NFP_11." {$poster}
{$post}
{$datestamp}

"; } } } +else +{ + $text = NFP_2; -$ns->tablerender($menu_pref['newforumposts_caption'], $text, 'nfp_menu'); - +} +$e107->ns->tablerender($menu_pref['newforumposts_caption'], $text, 'nfp_menu'); ?> \ No newline at end of file diff --git a/e107_plugins/forum/templates/forum_icons_template.php b/e107_plugins/forum/templates/forum_icons_template.php index e63de3314..548fc7cf2 100644 --- a/e107_plugins/forum/templates/forum_icons_template.php +++ b/e107_plugins/forum/templates/forum_icons_template.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/templates/forum_icons_template.php,v $ -| $Revision: 1.2 $ -| $Date: 2007-03-04 16:59:32 $ -| $Author: e107steved $ +| $Revision: 1.3 $ +| $Date: 2008-12-07 00:21:21 $ +| $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -51,6 +51,9 @@ define("IMAGE_admin_move2", "".LA
 define("IMAGE_post", "<img src="); define("IMAGE_post2", ""); define("IMAGE_report", "".LAN_413.""); + +define("IMAGE_track", "".LAN_391.""); +define("IMAGE_untrack", "".LAN_392.""); // Admin Icons