1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-22 13:41:52 +02:00

Fixes - forum thread editing. Also pagination and redirection fixes. "Move Thread" reworked and integrated into forum_post.php

This commit is contained in:
Cameron 2015-05-09 13:22:27 -07:00
parent cec9f33168
commit 3f49076a2b
8 changed files with 298 additions and 53 deletions

@ -24,17 +24,16 @@ class forum_url // plugin-folder + '_url'
function config()
{
$config = array();
$config['index'] = array(
'regex' => '^forum/?$', // matched against url, and if true, redirected to 'redirect' below.
'sef' => 'forum', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}forum/forum.php', // file-path of what to load when the regex returns true.
$config['post'] = array(
'regex' => '^forum/post/?',
'sef' => 'forum/post/',
'redirect' => '{e_PLUGIN}forum/forum_post.php',
);
$config['topic'] = array(
'regex' => '^forum/(.*)/(\d*)-([\w-]*)/?\??(.*)',
'sef' => 'forum/{forum_sef}/{thread_id}-{thread_sef}',
'sef' => 'forum/{forum_sef}/{thread_id}-{thread_sef}/',
'redirect' => '{e_PLUGIN}forum/forum_viewtopic.php?id=$2&$4'
);
@ -46,6 +45,15 @@ class forum_url // plugin-folder + '_url'
'legacy' => '{e_PLUGIN}forum/forum_viewforum.php?id={forum_id}'
);
$config['index'] = array(
'regex' => '^forum/?$', // matched against url, and if true, redirected to 'redirect' below.
'sef' => 'forum', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}forum/forum.php', // file-path of what to load when the regex returns true.
);
return $config;
}

@ -767,7 +767,7 @@ class e107forum
$oldForumId = $threadInfo['thread_forum_id'];
//Move thread to new forum, changing thread title if needed
if($threadTitle)
if(!empty($threadTitle))
{
if($titleType == 0)
@ -778,9 +778,10 @@ class e107forum
else
{
//Replace title
$threadTitle = ", thread_name = '{$threadTitle}'";
$threadTitle = ", thread_name = '{$threadTitle}', thread_sef='".eHelper::title2sef($threadTitle,'dashl')."' ";
}
}
$sql->update('forum_thread', "thread_forum_id={$newForumId} {$threadTitle} WHERE thread_id={$threadId}");
//Move all posts to new forum
@ -892,7 +893,7 @@ class e107forum
if('post' === $start)
{
$qry = '
SELECT u.user_name, t.thread_active, t.thread_datestamp, t.thread_name, t.thread_user, t.thread_id, p.* FROM `#forum_post` AS p
SELECT u.user_name, t.thread_active, t.thread_datestamp, t.thread_name, t.thread_sef, t.thread_user, t.thread_id, 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;

@ -69,6 +69,10 @@ if (isset($_POST['deletepollconfirm']))
$url = e_PLUGIN."forum/forum_viewtopic.php?".$thread_id;
}
// Moved to forum_post.php
/*
if (isset($_POST['move']))
{
// print_a($_POST);
@ -107,6 +111,12 @@ if (isset($_POST['movecancel']))
$url = $e107::getUrl()->create('forum/forum/view', 'id='.$postInfo[0]['post_forum']);// XXX _URL_ thread name
}
*/
if ($message)
{
$text = "<div style='text-align:center'>".$message."
@ -132,21 +142,11 @@ if ($action == "delete_poll")
require_once(FOOTERF);
exit;
}
/*
if ($action == 'move')
{
$postInfo = $forum->postGet($id, 0, 1);
/*
* <form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
*/
$frm = e107::getForm();
$qry = "
@ -213,5 +213,10 @@ if ($action == 'move')
$ns->tablerender(LAN_FORUM_5019, $text);
}
*/
require_once(FOOTERF);
?>

