2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 10/24/2004 *
\r
4 * =============== Last change: 11/14/2004 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : rewrite_functions.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Special functions for rewrite extension *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Spezielle Funktion fuer rewrite-Erweiterung *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
\r
42 function REWRITE_LINKS($HTML)
\r
44 global $_GET, $CONFIG;
\r
46 // Skip rewriting for the admin area (which search engine may enter here???)
\r
47 if (ereg($GLOBALS['module'], $CONFIG['rewrite_skipped_mods'])) return $HTML;
\r
49 // Strip slashes with double-backslashes for the preg_replace() function
\r
50 $URL = str_replace("/", "\\/", URL);
\r
52 // Generate target URL
\r
53 $target = URL."/cms/";
\r
55 // Convert modules.php?module=...
\r
56 $test = preg_replace("/".$URL."\\/modules.php\\?module=/i", $target, $HTML);
\r
58 if (eregi(SERVER_URL, $test))
\r
60 // Konvert URLs from my server
\r
61 $URL = str_replace("/", "\\/", SERVER_URL);
\r
62 $test = preg_replace("/".$URL."\\/modules.php\\?module=/i", SERVER_URL."/cms/", $test);
\r
65 // Strip slashes as above for the main URL
\r
66 $target2 = str_replace("/", "\\/", $target);
\r
69 $act = $target."\$1/act/";
\r
71 // Convert &|&action=...
\r
72 $test = preg_replace("/".$target2."(.*)&action=/i", $act, $test);
\r
74 // "The same procedure as last variable"... now for &what=
\r
75 $wht = $target."\$1/wht/";
\r
76 $target2 = str_replace("/", "\\/", $target);
\r
77 $test = preg_replace("/".$target2."(.*)&what=/i", $wht, $test);
\r
79 if ((EXT_IS_ACTIVE("rallye")) && (eregi("rallye=", $test)))
\r
81 // Replace data when rallye extension is active
\r
82 // Add more if you need more like these entries
\r
83 $REPLACE = array("rallye", "activate", "auto", "notify", "sub");
\r
84 foreach ($REPLACE as $var)
\r
86 // This will replace "&var=" to "/var/"
\r
87 $test = preg_replace("/&".$var."=/i", "/".$var."/", $test);
\r
91 // Simple from->to replacements
\r
93 'search' => array("u_id", "url", "page", "offset", "mid", "bid", "sub", "home"),
\r
94 'replace' => array("u" , "url", "page", "offset", "m" , "b" , "s" , "h")
\r
97 if ((EXT_IS_ACTIVE("admins")) && (eregi("admin=", $test)))
\r
99 // Replace &admin= with "/aid/"
\r
100 $REPLACE['search'][] = "admin";
\r
101 $REPLACE['replace'][] = "aid";
\r
104 // Replace all array elements through
\r
105 foreach ($REPLACE['search'] as $k=>$v)
\r
107 if (eregi("$v=", $test))
\r
109 // Replace &u_id= with /u/
\r
110 $test = preg_replace("/&".$v."=/i", "/".$REPLACE['replace'][$k]."/", $test);
\r
114 // Repair missed &what=??? entries
\r
115 while (preg_match("/&what=(.*)\/(.*)\/(.*)/i", $test))
\r
117 $test = preg_replace("/&what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $test);
\r
120 // Return rewritten code
\r