sirena wrote:Very well put together. Wow, lots of members too.
Thx ;-)
sirena wrote:The "/dev/null" forum - how did you set that up to auto-remove posts?
There is function which do this :-) (putted in functions.php, invoked from header.php)
// Delete topics from '/dev/null'
function forum_clean_devnull()
{
global $db, $db_type, $pun_config, $pun_user;
if($pun_user['g_id'] > PUN_MOD)
return;
require_once PUN_ROOT.'include/search_idx.php';
//For each forum, which name is '/dev/null'
$fresult = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE forum_name=\'/dev/null\'') or error('Unable to get forum list', __FILE__, __LINE__, $db->error());
while(list($fid) = $db->fetch_row($fresult)){
// Find topics, where last_post is time() - 1 day
$long_ago = time() - 60 * 60 * 24;
$topics_were_deleted = 0;
$tresult = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE last_post<'.$long_ago.' AND forum_id='.$fid) or error('Unable to get topic list', __FILE__, __LINE__, $db->error());
while(list($topic) = $db->fetch_row($tresult)){
// Delete the topics and any redirect topics
$db->query('DELETE FROM '.$db->prefix.'topics WHERE id='.$topic.' OR moved_to='.$topic) or error('Unable to delete topic', __FILE__, __LINE__, $db->error());
$topics_were_deleted = 1;
// Delete any subscriptions
$db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id='.$topic) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
// Create a list of the post ID's in this topic and then strip the search index
$result = $db->query('SELECT id, poster_id FROM '.$db->prefix.'posts WHERE topic_id='.$topic) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
$post_ids = '';
while (list($post_id, $user_id) = $db->fetch_row($result)){
$post_ids .= ($post_ids != '') ? ','.$post_id : $post_id;
$db->query('UPDATE user SET forum_posty=forum_posty-1 WHERE id='.$user_id) or error('Unable to update user data', __FILE__, __LINE__, $db->error());
}
// We have to check that we actually have a list of post ID's since we could be deleting just a redirect topic
if ($post_ids != '')
strip_search_index($post_ids);
// Delete posts
$db->query('DELETE FROM '.$db->prefix.'posts WHERE topic_id='.$topic) or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
}
if($topics_were_deleted == 1){
update_forum($fid);
@include PUN_ROOT.'include/cache.php';
generate_latest_topics_cache();
}
}
}
Some code was cp'ed from delete.php (AFAIR). There is reference to table user in the database - this table is a part of linux.pl, not PunBB. At the end there is reference to generate_latest_topics_cache() - this function generates file in cache with list of the newest posted topics.