@ -10,7 +10,14 @@
*
*/
require_once('../../class2.php');
if(!defined('e107_INIT'))
{
require_once('../../class2.php');
}
define('NAVIGATION_ACTIVE','forum'); // ??
$e107 = e107::getInstance();
@ -39,6 +46,9 @@ class forum_post_handler
function __construct()
{
$this->checkForumJump();
require_once(e_PLUGIN.'forum/forum_class.php'); // includes LAN file.
@ -52,10 +62,25 @@ class forum_post_handler
define('MODERATOR', USER && $this->forumObj->isModerator(USERID));
$this->data = $this->processGet();
$this->checkPerms($this->data['forum_id']);
$this->processPosted();
$this->renderForm();
if($this->action == 'move')
{
$this->renderFormMove();
}
else
{
$this->renderForm();
}
if(E107_DEBUG_LEVEL > 0)
{
e107::getMessage()->addInfo(print_a($this->data,true));
echo e107::getMessage()->render();
}
}
@ -70,7 +95,9 @@ class forum_post_handler
if (!e_QUERY || empty($_GET['id']))
{
header('Location:'.e107::getUrl()->create('forum/forum/main', array(), 'full=1&encode=0'));
$url = e107::url('forum','index',null,'full');
e107::getRedirect()->go($url);
// header('Location:'.e107::getUrl()->create('forum/forum/main', array(), 'full=1&encode=0'));
exit;
}
@ -101,6 +128,7 @@ class forum_post_handler
break;
case 'edit':
case 'move':
case 'quote':
$postInfo = $this->forumObj->postGet($this->post, 'post');
$forumInfo = $this->forumObj->forumGet($postInfo['post_forum']);
@ -111,7 +139,9 @@ class forum_post_handler
break;
default:
header("Location:".e107::getUrl()->create('forum/forum/main', array(), 'full=1&encode=0'));
$url = e107::url('forum','index',null,'full');
e107::getRedirect()->go($url);
// header("Location:".e107::getUrl()->create('forum/forum/main', array(), 'full=1&encode=0'));
exit;
}
}
@ -138,6 +168,11 @@ class forum_post_handler
$this->updateThread();
}
if(!empty($_POST['move_thread']))
{
$this->moveThread($_POST);
}
if(isset($_POST['update_reply']))
{
$this->updateReply();
@ -148,12 +183,14 @@ class forum_post_handler
$this->renderPreview();
}
if (isset($_POST['submitpoll']))
if(isset($_POST['submitpoll']))
{
$this->submitPoll();
}
}
@ -285,6 +322,110 @@ class forum_post_handler
}
function renderFormMove()
{
if(!deftrue('MODERATOR'))
{
return;
}
$frm = e107::getForm();
$sql = e107::getDb();
$tp = e107::getParser();
$ns = e107::getRender();
$qry = "
SELECT f.forum_id, f.forum_name, fp.forum_name AS forum_parent, sp.forum_name AS sub_parent
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id
LEFT JOIN `#forum` AS sp ON f.forum_sub = sp.forum_id
WHERE f.forum_parent != 0
ORDER BY f.forum_parent ASC, f.forum_sub, f.forum_order ASC
";
$fList = $sql->retrieve($qry,true);
$opts = array();
$currentName = "";
foreach($fList as $f)
{
if(substr($f['forum_name'], 0, 1) != '*')
{
$f['sub_parent'] = ltrim($f['sub_parent'], '*');
$for_name = $f['forum_parent'].' &gg; ';
$for_name .= ($f['sub_parent'] ? $f['sub_parent'].' &gg; ' : '');
$for_name .= $f['forum_name'];
if($this->data['forum_id'] == $f['forum_id'])
{
$for_name .= " (Current)";
$currentName = $for_name;
continue;
}
$id = $f['forum_id'];
$opts[$id] = $for_name;
}
}
$text = "
<form class='forum-horizontal' method='post' action='".e_REQUEST_URI."'>
<div>
<table class='table table-striped' style='".ADMIN_WIDTH."'>
<tr>
<td>".LAN_FORUM_3011.": </td>
<td>
".$tp->toHTML($this->data['thread_name'],true)."
</td>
</tr>
<tr><td></td>
<td><div class='alert alert-warning'>".$tp->toHTML($this->data['post_entry'], true)."</div></td></tr>
<tr>
<td>".LAN_FORUM_5019.": </td>
<td>".$frm->select('forum_move', $opts, $this->data['forum_id'], 'required=1', $currentName)."
</td>
</tr>
<tr>
<td >".LAN_FORUM_5026."</td>
<td><div class='radio'>
".$frm->radio('rename_thread','none',true, 'label='.LAN_FORUM_5022)."
</div>
<div class='radio'>
".$frm->radio('rename_thread', 'add', false, array('label'=> $tp->lanVars(LAN_FORUM_5024,'<b> ['.LAN_FORUM_5021.']</b> '))). "
</div>
<div class='radio'>".$frm->radio('rename_thread','rename', false, array('label'=>LAN_FORUM_5025))."
".$frm->text('newtitle', $tp->toForm($this->data['thread_name'], 250))."
</div>
</div></td>
</tr>
</table>
<div class='center'>
<input class='btn btn-primary button' type='submit' name='move_thread' value='".LAN_FORUM_5019."' />
<a class='btn btn-default button' href='".e_REFERER_SELF."' >".LAN_CANCEL."</a>
</div>
</div>
</form>";
// $threadName = $tp->toHTML($this->data['thread_name'], true);
// $threadText = ;
// $text .= "<h3>".$threadName."</h3><div>".$threadText."</div>"; // $e107->ns->tablerender(, ), '', true).$ns->tablerender('', $text, '', true);
$ns->tablerender(LAN_FORUM_5019, $text);
}
function renderForm()
{
@ -301,15 +442,6 @@ class forum_post_handler
}
if(E107_DEBUG_LEVEL > 0)
{
e107::getMessage()->addInfo(print_a($data,true));
echo e107::getMessage()->render();
}
require_once(FOOTERF);
exit;
}
@ -403,7 +535,7 @@ class forum_post_handler
$ns->tablerender(LAN_FORUM_3005, $text);
/*
if ($this->action == 'edit')
{
if ($_POST['subject'])
@ -420,7 +552,7 @@ class forum_post_handler
{
$action = 'rp';
$eaction = false;
}
}*/
}
@ -582,13 +714,16 @@ class forum_post_handler
$threadLink = e107::getUrl()->create('forum/thread/last', $postInfo);
$forumLink = e107::getUrl()->create('forum/forum/view', $forumInfo);
// $threadLink = e107::getUrl()->create('forum/thread/last', $postInfo);
// $forumLink = e107::getUrl()->create('forum/forum/view', $forumInfo);
$threadLink = e107::url('forum','topic',$this->data,'full')."&amp;last=1";
$forumLink = e107::url('forum', 'forum', $this->data);
if ($this->forumObj->prefs->get('redirect'))
{
header('location:'.e107::getUrl()->create('forum/thread/last', $postInfo, array('encode' => false, 'full' => true)));
e107::getRedirect()->go($threadLink);
// header('location:'.e107::getUrl()->create('forum/thread/last', $postInfo, array('encode' => false, 'full' => true)));
exit;
}
else
@ -618,6 +753,50 @@ class forum_post_handler
}
function moveThread($posted)
{
if(!deftrue('MODERATOR'))
{
return;
}
$tp = e107::getParser();
$mes = e107::getMessage();
$newThreadTitle = '';
$newThreadTitleType = 0;
if($posted['rename_thread'] == 'add')
{
$newThreadTitle = '['.LAN_FORUM_5021.']';
}
elseif($posted['rename_thread'] == 'rename' && trim($posted['newtitle']) != '')
{
$newThreadTitle = $tp->toDB($posted['newtitle']);
$newThreadTitleType = 1;
}
$threadId = intval($_GET['id']);
$toForum = $posted['forum_move'];
$this->forumObj->threadMove($threadId, $toForum, $newThreadTitle, $newThreadTitleType);
$message = LAN_FORUM_5005."<br />";// XXX _URL_ thread name
$url = e107::url('forum','topic', $this->data);
$text = "<a class='btn btn-primary' href='".$url."'>".LAN_FORUM_5007."</a>";
$mes->addSuccess($message.$text);
echo $mes->render();
// $ns->tablerender(LAN_FORUM_5008, $text);
}
function updateThread()
{
@ -664,10 +843,15 @@ class forum_post_handler
e107::getCache()->clear('newforumposts');
$url = e107::getUrl()->create('forum/thread/post', array('name'=>$threadVals['thread_name'], 'id' => $this->data['post_id'], 'thread' => $this->data['post_thread']), array('encode'=>false));
$url = e107::url('forum','topic',$this->data);
header('location:'.$url);
e107::getRedirect()->go($url);
exit;
// $url = e107::getUrl()->create('forum/thread/post', array('name'=>$threadVals['thread_name'], 'id' => $this->data['post_id'], 'thread' => $this->data['post_thread']), array('encode'=>false));
// header('location:'.$url);
// exit;
}
@ -701,8 +885,12 @@ class forum_post_handler
$this->forumObj->postUpdate($this->data['post_id'], $postVals);
e107::getCache()->clear('newforumposts');
$url = e107::getUrl()->create('forum/thread/post', "id={$this->data['post_id']}", 'encode=0&full=1'); // XXX what data is available, find thread name
// $url = e107::url('forum','topic',$this->data,true)."&f=post"; //FIXME
header('location:'.$url);
exit;
@ -833,8 +1021,33 @@ class forum_post_handler
require_once(HEADERF);
new forum_post_handler;
require_once(FOOTERF);
exit;
require_once(e_PLUGIN.'forum/forum_class.php');
$forum = new e107forum();

