Hello, I am trying to use this hack in content module for xoops.
I almost got it work but not really sure where is the problem.
I have put the include of seo_url.php in mainfile.php, because I want that rewrite works also at the root not only when I am in module content.
Module content has only index.php and there is no header.php.
I have put both seo.php and seo_url.php in modules/content directory.
This is how I did but still missing something:
1. seo_url.php
-------------------------------------------------------------------------------------
if (!defined("XOOPS_ROOT_PATH") || !defined("XOOPS_URL") ) {
 exit();
}
define('REAL_MODULE_NAME', 'content');
define('SEO_MODULE_NAME', 'storitve');
ob_start('seo_urls');
function seo_urls($s) 
{
 $XPS_URL = str_replace('/','\/', quotemeta(XOOPS_URL) );
 $s = content_absolutize($s); // Fix URLs and HTML. 
 $module_name = REAL_MODULE_NAME; 
 $search = array(
 // Search URLs of modules' directry.
 '/<(a|meta)([^>]*)(href|url)=([\'\"]{0,1})'.$XPS_URL.'\/modules\/'.$module_name.'\/(index.php)([^>\'\"]*)([\'\"]{1})([^>]*)>/i',
 ); 
 $s = preg_replace_callback($search, 'replace_links', $s); 
 return $s; 
}
function replace_links($matches)
{
 switch ($matches[5]) {
 case 'index.php':
 $add_to_url = '';
 $req_string = $matches[6];
 if (!empty($matches[6])) 
 {
// replacing id=x 
 if(preg_match('/id=([0-9]+)/', $matches[6], $mvars))
 {
 $add_to_url = 'c/'.$mvars[1].'/'.content_seo_id($mvars[1]).'/';
 $req_string = preg_replace('/id=[0-9]+/','', $matches[6]);
 }
 else 
 {
 return $matches['0'];
 }
 }
// break;
// case 'viewcontent.php':
// $add_to_url = '';
// $req_string = $matches[6];
// if (!empty($matches[6])) 
// {
// replacing content=x 
// if(preg_match('/content=([0-9]+)/', $matches[6], $mvars))
// {
// $add_to_url = 'f/'.$mvars[1].'/'.content_seo_content($mvars[1]).'/';
// $req_string = preg_replace('/content=[0-9]+/','', $matches[6]);
// }
// else 
// {
// return $matches['0'];
// }
// }
// break;
// case 'viewtopic.php':
// $add_to_url = '';
// $req_string = $matches[6];
// if (!empty($matches[6])) 
// {
//
// replacing topic_id=x 
// if(preg_match('/topic_id=([0-9]+)/', $matches[6], $mvars))
// {
// $add_to_url = 't/'.$mvars[1].'/'.content_seo_topic($mvars[1]).'/';
// $req_string = preg_replace('/topic_id=[0-9]+/','', $matches[6]);
// }
// else 
// {
// return $matches['0'];
// }
// }
// break;
// 
// default:
// break;
 }
 if ($req_string == '?') 
 {
 $req_string = '';
 }
 $ret = '<'.$matches[1].$matches[2].$matches[3].'='.$matches[4].XOOPS_URL.'/'.SEO_MODULE_NAME.'/'.$add_to_url.$req_string.$matches[7].$matches[8].'>';
 return $ret;
}
function content_seo_id($_id)
{
 $db =& Database::getInstance();
 $query = "
 SELECT
 ptitle
 FROM
 nova_content
 WHERE 
 storyid = $_id
 ";
 $result = $db->query($query);
 $res = $db->fetchArray($result);
 $ret = content_seo_title($res['ptitle']);
 return $ret;
}
//function content_seo_content($_id)
//{
// $db =& Database::getInstance();
// $query = "
// SELECT
// content_name
// FROM
// spir3d_bb_contents
// WHERE 
// content_id = $_id
// ";
// $result = $db->query($query);
// $res = $db->fetchArray($result);
// $ret = content_seo_title($res['content_name']);
// return $ret;
//}
//function content_seo_topic($_id)
//{
// $db =& Database::getInstance();
// $query = "
// SELECT
// topic_title
// FROM
// spir3d_bb_topics
// WHERE 
// topic_id = $_id
// ";
// $result = $db->query($query);
// $res = $db->fetchArray($result);
// $ret = content_seo_title($res['topic_title']);
// return $ret;
//}
function content_seo_title($title='', $withExt=false)
{
 /**
 * if XOOPS ML is present, let's sanitize the title with the current language
 */
 $myts = MyTextSanitizer::getInstance();
 if (method_exists($myts, 'formatForML')) {
 $title = $myts->formatForML($title);
 }
 // Transformation de la chaine en minuscule
 // Codage de la chaine afin d'éviter les erreurs 500 en cas de caract?res imprévus
 $title = rawurlencode(strtolower($title));
 // Transformation des ponctuations
 // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ .
 $pattern = array("/%09/", "/%20/", "/%21/", "/%22/", "/%23/", "/%25/", "/%26/", "/%27/", "/%28/", "/%29/", "/%2C/", "/%2F/", "/%3A/", "/%3B/", "/%3C/", "/%3D/", "/%3E/", "/%3F/", "/%40/", "/%5B/", "/%5C/", "/%5D/", "/%5E/", "/%7B/", "/%7C/", "/%7D/", "/%7E/", "/\./", "/%2A/");
 $rep_pat = array( "-" , "-" , "" , "" , "" , "-100" , "" , "-" , "" , "" , "" , "-" , "" , "" , "" , "-" , "" , "" , "-at-" , "" , "-" , "" , "-" , "" , "-" , "" , "-" , "" , "" );
 $title = preg_replace($pattern, $rep_pat, $title);
 // Transformation des caract?res accentués
 // ? é ? ë ç ? â ä î ? ? ü ? ô ö
 $pattern = array("/%B0/", "/%E8/", "/%E9/", "/%EA/", "/%EB/", "/%E7/", "/%E0/", "/%E2/", "/%E4/", "/%EE/", "/%EF/", "/%F9/", "/%FC/", "/%FB/", "/%F4/", "/%F6/");
 $rep_pat = array( "-", "e" , "e" , "e" , "e" , "c" , "a" , "a" , "a" , "i" , "i" , "u" , "u" , "u" , "o" , "o" );
 $title = preg_replace($pattern, $rep_pat, $title);
 if (sizeof($title) > 0)
 {
 if ($withExt) {
 $title .= '.html';
 }
 return $title;
 }
 else
 return '';
}
function content_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'
 ,'/<([^>\?\&]*)(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})([^#]{1}[^\/\"\'>]*)([\"\']{1})([^>]*)>/i'
 ,'/<([^>\?\&]*)(href|src|action|background|window\.location)=([\"\']{1})(?:\.\/)?([^\"\'\/:]*\/*)?([^\"\'\/:]*\/*)?([^\"\'\/:]*\/*)?([a-zA-Z0-9_\-]+)\.([^\"\'>]*)([\"\']{1})([^>]*)>/i'
 ,'/[^"\'a-zA-Z_0-9](window\.open|url)\(([\"\']{0,1})(?:\.\/)?([^\"\'\/]*)\.([^\"\'\/]+)([\"\']*)([^\)]*)/i'
 ,'/
]*)url=([a-zA-Z0-9_\-]+)\.([^\"\'>]*)([\"\']{1})([^>]*)>/i'
 );
 $out = array(
 '<\\1\\2="\\3"\\4>'
 ,'<\\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>'
 ,'<\\1\\2=\\3'.$host.$req_dir.'/\\4\\5\\6\\7.\\8\\9\\10>'
 ,'$1($2'.$host.$req_dir.'/$3.$4$5$6'
 ,'
'
 );
 $s = preg_replace($in, $out, $s);  
 return $s;
}
?>
-------------------------------------------------------------------------------------------
2. seo.php
-------------------------------------------------------------------------------------------
/*
 * $Id: seo.php,v 1.5 2006/08/15 19:52:08 malanciault Exp $
 * Module: content
 * Author: Sudhaker Raj <
http://xoops.biz>
 * Licence: GNU
 */
