0) { while ($data = dbarray($result)) { // delete all attachments $result2 = dbquery("SELECT attach_name FROM ".DB_FORUM_ATTACHMENTS." WHERE post_id='".$data['post_id']."'"); if (dbrows($result2) != 0) { $delattach++; $attach = dbarray($result2); @unlink(FORUM."attachments/".$attach['attach_name']); dbquery("DELETE FROM ".DB_FORUM_ATTACHMENTS." WHERE post_id='".$data['post_id']."'"); } } } } /** * Delete all forum threads * * @param $forum_id * @param bool $time */ protected static function prune_threads($forum_id, $time = FALSE) { // delete follows on threads $result = dbquery("SELECT thread_id, thread_lastpost FROM ".DB_FORUM_THREADS." WHERE forum_id='".$forum_id."' ".($time ? "AND thread_lastpost < '".$time."'" : '')." "); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("DELETE FROM ".DB_FORUM_THREAD_NOTIFY." WHERE thread_id='".$data['thread_id']."'"); } } // delete threads dbquery("DELETE FROM ".DB_FORUM_THREADS." WHERE forum_id='$forum_id' ".($time ? "AND thread_lastpost < '".$time."'" : '')." "); } /** * Recalculate a forum post count * * @param $forum_id * * @return string */ protected static function recalculate_post($forum_id) { // update last post $result = dbquery("SELECT thread_lastpost, thread_lastuser FROM ".DB_FORUM_THREADS." WHERE forum_id='".$forum_id."' ORDER BY thread_lastpost DESC LIMIT 0,1"); // get last thread_lastpost. if (dbrows($result)) { $data = dbarray($result); dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost='".$data['thread_lastpost']."', forum_lastuser='".$data['thread_lastuser']."' WHERE forum_id='".$forum_id."'"); } else { dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost='0', forum_lastuser='0' WHERE forum_id='".$forum_id."'"); } // update postcount on each threads - this is the remaining. $result = dbquery("SELECT COUNT(post_id) AS postcount, thread_id FROM ".DB_FORUM_POSTS." WHERE forum_id='".$forum_id."' GROUP BY thread_id"); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("UPDATE ".DB_FORUM_THREADS." SET thread_postcount='".$data['postcount']."' WHERE thread_id='".$data['thread_id']."'"); } } // calculate and update total combined postcount on all threads to forum $result = dbquery("SELECT SUM(thread_postcount) AS postcount, forum_id FROM ".DB_FORUM_THREADS." WHERE forum_id='".$forum_id."' GROUP BY forum_id"); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("UPDATE ".DB_FORUMS." SET forum_postcount='".$data['postcount']."' WHERE forum_id='".$data['forum_id']."'"); } } // calculate and update total threads to forum $result = dbquery("SELECT COUNT(thread_id) AS threadcount, forum_id FROM ".DB_FORUM_THREADS." WHERE forum_id='".$forum_id."' GROUP BY forum_id"); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("UPDATE ".DB_FORUMS." SET forum_threadcount='".$data['threadcount']."' WHERE forum_id='".$data['forum_id']."'"); } } } /** * Remove the entire forum branch, image and order updated * * @param bool $index * @param bool $time */ protected function prune_forums($index = FALSE, $time = FALSE) { // delete forums - wipeout branch, image, order updated. $index = $index ? $index : 0; // need to refetch a new index after moving, else the id will be targetted $branch_data = $this->get_forum_index(); //print_p($branch_data[$index]); //print_p("Index is $index"); $index_data = dbarray(dbquery("SELECT forum_id, forum_image, forum_order FROM ".DB_FORUMS." ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$index."'")); // check if there is a sub for this node. if (isset($branch_data[$index])) { $data = []; foreach ($branch_data[$index] as $forum_id) { $data = dbarray(dbquery("SELECT forum_id, forum_image, forum_order FROM ".DB_FORUMS." ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$forum_id."'")); if ($data['forum_image'] && file_exists(IMAGES."forum/".$data['forum_image'])) { unlink(IMAGES."forum/".$data['forum_image']); } dbquery("UPDATE ".DB_FORUMS." SET forum_order=forum_order-1 ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$forum_id."' AND forum_order>'".$data['forum_order']."'"); dbquery("DELETE FROM ".DB_FORUMS." ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='$forum_id' ".($time ? "AND forum_lastpost < '".$time."'" : '')." "); if (isset($branch_data[$data['forum_id']])) { self::prune_forums($branch_data, $time); } // end foreach } // finally remove itself. if ($index_data['forum_image'] && file_exists(IMAGES."forum/".$index_data['forum_image'])) { unlink(IMAGES."forum/".$data['forum_image']); //print_p("unlinked ".$index_data['forum_image'].""); } dbquery("UPDATE ".DB_FORUMS." SET forum_order=forum_order-1 ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$index."' AND forum_order>'".$index_data['forum_order']."'"); //print_p("deleted ".$index.""); dbquery("DELETE FROM ".DB_FORUMS." ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$index."' ".($time ? "AND forum_lastpost < '".$time."'" : '')." "); } else { if ($index_data['forum_image'] && file_exists(IMAGES."forum/".$index_data['forum_image'])) { unlink(IMAGES."forum/".$index_data['forum_image']); //print_p("unlinked ".$index_data['forum_image'].""); } dbquery("UPDATE ".DB_FORUMS." SET forum_order=forum_order-1 ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$index."' AND forum_order>'".$index_data['forum_order']."'"); //print_p("deleted ".$index.""); dbquery("DELETE FROM ".DB_FORUMS." ".(multilang_table("FO") ? "WHERE ".in_group('forum_language', LANGUAGE)." AND" : "WHERE")." forum_id='".$index."' ".($time ? "AND forum_lastpost < '".$time."'" : '')." "); } } /** * Get forum index for hierarchy traversal * * @return array */ protected static function get_forum_index() { return dbquery_tree(DB_FORUMS, 'forum_id', 'forum_cat'); } }