*/ class SitemapsPageWBBListener implements EventListener { protected $wbb = false; protected $thread_posts_per_page=0; protected $board_threads_per_page=0; protected $boardIDs = array(), $boards = array(); protected $eventObj; protected $className; /** * @see EventListener::execute() */ public function execute($eventObj, $className, $eventName) { $this->eventObj = $eventObj; $this->className = $className; switch ($eventName) { case 'readParameters': $this->readParameters(); break; case 'readData': $this->readData(); break; case 'assignVariables': $this->assignVariables(); break; } } /** * how many posts in one thread */ protected function threadPostsPerPage() { if($this->thread_posts_per_page > 0) return $this->thread_posts_per_page; $sql = "SELECT opt.optionValue FROM wcf".WCF_N."_option opt WHERE opt.optionName = 'thread_posts_per_page' LIMIT 1;"; $result = WCF::getDB()->sendQuery($sql); $row = WCF::getDB()->fetchArray($result); $this->thread_posts_per_page = $row['optionValue']; } /** * how many threads in one forum */ protected function boardThreadsPerPage() { if($this->board_threads_per_page > 0) return $this->board_threads_per_page; $sql = "SELECT opt.optionValue FROM wcf".WCF_N."_option opt WHERE opt.optionName = 'board_threads_per_page' LIMIT 1;"; $result = WCF::getDB()->sendQuery($sql); $row = WCF::getDB()->fetchArray($result); $this->board_threads_per_page = $row['optionValue']; } /** * Gets the threads for the sitemaps. */ protected function readThreads() { require_once(WBB_DIR.'lib/data/thread/FeedThread.class.php'); // accessible boards require_once(WBB_DIR.'lib/data/board/Board.class.php'); $boardIDs = Board::getAccessibleBoards(array('canViewBoard', 'canEnterBoard', 'canReadThread')); // get threads if (!empty($boardIDs)) { // read count $this->threadPostsPerPage(); $sql = "SELECT post.*, thread.* FROM wbb".WBB_N."_thread thread LEFT JOIN wbb".WBB_N."_post post ON (post.postID = thread.firstPostID) WHERE thread.boardID IN (".$boardIDs.") ".(count($this->boardIDs) ? "AND thread.boardID IN (".implode(',', $this->boardIDs).")" : "")." AND thread.isDeleted = 0 AND thread.isDisabled = 0 AND thread.firstPostID > 0 ORDER BY thread.time DESC"; // TEMPLATE $tpl = ''.PAGE_URL.'/%s%s'; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $pages = ceil($row['replies']/$this->thread_posts_per_page); $tmp = new SitemapsThread($row); if($this->eventObj->rewriter === null) { $tmp->url = sprintf('index.php?page=Thread&threadID=%d', $row['threadID']); } else { $this->eventObj->rewriter->publicCacheThreads($row['threadID'], $row); $tmp->url = $this->eventObj->rewriter->publicParseThreadURLs($row['threadID'], ''); } // PRINT printf($tpl, $tmp->url, date('c', $tmp->time)); for($j=2; $j<$pages; $j++) { $tmp = new SitemapsThread($row['threadID'], $row); if($this->eventObj->rewriter === null) { $tmp->url = sprintf('index.php?page=Thread&threadID=%d&pageNo=%d', $row['threadID'], $j); } else { $tmp->url = $this->eventObj->rewriter->publicParseMultipleThreadURLs($row['threadID'], $j, ''); } // PRINT printf($tpl, $tmp->url, date('c', $tmp->time)); } // titles are not used again.. clear cache if($this->eventObj->rewriter !== null) $this->eventObj->rewriter->clearCache(); } } } /** * Gets the boards for the sitemaps overview and for the numbered board pages. */ protected function readBoards() { // accessible boards $boardIDs = Board::getAccessibleBoards(array('canViewBoard', 'canEnterBoard', 'canReadThread')); // get threads if (!empty($boardIDs)) { // read count $this->boardThreadsPerPage(); $sql = "SELECT board.*, t.lastPostTime FROM wbb".WBB_N."_board board NATURAL JOIN wbb".WBB_N."_board_last_post blp JOIN wbb".WBB_N."_thread t ON blp.threadID = t.threadID WHERE board.threads > 0 AND board.boardID IN (".$boardIDs.") ".(count($this->boardIDs) && $this->boardIDs[0] ? "AND board.boardID IN (".implode(',', $this->boardIDs).")" : "")." ORDER BY board.time DESC"; $i=0; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $pages = ceil($row['threads']/$this->board_threads_per_page); $this->boards[$i] = new SitemapsBoard($row['boardID'], $row); $this->boards[$i]->full = true; $this->boards[$i]->time = $row['lastPostTime']; if(intval($this->boards[$i]->getThreads()) == 0) { continue; } if($this->eventObj->rewriter === null) { $this->boards[$i]->url = sprintf('index.php?page=Board&boardID=%d', $row['boardID']); } else { $this->boards[$i]->url = $this->eventObj->rewriter->publicParseBoardURLs($row['boardID'], ''); } // PRINT for($j=2; $j<$pages; $j++) { $i++; $this->boards[$i] = new Board($row['boardID'], $row); $this->boards[$i]->time = $row['lastPostTime']; if($this->eventObj->rewriter === null) { $this->boards[$i]->url = sprintf('index.php?page=Board&boardID=%d&pageNo=%d', $row['boardID'], $j); } else { $this->boards[$i]->url = $this->eventObj->rewriter->publicParseMultipleBoardURLs($row['boardID'], $j, ''); } } $i++; // titles are not used again.. clear cache if($this->eventObj->rewriter !== null) $this->eventObj->rewriter->clearCache(); } } } /** * gets the board for the index */ protected function readIndex() { $this->readBoards(); //index $tpl = ''.PAGE_URL.'/index.php?page=Sitemaps&boardID=%d%s'; printf($tpl, 0, date('c')); foreach(array_filter($this->boards, create_function('$a','return isset($a->full);')) as $board) { printf($tpl, $board->boardID, date('c', $board->time)); } } /** * @see Page::readParameters() */ protected function readParameters () { if(isset($_GET['boardID'])) { $this->wbb = true; $this->boardIDs = ArrayUtil::toIntegerArray(explode(',', $_GET['boardID'])); } } /** * @see Page::readData() */ protected function readData () { if($this->eventObj->index) { //index $this->eventObj->setType('sitemapindex'); } else if($this->wbb) { //boards or threads $this->eventObj->setType('urlset'); } } /** * @see Page::assignVariables() */ protected function assignVariables () { if($this->eventObj->index) { //index $this->readIndex(); } else if($this->wbb) { if($this->boardIDs[0] == 0) { //boards $this->readBoards(); $tpl = ''.PAGE_URL.'/%s%s'; foreach($this->boards as $board) { printf($tpl, $board->url, date('c', $board->time)); } } else { //threads $this->readThreads(); } } } } ?>