2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
16 * Class for rewriting pretty urls on forums.
23 function ForumsUrl() {
24 $this->rule = array(0=>'fid', 1=>'pid');
29 * Construct pretty url by the given query string.
31 function constructPrettyUrl($query){
36 //If this is already a pretty url,but without mod_apache rule
37 //unwrap it and reconstruct
38 if (is_array($query)){
40 foreach($query as $fk=>$fv){
41 if (preg_match('/\.php/', $fv)==1){
42 continue; //skip the php file
45 //check if this is part of the rule, if so,add it, o/w ignore
46 if (array_search($fv, $this->rule)!==FALSE){
47 $new_query .= $fv . '=' . $query[$fk+1] . SEP;
48 } elseif (preg_match('/([0-9]+)\.html/', $fv, $matches)==1){
49 $new_query .= 'page=' . $matches[1] . SEP;
52 $query = $new_query; //done
55 $temp = explode(SEP, $query);
56 foreach ($temp as $index=>$attributes){
57 if(empty($attributes)){
58 //skip the ones that are empty.
61 list($key, $value) = preg_split('/\=/', $attributes, 2);
62 $query_parts[$key] = $value;
67 //construct pretty url on mapping
68 foreach ($this->rule as $key=>$value){
70 //if this value is empty, the url construction should quit.
71 if ($query_parts[$value] ==''){
74 $url .= $query_parts[$value].'/';
76 //if the query parts are not in the defined rules, set it back to query string again
77 if ($query_parts[$this->rule[$key]]!=''){
78 $query_parts[$this->rule[$key]] = '';
82 //Go through the query_parts again, and for those values that are not empty
83 // add it to the querystring
84 foreach($query_parts as $key=>$value){
85 //paginator are handle differently
86 if ($value!='' && $key!='page'){
87 $query_string .= $key.'='.$value.SEP;
90 //take out the last sep.
91 $query_string = substr($query_string, 0, -1);
94 if ($query_parts['page']!=''){
95 $url .= $query_parts['page'].'.html';
98 //append query string at the back
99 if ($query_string!=''){
100 $url .= '?'.$query_string;