@ -247,8 +247,10 @@ if ($thread->pages > 1)
if(!$thread->page) $thread->page = 1;
// $url = rawurlencode(e107::getUrl()->create('forum/thread/view', array('name' => $thread->threadInfo['thread_name'], 'id' => $thread->threadId, 'page' => '[FROM]')));
$url = e_REQUEST_SELF."?p=[FROM]"; // SEF URL Friendly.
$parms = "total={$thread->pages}&type=page&current={$thread->page}&url=".$url."&caption=off&tmpl=default&navcount=4&glyphs=1";
// $url = e_REQUEST_SELF."?p=[FROM]"; // SEF URL Friendly.
$url = e107::url('forum','topic', $thread->threadInfo)."&amp;p=[FROM]";
$parms = "total={$thread->pages}&type=page&current={$thread->page}&url=".urlencode($url)."&caption=off&tmpl=default&navcount=4&glyphs=1";
//XXX FIXME - pull-down template not practical here. Can we force another?
@ -758,6 +760,8 @@ class e107ForumThread
$this->message = LAN_FORUM_2012;
break;
// TODO Move to form_post.php
case 'report':
$threadId = (int)$_GET['id'];
$postId = (int)$_GET['post'];

@ -265,7 +265,7 @@ define("LAN_FORUM_5010", "Confirm Delete Forum Post"); // LAN_FORUM_5010
define("LAN_FORUM_5019", "Move Thread"); // LAN_FORUM_5019
define("LAN_FORUM_5021", "moved"); // LAN_FORUM_5021
define("LAN_FORUM_5022", "Do not rename thread title"); // LAN_FORUM_5022
define("LAN_FORUM_5024", "to title"); // LAN_FORUM_5024
define("LAN_FORUM_5024", "Add [x] prefix to the subject/title"); // LAN_FORUM_5024
define("LAN_FORUM_5025", "Rename to:"); // LAN_FORUM_5025
define("LAN_FORUM_5026", "Rename thread options:"); // LAN_FORUM_5026

