Ejemplo n.º 1
0
/**
 * Trim the threads to the page limit and delete posts which are older than limited
 */
function TrimToPageLimit($board)
{
    global $tc_db;
    if ($board['maxage'] != 0) {
        // If the maximum thread age setting is not zero (do not delete old threads), find posts which are older than the limit, and delete them
        $results = $tc_db->GetAll("SELECT `id`, `timestamp` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0 AND `stickied` = 0 AND ((`timestamp` + " . $board['maxage'] * 3600 . ") < " . time() . ")");
        foreach ($results as $line) {
            // If it is older than the limit
            $post_class = new Post($line['id'], $board['name'], $board['id']);
            $post_class->Delete(true);
        }
    }
    if ($board['maxpages'] != 0) {
        // If the maximum pages setting is not zero (do not limit pages), find posts which are over the limit, and delete them
        $results = $tc_db->GetAll("SELECT `id`, `stickied` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0");
        $results_count = count($results);
        if (calculatenumpages($board['type'], $results_count) >= $board['maxpages']) {
            $board['maxthreads'] = $board['maxpages'] * KU_THREADS;
            $numthreadsover = $results_count - $board['maxthreads'];
            if ($numthreadsover > 0) {
                $resultspost = $tc_db->GetAll("SELECT `id`, `stickied` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0 AND `stickied` = 0 ORDER BY `bumped` ASC LIMIT " . $numthreadsover);
                foreach ($resultspost as $linepost) {
                    $post_class = new Post($linepost['id'], $board['name'], $board['id']);
                    $post_class->Delete(true);
                }
            }
        }
    }
    // If the thread was marked for deletion more than two hours ago, delete it
    $results = $tc_db->GetAll("SELECT `id` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0 AND `stickied` = 0 AND `deleted_timestamp` > 0 AND (`deleted_timestamp` <= " . time() . ")");
    foreach ($results as $line) {
        // If it is older than the limit
        $post_class = new Post($line['id'], $board['name'], $board['id']);
        $post_class->Delete(true);
    }
}
Ejemplo n.º 2
0
 /**
  * Regenerate all pages
  */
 function RegeneratePages()
 {
     global $tc_db, $CURRENTLOCALE;
     $this->InitializeDwoo();
     $results = $tc_db->GetAll("SELECT `filetype` FROM `" . KU_DBPREFIX . "embeds`");
     foreach ($results as $line) {
         $this->board['filetypes'][] .= $line[0];
     }
     $this->dwoo_data->assign('filetypes', $this->board['filetypes']);
     $maxpages = $this->board['maxpages'];
     $numposts = $tc_db->GetAll("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = 0 AND `IS_DELETED` = 0");
     if ($this->board['type'] == 1) {
         $postsperpage = KU_THREADSTXT;
     } elseif ($this->board['type'] == 3) {
         $postsperpage = 30;
     } else {
         $postsperpage = KU_THREADS;
     }
     $i = 0;
     $liststooutput = 0;
     $totalpages = calculatenumpages($this->board['type'], $numposts[0][0] - 1);
     if ($totalpages == '-1') {
         $totalpages = 0;
     }
     $this->dwoo_data->assign('numpages', $totalpages);
     while ($i <= $totalpages) {
         $newposts = array();
         $this->dwoo_data->assign('thispage', $i);
         $threads = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = 0 AND `IS_DELETED` = 0 ORDER BY `stickied` DESC, `bumped` DESC LIMIT " . $postsperpage . " OFFSET " . $postsperpage * $i);
         $executiontime_start_page = microtime_float();
         foreach ($threads as $k => $thread) {
             // If the thread is on the page set to mark, && hasn't been marked yet, mark it
             if ($thread['deleted_timestamp'] == 0 && $this->board['markpage'] > 0 && $i >= $this->board['markpage']) {
                 $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `deleted_timestamp` = '" . (time() + 7200) . "' WHERE `boardid` = " . $tc_db->qstr($this->board['id']) . " AND `id` = '" . $thread['id'] . "'");
                 clearPostCache($thread['id'], $this->board['name']);
                 $this->RegenerateThreads($thread['id']);
                 $this->dwoo_data->assign('replythread', 0);
             }
             $thread = $this->BuildPost($thread, true);
             if ($this->board['type'] != 3) {
                 $omitids = '';
                 $posts = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = " . $thread['id'] . " " . ($this->board['type'] != 1 ? "AND `IS_DELETED` = 0" : "") . " ORDER BY `id` DESC LIMIT " . ($thread['stickied'] == 1 ? KU_REPLIESSTICKY : KU_REPLIES));
                 foreach ($posts as $key => $post) {
                     $omitids .= $post['id'] . ",";
                     $posts[$key] = $this->BuildPost($post, true);
                 }
                 $posts = array_reverse($posts);
                 $omitids = substr($omitids, 0, -1);
                 array_unshift($posts, $thread);
                 $newposts[] = $posts;
             } else {
                 if (!$thread['tag']) {
                     $thread['tag'] = '*';
                 }
                 $newposts[] = $thread;
             }
             $replycount = array();
             if ($this->board['type'] == 1 || $this->board['type'] == 3) {
                 $replycount = $tc_db->GetAll("SELECT COUNT(`id`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $tc_db->qstr($this->board['id']) . " AND `parentid` = " . $thread['id']);
             } else {
                 $replycount = $tc_db->GetAll("SELECT COUNT(`id`) AS replies, SUM(CASE WHEN `file_md5` = '' THEN 0 ELSE 1 END) AS files FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . "  AND `parentid` = " . $thread['id'] . " AND `is_deleted` = 0 AND `id` NOT IN (" . $omitids . ")");
             }
             // Workaround for upload boards
             if ($this->board['type'] == 3) {
                 $newposts[$k]['replies'] = $replycount[0][0];
             } else {
                 $newposts[$k][0]['replies'] = $replycount[0][0];
                 $newposts[$k][0]['images'] = isset($replycount[0][1]) ? $replycount[0][1] : '';
             }
         }
         if ($this->board['type'] == 0 && !isset($embeds)) {
             $embeds = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "embeds`");
             $this->dwoo_data->assign('embeds', $embeds);
         }
         if (!isset($header)) {
             $header = $this->PageHeader();
             $header = str_replace("<!sm_threadid>", 0, $header);
         }
         if (!isset($postbox)) {
             $postbox = $this->Postbox();
             $postbox = str_replace("<!sm_threadid>", 0, $postbox);
         }
         $this->dwoo_data->assign('posts', $newposts);
         $this->dwoo_data->assign('file_path', getCLBoardPath($this->board['name'], $this->board['loadbalanceurl_formatted'], ''));
         $content = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_board_page.tpl', $this->dwoo_data);
         $footer = $this->Footer(false, microtime_float() - $executiontime_start_page, $this->board['type'] == 1 ? true : false);
         $content = $header . $postbox . $content . $footer;
         $content = str_replace("\t", '', $content);
         $content = str_replace("&nbsp;\r\n", '&nbsp;', $content);
         if ($i == 0) {
             $page = KU_BOARDSDIR . $this->board['name'] . '/' . KU_FIRSTPAGE;
             $this->PrintPage($page, $content, $this->board['name']);
         } else {
             $page = KU_BOARDSDIR . $this->board['name'] . '/' . $i . '.html';
             $this->PrintPage($page, $content, $this->board['name']);
         }
         $i++;
     }
     // If text board, rebuild thread list html files
     if ($this->board['type'] == 1) {
         $numpostsleft = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0");
         $liststooutput = floor(($numpostsleft - 1) / 40);
         $this->dwoo_data->assign('numpages', $liststooutput + 1);
         $listpage = 0;
         $currentpostwave = 0;
         while ($numpostsleft > 0) {
             $this->dwoo_data->assign('thispage', $listpage + 1);
             $executiontime_start_list = microtime_float();
             $page = $this->PageHeader(0, $currentpostwave, $liststooutput);
             $this->Footer(false, microtime_float() - $executiontime_start_list, true);
             if ($listpage == 0) {
                 $this->PrintPage(KU_BOARDSDIR . $this->board['name'] . '/list.html', $page, $this->board['name']);
             } else {
                 $this->PrintPage(KU_BOARDSDIR . $this->board['name'] . '/list' . ($listpage + 1) . '.html', $page, $this->board['name']);
             }
             $currentpostwave += 40;
             $numpostsleft -= 40;
             $listpage++;
         }
     }
     // If the board has catalog mode enabled, build it
     if ($this->board['enablecatalog'] == 1 && ($this->board['type'] == 0 || $this->board['type'] == 2)) {
         $executiontime_start_catalog = microtime_float();
         $catalog_head = $this->PageHeader() . '&#91;<a href="' . KU_BOARDSFOLDER . $this->board['name'] . '/">' . _gettext('Return') . '</a>&#93; <div class="catalogmode">' . _gettext('Catalog Mode') . '</div>' . "\n" . '<table border="1" align="center">' . "\n" . '<tr>' . "\n";
         $catalog_page = '';
         $results = $tc_db->GetAll("SELECT `id` , `subject` , `file` , `file_type` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0 ORDER BY `stickied` DESC, `bumped` DESC");
         $numresults = count($results);
         if ($numresults > 0) {
             $celnum = 0;
             $trbreak = 0;
             $row = 1;
             // Calculate the number of rows we will actually output
             $maxrows = max(1, ($numresults - $numresults % 12) / 12);
             foreach ($results as $line) {
                 $celnum++;
                 $trbreak++;
                 if ($trbreak == 13 && $celnum != $numresults) {
                     $catalog_page .= '</tr>' . "\n" . '<tr>' . "\n";
                     $row++;
                     $trbreak = 1;
                 }
                 if ($row <= $maxrows) {
                     $replies = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = " . $line['id']);
                     $catalog_page .= '<td valign="middle">' . "\n" . '<a href="' . KU_BOARDSFOLDER . $this->board['name'] . '/res/' . $line['id'] . '.html"';
                     if ($line['subject'] != '') {
                         $catalog_page .= ' title="' . $line['subject'] . '"';
                     }
                     $catalog_page .= '>';
                     if ($line['file'] != '' && $line['file'] != 'removed') {
                         if ($line['file_type'] == 'jpg' || $line['file_type'] == 'png' || $line['file_type'] == 'gif') {
                             $file_path = getCLBoardPath($this->board['name'], $this->board['loadbalanceurl_formatted'], $this->archive_dir);
                             $catalog_page .= '<img src="' . $file_path . '/thumb/' . $line['file'] . 'c.' . $line['file_type'] . '" alt="' . $line['id'] . '" border="0" />';
                         } else {
                             $catalog_page .= _gettext('File');
                         }
                     } elseif ($line['file'] == 'removed') {
                         $catalog_page .= 'Rem.';
                     } else {
                         $catalog_page .= _gettext('None');
                     }
                     $catalog_page .= '</a><br />' . "\n" . '<small>' . $replies . '</small>' . "\n" . '</td>' . "\n";
                 }
             }
         } else {
             $catalog_page .= '<td>' . "\n" . _gettext('No threads.') . "\n" . '</td>' . "\n";
         }
         $catalog_page .= '</tr>' . "\n" . '</table><br /><hr />' . $this->Footer(false, microtime_float() - $executiontime_start_catalog);
         $this->PrintPage(KU_BOARDSDIR . $this->board['name'] . '/catalog.html', $catalog_head . $catalog_page, $this->board['name']);
     }
     // Delete old pages
     $dir = KU_BOARDSDIR . $this->board['name'];
     $files = glob("{$dir}/*.html");
     if (is_array($files)) {
         foreach ($files as $htmlfile) {
             if (preg_match("/[0-9+].html/", $htmlfile)) {
                 if (substr(basename($htmlfile), 0, strpos(basename($htmlfile), '.html')) > $totalpages) {
                     unlink($htmlfile);
                 }
             }
             if (preg_match("/list[0-9+].html/", $htmlfile)) {
                 if (substr(basename($htmlfile), 4, strpos(basename($htmlfile), '.html')) > $liststooutput + 1) {
                     unlink($htmlfile);
                 }
             }
             if (preg_match("/catalog.html/", $htmlfile)) {
                 if (!($this->board['enablecatalog'] == 1 && ($this->board['type'] == 0 || $this->board['type'] == 2))) {
                     unlink($htmlfile);
                 }
             }
         }
     }
 }