Régulier 
Inscrit: 07/03/2004 18:48
De Alger
|
voici tous le code du fichier
<?php
// $Id: simplified_url.php,v 1.5 2005/07/02 17:15:00 suin Exp $
// ------------------------------------------------------------------------ //
// SIMPLIFIED URLs FOR XOOPS based on ShortURLs //
// Copyright (c) 2004 suin and Reynaldo Alvarez //
// <http://www.suin.jp> &nb ... nbsp; //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// ------------------------------------------------------------------------ //
//
if (!defined("XOOPS_ROOT_PATH") || !defined("XOOPS_URL") ) {
exit();
}
// ´Ê°×²½¤ò̵¸ú¤Ë¤¹¤ë¥â¥¸¥å¡¼¥ë
// "|"¤Ç¥â¥¸¥å¡¼¥ë¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ò¶èÀڤ롣 If you do not want to simplify any module, divide the module's dir with "|".
$cancel_module = "";
//$cancel_module = "xoopspoll|newbb|news";
if( !empty( $cancel_module ) && isset( $sd_res ) ){
if( ( preg_match("//modules/(".$cancel_module.")//", $_SERVER['SCRIPT_NAME']) )){
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}
if( ( !preg_match("//modules/([^/]*)/admin//", $_SERVER['SCRIPT_NAME']) )
&& ( !preg_match("//modules/system//", $_SERVER['SCRIPT_NAME']) )
&& ( !preg_match("/admin.php/", $_SERVER['SCRIPT_NAME']) ) ) {
//ob_start('ob_gzhandler');
//ob_start('absolutize');
ob_start('simplify_urls');
}else{
if( isset( $sd_res ) ){
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}
function simplify_urls($s)
{
$XPS_URL = str_replace('/','/', quotemeta(XOOPS_URL) );
$s = absolutize($s);
// Fix URLs and HTML. //if (strpos($s, "storyid")) {
//include_once XOOPS_ROOT_PATH."/modules/news/class/class.newsstory.php";
//include_once XOOPS_ROOT_PATH.'/modules/news/class/class.sfiles.php';
//include_once XOOPS_ROOT_PATH.'/modules/news/include/functions.php';
//include_once XOOPS_ROOT_PATH."/modules/news/class/class.newstopic.php";
//include_once XOOPS_ROOT_PATH."/modules/news/class/keyhighlighter.class.php";
//$newsStory = new NewsStory($storyid);
//$title=urlencode($newsStory->title);
//$s .= "&title=".urlencode($newsStory->title);
//}
preg_match('/(storyid=)(.*)(.*)/iUs',$s, $recherche);
$storyid = $recherche[2];
$title = null;
global $xoopsDB;
$sql = "SELECT title FROM ".$xoopsDB->prefix("stories")." WHERE storyid = ".intval($storyid);
if ($res = $xoopsDB->query($sql)) {
if ($oRS = mysql_fetch_object($res)) {
$title = $oRS->title;
}
}
if ($title) {
$s = str_replace("news-article.storyid-([a-zA-Z0-9_-]+).htm", "article-$1-$title.htm", $s);
$s .= "&title=".urlencode($title);
}
$in = array(
// Search URLs of Xoops's root directry.
'/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/([a-zA-Z0-9_-]+).php(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
// Search URLs of modules' directry.
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/news/article.php?storyid=([a-zA-Z0-9_-]*)&title=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
, '/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
);
$out = array(
// Replace URLs of Xoops's root directry.
'<$1$2$3=$4'.XOOPS_URL.'/$5.html$6$7$8>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5.$6-$7.html$8$9$10>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5.$6-$7-$8-$9.html$10$11$12>'
// Replace URLs of modules' directry.
, '<$1$2$3=$4'.XOOPS_URL.'/$5-index.htm$6$7$8>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.htm$7$8$9>'
, '<$1$2$3=$4'.XOOPS_URL.'/article-$5-$6.htm$7$8$9>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.$7-$8.htm$9$10$11>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.$7-$8-$9-$10.htm$11$12$13>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.$7-$8-$9-$10-$11-$12.htm$13$14$15>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.$7-$8-$9-$10-$11-$12-$13-$14.htm$15$16$17>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.$7-$8-$9-$10-$11-$12-$13-$14-$15-$16.htm$17$18$19>'
, '<$1$2$3=$4'.XOOPS_URL.'/$5-$6.$7-$8-$9-$10-$11-$12-$13-$14-$15-$16-$17-$18.htm$19$20$21>'
);
$s = preg_replace($in, $out, $s);
// $s = preg_replace('/<([^>]*)>/i','{\1}', $s);
// $s = $s.'<!-- Simplified URLs Version 1.1 http://www.suin.jp/ -->';
return $s;
}
function absolutize($s){
if(preg_match('//$/',$_SERVER['REQUEST_URI'])){
$req_dir=preg_replace('//$/','',$_SERVER['REQUEST_URI']);
$req_php="";
}else{
$req_dir=dirname($_SERVER['REQUEST_URI']);
$req_php=preg_replace('/.*(/[a-zA-Z0-9_-]+).php.*/','\1.php',$_SERVER['REQUEST_URI']);
}
$req_dir = ($req_dir == "\" || $req_dir == "/" ) ? "" : $req_dir ;
$dir_arr=explode('/', $req_dir);
$m = count($dir_arr)-1;
$d1 = @str_replace('/'.$dir_arr[$m], '', $req_dir);
$d2 = @str_replace('/'.$dir_arr[$m-1], '', $d1);
$d3 = @str_replace('/'.$dir_arr[$m-2], '', $d2);
$d4 = @str_replace('/'.$dir_arr[$m-3], '', $d3);
$d5 = @str_replace('/'.$dir_arr[$m-4], '', $d4);
$host = 'http://'.$_SERVER['HTTP_HOST'];
$in = array(
'/<([^>?&]*)(href|src|action|background|window.location)=([^"' >]+)([^>]*)>/i'
//off1 ,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})../../../../../([^"']*)(["']{1})([^>]*)>/i'
//off2 ,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})../../../../([^"']*)(["']{1})([^>]*)>/i'
,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})../../../([^"']*)(["']{1})([^>]*)>/i'
,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})../../([^"']*)(["']{1})([^>]*)>/i'
,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})../([^"']*)(["']{1})([^>]*)>/i'
,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})/([^"']*)(["']{1})([^>]*)>/i'
,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})?([^"']*)(["']{1})([^>]*)>/i'
//This dir
,'/<([^>?&]*)(href|src|action|background|window.location)=(["']{1})(?:./)?([^"'/:]*/*)?([^"'/:]*/*)?([^"'/:]*/*)?([a-zA-Z0-9_-]+).([^"'>]*)(["']{1})([^>]*)>/i'
,'/[^"'a-zA-Z_0-9](window.open|url)((["']{0,1})(?:./)?([^"'/]*).([^"'/]+)(["']*)([^)]*)/i'
,'/<meta([^>]*)url=([a-zA-Z0-9_-]+).([^"'>]*)(["']{1})([^>]*)>/i'
);
$out = array(
'<\1\2="\3"\4>'
//off1 ,'<\1\2=\3'.$host.$d5.'/\4\5\6>'
//off2 ,'<\1\2=\3'.$host.$d4.'/\4\5\6>'
,'<\1\2=\3'.$host.$d3.'/\4\5\6>'
,'<\1\2=\3'.$host.$d2.'/\4\5\6>'
,'<\1\2=\3'.$host.$d1.'/\4\5\6>'
,'<\1\2=\3'.$host.'/\4\5\6>'
,'<\1\2=\3'.$host.$_SERVER['PHP_SELF'].'?\4\5\6>'
//This dir.
,'<\1\2=\3'.$host.$req_dir.'/\4\5\6\7.\8\9\10>'
,'$1($2'.$host.$req_dir.'/$3.$4$5$6'
,'<meta$1url='.$host.$req_dir.'/$2.$3$4$5>'
);
$s = preg_replace($in, $out, $s);
//off3 z$s = preg_replace('/<([^>]*)>/i','{\1}', $s);
return $s;
}
?>
Posté le : 19/04/2007 13:27
|