Hi Dugris and everyone else!
Thanks for this great smarty output filter! I got it to work on my site in less than half an hour! Beautifully done
. For now, this filter only rewrites module folders: 'modules/xigg' changes to 'news' etc.
I was wondering if it were possible to add support for string rewriting? All those funny string characters à la 'cid=0&smode=Weekly&action=View&event_id=7502&caldate=2008-6-13' are driving me crazy! I
know it
can be
done with smarty
output filters, but maybe someone can help a hand?
I see two ways to rewrite urls: specific rewrites per-module or global rewrites for selected modules.
For 'global' rewrites I especially like the work done with
suin's simplified urls hack:
function simplify_urls($s)
{
$XPS_URL = str_replace('/','/', quotemeta(XOOPS_URL) );
$s = absolutize($s); // Fix URLs and HTML.
$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/([a-zA-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-]+)=([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.'/$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.'';
return $s;
}
But we could also add module-specific rewrites (in separate config files like coRewriteModule.ini.php?). Just look at the
great job Wishcraft did for some popular modules:
This is the modification for SEO paths for News
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/([a-zA-Z0-9 %_-]+)/comment_([a-zA-Z0-9&%?_.-=]+) modules/news/comment_$3 [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/([a-zA-Z0-9 %_-]+)/images/(.*) modules/news/images/$2 [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/images/(.*) modules/news/images/$2 [L,NC,QSA]
RewriteRule ^news/images/(.*) modules/news/images/$2 [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/([a-zA-Z0-9 %_-]+)/([0-9]+) modules/news/article.php?storycategory=$1&story_title=$2&storyid=$3 [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/([a-zA-Z0-9 %_-]+)/ modules/news/article.php?storycategory=$1&story_title=$2 [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/([0-9]+),([0-9]+) modules/news/index.php?storycategory=$1&topic_id=$2&start=$3 [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-9 %_-]+)/ modules/news/index.php?storycategory=$1 [L,NC,QSA]
RewriteRule ^news/([0-9]+),([0-9]+) modules/news/index.php?topic_id=$1&start=$2 [L,NC,QSA]
RewriteRule ^news/ modules/news/index.php [L,NC,QSA]
RewriteRule ^news modules/news/index.php [L,NC,QSA]
RewriteRule ^news/article.php?storyid=([0-9]+) modules/news/article.php?storyid=$1 [L,NC,QSA]
We could create a working platform where XOOPS users can add rewrite plugins per module (like the one above). This smarty output filter can save us a lot of time hacking our php files.
Dugris and others, what do you think of this concept?