Esempio n. 1
0
function get_id($id_field, $field)
{
    $last_id = get_single_value($id_field, $field);
    if ($last_id) {
        return $last_id + 1;
    } else {
        return 1;
    }
}
Esempio n. 2
0
</td></tr></table>
<?php 
}
// Bonus exchange
if ($action == "exchange") {
    if ($_POST["userid"] || $_POST["points"] || $_POST["bonus"] || $_POST["art"]) {
        write_log("User " . $CURUSER["username"] . "," . $CURUSER["ip"] . " is trying to cheat at bonus system", 'mod');
        die($lang_mybonus['text_cheat_alert']);
    }
    $option = (int) $_POST["option"];
    $bonusarray = bonusarray($option);
    $points = $bonusarray['points'];
    $userid = $CURUSER['id'];
    $art = $bonusarray['art'];
    // Be sure the bonus data is newest
    $nowbonus = get_single_value("users", "seedbonus", "WHERE id = " . sqlesc($userid));
    $bonuscomment = $CURUSER['bonuscomment'];
    $seedbonus = $nowbonus - $points;
    if ($nowbonus >= $points) {
        //=== trade for upload
        if ($art == "traffic") {
            if ($CURUSER['uploaded'] > $dlamountlimit_bonus * 1073741824) {
                //uploaded amount reach limit
                $ratio = $CURUSER['uploaded'] / $CURUSER['downloaded'];
            } else {
                $ratio = 0;
            }
            if ($ratiolimit_bonus > 0 && $ratio > $ratiolimit_bonus) {
                die($lang_mybonus['text_cheat_alert']);
            } else {
                $upload = $CURUSER['uploaded'];
Esempio n. 3
0
<?php 
    $Cache->new_page('stats_torrents', 1800, true);
    if (!$Cache->get_page()) {
        $Cache->add_whole_row();
        $torrents = number_format(get_row_count("torrents"));
        $dead = number_format(get_row_count("torrents", "WHERE visible='no'"));
        $seeders = get_row_count("peers", "WHERE seeder='yes'");
        $leechers = get_row_count("peers", "WHERE seeder='no'");
        if ($leechers == 0) {
            $ratio = 0;
        } else {
            $ratio = round($seeders / $leechers * 100);
        }
        $activewebusernow = get_row_count("users", "WHERE last_access >= " . sqlesc(date("Y-m-d H:i:s", TIMENOW - 900)));
        $activewebusernow = number_format($activewebusernow);
        $activetrackerusernow = number_format(get_single_value("peers", "COUNT(DISTINCT(userid))"));
        $peers = number_format($seeders + $leechers);
        $seeders = number_format($seeders);
        $leechers = number_format($leechers);
        $totaltorrentssize = mksize(get_row_sum("torrents", "size"));
        $totaluploaded = get_row_sum("users", "uploaded");
        $totaldownloaded = get_row_sum("users", "downloaded");
        $totaldata = $totaldownloaded + $totaluploaded;
        ?>
<tr>
<?php 
        twotd($lang_index['row_torrents'], $torrents);
        twotd($lang_index['row_dead_torrents'], $dead);
        ?>
</tr>
<tr>
Esempio n. 4
0
<?php

require "include/bittorrent.php";
dbconn();
require_once get_langfile_path();
loggedinorreturn();
parked();
$id = $_GET["id"];
int_check($id, true);
stdhead($lang_viewsnatches['head_snatch_detail']);
begin_main_frame();
$torrent_name = get_single_value("torrents", "name", "WHERE id = " . sqlesc($id));
print "<h1 align=center>" . $lang_viewsnatches['text_snatch_detail_for'] . "<a href=details.php?id=" . htmlspecialchars($id) . "><b>" . htmlspecialchars($torrent_name) . "</b></a></h1>";
$count = get_row_count("snatched", "WHERE finished = 'yes' AND torrentid = " . sqlesc($id));
if ($count) {
    $perpage = 25;
    list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["SCRIPT_NAME"] . "?id=" . htmlspecialchars($id) . "&");
    print "<p align=center>" . $lang_viewsnatches['text_users_top_finished_recently'] . "</p>";
    print "<table border=1 cellspacing=0 cellpadding=5 align=center width=940>\n";
    print "<tr><td class=colhead align=center>" . $lang_viewsnatches['col_username'] . "</td>" . (get_user_class() >= $userprofile_class ? "<td class=colhead align=center>" . $lang_viewsnatches['col_ip'] . "</td>" : "") . "<td class=colhead align=center>" . $lang_viewsnatches['col_uploaded'] . "/" . $lang_viewsnatches['col_downloaded'] . "</td><td class=colhead align=center>" . $lang_viewsnatches['col_ratio'] . "</td><td class=colhead align=center>" . $lang_viewsnatches['col_se_time'] . "</td><td class=colhead align=center>" . $lang_viewsnatches['col_le_time'] . "</td><td class=colhead align=center>" . $lang_viewsnatches['col_when_completed'] . "</td><td class=colhead align=center>" . $lang_viewsnatches['col_last_action'] . "</td><td class=colhead align=center>" . $lang_viewsnatches['col_report_user'] . "</td></tr>";
    $res = sql_query("SELECT * FROM snatched WHERE finished='yes' AND torrentid =" . sqlesc($id) . " ORDER BY completedat DESC {$limit}");
    while ($arr = mysql_fetch_assoc($res)) {
        //start torrent
        if ($arr["downloaded"] > 0) {
            $ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
            $ratio = "<font color=" . get_ratio_color($ratio) . ">{$ratio}</font>";
        } elseif ($arr["uploaded"] > 0) {
            $ratio = $lang_viewsnatches['text_inf'];
        } else {
            $ratio = "---";
        }
Esempio n. 5
0
function docleanup($forceAll = 0, $printProgress = false)
{
    //require_once(get_langfile_path("cleanup.php",true));
    global $lang_cleanup_target;
    global $torrent_dir, $signup_timeout, $max_dead_torrent_time, $autoclean_interval_one, $autoclean_interval_two, $autoclean_interval_three, $autoclean_interval_four, $autoclean_interval_five, $SITENAME, $bonus, $invite_timeout, $offervotetimeout_main, $offeruptimeout_main, $iniupload_main;
    global $donortimes_bonus, $perseeding_bonus, $maxseeding_bonus, $tzero_bonus, $nzero_bonus, $bzero_bonus, $l_bonus;
    global $expirehalfleech_torrent, $expirefree_torrent, $expiretwoup_torrent, $expiretwoupfree_torrent, $expiretwouphalfleech_torrent, $expirethirtypercentleech_torrent, $expirenormal_torrent, $hotdays_torrent, $hotseeder_torrent, $halfleechbecome_torrent, $freebecome_torrent, $twoupbecome_torrent, $twoupfreebecome_torrent, $twouphalfleechbecome_torrent, $thirtypercentleechbecome_torrent, $normalbecome_torrent, $deldeadtorrent_torrent;
    global $neverdelete_account, $neverdeletepacked_account, $deletepacked_account, $deleteunpacked_account, $deletenotransfer_account, $deletenotransfertwo_account, $deletepeasant_account, $psdlone_account, $psratioone_account, $psdltwo_account, $psratiotwo_account, $psdlthree_account, $psratiothree_account, $psdlfour_account, $psratiofour_account, $psdlfive_account, $psratiofive_account, $putime_account, $pudl_account, $puprratio_account, $puderatio_account, $eutime_account, $eudl_account, $euprratio_account, $euderatio_account, $cutime_account, $cudl_account, $cuprratio_account, $cuderatio_account, $iutime_account, $iudl_account, $iuprratio_account, $iuderatio_account, $vutime_account, $vudl_account, $vuprratio_account, $vuderatio_account, $exutime_account, $exudl_account, $exuprratio_account, $exuderatio_account, $uutime_account, $uudl_account, $uuprratio_account, $uuderatio_account, $nmtime_account, $nmdl_account, $nmprratio_account, $nmderatio_account, $getInvitesByPromotion_class;
    global $enablenoad_advertisement, $noad_advertisement;
    global $Cache;
    set_time_limit(0);
    ignore_user_abort(1);
    $now = time();
    //Priority Class 1: cleanup every 15 mins
    //2.update peer status
    $deadtime = deadtime();
    $deadtime = date("Y-m-d H:i:s", $deadtime);
    sql_query("DELETE FROM peers WHERE last_action < " . sqlesc($deadtime)) or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress('update peer status');
    }
    //11.calculate seeding bonus
    $res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        $sqrtof2 = sqrt(2);
        $logofpointone = log(0.1);
        $valueone = $logofpointone / $tzero_bonus;
        $pi = 3.141592653589793;
        $valuetwo = $bzero_bonus * (2 / $pi);
        $valuethree = $logofpointone / ($nzero_bonus - 1);
        $timenow = TIMENOW;
        $sectoweek = 7 * 24 * 60 * 60;
        while ($arr = mysql_fetch_assoc($res)) {
            $A = 0;
            $count = 0;
            $all_bonus = 0;
            $torrentres = sql_query("select torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = {$arr['userid']} AND peers.seeder ='yes'") or sqlerr(__FILE__, __LINE__);
            while ($torrent = mysql_fetch_array($torrentres)) {
                $weeks_alive = ($timenow - strtotime($torrent[added])) / $sectoweek;
                $gb_size = $torrent[size] / 1073741824;
                $temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent[seeders] - 1)));
                $A += $temp;
                $count++;
            }
            if ($count > $maxseeding_bonus) {
                $count = $maxseeding_bonus;
            }
            $all_bonus = ($valuetwo * atan($A / $l_bonus) + $perseeding_bonus * $count) / (3600 / $autoclean_interval_one);
            $is_donor = get_single_value("users", "donor", "WHERE id=" . $arr['userid']);
            if ($is_donor == 'yes' && $donortimes_bonus > 0) {
                $all_bonus = $all_bonus * $donortimes_bonus;
            }
            KPS("+", $all_bonus, $arr["userid"]);
        }
    }
    if ($printProgress) {
        printProgress('calculate seeding bonus');
    }
    //Priority Class 2: cleanup every 30 mins
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime2'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime2'," . sqlesc($now) . ")") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_two > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 1';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime2'") or sqlerr(__FILE__, __LINE__);
    }
    //2.5.update torrents' visibility
    $deadtime = deadtime() - $max_dead_torrent_time;
    sql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME({$deadtime}) AND seeders=0") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("update torrents' visibility");
    }
    //Priority Class 3: cleanup every 60 mins
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime3'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime3',{$now})") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_three > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 2';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime3'") or sqlerr(__FILE__, __LINE__);
    }
    //4.update count of seeders, leechers, comments for torrents
    $torrents = array();
    $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        if ($row["seeder"] == "yes") {
            $key = "seeders";
        } else {
            $key = "leechers";
        }
        $torrents[$row["torrent"]][$key] = $row["c"];
    }
    $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        $torrents[$row["torrent"]]["comments"] = $row["c"];
    }
    $fields = explode(":", "comments:leechers:seeders");
    $res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        $id = $row["id"];
        $torr = $torrents[$id];
        foreach ($fields as $field) {
            if (!isset($torr[$field])) {
                $torr[$field] = 0;
            }
        }
        $update = array();
        foreach ($fields as $field) {
            if ($torr[$field] != $row[$field]) {
                $update[] = "{$field} = " . $torr[$field];
            }
        }
        if (count($update)) {
            sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = {$id}") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("update count of seeders, leechers, comments for torrents");
    }
    //set no-advertisement-by-bonus time out
    sql_query("UPDATE users SET noad='no' WHERE noaduntil < " . sqlesc(date("Y-m-d H:i:s")) . ($enablenoad_advertisement == 'yes' ? " AND class < " . sqlesc($noad_advertisement) : ""));
    if ($printProgress) {
        printProgress("set no-advertisement-by-bonus time out");
    }
    //12. update forum post/topic count
    $forums = sql_query("select id from forums") or sqlerr(__FILE__, __LINE__);
    while ($forum = mysql_fetch_assoc($forums)) {
        $postcount = 0;
        $topiccount = 0;
        $topics = sql_query("select id from topics where forumid={$forum['id']}") or sqlerr(__FILE__, __LINE__);
        while ($topic = mysql_fetch_assoc($topics)) {
            $res = sql_query("select count(*) from posts where topicid={$topic['id']}") or sqlerr(__FILE__, __LINE__);
            $arr = mysql_fetch_row($res);
            $postcount += $arr[0];
            ++$topiccount;
        }
        sql_query("update forums set postcount={$postcount}, topiccount={$topiccount} where id={$forum['id']}") or sqlerr(__FILE__, __LINE__);
    }
    $Cache->delete_value('forums_list');
    if ($printProgress) {
        printProgress("update forum post/topic count");
    }
    //14.cleanup offers
    //Delete offers if not voted on after some time
    if ($offervotetimeout_main) {
        $secs = (int) $offervotetimeout_main;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $offervotetimeout_main));
        $res = sql_query("SELECT id, name FROM offers WHERE added < {$dt} AND allowed <> 'allowed'") or sqlerr(__FILE__, __LINE__);
        while ($arr = mysql_fetch_assoc($res)) {
            sql_query("DELETE FROM offers WHERE id={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM offervotes WHERE offerid={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM comments WHERE offer={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            write_log("Offer {$arr['id']} ({$arr['name']}) was deleted by system (vote timeout)", 'normal');
        }
    }
    if ($printProgress) {
        printProgress("delete offers if not voted on after some time");
    }
    //Delete offers if not uploaded after being voted on for some time.
    if ($offeruptimeout_main) {
        $secs = (int) $offeruptimeout_main;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $res = sql_query("SELECT id, name FROM offers WHERE allowedtime < {$dt} AND allowed = 'allowed'") or sqlerr(__FILE__, __LINE__);
        while ($arr = mysql_fetch_assoc($res)) {
            sql_query("DELETE FROM offers WHERE id={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM offervotes WHERE offerid={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM comments WHERE offer={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            write_log("Offer {$arr['id']} ({$arr['name']}) was deleted by system (upload timeout)", 'normal');
        }
    }
    if ($printProgress) {
        printProgress("delete offers if not uploaded after being voted on for some time.");
    }
    //15.cleanup torrents
    //Start: expire torrent promotion
    function torrent_promotion_expire($days, $type = 2, $targettype = 1)
    {
        $secs = (int) ($days * 86400);
        //XX days
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $res = sql_query("SELECT id, name FROM torrents WHERE added < {$dt} AND sp_state = " . sqlesc($type) . ' AND promotion_time_type=0') or sqlerr(__FILE__, __LINE__);
        switch ($targettype) {
            case 1:
                $sp_state = 1;
                $become = "normal";
                break;
            case 2:
                $sp_state = 2;
                $become = "Free";
                break;
            case 3:
                $sp_state = 3;
                $become = "2X";
                break;
            case 4:
                $sp_state = 4;
                $become = "2X Free";
                break;
            case 5:
                $sp_state = 5;
                $become = "50%";
                break;
            case 6:
                $sp_state = 6;
                $become = "2X 50%";
                break;
            default:
                $sp_state = 1;
                $become = "normal";
                break;
        }
        while ($arr = mysql_fetch_assoc($res)) {
            sql_query("UPDATE torrents SET sp_state = " . sqlesc($sp_state) . " WHERE id={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            if ($sp_state == 1) {
                write_log("Torrent {$arr['id']} ({$arr['name']}) is no longer on promotion (time expired)", 'normal');
            } else {
                write_log("Promotion type for torrent {$arr['id']} ({$arr['name']}) is changed to " . $become . " (time expired)", 'normal');
            }
        }
    }
    if ($expirehalfleech_torrent) {
        torrent_promotion_expire($expirehalfleech_torrent, 5, $halfleechbecome_torrent);
    }
    if ($expirefree_torrent) {
        torrent_promotion_expire($expirefree_torrent, 2, $freebecome_torrent);
    }
    if ($expiretwoup_torrent) {
        torrent_promotion_expire($expiretwoup_torrent, 3, $twoupbecome_torrent);
    }
    if ($expiretwoupfree_torrent) {
        torrent_promotion_expire($expiretwoupfree_torrent, 4, $twoupfreebecome_torrent);
    }
    if ($expiretwouphalfleech_torrent) {
        torrent_promotion_expire($expiretwouphalfleech_torrent, 6, $twouphalfleechbecome_torrent);
    }
    if ($expirethirtypercentleech_torrent) {
        torrent_promotion_expire($expirethirtypercentleech_torrent, 7, $thirtypercentleechbecome_torrent);
    }
    if ($expirenormal_torrent) {
        torrent_promotion_expire($expirenormal_torrent, 1, $normalbecome_torrent);
    }
    //expire individual torrent promotion
    sql_query("UPDATE torrents SET sp_state = 1, promotion_time_type=0, promotion_until='0000-00-00 00:00:00' WHERE promotion_time_type=2 AND promotion_until < " . sqlesc(date("Y-m-d H:i:s", TIMENOW))) or sqlerr(__FILE__, __LINE__);
    //End: expire torrent promotion
    if ($printProgress) {
        printProgress("expire torrent promotion");
    }
    //automatically pick hot
    if ($hotdays_torrent) {
        $secs = (int) ($hotdays_torrent * 86400);
        //XX days
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        sql_query("UPDATE torrents SET picktype = 'hot' WHERE added > {$dt} AND picktype = 'normal' AND seeders > " . sqlesc($hotseeder_torrent)) or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("automatically pick hot");
    }
    //Priority Class 4: cleanup every 24 hours
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime4'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime4',{$now})") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_four > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 3';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime4'") or sqlerr(__FILE__, __LINE__);
    }
    //3.delete unconfirmed accounts
    $deadtime = time() - $signup_timeout;
    sql_query("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME({$deadtime}) AND last_login < FROM_UNIXTIME({$deadtime}) AND last_access < FROM_UNIXTIME({$deadtime})") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete unconfirmed accounts");
    }
    //5.delete old login attempts
    $secs = 12 * 60 * 60;
    // Delete failed login attempts per half day.
    $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
    // calculate date.
    sql_query("DELETE FROM loginattempts WHERE banned='no' AND added < {$dt}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete old login attempts");
    }
    //6.delete old invite codes
    $secs = $invite_timeout * 24 * 60 * 60;
    // when?
    $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
    // calculate date.
    sql_query("DELETE FROM invites WHERE time_invited < {$dt}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete old invite codes");
    }
    //7.delete regimage codes
    sql_query("TRUNCATE TABLE `regimages`") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete regimage codes");
    }
    //10.clean up user accounts
    // make sure VIP or above never get deleted
    $neverdelete_account = $neverdelete_account <= UC_VIP ? $neverdelete_account : UC_VIP;
    //delete inactive user accounts, no transfer. Alt. 1: last access time
    if ($deletenotransfer_account) {
        $secs = $deletenotransfer_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $maxclass = $neverdelete_account;
        sql_query("DELETE FROM users WHERE parked='no' AND status='confirmed' AND class < {$maxclass} AND last_access < {$dt} AND (uploaded = 0 || uploaded = " . sqlesc($iniupload_main) . ") AND downloaded = 0") or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("delete inactive user accounts, no transfer. Alt. 1: last access time");
    }
    //delete inactive user accounts, no transfer. Alt. 2: registering time
    if ($deletenotransfertwo_account) {
        $secs = $deletenotransfertwo_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $maxclass = $neverdelete_account;
        sql_query("DELETE FROM users WHERE parked='no' AND status='confirmed' AND class < {$maxclass} AND added < {$dt} AND (uploaded = 0 || uploaded = " . sqlesc($iniupload_main) . ") AND downloaded = 0") or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("delete inactive user accounts, no transfer. Alt. 2: registering time");
    }
    //delete inactive user accounts, not parked
    if ($deleteunpacked_account) {
        $secs = $deleteunpacked_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $maxclass = $neverdelete_account;
        sql_query("DELETE FROM users WHERE parked='no' AND status='confirmed' AND class < {$maxclass} AND last_access < {$dt}") or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("delete inactive user accounts, not parked");
    }
    //delete parked user accounts, parked
    if ($deletepacked_account) {
        $secs = $deletepacked_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $maxclass = $neverdeletepacked_account;
        sql_query("DELETE FROM users WHERE parked='yes' AND status='confirmed' AND class < {$maxclass} AND last_access < {$dt}") or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("delete parked user accounts, parked");
    }
    //remove VIP status if time's up
    $res = sql_query("SELECT id, modcomment FROM users WHERE vip_added='yes' AND vip_until < NOW()") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            $dt = sqlesc(date("Y-m-d H:i:s"));
            $subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_vip_status_removed']);
            $msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_vip_status_removed_body']);
            ///---AUTOSYSTEM MODCOMMENT---//
            $modcomment = htmlspecialchars($arr["modcomment"]);
            $modcomment = date("Y-m-d") . " - VIP status removed by - AutoSystem.\n" . $modcomment;
            $modcom = sqlesc($modcomment);
            ///---end
            sql_query("UPDATE users SET class = '1', vip_added = 'no', vip_until = '0000-00-00 00:00:00', modcomment = {$modcom} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, {$dt}, {$msg}, {$subject})") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("remove VIP status if time's up");
    }
    // promote peasant back to user
    function peasant_to_user($down_floor_gb, $down_roof_gb, $minratio)
    {
        global $lang_cleanup_target;
        if ($down_floor_gb) {
            $downlimit_floor = $down_floor_gb * 1024 * 1024 * 1024;
            $downlimit_roof = $down_roof_gb * 1024 * 1024 * 1024;
            $res = sql_query("SELECT id FROM users WHERE class = 0 AND downloaded >= {$downlimit_floor} " . ($downlimit_roof > $down_floor_gb ? " AND downloaded < {$downlimit_roof}" : "") . " AND uploaded / downloaded >= {$minratio}") or sqlerr(__FILE__, __LINE__);
            if (mysql_num_rows($res) > 0) {
                $dt = sqlesc(date("Y-m-d H:i:s"));
                while ($arr = mysql_fetch_assoc($res)) {
                    $subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_low_ratio_warning_removed']);
                    $msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_your_ratio_warning_removed']);
                    writecomment($arr[id], "Leech Warning removed by System.");
                    sql_query("UPDATE users SET class = 1, leechwarn = 'no', leechwarnuntil = '0000-00-00 00:00:00' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                    sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, {$subject}, {$msg})") or sqlerr(__FILE__, __LINE__);
                }
            }
        }
    }
    peasant_to_user($psdlfive_account, 0, $psratiofive_account);
    peasant_to_user($psdlfour_account, $psdlfive_account, $psratiofour_account);
    peasant_to_user($psdlthree_account, $psdlfour_account, $psratiothree_account);
    peasant_to_user($psdltwo_account, $psdlthree_account, $psratiotwo_account);
    peasant_to_user($psdlone_account, $psdltwo_account, $psratioone_account);
    if ($printProgress) {
        printProgress("promote peasant back to user");
    }
    //end promote peasant back to user
    // start promotion
    function promotion($class, $down_floor_gb, $minratio, $time_week, $addinvite = 0)
    {
        global $lang_cleanup_target;
        $oriclass = $class - 1;
        if ($down_floor_gb) {
            $limit = $down_floor_gb * 1024 * 1024 * 1024;
            $maxdt = date("Y-m-d H:i:s", TIMENOW - 86400 * 7 * $time_week);
            $res = sql_query("SELECT id, max_class_once FROM users WHERE class = {$oriclass} AND downloaded >= {$limit} AND uploaded / downloaded >= {$minratio} AND added < " . sqlesc($maxdt)) or sqlerr(__FILE__, __LINE__);
            if (mysql_num_rows($res) > 0) {
                $dt = sqlesc(date("Y-m-d H:i:s"));
                while ($arr = mysql_fetch_assoc($res)) {
                    $subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_promoted_to'] . get_user_class_name($class, false, false, false));
                    $msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_now_you_are'] . get_user_class_name($class, false, false, false) . $lang_cleanup_target[get_user_lang($arr[id])]['msg_see_faq']);
                    if ($class <= $arr[max_class_once]) {
                        sql_query("UPDATE users SET class = {$class} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                    } else {
                        sql_query("UPDATE users SET class = {$class}, max_class_once={$class}, invites=invites+{$addinvite} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                    }
                    sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, {$subject}, {$msg})") or sqlerr(__FILE__, __LINE__);
                }
            }
        }
    }
    //do not change the ascending order
    promotion(UC_POWER_USER, $pudl_account, $puprratio_account, $putime_account, $getInvitesByPromotion_class[UC_POWER_USER]);
    promotion(UC_ELITE_USER, $eudl_account, $euprratio_account, $eutime_account, $getInvitesByPromotion_class[UC_ELITE_USER]);
    promotion(UC_CRAZY_USER, $cudl_account, $cuprratio_account, $cutime_account, $getInvitesByPromotion_class[UC_CRAZY_USER]);
    promotion(UC_INSANE_USER, $iudl_account, $iuprratio_account, $iutime_account, $getInvitesByPromotion_class[UC_INSANE_USER]);
    promotion(UC_VETERAN_USER, $vudl_account, $vuprratio_account, $vutime_account, $getInvitesByPromotion_class[UC_VETERAN_USER]);
    promotion(UC_EXTREME_USER, $exudl_account, $exuprratio_account, $exutime_account, $getInvitesByPromotion_class[UC_EXTREME_USER]);
    promotion(UC_ULTIMATE_USER, $uudl_account, $uuprratio_account, $uutime_account, $getInvitesByPromotion_class[UC_ULTIMATE_USER]);
    promotion(UC_NEXUS_MASTER, $nmdl_account, $nmprratio_account, $nmtime_account, $getInvitesByPromotion_class[UC_NEXUS_MASTER]);
    // end promotion
    if ($printProgress) {
        printProgress("promote users to other classes");
    }
    // start demotion
    function demotion($class, $deratio)
    {
        global $lang_cleanup_target;
        $newclass = $class - 1;
        $res = sql_query("SELECT id FROM users WHERE class = {$class} AND uploaded / downloaded < {$deratio}") or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($res) > 0) {
            $dt = sqlesc(date("Y-m-d H:i:s"));
            while ($arr = mysql_fetch_assoc($res)) {
                $subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_demoted_to'] . get_user_class_name($newclass, false, false, false);
                $msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_demoted_from'] . get_user_class_name($class, false, false, false) . $lang_cleanup_target[get_user_lang($arr[id])]['msg_to'] . get_user_class_name($newclass, false, false, false) . $lang_cleanup_target[get_user_lang($arr[id])]['msg_because_ratio_drop_below'] . $deratio . ".\n";
                sql_query("UPDATE users SET class = {$newclass} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
            }
        }
    }
    //do not change the descending order
    demotion(UC_NEXUS_MASTER, $nmderatio_account);
    demotion(UC_ULTIMATE_USER, $uuderatio_account);
    demotion(UC_EXTREME_USER, $exuderatio_account);
    demotion(UC_VETERAN_USER, $vuderatio_account);
    demotion(UC_INSANE_USER, $iuderatio_account);
    demotion(UC_CRAZY_USER, $cuderatio_account);
    demotion(UC_ELITE_USER, $euderatio_account);
    demotion(UC_POWER_USER, $puderatio_account);
    if ($printProgress) {
        printProgress("demote users to other classes");
    }
    // end demotion
    // start demote users to peasant
    function user_to_peasant($down_floor_gb, $minratio)
    {
        global $lang_cleanup_target;
        global $deletepeasant_account;
        $length = $deletepeasant_account * 86400;
        // warn users until xxx days
        $until = date("Y-m-d H:i:s", TIMENOW + $length);
        $downlimit_floor = $down_floor_gb * 1024 * 1024 * 1024;
        $res = sql_query("SELECT id FROM users WHERE class = 1 AND downloaded > {$downlimit_floor} AND uploaded / downloaded < {$minratio}") or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($res) > 0) {
            $dt = sqlesc(date("Y-m-d H:i:s"));
            while ($arr = mysql_fetch_assoc($res)) {
                $subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_demoted_to'] . get_user_class_name(UC_PEASANT, false, false, false);
                $msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_must_fix_ratio_within'] . $deletepeasant_account . $lang_cleanup_target[get_user_lang($arr[id])]['msg_days_or_get_banned'];
                writecomment($arr[id], "Leech Warned by System - Low Ratio.");
                sql_query("UPDATE users SET class = 0 , leechwarn = 'yes', leechwarnuntil = " . sqlesc($until) . " WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
            }
        }
    }
    user_to_peasant($psdlone_account, $psratioone_account);
    user_to_peasant($psdltwo_account, $psratiotwo_account);
    user_to_peasant($psdlthree_account, $psratiothree_account);
    user_to_peasant($psdlfour_account, $psratiofour_account);
    user_to_peasant($psdlfive_account, $psratiofive_account);
    if ($printProgress) {
        printProgress("demote Users to peasant");
    }
    // end Users to Peasant
    //ban users with leechwarning expired
    $dt = sqlesc(date("Y-m-d H:i:s"));
    // take date time
    $res = sql_query("SELECT id FROM users WHERE enabled = 'yes' AND leechwarn = 'yes' AND leechwarnuntil < {$dt}") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            writecomment($arr[id], "Banned by System because of Leech Warning expired.");
            sql_query("UPDATE users SET enabled = 'no', leechwarnuntil = '0000-00-00 00:00:00' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("ban users with leechwarning expired");
    }
    //Remove warning of users
    $dt = sqlesc(date("Y-m-d H:i:s"));
    // take date time
    $res = sql_query("SELECT id FROM users WHERE enabled = 'yes' AND warned = 'yes' AND warneduntil < {$dt}") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            $subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_warning_removed'];
            $msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_your_warning_removed'];
            writecomment($arr[id], "Warning removed by System.");
            sql_query("UPDATE users SET warned = 'no', warneduntil = '0000-00-00 00:00:00' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("remove warning of users");
    }
    //17.update total seeding and leeching time of users
    $res = sql_query("SELECT * FROM users") or sqlerr(__FILE__, __LINE__);
    while ($arr = mysql_fetch_assoc($res)) {
        //die("s" . $arr['id']);
        $res2 = sql_query("SELECT SUM(seedtime) as st, SUM(leechtime) as lt FROM snatched where userid = " . $arr['id'] . " LIMIT 1") or sqlerr(__FILE__, __LINE__);
        $arr2 = mysql_fetch_assoc($res2) or sqlerr(__FILE__, __LINE__);
        //die("ss" . $arr2['st']);
        //die("sss" . "UPDATE users SET seedtime = " . $arr2['st'] . ", leechtime = " . $arr2['lt'] . " WHERE id = " . $arr['id']);
        sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("update total seeding and leeching time of users");
    }
    // delete torrents that have been dead for a long time
    if ($deldeadtorrent_torrent > 0) {
        $length = $deldeadtorrent_torrent * 86400;
        $until = date("Y-m-d H:i:s", TIMENOW - $length);
        $dt = sqlesc(date("Y-m-d H:i:s"));
        $res = sql_query("SELECT id, name, owner FROM torrents WHERE visible = 'no' AND last_action < " . sqlesc($until) . " AND seeders = 0 AND leechers = 0") or sqlerr(__FILE__, __LINE__);
        while ($arr = mysql_fetch_assoc($res)) {
            deletetorrent($arr['id']);
            $subject = $lang_cleanup_target[get_user_lang($arr[owner])]['msg_your_torrent_deleted'];
            $msg = $lang_cleanup_target[get_user_lang($arr[owner])]['msg_your_torrent'] . "[i]" . $arr['name'] . "[/i]" . $lang_cleanup_target[get_user_lang($arr[owner])]['msg_was_deleted_because_dead'];
            sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['owner']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
            write_log("Torrent {$arr['id']} ({$arr['name']}) is deleted by system because of being dead for a long time.", 'normal');
        }
    }
    if ($printProgress) {
        printProgress("delete torrents that have been dead for a long time");
    }
    //Priority Class 5: cleanup every 15 days
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime5'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime5',{$now})") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_five > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 4';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime5'") or sqlerr(__FILE__, __LINE__);
    }
    //update clients' popularity
    $res = sql_query("SELECT id FROM agent_allowed_family");
    while ($row = mysql_fetch_array($res)) {
        $count = get_row_count("users", "WHERE clientselect=" . sqlesc($row['id']));
        sql_query("UPDATE agent_allowed_family SET hits=" . sqlesc($count) . " WHERE id=" . sqlesc($row['id']));
    }
    if ($printProgress) {
        printProgress("update clients' popularity");
    }
    //delete old messages sent by system
    $length = 180 * 86400;
    //half a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    sql_query("DELETE FROM messages WHERE sender = 0 AND added < " . sqlesc($until));
    if ($printProgress) {
        printProgress("delete old messages sent by system");
    }
    //delete old readpost records
    $length = 180 * 86400;
    //half a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    $postIdHalfYearAgo = get_single_value('posts', 'id', 'WHERE added < ' . sqlesc($until) . ' ORDER BY added DESC');
    if ($postIdHalfYearAgo) {
        sql_query("UPDATE users SET last_catchup = " . sqlesc($postIdHalfYearAgo) . " WHERE last_catchup < " . sqlesc($postIdHalfYearAgo));
        sql_query("DELETE FROM readposts WHERE lastpostread < " . sqlesc($postIdHalfYearAgo));
    }
    if ($printProgress) {
        printProgress("delete old readpost records");
    }
    //delete old ip log
    $length = 365 * 86400;
    //a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    sql_query("DELETE FROM iplog WHERE access < " . sqlesc($until));
    if ($printProgress) {
        printProgress("delete old ip log");
    }
    //delete old general log
    $secs = 365 * 86400;
    //a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    sql_query("DELETE FROM sitelog WHERE added < " . sqlesc($until)) or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete old general log");
    }
    //1.delete torrents that doesn't exist any more
    do {
        $res = sql_query("SELECT id FROM torrents") or sqlerr(__FILE__, __LINE__);
        $ar = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            $ar[$id] = 1;
        }
        if (!count($ar)) {
            break;
        }
        $dp = @opendir($torrent_dir);
        if (!$dp) {
            break;
        }
        $ar2 = array();
        while (($file = readdir($dp)) !== false) {
            if (!preg_match('/^(\\d+)\\.torrent$/', $file, $m)) {
                continue;
            }
            $id = $m[1];
            $ar2[$id] = 1;
            if (isset($ar[$id]) && $ar[$id]) {
                continue;
            }
            $ff = $torrent_dir . "/{$file}";
            unlink($ff);
        }
        closedir($dp);
        if (!count($ar2)) {
            break;
        }
        $delids = array();
        foreach (array_keys($ar) as $k) {
            if (isset($ar2[$k]) && $ar2[$k]) {
                continue;
            }
            $delids[] = $k;
            unset($ar[$k]);
        }
        if (count($delids)) {
            sql_query("DELETE FROM torrents WHERE id IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
        }
        $res = sql_query("SELECT torrent FROM peers GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
        $delids = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            if (isset($ar[$id]) && $ar[$id]) {
                continue;
            }
            $delids[] = $id;
        }
        if (count($delids)) {
            sql_query("DELETE FROM peers WHERE torrent IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
        }
        $res = sql_query("SELECT torrent FROM files GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
        $delids = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            if ($ar[$id]) {
                continue;
            }
            $delids[] = $id;
        }
        if (count($delids)) {
            sql_query("DELETE FROM files WHERE torrent IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
        }
    } while (0);
    if ($printProgress) {
        printProgress("delete torrents that doesn't exist any more");
    }
    //8.lock topics where last post was made more than x days ago
    $secs = 365 * 24 * 60 * 60;
    sql_query("UPDATE topics, posts SET topics.locked='yes' WHERE topics.lastpost = posts.id AND topics.sticky = 'no' AND UNIX_TIMESTAMP(posts.added) < " . TIMENOW . " - {$secs}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("lock topics where last post was made more than x days ago");
    }
    //9.delete report items older than four week
    $secs = 4 * 7 * 24 * 60 * 60;
    $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
    sql_query("DELETE FROM reports WHERE dealtwith=1 AND added < {$dt}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete report items older than four week");
    }
    return 'Full cleanup is done';
}
Esempio n. 6
0
            $updateset[] = "nfo = " . sqlesc(str_replace("\r\r\n", "\r\n", file_get_contents($nfofilename)));
        }
        $Cache->delete_value('nfo_block_torrent_id_' . $id);
    } elseif ($nfoaction == "remove") {
        $updateset[] = "nfo = ''";
        $Cache->delete_value('nfo_block_torrent_id_' . $id);
    }
}
$catid = 0 + $type;
if (!is_valid_id($catid)) {
    bark($lang_takeedit['std_missing_form_data']);
}
if (!$name || !$descr) {
    bark($lang_takeedit['std_missing_form_data']);
}
$newcatmode = get_single_value("categories", "mode", "WHERE id=" . sqlesc($catid));
if ($enablespecial == 'yes' && get_user_class() >= $movetorrent_class) {
    $allowmove = true;
} else {
    $allowmove = false;
}
if ($oldcatmode != $newcatmode && !$allowmove) {
    bark($lang_takeedit['std_cannot_move_torrent']);
}
$updateset[] = "anonymous = '" . ($_POST["anonymous"] ? "yes" : "no") . "'";
$updateset[] = "name = " . sqlesc($name);
$updateset[] = "descr = " . sqlesc($descr);
$updateset[] = "url = " . sqlesc($url);
$updateset[] = "douban_url = " . sqlesc($douban_url);
$updateset[] = "small_descr = " . sqlesc($_POST["small_descr"]);
//$updateset[] = "ori_descr = " . sqlesc($descr);
Esempio n. 7
0
function insert_compose_frame($id, $type = 'new')
{
	global $maxsubjectlength, $CURUSER;
	global $lang_forums;
	$hassubject = false;
	$subject = "";
	$body = "";
	print("<form id=\"compose\" method=\"post\" name=\"compose\" action=\"?action=post\">\n");
	switch ($type){
		case 'new':
		{
			$forumname = get_single_value("forums","name","WHERE id=".sqlesc($id));
			$title = $lang_forums['text_new_topic_in']." <a href=\"".htmlspecialchars("?action=viewforum&forumid=".$id)."\">".htmlspecialchars($forumname)."</a> ".$lang_forums['text_forum'];
			$hassubject = true;
			if($id == 5)$subject = "【悬赏***麦粒】【求*****】";
			break;
		}
		case 'reply':
		{
			$topicname = get_single_value("topics","subject","WHERE id=".sqlesc($id));
			$title = $lang_forums['text_reply_to_topic']." <a href=\"".htmlspecialchars("?action=viewtopic&topicid=".$id)."\">".htmlspecialchars($topicname)."</a> ";
			break;
		}
		case 'quote':
		{
			$topicid=get_single_value("posts","topicid","WHERE id=".sqlesc($id));
			$topicname = get_single_value("topics","subject","WHERE id=".sqlesc($topicid));
			$title = $lang_forums['text_reply_to_topic']." <a href=\"".htmlspecialchars("?action=viewtopic&topicid=".$topicid)."\">".htmlspecialchars($topicname)."</a> ";
			$res = sql_query("SELECT posts.body, users.username FROM posts LEFT JOIN users ON posts.userid = users.id WHERE posts.id=$id") or sqlerr(__FILE__, __LINE__);
			if (mysql_num_rows($res) != 1)
				stderr($lang_forums['std_error'], $lang_forums['std_no_post_id']);
			$arr = mysql_fetch_assoc($res);
			$arr["body"] = preg_replace('/\[(@)([^\]]*?)\]/','[b]@$2[/b]',$arr["body"]);
			$body = "[quote=".htmlspecialchars($arr["username"])."]".htmlspecialchars(unesc($arr["body"]))."[/quote]";
			$id = $topicid;
			$type = 'quote';
			break;
		}
		case 'edit':
		{
			$res = sql_query("SELECT topicid, body FROM posts WHERE id=".sqlesc($id)." LIMIT 1") or sqlerr(__FILE__, __LINE__);
			$row = mysql_fetch_array($res);
			$topicid=$row['topicid'];
			$firstpost = get_single_value("posts","MIN(id)", "WHERE topicid=".sqlesc($topicid));
			if ($firstpost == $id){
				$subject = get_single_value("topics","subject","WHERE id=".sqlesc($topicid));
				$onlyauthor = get_single_value("topics","onlyauthor","WHERE id=".sqlesc($topicid));
				$hassubject = true;
			}
			$body = htmlspecialchars(unesc($row["body"]));
			$title = $lang_forums['text_edit_post'];
			break;
		}
		default:
		{
			die;
		}
	}
	print("<input type=\"hidden\" name=\"id\" value=\"".$id."\" />");
	print("<input type=\"hidden\" name=\"type\" value=\"".$type."\" />");
	begin_compose($title, $type, $body, $hassubject, $subject,$maxsubjectlength, $onlyauthor);
	end_compose();
	print("</form>");
}
Esempio n. 8
0
function get_view_count($tab, $start_dt, $end_dt, $app_id)
{
    if ($start_dt == '') {
        $start_dt = date("Y-m-d H:i:s");
    }
    if ($end_dt == '') {
        $end_dt = date("Y-m-d H:i:s");
    }
    $app_views = get_single_value($tab, "sum(views)", "DATE_FORMAT(dateupdated,'%Y-%m-%d')>='{$start_dt}' AND \r\n\tDATE_FORMAT(dateupdated,'%Y-%m-%d')<='{$end_dt}' AND app_id={$app_id}");
    if ($app_views == '') {
        $app_views = 0;
    }
    return $app_views;
}
Esempio n. 9
0
function get_css_uri($file = "")
{
    $cssRow = get_css_row();
    $ss_uri = $cssRow['uri'];
    if (!$ss_uri) {
        $ss_uri = get_single_value("stylesheets", "uri", "WHERE id=" . sqlesc($defcss));
    }
    if ($file == "") {
        return $ss_uri;
    } else {
        return $ss_uri . $file;
    }
}
Esempio n. 10
0
     } else {
         $warneduntil = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")) + $warnlength * 604800);
         $dur = $warnlength . $lang_modtask_target[get_user_lang($userid)]['msg_week'] . ($warnlength > 1 ? $lang_modtask_target[get_user_lang($userid)]['msg_s'] : "");
         $msg = sqlesc($lang_modtask_target[get_user_lang($userid)]['msg_you_are_warned_for'] . $dur . $lang_modtask_target[get_user_lang($userid)]['msg_by'] . $CURUSER['username'] . "." . ($warnpm ? $lang_modtask_target[get_user_lang($userid)]['msg_reason'] . $warnpm : ""));
         $modcomment = date("Y-m-d") . " - Warned for {$dur} by " . $CURUSER['username'] . ".\nReason: {$warnpm}.\n" . $modcomment;
         $updateset[] = "warneduntil = '{$warneduntil}'";
     }
     $subject = sqlesc($lang_modtask_target[get_user_lang($userid)]['msg_you_are_warned']);
     $added = sqlesc(date("Y-m-d H:i:s"));
     sql_query("INSERT INTO messages (sender, receiver, subject, msg, added) VALUES (0, {$userid}, {$subject}, {$msg}, {$added})") or sqlerr(__FILE__, __LINE__);
     $updateset[] = "warned = 'yes', timeswarned = timeswarned+1, lastwarned={$added}, warnedby={$CURUSER['id']}";
 }
 if ($enabled != $curenabled) {
     if ($enabled == 'yes') {
         $modcomment = date("Y-m-d") . " - Enabled by " . $CURUSER['username'] . ".\n" . $modcomment;
         if (get_single_value("users", "class", "WHERE id = " . sqlesc($userid)) == UC_PEASANT) {
             $length = 30 * 86400;
             // warn users until 30 days
             $until = sqlesc(date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")) + $length));
             sql_query("UPDATE users SET enabled='yes', leechwarn='yes', leechwarnuntil={$until} WHERE id = " . sqlesc($userid));
         } else {
             sql_query("UPDATE users SET enabled='yes', leechwarn='no' WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
         }
     } else {
         $modcomment = date("Y-m-d") . " - Disabled by " . $CURUSER['username'] . ".\n" . $modcomment;
     }
 }
 if ($arr['noad'] != $noad) {
     $updateset[] = 'noad = ' . sqlesc($noad);
     $modcomment = date("Y-m-d") . " - No Ad set to " . $noad . " by " . $CURUSER['username'] . ".\n" . $modcomment;
 }
Esempio n. 11
0
 function dltable($name, $arr, $torrent)
 {
     global $lang_viewpeerlist, $viewanonymous_class, $userprofile_class, $enablelocation_tweak;
     global $CURUSER;
     $s = "<b>" . count($arr) . " {$name}</b>\n";
     if (!count($arr)) {
         return $s;
     }
     $s .= "\n";
     $s .= "<table width=825 class=main border=1 cellspacing=0 cellpadding=3>\n";
     $s .= "<tr><td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_user_ip'] . "</td>" . ($enablelocation_tweak == 'yes' || get_user_class() >= $userprofile_class ? "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_location'] . "</td>" : "") . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_connectable'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_uploaded'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_rate'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_downloaded'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_rate'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_ratio'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_complete'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_connected'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_idle'] . "</td>" . "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_client'] . "</td></tr>\n";
     $now = time();
     foreach ($arr as $e) {
         $privacy = get_single_value("users", "privacy", "WHERE id=" . sqlesc($e['userid']));
         ++$num;
         $highlight = $CURUSER["id"] == $e['userid'] ? " bgcolor=#BBAF9B" : "";
         $s .= "<tr{$highlight}>\n";
         if ($privacy == "strong" || $torrent['anonymous'] == 'yes' && $e['userid'] == $torrent['owner']) {
             if (get_user_class() >= $viewanonymous_class || $e['userid'] == $CURUSER['id']) {
                 $s .= "<td class=rowfollow align=left width=1%><i>" . $lang_viewpeerlist['text_anonymous'] . "</i><br />(" . get_username($e['userid']) . ")";
             } else {
                 $s .= "<td class=rowfollow align=left width=1%><i>" . $lang_viewpeerlist['text_anonymous'] . "</i></a></td>\n";
             }
         } else {
             $s .= "<td class=rowfollow align=left width=1%>" . get_username($e['userid']);
         }
         $secs = max(1, $e["la"] - $e["st"]);
         if ($enablelocation_tweak == 'yes') {
             list($loc_pub, $loc_mod) = get_ip_location($e["ip"]);
             $location = get_user_class() >= $userprofile_class ? "<div title='" . $loc_mod . "'>" . $loc_pub . "</div>" : $loc_pub;
             $s .= "<td class=rowfollow align=center width=1%><nobr>" . $location . "</nobr></td>\n";
         } elseif (get_user_class() >= $userprofile_class) {
             $location = $e["ip"];
             $s .= "<td class=rowfollow align=center width=1%><nobr>" . $location . "</nobr></td>\n";
         } else {
             $location = "";
         }
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . ($e[connectable] == "yes" ? $lang_viewpeerlist['text_yes'] : "<font color=red>" . $lang_viewpeerlist['text_no'] . "</font>") . "</nobr></td>\n";
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize($e["uploaded"]) . "</nobr></td>\n";
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</nobr></td>\n";
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize($e["downloaded"]) . "</nobr></td>\n";
         if ($e["seeder"] == "no") {
             $s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</nobr></td>\n";
         } else {
             $s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e[st])) . "/s</nobr></td>\n";
         }
         if ($e["downloaded"]) {
             $ratio = floor($e["uploaded"] / $e["downloaded"] * 1000) / 1000;
             $s .= "<td class=rowfollow align=\"center\" width=1%><font color=" . get_ratio_color($ratio) . "><nobr>" . number_format($ratio, 3) . "</nobr></font></td>\n";
         } elseif ($e["uploaded"]) {
             $s .= "<td class=rowfollow align=center width=1%>" . $lang_viewpeerlist['text_inf'] . "</td>\n";
         } else {
             $s .= "<td class=rowfollow align=center width=1%>---</td>\n";
         }
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . sprintf("%.2f%%", 100 * (1 - $e["to_go"] / $torrent["size"])) . "</nobr></td>\n";
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . mkprettytime($now - $e["st"]) . "</nobr></td>\n";
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . mkprettytime($now - $e["la"]) . "</nobr></td>\n";
         $s .= "<td class=rowfollow align=center width=1%><nobr>" . htmlspecialchars(get_agent($e["peer_id"], $e["agent"])) . "</nobr></td>\n";
         $s .= "</tr>\n";
     }
     $s .= "</table>\n";
     return $s;
 }
