home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / unitednuke / unitednuke.exe / html / includes / prune.php < prev    next >
PHP Script  |  2004-01-10  |  9KB  |  202 lines

  1. <?php
  2. /***************************************************************************
  3. *                                 prune.php
  4. *                            -------------------
  5. *   begin                : Thursday, June 14, 2001
  6. *   copyright            : (C) 2001 The phpBB Group
  7. *   email                : support@phpbb.com
  8. *
  9. *   $Id: prune.php,v 1.19.2.6 2003/03/18 23:23:57 acydburn Exp $
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. * phpbb2 forums port version 2.0.5 (c) 2003 - Nuke Cops (http://nukecops.com)
  15. *
  16. * Ported by Nuke Cops to phpbb2 standalone 2.0.5 Test
  17. * and debugging completed by the Elite Nukers and site members.
  18. *
  19. * You run this package at your sole risk. Nuke Cops and affiliates cannot
  20. * be held liable if anything goes wrong. You are advised to test this
  21. * package on a development system. Backup everything before implementing
  22. * in a production environment. If something goes wrong, you can always
  23. * backout and restore your backups.
  24. *
  25. * Installing and running this also means you agree to the terms of the AUP
  26. * found at Nuke Cops.
  27. *
  28. * This is version 2.0.5 of the phpbb2 forum port for PHP-Nuke. Work is based
  29. * on Tom Nitzschner's forum port version 2.0.6. Tom's 2.0.6 port was based
  30. * on the phpbb2 standalone version 2.0.3. Our version 2.0.5 from Nuke Cops is
  31. * now reflecting phpbb2 standalone 2.0.5 that fixes some bugs and the
  32. * invalid_session error message.
  33. ***************************************************************************/
  34. /***************************************************************************
  35.  *   This file is part of the phpBB2 port to Nuke 6.0 (c) copyright 2002
  36.  *   by Tom Nitzschner (tom@toms-home.com)
  37.  *   http://bbtonuke.sourceforge.net (or http://www.toms-home.com)
  38.  *
  39.  *   As always, make a backup before messing with anything. All code
  40.  *   release by me is considered sample code only. It may be fully
  41.  *   functual, but you use it at your own risk, if you break it,
  42.  *   you get to fix it too. No waranty is given or implied.
  43.  *
  44.  *   Please post all questions/request about this port on http://bbtonuke.sourceforge.net first,
  45.  *   then on my site. All original header code and copyright messages will be maintained
  46.  *   to give credit where credit is due. If you modify this, the only requirement is
  47.  *   that you also maintain all original copyright messages. All my work is released
  48.  *   under the GNU GENERAL PUBLIC LICENSE. Please see the README for more information.
  49.  *
  50.  ***************************************************************************/
  51. /***************************************************************************
  52.  *
  53.  *   This program is free software; you can redistribute it and/or modify
  54.  *   it under the terms of the GNU General Public License as published by
  55.  *   the Free Software Foundation; either version 2 of the License, or
  56.  *   (at your option) any later version.
  57.  *
  58.  ***************************************************************************/
  59.  
  60. if ( !defined('IN_PHPBB') )
  61. {
  62.    die("Hacking attempt");
  63. }
  64.  
  65. if ($forum_admin == 1) {
  66.     require("../../../includes/functions_search.php");
  67. } else {
  68.     require("includes/functions_search.php");
  69. }
  70.  
  71. function prune($forum_id, $prune_date, $prune_all = false)
  72. {
  73.         global $db, $lang;
  74.  
  75.         $prune_all = ($prune_all) ? '' : 'AND t.topic_vote = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
  76.         //
  77.         // Those without polls and announcements ... unless told otherwise!
  78.         //
  79.         $sql = "SELECT t.topic_id
  80.                 FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
  81.                 WHERE t.forum_id = $forum_id
  82.                         $prune_all
  83.                         AND ( p.post_id = t.topic_last_post_id
  84.                                 OR t.topic_last_post_id = 0 )";
  85.         if ( $prune_date != '' )
  86.         {
  87.                 $sql .= " AND p.post_time < $prune_date";
  88.         }
  89.  
  90.         if ( !($result = $db->sql_query($sql)) )
  91.         {
  92.                 message_die(GENERAL_ERROR, 'Could not obtain lists of topics to prune', '', __LINE__, __FILE__, $sql);
  93.         }
  94.  
  95.         $sql_topics = '';
  96.         while( $row = $db->sql_fetchrow($result) )
  97.         {
  98.                 $sql_topics .= ( ( $sql_topics != '' ) ? ', ' : '' ) . $row['topic_id'];
  99.         }
  100.         $db->sql_freeresult($result);
  101.  
  102.         if( $sql_topics != '' )
  103.         {
  104.                 $sql = "SELECT post_id
  105.                         FROM " . POSTS_TABLE . "
  106.                         WHERE forum_id = $forum_id
  107.                                 AND topic_id IN ($sql_topics)";
  108.                 if ( !($result = $db->sql_query($sql)) )
  109.                 {
  110.                         message_die(GENERAL_ERROR, 'Could not obtain list of posts to prune', '', __LINE__, __FILE__, $sql);
  111.                 }
  112.  
  113.                 $sql_post = '';
  114.                 while ( $row = $db->sql_fetchrow($result) )
  115.                 {
  116.                         $sql_post .= ( ( $sql_post != '' ) ? ', ' : '' ) . $row['post_id'];
  117.                 }
  118.                 $db->sql_freeresult($result);
  119.  
  120.                 if ( $sql_post != '' )
  121.                 {
  122.                         $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
  123.                                 WHERE topic_id IN ($sql_topics)";
  124.                         if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
  125.                         {
  126.                                 message_die(GENERAL_ERROR, 'Could not delete watched topics during prune', '', __LINE__, __FILE__, $sql);
  127.                         }
  128.  
  129.                         $sql = "DELETE FROM " . TOPICS_TABLE . "
  130.                                 WHERE topic_id IN ($sql_topics)";
  131.                         if ( !$db->sql_query($sql) )
  132.                         {
  133.                                 message_die(GENERAL_ERROR, 'Could not delete topics during prune', '', __LINE__, __FILE__, $sql);
  134.                         }
  135.  
  136.                         $pruned_topics = $db->sql_affectedrows();
  137.  
  138.                         $sql = "DELETE FROM " . POSTS_TABLE . "
  139.                                 WHERE post_id IN ($sql_post)";
  140.                         if ( !$db->sql_query($sql) )
  141.                         {
  142.                                 message_die(GENERAL_ERROR, 'Could not delete post_text during prune', '', __LINE__, __FILE__, $sql);
  143.                         }
  144.  
  145.                         $pruned_posts = $db->sql_affectedrows();
  146.  
  147.                         $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
  148.                                 WHERE post_id IN ($sql_post)";
  149.                         if ( !$db->sql_query($sql) )
  150.                         {
  151.                                 message_die(GENERAL_ERROR, 'Could not delete post during prune', '', __LINE__, __FILE__, $sql);
  152.                         }
  153.  
  154.                         remove_search_post($sql_post);
  155.  
  156.                         return array ('topics' => $pruned_topics, 'posts' => $pruned_posts);
  157.                 }
  158.         }
  159.  
  160.         return array('topics' => 0, 'posts' => 0);
  161. }
  162.  
  163. //
  164. // Function auto_prune(), this function will read the configuration data from
  165. // the auto_prune table and call the prune function with the necessary info.
  166. //
  167. function auto_prune($forum_id = 0)
  168. {
  169.         global $db, $lang;
  170.  
  171.         $sql = "SELECT *
  172.                 FROM " . PRUNE_TABLE . "
  173.                 WHERE forum_id = $forum_id";
  174.         if ( !($result = $db->sql_query($sql)) )
  175.         {
  176.                 message_die(GENERAL_ERROR, 'Could not read auto_prune table', '', __LINE__, __FILE__, $sql);
  177.         }
  178.  
  179.         if ( $row = $db->sql_fetchrow($result) )
  180.         {
  181.                 if ( $row['prune_freq'] && $row['prune_days'] )
  182.                 {
  183.                         $prune_date = time() - ( $row['prune_days'] * 86400 );
  184.                         $next_prune = time() + ( $row['prune_freq'] * 86400 );
  185.  
  186.                         prune($forum_id, $prune_date);
  187.                         sync('forum', $forum_id);
  188.  
  189.                         $sql = "UPDATE " . FORUMS_TABLE . "
  190.                                 SET prune_next = $next_prune
  191.                                 WHERE forum_id = $forum_id";
  192.                         if ( !$db->sql_query($sql) )
  193.                         {
  194.                                 message_die(GENERAL_ERROR, 'Could not update forum table', '', __LINE__, __FILE__, $sql);
  195.                         }
  196.                 }
  197.         }
  198.  
  199.         return;
  200. }
  201.  
  202. ?>