@ -111,7 +111,7 @@ class plugin_forum_post_shortcodes extends e_shortcode
elseif($this->var['action'] == 'edit')
{
$_POST['subject'] = $this->var['thread_name'];
if($this->var['thread_user'] != USERID)
if($this->var['thread_user'] != USERID && !deftrue('MODERATOR'))
{
$opts['disabled'] = 1;
}
@ -152,7 +152,9 @@ class plugin_forum_post_shortcodes extends e_shortcode
$post = preg_replace('#\[hide].*?\[/hide]#s', '', trim($this->var['post_entry']));
$quoteName = ($this->var['user_name'] ? $this->var['user_name'] : $this->var['post_user_anon']);
$text = $tp->toText("[quote={$quoteName}]\n".$post."\n[/quote]\n",true);
$text .= "<br /><br />";
$text .= "\n\n";
// $text = $tp->toForm($text);
$this->var['action'] = 'rp';
}
elseif($this->var['action'] == 'edit')

@ -517,13 +517,19 @@ class plugin_forum_view_shortcodes extends e_shortcode
// Edit
if ( (USER && $this->postInfo['post_user'] == USERID && $this->thread->threadInfo['thread_active']))
{
$text .= "<li class='text-right'><a href='".e107::getUrl()->create('forum/thread/edit', array('id' => $this->postInfo['post_thread'], 'post'=>$this->postInfo['post_id']))."'>".LAN_EDIT." ".$tp->toGlyph('edit')."</a></li>";
$url = e107::url('forum','post')."?f=edit&amp;id=".$this->postInfo['post_thread']."&amp;post=".$this->postInfo['post_id'];
//$url = e107::getUrl()->create('forum/thread/edit', array('id' => $this->postInfo['post_thread'], 'post'=>$this->postInfo['post_id']));
$text .= "<li class='text-right'><a href='".$url."'>".LAN_EDIT." ".$tp->toGlyph('edit')."</a></li>";
}
if($this->forum->checkperm($this->postInfo['post_forum'], 'post'))
{
$text .= "<li class='text-right'><a href='".e107::getUrl()->create('forum/thread/quote', array('id' => $this->postInfo['post_thread'], 'post'=>$this->postInfo['post_id']))."'>".LAN_FORUM_2041." ".$tp->toGlyph('share-alt')."</a></li>";
$url = e107::url('forum','post')."?f=quote&amp;id=".$this->postInfo['post_thread']."&amp;post=".$this->postInfo['post_id'];
//$url = e107::getUrl()->create('forum/thread/quote', array('id' => $this->postInfo['post_thread'], 'post'=>$this->postInfo['post_id']));
$text .= "<li class='text-right'><a href='".$url."'>".LAN_FORUM_2041." ".$tp->toGlyph('share-alt')."</a></li>";
// $text .= "<li class='text-right'><a href='".e107::getUrl()->create('forum/thread/quote', array('id' => $this->postInfo['post_id']))."'>".LAN_FORUM_2041." ".$tp->toGlyph('share-alt')."</a></li>";
}
@ -536,7 +542,11 @@ class plugin_forum_view_shortcodes extends e_shortcode
if ((USER && $this->postInfo['post_user'] != USERID && $this->thread->threadInfo['thread_active']))
{
$text .= "<li class='text-right'><a href='".e107::getUrl()->create('forum/thread/edit', array('id' => $this->postInfo['post_thread'], 'post'=>$this->postInfo['post_id']))."'>".LAN_EDIT." ".$tp->toGlyph('edit')."</a></li>";
$url = e107::url('forum','post')."?f=edit&amp;id=".$this->postInfo['post_thread']."&amp;post=".$this->postInfo['post_id'];
// $url = e107::getUrl()->create('forum/thread/edit', array('id' => $this->postInfo['post_thread'], 'post'=>$this->postInfo['post_id']));
$text .= "<li class='text-right'><a href='".$url."'>".LAN_EDIT." ".$tp->toGlyph('edit')."</a></li>";
}
// only show delete button when post is not the initial post of the topic
@ -547,11 +557,13 @@ class plugin_forum_view_shortcodes extends e_shortcode
if ($type == 'thread')
{
$text .= "<li class='text-right'><a href='" . e107::getUrl()->create('forum/thread/move', array('id' => $this->postInfo['post_id']))."'>".LAN_FORUM_2042." ".$tp->toGlyph('move')."</a></a></li>";
$url = e107::url('forum','post')."?f=move&amp;id=".$this->postInfo['post_thread']."&amp;post=".$this->postInfo['post_id'];
// $url = e107::getUrl()->create('forum/thread/move', array('id' => $this->postInfo['post_id'], 'post'=>$this->postInfo['post_id']));
$text .= "<li class='text-right'><a href='" . $url."'>".LAN_FORUM_2042." ".$tp->toGlyph('move')."</a></a></li>";
}
else
else //TODO
{
$text .= "<li class='text-right'><a href='" . e107::getUrl()->create('forum/thread/split', array('id' => $this->postInfo['post_id']))."'>".LAN_FORUM_2043." ".$tp->toGlyph('cut')."</a></li>";
// $text .= "<li class='text-right'><a href='" . e107::getUrl()->create('forum/thread/split', array('id' => $this->postInfo['post_id'], 'post'=>$this->postInfo['post_id']))."'>".LAN_FORUM_2043." ".$tp->toGlyph('cut')."</a></li>";
}
}