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