diff --git a/e107_plugins/forum/attachments/index.html b/e107_plugins/forum/attachments/index.html
new file mode 100644
index 000000000..e69de29bb
diff --git a/e107_plugins/forum/attachments/thumb/index.html b/e107_plugins/forum/attachments/thumb/index.html
new file mode 100644
index 000000000..e69de29bb
diff --git a/e107_plugins/forum/e_url/thread.php b/e107_plugins/forum/e_url/thread.php
index 3e5cd8a28..b1358356a 100644
--- a/e107_plugins/forum/e_url/thread.php
+++ b/e107_plugins/forum/e_url/thread.php
@@ -1,5 +1,5 @@
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_active'] = 'int';
$this->fieldTypes['forum_thread']['thread_datestamp'] = 'int';
$this->fieldTypes['forum_thread']['thread_views'] = 'int';
$this->fieldTypes['forum_thread']['thread_replies'] = 'int';
@@ -356,11 +356,71 @@ class e107forum
$viewed = $tmp['plugin_forum_user_viewed'];
unset($tmp);
}
-
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)
{
global $sql;
@@ -388,23 +448,24 @@ class e107forum
$sql2 = new db;
if ($type == 'thread')
{
- $id = intval($id);
- $thread_info = $this->thread_get_lastpost($id);
- list($uid, $uname) = explode(".", $thread_info['thread_user'], 2);
- if ($thread_info)
+ $id = (int)$id;
+ $lpInfo = $this->threadGetLastpost($id);
+ $tmp = array();
+ if($lpInfo['user_name'])
{
- if($thread_info['user_name'] != "")
- {
- $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);
+ $tmp['thread_lastuser'] = $lpInfo['post_user'];
+ $tmp['thread_lastuser_anon'] = '_NULL_';
}
- 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 ($id == 'all')
@@ -753,29 +814,21 @@ class e107forum
return $ret;
}
- function thread_get_lastpost($forum_id)
+ function threadGetLastpost($id)
{
- $forum_id = intval($forum_id);
- global $sql;
- 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 ";
- }
+ $e107 = e107::getInstance();
+ $id = (int)$id;
$qry = "
- SELECT t.thread_user, t.thread_datestamp, u.user_name FROM #forum_t AS t
- LEFT JOIN #user AS u ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id
- {$where}
- ORDER BY t.thread_datestamp DESC LIMIT 0,1
+ 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 u.user_id = p.post_user
+ WHERE p.post_thread = {$id}
+ 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)
diff --git a/e107_plugins/forum/forum_mod.php b/e107_plugins/forum/forum_mod.php
index e6d3370c4..1847fff1b 100644
--- a/e107_plugins/forum/forum_mod.php
+++ b/e107_plugins/forum/forum_mod.php
@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_mod.php,v $
-| $Revision: 1.3 $
-| $Date: 2008-12-09 21:46:14 $
+| $Revision: 1.4 $
+| $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -33,6 +33,7 @@ function forum_thread_moderate($p)
if (preg_match("#(.*?)_(\d+)_x#", $key, $matches))
{
$act = $matches[1];
+// print_a($matches); return;
$id = (int)$matches[2];
switch ($act)
@@ -61,6 +62,10 @@ function forum_thread_moderate($p)
return forumDeleteThread($id);
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.'.';
+
+}
+
+
?>
\ No newline at end of file
diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php
index 7e6e315f9..fd22763c6 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.28 $
-| $Date: 2008-12-10 15:29:31 $
+| $Revision: 1.29 $
+| $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -258,7 +258,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
}
$postInfo['post_attachments'] = implode(',', $attachments);
}
- var_dump($uploadResult);
+// var_dump($uploadResult);
switch($action)
{
@@ -576,7 +576,10 @@ function process_upload()
require_once(e_HANDLER.'resize_handler.php');
$orig_file = $upload['name'];
$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'])
{
diff --git a/e107_plugins/forum/forum_shortcodes.php b/e107_plugins/forum/forum_shortcodes.php
index abec08afb..546aa6c1d 100644
--- a/e107_plugins/forum/forum_shortcodes.php
+++ b/e107_plugins/forum/forum_shortcodes.php
@@ -42,12 +42,16 @@ if($postInfo['post_attachments'])
case 'file':
$txt .= IMAGE_attachment." {$info[2]}
";
break;
-
+
case 'img':
//if image has a thumb, show it and link to main
if(isset($info[2]))
{
- $txt .= "
";
+ $txt .= "
";
+ }
+ else
+ {
+ $txt .= "
";
}
}
}
@@ -212,7 +216,6 @@ if (USER && $postInfo['post_user'] == USERID && $threadInfo['thread_active'])
{
return " 'edit', 'id' => $postInfo['post_id']))."'>".IMAGE_edit.' ';
}
-return '';
SC_END
SC_BEGIN QUOTEIMG
diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php
index 9851203ab..313834b76 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.11 $
-| $Date: 2008-12-09 21:46:14 $
+| $Revision: 1.12 $
+| $Date: 2008-12-11 16:02:05 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -69,22 +69,6 @@ if (USER || USER != $threadInfo['thread_user'] || !$thread->noInc)
$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'));
$modArray = $forum->forum_getmods($thread->threadInfo['forum_moderators']);
define('MODERATOR', (USER && is_array($modArray) && in_array(USERID, array_keys($modArray))));
@@ -286,7 +270,7 @@ else
echo "