From 0f7c3be9ed45a7274bafcdc0af1357413ce63b49 Mon Sep 17 00:00:00 2001 From: mcfly Date: Sat, 13 Dec 2008 21:52:19 +0000 Subject: [PATCH] More work on edit, and some pagination --- e107_plugins/forum/attachments/index.htm | 0 .../forum/attachments/thumb/index.htm | 0 e107_plugins/forum/e_url/forum.php | 8 ++- e107_plugins/forum/e_url/thread.php | 5 +- e107_plugins/forum/forum_class.php | 35 +++++++++- e107_plugins/forum/forum_post.php | 64 +++++++++++-------- e107_plugins/forum/forum_post_shortcodes.php | 2 +- e107_plugins/forum/forum_shortcodes.php | 13 ++-- e107_plugins/forum/forum_viewtopic.php | 62 +++++------------- .../languages/English/lan_forum_viewtopic.php | 5 +- .../templates/forum_viewtopic_template.php | 13 ++-- 11 files changed, 114 insertions(+), 93 deletions(-) create mode 100755 e107_plugins/forum/attachments/index.htm create mode 100755 e107_plugins/forum/attachments/thumb/index.htm diff --git a/e107_plugins/forum/attachments/index.htm b/e107_plugins/forum/attachments/index.htm new file mode 100755 index 000000000..e69de29bb diff --git a/e107_plugins/forum/attachments/thumb/index.htm b/e107_plugins/forum/attachments/thumb/index.htm new file mode 100755 index 000000000..e69de29bb diff --git a/e107_plugins/forum/e_url/forum.php b/e107_plugins/forum/e_url/forum.php index 877890a99..28e8861f6 100644 --- a/e107_plugins/forum/e_url/forum.php +++ b/e107_plugins/forum/e_url/forum.php @@ -1,5 +1,5 @@ fieldTypes['forum_post']['post_user'] = 'int'; $this->fieldTypes['forum_post']['post_forum'] = 'int'; $this->fieldTypes['forum_post']['post_datestamp'] = 'int'; + $this->fieldTypes['forum_post']['post_edit_datestamp'] = 'int'; + $this->fieldTypes['forum_post']['post_edit_user'] = 'int'; $this->fieldTypes['forum_post']['post_thread'] = 'int'; $this->fieldTypes['forum_post']['post_options'] = 'escape'; $this->fieldTypes['forum_post']['post_attachments'] = 'escape'; @@ -248,12 +250,27 @@ class e107forum return false; } - function threadUpdate($threadInfo, $inc) + function threadUpdate($threadId, $threadInfo) { $e107 = e107::getInstance(); + $threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; + $threadInfo['WHERE'] = 'thread_id = '.(int)$threadId; +// var_dump($threadInfo); +// exit; + $e107->sql->db_Update('forum_thread', $threadInfo); //TODO: Add this } + function postUpdate($postId, $postInfo) + { + $e107 = e107::getInstance(); + $postInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_post']; + $postInfo['WHERE'] = 'post_id = '.(int)$postId; +// var_dump($postInfo); +// exit; + $e107->sql->db_Update('forum_post', $postInfo); + } + function threadGet($id, $joinForum = true, $uid = USERID) { global $pref; @@ -433,6 +450,18 @@ class e107forum } } + /** + * Given threadId and postId, determine which number of post in thread the postid is + * + */ + function postGetPostNum($threadId, $postId) + { + $threadId = (int)$threadId; + $postId = (int)$postId; + $e107 = e107::getInstance(); + return $e107->sql->db_Count('forum_post', '(*)', "WHERE post_id <= {$postId} AND post_thread = {$threadId} ORDER BY post_id ASC"); + } + function thread_postnum($thread_id) { diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index d34be908d..115796b49 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.30 $ -| $Date: 2008-12-11 21:50:18 $ +| $Revision: 1.31 $ +| $Date: 2008-12-13 21:52:18 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -69,7 +69,7 @@ switch($action) } -echo "forumId = $forumId
"; +//echo "forumId = $forumId
"; // check if user can post to this forum ... if (!$forum->checkPerm($forumId, 'post')) { @@ -322,6 +322,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) $poll->submit_poll(2); } + $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 ($pref['forum_redirect']) @@ -345,16 +346,18 @@ if (isset($_POST['newthread']) || isset($_POST['reply'])) } echo (isset($_POST['newthread']) ? $FORUMTHREADPOSTED : $FORUMREPLYPOSTED); - $e107cache->clear('newforumposts'); require_once(FOOTERF); exit; } } } -require_once(HEADERF); if (isset($_POST['update_thread'])) { +// var_dump($_POST); +// var_dump($threadInfo); +// var_dump($postInfo); +// exit; if (!$_POST['subject'] || !$_POST['post']) { $error = "
".LAN_27."
"; @@ -363,23 +366,24 @@ if (isset($_POST['update_thread'])) { if (!isAuthor()) { + require_once(HEADERF); $ns->tablerender(LAN_95, "
".LAN_96.'
'); require_once(FOOTERF); exit; } - $newvals['thread_edit_datestamp'] = time(); - $newvals['thread_thread'] = $_POST['post']; - $newvals['thread_name'] = $_POST['subject']; - $newvals['thread_active'] = (isset($_POST['email_notify'])) ? '99' : '1'; // Always set in case it's changed - if (isset($_POST['threadtype']) && MODERATOR) - { - $newvals['thread_s'] = $_POST['threadtype']; - } - $forum->thread_update($id, $newvals); - $e107cache->clear("newforumposts"); - $url = e_PLUGIN."forum/forum_viewtopic.php?{$thread_info['head']['thread_id']}.0"; - echo "\n"; + $postVals['post_edit_datestamp'] = time(); + $postVals['post_edit_user'] = USERID; + $postVals['post_entry'] = $_POST['post']; + + $threadVals['thread_name'] = $_POST['subject']; + + $forum->threadUpdate($postInfo['post_thread'], $threadVals); + $forum->postUpdate($postInfo['post_id'], $postVals); + $e107cache->clear('newforumposts'); + $url = $e107->url->getUrl('forum', 'thread', "func=post&id={$postInfo['post_id']}"); + header('location:'.$url); + exit; } } @@ -387,27 +391,31 @@ if (isset($_POST['update_reply'])) { if (!$_POST['post']) { - $error = "
".LAN_27."
"; + $error = "
".LAN_27.'
'; } else { if (!isAuthor()) { - $ns->tablerender(LAN_95, "
".LAN_96."
"); + require_once(HEADERF); + $ns->tablerender(LAN_95, "
".LAN_96.'
'); require_once(FOOTERF); exit; } - $url = e_PLUGIN."forum/forum_viewtopic.php?{$id}.post"; - echo "\n"; - $newvals['thread_edit_datestamp'] = time(); - $newvals['thread_thread'] = $_POST['post']; - $forum->thread_update($id, $newvals); - $e107cache->clear("newforumposts"); - $url = e_PLUGIN."forum/forum_viewtopic.php?{$id}.post"; - echo "\n"; + $postVals['post_edit_datestamp'] = time(); + $postVals['post_edit_user'] = USERID; + $postVals['post_entry'] = $_POST['post']; + + $forum->postUpdate($postInfo['post_id'], $postVals); + $e107cache->clear('newforumposts'); + $url = $e107->url->getUrl('forum', 'thread', "func=post&id={$postInfo['post_id']}"); + header('location:'.$url); + exit; } } +require_once(HEADERF); + if ($error) { $ns->tablerender(LAN_20, $error); @@ -524,7 +532,7 @@ else function isAuthor() { global $postInfo; - print_a($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 1d43ad82d..2586884fb 100644 --- a/e107_plugins/forum/forum_post_shortcodes.php +++ b/e107_plugins/forum/forum_post_shortcodes.php @@ -29,7 +29,7 @@ return $tp->parseTemplate($THREADTOPIC_REPLY, TRUE, $forum_shortcodes); SC_END SC_BEGIN FORMSTART -return "
"; +return ""; SC_END SC_BEGIN FORMEND diff --git a/e107_plugins/forum/forum_shortcodes.php b/e107_plugins/forum/forum_shortcodes.php index 8e59f020f..915db975b 100644 --- a/e107_plugins/forum/forum_shortcodes.php +++ b/e107_plugins/forum/forum_shortcodes.php @@ -316,20 +316,25 @@ SC_END SC_BEGIN LASTEDIT global $postInfo, $gen; +//var_dump($postInfo); if ($postInfo['post_edit_datestamp']) { - return $gen->convert_date($postInfo['thread_edit_datestamp'],'forum'); + return $gen->convert_date($postInfo['post_edit_datestamp'],'forum'); } SC_END SC_BEGIN LASTEDITBY global $postInfo; -$e107 = e107::getInstance(); -if ($postInfo['post_edit_datestamp']) +if(isset($postInfo['edit_name'])) { + if($parm == 'link') + { + $e107 = e107::getInstance(); + $url = $e107->url->getUrl('core:user', 'main', 'func=profile&id='.$postInfo['post_edit_user']); + return "{$postInfo['edit_name']}"; + } return $postInfo['edit_name']; } -return ''; SC_END SC_BEGIN POLL diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index eb8f69d57..e3306b9e9 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.13 $ -| $Date: 2008-12-11 21:50:18 $ +| $Revision: 1.14 $ +| $Date: 2008-12-13 21:52:18 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -42,6 +42,10 @@ include_lan(e_PLUGIN . 'forum/templates/forum_icons_template.php'); $forum = new e107forum; $thread = new e107ForumThread; +if(isset($_GET['f']) && $_GET['f'] == 'post') +{ + $thread->processFunction(); +} $thread->init(); @@ -80,7 +84,7 @@ if (MODERATOR && isset($_POST['mod'])) $thread->threadInfo = $forum->threadGet($thread->threadId); } -$postList = $forum->PostGet($thread->threadId, $thread->page * $thread->perPage, $thread->perPage); +$postList = $forum->PostGet($thread->threadId, ($thread->page-1) * $thread->perPage, $thread->perPage); //var_dump($thread->threadInfo); require_once (e_HANDLER . 'level_handler.php'); @@ -449,7 +453,7 @@ class e107ForumThread $e107 = e107::getInstance(); $this->threadId = (int)varset($_GET['id']); $this->perPage = (varset($_GET['perpage']) ? (int)$_GET['perpage'] : $pref['forum_postspage']); - $this->page = (varset($_GET['p']) ? (int)$_GET['p'] : 0); + $this->page = (varset($_GET['p']) ? (int)$_GET['p'] : 1); //If threadId doesn't exist, or not given, redirect to main forum page if (!$this->threadId || !$this->threadInfo = $forum->threadGet($this->threadId)) @@ -492,7 +496,7 @@ class e107ForumThread function processFunction() { - global $forum, $thread; + global $forum, $thread, $pref; $e107 = e107::getInstance(); if (!isset($_GET['f'])) { @@ -503,47 +507,15 @@ class e107ForumThread switch ($function) { case 'post': - if ($thread_id) - { - $post_num = $forum->thread_postnum($thread_id); - $pages = ceil(($post_num['post_num'] + 1) / $pref['forum_postspage']); - $topic_from = ($pages - 1) * $pref['forum_postspage']; - if ($post_num['parent'] != $thread_id) - { - header("location: " . e_SELF . "?{$post_num['parent']}.{$topic_from}#post_{$thread_id}"); - exit; - } - } - else - { - header('Location:' . $e107->url->getUrl('forum', 'forum', array('func' => 'main'))); - exit; - } + $postId = varset($_GET['id']); + $postInfo = $forum->postGet($postId,'post'); + $postNum = $forum->postGetPostNum($postInfo['post_thread'], $postId); + $postPage = ceil($postNum / $pref['forum_postspage']); + $url = $e107->url->getUrl('forum', 'thread', "func=view&id={$postInfo['post_thread']}&page=$postPage"); +// echo "url: $url
"; + header('location: '.$url); + exit; break; -/* - case 'track': - 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; - - case 'untrack': - 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': // $pref['forum_postspage'] = ($pref['forum_postspage'] ? $pref['forum_postspage'] : 10); diff --git a/e107_plugins/forum/languages/English/lan_forum_viewtopic.php b/e107_plugins/forum/languages/English/lan_forum_viewtopic.php index 5a808746b..c5b222575 100644 --- a/e107_plugins/forum/languages/English/lan_forum_viewtopic.php +++ b/e107_plugins/forum/languages/English/lan_forum_viewtopic.php @@ -4,8 +4,8 @@ | e107 website system - Language File. | | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/languages/English/lan_forum_viewtopic.php,v $ -| $Revision: 1.1.1.1 $ -| $Date: 2006-12-02 04:35:18 $ +| $Revision: 1.2 $ +| $Date: 2008-12-13 21:52:19 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -85,5 +85,6 @@ define("FORLAN_101", "Email Thread"); define("FORLAN_102", "Print View"); define('FORLAN_103', '[user deleted]'); define('FORLAN_104', 'Thread not found'); +define('FORLAN_BY', 'by'); define("FORLAN_HIDDEN", "HIDDEN - LOGIN AND REPLY TO REVEAL"); ?> diff --git a/e107_plugins/forum/templates/forum_viewtopic_template.php b/e107_plugins/forum/templates/forum_viewtopic_template.php index 148d5355b..cc6dfcbf9 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.4 $ -| $Date: 2008-12-11 21:50:18 $ +| $Revision: 1.5 $ +| $Date: 2008-12-13 21:52:19 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -20,9 +20,10 @@ if (!defined('e107_INIT')) { exit; } if(!defined("USER_WIDTH")){ define("USER_WIDTH","width:95%;margin-left:auto;margin-right:auto"); } +$sc_style['LASTEDIT']['pre'] = "

[ ".LAN_29.' '; -$sc_style['LASTEDIT']['pre'] = "

[ ".LAN_29." "; -$sc_style['LASTEDIT']['post'] = " ]"; +$sc_style['LASTEDITBY']['pre'] = ' '.FORLAN_BY.' '; +$sc_style['LASTEDITBY']['post'] = ' ]
'; $sc_style['LEVEL']['pre'] = "
"; $sc_style['LEVEL']['post'] = "
"; @@ -129,7 +130,7 @@ $FORUMTHREADSTYLE = " {POLL} {POST} {ATTACHMENTS} - {LASTEDIT} + {LASTEDIT}{LASTEDITBY=link} {SIGNATURE} @@ -215,7 +216,7 @@ $FORUMREPLYSTYLE = " {POST} {ATTACHMENTS} - {LASTEDIT} + {LASTEDIT}{LASTEDITBY} {SIGNATURE}