Hello everyone,
I've used preg_match_all to replace all of my URLs to be more SEO friendly. However, I tried to use preg_match_all (global_complete hook) for redirects such as showthread.php?p=id#postid and search.php?searchid=id however it does not want to cooperate since they are "redirects" and not URLs...I've tried using the following code.
PHP Code:
$found = preg_match_all('#showthread\.php\?p=([0-9]+)\#post([0-9]+)#i', $output, $matches);
if($found)
{
// Build an array of ID's
$ids = array();
for($i = 0; $i < $found; $i++)
{
if(is_numeric($matches[1][$i]))
$ids[] = $matches[1][$i];
}
$ids = implode(',', $ids);
// Go through each
$res = $vbulletin->db->query_read("SELECT threadid, postid FROM " . TABLE_PREFIX . "post WHERE postid IN($ids)");
while($t = $vbulletin->db->fetch_array($res))
{
$tid = $t['threadid'];
$pid = $t['postid'];
$threadinfo = $vbulletin->db->query_first("SELECT title, forumid FROM thread WHERE threadid='$tid'");
$title = urlize($threadinfo['title']);
$fid = $threadinfo['forumid'];
$f = fetch_foruminfo($fid);
$fname = urlize($f['title']);
$output = str_replace("showthread.php?p=$pid#post$pid", "$fname/p-$title-$pid.html#$pid", $output);
}
}
But preg_match_all found nothing. Is there a special way I have to do this or in a different hook then global_complete? I really don't want to modify any files if I can stay away from that. Any help would be greatly appreciated