Esempio n. 12
0
function docleanup($forceAll = 0, $printProgress = false)
{
    //require_once(get_langfile_path("cleanup.php",true));
    global $lang_cleanup_target;
    global $torrent_dir, $signup_timeout, $max_dead_torrent_time, $autoclean_interval_one, $autoclean_interval_two, $autoclean_interval_three, $autoclean_interval_four, $autoclean_interval_five, $SITENAME, $bonus, $invite_timeout, $offervotetimeout_main, $offeruptimeout_main, $iniupload_main;
    global $donortimes_bonus, $perseeding_bonus, $maxseeding_bonus, $tzero_bonus, $nzero_bonus, $bzero_bonus, $l_bonus;
    global $expirehalfleech_torrent, $expirefree_torrent, $expiretwoup_torrent, $expiretwoupfree_torrent, $expiretwouphalfleech_torrent, $expirethirtypercentleech_torrent, $expirenormal_torrent, $hotdays_torrent, $hotseeder_torrent, $halfleechbecome_torrent, $freebecome_torrent, $twoupbecome_torrent, $twoupfreebecome_torrent, $twouphalfleechbecome_torrent, $thirtypercentleechbecome_torrent, $normalbecome_torrent, $deldeadtorrent_torrent;
    global $neverdelete_account, $neverdeletepacked_account, $deletepacked_account, $deleteunpacked_account, $deletenotransfer_account, $deletenotransfertwo_account, $deletepeasant_account, $psdlone_account, $psratioone_account, $psdltwo_account, $psratiotwo_account, $psdlthree_account, $psratiothree_account, $psdlfour_account, $psratiofour_account, $psdlfive_account, $psratiofive_account, $putime_account, $pudl_account, $puprratio_account, $puderatio_account, $eutime_account, $eudl_account, $euprratio_account, $euderatio_account, $cutime_account, $cudl_account, $cuprratio_account, $cuderatio_account, $iutime_account, $iudl_account, $iuprratio_account, $iuderatio_account, $vutime_account, $vudl_account, $vuprratio_account, $vuderatio_account, $exutime_account, $exudl_account, $exuprratio_account, $exuderatio_account, $uutime_account, $uudl_account, $uuprratio_account, $uuderatio_account, $nmtime_account, $nmdl_account, $nmprratio_account, $nmderatio_account, $getInvitesByPromotion_class;
    global $enablenoad_advertisement, $noad_advertisement;
    global $Cache;
    global $memcache;
    set_time_limit(0);
    ignore_user_abort(1);
    $now = time();
    //Priority Class 1: cleanup every 15 mins
    //2.update peer status
    $deadtime = deadtime();
    $deadtime = date("Y-m-d H:i:s", $deadtime);
    sql_query("DELETE FROM peers WHERE last_action < " . sqlesc($deadtime)) or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress('更新种子状态last_action');
    }
    //11.calculate seeding bonus
    $res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        $sqrtof2 = sqrt(2);
        $logofpointone = log(0.1);
        $valueone = $logofpointone / $tzero_bonus;
        $pi = 3.141592653589793;
        $valuetwo = $bzero_bonus * (2 / $pi);
        $valuethree = $logofpointone / ($nzero_bonus - 1);
        $timenow = TIMENOW;
        $sectoweek = 7 * 24 * 60 * 60;
        while ($arr = mysql_fetch_assoc($res)) {
            $A = 0;
            $count = 0;
            $all_bonus = 0;
            $torrentres = sql_query("select torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = {$arr['userid']} AND peers.seeder ='yes'") or sqlerr(__FILE__, __LINE__);
            while ($torrent = mysql_fetch_array($torrentres)) {
                $weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
                $gb_size = $torrent['size'] / 1073741824;
                $temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent['seeders'] - 1)));
                $A += $temp;
                $count++;
            }
            if ($count > $maxseeding_bonus) {
                $count = $maxseeding_bonus;
            }
            $all_bonus = ($valuetwo * atan($A / $l_bonus) + $perseeding_bonus * $count) / (3600 / $autoclean_interval_one);
            $is_donor = get_single_value("users", "donor", "WHERE id=" . $arr['userid']);
            if ($is_donor == 'yes' && $donortimes_bonus > 0) {
                $all_bonus = $all_bonus * $donortimes_bonus;
            }
            KPS("+", $all_bonus, $arr["userid"]);
        }
    }
    if ($printProgress) {
        printProgress('为做种用户发放奖励');
    }
    //Priority Class 2: cleanup every 30 mins
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime2'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime2'," . sqlesc($now) . ")") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_two > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 1';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime2'") or sqlerr(__FILE__, __LINE__);
    }
    //2.5.update torrents' visibility
    $deadtime = deadtime() - $max_dead_torrent_time;
    sql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME({$deadtime}) AND seeders=0") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("更新种子的可见状态");
    }
    //Priority Class 3: cleanup every 60 mins
    //自动清理过期短信
    if (time() > 1323069888 + 604800) {
        $deltime = date("Y-m-d H:i:s", time() - 2592000);
        //一个月前时间
        sql_query("DELETE FROM messages WHERE location='1' AND added < '" . $deltime . "'") or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("清理过期短信");
    }
    //自动清理过期短信结束
    //将超过三天未登录用户重置salarynum
    $deltime = date("Y-m-d", time() - 86400 * 3);
    $res = sql_query("SELECT id FROM users WHERE  salarynum > 1 AND salary < '" . $deltime . "'") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        sql_query("UPDATE users SET salarynum = 1 WHERE id = {$row['id']}") or sqlerr(__FILE__, __LINE__);
        //write_log("系统qinglile yonghu salrty--- $row[id]",'normal');
    }
    if ($printProgress) {
        printProgress("将超过三天未登录用户重置salarynum");
    }
    //自动清理过期的回收站、候选区种子
    $deltime = date("Y-m-d H:i:s", time() - 86400 * 15);
    //这里默认15天
    $res = sql_query("SELECT id, name, status, owner FROM torrents WHERE status != 'normal' AND last_status < '" . $deltime . "'") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_array($res)) {
        deletetorrent($row['id']);
        $beforeStatus = getTorrentStatus($row['status']);
        sendMessage(0, $row['owner'], "你在回收站里的种子被删除了", "系统自动清理:{$beforeStatus} 种子 {$row['id']} ({$row['name']}) 被系统自动删除了 。原因是: (长时间未处理)");
        write_log("系统自动清理:{$beforeStatus} 种子 {$row['id']} ({$row['name']}) 被系统自动删除了 。原因是: (长时间未处理)", 'normal');
        //sendDelMsg($row['id'], "系统自动清理:$beforeStatus 种子 $row[id] ($row[name]) 被系统自动删除了 。原因是: (长时间未处理)", 'delete');
    }
    if ($printProgress) {
        printProgress("回收站过期种子清理");
    }
    //自动清理回收站,候选区结束
    //Priority Class 3: cleanup every 60 mins
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime3'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime3',{$now})") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_three > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 2';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime3'") or sqlerr(__FILE__, __LINE__);
    }
    //4.update count of seeders, leechers, comments for torrents
    $torrents = array();
    $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        if ($row["seeder"] == "yes") {
            $key = "seeders";
        } else {
            $key = "leechers";
        }
        $torrents[$row["torrent"]][$key] = $row["c"];
    }
    $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        $torrents[$row["torrent"]]["comments"] = $row["c"];
    }
    $fields = explode(":", "comments:leechers:seeders");
    $res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        $id = $row["id"];
        $torr = $torrents[$id];
        foreach ($fields as $field) {
            if (!isset($torr[$field])) {
                $torr[$field] = 0;
            }
        }
        $update = array();
        foreach ($fields as $field) {
            if ($torr[$field] != $row[$field]) {
                $update[] = "{$field} = " . $torr[$field];
            }
        }
        if (count($update)) {
            sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = {$id}") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("更新做种、下载、评论数量");
    }
    //set no-advertisement-by-bonus time out
    sql_query("UPDATE users SET noad='no' WHERE noaduntil < " . sqlesc(date("Y-m-d H:i:s")) . ($enablenoad_advertisement == 'yes' ? " AND class < " . sqlesc($noad_advertisement) : ""));
    if ($printProgress) {
        printProgress("判断麦粒购买不显示广告截止set no-advertisement-by-bonus time out");
    }
    //12. update forum post/topic count
    $forums = sql_query("select id from forums") or sqlerr(__FILE__, __LINE__);
    while ($forum = mysql_fetch_assoc($forums)) {
        $postcount = 0;
        $topiccount = 0;
        $topics = sql_query("select id from topics where forumid={$forum['id']}") or sqlerr(__FILE__, __LINE__);
        while ($topic = mysql_fetch_assoc($topics)) {
            $res = sql_query("select count(*) from posts where topicid={$topic['id']}") or sqlerr(__FILE__, __LINE__);
            $arr = mysql_fetch_row($res);
            $postcount += $arr[0];
            ++$topiccount;
        }
        sql_query("update forums set postcount={$postcount}, topiccount={$topiccount} where id={$forum['id']}") or sqlerr(__FILE__, __LINE__);
    }
    $Cache->delete_value('forums_list');
    if ($printProgress) {
        printProgress("更新论坛主题/帖子数量update forum post/topic count");
    }
    //14.cleanup offers
    //Delete offers if not voted on after some time
    if ($offervotetimeout_main) {
        $secs = (int) $offervotetimeout_main;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $offervotetimeout_main));
        $res = sql_query("SELECT id, name FROM offers WHERE added < {$dt} AND allowed <> 'allowed'") or sqlerr(__FILE__, __LINE__);
        while ($arr = mysql_fetch_assoc($res)) {
            sql_query("DELETE FROM offers WHERE id={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM offervotes WHERE offerid={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM comments WHERE offer={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            write_log("系统自动清理:Offer {$arr['id']} ({$arr['name']}) was deleted by system (vote timeout)", 'normal');
        }
    }
    if ($printProgress) {
        printProgress("删除候选(无用)delete offers if not voted on after some time");
    }
    //Delete offers if not uploaded after being voted on for some time.
    if ($offeruptimeout_main) {
        $secs = (int) $offeruptimeout_main;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $res = sql_query("SELECT id, name FROM offers WHERE allowedtime < {$dt} AND allowed = 'allowed'") or sqlerr(__FILE__, __LINE__);
        while ($arr = mysql_fetch_assoc($res)) {
            sql_query("DELETE FROM offers WHERE id={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM offervotes WHERE offerid={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("DELETE FROM comments WHERE offer={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            write_log("系统自动清理:Offer {$arr['id']} ({$arr['name']}) was deleted by system (upload timeout)", 'normal');
        }
    }
    if ($printProgress) {
        printProgress("删除候选(无用)delete offers if not uploaded after being voted on for some time.");
    }
    //15.cleanup torrents
    //Start: expire torrent promotion
    function torrent_promotion_expire($days, $type = 2, $targettype = 1)
    {
        $secs = (int) ($days * 86400);
        //XX days
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $res = sql_query("SELECT id, name FROM torrents WHERE added < {$dt} AND sp_state = " . sqlesc($type) . ' AND promotion_time_type=0') or sqlerr(__FILE__, __LINE__);
        switch ($targettype) {
            case 1:
                $sp_state = 1;
                $become = "normal";
                break;
            case 2:
                $sp_state = 2;
                $become = "Free";
                break;
            case 3:
                $sp_state = 3;
                $become = "2X";
                break;
            case 4:
                $sp_state = 4;
                $become = "2X Free";
                break;
            case 5:
                $sp_state = 5;
                $become = "50%";
                break;
            case 6:
                $sp_state = 6;
                $become = "2X 50%";
                break;
            default:
                $sp_state = 1;
                $become = "normal";
                break;
        }
        while ($arr = mysql_fetch_assoc($res)) {
            sql_query("UPDATE torrents SET sp_state = " . sqlesc($sp_state) . " WHERE id={$arr['id']}") or sqlerr(__FILE__, __LINE__);
            if ($sp_state == 1) {
                write_log("系统自动清理:Torrent {$arr['id']} ({$arr['name']}) is no longer on promotion (time expired)", 'normal');
            } else {
                write_log("系统自动清理:Promotion type for torrent {$arr['id']} ({$arr['name']}) is changed to " . $become . " (time expired)", 'normal');
            }
        }
    }
    if ($expirehalfleech_torrent) {
        torrent_promotion_expire($expirehalfleech_torrent, 5, $halfleechbecome_torrent);
    }
    if ($expirefree_torrent) {
        torrent_promotion_expire($expirefree_torrent, 2, $freebecome_torrent);
    }
    if ($expiretwoup_torrent) {
        torrent_promotion_expire($expiretwoup_torrent, 3, $twoupbecome_torrent);
    }
    if ($expiretwoupfree_torrent) {
        torrent_promotion_expire($expiretwoupfree_torrent, 4, $twoupfreebecome_torrent);
    }
    if ($expiretwouphalfleech_torrent) {
        torrent_promotion_expire($expiretwouphalfleech_torrent, 6, $twouphalfleechbecome_torrent);
    }
    if ($expirethirtypercentleech_torrent) {
        torrent_promotion_expire($expirethirtypercentleech_torrent, 7, $thirtypercentleechbecome_torrent);
    }
    if ($expirenormal_torrent) {
        torrent_promotion_expire($expirenormal_torrent, 1, $normalbecome_torrent);
    }
    //expire individual torrent promotion
    sql_query("UPDATE torrents SET sp_state = 1, promotion_time_type=0, promotion_until='0000-00-00 00:00:00' WHERE promotion_time_type=2 AND promotion_until < " . sqlesc(date("Y-m-d H:i:s", TIMENOW))) or sqlerr(__FILE__, __LINE__);
    //End: expire torrent promotion
    if ($printProgress) {
        printProgress("判断种子促销截止expire torrent promotion");
    }
    //automatically pick hot
    if ($hotdays_torrent) {
        $secs = (int) ($hotdays_torrent * 86400);
        //XX days
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        sql_query("UPDATE torrents SET picktype = 'hot' WHERE added > {$dt} AND picktype = 'normal' AND seeders > " . sqlesc($hotseeder_torrent)) or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("判断种子是否热门automatically pick hot");
    }
    //Priority Class 4: cleanup every 24 hours
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime4'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime4',{$now})") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_four > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 3';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime4'") or sqlerr(__FILE__, __LINE__);
    }
    //3.delete unconfirmed accounts
    $deadtime = time() - $signup_timeout;
    $delres = sql_query("SELECT id, username FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME({$deadtime}) AND last_login < FROM_UNIXTIME({$deadtime}) AND last_access < FROM_UNIXTIME({$deadtime})");
    while ($userinfo = mysql_fetch_assoc($delres)) {
        record_op_log(0, $userinfo['id'], $userinfo['username'], 'del', '账号审核未通过');
        sql_query("DELETE FROM users WHERE id='" . $userinfo['id'] . "'") or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("删除未通过审核的账户delete unconfirmed accounts");
    }
    //5.delete old login attempts
    $secs = 12 * 60 * 60;
    // Delete failed login attempts per half day.
    $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
    // calculate date.
    sql_query("DELETE FROM loginattempts WHERE banned='no' AND added < {$dt}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("删除长时间未活动的附件delete old login attempts");
    }
    //6.delete old invite codes
    $secs = $invite_timeout * 24 * 60 * 60;
    // when?
    $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
    // calculate date.
    sql_query("DELETE FROM invites WHERE time_invited < {$dt}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("删除未发布的邀请码delete old invite codes");
    }
    //7.delete regimage codes
    sql_query("TRUNCATE TABLE `regimages`") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete regimage codes");
    }
    //10.clean up user accounts
    $deletetitle = '你在麦田pt的账号将要被删除';
    $body = "你好,你在麦田pt注册的账号 {$userinfo['username']}  已经连续 " . $deletenotransfer_account * 0.8 . "天未登录,由于你的账号没有产生流量,如果连续{$deletenotransfer_account} 天未登录,你的账号将会被删除。\n 麦田pt期待您的回归,我们的地址是 pt.nwsuaf6.edu.cn  如果没有ipv6环境可以使用pt.nwsuaf6.edu.cn.ipv4.sixxs.org 登陆账号";
    // make sure VIP or above never get deleted
    $neverdelete_account = $neverdelete_account <= UC_VIP ? $neverdelete_account : UC_VIP;
    //delete inactive user accounts, no transfer. Alt. 1: last access time
    if ($deletenotransfer_account) {
        $secs = $deletenotransfer_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $maxclass = $neverdelete_account;
        /*发邮件
        		$secs2 = $secs*0.8;
        		$dt2 = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs2)));
        		$delres = sql_query("SELECT id, username, email FROM users WHERE parked='no' AND status='confirmed' AND class < $maxclass AND last_access < $dt2 AND (uploaded = 0 || uploaded = ".sqlesc($iniupload_main).") AND downloaded = 0");
        		$notransfererr=0;$notransferdone=0;
        		$notransferemail = array();
        		while ($userinfo = mysql_fetch_assoc($delres)){
                            if(	sent_mail($userinfo['email'], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, false, '', get_email_encode(get_langfolder_cookie()),'noerror'))
        						{$emailflag =1;$notransferdone++;}
        					else
        					{$emailflag =0;
        					$notransfererr++;continue;}
        				$notransferemail[] = $userinfo['email'];$notransfererr++;
                        }
        			if(sent_mail($notransferemail[0], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, true, $notransferemail, get_email_encode(get_langfolder_cookie()),'noerror'))	
        			write_log("系统自动发送邮件:给$notransfererr 位注册后连续".$deletenotransfer_account*0.8 ." 天未登录且无流量用户发送邮件提醒",'normal');
        			else write_log("系统自动发送邮件:有$notransfererr 位无流量用户发送邮件失败!!!!!!!$notransferdone 位成功".__LINE__,'normal');
        			if ($printProgress) {
        		printProgress("给注册后连续".$deletenotransfer_account*0.8 ." 天未登录且无流量用户发送邮件提醒");
        	}
        	*/
        $delres = sql_query("SELECT id, username FROM users WHERE parked='no' AND status='confirmed' AND class < {$maxclass} AND last_access < {$dt} AND (uploaded = 0 || uploaded = " . sqlesc($iniupload_main) . ") AND downloaded = 0");
        while ($userinfo = mysql_fetch_assoc($delres)) {
            record_op_log(0, $userinfo['id'], $userinfo['username'], 'del', '无流量账号连续' . $deletenotransfer_account . '天未登录');
            sql_query("DELETE FROM users WHERE id='" . $userinfo['id'] . "'") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("删除无流量未登录用户delete inactive user accounts, no transfer. Alt. 1: last access time");
    }
    //delete inactive user accounts, no transfer. Alt. 2: registering time
    if ($deletenotransfertwo_account) {
        $secs = $deletenotransfertwo_account * 24 * 60 * 60;
        $secs2 = $secs * 1.8;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $dt2 = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs2));
        $maxclass = $neverdelete_account;
        /*发送email
        		$notransfererr1=0;$notransferdone1=0;
        		$notransferemail1 = array();
        		$delres = sql_query("SELECT id, username, email FROM users WHERE  parked='no' AND status='confirmed' AND class < $maxclass AND added < $dt2 AND (uploaded = 0 || uploaded = ".sqlesc($iniupload_main).") AND downloaded = 0");
                       while ($userinfo = mysql_fetch_assoc($delres)){
                            if(	sent_mail($userinfo['email'], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, false, '', get_email_encode(get_langfolder_cookie()),'noerror'))
        						$emailflag =1;
        					else
        					{$notransfererr1++;$emailflag =0;continue;}
        				$notransferemail1[] = $userinfo['email'];$notransfererr1++;
                        }
        			if(sent_mail($notransferemail1[0], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, true, $notransferemail1, get_email_encode(get_langfolder_cookie()),'noerror'))
        			write_log("系统自动发送邮件:给$notransfererr1 位注册后连续".$deletenotransfertwo_account*0.8 ." 天未登录且无流量用户发送邮件提醒",'normal');
        			else write_log("系统自动发送邮件:有$notransfererr1 位长时间未登录用户发送邮件失败!!!!$notransferdone1 位成功!!!".__LINE__,'normal');
        			if ($printProgress) {
        		printProgress("给注册后连续".$deletenotransfertwo_account*0.8 ." 天未登录用户发送邮件提醒");
        	}*/
        //delete
        $delres = sql_query("SELECT id, username FROM users WHERE  parked='no' AND status='confirmed' AND class < {$maxclass} AND added < {$dt} AND (uploaded = 0 || uploaded = " . sqlesc($iniupload_main) . ") AND downloaded = 0");
        while ($userinfo = mysql_fetch_assoc($delres)) {
            record_op_log(0, $userinfo['id'], $userinfo['username'], 'del', '注册' . $deletenotransfertwo_account . '天后仍未产生任何流量');
            sql_query("DELETE FROM users WHERE id='" . $userinfo['id'] . "'") or sqlerr(__FILE__, __LINE__);
        }
        if ($printProgress) {
            printProgress("删除无流量未登录用户delete inactive user accounts, no transfer. Alt. 2: registering time");
        }
    }
    //delete inactive user accounts, not parked
    if ($deleteunpacked_account) {
        $secs = $deleteunpacked_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $secs2 = $secs * 0.8;
        $dt2 = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs2));
        $maxclass = $neverdelete_account;
        /*
        	$uppackederrnum =0;$uppackeddonenum =0;
        	$uppackedemail = array();
        		$body = "你好,你在麦田pt注册的账号 {$userinfo['username']}  已经连续 ".$deleteunpacked_account*0.8 ."天未登录,由于你的账号没有封存,如果连续$deleteunpacked_account 天未登录,你的账号将会被删除。\n 麦田pt期待您的回归,我们的地址是 pt.nwsuaf6.edu.cn  如果没有ipv6环境可以使用pt.nwsuaf6.edu.cn.ipv4.sixxs.org 登陆账号";
                        $delres = sql_query("SELECT id, username,email FROM users WHERE parked='no' AND status='confirmed' AND class < $maxclass AND last_access < $dt2");
                        while ($userinfo = mysql_fetch_assoc($delres)){
                            if(	sent_mail($userinfo['email'], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, false, '', get_email_encode(get_langfolder_cookie()),'noerror'))
        			{$emailflag =1;$uppackeddonenum++;}
        				else
        				{$uppackederrnum++;$emailflag =0;continue;}
        			$uppackedemail[] = $userinfo['email'];$uppackederrnum++;
                        }
        		if(sent_mail($uppackedemail[0], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, true, $uppackedemail, get_email_encode(get_langfolder_cookie()),'noerror'))	
        		write_log("系统自动发送邮件:给$uppackederrnum 位未封存账号连续".$deleteunpacked_account*0.8 ." 天未登录用户发送邮件提醒",'normal');
        		else write_log("系统自动发送邮件:有$uppackederrnum 位封存长时间未登录用户发送邮件失败!!!$uppackeddonenum 位成功!!!!".__LINE__,'normal');
        		if ($printProgress) {
        	printProgress("给未封存账号连续".$deleteunpacked_account*0.8 ." 天未登录用户发送邮件提醒");
        }
        */
        //delete
        $delres = sql_query("SELECT id, username FROM users WHERE parked='no' AND status='confirmed' AND class < {$maxclass} AND last_access < {$dt}");
        while ($userinfo = mysql_fetch_assoc($delres)) {
            record_op_log(0, $userinfo['id'], $userinfo['username'], 'del', '未封存账号连续' . $deleteunpacked_account . '天未登录');
            sql_query("DELETE FROM users WHERE id='" . $userinfo['id'] . "'") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("删除未封存长时间未登录用户delete inactive user accounts, not parked");
    }
    //delete parked user accounts, parked
    if ($deletepacked_account) {
        $secs = $deletepacked_account * 24 * 60 * 60;
        $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
        $secs2 = $secs * 0.8;
        $dt2 = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs2));
        $maxclass = $neverdeletepacked_account;
        /*发邮件
        		$packednum=0;$packeddonenum=0;
        		 $packedemail[] = array();
        			$body ="你好,你在麦田pt注册的账号 {$userinfo['username']}  已经连续 ".$deletepacked_account*0.8 ."天未登录,虽然你的账号已经封存,但是如果连续$deletepacked_account 天未登录,你的账号仍然会被删除。\n 麦田pt期待您的回归,我们的地址是 pt.nwsuaf6.edu.cn  如果没有ipv6环境可以使用pt.nwsuaf6.edu.cn.ipv4.sixxs.org 登陆账号";
                        $delres = sql_query("SELECT id, username, email FROM users WHERE parked='yes' AND status='confirmed' AND class < $maxclass AND last_access < $dt2");
        				
                        while ($userinfo = mysql_fetch_assoc($delres)){
                            if(	sent_mail($userinfo['email'], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, false, '', get_email_encode(get_langfolder_cookie()),'noerror'))
        						{$emailflag =1;$packeddonenum++;}
        					else
        					{$emailflag =0;continue;}
        					$packednum++;
        					$packedemail[] = $userinfo['email'];
                        }
        				if (sent_mail($packedemail[0], $SITENAME, $SITEEMAIL, change_email_encode(get_langfolder_cookie(), $deletetitle), change_email_encode(get_langfolder_cookie(),$body), '', false, true, $packedemail, get_email_encode(get_langfolder_cookie()),'noerror'))
        			write_log("系统自动发送邮件:给$packednum 位封存账号连续".$deletepacked_account*0.8 ." 天未登录用户发送邮件提醒",'normal');
        			else write_log("系统自动发送邮件:有$packednum 位封存账号发送邮件失败!!!!!!!".__LINE__,'normal');
        			if ($printProgress) {
        		printProgress("给封存账号连续".$deletepacked_account*0.8 ." 天未登录用户发送邮件提醒");
        	}
        	*/
        //delete
        $delres = sql_query("SELECT id, username FROM users WHERE parked='yes' AND status='confirmed' AND class < {$maxclass} AND last_access < {$dt}");
        while ($userinfo = mysql_fetch_assoc($delres)) {
            record_op_log(0, $userinfo['id'], $userinfo['username'], 'del', '封存账号连续' . $deletepacked_account . '天未登录');
            sql_query("DELETE FROM users WHERE id='" . $userinfo['id'] . "'") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("删除长时间未登录的封存用户delete parked user accounts, parked");
    }
    //remove VIP status if time's up
    $res = sql_query("SELECT id, modcomment FROM users WHERE vip_added='yes' AND vip_until < NOW()") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            $dt = sqlesc(date("Y-m-d H:i:s"));
            $subject = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_vip_status_removed']);
            $msg = sqlesc($lang_cleanup_target[get_user_lang($arr[id])]['msg_vip_status_removed_body']);
            ///---AUTOSYSTEM MODCOMMENT---//
            $modcomment = htmlspecialchars($arr["modcomment"]);
            $modcomment = date("Y-m-d") . " - VIP status removed by - AutoSystem.\n" . $modcomment;
            $modcom = sqlesc($modcomment);
            ///---end
            sql_query("UPDATE users SET class = '1', vip_added = 'no', vip_until = '0000-00-00 00:00:00', modcomment = {$modcom} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, {$dt}, {$msg}, {$subject})") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("判断购买vip到期remove VIP status if time's up");
    }
    // promote peasant back to user
    function peasant_to_user($down_floor_gb, $down_roof_gb, $minratio)
    {
        global $lang_cleanup_target;
        if ($down_floor_gb) {
            $downlimit_floor = $down_floor_gb * 1024 * 1024 * 1024;
            $downlimit_roof = $down_roof_gb * 1024 * 1024 * 1024;
            $res = sql_query("SELECT id FROM users WHERE class = 0 AND downloaded >= {$downlimit_floor} " . ($downlimit_roof > $down_floor_gb ? " AND downloaded < {$downlimit_roof}" : "") . " AND uploaded / downloaded >= {$minratio}") or sqlerr(__FILE__, __LINE__);
            if (mysql_num_rows($res) > 0) {
                $dt = sqlesc(date("Y-m-d H:i:s"));
                while ($arr = mysql_fetch_assoc($res)) {
                    $subject = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_low_ratio_warning_removed']);
                    $msg = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_your_ratio_warning_removed']);
                    writecomment($arr['id'], "Leech Warning removed by System.");
                    sql_query("UPDATE users SET class = 1, leechwarn = 'no', leechwarnuntil = '0000-00-00 00:00:00' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                    sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, {$subject}, {$msg})") or sqlerr(__FILE__, __LINE__);
                }
            }
        }
    }
    peasant_to_user($psdlfive_account, 0, $psratiofive_account);
    peasant_to_user($psdlfour_account, $psdlfive_account, $psratiofour_account);
    peasant_to_user($psdlthree_account, $psdlfour_account, $psratiothree_account);
    peasant_to_user($psdltwo_account, $psdlthree_account, $psratiotwo_account);
    peasant_to_user($psdlone_account, $psdltwo_account, $psratioone_account);
    if ($printProgress) {
        printProgress("土豆判断升级promote peasant back to user");
    }
    //end promote peasant back to user
    // start promotion
    function promotion($class, $down_floor_gb, $minratio, $time_week, $addinvite = 0)
    {
        global $lang_cleanup_target;
        $oriclass = $class - 1;
        if ($down_floor_gb) {
            $limit = $down_floor_gb * 1024 * 1024 * 1024;
            $maxdt = date("Y-m-d H:i:s", TIMENOW - 86400 * 7 * $time_week);
            $res = sql_query("SELECT id, max_class_once FROM users WHERE class = {$oriclass} AND downloaded >= {$limit} AND uploaded / downloaded >= {$minratio} AND added < " . sqlesc($maxdt)) or sqlerr(__FILE__, __LINE__);
            if (mysql_num_rows($res) > 0) {
                $dt = sqlesc(date("Y-m-d H:i:s"));
                while ($arr = mysql_fetch_assoc($res)) {
                    $subject = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_promoted_to'] . get_user_class_name($class, false, false, false));
                    $msg = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_now_you_are'] . get_user_class_name($class, false, false, false) . $lang_cleanup_target[get_user_lang($arr['id'])]['msg_see_faq']);
                    if ($class <= $arr[max_class_once]) {
                        sql_query("UPDATE users SET class = {$class} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                    } else {
                        sql_query("UPDATE users SET class = {$class}, max_class_once={$class}, invites=invites+{$addinvite} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                    }
                    sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, {$subject}, {$msg})") or sqlerr(__FILE__, __LINE__);
                }
            }
        }
    }
    //do not change the ascending order
    promotion(UC_POWER_USER, $pudl_account, $puprratio_account, $putime_account, $getInvitesByPromotion_class[UC_POWER_USER]);
    promotion(UC_ELITE_USER, $eudl_account, $euprratio_account, $eutime_account, $getInvitesByPromotion_class[UC_ELITE_USER]);
    promotion(UC_CRAZY_USER, $cudl_account, $cuprratio_account, $cutime_account, $getInvitesByPromotion_class[UC_CRAZY_USER]);
    promotion(UC_INSANE_USER, $iudl_account, $iuprratio_account, $iutime_account, $getInvitesByPromotion_class[UC_INSANE_USER]);
    promotion(UC_VETERAN_USER, $vudl_account, $vuprratio_account, $vutime_account, $getInvitesByPromotion_class[UC_VETERAN_USER]);
    promotion(UC_EXTREME_USER, $exudl_account, $exuprratio_account, $exutime_account, $getInvitesByPromotion_class[UC_EXTREME_USER]);
    promotion(UC_ULTIMATE_USER, $uudl_account, $uuprratio_account, $uutime_account, $getInvitesByPromotion_class[UC_ULTIMATE_USER]);
    promotion(UC_NEXUS_MASTER, $nmdl_account, $nmprratio_account, $nmtime_account, $getInvitesByPromotion_class[UC_NEXUS_MASTER]);
    // end promotion
    if ($printProgress) {
        printProgress("升级判定promote users to other classes");
    }
    // start demotion
    function demotion($class, $deratio)
    {
        global $lang_cleanup_target;
        $newclass = $class - 1;
        $res = sql_query("SELECT id FROM users WHERE class = {$class} AND uploaded / downloaded < {$deratio}") or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($res) > 0) {
            $dt = sqlesc(date("Y-m-d H:i:s"));
            while ($arr = mysql_fetch_assoc($res)) {
                $subject = $lang_cleanup_target[get_user_lang($arr['id'])]['msg_demoted_to'] . get_user_class_name($newclass, false, false, false);
                $msg = $lang_cleanup_target[get_user_lang($arr['id'])]['msg_demoted_from'] . get_user_class_name($class, false, false, false) . $lang_cleanup_target[get_user_lang($arr['id'])]['msg_to'] . get_user_class_name($newclass, false, false, false) . $lang_cleanup_target[get_user_lang($arr['id'])]['msg_because_ratio_drop_below'] . $deratio . ".\n";
                sql_query("UPDATE users SET class = {$newclass} WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
            }
        }
    }
    //do not change the descending order
    demotion(UC_NEXUS_MASTER, $nmderatio_account);
    demotion(UC_ULTIMATE_USER, $uuderatio_account);
    demotion(UC_EXTREME_USER, $exuderatio_account);
    demotion(UC_VETERAN_USER, $vuderatio_account);
    demotion(UC_INSANE_USER, $iuderatio_account);
    demotion(UC_CRAZY_USER, $cuderatio_account);
    demotion(UC_ELITE_USER, $euderatio_account);
    demotion(UC_POWER_USER, $puderatio_account);
    if ($printProgress) {
        printProgress("降级判定demote users to other classes");
    }
    // end demotion
    // start demote users to peasant
    function user_to_peasant($down_floor_gb, $minratio)
    {
        global $lang_cleanup_target;
        global $deletepeasant_account;
        $length = $deletepeasant_account * 86400;
        // warn users until xxx days
        $until = date("Y-m-d H:i:s", TIMENOW + $length);
        $downlimit_floor = $down_floor_gb * 1024 * 1024 * 1024;
        $res = sql_query("SELECT id FROM users WHERE class = 1 AND downloaded > {$downlimit_floor} AND uploaded / downloaded < {$minratio}") or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($res) > 0) {
            $dt = sqlesc(date("Y-m-d H:i:s"));
            while ($arr = mysql_fetch_assoc($res)) {
                $subject = $lang_cleanup_target[get_user_lang($arr['id'])]['msg_demoted_to'] . get_user_class_name(UC_PEASANT, false, false, false);
                $msg = $lang_cleanup_target[get_user_lang($arr['id'])]['msg_must_fix_ratio_within'] . $deletepeasant_account . $lang_cleanup_target[get_user_lang($arr['id'])]['msg_days_or_get_banned'];
                writecomment($arr['id'], "Leech Warned by System - Low Ratio.");
                sql_query("UPDATE users SET class = 0 , leechwarn = 'yes', leechwarnuntil = " . sqlesc($until) . " WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
            }
        }
    }
    user_to_peasant($psdlone_account, $psratioone_account);
    user_to_peasant($psdltwo_account, $psratiotwo_account);
    user_to_peasant($psdlthree_account, $psratiothree_account);
    user_to_peasant($psdlfour_account, $psratiofour_account);
    user_to_peasant($psdlfive_account, $psratiofive_account);
    if ($printProgress) {
        printProgress("降级到土豆demote Users to peasant");
    }
    // end Users to Peasant
    //ban users with leechwarning expired
    $length = 1 * 86400;
    // warn users until xxx days
    $dt = date("Y-m-d H:i:s", TIMENOW - $length);
    $res = sql_query("SELECT id, seedbonus FROM users WHERE enabled = 'yes' AND leechwarn = 'yes' AND leechwarnuntil < '{$dt}'") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            $addup = $arr['seedbonus'] * 2222222;
            writeBonusComment($arr[id], "即将被封号,系统自动将所有麦粒换成上传量.");
            sql_query("UPDATE users SET uploaded = uploaded + {$addup},seedbonus = 0 WHERE id =" . $arr['id']) or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("系统自动将一天后即将被封号的土豆的所有麦粒换成上传量");
    }
    $dt = sqlesc(date("Y-m-d H:i:s"));
    // take date time
    $res = sql_query("SELECT id, username FROM users WHERE enabled = 'yes' AND leechwarn = 'yes' AND leechwarnuntil < {$dt}") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            writecomment($arr[id], "Banned by System because of Leech Warning expired.");
            record_op_log(0, $arr['id'], $arr['username'], 'ban', '持续未改善分享率');
            sql_query("UPDATE users SET enabled = 'no', leechwarnuntil = '0000-00-00 00:00:00' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("ban掉持续未改善分享率的土豆ban users with leechwarning expired");
    }
    //Remove warning of users//同时如果被禁言、禁止上传下载的话,一同恢复
    $dt = sqlesc(date("Y-m-d H:i:s"));
    // take date time
    $res = sql_query("SELECT id,forumpost,uploadpos,downloadpos FROM users WHERE enabled = 'yes' AND warned = 'yes' AND warneduntil < {$dt}") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0) {
        while ($arr = mysql_fetch_assoc($res)) {
            $subject = $lang_cleanup_target[get_user_lang($arr[id])]['msg_warning_removed'];
            $msg = $lang_cleanup_target[get_user_lang($arr[id])]['msg_your_warning_removed'];
            if ($arr['forumpost'] == 'no') {
                sql_query("UPDATE users SET forumpost = 'yes' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                $msg .= "。你的禁言同时被解除。";
            }
            if ($arr['uploadpos'] == 'no') {
                sql_query("UPDATE users SET uploadpos = 'yes' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                $msg .= "。你的禁止上传处罚同时被解除。";
            }
            if ($arr['downloadpos'] == 'no') {
                sql_query("UPDATE users SET downloadpos = 'yes' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
                $msg .= "。你的禁止下载处罚同时被解除。";
            }
            writecomment($arr[id], "Warning removed by System.");
            sql_query("UPDATE users SET warned = 'no', warneduntil = '0000-00-00 00:00:00' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__);
            sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
        }
    }
    if ($printProgress) {
        printProgress("移除警告,同时移除处罚remove warning of users");
    }
    //17.update total seeding and leeching time of users
    $res = sql_query("SELECT * FROM users") or sqlerr(__FILE__, __LINE__);
    while ($arr = mysql_fetch_assoc($res)) {
        //die("s" . $arr['id']);
        $res2 = sql_query("SELECT SUM(seedtime) as st, SUM(leechtime) as lt FROM snatched where userid = " . $arr['id'] . " LIMIT 1") or sqlerr(__FILE__, __LINE__);
        $arr2 = mysql_fetch_assoc($res2) or sqlerr(__FILE__, __LINE__);
        //die("ss" . $arr2['st']);
        //die("sss" . "UPDATE users SET seedtime = " . $arr2['st'] . ", leechtime = " . $arr2['lt'] . " WHERE id = " . $arr['id']);
        sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("update total seeding and leeching time of users");
    }
    // delete torrents that have been dead for a long time
    if ($deldeadtorrent_torrent > 0) {
        $length = $deldeadtorrent_torrent * 86400;
        $until = date("Y-m-d H:i:s", TIMENOW - $length);
        $dt = sqlesc(date("Y-m-d H:i:s"));
        $res = sql_query("SELECT id, name, owner FROM torrents WHERE visible = 'no' AND last_action < " . sqlesc($until) . " AND seeders = 0 AND leechers = 0") or sqlerr(__FILE__, __LINE__);
        while ($arr = mysql_fetch_assoc($res)) {
            deletetorrent($arr['id']);
            $subject = $lang_cleanup_target[get_user_lang($arr[owner])]['msg_your_torrent_deleted'];
            $msg = $lang_cleanup_target[get_user_lang($arr[owner])]['msg_your_torrent'] . "[i]" . $arr['name'] . "[/i]" . $lang_cleanup_target[get_user_lang($arr[owner])]['msg_was_deleted_because_dead'];
            sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['owner']}, {$dt}, " . sqlesc($subject) . ", " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
            write_log("系统自动清理:系统删除了断种 {$arr['id']} ({$arr['name']})", 'normal');
        }
    }
    if ($printProgress) {
        printProgress("清理断种delete torrents that have been dead for a long time");
    }
    //彩票开奖
    drawlotteryfun();
    if ($printProgress) {
        printProgress("彩票开奖");
    }
    //Priority Class 5: cleanup every 15 days
    $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime5'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime5',{$now})") or sqlerr(__FILE__, __LINE__);
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval_five > $now && !$forceAll) {
        return 'Cleanup ends at Priority Class 4';
    } else {
        sql_query("UPDATE avps SET value_u = " . sqlesc($now) . " WHERE arg='lastcleantime5'") or sqlerr(__FILE__, __LINE__);
    }
    //update clients' popularity
    $res = sql_query("SELECT id FROM agent_allowed_family");
    while ($row = mysql_fetch_array($res)) {
        $count = get_row_count("users", "WHERE clientselect=" . sqlesc($row['id']));
        sql_query("UPDATE agent_allowed_family SET hits=" . sqlesc($count) . " WHERE id=" . sqlesc($row['id']));
    }
    if ($printProgress) {
        printProgress("update clients' popularity");
    }
    //delete old messages sent by system
    $length = 180 * 86400;
    //half a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    sql_query("DELETE FROM messages WHERE sender = 0 AND added < " . sqlesc($until));
    if ($printProgress) {
        printProgress("清理系统发的旧信息delete old messages sent by system");
    }
    //delete old readpost records
    $length = 180 * 86400;
    //half a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    //	$postIdHalfYearAgo = get_single_value('posts', 'id', 'WHERE added < ' . sqlesc($until).' ORDER BY added DESC');echo "333<br/>";这一行代码执行失败,暂时修改无能
    $postIdHalfYearAgo = 0;
    if ($postIdHalfYearAgo) {
        sql_query("UPDATE users SET last_catchup = " . sqlesc($postIdHalfYearAgo) . " WHERE last_catchup < " . sqlesc($postIdHalfYearAgo)) or sqlerr(__FILE__, __LINE__);
        sql_query("DELETE FROM readposts WHERE lastpostread < " . sqlesc($postIdHalfYearAgo)) or sqlerr(__FILE__, __LINE__);
    }
    if ($printProgress) {
        printProgress("delete old readpost records");
    }
    //delete old ip log
    $length = 365 * 86400;
    //a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    sql_query("DELETE FROM iplog WHERE access < " . sqlesc($until));
    if ($printProgress) {
        printProgress("删除旧的ip记录delete old ip log");
    }
    //delete old general log
    $secs = 365 * 86400;
    //a year
    $until = date("Y-m-d H:i:s", TIMENOW - $length);
    sql_query("DELETE FROM sitelog WHERE added < " . sqlesc($until)) or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete old general log");
    }
    //1.delete torrents that doesn't exist any more
    do {
        $res = sql_query("SELECT id FROM torrents") or sqlerr(__FILE__, __LINE__);
        $ar = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            $ar[$id] = 1;
        }
        if (!count($ar)) {
            break;
        }
        $dp = @opendir($torrent_dir);
        if (!$dp) {
            break;
        }
        $ar2 = array();
        while (($file = readdir($dp)) !== false) {
            if (!preg_match('/^(\\d+)\\.torrent$/', $file, $m)) {
                continue;
            }
            $id = $m[1];
            $ar2[$id] = 1;
            if (isset($ar[$id]) && $ar[$id]) {
                continue;
            }
            $ff = $torrent_dir . "/{$file}";
            unlink($ff);
        }
        closedir($dp);
        if (!count($ar2)) {
            break;
        }
        $delids = array();
        foreach (array_keys($ar) as $k) {
            if (isset($ar2[$k]) && $ar2[$k]) {
                continue;
            }
            $delids[] = $k;
            unset($ar[$k]);
        }
        if (count($delids)) {
            sql_query("DELETE FROM torrents WHERE id IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
        }
        $res = sql_query("SELECT torrent FROM peers GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
        $delids = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            if (isset($ar[$id]) && $ar[$id]) {
                continue;
            }
            $delids[] = $id;
        }
        if (count($delids)) {
            sql_query("DELETE FROM peers WHERE torrent IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
        }
        $res = sql_query("SELECT torrent FROM files GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
        $delids = array();
        while ($row = mysql_fetch_array($res)) {
            $id = $row[0];
            if ($ar[$id]) {
                continue;
            }
            $delids[] = $id;
        }
        if (count($delids)) {
            sql_query("DELETE FROM files WHERE torrent IN (" . join(",", $delids) . ")") or sqlerr(__FILE__, __LINE__);
        }
    } while (0);
    if ($printProgress) {
        printProgress("delete torrents that doesn't exist any more");
    }
    //8.lock topics where last post was made more than x days ago
    $secs = 365 * 24 * 60 * 60;
    sql_query("UPDATE topics, posts SET topics.locked='yes' WHERE topics.lastpost = posts.id AND topics.sticky = 'no' AND UNIX_TIMESTAMP(posts.added) < " . TIMENOW . " - {$secs}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("锁定长时间无活动帖子lock topics where last post was made more than x days ago");
    }
    //9.delete report items older than four week
    $secs = 4 * 7 * 24 * 60 * 60;
    $dt = sqlesc(date("Y-m-d H:i:s", TIMENOW - $secs));
    sql_query("DELETE FROM reports WHERE dealtwith=1 AND added < {$dt}") or sqlerr(__FILE__, __LINE__);
    if ($printProgress) {
        printProgress("delete report items older than four week");
    }
    return '所有清理结束Full cleanup is done';
}
Esempio n. 13
0
include "sendmail.php";
include "tablename.php";
include "message.php";
include_once 'imageTransform.php';
//................Paging file..............
include "newpaging.php";
$prs_pageing = new get_pageing_new();
include "newpaging_front.php";
$prs_pageing1 = new get_pageing_new1();
include "cmspaging.php";
$cms_pageing = new get_pageing_cms();
include "ajaxpaging.php";
$ajax_pageing = new get_pageing_ajax();
$session_id = session_id();
$adminsetting = array();
$adminmail = get_single_value(ADMIN, 'email', '1=1');
//$admintwitter=get_single_value (ADMIN,'twitter_acc','1=1');
//$adminfacebook=get_single_value (ADMIN,'facebook_acc','1=1');
//$adminsetting=single_row(ADMIN_SETTING,'*','1=1');
//$blog_url=get_single_value(ADMIN_SETTING,'blog_url','1=1');
//$paypal_acc=get_single_value (ADMIN,'paypal_acc','1=1');
//$def_currency = get_single_value (CURRENCY,'symbol','def = 1');
$cur_page_arr = split("/", $_SERVER['PHP_SELF']);
$cur_page = $cur_page_arr[count($cur_page_arr) - 1];
if ($cur_page == "login.php" || $cur_page == "signup.php") {
} else {
    $_SESSION["page"] = $cur_page;
}
//............search for the menu number [start].............
if (count($menu) > 0) {
    foreach ($menu as $k => $v) {
Esempio n. 14
0
     //			$res = sql_query("SELECT id, user, torrent, offer, request FROM comments WHERE id=".sqlesc($row['reportid']));
     $res = sql_query("SELECT id, user, torrent, offer, request FROM comments WHERE id=" . sqlesc($row['reportid']));
     if (mysql_num_rows($res) == 0) {
         $reporting = $lang_reports['text_comment_does_not_exist'];
     } else {
         $arr = mysql_fetch_array($res);
         if ($arr['torrent']) {
             $name = get_single_value("torrents", "name", "WHERE id=" . sqlesc($arr['torrent']));
             $url = "details.php?id=" . $arr['torrent'] . "#cid" . $row['reportid'];
             $of = $lang_reports['text_of_torrent'];
         } elseif ($arr['offer']) {
             $name = get_single_value("offers", "name", "WHERE id=" . sqlesc($arr['offer']));
             $url = "offers.php?id=" . $arr['offer'] . "&off_details=1#cid" . $row['reportid'];
             $of = $lang_reports['text_of_offer'];
         } elseif ($arr['request']) {
             $name = get_single_value("req", "name", "WHERE id=" . sqlesc($arr['request']));
             $url = "viewrequest.php?action=view&id=" . $arr['request'] . "&req_details=1#cid" . $row['reportid'];
             $of = $lang_reports['text_of_request'];
         } else {
             //Comment belongs to no one
             $of = "unknown";
         }
         $reporting = $lang_reports['text_comment_id'] . $row['reportid'] . $of . "<b><a href=\"" . $url . "\">" . htmlspecialchars($name) . "</a></b>" . $lang_reports['text_by'] . get_username($arr['user']);
         $reported = $arr['user'];
     }
     break;
 case "subtitle":
     $type = $lang_reports['text_subtitle'];
     $res = sql_query("SELECT id, torrent_id, title FROM subs WHERE id=" . sqlesc($row['reportid']));
     if (mysql_num_rows($res) == 0) {
         $reporting = $lang_reports['text_subtitle_does_not_exist'];
Esempio n. 15
0
function insert_compose_frame($id, $type = 'new')
{
    global $maxsubjectlength, $CURUSER;
    global $lang_forums;
    $hassubject = false;
    $hasmodechoose = false;
    $subject = "";
    $body = "";
    print "<form id=\"compose\" method=\"post\" name=\"compose\" action=\"?action=post\">\n";
    switch ($type) {
        case 'new':
            $forumname = get_single_value("forums", "name", "WHERE id=" . sqlesc($id));
            $forummode = get_single_value("forums", "casinomode", "WHERE id=" . sqlesc($id));
            $forummodeclass = get_single_value("forums", "casinoclass", "WHERE id=" . sqlesc($id));
            $title = $lang_forums['text_new_topic_in'] . " <a href=\"" . htmlspecialchars("?action=viewforum&forumid=" . $id) . "\">" . htmlspecialchars($forumname) . "</a> " . $lang_forums['text_forum'];
            $hassubject = true;
            if ($forummode && (get_user_class() >= $forummodeclass || is_forum_moderator($id, 'forum'))) {
                $hasmodechoose = true;
            }
            break;
        case 'reply':
            $topicname = get_single_value("topics", "subject", "WHERE id=" . sqlesc($id));
            $title = $lang_forums['text_reply_to_topic'] . " <a href=\"" . htmlspecialchars("?action=viewtopic&topicid=" . $id) . "\">" . htmlspecialchars($topicname) . "</a> ";
            break;
        case 'quote':
            $topicid = get_single_value("posts", "topicid", "WHERE id=" . sqlesc($id));
            $topicmode = get_single_value("topics", "casinomode", "WHERE id=" . sqlesc($topicid)) == "yes";
            $topicname = get_single_value("topics", "subject", "WHERE id=" . sqlesc($topicid));
            $title = $lang_forums['text_reply_to_topic'] . " <a href=\"" . htmlspecialchars("?action=viewtopic&topicid=" . $topicid) . "\">" . htmlspecialchars($topicname) . "</a> ";
            $res = sql_query("SELECT posts.body, users.username FROM posts LEFT JOIN users ON posts.userid = users.id WHERE posts.id={$id}") or sqlerr(__FILE__, __LINE__);
            if (mysql_num_rows($res) != 1) {
                stderr($lang_forums['std_error'], $lang_forums['std_no_post_id']);
            }
            $arr = mysql_fetch_assoc($res);
            if (!$topicmode) {
                $body = "[quote=" . htmlspecialchars($arr["username"]) . "]" . htmlspecialchars(unesc($arr["body"])) . "[/quote]";
            } else {
                $body = "[quote=" . htmlspecialchars($arr["username"]) . "]" . "[/quote]";
            }
            $id = $topicid;
            $type = 'reply';
            break;
        case 'edit':
            $res = sql_query("SELECT topicid, body FROM posts WHERE id=" . sqlesc($id) . " LIMIT 1") or sqlerr(__FILE__, __LINE__);
            $row = mysql_fetch_array($res);
            $topicid = $row['topicid'];
            $firstpost = get_single_value("posts", "MIN(id)", "WHERE topicid=" . sqlesc($topicid));
            if ($firstpost == $id) {
                $subject = get_single_value("topics", "subject", "WHERE id=" . sqlesc($topicid));
                $hassubject = true;
                $forumid = get_single_value("topics", "forumid", "WHERE id=" . sqlesc($topicid));
                $forummode = get_single_value("forums", "casinomode", "WHERE id=" . sqlesc($forumid));
                $forummodeclass = get_single_value("forums", "casinoclass", "WHERE id=" . sqlesc($forumid));
                if ($forummode && (get_user_class() >= $forummodeclass || is_forum_moderator($forumid, 'forum'))) {
                    $hasmodechoose = true;
                }
            }
            $body = htmlspecialchars(unesc($row["body"]));
            $title = $lang_forums['text_edit_post'];
            break;
        default:
            die;
    }
    print "<input type=\"hidden\" name=\"id\" value=\"" . $id . "\" />";
    print "<input type=\"hidden\" name=\"type\" value=\"" . $type . "\" />";
    begin_compose($title, $type, $body, $hassubject, $subject, 100, $hasmodechoose);
    end_compose();
    print "</form>";
}
Esempio n. 16
0
stdhead($lang_faq['head_faq']);
$Cache->new_page('faq', 900, true);
if (!$Cache->get_page()) {
    $Cache->add_whole_row();
    //make_folder("cache/" , get_langfolder_cookie());
    //cache_check ('faq');
    begin_main_frame();
    begin_frame($lang_faq['text_welcome_to'] . $SITENAME . " - " . $SLOGAN);
    print $lang_faq['text_welcome_content_one'] . $lang_faq['text_welcome_content_two'];
    end_frame();
    if ($CURUSER) {
        $lang_id = $CURUSER['lang'];
    } else {
        $lang_id = get_guest_lang_id();
    }
    $is_rulelang = get_single_value("language", "rule_lang", "WHERE id = " . sqlesc($lang_id));
    if (!$is_rulelang) {
        $lang_id = 6;
        //English
    }
    $res = sql_query("SELECT `id`, `link_id`, `question`, `flag` FROM `faq` WHERE `type`='categ' AND `lang_id` = " . sqlesc($lang_id) . " ORDER BY `order` ASC");
    while ($arr = mysql_fetch_array($res)) {
        $faq_categ[$arr[link_id]][title] = $arr[question];
        $faq_categ[$arr[link_id]][flag] = $arr[flag];
        $faq_categ[$arr[link_id]][link_id] = $arr[link_id];
    }
    $res = sql_query("SELECT `id`, `link_id`, `question`, `answer`, `flag`, `categ` FROM `faq` WHERE `type`='item' AND `lang_id` = " . sqlesc($lang_id) . " ORDER BY `order` ASC");
    while ($arr = mysql_fetch_array($res, MYSQL_BOTH)) {
        $faq_categ[$arr[categ]][items][$arr[id]][question] = $arr[question];
        $faq_categ[$arr[categ]][items][$arr[id]][answer] = $arr[answer];
        $faq_categ[$arr[categ]][items][$arr[id]][flag] = $arr[flag];
Esempio n. 17
0
        //$some_variable .= "(0, $row[userid], '" . date("Y-m-d H:i:s") . "', " . sqlesc($pn_msg) . ")";
        //=== use this if you DO have subject in your PMs
        sql_query("INSERT INTO messages (sender, subject, receiver, added, msg) VALUES (0, " . sqlesc($subject) . ", {$row['userid']}, " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc($pn_msg) . ")") or sqlerr(__FILE__, __LINE__);
        //=== use this if you do NOT have subject in your PMs
        //sql_query("INSERT INTO messages (sender, receiver, added, msg) VALUES ".$some_variable."") or sqlerr(__FILE__, __LINE__);
        //===end
    }
    //=== delete all offer stuff
    sql_query("DELETE FROM offers WHERE id = " . $offerid);
    sql_query("DELETE FROM offervotes WHERE offerid = " . $offerid);
    sql_query("DELETE FROM comments WHERE offer = " . $offerid);
}
//=== end notify people who voted on offer
/* Email notifs */
if ($emailnotify_smtp == 'yes' && $smtptype != 'none') {
    $cat = get_single_value("categories", "name", "WHERE id=" . sqlesc($catid));
    $res = sql_query("SELECT id, email, lang FROM users WHERE enabled='yes' AND parked='no' AND status='confirmed' AND notifs LIKE '%[cat{$catid}]%' AND notifs LIKE '%[email]%' ORDER BY lang ASC") or sqlerr(__FILE__, __LINE__);
    $uploader = $anon;
    $size = mksize($totallen);
    $description = format_comment($descr);
    //dirty code, change later
    $langfolder_array = array("en", "chs", "cht", "ko", "ja");
    $body_arr = array("en" => "", "chs" => "", "cht" => "", "ko" => "", "ja" => "");
    $i = 0;
    foreach ($body_arr as $body) {
        $body_arr[$langfolder_array[$i]] = <<<EOD
{$lang_takeupload_target[$langfolder_array[$i]]['mail_hi']}

{$lang_takeupload_target[$langfolder_array[$i]]['mail_new_torrent']}

{$lang_takeupload_target[$langfolder_array[$i]]['mail_torrent_name']}{$torrent}
Esempio n. 18
0
    die;
}
//=== end offer votes list
//=== offer votes
if ($_GET["vote"]) {
    $offerid = 0 + htmlspecialchars($_GET["id"]);
    $vote = htmlspecialchars($_GET["vote"]);
    if ($vote == 'against' && get_user_class() < $againstoffer_class) {
        stderr($lang_offers['std_error'], $lang_offers['std_smell_rat']);
    }
    if ($vote == 'yeah' || $vote == 'against') {
        $userid = 0 + $CURUSER["id"];
        $res = sql_query("SELECT * FROM offervotes WHERE offerid=" . sqlesc($offerid) . " AND userid=" . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
        $arr = mysql_fetch_assoc($res);
        $voted = $arr;
        $offer_userid = get_single_value("offers", "userid", "WHERE id=" . sqlesc($offerid));
        if ($offer_userid == $CURUSER['id']) {
            stderr($lang_offers['std_error'], $lang_offers['std_cannot_vote_youself']);
        } elseif ($voted) {
            stderr($lang_offers['std_already_voted'], $lang_offers['std_already_voted_note'] . "<a  href=offers.php?id={$offerid}&off_details=1>" . $lang_offers['std_back_to_offer_detail'], false);
        } else {
            sql_query("UPDATE offers SET {$vote} = {$vote} + 1 WHERE id=" . sqlesc($offerid)) or sqlerr(__FILE__, __LINE__);
            $res = sql_query("SELECT users.username, offers.userid, offers.name FROM offers LEFT JOIN users ON offers.userid = users.id WHERE offers.id = " . sqlesc($offerid)) or sqlerr(__FILE__, __LINE__);
            $arr = mysql_fetch_assoc($res);
            $rs = sql_query("SELECT yeah, against, allowed FROM offers WHERE id=" . sqlesc($offerid)) or sqlerr(__FILE__, __LINE__);
            $ya_arr = mysql_fetch_assoc($rs);
            $yeah = $ya_arr["yeah"];
            $against = $ya_arr["against"];
            $finishtime = date("Y-m-d H:i:s");
            //allowed and send offer voted on message
            if ($yeah - $against >= $minoffervotes && $ya_arr['allowed'] != "allowed") {
Esempio n. 19
0
    stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_post'] . $forumpost . $lang_report['text_of_topic'] . "<a href=\"forums.php?action=viewtopic&topicid=" . $arr['topicid'] . "&page=p" . htmlspecialchars($forumpost) . "#" . htmlspecialchars($forumpost) . "\"><b>" . htmlspecialchars($arr['subject']) . "</b></a>" . $lang_report['text_by'] . get_username($arr['postuserid']) . $lang_report['text_to_staff'] . "<br />" . $lang_report['text_reason_note'] . "<br /><form method=post action=report.php><input type=hidden name=takeforumpost value=\"" . htmlspecialchars($forumpost) . "\">" . $lang_report['text_reason_is'] . "<input type=text style=\"width: 200px\" name=reason><input type=submit value=\"" . $lang_report['submit_confirm'] . "\"></form>", false);
} elseif (isset($commentid)) {
    int_check($commentid);
    $res = sql_query("SELECT id, user, torrent, offer FROM comments WHERE id=" . sqlesc($commentid));
    if (mysql_num_rows($res) == 0) {
        stderr($lang_report['std_error'], $lang_report['std_invalid_comment_id']);
    }
    $arr = mysql_fetch_array($res);
    if ($arr['torrent']) {
        //Comment of torrent. BTW, this is shitty code!
        $name = get_single_value("torrents", "name", "WHERE id=" . sqlesc($arr['torrent']));
        $url = "details.php?id=" . $arr['torrent'] . "#" . $commentid;
        $of = $lang_report['text_of_torrent'];
    } elseif ($arr['offer']) {
        //Comment of offer
        $name = get_single_value("offers", "name", "WHERE id=" . sqlesc($arr['offer']));
        $url = "offers.php?id=" . $arr['offer'] . "&off_details=1#" . $commentid;
        $of = $lang_report['text_of_offer'];
    } else {
        //Comment belongs to no one
        stderr($lang_report['std_error'], $lang_report['std_orphaned_comment']);
    }
    stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_comment'] . $commentid . $of . "<a href=\"" . $url . "\"><b>" . htmlspecialchars($name) . "</b></a>" . $lang_report['text_by'] . get_username($arr['user']) . $lang_report['text_to_staff'] . "<br />" . $lang_report['text_reason_note'] . "<br /><form method=post action=report.php><input type=hidden name=takecommentid value=\"" . htmlspecialchars($commentid) . "\">" . $lang_report['text_reason_is'] . "<input type=text style=\"width: 200px\" name=reason><input type=submit value=\"" . $lang_report['submit_confirm'] . "\"></form>", false);
} elseif (isset($reportofferid)) {
    int_check($reportofferid);
    $res = sql_query("SELECT id,name FROM offers WHERE id=" . sqlesc($reportofferid));
    if (mysql_num_rows($res) == 0) {
        stderr($lang_report['std_error'], $lang_report['std_invalid_offer_id']);
    }
    $arr = mysql_fetch_array($res);
    stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_offer'] . "<a href=\"offers.php?id=" . $arr[id] . "&off_details=1\"><b>" . htmlspecialchars($arr['name']) . "</b></a>" . $lang_report['text_to_staff'] . "<br />" . $lang_report['text_reason_note'] . "<br /><form method=post action=report.php><input type=hidden name=takereportofferid value=\"" . htmlspecialchars($reportofferid) . "\">" . $lang_report['text_reason_is'] . "<input type=text style=\"width: 200px\" name=reason><input type=submit value=\"" . $lang_report['submit_confirm'] . "\"></form>", false);
Esempio n. 20
0
function get_message_number()
{
    return get_single_value("status", "value", "WHERE name = 'messagenumber'");
}