root/include/class.seo.php

Revision 336, 50.4 kB (checked in by Nafania, 1 year ago)

Мелкие баг-фиксы. Поддержка сфинкса (корявая) в поиске торрентов. sphinxapi.php надо использовать свой - тот что лежит, только для примера.
Список файлов показывается напрямую из торрент файла, а не из базы, но таблицы пока оставлены - на всякий случай.

Line 
1 <?php
2 /**</span>
3 <span class="code-comment">*
4 * @package Ultimate SEO URL phpBB SEO
5 * @version $Id: phpbb_seo_class.php 236 2010-03-03 08:20:36Z dcz $
6 * @copyright (c) 2006 - 2010 www.phpbb-seo.com
7 * @license http://www.opensource.org/licenses/rpl1.5.txt Reciprocal Public License 1.5
8 *
9 */
10 /**
11 * phpBB_SEO Class
12 * www.phpBB-SEO.com
13 * @package Ultimate SEO URL phpBB SEO
14 */
15
16 class seo {</span>
17 <span class="code-keyword">    var    $version = '0.6.4';
18     var    $modrtype = 2; // We set it to mixed as a default value
19     var    $seo_path = array();
20     var    $seo_url = array( 'forum' =>  array(), 'topic' =>  array(), 'user' => array(), 'username' => array(), 'group' => array(), 'file' => array(), 'browse' => array(), 'details' => array() );
21     var  $seo_parent = array();
22     var    $filter = array(
23             'details' =>  array(),
24             'browse' =>  array('page' => 0),
25             'forum' => array('page' => 'viewforum', 'topicdays' => 0),
26             //'forum' => array('st' => 0, 'sk' => 't', 'sd' => 'd'),
27             'topic' => array('st' => 0, 'sk' => 't', 'sd' => 'a', 'highlight' => '', 'page' => 'viewtopic', 'postdays' => 0, 'postorder' => 0),
28             'search' => array('st' => 0, 'sk' => 't', 'sd' => 'd', 'ch' => '', 'page' => 'search', 'mode' => 'results'),
29             'post' => array('page' => 'viewtopic'),
30         );
31
32     var    $seo_stop_files = array('posting' => 1, 'ucp' => 1, 'swatch' => 1, 'mcp' => 1);
33     var    $seo_stop_vars = array();
34     var    $seo_stop_dirs = array();
35     var    $seo_delim = array(
36             'details' =>  '-t',
37             'browse' =>  '-c',
38             'forum_cat' => '-c',
39             'forum' => '-f',
40             'topic' => '-t',
41             'userdetails' => '-u',
42             'group' => '-g',
43             'start' => '-',
44             'sr' => '-'
45         );
46     var    $seo_ext = array(
47             'details' =>  '.html',
48             'browse' =>  '/',
49
50             'browse_static' =>  '/',
51
52             'phpbb2' => '/',
53             'forum_cat' => '/',
54             'forum' => '/',
55             'topic' => '.html',
56             'post' => '.html',
57             'index' => '',
58             'search' => '.html',
59             'userdetails' => '/',
60             'group' => '.html',
61             'leaders' => '.html',
62             'atopic' => '.html',
63             'utopic' => '.html',
64             'npost' => '.html',
65             'pagination' => '.html',
66             'gz_ext' => '',
67             'comment' =>  '.html',
68             'faq' =>  '.html',
69             'rules' =>  '.html',
70             'login' =>  '.html',
71             'signup' =>  '.html',
72         );
73     var    $seo_static = array(
74             'details' =>  'details',
75             'browse' =>  'browse',
76
77             'browse_static' =>  'torrents',
78
79             'phpbb2' => 'forum',
80             'forum_cat' => 'forum_cat',
81             'forum' => 'forum',
82             'topic' => 'topic',
83             'post' => 'post',
84             'index' => '',
85             'search' => 'search',
86             'userdetails' => 'user',
87             'group' => 'group',
88             'global_announce' => 'announces',
89             'atopic' => 'active-topics',
90             'utopic' => 'unanswered',
91             'npost' => 'newposts',
92             'pagination' => 'page',
93             'gz_ext' => '.gz',
94             'printertopic' => 'print',
95             'comment' =>  'comment',
96             'faq' =>  'faq',
97             'rules' =>  'rules',
98             'login' =>  'login',
99             'signup' =>  'signup',
100         );
101     var    $file_hbase = array();
102     var    $get_vars = array();
103     var    $path = '';
104     var    $start = '';
105     var    $filename = '';
106     var    $file = '';
107     var    $url_in = '';
108     var    $url = '';
109     var    $page_url = '';
110     var    $seo_opt = array(
111             'url_rewrite' => false,
112             'modrtype' => 2,
113 //            'sql_rewrite' => false,</span>
114 <span class="code-comment">            'profile_inj' => false,
115             'profile_vfolder' => false,
116             'profile_noids' => false,
117             'rem_sid' => false,
118             'rem_hilit' => false,
119             'rem_small_words' => false,
120             'virtual_folder' => false,
121             'virtual_root' => false,
122             'cache_layer' => true, // Forum url caching, by default
123             'rem_ids' => false,
124         );
125     var    $rewrite_method = array();
126     var    $paginate_method = array();
127     var    $seo_cache = array();
128     var    $cache_config = array();
129     var    $RegEx = array();
130     var    $sftpl = array();
131     var    $url_replace = array();
132     /**
133     * constuctor
134     */
135     function seo() {
136         global $config, $root_path;
137         // fix for an interesting bug with parse_str http://bugs.php.net/bug.php?id=48697
138         // and apparently, the bug is still here in php5.3
139         @ini_set("mbstring.internal_encoding", 'UTF-8');
140         // Nothing should be edited here, please do your custom settings in the
141         // seo/includes/seo_modules.php instead to make your updates easier.
142         // reset the rewrite_method for $root_path
143         $this->rewrite_method[$root_path] = array();
144         // phpBB files must be treated a bit differently
145         $this->seo_static['file'] = array();
146         $this->seo_static['file_index'] = 'resources';
147         $this->seo_static['thumb'] = 'thumb';
148         // Options that may be bypassed by the cached settings.
149         $this->cache_config['dynamic_options'] = array_keys($this->seo_opt); // Do not change
150         // copyright notice, do not change
151         // Caching config
152         $this->seo_opt['cache_folder'] = 'cache/'; // Folder where the cache file is stored
153         define('SEO_CACHE_PATH', rtrim(realpath($root_path . $this->seo_opt['cache_folder']), '/') . '/'); // do not change
154         $this->seo_opt['topic_type'] = array(); // do not change
155         $this->seo_opt['topic_last_page'] = array(); // do not change
156         $this->cache_config['cache_enable'] = true; // do not change
157         $this->cache_config['rem_ids'] = $this->seo_opt['rem_ids']; // do not change, set up above
158         $this->cache_config['files'] = array('forum_cat' => 'seo_cache.php', 'forum' => 'seo_cache.php', 'browse' => 'seo_cache.php', 'htaccess' => '.htaccess');
159         $this->cache_config['cached'] = false; // do not change
160         $this->cache_config['forum'] = array(); // do not change
161         $this->cache_config['browse'] = array(); // do not change
162         $this->cache_config['topic'] = array(); // do not change
163         $this->cache_config['forum_cat'] = array(); // do not change
164         $this->cache_config['settings'] = array(); // do not change
165         // --> DOMAIN SETTING <-- //
166         // Path Settings, only rely on DB
167         $server_protocol = ($config['server_protocol']) ? $config['server_protocol'] : (($config['cookie_secure']) ? 'https://' : 'http://');
168         $server_name = trim($config['server_name'], '/') . '/';
169         $server_port = max(0, (int) $config['server_port']);
170         $server_port = ($server_port && $server_port <> 80) ? ':' . $server_port : '';
171         $script_path = trim($config['script_path'], '/ ');
172         $script_path = (empty($script_path) ) ? '' : $script_path . '/';
173         $this->seo_path['root_url'] = strtolower($server_protocol . $server_name . $server_port);
174         $this->seo_path['urlR'] = $this->seo_path['url'] =  $this->seo_path['root_url'] . $script_path;
175         $this->seo_path['script'] = $script_path;
176         $this->seo_path['files'] = $this->seo_path['url'] . 'download/';
177         $this->seo_path['canonical'] = '';
178
179         // File setting
180         $this->seo_req_uri();
181         $this->seo_opt['seo_base_href'] = $this->seo_opt['req_file'] = $this->seo_opt['req_self'] = '';
182         if ($script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF')) {
183             // From session.php
184             // Replace backslashes and doubled slashes (could happen on some proxy setups)
185             $this->seo_opt['req_self'] = str_replace(array('\\', '//'), '/', $script_name);
186             // basenamed page name (for example: index)
187             $this->seo_opt['req_file'] = urlencode(htmlspecialchars(str_replace(".php", '', basename($this->seo_opt['req_self']))));
188         }
189         // Load settings from phpbb_seo/includes/seo_modules.php
190         if ($this->check_cache()) {
191             foreach($this->cache_config['dynamic_options'] as $optionname => $optionvalue ) {
192                 if (@is_array($this->cache_config['settings'][$optionname])) {
193                     $this->seo_opt[$optionname] = array_merge($this->seo_opt[$optionname], $this->cache_config['settings'][$optionname]);
194                 } elseif ( @isset($this->cache_config['settings'][$optionvalue]) ) {
195                     $this->seo_opt[$optionvalue] = $this->cache_config['settings'][$optionvalue];
196                 }
197                 if ( isset($config['seo_' . $optionvalue]) ) {
198                     $this->seo_opt[$optionvalue] = (bool) $config['seo_' . $optionvalue];
199                 }
200             }
201             $this->modrtype = @isset($this->seo_opt['modrtype']) ? $this->seo_opt['modrtype'] : $this->modrtype;
202             if ( $this->modrtype > 1 ) { // Load cached URLs
203                 $this->seo_url['forum_cat'] =& $this->cache_config['forum_cat'];
204                 $this->seo_url['forum'] =& $this->cache_config['forum'];
205                 $this->seo_url['browse'] =& $this->cache_config['browse'];
206             }
207         }
208         $this->check_config();
209 //        $this->seo_path['filesR'] = $this->seo_path['url'] . $this->seo_static['file_index'] . $this->seo_delim['file'];</span>
210 <span class="code-comment">        if ( ( include($root_path . '/languages/lang_' . $config['default_lang'] . '/lang_convert_table.php') ) !== false ) {
211             $this->url_replace = $lang['convert_table'];
212         }
213         // see if we have some custom replacement
214         if (!empty($this->url_replace)) {
215             $this->url_replace = array(
216                 'find' => array_keys($this->url_replace),
217                 'replace' => array_values($this->url_replace)
218             );
219         }
220         $this->seo_opt['topic_per_page'] = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page']; // do not change
221
222         $this->seo_opt['phpbb2_inj'] = ( $this->seo_ext['phpbb2'] === '/' ? $this->seo_static['phpbb2'] . $this->seo_ext['phpbb2'] : '' );
223         // Array of the filenames that require the use of a base href tag.
224
225         $this->file_hbase = array_merge(array(
226             'details' => $this->seo_path['url'],
227             'browse' => $this->seo_path['url'],
228             'phpbb2' => $this->seo_path['url'],
229             'viewtopic' => $this->seo_path['url'],
230             'forum' => $this->seo_path['url'],
231             'userdetails' => $this->seo_path['url'],
232             'search' => $this->seo_path['url']
233         ), $this->file_hbase);
234         // Stop dirs
235         $this->seo_stop_dirs = array_merge(array($root_path . 'admin/' => false), $this->seo_stop_dirs);
236         // Rewrite functions array : array( 'path' => array('file_name' => 'function_name'));
237         // Warning, this way of doing things is path aware, this implies path to be properly sent to append_sid()
238         // Allow to add options without slowing down the URL rewriting process
239         $this->rewrite_method[$root_path] = array_merge(
240             array(
241                 'viewtopic' => 'viewtopic',
242                 'viewforum' => 'viewforum',
243                 'index' => 'index',
244                 'userdetails' => 'userdetails',
245                 'search' => 'search',
246
247                 'details' => 'details',
248                 'browse' => 'browse',
249                 'forum_cat' => 'viewforumcat',
250                 'phpbb2' => 'phpbb2',
251                 'comment' => 'comment',
252                 'faq' => 'faq',
253                 'rules' => 'rules',
254                 'login' => 'login',
255                 'signup' => 'signup',
256             ),
257             $this->rewrite_method[$root_path]
258         );
259 //        $this->rewrite_method[$root_path . 'download/']['file'] = $this->seo_opt['rewrite_files'] ? 'files' : '';</span>
260 <span class="code-comment">        $this->paginate_method = array_merge(
261             array(
262                 'topic' => $this->seo_ext['topic'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
263                 'forum' => $this->seo_ext['forum'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
264                 'group' => $this->seo_ext['group'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
265 //                'user' => $this->seo_ext['user'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',</span>
266 <span class="code-comment">                'atopic' => $this->seo_ext['atopic'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
267                 'utopic' => $this->seo_ext['utopic'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
268                 'npost' => $this->seo_ext['npost'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
269
270                 'index' => $this->seo_ext['index'] === '' ? 'rewrite_index_pagination_page' : 'rewrite_tracker_pagination',
271                 'browse' => $this->seo_ext['browse'] === '/' ? 'rewrite_tracker_pagination_page' : 'rewrite_tracker_pagination',
272                 'details' => $this->seo_ext['details'] === '/' ? 'rewrite_tracker_pagination_page' : 'rewrite_tracker_pagination',
273                 'search' => $this->seo_ext['search'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
274                 'group' => $this->seo_ext['group'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
275                 'userdetails' => $this->seo_ext['userdetails'] === '/' ? 'rewrite_tracker_pagination_page' : 'rewrite_tracker_pagination',
276             ),
277             $this->paginate_method
278         );
279         $this->RegEx = array_merge(
280             array(
281                 'topic' => array(
282                     'check' => '`^' . ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . '(' . $this->seo_static['topic'] . '|[a-z0-9_-]+' . $this->seo_delim['topic'] . ')$`i',
283                     'match' => '`^((([a-z0-9_-]+)(' . $this->seo_delim['forum'] . '([0-9]+))?/)?(' . $this->seo_static['topic'] . '(?!=' . $this->seo_delim['topic'] . ')|.+(?=' . $this->seo_delim['topic'] . '))(' . $this->seo_delim['topic'] . ')?)([0-9]+)$`i',
284                     'parent' => 2,
285                     'parent_id' => 5,
286                     'title' => 6,
287                     'id' => 8,
288                     'url' => 1,
289                 ),
290                 'forum' => array(
291                     'check' => '`^' . ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . '(' . $this->seo_static['forum'] . '|[a-z0-9_-]+' . $this->seo_delim['forum'] . ')$`i',
292                     'match' => '`^((([a-z0-9_-]+)(' . $this->seo_delim['forum_cat'] . '([0-9]+))?/)?(' . $this->seo_static['forum'] . '(?!=' . $this->seo_delim['forum'] . ')|.+(?=' . $this->seo_delim['forum'] . '))(' . $this->seo_delim['forum'] . ')?)([0-9]+)$`i',
293                     'title' => 6,
294                     'id' => 8,
295                 ),
296                 'browse' => array(
297                     'check' => $this->modrtype >= 2 ? '`^[a-z0-9_-]+(' . $this->seo_delim['browse'] . '[0-9]+)?$`i' : '`^' . $this->seo_static['browse'] . '[0-9]+$`i',
298                     'match' => '`^(' . ( $this->seo_opt['virtual_folder'] ? '.*\/' : '') . ')((' . $this->seo_static['browse'] . '|.+)(' . $this->seo_delim['browse'] . '([0-9]+))?)$`i',
299                     'title' => '\3',
300                     'id' => '\5',
301                 ),
302                 'forum_cat' => array(
303                     'check' => $this->modrtype >= 2 ? '`^[a-z0-9_-]+(' . $this->seo_delim['forum_cat'] . '[0-9]+)?$`i' : '`^' . $this->seo_static['forum_cat'] . '[0-9]+$`i',
304                     'match' => '`^((' . $this->seo_static['forum_cat'] . '|.+)(' . $this->seo_delim['forum_cat'] . '([0-9]+))?)$`i',
305                     'title' => '\2',
306                     'id' => '\4',
307                 ),
308                 'details' => array(
309                     'check' => '`^' . ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . '(' . $this->seo_static['details'] . '|[a-z0-9_-]+' . $this->seo_delim['details'] . ')$`i',
310                     'match' => '`^((([a-z0-9_-]+)(' . $this->seo_delim['browse'] . '([0-9]+))?/)?(' . $this->seo_static['details'] . '(?!=' . $this->seo_delim['details'] . ')|.+(?=' . $this->seo_delim['details'] . '))(' . $this->seo_delim['details'] . ')?)([0-9]+)' . str_replace('.', '\.', $this->seo_ext['details']) . '$`i',
311                     'parent' => 2,
312                     'parent_id' => 5,
313                     'title' => 6,
314                     'id' => 8,
315                     'url' => 1,
316                 ),
317             ),
318             $this->RegEx
319         );
320         // preg_replace() patterns for format_url()
321         // One could want to add |th|horn after |slash, but I'm not sure that Þ should be replaced with t and Ð with e
322         $this->RegEx['url_find'] = array('`&([a-z]+)(acute|grave|circ|cedil|tilde|uml|lig|ring|caron|slash);`i', '`&(amp;)?[^;]+;`i', '`[^a-z0-9]`i'); // Do not remove : deaccentuation, html/xml entities & non a-z chars
323         $this->RegEx['url_replace'] = array('\1', '-', '-');
324         if ($this->seo_opt['rem_small_words']) {
325             $this->RegEx['url_find'][] = '`(^|-)[a-z0-9]{1,2}(?=-|$)`i';
326             $this->RegEx['url_replace'][] = '-';
327         }
328         $this->RegEx['url_find'][] ='`[-]+`'; // Do not remove : multi hyphen reduction
329         $this->RegEx['url_replace'][] = '-';
330         // $1 parent : string/
331         // $2 title / url : topic-title / forum-url-fxx
332         // $3 id
333         $this->sftpl = array_merge(
334             array(
335                 'topic' => ($this->seo_opt['virtual_folder'] ? '%1$s' : '') . '%2$s' . $this->seo_delim['topic'] . '%3$s',
336                 'topic_smpl' => ($this->seo_opt['virtual_folder'] ? '%1$s' : '') . $this->seo_static['topic'] . '%3$s',
337                 'forum' => ($this->seo_opt['virtual_folder'] ? '%1$s' : '') . '%2$s' . $this->seo_delim['forum'] . '%3$s',
338                 'forum_cat' => '%2$s' . $this->seo_delim['forum_cat'] . '%3$s',
339                 'group' => $this->seo_opt['profile_inj'] ? '%2$s' . $this->seo_delim['group'] . '%3$s' : $this->seo_static['group'] . '%3$s',
340
341                 'details' => ($this->seo_opt['virtual_folder'] ? '%1$s' : '') . '%2$s' . $this->seo_delim['details'] . '%3$s',
342                 'browse' => ($this->seo_opt['virtual_folder'] ? '%1$s' : '') . '%2$s' . $this->seo_delim['browse'] . '%3$s',
343             ),
344             $this->sftpl
345         );
346         // File setting
347         $this->seo_req_uri();
348         $this->seo_opt['seo_base_href'] = $this->seo_opt['req_file'] = $this->seo_opt['req_self'] = '';
349         if ($script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF')) {
350             // From session.php
351             // Replace backslashes and doubled slashes (could happen on some proxy setups)
352             $this->seo_opt['req_self'] = str_replace(array('\\', '//'), '/', $script_name);
353             // basenamed page name (for example: index)
354             $this->seo_opt['req_file'] = urlencode(htmlspecialchars(str_replace(".php", '', basename($this->seo_opt['req_self']))));
355         }
356         if ( $this->seo_opt['url_rewrite'] && !defined('ADMIN_START') && isset($this->file_hbase[$this->seo_opt['req_file']])) {
357             $this->seo_opt['seo_base_href'] = '<base href="' . $this->file_hbase[$this->seo_opt['req_file']] . '"/>';
358         }
359         return;
360     }
361     /**
362     * will make sure that configured options are consistent
363     * @access private
364     */
365     function check_config() {
366         $this->modrtype = max(0, (int) $this->modrtype);
367         // For profiles and user messages pages, if we do not inject, we do not get rid of ids
368         $this->seo_opt['profile_noids'] = $this->seo_opt['profile_inj'] ? $this->seo_opt['profile_noids'] : false;
369         // If profile noids ...
370         if ($this->seo_opt['profile_noids']) {
371             $this->seo_ext['userdetails'] = '/';
372         }
373         // Profile ans user messages virtual folder
374         if ($this->seo_opt['profile_vfolder']) {
375             $this->seo_ext['userdetails'] = '/';
376         }
377         $this->seo_delim['sr'] = $this->seo_ext['userdetails'] == '/' ? '/' : $this->seo_delim['sr'];
378         // If we use virtual folder, we need '/' at the end of the forum URLs
379         if ($this->seo_opt['virtual_folder']) {
380             $this->seo_ext['forum'] = $this->seo_ext['global_announce'] = $this->seo_ext['browse'] = '/';
381         }
382         // If the forum cache is not activated
383         if (!$this->seo_opt['cache_layer']) {
384             $this->seo_opt['rem_ids'] = false;
385         }
386         // virtual root option
387         if ($this->seo_opt['virtual_root'] && $this->seo_path['phpbb_script']) {
388             // virtual root is available and activated
389             $this->seo_path['urlR'] = $this->seo_path['root_url'];
390             $this->file_hbase['index'] = $this->seo_path['url'];
391             $this->seo_static['index'] = empty($this->seo_static['index']) ? '/' : $this->seo_static['index'];
392         } else {
393             // virtual root is not used or usable
394             $this->seo_opt['virtual_root'] = false;
395         }
396         $this->seo_ext['index'] = empty($this->seo_static['index']) ? '' : ( empty($this->seo_ext['index']) ? '.html' : $this->seo_ext['index']);
397         // In case url rewriting is deactivated
398         if (!$this->seo_opt['url_rewrite'] || $this->modrtype == 0) {
399             $this->seo_opt['sql_rewrite'] = false;
400             $this->seo_opt['zero_dupe']['on'] = false;
401         }
402     }
403     // --> URL rewriting functions <--
404     /**
405     * format_url( $url, $type = 'topic' )
406     * Prepare Titles for URL injection
407     */
408     function format_url( $url, $type = 'topic' ) {
409         //$url = preg_replace('`\[.*\]`U','',$url);
410         if (isset($this->url_replace['find'])) {
411             $url = str_replace($this->url_replace['find'], $this->url_replace['replace'], $url);
412         }
413         $url = htmlentities($url, ENT_COMPAT, 'UTF-8');
414         $url = preg_replace($this->RegEx['url_find'] , $this->RegEx['url_replace'], $url);
415         $url = strtolower(trim($url, '-'));
416         return empty($url) ? $type : $url;
417     }
418     /**
419     * set_url( $url, $id = 0, $type = 'forum', $parent = '' )
420     * Prepare url first part and checks cache
421     */
422     //function set_url( $url, $id = 0, $type = 'forum',  $parent = '') {
423     function set_url( $url, $id = 0, $type = 'forum') {
424         if ( !empty($this->seo_parent[$type][$id]['urls']) ) {
425             $parent = implode('/', $this->seo_parent[$type][$id]['urls']) . '/';
426         }
427         else {
428             $parent = '';
429         }
430
431         if ( empty($this->seo_url[$type][$id]) ) {
432             $this->seo_parent[$type][$id]['parent_set'] = true;
433             $this->seo_url[$type][$id] = ( !empty($this->cache_config[$type][$id]) ? $parent . $this->cache_config[$type][$id] : sprintf($this->sftpl[$type], $parent, $this->format_url($url, $this->seo_static[$type]), $id) );
434         }
435         elseif ( $parent && empty($this->seo_parent[$type][$id]['parent_set']) ) {
436             $this->seo_url[$type][$id] = $parent . $this->seo_url[$type][$id];
437             $this->seo_parent[$type][$id]['parent_set'] = true;
438         }
439         unset($this->seo_parent[$type][$id]['urls']);
440
441         return $this->seo_url[$type][$id];
442     }
443
444     /**
445     */
446     function set_parent( $id = 0, $type = '', $parent_id = '', $parent_type = '' ) {
447         $url = ( !empty($this->seo_url[$parent_type][$parent_id]) ? $this->seo_url[$parent_type][$parent_id] : '' );
448         $this->seo_parent[$type][$id]['urls'][] = !empty($this->cache_config[$parent_type][$parent_id]) ? $this->cache_config[$parent_type][$parent_id] : $url;
449     }
450     /**
451     * prepare_url( $type, $title, $id, $parent = '', $smpl = false )
452     * Prepare url first part
453     */
454     function prepare_url( $type, $title, $id, $parent = '', $smpl = false ) {
455         return empty($this->seo_url[$type][$id]) ? ($this->seo_url[$type][$id] = sprintf($this->sftpl[$type . ($smpl ? '_smpl' : '')], $parent, !$smpl ? $this->format_url($title, $this->seo_static[$type]) : '', $id)) : $this->seo_url[$type][$id];
456     }
457     /**
458     * set_title( $type, $title, $id, $parent = '' )
459     * Set title for url injection
460     */
461     function set_title( $type, $title, $id, $parent = '' ) {
462         return empty($this->seo_url[$type][$id]) ? ($this->seo_url[$type][$id] = ($parent ? $parent . '/' : '') . $this->format_url($title, $this->seo_static[$type])) : $this->seo_url[$type][$id];
463     }
464     /**
465     * get_url_info($type, $url, $info = 'title')
466     * Get info from url (title, id, parent etc ...)
467     */
468     function get_url_info($type, $url, $info = 'title') {
469         $url = trim($url, '/ ');
470         if (preg_match($this->RegEx[$type]['match'], $url, $matches)) {
471             return !empty($matches[$this->RegEx[$type][$info]]) ? $matches[$this->RegEx[$type][$info]] : '';
472         }
473         return '';
474     }
475     /**
476     * check_url( $type, $url, $parent = '')
477     * Validate a prepared url
478     */
479     function check_url( $type, $url, $parent = '') {
480         if (empty($url)) {
481             return false;
482         }
483         $parent = !empty($parent) ? (string) $parent : '[a-z0-9/_-]+';
484         return !empty($this->RegEx[$type]['check']) ? preg_match(sprintf($this->RegEx[$type]['check'], $parent), $url) : false;
485     }
486     /**
487     * prepare_iurl( $data, $type, $parent = '' )
488     * Prepare url first part (not for forums) with SQL based URL rewriting
489     */
490     function prepare_iurl( $data, $type, $parent = '' ) {
491         $id = max(0, (int) $data[$type . '_id']);
492         if ( empty($this->seo_url[$type][$id]) ) {
493             if (!empty($data[$type . '_url'])) {
494                 return ($this->seo_url[$type][$id] = $data[$type . '_url'] . $id);
495             } else {
496                 return ($this->seo_url[$type][$id] = sprintf($this->sftpl[$type . ($this->modrtype > 2 ? '' : '_smpl')], $parent, $this->modrtype > 2 ? $this->format_url($data[$type . '_title'], $this->seo_static[$type]) : '', $id));
497             }
498         }
499         return $this->seo_url[$type][$id];
500     }
501     /**
502     * drop_sid( $url )
503     * drop the sid's in url
504     */
505     function drop_sid( $url ) {
506         return (strpos($url, 'sid=') !== false) ? trim(preg_replace(array('`&(amp;)?sid=[a-z0-9]*(&amp;|&)?`', '`(\?)sid=[a-z0-9]*`'), array('\2', '\1'), $url), '?') : $url;
507     }
508     /**
509     * simple function to set torrent url with cats and it's set cat url with parents
510     * if called where cat urls used to, then no need to call set_cat_url
511     * @access public
512     */
513     function set_torrent_url ( $fid, $name, $cat_id ) {
514         global $cache;
515         static $cats;
516
517         if ( !isset($cats) ) {
518             $cats = $cache->obtain_cats();
519         }
520
521         $name = strip_tags(censor_text($name));
522
523         $cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 );
524
525         if ( $cat_parent_id ) {
526             $this->set_url($cats[$cat_parent_id]['cat_name'], $cat_parent_id, $this->seo_static['browse']);
527             $this->set_parent($cat_id, $this->seo_static['browse'], $cat_parent_id, $this->seo_static['browse']);
528             //$this->set_parent($fid, $this->seo_static['details'], $cat_parent_id, $this->seo_static['browse']);
529         }
530
531         $this->set_url($cats[$cat_id]['cat_name'], $cat_id, $this->seo_static['browse']);
532
533         $this->set_parent($fid, $this->seo_static['details'], $cat_id, $this->seo_static['browse']);
534
535         $this->set_url($name, $fid, $this->seo_static['details']);
536     }
537
538     /**
539     * simple function to set cat url with parents
540     * @access public
541     */
542     function set_cat_url ( $cat_id, $name ) {
543         global $cache;
544         static $cats;
545
546         if ( !isset($cats) ) {
547             $cats = $cache->obtain_cats();
548         }
549
550         $name = censor_text($cats[$cat_id]['cat_name']);
551
552         $cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 );
553
554         if ( $cat_parent_id ) {
555             $cat_parent_name = censor_text($cats[$cat_parent_id]['cat_name']);
556
557             $this->set_url($cat_parent_name, $cat_parent_id, $this->seo_static['browse']);
558             $this->set_parent($cat_id, $this->seo_static['browse'], $cat_parent_id, $this->seo_static['browse']);
559         }
560
561         $this->set_url($name, $cat_id, $this->seo_static['browse']);
562     }
563
564     function setForumUrl ( $forumId, $forumName ) {
565         global $cache;
566         static $forumCats, $forums, $forumsParent;
567
568         if ( !isset($forumCats) ) {
569             $forumCats = $cache->obtainForumCats();
570         }
571
572         if ( !isset($forumsParent) ) {
573             list($forums, $forumsParent) = $cache->obtainForums();
574         }
575
576         $forumCat = $forums[$forumId]['cat_id'];
577         $forumParentId = ( isset($forums[$forumId]['forum_parent']) ? $forums[$forumId]['forum_parent'] : 0 );
578
579         $this->set_url($forumCats[$forumCat]['cat_title'], $forumCat, $this->seo_static['forum_cat']);
580
581         if ( $forumParentId ) {
582         //set parent cat for parent forum
583         $this->set_parent($forumParentId, $this->seo_static['forum'], $forumCat, $this->seo_static['forum_cat']);
584         $this->set_url($forums[$forumParentId]['forum_name'], $forumParentId, $this->seo_static['forum']);
585
586         $this->set_parent($forumId, $this->seo_static['forum'], $forumParentId, $this->seo_static['forum']);
587         }
588         else {
589         $this->set_parent($forumId, $this->seo_static['forum'], $forumCat, $this->seo_static['forum_cat']);
590         }
591
592
593         $this->set_url($forumName, $forumId, $this->seo_static['forum']);
594     }
595
596     /**
597     * set_user_url( $username, $user_id = 0 )
598     * Prepare profile url
599     */
600     function set_user_url( $username, $user_id = 0 ) {
601         if (empty($this->seo_url['userdetails'][$user_id])) {
602             $this->seo_url['username'][$username] = $user_id;
603             if ( $this->seo_opt['profile_inj'] ) {
604                 if ( $this->seo_opt['profile_noids'] ) {
605                     $this->seo_url['userdetails'][$user_id] = $this->seo_static['userdetails'] . '/' . $this->seo_url_encode($username);
606                 } else {
607                     $this->seo_url['userdetails'][$user_id] = $this->format_url($username$this->seo_delim['userdetails']) . $this->seo_delim['userdetails'] . $user_id;
608                 }
609             } else {
610                 $this->seo_url['userdetails'][$user_id] = $this->seo_static['userdetails'] . $user_id;
611             }
612         }
613     }
614     /**
615     * seo_url_encode( $url )
616     * custom urlencoding
617     */
618     function seo_url_encode( $url ) {
619         // can be faster to return $url directly if you do not allow more chars than
620         // [a-zA-Z0-9_\.-] in your usernames
621         // return $url;
622         // Here we hanlde the "&", "/", "+" and "#" case proper ( http://www.php.net/urlencode => http://issues.apache.org/bugzilla/show_bug.cgi?id=34602 )
623         static $find = array('&', '/', '#', '+');
624         static $replace = array('%26', '%2F', '%23', '%2b');
625         return rawurlencode(str_replace( $find, $replace, htmlspecialchars_decode(str_replace('&amp;amp;', '%26', rawurldecode($url)))));
626     }
627     /**
628     * url_rewrite($url, $params = false, $is_amp = true, $session_id = false)
629     * builds and Rewrite URLs.
630     * Allow adding of many more cases than just the
631     * regular phpBB URL rewritting without slowing down the process.
632     * Mimics append_sid with some shortcuts related to how url are rewritten
633     */
634     function url_rewrite($url, $params = false, $is_amp = true, $session_id = false) {
635         global $userdata, $_SID, $_EXTRA_URL, $root_path;
636         $qs = $anchor = '';
637         $this->get_vars = array();
638         $amp_delim = ($is_amp) ? '&amp;' : '&';
639         if (strpos($url, '#') !== false) {
640             list($url, $anchor) = explode('#', $url, 2);
641             $anchor = '#' . $anchor;
642         }
643         @list($this->path, $qs) = explode('?', $url, 2);
644         if (is_array($params)) {
645             if (!empty($params['#'])) {
646                 $anchor = '#' . $params['#'];
647                 unset($params['#']);
648             }
649             $qs .= ($qs ? $amp_delim : '') . $this->query_string($params, $amp_delim, '');
650         } elseif ($params) {
651             if (strpos($params, '#') !== false) {
652                 list($params, $anchor) = explode('#', $params, 2);
653                 $anchor = '#' . $anchor;
654             }
655             $qs .= ($qs ? $amp_delim : '') . $params;
656         }
657         // Appending custom url parameter?
658         if (!empty($_EXTRA_URL)) {
659             $qs .= ($qs ? $amp_delim : '') . implode($amp_delim, $_EXTRA_URL);
660         }
661         // Sid ?
662         if ($session_id === false && !empty($_SID)) {
663             $qs .= ($qs ? $amp_delim : '') . "sid=$_SID";
664         } else if ($session_id) {
665             $qs .= ($qs ? $amp_delim : '') . "sid=$session_id";
666         }
667         // Build vanilla URL
668         if (preg_match("`\.[a-z0-9]+$`i", $this->path) ) {
669             $this->file = basename($this->path);
670             $this->path = ltrim(str_replace($this->file, '', $this->path), '/');
671         } else {
672             $this->file = '';
673             $this->path = ltrim($this->path, '/');
674         }
675         $this->url_in = $this->file . ($qs ? '?' . $qs : '');
676         $url = $this->path . $this->url_in . $anchor;
677         if (isset($this->seo_cache[$url])) {
678             return $this->seo_cache[$url];
679         }
680         if ( !$this->seo_opt['url_rewrite'] || defined('ADMIN_START') || isset($this->seo_stop_dirs[$this->path]) ) {
681             return ($this->seo_cache[$url] = $url);
682         }
683         $this->filename = trim(str_replace(".php", '', $this->file));
684         if ( isset($this->seo_stop_files[$this->filename]) ) {
685             // add full url
686             $url = $this->path == $phpbb_root_path ? $this->seo_path['phpbb_url'] . preg_replace('`^' . $phpbb_root_path . '`', '', $url) : $url;
687             return ($this->seo_cache[$url] = $url);
688         }
689         parse_str(str_replace('&amp;', '&', $qs), $this->get_vars);
690         // strp slashes if necessary
691         if (defined('STRIP')) {
692             $this->get_vars = array_map(array(&$this, 'stripslashes'), $this->get_vars);
693         }
694         if (empty($userdata['session_logged_in'])) {
695             if ( $this->seo_opt['rem_sid'] ) {
696                 unset($this->get_vars['sid']);
697             }
698             if ( $this->seo_opt['rem_hilit'] ) {
699                 unset($this->get_vars['highlight']);
700             }
701         }
702         $this->url = $this->file;
703         if ( !empty($this->rewrite_method[$this->path][$this->filename]) ) {
704             $this->{$this->rewrite_method[$this->path][$this->filename]}();
705             return ($this->seo_cache[$url] = $this->path . $this->url . $this->query_string($this->get_vars, $amp_delim, '?') . $anchor);
706         } else {
707             return ($this->seo_cache[$url] = $url);
708         }
709     }
710     /**
711     * URL rewritting for viewtopic.php
712     * With Virtual Folder Injection
713     * @access private
714     */
715     function viewtopic() {
716         global $root_path;
717         $this->filter_url($this->seo_stop_vars);
718         $this->path = $this->seo_path['urlR'];
719         if ( !empty($this->get_vars['p']) ) {
720             $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_static['post'] . $this->get_vars['p'] . $this->seo_ext['post'];
721             unset($this->get_vars['p'], $this->get_vars['f'], $this->get_vars['t'], $this->get_vars['start']);
722             return;
723         }
724         if ( isset($this->get_vars['t']) && !empty($this->seo_url['topic'][$this->get_vars['t']]) ) {
725             // Filter default params
726             $this->filter_get_var($this->filter['topic']);
727             $this->{$this->paginate_method['topic']}($this->seo_ext['topic']);
728             $this->print_topic();
729             $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_url['topic'][$this->get_vars['t']] . $this->print . $this->start;
730             unset($this->get_vars['t'], $this->get_vars['f'], $this->get_vars['p']);
731             return;
732         } else if (!empty($this->get_vars['t'])) {
733             // Filter default params
734             $this->filter_get_var($this->filter['topic']);
735             $this->{$this->paginate_method['topic']}($this->seo_ext['topic']);
736             $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_static['topic'] . $this->get_vars['t'] . $this->start;
737             unset($this->get_vars['t'], $this->get_vars['f'], $this->get_vars['p']);
738             return;
739         }
740         $this->path = $this->seo_path['url'];
741         return;
742     }
743     /**
744     * URL rewritting for viewforum.php
745     * @access private
746     */
747     function viewforum() {
748         global $root_path;
749         $this->path = $this->seo_path['urlR'];
750         $this->filter_url($this->seo_stop_vars);
751         if ( isset($this->get_vars['f']) && !empty($this->seo_url['forum'][$this->get_vars['f']]) ) {
752             // Filter default params
753             $this->filter_get_var($this->filter['forum']);
754             $this->{$this->paginate_method['forum']}($this->seo_ext['forum']);
755             $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_url['forum'][$this->get_vars['f']] . $this->start;
756             unset($this->get_vars['f']);
757             return;
758         } else if (!empty($this->get_vars['f'])) {
759             // Filter default params
760             $this->filter_get_var($this->filter['forum']);
761             $this->{$this->paginate_method['forum']}($this->seo_ext['forum']);
762             $this->url = $this->seo_static['forum'] . $this->get_vars['f'] . $this->start;
763             unset($this->get_vars['f']);
764             return;
765         }
766         $this->path = $this->seo_path['url'];
767         return;
768     }
769     /**
770     * URL rewritting for userdetails.php
771     * with nicknames and group name injection
772     * @access private
773     */
774     function userdetails() {
775         global $root_path;
776         $this->path = $this->seo_path['urlR'];
777         if ( !empty($this->get_vars['action']) ) {
778
779             if ( !empty($this->get_vars['id']) ) {
780                 $url = $this->seo_url['userdetails'][$this->get_vars['id']] . $this->seo_delim['sr'];
781             }
782             else {
783                 $url = $this->seo_static['userdetails'] . $this->seo_ext['userdetails'] . $this->get_vars['un'] . $this->seo_delim['sr'];
784             }
785
786             switch ( $this->get_vars['action'] ) {
787                 case 'comments_history':
788                     $this->{$this->paginate_method['userdetails']}($this->seo_ext['userdetails']);
789                     $this->url = $url . 'comments' . $this->start;
790                 break;
791
792                 default:
793                     $this->url = $url . $this->get_vars['action'] . $this->seo_delim['sr'];
794                 break;
795
796             }
797
798             unset($this->get_vars['action'], $this->get_vars['id'], $this->get_vars['un']);
799         }
800         elseif ( @isset($this->seo_url['userdetails'][$this->get_vars['id']]) ) {
801             $this->url = $this->seo_url['userdetails'][$this->get_vars['id']] . $this->seo_ext['userdetails'];
802             unset($this->get_vars['id']);
803             return;
804         }
805         $this->path = $this->seo_path['url'];
806         return;
807     }
808     /**
809     * URL rewritting for search.php
810     * @access private
811     */
812     function search() {
813         global $root_path, $userdata;
814         $this->path = $this->seo_path['urlR'];
815         $user_id = !empty($this->get_vars['author_id']) ? $this->get_vars['author_id'] : ( isset($this->seo_url['username'][rawurldecode(@$this->get_vars['author'])]) ? $this->seo_url['username'][rawurldecode($this->get_vars['author'])] : 0);
816         if ( $user_id && isset($this->seo_url['user'][$user_id]) ) {
817             // Filter default params
818             $this->filter_get_var($this->filter['search']);
819             $this->{$this->paginate_method['user']}($this->seo_ext['user']);
820             $sr = (@$this->get_vars['sr'] == 'topics' ) ? 'topics' : 'posts';
821             $this->url = $this->seo_url['user'][$user_id] . $this->seo_delim['sr'] . $sr . $this->start;
822             unset($this->get_vars['author_id'], $this->get_vars['author'], $this->get_vars['sr']);
823             return;
824         } elseif ( $this->seo_opt['profile_noids'] && !empty($this->get_vars['author']) ) {
825             // Filter default params
826             $this->filter_get_var($this->filter['search']);
827             $this->rewrite_pagination_page();
828             $sr = (@$this->get_vars['sr'] == 'topics' ) ? '/topics' : '/posts';
829             $this->url = $this->seo_static['user'] . '/' . $this->seo_url_encode($this->get_vars['author']) . $sr . $this->start;
830             unset($this->get_vars['author'], $this->get_vars['author_id'], $this->get_vars['sr']);
831             return;
832         } elseif ( $this->seo_opt['profile_noids'] && !empty($this->get_vars['search_author']) ) {
833             $this->url = $this->seo_static['userdetails'] . $this->seo_delim['sr'] . $this->get_vars['search_author'] . $this->seo_delim['sr'] . 'topics' . $this->seo_ext['userdetails'];
834             unset($this->get_vars['search_author']);
835             return;
836         }
837         elseif (!empty($this->get_vars['search_id'])) {
838             switch ($this->get_vars['search_id']) {
839                 case 'active_topics':
840                     $this->filter_get_var($this->filter['search']);
841                     $this->{$this->paginate_method['atopic']}($this->seo_ext['atopic']);
842                     $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_static['atopic'] . $this->start;
843                     unset($this->get_vars['search_id'], $this->get_vars['sr']);
844                     if (@$this->get_vars['st'] == 7) {
845                         unset($this->get_vars['st']);
846                     }
847                     return;
848                 case 'unanswered':
849                     $this->filter_get_var($this->filter['search']);
850                     $this->{$this->paginate_method['utopic']}($this->seo_ext['utopic']);
851                     $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_static['utopic'] . $this->start;
852                     unset($this->get_vars['search_id']);
853                     if (@$this->get_vars['sr'] == 'topics') {
854                         unset($this->get_vars['sr']);
855                     }
856                     return;
857                 case 'egosearch':
858                     global $userdata;
859                     $this->set_user_url($userdata['name'], $userdata['uid']);
860                     $this->rewrite_pagination_page();
861                     $this->url = $this->seo_url['userdetails'][$userdata['uid']] . $this->seo_delim['sr'] . 'topics' . $this->start;
862                     unset($this->get_vars['search_id']);
863                     return;
864                 case 'newposts':
865                     $this->filter_get_var($this->filter['search']);
866                     $this->{$this->paginate_method['npost']}($this->seo_ext['npost']);
867                     $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_static['npost'] . $this->start;
868                     unset($this->get_vars['search_id']);
869                     if (@$this->get_vars['sr'] == 'topics') {
870                         unset($this->get_vars['sr']);
871                     }
872                     return;
873             }
874         }
875         $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_static['search'] . $this->seo_ext['search'];
876         //$this->path = $this->seo_path['url'];
877         return;
878     }
879     /**
880     * URL rewritting for download/file.php
881     * @access private
882     */
883     function files() {
884         $this->filter_url($this->seo_stop_vars);
885         $this->path = $this->seo_path['filesR'];
886         if (isset($this->get_vars['id']) && !empty($this->seo_url['file'][$this->get_vars['id']])) {
887             $this->url = $this->seo_url['file'][$this->get_vars['id']];
888             if (!empty($this->get_vars['t'])) {
889                 $this->url .= $this->seo_delim['file'] . $this->seo_static['thumb'];
890             } /*else if (@$this->get_vars['mode'] == 'view') {
891                 $this->url .= $this->seo_delim['file'] . 'view';
892             }*/
893             $this->url .= $this->seo_delim['file'] . $this->get_vars['id'];
894             unset($this->get_vars['id'], $this->get_vars['t'], $this->get_vars['mode']);
895             return;
896         }
897         $this->path = $this->seo_path['files'];
898         return;
899     }
900     /**
901     * URL rewritting for index.php
902     * @access private
903     */
904     function index() {
905         global $root_path;
906         $this->path = $this->seo_path['urlR'];
907         if ($this->filter_url($this->seo_stop_vars)) {
908             $this->{$this->paginate_method['index']}($this->seo_ext['index']);
909             $this->url = $this->seo_static['index'] . $this->start;
910             return;
911         }
912         $this->path = $this->seo_path['url'];
913         return;
914     }
915     /**
916     * URL rewritting for details.php
917     * With Virtual Folder Injection
918     * @access private
919     */
920     function details() {
921         global $root_path;
922         $this->filter_url($this->seo_stop_vars);
923         $this->path = $this->seo_path['urlR'];
924         if ( @$this->get_vars['action'] == 'download' && isset($this->get_vars['id']) && !empty($this->seo_url['details'][$this->get_vars['id']]) ) {
925             // Filter default params
926             $this->filter_get_var($this->filter['details']);
927             $this->{$this->paginate_method['details']}($this->seo_ext['details']);
928             $this->url = $this->seo_url['details'][$this->get_vars['id']] . '.torrent';
929             unset($this->get_vars['id'], $this->get_vars['action']);
930             return;
931         }
932         if ( isset($this->get_vars['id']) && !empty($this->seo_url['details'][$this->get_vars['id']]) ) {
933             // Filter default params
934             $this->filter_get_var($this->filter['details']);
935             $this->{$this->paginate_method['details']}($this->seo_ext['details']);
936             $this->url = $this->seo_url['details'][$this->get_vars['id']] . $this->start;
937             unset($this->get_vars['id']);
938             return;
939         } else if (!empty($this->get_vars['id'])) {
940             // Filter default params
941             $this->filter_get_var($this->filter['details']);
942             $this->{$this->paginate_method['details']}($this->seo_ext['details']);
943             $this->url = $this->seo_static['details'] . $this->get_vars['id'] . $this->start;
944             unset($this->get_vars['id']);
945             return;
946         }
947         $this->path = $this->seo_path['url'];
948         return;
949     }
950     /**
951     * URL rewritting for browse.php
952     * @access private
953     */
954     function browse() {
955         global $root_path;
956         $this->path = $this->seo_path['urlR'];
957         $this->filter_url($this->seo_stop_vars);
958         if ( isset($this->get_vars['cat']) && !empty($this->seo_url['browse'][$this->get_vars['cat']]) ) {
959             // Filter default params
960             $this->filter_get_var($this->filter['browse']);
961             $this->{$this->paginate_method['browse']}($this->seo_ext['browse']);
962             $this->url = $this->seo_url['browse'][$this->get_vars['cat']] . $this->start;
963             unset($this->get_vars['cat'], $this->get_vars['cat_p']);
964             return;
965         }
966
967         if ( isset($this->get_vars['search_in']) ) {
968             // Filter default params
969             $this->filter_get_var($this->filter['browse']);
970             $this->{$this->paginate_method['browse']}($this->seo_ext['browse']);
971
972             switch( $this->get_vars['search_in'] ){
973                 case 1:
974                     $this->url = $this->seo_static['browse_static'] . ( !empty($this->get_vars['search']) ? '/name/' . $this->get_vars['search'] : '' ) . $this->start;
975                 break;
976                 case 2:
977                     $this->url = $this->seo_static['browse_static'] . ( !empty($this->get_vars['search']) ? '/descr/' . $this->get_vars['search'] : '' ) . $this->start;
978                 break;
979                 case 3:
980                     $this->url = $this->seo_static['browse_static'] . ( !empty($this->get_vars['search']) ? '/tags/' . $this->get_vars['search'] : '' ) . $this->start;
981                 break;
982             } // switch
983
984             unset($this->get_vars['search_in'], $this->get_vars['search']);
985
986             return;
987         }
988
989         $this->{$this->paginate_method['browse']}($this->seo_ext['browse_static']);
990         $this->url = $this->seo_static['browse_static'] . $this->start;
991         return;
992
993         $this->path = $this->seo_path['url'];
994         return;
995     }
996     /**
997     * URL rewritting for phpbb2.php
998     * @access private
999     */
1000     function phpbb2() {
1001         if ( !empty($this->get_vars['page']) ) {
1002             if ( !empty($this->rewrite_method[$this->path][$this->get_vars['page']]) ) {
1003                 $this->{$this->rewrite_method[$this->path][$this->get_vars['page']]}();
1004                 unset($this->get_vars['page']);
1005                 return;
1006             }
1007         }
1008         elseif ( isset($this->get_vars['c']) ) {
1009             $this->viewforumcat();
1010             return;
1011         }
1012         $this->path = $this->seo_path['urlR'];
1013         if ($this->filter_url($this->seo_stop_vars)) {
1014             $this->url = $this->seo_static['phpbb2'] . $this->seo_ext['phpbb2'];
1015             return;
1016         }
1017         $this->path = $this->seo_path['url'];
1018         return;
1019     }
1020
1021     /**
1022     * URL rewritting for viewforum.php
1023     * @access private
1024     */
1025     function viewforumcat() {
1026         global $root_path;
1027         $this->path = $this->seo_path['urlR'];
1028         $this->filter_url($this->seo_stop_vars);
1029         if ( isset($this->get_vars['c']) && !empty($this->seo_url['forum_cat'][$this->get_vars['c']]) ) {
1030             $this->url = $this->seo_opt['phpbb2_inj'] . $this->seo_url['forum_cat'][$this->get_vars['c']] . $this->seo_ext['forum_cat'];
1031             unset($this->get_vars['c']);
1032             return;
1033         }
1034         $this->path = $this->seo_path['url'];
1035         return;
1036     }
1037     /**
1038     * URL rewritting for comment.php
1039     * @access private
1040     */
1041     function comment() {
1042         $this->path = $this->seo_path['urlR'];
1043         if ($this->filter_url($this->seo_stop_vars)) {
1044             if ( !empty($this->get_vars['cid']) ) {
1045                 $this->url = $this->seo_static['comment'] . $this->get_vars['cid'] . $this->seo_ext['comment'];
1046                 unset($this->get_vars['cid']);
1047             }
1048             else {
1049                 $this->url = $this->seo_static['comment'] . $this->seo_ext['comment'];
1050             }
1051             return;
1052         }
1053         $this->path = $this->seo_path['url'];
1054         return;
1055     }
1056     /**
1057     * URL rewritting for faq.php
1058     * @access private
1059     */
1060     function faq() {
1061
1062         $this->path = $this->seo_path['urlR'];
1063         if ($this->filter_url($this->seo_stop_vars)) {
1064             if ( !empty($this->get_vars['mode']) ) {
1065                 $this->url = $this->seo_static['faq'] . '_' . $this->get_vars['mode'] . $this->seo_ext['faq'];
1066                 unset($this->get_vars['mode']);
1067             }
1068             else {
1069                 $this->url = $this->seo_static['faq'] . $this->seo_ext['faq'];
1070             }
1071             return;
1072         }
1073         $this->path = $this->seo_path['url'];
1074         return;
1075     }
1076     /**
1077     * URL rewritting for rules.php
1078     * @access private
1079     */
1080     function rules() {
1081         $this->path = $this->seo_path['urlR'];
1082         if ($this->filter_url($this->seo_stop_vars)) {
1083             $this->url = $this->seo_static['rules'] . $this->seo_ext['rules'];
1084             return;
1085         }
1086         $this->path = $this->seo_path['url'];
1087         return;
1088     }
1089     /**
1090     * URL rewritting for login.php
1091     * @access private
1092     */
1093     function login() {
1094         $this->path = $this->seo_path['urlR'];
1095         if ($this->filter_url($this->seo_stop_vars)) {
1096             $this->url = $this->seo_static['login'] . $this->seo_ext['login'];
1097             return;
1098         }
1099         $this->path = $this->seo_path['url'];
1100         return;
1101     }
1102     /**
1103     * URL rewritting for signup.php
1104     * @access private
1105     */
1106     function signup() {
1107         $this->path = $this->seo_path['urlR'];
1108         if ($this->filter_url($this->seo_stop_vars)) {
1109             $this->url = $this->seo_static['signup'] . $this->seo_ext['signup'];
1110             return;
1111         }
1112         $this->path = $this->seo_path['url'];
1113         return;
1114     }
1115     /**
1116     * Returns true if the user can edit urls
1117     * @access public
1118     */
1119     function url_can_edit($forum_id = 0) {
1120         global $userdata, $auth;
1121         if (empty($this->seo_opt['sql_rewrite']) || empty($userdata['session_logged_in'])) {
1122             return false;
1123         }
1124         if ($auth->acl_get('a_')) {
1125             return true;
1126         }
1127         // un comment to grant url edit perm to moderators in at least a forums
1128         /*if ($auth->acl_getf_global('m_')) {
1129             return true;
1130         }*/
1131         $forum_id = max(0, (int) $forum_id);
1132         if ($forum_id && $auth->acl_get('m_', $forum_id)) {
1133             return true;
1134         }
1135         return false;
1136     }
1137     /**
1138     * Will break if a $filter pattern is foundin $url.
1139     * Example $filter = array("view=", "mark=");
1140     * @access private
1141     */
1142     function filter_url($filter = array()) {
1143         foreach ($filter as $patern ) {
1144             if ( strpos($this->url_in, $patern) !== false ) {
1145                 $this->get_vars = array();
1146                 $this->url = $this->url_in;
1147                 return false;
1148             }
1149         }
1150         return true;
1151     }
1152     /**
1153     * Will unset all default var stored in $filter array.
1154     * Example $filter = array('st' => 0, 'sk' => 't', 'sd' => 'a', 'hilit' => '');
1155     * @access private
1156     */
1157     function filter_get_var($filter = array()) {
1158         if ( !empty($this->get_vars) ) {
1159             foreach ($this->get_vars as $paramkey => $paramval) {
1160                 if ( isset($filter[$paramkey]) ) {
1161                     if ( $filter[$paramkey] ==  $this->get_vars[$paramkey] || !isset($this->get_vars[$paramkey])) {
1162                         unset($this->get_vars[$paramkey]);
1163                     }
1164                 }
1165             }
1166         }
1167         return;
1168     }
1169     /**
1170     * Appends the GET vars in the query string
1171     * @access public
1172     */
1173     function query_string($get_vars = array(), $amp_delim = '&amp;', $url_delim = '?') {
1174         if(empty($get_vars)) {
1175             return '';
1176         }
1177         $params = array();
1178         foreach($get_vars as $key => $value) {
1179             if (is_array($value)) {
1180                 foreach($value as $k => $v) {
1181                     $params[] = $key . '[' . $k . ']=' . $v;
1182                 }
1183             } else {
1184                 $params[] = $key . (!trim($value) ? '' : '=' . $value);
1185             }
1186         }
1187         return $url_delim . implode($amp_delim , $params);
1188     }
1189     /**
1190     * rewrite pagination, simple
1191     * -xx.html
1192     */
1193     function rewrite_pagination($suffix) {
1194         $this->start = $this->seo_start( @$this->get_vars['start'] ) . $suffix;
1195         unset($this->get_vars['start']);
1196     }
1197     /**
1198     * rewrite pagination, virtual folder
1199     * /pagexx.html
1200     */
1201     function rewrite_pagination_page() {
1202         $this->start = '/' . $this->seo_start_page( @$this->get_vars['start'] );
1203         unset($this->get_vars['start']);
1204     }
1205     /**
1206     * rewrite pagination, virtual folder
1207     * /pagexx.html
1208     */
1209     function rewrite_index_pagination_page() {
1210         $this->start = ( @$this->get_vars['page'] ? $this->seo_start_page( $this->get_vars['page'] ) : '' );
1211         unset($this->get_vars['page']);
1212     }
1213     /**
1214     * rewrite pagination, simple
1215     * -xx.html
1216     */
1217     function rewrite_tracker_pagination($suffix) {
1218         $this->start = $this->seo_start( @$this->get_vars['page'] ) . $suffix;
1219         unset($this->get_vars['page']);
1220     }
1221     /**
1222     * rewrite pagination, virtual folder
1223     * /pagexx.html
1224     */
1225     function rewrite_tracker_pagination_page() {
1226         $this->start = '/' . $this->seo_start_page( @$this->get_vars['page'] );
1227         unset($this->get_vars['page']);
1228     }
1229     /**
1230     * Returns usable start param
1231     * -xx
1232     */
1233     function seo_start($start) {
1234         return ($start >= 1 ) ? $this->seo_delim['start'] . (int) $start : '';
1235     }
1236     /**
1237     * Returns usable start param
1238     * pagexx.html
1239     * Only used in virtual folder mode
1240     */
1241     function seo_start_page($start) {
1242         return ($start >=1 ) ? $this->seo_static['pagination'] . (int) $start . $this->seo_ext['pagination'] : '';
1243     }
1244
1245
1246     function print_topic () {
1247         $this->print = ( isset($this->get_vars['printertopic']) ? '_' . $this->seo_static['printertopic'] . ( isset($this->get_vars['finish_rel']) ? '-full' : '' ) : '' );
1248         unset($this->get_vars['printertopic']);
1249         unset($this->get_vars['finish_rel']);
1250     }
1251     /**
1252     * Returns the full REQUEST_URI
1253     */
1254     function seo_req_uri() {
1255         if ( !empty($_SERVER['HTTP_X_REWRITE_URL']) ) { // IIS  isapi_rewrite
1256             $this->seo_path['uri'] = ltrim($_SERVER['HTTP_X_REWRITE_URL'], '/');
1257         } elseif ( !empty($_SERVER['REQUEST_URI']) ) { // Apache mod_rewrite
1258             $this->seo_path['uri'] = ltrim($_SERVER['REQUEST_URI'], '/');
1259         } else { // no mod rewrite
1260             $this->seo_path['uri'] =  ltrim($_SERVER['SCRIPT_NAME'], '/') . ( ( !empty($_SERVER['QUERY_STRING']) ) ? '?'.$_SERVER['QUERY_STRING'] : '' );
1261         }
1262         $this->seo_path['uri'] = str_replace( '%26', '&', rawurldecode($this->seo_path['uri']));
1263         // workaround for FF default iso encoding
1264         //if (!$this->is_utf8($this->seo_path['uri'])) {
1265         //    $this->seo_path['uri'] = utf8_normalize_nfc(utf8_recode($this->seo_path['uri'], 'iso-8859-1'));
1266         //}
1267         $this->seo_path['uri'] = $this->seo_path['root_url'] . $this->seo_path['uri'];
1268         return $this->seo_path['uri'];
1269     }
1270     // -> Cache functions
1271     /**
1272     * forum_id(&$forum_id, $forum_uri = '')
1273     * will tell the forum id from the uri or the forum_uri GET var by checking the cache.
1274     */
1275     function get_id_from_uri(&$id, $uri = '', $type = 'browse') {
1276         if (empty($uri)) {
1277             $uri = request_var('uri', '');
1278             unset($_GET['uri'], $_REQUEST['uri']);
1279         }
1280         if (empty($uri)) {
1281             return 0;
1282         }
1283         $uri = end(explode('/', $uri));
1284         if ( isset($this->cache_config[$type . '_flip'][$uri]) ) {
1285             $_id = $this->cache_config[$type . '_flip'][$uri];
1286             $id = max(0, (int) $_id);
1287         } elseif ( $_id = $this->get_url_info($type, $uri, 'id')) {
1288             $id = max(0, (int) $_id);
1289         }
1290         return $id;
1291     }
1292     /**
1293     * check_cache() will tell if the required file exists.
1294     * @access private
1295     */
1296     function check_cache( $type = 'forum', $from_bkp = false ) {
1297         $file = SEO_CACHE_PATH . @$this->cache_config['files'][$type];
1298         if( !$this->cache_config['cache_enable'] || !isset($this->cache_config['files'][$type]) || !file_exists($file) ) {
1299             $this->cache_config['cached'] = false;
1300             return false;
1301         }
1302         include($file);
1303         if (is_array($this->cache_config[$type]) ) {
1304             $this->cache_config['cached'] = true;
1305             return true;
1306         } else {
1307             if ( !$from_bkp ) {
1308                 // Try the current backup
1309                 @copy($file . '.current', $file);
1310                 $this->check_cache( $type, true );
1311             }
1312             $this->cache_config['cached'] = false;
1313             return false;
1314         }
1315     }
1316     /**
1317     * is_utf8($string)
1318     * Borrowed from php.net : http://www.php.net/mb_detect_encoding (detectUTF8)
1319     */
1320     function is_utf8($string) {
1321         // non-overlong 2-byte|excluding overlongs|straight 3-byte|excluding surrogates|planes 1-3|planes 4-15|plane 16
1322         return preg_match('%(?:[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF] |\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})+%xs', $string);
1323     }
1324     /**
1325     * stripslashes($value)
1326     * Borrowed from php.net : http://www.php.net/stripslashes
1327     */
1328     function stripslashes($value) {
1329         return is_array($value) ? array_map(array(&$this, 'stripslashes'), $value) : stripslashes($value);
1330     }
1331     // --> Add on Functions <--
1332     // --> Gen stats
1333     /**
1334     * Returns usable microtime
1335     * Borrowed from php.net
1336     */
1337     function microtime_float() {
1338         return array_sum(explode(' ',microtime()));
1339     }
1340 } // End of the seo class
1341 ?>
1342
Note: See TracBrowser for help on using the browser.