Exemple #1
0
 /**
  * Regenerate each thread's corresponding html file, starting with the most recently bumped
  */
 public function regenerateThreads($id = 0)
 {
     $numimages = 0;
     $embeds = $this->db->select("embeds")->fields("embeds")->execute()->fetchAll();
     $this->twigData['embeds'] = $embeds;
     // No ID? Get every thread.
     if ($id == 0) {
         // Okay let's do this!
         $threads = $this->db->select("posts")->fields("posts")->condition("post_board", $this->board->board_id)->condition("post_parent", 0)->condition("post_deleted", 0)->orderBy("post_id", "DESC")->execute()->fetchAll();
         if (count($threads) > 0) {
             foreach ($threads as $thread) {
                 $this->regenerateThreads($thread->post_id);
             }
         }
     } else {
         for ($i = 0; $i < 3; $i++) {
             if (!$i > 0 && kxEnv::Get('kx:extras:firstlast') || $i == 1 && $replycount < 50 || $i == 2 && $replycount < 100) {
                 break;
             }
             if ($i == 0) {
                 $lastBit = "";
                 $executiontime_start_thread = microtime(true);
                 //---------------------------------------------------------------------------------------------------
                 // Okay, this may seem confusing, but we're caching this so we can use it as a prepared statement
                 // instead of executing it every time. This is only really useful if we're regenerating all threads,
                 // but the perfomance impact otherwise is minimal.
                 //----------------------------------------------------------------------------------------------------
                 if (!isset($this->board->preparedThreads)) {
                     $this->board->preparedThreads = $this->db->select("posts")->fields("posts")->where("post_board = " . $this->board->board_id . " AND (post_id = ? OR post_parent = ?) AND post_deleted = 0")->orderBy("post_id")->build();
                 }
                 // Since we prepared the statement earlier, we just need to execute it.
                 $this->board->preparedThreads->execute(array($id, $id));
                 $thread = $this->board->preparedThreads->fetchAll();
                 foreach ($thread as &$post) {
                     $post = $this->buildPost($post, false);
                     if (!empty($post->file_type)) {
                         foreach ($post->file_type as $type) {
                             if ($type == 'jpg' || $type == 'gif' || $type == 'png') {
                                 $numimages++;
                             }
                         }
                     }
                 }
                 //-----------------------------------------------------------------------
                 // When using a pointer in a foreach, the $value variable persists
                 // as the last index of an array, we can use this to our advantage here.
                 //-----------------------------------------------------------------------
                 if (kxEnv::Get('kx:extras:postspy')) {
                     $twigData['lastid'] = $post->post_id;
                 }
                 // Now we can get rid of it
                 unset($post);
                 $this->board->header = $this->pageHeader($id);
                 $this->board->postbox = $this->postBox($id);
                 //-----------
                 // Dwoo-hoo
                 //-----------
                 $this->twigData['numimages'] = $numimages;
                 $this->twigData['replythread'] = $id;
                 $this->twigData['threadid'] = $thread[0]->post_id;
                 $this->twigData['posts'] = $thread;
                 $replycount = count($thread) - 1;
                 $this->twigData['replycount'] = $replycount;
                 if (!isset($this->board->footer)) {
                     $this->board->footer = $this->footer(false, microtime(true) - $executiontime_start_thread);
                 }
             } else {
                 if ($i == 1) {
                     $lastBit = "+50";
                     $this->twigData['modifier'] = "last50";
                     // Grab the last 50 replies
                     $this->twigData['posts'] = array_slice($thread, -50, 50);
                     // Add the thread to the top of this, since it wont be included in the result
                     array_unshift($this->twigData['posts'], $thread[0]);
                 } elseif ($i == 2) {
                     $lastBit = "-100";
                     $this->twigData['modifier'] = "first100";
                     // Grab the first 100 posts
                     $this->twigData['posts'] = array_slice($thread, 0, 100);
                 }
             }
             $this->twigData['board'] = $this->board;
             //print_r($this->twigData);
             $content = kxTemplate::get('board/' . $this->boardType . '/thread', $this->twigData, true);
             kxFunc::outputToFile(KX_BOARD . '/' . $this->board->board_name . $this->archive_dir . '/res/' . $id . $lastBit . '.html', $content, $this->board->board_name);
         }
     }
 }