1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 20:57:26 +02:00

thread and post deletion now working

This commit is contained in:
mcfly
2008-12-11 16:02:05 +00:00
parent e50dd8d467
commit ca57d71401
8 changed files with 181 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
<?php <?php
// $Id: thread.php,v 1.4 2008-12-07 04:16:38 mcfly_e107 Exp $ // $Id: thread.php,v 1.5 2008-12-11 16:02:05 mcfly_e107 Exp $
function url_forum_thread($parms) function url_forum_thread($parms)
{ {
switch($parms['func']) switch($parms['func'])
@@ -34,6 +34,10 @@ function url_forum_thread($parms)
return e_PLUGIN_ABS."forum/forum_post.php?f=edit&id={$parms['id']}"; return e_PLUGIN_ABS."forum/forum_post.php?f=edit&id={$parms['id']}";
break; break;
case 'move':
return e_PLUGIN_ABS."forum/forum_post.php?f=move&id={$parms['id']}";
break;
case 'quote': case 'quote':
return e_PLUGIN_ABS."forum/forum_post.php?f=quote&id={$parms['id']}"; return e_PLUGIN_ABS."forum/forum_post.php?f=quote&id={$parms['id']}";
break; break;

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
| $Revision: 1.22 $ | $Revision: 1.23 $
| $Date: 2008-12-10 21:00:48 $ | $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $ | $Author: mcfly_e107 $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -39,7 +39,7 @@ class e107forum
$this->fieldTypes['forum_thread']['thread_lastuser'] = 'int'; $this->fieldTypes['forum_thread']['thread_lastuser'] = 'int';
$this->fieldTypes['forum_thread']['thread_s'] = 'int'; $this->fieldTypes['forum_thread']['thread_s'] = 'int';
$this->fieldTypes['forum_thread']['thread_forum_id'] = 'int'; $this->fieldTypes['forum_thread']['thread_forum_id'] = 'int';
$this->fieldTypes['forum_thread']['thread_active'] = 'int'; $this->fieldTypes['forum_thread']['thread_active'] = 'int';
$this->fieldTypes['forum_thread']['thread_datestamp'] = 'int'; $this->fieldTypes['forum_thread']['thread_datestamp'] = 'int';
$this->fieldTypes['forum_thread']['thread_views'] = 'int'; $this->fieldTypes['forum_thread']['thread_views'] = 'int';
$this->fieldTypes['forum_thread']['thread_replies'] = 'int'; $this->fieldTypes['forum_thread']['thread_replies'] = 'int';
@@ -356,11 +356,71 @@ class e107forum
$viewed = $tmp['plugin_forum_user_viewed']; $viewed = $tmp['plugin_forum_user_viewed'];
unset($tmp); unset($tmp);
} }
return explode(',', $viewed); return explode(',', $viewed);
} }
function postDeleteAttachments($type = 'post', $id='', $f='')
{
$e107 = e107::getInstance();
$id = (int)$id;
if(!$id) { return; }
if($type == 'thread')
{
if(!$e107->sql->db_Select('forum_post', 'post_id', 'post_attachments IS NOT NULL'))
{
return true;
}
$postList = array();
while($row = $e107->sql->dbFetch(MYSQL_ASSOC))
{
$postList[] = $row['post_id'];
}
foreach($postList as $postId)
{
$this->postDeleteAttachment('post', $postId);
}
}
if($type == 'post')
{
if(!$e107->sql->db_Select('forum_post', 'post_attachments', 'post_id = '.$id))
{
return true;
}
$tmp = $e107->sql->db_Fetch(MYSQL_ASSOC);
$attachments = explode(',', $tmp['post_attachments']);
foreach($attachments as $k => $a)
{
$info = explode('*', $a);
if('' == $f || $info[1] == $f)
{
$fname = e_PLUGIN."forum/attachments/{$info[1]}";
@unlink($fname);
//If attachment is an image and there is a thumb, remove it
if('img' == $info[0] && $info[2])
{
$fname = e_PLUGIN."forum/attachments/thumb/{$info[2]}";
@unlink($fname);
}
}
unset($attachments[$k]);
}
$tmp = array();
if(count($attachments))
{
$tmp['post_attachments'] = implode(',', $attachments);
}
else
{
$tmp['post_attachments'] = '_NULL_';
}
$tmp['_FILE_TYPES']['post_attachments'] = 'escape';
$tmp['WHERE'] = 'post_id = '.$id;
$e107->sql->db_update('forum_post', $tmp);
}
}
function thread_postnum($thread_id) function thread_postnum($thread_id)
{ {
global $sql; global $sql;
@@ -388,23 +448,24 @@ class e107forum
$sql2 = new db; $sql2 = new db;
if ($type == 'thread') if ($type == 'thread')
{ {
$id = intval($id); $id = (int)$id;
$thread_info = $this->thread_get_lastpost($id); $lpInfo = $this->threadGetLastpost($id);
list($uid, $uname) = explode(".", $thread_info['thread_user'], 2); $tmp = array();
if ($thread_info) if($lpInfo['user_name'])
{ {
if($thread_info['user_name'] != "") $tmp['thread_lastuser'] = $lpInfo['post_user'];
{ $tmp['thread_lastuser_anon'] = '_NULL_';
$thread_lastuser = $uid.".".$thread_info['user_name'];
}
else
{
$tmp = explode(chr(1), $thread_info['thread_user']);
$thread_lastuser = $tmp[0];
}
$sql->db_Update('forum_t', "thread_lastpost = ".intval($thread_info['thread_datestamp']).", thread_lastuser = '".$tp -> toDB($thread_lastuser, true)."' WHERE thread_id = ".$id);
} }
return $thread_info; else
{
$tmp['thread_lastuser'] = 0;
$tmp['thread_lastuser_anon'] = $lpInfo['post_user_anon'];
}
$tmp['thread_lastpost'] = $lpInfo['post_datestamp'];
$tmp['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$sql->db_Update('forum_thread', $tmp);
return $lpInfo;
} }
if ($type == 'forum') { if ($type == 'forum') {
if ($id == 'all') if ($id == 'all')
@@ -753,29 +814,21 @@ class e107forum
return $ret; return $ret;
} }
function thread_get_lastpost($forum_id) function threadGetLastpost($id)
{ {
$forum_id = intval($forum_id); $e107 = e107::getInstance();
global $sql; $id = (int)$id;
if ($sql->db_Count('forum_t', '(*)', "WHERE thread_parent = {$forum_id} "))
{
$where = "WHERE t.thread_parent = $forum_id ";
}
else
{
$where = "WHERE t.thread_id = $forum_id ";
}
$qry = " $qry = "
SELECT t.thread_user, t.thread_datestamp, u.user_name FROM #forum_t AS t SELECT p.post_user, p.post_user_anon, p.post_datestamp, p.post_thread, u.user_name FROM `#forum_post` AS p
LEFT JOIN #user AS u ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id LEFT JOIN `#user` AS u ON u.user_id = p.post_user
{$where} WHERE p.post_thread = {$id}
ORDER BY t.thread_datestamp DESC LIMIT 0,1 ORDER BY p.post_datestamp DESC LIMIT 0,1
"; ";
if ($sql->db_Select_gen($qry)) if ($e107->sql->db_Select_gen($qry))
{ {
return $sql->db_Fetch(MYSQL_ASSOC); return $e107->sql->db_Fetch(MYSQL_ASSOC);
} }
return FALSE; return false;
} }
// function forum_get_topic_count($forum_id) // function forum_get_topic_count($forum_id)

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_mod.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_mod.php,v $
| $Revision: 1.3 $ | $Revision: 1.4 $
| $Date: 2008-12-09 21:46:14 $ | $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $ | $Author: mcfly_e107 $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -33,6 +33,7 @@ function forum_thread_moderate($p)
if (preg_match("#(.*?)_(\d+)_x#", $key, $matches)) if (preg_match("#(.*?)_(\d+)_x#", $key, $matches))
{ {
$act = $matches[1]; $act = $matches[1];
// print_a($matches); return;
$id = (int)$matches[2]; $id = (int)$matches[2];
switch ($act) switch ($act)
@@ -61,6 +62,10 @@ function forum_thread_moderate($p)
return forumDeleteThread($id); return forumDeleteThread($id);
break; break;
case 'deletePost':
return forumDeletePost($id);
break;
} }
} }
} }
@@ -103,4 +108,47 @@ function forumDeleteThread($threadId)
} }
} }
function forumDeletePost($postId)
{
$postId = (int)$postId;
require_once (e_PLUGIN.'forum/forum_class.php');
$e107 = e107::getInstance();
$f = &new e107forum;
if(!$e107->sql->db_Select('forum_post', '*', 'post_id = '.$postId))
{
echo 'NOT FOUND!'; return;
}
$row = $e107->sql->db_Fetch(MYSQL_ASSOC);
//decrement user post counts
if ($row['post_user'])
{
$e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_id='.$row['post_user']);
}
//delete attachments if they exist
if($row['post_attachments'])
{
$f->postDeleteAttachments('post', $postId);
}
// delete post
$e107->sql->db_Delete('forum_post', 'post_id='.$postId);
// update thread with correct reply counts
$e107->sql->db_Update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']);
// update forum with correct thread/reply counts
$e107->sql->db_Update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']);
// update thread lastpost info
$f->forumUpdateLastpost('thread', $row['post_thread']);
// update forum lastpost info
$f->forumUpdateLastpost('forum', $row['post_forum']);
return FORLAN_6.' and '.$threadInfo['thread_total_replies'].' '.FORLAN_7.'.';
}
?> ?>

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $
| $Revision: 1.28 $ | $Revision: 1.29 $
| $Date: 2008-12-10 15:29:31 $ | $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $ | $Author: mcfly_e107 $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -258,7 +258,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
} }
$postInfo['post_attachments'] = implode(',', $attachments); $postInfo['post_attachments'] = implode(',', $attachments);
} }
var_dump($uploadResult); // var_dump($uploadResult);
switch($action) switch($action)
{ {
@@ -576,7 +576,10 @@ function process_upload()
require_once(e_HANDLER.'resize_handler.php'); require_once(e_HANDLER.'resize_handler.php');
$orig_file = $upload['name']; $orig_file = $upload['name'];
$new_file = 'th_'.$orig_file; $new_file = 'th_'.$orig_file;
if(resize_image($attachmentDir.$orig_file, $attachmentDir.'thumb/'.$new_file, $pref['forum_maxwidth']))
$resizeDir = ($pref['forum_linkimg'] ? 'thumb/' : '');
if(resize_image($attachmentDir.$orig_file, $attachmentDir.$resizeDir.$new_file, $pref['forum_maxwidth']))
{ {
if($pref['forum_linkimg']) if($pref['forum_linkimg'])
{ {

View File

@@ -42,12 +42,16 @@ if($postInfo['post_attachments'])
case 'file': case 'file':
$txt .= IMAGE_attachment." <a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'>{$info[2]}</a><br />"; $txt .= IMAGE_attachment." <a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'>{$info[2]}</a><br />";
break; break;
case 'img': case 'img':
//if image has a thumb, show it and link to main //if image has a thumb, show it and link to main
if(isset($info[2])) if(isset($info[2]))
{ {
$txt .= "<a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'><img src='".e_PLUGIN_ABS."forum/attachments/thumb/{$info[2]}' alt='' /></a>"; $txt .= "<a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'><img src='".e_PLUGIN_ABS."forum/attachments/thumb/{$info[2]}' alt='' /></a>";
}
else
{
$txt .= "<img src='".e_PLUGIN_ABS."forum/attachments/{$info[1]}' alt='' />";
} }
} }
} }
@@ -212,7 +216,6 @@ if (USER && $postInfo['post_user'] == USERID && $threadInfo['thread_active'])
{ {
return "<a href='".$e107->url->getUrl('forum', 'thread', array('func' => 'edit', 'id' => $postInfo['post_id']))."'>".IMAGE_edit.'</a> '; return "<a href='".$e107->url->getUrl('forum', 'thread', array('func' => 'edit', 'id' => $postInfo['post_id']))."'>".IMAGE_edit.'</a> ';
} }
return '';
SC_END SC_END
SC_BEGIN QUOTEIMG SC_BEGIN QUOTEIMG

View File

@@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $
| $Revision: 1.11 $ | $Revision: 1.12 $
| $Date: 2008-12-09 21:46:14 $ | $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $ | $Author: mcfly_e107 $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -69,22 +69,6 @@ if (USER || USER != $threadInfo['thread_user'] || !$thread->noInc)
$forum->threadIncview($threadId); $forum->threadIncview($threadId);
} }
//print_a($postList);
//if(intval($thread_info['head']['thread_forum_id']) == 0)
//{
// require_once(HEADERF);
// $ns->tablerender(LAN_01, FORLAN_104, array('forum_viewtopic', '104'));
// require_once(FOOTERF);
// exit;
//}
//$forum_info = $forum->forum_get($thread_info['head']['thread_forum_id']);
//
//if (!check_class($forum_info['forum_class']) || !check_class($forum_info['parent_class'])) {
// header("Location:".e_PLUGIN."forum/forum.php");
// exit;
//}
define('e_PAGETITLE', LAN_01 . ' / ' . $e107->tp->toHTML($thread->threadInfo['forum_name'], true, 'no_hook, emotes_off') . " / " . $tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off')); define('e_PAGETITLE', LAN_01 . ' / ' . $e107->tp->toHTML($thread->threadInfo['forum_name'], true, 'no_hook, emotes_off') . " / " . $tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off'));
$modArray = $forum->forum_getmods($thread->threadInfo['forum_moderators']); $modArray = $forum->forum_getmods($thread->threadInfo['forum_moderators']);
define('MODERATOR', (USER && is_array($modArray) && in_array(USERID, array_keys($modArray)))); define('MODERATOR', (USER && is_array($modArray) && in_array(USERID, array_keys($modArray))));
@@ -286,7 +270,7 @@ else
echo "<script type=\"text/javascript\"> echo "<script type=\"text/javascript\">
function confirm_(mode, forum_id, thread_id, thread) { function confirm_(mode, forum_id, thread_id, thread) {
if (mode == 'thread') { if (mode == 'Thread') {
return confirm(\"" . $tp->toJS(LAN_409) . "\"); return confirm(\"" . $tp->toJS(LAN_409) . "\");
} else { } else {
return confirm(\"" . $tp->toJS(LAN_410) . " [ " . $tp->toJS(LAN_411) . "\" + thread + \" ]\"); return confirm(\"" . $tp->toJS(LAN_410) . " [ " . $tp->toJS(LAN_411) . "\" + thread + \" ]\");
@@ -297,30 +281,35 @@ require_once (FOOTERF);
function showmodoptions() function showmodoptions()
{ {
global $thread_id; global $thread, $postInfo;
global $thread_info;
global $forum_info; // var_dump($thread);
global $post_info; // var_dump($postInfo);
$forum_id = $forum_info['forum_id'];
if ($post_info['thread_parent'] == false) $e107 = e107::getInstance();
$forum_id = $thread->threadInfo['forum_id'];
if ($postInfo['thread_start'])
{ {
$type = 'thread'; $type = 'Thread';
$ret = "<form method='post' action='" . e_PLUGIN . "forum/forum_viewforum.php?{$forum_id}' id='frmMod_{$forum_id}_{$post_info['thread_id']}'>"; $ret = "<form method='post' action='" . $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => $postInfo['post_thread']))."' id='frmMod_{$postInfo['post_forum']}_{$postInfo['post_thread']}'>";
$delId = $postInfo['post_thread'];
} }
else else
{ {
$type = 'reply'; $type = 'Post';
$ret = "<form method='post' action='" . e_SELF . "?" . e_QUERY . "' id='frmMod_{$forum_id}_{$post_info['thread_id']}'>"; $ret = "<form method='post' action='" . e_SELF . '?' . e_QUERY . "' id='frmMod_{$postInfo['post_forum']}_{$postInfo['post_thread']}'>";
$delId = $postInfo['post_id'];
} }
$ret .= " $ret .= "
<div> <div>
<a href='" . e_PLUGIN . "forum/forum_post.php?edit.{$post_info['thread_id']}.{$topic_from}'>" . IMAGE_admin_edit . "</a> <a href='" . $e107->url->getUrl('forum', 'thread', array('func' => 'edit', 'id' => $postInfo['post_id']))."'>" . IMAGE_admin_edit . "</a>
<input type='image' " . IMAGE_admin_delete . " name='delete_{$post_info['thread_id']}' value='thread_action' onclick=\"return confirm_('{$type}', {$forum_id}, {$thread_id}, '{$post_info['user_name']}')\" /> <input type='image' " . IMAGE_admin_delete . " name='delete{$type}_{$delId}' value='thread_action' onclick=\"return confirm_('{$type}', {$postInfo['post_forum']}, {$postInfo['post_thread']}, '{$postInfo['user_name']}')\" />
<input type='hidden' name='mod' value='1'/>
"; ";
if ($type == 'thread') if ($type == 'Thread')
{ {
$ret .= "<a href='" . e_PLUGIN . "forum/forum_conf.php?move.{$thread_id}'>" . IMAGE_admin_move2 . "</a>"; $ret .= "<a href='" . $e107->url->getUrl('forum', 'thread', array('func' => 'move', 'id' => $postInfo['post_id']))."'>" . IMAGE_admin_move2 . "</a>";
} }
$ret .= " $ret .= "
</div> </div>