X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Frewrite_functions.php;h=467e6babfbbdcf8649ce0c3eb170973201098eb2;hb=33e11a76a6d2d20d20d54ed1a7380ed1375bd3ed;hp=2b1a74b26b4b4d3b67a88538298910b6c6d5f0be;hpb=fb7120ffa230b62b54895bcf95952e1cf30f8594;p=mailer.git diff --git a/inc/libs/rewrite_functions.php b/inc/libs/rewrite_functions.php index 2b1a74b26b..467e6babfb 100644 --- a/inc/libs/rewrite_functions.php +++ b/inc/libs/rewrite_functions.php @@ -38,81 +38,53 @@ // Some security stuff... if (!defined('__SECURITY')) { - $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php"; + $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php'; require($INC); } -// -function REWRITE_LINKS ($HTML) { - // Skip rewriting for the admin area (which search engine may enter here???) - if (ereg($GLOBALS['module'], getConfig('rewrite_skip'))) return $HTML; - - // Strip slashes with double-backslashes for the preg_replace() function - $URL = str_replace("/", "\\/", constant('URL')); +// Rewrite links in HTML for better SEO (ugly part of mx!) +function rewriteLinksInCode ($HTML) { + // Skip rewriting for configured modules + if (eregi($GLOBALS['module'], getConfig('rewrite_skip')) !== false) return $HTML; // Generate target URL - $target = constant('URL')."/cms/"; + $target = "{!URL!}/cms/"; + + // Convert modules.php?module=... + $output = str_replace(constant('URL') . "/modules.php?module=", $target, $HTML); // Convert modules.php?module=... - $test = preg_replace("/".$URL."\\/modules.php\\?module=/i", $target, $HTML); + $output = str_replace("{!URL!}/modules.php?module=", $target, $output); + + // Do we have an URL linked to mxchange.org? + if (eregi(constant('SERVER_URL'), $output)) { + // Convert URLs from my server + $output = str_replace("{!URL!}/modules.php?module=", constant('SERVER_URL')."/cms/", $output); - if (eregi(SERVER_URL, $test)) { - // Konvert URLs from my server - $URL = str_replace("/", "\\/", constant('SERVER_URL')); - $test = preg_replace("/".$URL."\\/modules.php\\?module=/i", constant('SERVER_URL')."/cms/", $test); + // Convert URLs from my server + $output = str_replace(constant('URL') . "/modules.php?module=", constant('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/"; // Convert &|&action=... - $test = preg_replace("/".$target2."(.*)&action=/i", $act, $test); + $output = preg_replace('/' . $target2 . "(.*)&action=/i", $act, $output); // "The same procedure as last variable"... now for &what= $wht = $target."\$1/wht/"; - $target2 = str_replace("/", "\\/", $target); - $test = preg_replace("/".$target2."(.*)&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 "&var=" to "/var/" - $test = preg_replace("/&".$var."=/i", "/".$var."/", $test); - } // END - foreach - } // END - if - - // Simple from->to replacements - $REPLACE = array( - 'search' => array("uid", "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 &admin= with "/aid/" - $REPLACE['search'][] = "admin"; - $REPLACE['replace'][] = "aid"; - } // END - if - - // Replace all array elements through - foreach ($REPLACE['search'] as $k => $v) { - if (eregi("$v=", $test)) { - // Replace &uid= with /u/ - $test = preg_replace("/&".$v."=/i", "/".$REPLACE['replace'][$k]."/", $test); - } // END - if - } // END - foreach + $output = preg_replace('/' . $target2 . "(.*)&what=/i", $wht, $output); // Repair missed &what=??? entries - while (preg_match("/&what=(.*)\/(.*)\/(.*)/i", $test)) { - $test = preg_replace("/&what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $test); + while (preg_match("/&what=(.*)\/(.*)\/(.*)/i", $output)) { + $output = preg_replace("/&what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $output); } // END - while // Return rewritten code - return $test; + return $output; } // ?>