diff --git a/e107_plugins/forum/e_url.php b/e107_plugins/forum/e_url.php index 2e6702acd..70554b95d 100644 --- a/e107_plugins/forum/e_url.php +++ b/e107_plugins/forum/e_url.php @@ -54,6 +54,10 @@ class forum_url // plugin-folder + '_url' 'sef' => 'forum/post/?f=move&id={thread_id}', ); + $config['split'] = array( + 'sef' => 'forum/post/?f=split&id={thread_id}&post={post_id}', + ); + $config['topic'] = array( 'regex' => 'forum\/([^\/]*)\/([\d]*)(?:\/|-)([\w-]*)/?\??(.*)', // 'regex' => '^forum/(.*)/(\d*)(?:-|/)([\w-]*)/?\??(.*)', diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index a9d3a8a7a..3b19c3530 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -825,12 +825,18 @@ class e107forum if($newThreadId = e107::getDb()->insert('forum_thread', $info)) { - - $postInfo['post_thread'] = $newThreadId; - - if(!$newPostId = $this->postAdd($postInfo, false)) + if($postInfo !== false) { - e107::getMessage()->addDebug("There was a problem: ".print_a($postInfo,true)); + $postInfo['post_thread'] = $newThreadId; + + if(!$newPostId = $this->postAdd($postInfo, false)) + { + e107::getMessage()->addDebug("There was a problem: ".print_a($postInfo,true)); + } + } + else + { + $newPostId = 0; } $this->threadMarkAsRead($newThreadId); @@ -1020,7 +1026,8 @@ class e107forum LIMIT {$start}, {$num} "; } - if($sql->gen($qry)) + + if($sql->gen($qry)!==false) { $ret = array(); while($row = $sql->fetch()) @@ -1269,7 +1276,9 @@ class e107forum $sql = e107::getDb(); $tp = e107::getParser(); - $sql2 = new db; + $sql2 = e107::getDb('sql2'); + + if ($type == 'thread') { $id = (int)$id; @@ -1285,15 +1294,20 @@ class e107forum $tmp['thread_lastuser'] = 0; $tmp['thread_lastuser_anon'] = ($lpInfo['post_user_anon'] ? $lpInfo['post_user_anon'] : 'Anonymous'); } + $tmp['thread_lastpost'] = $lpInfo['post_datestamp']; $info = array(); $info['data'] = $tmp; // $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread']; $info['WHERE'] = 'thread_id = '.$id; + $sql->update('forum_thread', $info); return $lpInfo; } + + + if ($type == 'forum') { if ($id == 'all') @@ -2032,6 +2046,22 @@ class e107forum } + /** + * @param $threadID + * @return int + */ + function threadUpdateCounts($threadID) + { + $sql = e107::getDb(); + + $replies = $sql->count('forum_post', '(*)', 'WHERE post_thread='.$threadID); + + return $sql->update('forum_thread', "thread_total_replies={$replies} WHERE thread_id=".$threadID); + + } + + + function getUserCounts() { diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index 8c048e5b1..49ae93e4d 100644 --- a/e107_plugins/forum/forum_post.php +++ b/e107_plugins/forum/forum_post.php @@ -71,8 +71,13 @@ class forum_post_handler $this->data = $this->processGet(); + $this->checkPerms($this->data['forum_id']); - $this->processPosted(); + + if($this->processPosted() === false) + { + return false; + } if($this->action == 'report') { @@ -82,6 +87,10 @@ class forum_post_handler { $this->renderFormMove(); } + elseif($this->action == 'split') + { + $this->renderFormSplit(); + } else { $this->renderForm(); @@ -141,6 +150,7 @@ class forum_post_handler case 'edit': case "quote": case "report": + case 'split': $postInfo = $this->forumObj->postGet($this->post, 'post'); $forumInfo = $this->forumObj->forumGet($postInfo['post_forum']); $data = array_merge($postInfo ,$forumInfo); @@ -193,6 +203,12 @@ class forum_post_handler $this->moveThread($_POST); } + if(!empty($_POST['split_thread'])) + { + $this->splitThread($_POST); + return false; + } + if(isset($_POST['update_reply'])) { $this->updateReply(); @@ -213,7 +229,7 @@ class forum_post_handler $this->submitReport(); } - + return true; } @@ -650,7 +666,7 @@ class forum_post_handler } - function renderFormMove() + private function renderFormSplit() { if(!deftrue('MODERATOR')) { @@ -663,6 +679,65 @@ class forum_post_handler $tp = e107::getParser(); $ns = e107::getRender(); + $sc = e107::getScBatch('post', 'forum')->setScVar('forum', $this->forumObj)->setScVar('threadInfo', vartrue($this->data))->setVars($this->data); + $text = $tp->parseTemplate("
{FORUM_POST_BREADCRUMB}
",true,$sc); + + + + $text .= e107::getMessage()->setTitle("Warning!",E_MESSAGE_ERROR)->addError("This post, and every post below it will be moved into a new thread/topic.")->render(); + + $text .= " +
+
+ + + + + + + + + + + + + +
".LAN_FORUM_3050."
".$tp->toHTML($this->data['post_entry'], true)."
".LAN_FORUM_3051.": ".$this->forumSelect('forum_split',$this->data['forum_id'], 'required=1')." + +
".LAN_FORUM_3042." + + ".$frm->text('new_thread_title', $tp->toForm($this->data['thread_name'], 250))." + +
+ + +
+
"; + + + $ns->tablerender(LAN_FORUM_3052, $text); + + + } + + + + + + /** + * Render a drop-down list of forums. + * @param $name + * @param mixed $curVal + * @param string|array $opts + * @return string + */ + private function forumSelect($name, $curVal=null, $opts=null) + { + $sql = e107::getDb(); + $qry = " SELECT f.forum_id, f.forum_name, fp.forum_name AS forum_parent, sp.forum_name AS sub_parent FROM `#forum` AS f @@ -674,7 +749,6 @@ class forum_post_handler $fList = $sql->retrieve($qry,true); - $opts = array(); $currentName = ""; @@ -700,6 +774,25 @@ class forum_post_handler } + return e107::getForm()->select($name, $opts, $curVal, $opts, $currentName); + } + + + /** + * Render Move Form. + */ + private function renderFormMove() + { + if(!deftrue('MODERATOR')) + { + return; + } + + $frm = e107::getForm(); + $tp = e107::getParser(); + $ns = e107::getRender(); + + $text = "
@@ -715,7 +808,7 @@ class forum_post_handler ".LAN_FORUM_5019.": - ".$frm->select('forum_move', $opts, $this->data['forum_id'], 'required=1', $currentName)." + ".$this->forumSelect('forum_move', $this->data['forum_id'], 'required=1')." @@ -1171,12 +1264,12 @@ class forum_post_handler } - function moveThread($posted) + private function moveThread($posted) { if(!deftrue('MODERATOR')) { - return; + return false; } $tp = e107::getParser(); @@ -1215,6 +1308,73 @@ class forum_post_handler + function splitThread($post) + { + if(!deftrue('MODERATOR')) + { + return false; + } + + $threadInfo = array(); + $threadInfo['thread_sticky'] = 0; + $threadInfo['thread_name'] = $post['new_thread_title']; + $threadInfo['thread_forum_id'] = (!empty($post['forum_split'])) ? intval($post['forum_split']) : $this->data['post_forum']; + $threadInfo['thread_active'] = 1; + $threadInfo['thread_datestamp'] = $this->data['post_datestamp']; + $threadInfo['thread_views'] = 0; + $threadInfo['thread_user'] = $this->data['post_user']; + + + print_a($this->data); + + if($ret = $this->forumObj->threadAdd($threadInfo, false)) + { + e107::getMessage()->addSuccess("Created new thread #".$ret['threadid']); + $update = array( + 'post_thread' => $ret['threadid'], + 'post_forum' => $threadInfo['thread_forum_id'], + 'WHERE' => "post_thread = ".$this->data['post_thread']." AND post_id >= ".$this->data['post_id'] + + ); + + if($result = e107::getDb()->update('forum_post', $update)) + { + + e107::getMessage()->addSuccess("Moved ".$result." posts to topic #". $ret['threadid']); + + + // Update old thread. + + if(!$this->forumObj->threadUpdateCounts($this->data['post_thread'])) + { + e107::getMessage()->addError("Couldn't update thread replies for original topic #". $this->data['post_thread']); + } + + if(!$this->forumObj->forumUpdateLastpost('thread',$this->data['post_thread'])) + { + e107::getMessage()->addError("Couldn't update last post user for original topic #". $this->data['post_thread']); + + } + + // Update new thread. + + if(!$this->forumObj->threadUpdateCounts($ret['threadid'])) + { + e107::getMessage()->addError("Couldn't update thread replies for #". $ret['threadid']); + } + + if(!$this->forumObj->forumUpdateLastpost('thread',$ret['threadid'])) + { + e107::getMessage()->addError("Couldn't update last post user for #". $ret['threadid']); + + } + + } + + } + } + + function updateThread() { diff --git a/e107_plugins/forum/forum_viewforum.php b/e107_plugins/forum/forum_viewforum.php index 824878e31..c939cf3f7 100644 --- a/e107_plugins/forum/forum_viewforum.php +++ b/e107_plugins/forum/forum_viewforum.php @@ -883,6 +883,7 @@ function fadminoptions($thread_info) //FIXME - not fully working. $moveUrl = e107::url('forum','move', $thread_info); + $splitUrl = e107::url('forum','split', $thread_info); $lockUnlock = ($thread_info['thread_active'] ) ? 'lock' : 'unlock'; $stickUnstick = ($thread_info['thread_sticky'] == 1) ? 'unstick' : 'stick'; @@ -904,6 +905,12 @@ function fadminoptions($thread_info) $text .= "
  • Move ".$tp->toGlyph('move')."
  • "; + if(e_DEVELOPER) + { +// $text .= "
  • Split ".$tp->toGlyph('scissors')."
  • "; +// print_a($thread_info); + } + /* $text .= "
  • Delete
  • "; diff --git a/e107_plugins/forum/languages/English/English_front.php b/e107_plugins/forum/languages/English/English_front.php index 6ab170a8f..46cf85621 100644 --- a/e107_plugins/forum/languages/English/English_front.php +++ b/e107_plugins/forum/languages/English/English_front.php @@ -219,6 +219,7 @@ define("LAN_FORUM_3038", "Normal"); // LAN_1 define("LAN_FORUM_3039", "Deactivate emoticons for this post"); // LAN_FORUMPOST_EMOTES define("LAN_FORUM_3040", "Enable/disable email tracking (email sent when reply is posted)"); // LAN_380 define("LAN_FORUM_3041", "Enable/disable tracking of this topic"); +define("LAN_FORUM_3042", "New Topic/Subject"); // missing 41-21 // forum_posted_template @@ -229,7 +230,9 @@ define("LAN_FORUM_3046", "Click here to view your poll"); // LAN_414 define("LAN_FORUM_3047", "Your message has been successfully posted."); // LAN_324 define("LAN_FORUM_3048", "Click here to view your message"); // LAN_325 define("LAN_FORUM_3049", "Your reply has been successfully posted."); // LAN_415 - +define("LAN_FORUM_3050", "Split point"); +define("LAN_FORUM_3051", "New location"); +define("LAN_FORUM_3052", "Split Thread"); // forum_icons_template diff --git a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php index 4eb890397..27b8a5367 100644 --- a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php @@ -604,9 +604,9 @@ class plugin_forum_view_shortcodes extends e_shortcode $url = e107::url('forum','move', array('thread_id'=>$this->postInfo['post_thread'])); $text .= "
  • ".LAN_FORUM_2042." ".$tp->toGlyph('move')."
  • "; } - else //TODO + elseif(e_DEVELOPER ===true) //TODO { - // $text .= "
  • $this->postInfo['post_id'], 'post'=>$this->postInfo['post_id']))."'>".LAN_FORUM_2043." ".$tp->toGlyph('cut')."
  • "; + $text .= "
  • $this->postInfo['post_thread'], 'post_id' => $this->postInfo['post_id']))."'>".LAN_FORUM_2043." ".$tp->toGlyph('cut')."
  • "; } } diff --git a/e107_plugins/forum/templates/forum_viewtopic_template.php b/e107_plugins/forum/templates/forum_viewtopic_template.php index 26ef029b3..ea8238359 100644 --- a/e107_plugins/forum/templates/forum_viewtopic_template.php +++ b/e107_plugins/forum/templates/forum_viewtopic_template.php @@ -331,7 +331,7 @@ $FORUM_VIEWTOPIC_TEMPLATE['thread'] = "