| 1 | <?php |
|---|
| 2 | // wbb imports |
|---|
| 3 | require_once(WBB_DIR.'lib/data/board/Board.class.php'); |
|---|
| 4 | |
|---|
| 5 | // do import if rewriter exists |
|---|
| 6 | if(file_exists(WBB_DIR.'lib/data/page/seo/WBBSEORewriter.class.php')) { |
|---|
| 7 | require_once(WBB_DIR.'lib/data/board/Board.class.php'); |
|---|
| 8 | } |
|---|
| 9 | // otherwise create a new class |
|---|
| 10 | else { |
|---|
| 11 | class WBBSEORewriter {} |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * Rewrites links to normal or seo urls |
|---|
| 16 | * |
|---|
| 17 | * @author Torben Brodt |
|---|
| 18 | * @package de.easy-coding.wcf.data.page.publicseorewriter |
|---|
| 19 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
|---|
| 20 | */ |
|---|
| 21 | class PublicSEORewriter extends WBBSEORewriter { |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * Caches threads. |
|---|
| 25 | * |
|---|
| 26 | * @param int $threadID |
|---|
| 27 | * @param array $row |
|---|
| 28 | */ |
|---|
| 29 | public function publicCacheThreads($threadID, $row) { |
|---|
| 30 | $row['topic'] = SEOUtil::formatString($row['topic']); |
|---|
| 31 | if ($this->encodeHTML) $row['topic'] = StringUtil::encodeHTML($row['topic']); |
|---|
| 32 | $this->cachedThreads[$row['threadID']] = array( |
|---|
| 33 | 'topic' => $row['topic'], |
|---|
| 34 | 'boardID' => $row['boardID'] |
|---|
| 35 | ); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * Caches boards. |
|---|
| 40 | * |
|---|
| 41 | * @param int $boardID |
|---|
| 42 | * @param array $row |
|---|
| 43 | */ |
|---|
| 44 | public function publicCacheBoards($boardID, $row) { |
|---|
| 45 | $this->cachedBoardTitles[$boardID] = SEOUtil::formatString(WCF::getLanguage()->get($row['title'])); |
|---|
| 46 | if ($this->encodeHTML && !preg_match('/^[a-z0-9_\-]+(?:\.[a-z0-9_\-]+)+$/i', $row['title'])) { |
|---|
| 47 | $this->cachedBoardTitles[$boardID] = StringUtil::encodeHTML($this->cachedBoardTitles[$boardID]); |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * clears the cache |
|---|
| 53 | */ |
|---|
| 54 | public function clearCache() { |
|---|
| 55 | $this->cachedThreads = array(); |
|---|
| 56 | $this->cachedBoardTitles = array(); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * Parses index urls. |
|---|
| 62 | * |
|---|
| 63 | * @param string $queryString |
|---|
| 64 | * @param string $string |
|---|
| 65 | * |
|---|
| 66 | * @return string |
|---|
| 67 | */ |
|---|
| 68 | public function publicParseIndexURLs($queryString, $string = null) { |
|---|
| 69 | if(defined('SEO_ENABLE') && SEO_ENABLE && defined('SEO_REWRITE_INDEX') && SEO_REWRITE_INDEX) { |
|---|
| 70 | if($string === null) $string = SEO_REWRITE_INDEX_FORMAT; |
|---|
| 71 | return $this->parseIndexURLs($queryString); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Parses multiple board urls. |
|---|
| 77 | * |
|---|
| 78 | * @param integer $boardID |
|---|
| 79 | * @param integer $pageNo |
|---|
| 80 | * @param string $queryString |
|---|
| 81 | * @param string $string |
|---|
| 82 | * |
|---|
| 83 | * @return string |
|---|
| 84 | */ |
|---|
| 85 | public function publicParseMultipleBoardURLs($boardID, $pageNo, $queryString, $string = null) { |
|---|
| 86 | if(defined('SEO_ENABLE') && SEO_ENABLE && defined('SEO_REWRITE_BOARD') && SEO_REWRITE_BOARD) { |
|---|
| 87 | if($string === null) $string = SEO_REWRITE_BOARD_MULTIPLE_FORMAT; |
|---|
| 88 | return $this->parseMultipleBoardURLs($boardID, $pageNo, $queryString); |
|---|
| 89 | } else { |
|---|
| 90 | return sprintf('index.php?page=Board&boardID=%d&pageNo=%d', $boardID, $pageNo); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Parses board urls. |
|---|
| 96 | * |
|---|
| 97 | * @param integer $boardID |
|---|
| 98 | * @param string $queryString |
|---|
| 99 | * @param string $string |
|---|
| 100 | * |
|---|
| 101 | * @return string |
|---|
| 102 | */ |
|---|
| 103 | public function publicParseBoardURLs($boardID, $queryString, $string = null) { |
|---|
| 104 | if(defined('SEO_ENABLE') && SEO_ENABLE && defined('SEO_REWRITE_BOARD') && SEO_REWRITE_BOARD) { |
|---|
| 105 | if($string === null) $string = SEO_REWRITE_BOARD_FORMAT |
|---|
| 106 | return $this->parseBoardURLs($boardID, $queryString); |
|---|
| 107 | } else { |
|---|
| 108 | return sprintf('index.php?page=Board&boardID=%d', $boardID); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /** |
|---|
| 113 | * Parses multiple thread urls. |
|---|
| 114 | * |
|---|
| 115 | * @param integer $threadID |
|---|
| 116 | * @param integer $pageNo |
|---|
| 117 | * @param string $queryString |
|---|
| 118 | * @param string $string |
|---|
| 119 | * |
|---|
| 120 | * @return string |
|---|
| 121 | */ |
|---|
| 122 | public function publicParseMultipleThreadURLs($threadID, $pageNo, $queryString, $string = null) { |
|---|
| 123 | if(defined('SEO_ENABLE') && SEO_ENABLE && defined('SEO_REWRITE_THREAD') && SEO_REWRITE_THREAD) { |
|---|
| 124 | if($string === null) $string = SEO_REWRITE_THREAD_MULTIPLE_FORMAT |
|---|
| 125 | return $this->parseMultipleThreadURLs($threadID, $pageNo, $queryString); |
|---|
| 126 | } else { |
|---|
| 127 | return sprintf('index.php?page=Thread&threadID=%d&pageNo=%d', $threadID, $pageNo); |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | /** |
|---|
| 132 | * Parses thread urls. |
|---|
| 133 | * |
|---|
| 134 | * @param integer $threadID |
|---|
| 135 | * @param string $queryString |
|---|
| 136 | * @param string $string |
|---|
| 137 | * |
|---|
| 138 | * @return string |
|---|
| 139 | */ |
|---|
| 140 | public function publicParseThreadURLs($threadID, $queryString, $string = null) { |
|---|
| 141 | if(defined('SEO_ENABLE') && SEO_ENABLE && defined('SEO_REWRITE_THREAD') && SEO_REWRITE_THREAD) { |
|---|
| 142 | if($string === null) $string = SEO_REWRITE_THREAD_FORMAT |
|---|
| 143 | return $this->parseThreadURLs($threadID, $queryString); |
|---|
| 144 | } else { |
|---|
| 145 | return sprintf('index.php?page=Thread&threadID=%d', $threadID); |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | /** |
|---|
| 150 | * Parses post urls. |
|---|
| 151 | * |
|---|
| 152 | * @param integer $postID |
|---|
| 153 | * @param string $queryString |
|---|
| 154 | * @param string $string |
|---|
| 155 | * |
|---|
| 156 | * @return string |
|---|
| 157 | */ |
|---|
| 158 | public function publicParsePostURLs($postID, $queryString, $string = null) { |
|---|
| 159 | if(defined('SEO_ENABLE') && SEO_ENABLE && defined('SEO_REWRITE_THREAD') && SEO_REWRITE_THREAD) { |
|---|
| 160 | if($string === null) $string = SEO_REWRITE_THREAD_POST_FORMAT; |
|---|
| 161 | return $this->parsePostURLs($postID, $queryString); |
|---|
| 162 | } else { |
|---|
| 163 | return sprintf('index.php?page=Thread&postID=%d', $postID); |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | ?> |
|---|