Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / libs / rewrite_functions.php
index 308b42da68ec462cf5ff66e39e2341c2dd36be69..5b76d5a1b31859742baf55c5e72d3f37c8086820 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/24/2004 *
- * ===============                              Last change: 11/14/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 10/24/2004 *
+ * ===================                          Last change: 11/14/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : rewrite_functions.php                            *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Spezielle Funktion fuer rewrite-Erweiterung      *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
+if (!defined('__SECURITY')) {
+       die();
 }
 
-//
-function REWRITE_LINKS($HTML)
-{
-       global $_CONFIG;
-
-       // Skip rewriting for the admin area (which search engine may enter here???)
-       if (ereg($GLOBALS['module'], $_CONFIG['rewrite_skip'])) return $HTML;
-
-       // Strip slashes with double-backslashes for the preg_replace() function
-       $URL = str_replace("/", "\\/", URL);
+// Rewrite links in HTML for better SEO (ugly part of mx!)
+function rewriteLinksInCode ($HTML) {
+       // Skip rewriting for configured modules
+       if (isInStringIgnoreCase(getModule(), getConfig('rewrite_skip')) !== false) return $HTML;
 
        // Generate target URL
-       $target = URL."/cms/";
+       $target = '{?URL?}/cms/';
+
+       // Final eval()
+       $eval = '$output = "' . preCompileCode(escapeQuotes($HTML)) . '";';
+       eval($eval);
 
        // Convert modules.php?module=...
-       $test = preg_replace("/".$URL."\\/modules.php\\?module=/i", $target, $HTML);
+       foreach (array(getConfig('URL'), '{?URL?}') as $rewrite) {
+               $output = str_replace($rewrite . '/modules.php?module=', $target, $output);
+       } // END - foreach
+
+       // Do we have an URL linked to mxchange.org?
+       if (isInStringIgnoreCase(getConfig('SERVER_URL'), $output)) {
+               // Convert URLs from my server
+               $output = str_replace('{?URL?}/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $output);
 
-       if (eregi(SERVER_URL, $test))
-       {
-               // Konvert URLs from my server
-               $URL = str_replace("/", "\\/", SERVER_URL);
-               $test = preg_replace("/".$URL."\\/modules.php\\?module=/i", SERVER_URL."/cms/", $test);
-       }
+               // Convert URLs from my server
+               $output = str_replace(getConfig('URL') . '/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $output);
+       } // END - if
 
        // Strip slashes as above for the main URL
-       $target2 = str_replace("/", "\\/", $target);
+       $target2 = preg_quote($target, '/');
 
        // Action variable
-       $act = $target."\$1/act/";
+       $action = $target . '$1/act/';
 
        // Convert &amp;|&action=...
-       $test = preg_replace("/".$target2."(.*)&amp;action=/i", $act, $test);
+       $output = preg_replace('/' . $target2 . '(.*)&amp;action=/i', $action, $output);
 
        // "The same procedure as last variable"... now for &amp;what=
-       $wht = $target."\$1/wht/";
-       $target2 = str_replace("/", "\\/", $target);
-       $test = preg_replace("/".$target2."(.*)&amp;what=/i", $wht, $test);
-
-       if ((EXT_IS_ACTIVE("rallye")) && (eregi("rallye=", $test)))
-       {
-               // Replace data when rallye extension is active
-               // Add more if you need more like these entries
-               $REPLACE = array("rallye", "activate", "auto", "notify", "sub");
-               foreach ($REPLACE as $var)
-               {
-                       // This will replace "&amp;var=" to "/var/"
-                       $test = preg_replace("/&amp;".$var."=/i", "/".$var."/", $test);
-               }
-       }
-
-       // Simple from->to replacements
-       $REPLACE = array(
-               'search'  => array("u_id", "url", "page", "offset", "mid", "bid", "sub", "home"),
-               'replace' => array("u"   , "url", "page", "offset", "m"  , "b"  , "s"  , "h")
-       );
-
-       if ((EXT_IS_ACTIVE("admins")) && (eregi("admin=", $test)))
-       {
-               // Replace &amp;admin= with "/aid/"
-               $REPLACE['search'][]  = "admin";
-               $REPLACE['replace'][] = "aid";
-       }
-
-       // Replace all array elements through
-       foreach ($REPLACE['search'] as $k=>$v)
-       {
-               if (eregi("$v=", $test))
-               {
-                       // Replace &amp;u_id= with /u/
-                       $test = preg_replace("/&amp;".$v."=/i", "/".$REPLACE['replace'][$k]."/", $test);
-               }
-       }
+       $what = $target . '$1/wht/';
+       $output = preg_replace('/' . $target2 . '(.*)&amp;what=/i', $what, $output);
 
        // Repair missed &amp;what=??? entries
-       while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $test))
-       {
-               $test = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $test);
-       }
+       while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $output)) {
+               $output = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $output);
+       } // END - while
 
        // Return rewritten code
-       return $test;
+       return $output;
 }
-//
+
+// [EOF]
 ?>