Reverted of changes in 1704, see ticket #160
[mailer.git] / inc / libs / rewrite_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/24/2004 *
4  * ===================                          Last change: 11/14/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : rewrite_functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Special functions for rewrite extension          *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Spezielle Funktion fuer rewrite-Erweiterung      *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 }
44
45 // Rewrite links in HTML for better SEO (ugly part of mx!)
46 function rewriteLinksInCode ($HTML) {
47         // Skip rewriting for configured modules
48         if (eregi(getModule(), getConfig('rewrite_skip')) !== false) return $HTML;
49
50         // Generate target URL
51         $target = '{?URL?}/cms/';
52         $output = $HTML;
53
54         // Final eval()
55         $eval = '$output = "' . compileCode(escapeQuotes($output)) . '";';
56         eval($eval);
57
58         // Convert modules.php?module=...
59         foreach (array(getConfig('URL'), '{?URL?}') as $rewrite) {
60                 $output = str_replace($rewrite . '/modules.php?module=', $target, $output);
61         } // END - foreach
62
63         // Do we have an URL linked to mxchange.org?
64         if (eregi(getConfig('SERVER_URL'), $output)) {
65                 // Convert URLs from my server
66                 $output = str_replace('{?URL?}/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $output);
67
68                 // Convert URLs from my server
69                 $output = str_replace(getConfig('URL') . '/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $output);
70         } // END - if
71
72         // Strip slashes as above for the main URL
73         $target2 = preg_quote($target, '/');
74
75         // Action variable
76         $action = $target . '$1/act/';
77
78         // Convert &amp;|&action=...
79         $output = preg_replace('/' . $target2 . '(.*)&amp;action=/i', $action, $output);
80
81         // "The same procedure as last variable"... now for &amp;what=
82         $what = $target . '$1/wht/';
83         $output = preg_replace('/' . $target2 . '(.*)&amp;what=/i', $what, $output);
84
85         // Repair missed &amp;what=??? entries
86         while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $output)) {
87                 $output = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $output);
88         } // END - while
89
90         // Return rewritten code
91         return $output;
92 }
93
94 // [EOF]
95 ?>