$seoArg = $_GET['seoOp'];
if (!empty($seoArg))
{
 $seoOther = explode("/",$seoOther);
}
$seoMap = array(
 'c' => 'index.php',
);
if (! empty($seoArg) && ! empty($seoMap[$seoArg]))
{
 // module specific dispatching logic, other module must implement as
 // per their requirements.
 $newUrl = '/modules/content/' . $seoMap[$seoArg];
 $_ENV['PHP_SELF'] = $newUrl;
 $_SERVER['SCRIPT_NAME'] = $newUrl;
 $_SERVER['PHP_SELF'] = $newUrl;
 switch ($seoArg) {
 case 'c':
 default:
 $_SERVER['REQUEST_URI'] = $newUrl . '?id=' . $seoArg;
 $_GET['id'] = $seoArg;
 }
 include( $seoMap[$seoArg]);
}
exit;
?>
----------------------------------------------------------------------------------------
3. and finaly .htaccess
----------------------------------------------------------------------------------------
RewriteEngine On
RewriteRule ^storitve/([a-z]+)/([0-9]+)(/(.+))? modules/content/seo.php?seoArg=$1&%{QUERY_STRING} [L]
RewriteRule ^storitve(/)? modules/content/?%{QUERY_STRING} [L] 
Please help, how to make it work.
Thanks,
Srdan