public function calcTotalPages() { $numposts = $this->db->select("posts")->fields("posts")->condition("post_board", $this->board->board_id)->condition("post_parent", 0)->condition("post_deleted", 0)->countQuery()->execute()->fetchField(); return kxFunc::pageCount($this->board->board_type, $numposts - 1); }
public function regeneratePages() { //----------------------------------------- // Setup //----------------------------------------- $this->twigData['filetypes'] = $this->getEmbeds(); $i = 0; if (!isset($postsperpage)) { $postsperpage = $this->environment->get('kx:display:imgthreads'); } $numposts = $this->db->select("posts")->fields("posts")->condition("post_board", $this->board->board_id)->condition("post_parent", 0)->condition("post_deleted", 0)->countQuery()->execute()->fetchField(); $totalpages = kxFunc::pageCount($this->board->board_type, $numposts - 1) - 1; // If no posts, $totalpages==-2, which causes the board to not regen. if ($totalpages < 0) { $totalpages = 0; } $this->twigData['numpages'] = $totalpages; //----------------------------------------- // Run through each page //----------------------------------------- while ($i <= $totalpages) { $this->twigData['thispage'] = $i; //-------------------------------------------------------------------------------------------------- // Grab our threads, stickies go first, then follow by bump time, then run through them //-------------------------------------------------------------------------------------------------- $threads = $this->db->select("posts")->fields("posts")->condition("post_board", $this->board->board_id)->condition("post_parent", 0)->condition("post_deleted", 0)->orderBy("post_stickied", "DESC")->orderBy("post_bumped", "DESC")->range($postsperpage * $i, $postsperpage)->execute()->fetchAll(); foreach ($threads as &$thread) { //------------------------------------------------------------------------------------------ // If the thread is on the page set to mark, and hasn't been marked yet, mark it //------------------------------------------------------------------------------------------ if ($this->markThread($thread, $i)) { $this->RegenerateThreads($thread->post_id); // RegenerateThreads overwrites the replythread variable. Reset it here. $this->twigData['replythread'] = 0; } $thread = $this->buildPost($thread, true); $outThread[] = $this->buildThread($thread); } if (!isset($embeds)) { $embeds = $this->db->select("embeds")->fields("embeds")->execute()->fetchAll(); $this->twigData['embeds'] = $embeds; } $this->twigData['posts'] = $outThread; //print_r($this->board); $this->twigData['file_path'] = KX_BOARD . '/' . $this->board->board_name; // Make required folders @mkdir($this->twigData['file_path'], 0777, true); @mkdir($this->twigData['file_path'] . '/src/', 0777, true); @mkdir($this->twigData['file_path'] . '/thumb/', 0777, true); @mkdir($this->twigData['file_path'] . '/res/', 0777, true); $this->twigData['board'] = $this->board; $this->footer(false, microtime(true) - kxEnv::Get('kx:executiontime:start')); $this->pageHeader(0); $this->postBox(0); //print_r($this->twigData); $content = kxTemplate::get('board/' . $this->boardType . '/board_page', $this->twigData, true); if ($i == 0) { $page = KX_BOARD . '/' . $this->board->board_name . '/' . kxEnv::Get('kx:pages:first'); } else { $page = KX_BOARD . '/' . $this->board->board_name . '/' . $i . '.html'; } //echo "<br />$page"; //die($content); kxFunc::outputToFile($page, $content, $this->board->board_name); $i++; } }