############################################################## ## MOD Title: MOD Topic_renew ## MOD Author: Merlin Sythove Dennis www.pimpmyforum.nl ## MOD Description: This mod will automatically: ## a. lock a topic if it reaches x amount of pages (set in the Admin Control Panel). ## b. append the number 1 to the old topic title if no number present yet. ## c. open a new topic with the same title and the next number ## d. post the post there ## e. create cross-links in the last post of the old topic, and the first post of the new topic ## f. Update topic watches to switch to the new topic ## g. If someone was busy posting whilst someone else renews a topic like this, ## their post will be appended to the newly made topic automatically ## ## MOD Version: 0.9.0 ## ## Installation Level: (Easy) ## Installation Time: 10 Minutes by hand ## Files To Edit: ## posting.php ## language/lang_english/lang_main.php ## If you want to install the ACP section: ## language/lang_english/lang_admin.php ## admin/admin_board.php ## templates/subSilver/admin/board_config_body.tpl ## ## Included Files: (N/A) ## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2 ############################################################## ## For security purposes, please check: http://www.phpbb.com/mods/ ## for the latest version of this MOD. Although MODs are checked ## before being allowed in the MODs Database there is no guarantee ## that there are no security problems within the MOD. No support ## will be given for MODs not found within the MODs Database which ## can be found at http://www.phpbb.com/mods/ ############################################################## ## Author Notes: ## MOD Discussion ## http://www.phpbb.com/community/viewtopic.php?f=16&t=530648&start=15&st=0&sk=t&sd=a ## MOD test procedure ## http://www.phpbb.com/community/viewtopic.php?f=16&t=530648&p=2919365#p2919365 ## ############################################################## ## MOD History: ## ## April 7 2007: first release version 0.9.0 ## ############################################################## ## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD ############################################################## # # NOTE: If you do not do the database update and leave out the Admin panel updates, # the MOD works fine and defaults to the maximum pages that you specify in the code. # Currently that is 100 pages. To skip the ACP section, continue at the next note below. # # #-----[ SQL ]------------------------------------------ # INSERT INTO `phpbb_config` ( `config_name` , `config_value` ) VALUES ('topic_renew', ''); # #-----[ OPEN ]------------------------------------------ # admin/admin_board.php # #-----[ FIND ]------------------------------------------ # "L_HOT_THRESHOLD" => $lang['Hot_threshold'], # #-----[ AFTER, ADD ]------------------------------------------ # //MOD Topic_renew "L_TOPIC_RENEW_TITLE" => $lang['Topic_renew_title'], "L_TOPIC_RENEW_EXPLAIN" => $lang['Topic_renew_explain'], "TOPIC_RENEW" => $new['topic_renew'], # #-----[ OPEN ]------------------------------------------ # lanugage/lang_english/lang_admin.php # #-----[ FIND ]------------------------------------------ # // // That's all Folks! # #-----[ BEFORE, ADD ]------------------------------------------ # //MOD Topic_renew $lang['Topic_renew_title'] = "Topic renew page count"; $lang['Topic_renew_explain'] = "Close topic and start a new one after the amount of pages you specify. Leave it empty to default to 100 pages. Set to zero to disable this mod."; # #-----[ OPEN ]------------------------------------------ # templates/subSilver/admin/board_config_body.tpl # #-----[ FIND ]------------------------------------------ # {L_POSTS_PER_PAGE} # #-----[ AFTER, ADD ]------------------------------------------ # {L_TOPIC_RENEW_TITLE}
{L_TOPIC_RENEW_EXPLAIN} # # NOTE: This is the end of the Admin Control Panel section, which you can skip if you like. # # #-----[ OPEN ]------------------------------------------ # language/lang_english/lang_main.php # #-----[ FIND ]------------------------------------------ # // // That's all Folks! # #-----[ BEFORE, ADD ]------------------------------------------ # //MOD Topic_renew $lang['Topic_renew_lastpost'] = "This topic continues here: [url=%s]%s[/url]"; $lang['Topic_renew_firstpost'] = "This topic is the continuation of: [url=%s]%s[/url]"; # #-----[ OPEN ]------------------------------------------ # posting.php # #-----[ FIND ]------------------------------------------ # $error_msg = ''; $post_data = array(); # #-----[ BEFORE, ADD ]------------------------------------------ # //START MOD Topic_renew //Set maximum replies per topic: pages * posts per page, default 100 pages. $topic_max_pages = (! is_null($board_config['topic_renew'])) ? $board_config['topic_renew'] : 100; $topic_max_replies = $topic_max_pages * $board_config['posts_per_page']; //This is how to customise some forums to have a special maximum of pages per topic //if ($forum_id == 2 || $forum_id == 3) //For forum 2 and forum 3 //{ // //Use a fixed amount of 10 pages // $topic_max_replies = 10 * $board_config['posts_per_page']; // //Use a quarter of the pages for normal topics elsewhere: // //$topic_max_replies = floor($topic_max_pages/4) * $board_config['posts_per_page']; //} //We are saving a new post. Admin and Mod have no special powers in this case! if ($submit == true && ($topic_max_replies > 0) && !(empty($topic_id)) && ($mode == 'reply' || $mode == 'quote')) // && $userdata['user_level'] == ADMIN) { //Need full url to forum later $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://'; $server_name = trim($board_config['server_name']); $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) . '/' : '/'; $script_path = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path'])); $forum_url = $server_protocol . $server_name . $server_port . $script_path . "/"; //Get this topic data $sql = "SELECT * FROM " . TOPICS_TABLE . " WHERE topic_id = $topic_id"; if ( ! ($result = $db->sql_query($sql)) || ! ($topic_info = $db->sql_fetchrow($result)) ) { message_die(GENERAL_ERROR, 'Could not select topic info', '', __LINE__, __FILE__, $sql); } $db->sql_freeresult($result); //Create an old and a new topic title $title = array(); $title = explode(" ", $topic_info['topic_title']); $number = is_numeric($title[count($title)-1]) ? intval($title[count($title)-1]): 0; if ($number) { unset($title[count($title)-1]); //Remove last word which is a number $number++; //make next number } else { $topic_info['topic_title'] .= " 1"; //Append 1 to the topic title $number = 2; } $new_title = (implode(" ", $title) . " " . $number); //Create new topic title with next number //Option 1: IS the topic locked? //Assumption: it has just been locked because someone else caused the topic_renewal to work if ($topic_info['topic_status'] == TOPIC_LOCKED) { //Find the new topic, if that exists. $sql = "SELECT * FROM " . TOPICS_TABLE . " WHERE topic_title = '" . addslashes($new_title) . "' AND topic_time > " . (time() - (1 * 3600)); //Note: Only select a topic with the correct title, AND that was made in the last x hours. //This situation we are in now, is when someone started writing a post just before the topic //was locked automatically, and wants to post after it was locked. The time constraint //minimises the possibility of finding a spurious old topic with the correct title. if ( ($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result)) ) { $db->sql_freeresult($result); //Yes! The topic with the correct title exists. Go and add this message to that new topic now. $topic_id = $row['topic_id']; } } //Option 2: SHOULD the topic be locked and a new topic started? else if ($topic_info['topic_replies'] >= $topic_max_replies) //Not yet locked is implied { $topic_renew = true; //Check if the correct time has already passed $topic_renew_local_time = 21; //Hard-coded: Local time zone hour when renewal should take place, or with first post after that time $topic_renew_UT_time = ($topic_renew_local_time + 24 - $board_config['board_timezone']) % 24; //GMT/UT time $topic_renew_UT_midnight = floor(time()/(24*3600)) * 24; //hours $topic_renew_time = ($topic_renew_UT_midnight + $topic_renew_UT_time ) * 3600; //Exact time today when turnover point is $topic_renew = false; //Fastest check first: is it already past that time? if (time() >= $topic_renew_time) { //Get the time of the last post in this topic. $sql = "SELECT post_time FROM " . POSTS_TABLE . " WHERE post_id = " . $topic_info['topic_last_post_id']; if ( ! ($result = $db->sql_query($sql)) || ! ($row = $db->sql_fetchrow($result))) { message_die(GENERAL_ERROR, 'Could not select last post', '', __LINE__, __FILE__, $sql); } //If the last post time is smaller than the renew_time, the turnover has happened. $topic_renew = ($row['post_time'] < $topic_renew_time); } if ($topic_renew) { //Lock current topic and change title if necessary $sql = "UPDATE " . TOPICS_TABLE . " SET topic_status = " . TOPIC_LOCKED . ", topic_title = '" . addslashes($topic_info['topic_title']) . "' WHERE topic_id = $topic_id"; if ( ! $result = $db->sql_query($sql)) //Success { message_die(GENERAL_ERROR, 'Could not lock old topic', '', __LINE__, __FILE__, $sql); } //Prepare custom message linking back to closed topic $old_url = $forum_url . "viewtopic.$phpEx?" . POST_POST_URL . "=" . $topic_info['topic_last_post_id'] . "#" . $topic_info['topic_last_post_id']; $topic_renew_message = sprintf($lang['Topic_renew_firstpost'], $old_url, addslashes($topic_info['topic_title'])) . "\n\n"; //Copy the current first post?? $old_message = ''; //Testing for now, assume this variable exists and is set: $board_config['topic_renew_first_post'] = true; if ($board_config['topic_renew_first_post']) { $sql = "SELECT * FROM " . POSTS_TEXT_TABLE . " WHERE post_id = " . $topic_info['topic_first_post_id']; if (!(($result = $db->sql_query($sql)) && ($old_row = $db->sql_fetchrow($result)) )) { message_die(GENERAL_ERROR, 'Could not obtain first post data to copy', '', __LINE__, __FILE__, $sql); } //Remove bbcode, that is all you need preg_replace("/\:$bbcode_uid/si", '', $message $old_bbcode_uid = $old_row['bbcode_uid']; $old_message = addslashes($old_row['post_text']); $old_message = preg_replace("/\:$old_bbcode_uid/si", '', $old_message) . "\n\n"; } //Make new topic with that post, change posting variables $forum_id = $topic_info['forum_id']; $HTTP_POST_VARS['subject'] = addslashes($new_title); $HTTP_POST_VARS['message'] = $topic_renew_message . $old_message . $HTTP_POST_VARS['message']; $mode = 'newtopic'; $is_auth_type = 'auth_post'; //Flag that the split is in operation for later: $topic_renew = true; } } } //END MOD Topic_renew # #-----[ FIND ]------------------------------------------ # update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id); } # #-----[ AFTER, ADD ]------------------------------------------ # //START MOD Topic_renew if ($topic_renew) { //Update topic watches from locked topic to newly made topic //Note that this is done before the topic notifications! $sql = "UPDATE " . TOPICS_WATCH_TABLE . " SET topic_id = $topic_id WHERE topic_id = " . $topic_info['topic_id']; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_ERROR, 'Could not update topic watches for locked topic', '', __LINE__, __FILE__, $sql); } //Append custom message to last message in old topic since we have new topic_id now. $new_url = $forum_url . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id; $topic_renew_message = "\n\n" . sprintf($lang['Topic_renew_lastpost'], $new_url, addslashes($new_title)); $sql = "SELECT * FROM " . POSTS_TEXT_TABLE . " WHERE post_id = " . $topic_info['topic_last_post_id']; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_ERROR, 'Could not select last post in locked topic', '', __LINE__, __FILE__, $sql); } $row = $db->sql_fetchrow($result); $sql = "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '" . $row['post_text'] . $topic_renew_message . "' WHERE post_id = " . $topic_info['topic_last_post_id']; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_ERROR, 'Could not update last post in locked topic', '', __LINE__, __FILE__, $sql); } } //END MOD Topic_renew # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # # EoM