minorgod |
12-12-2006 10:14 PM |
There is a problem with vRewrite when using it with the "redirect threads" option enabled. If you try to change thread modes it will not let you because the redirected URL does not include the "mode" variable. After hacking several plugins to no avail, I discovered that the plugin attached to the "global_complete" hook is incorrectly rewriting the links and removing the "mode" variable. After further study, I discovered that the problem was not happening on the "hybrid" mode link, but it was happening on the "linear" and "threaded" mode links. If you rearrange the order of the variables in the SHOWTHREAD template, it stops vRewrite from rewriting those links improperly. You simply need to make this small change to your SHOWTHREAD template:
FIND:
PHP Code:
<if condition="$show['linearmode']"> <td class="vbmenu_option" title="nohilite"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_linear.gif" alt="$vbphrase[linear_mode]" /> <strong>$vbphrase[linear_mode]</strong></td> <else /> <td class="vbmenu_option"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_linear.gif" alt="$vbphrase[linear_mode]" /> <a href="showthread.php?$session[sessionurl]p=$FIRSTPOSTID&mode=linear$highlightwords#post$FIRSTPOSTID">$vbphrase[switch_to_linear_mode]</a></td> </if> </tr> <tr> <if condition="$show['hybridmode']"> <td class="vbmenu_option" title="nohilite"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_hybrid.gif" alt="$vbphrase[hybrid_mode]" /> <strong>$vbphrase[hybrid_mode]</strong></td> <else /> <td class="vbmenu_option"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_hybrid.gif" alt="$vbphrase[hybrid_mode]" /> <a href="showthread.php?$session[sessionurl]mode=hybrid&t=$thread[threadid]$highlightwords">$vbphrase[switch_to_hybrid_mode]</a></td> </if> </tr> <tr> <if condition="$show['threadedmode']"> <td class="vbmenu_option" title="nohilite"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_threaded.gif" alt="$vbphrase[threaded_mode]" /> <strong>$vbphrase[threaded_mode]</strong></td> <else /> <td class="vbmenu_option"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_threaded.gif" alt="$vbphrase[threaded_mode]" /> <a href="showthread.php?$session[sessionurl]p=$FIRSTPOSTID&mode=threaded$highlightwords#post$FIRSTPOSTID">$vbphrase[switch_to_threaded_mode]</a></td> </if>
REPLACE WITH:
PHP Code:
<if condition="$show['linearmode']"> <td class="vbmenu_option" title="nohilite"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_linear.gif" alt="$vbphrase[linear_mode]" /> <strong>$vbphrase[linear_mode]</strong></td> <else /> <td class="vbmenu_option"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_linear.gif" alt="$vbphrase[linear_mode]" /> <a href="showthread.php?$session[sessionurl]mode=linear&p=$FIRSTPOSTID$highlightwords#post$FIRSTPOSTID">$vbphrase[switch_to_linear_mode]</a></td> </if> </tr> <tr> <if condition="$show['hybridmode']"> <td class="vbmenu_option" title="nohilite"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_hybrid.gif" alt="$vbphrase[hybrid_mode]" /> <strong>$vbphrase[hybrid_mode]</strong></td> <else /> <td class="vbmenu_option"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_hybrid.gif" alt="$vbphrase[hybrid_mode]" /> <a href="showthread.php?$session[sessionurl]mode=hybrid&t=$thread[threadid]$highlightwords">$vbphrase[switch_to_hybrid_mode]</a></td> </if> </tr> <tr> <if condition="$show['threadedmode']"> <td class="vbmenu_option" title="nohilite"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_threaded.gif" alt="$vbphrase[threaded_mode]" /> <strong>$vbphrase[threaded_mode]</strong></td> <else /> <td class="vbmenu_option"><img class="inlineimg" src="$stylevar[imgdir_button]/mode_threaded.gif" alt="$vbphrase[threaded_mode]" /> <a href="showthread.php?$session[sessionurl]mode=threaded&p=$FIRSTPOSTID$highlightwords#post$FIRSTPOSTID">$vbphrase[switch_to_threaded_mode]</a></td> </if>
This is sort of a hack for something that really needs to be fixed in the "vRewrite - main script" plugin attached to the "global_complete" hook, but that plugin is so ugly I can't figure out where to fix it.
EDIT: After further study, it appears that you also need to modify your "VRewrite - redirect handling" plugin (attached to the global_start hook). Simply replace it with this edited code to keep the redirect script from destroying the "mode" variable.
PHP Code:
if (($vbulletin->options['vrewrite_external']) AND ($vbulletin->options['vRewrite_on'])) { $current_script = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_ENV['REQUEST_URI']; if (preg_match("#external.php#", $current_script)) { ob_start (); require("external.php"); $output = ob_get_contents ();
$found = preg_match_all('#showthread\.php\?t=([0-9]+)&goto=newpost#i', $output, $matches); if($found) { $ids = array(); for($i = 0; $i < $found; $i++) { if(is_numeric($matches[1][$i])) $ids[] = $matches[1][$i]; } for ($i = 0; $i < count($ids); $i++) { $ttitle = urlize($vRewrite_thread["$ids[$i]"][title]); $fid = $vRewrite_thread["$ids[$i]"][ownerid]; $ftitle = urlize($vRewrite_forum["$fid"][title]); $tid = $ids[$i]; $new = (($vbulletin->options['vRewrite_showthread'] == 1) ? $ftitle : 'f-' . $ftitle . '-' . $fid); $output = str_replace("showthread.php?t=$tid&goto=newpost", "$new/t-$ttitle-$tid-new{$vbulletin->options['vRewrite_extension_showthread']}", $output); } } // end found ob_end_clean (); echo $output; exit(); } }
if($vbulletin->options['vRewrite_redirect'] AND $vbulletin->options['vRewrite_on']) { global $myurl; $myurl = $vbulletin->options['bburl'];
if(THIS_SCRIPT == 'showthread') {
if(!isset($_GET['is_vrewrite']) AND $vbulletin->options['vRewrite_redirect_showthread']){
// isnt all of this defined already in global .php? global $vbulletin; $vbulletin->input->clean_gpc('r', 'threadid', TYPE_UINT); $vbulletin->input->clean_gpc('r', 'postid', TYPE_UINT); $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT); $vbulletin->input->clean_gpc('r', 'goto', TYPE_STR);
switch ($vbulletin->GPC['goto']) { case 'newpost': $threadid = $vbulletin->GPC['threadid']; if (!empty($threadid)) {
$getlastpost = $db->query_first(" SELECT MIN(postid) AS postid, post.dateline, t.title as threadtitle, f.title as forumtitle, f.forumid as forumid FROM " . TABLE_PREFIX . "post AS post JOIN " . TABLE_PREFIX . "thread AS t ON(t.threadid=post.threadid) JOIN " . TABLE_PREFIX . "forum as f ON(f.forumid=t.forumid) WHERE post.threadid = " . intval($threadid) . " AND post.visible = 1 AND post.dateline > " . intval($vbulletin->userinfo['lastvisit']) . " GROUP BY t.title, f.title, f.forumid, t.threadid, post.dateline
LIMIT 1 "); if ($getlastpost['postid']) { $dateline = $getlastpost['dateline']; $getpstcnt = $db->query_first(" SELECT COUNT(*) AS postcount FROM " . TABLE_PREFIX . "post WHERE threadid = $threadid AND visible = 1 AND dateline <= $dateline "); $postcount = $getpstcnt['postcount']; $pp = sanitize_maxposts($vbulletin->GPC['perpage']); $page = ceil($postcount / $pp); if ($page <= 0) { $page = 1; }
$fname = urlize($getlastpost[forumtitle]); $tname = urlize($getlastpost[threadtitle]); $parentid = $getlastpost[forumid]; $new = (($vbulletin->options['vRewrite_showthread'] == 1) ? $fname : 'f-' . $fname . '-' . $parentid); if ($page <= 1) { exec_header_redirect("$myurl/$new/t-$tname-$threadid{$vbulletin->options['vRewrite_extension_showthread']}#post$getlastpost[postid]"); } else { if($vbulletin->options['vRewrite_page'] == "1") { exec_header_redirect("$myurl/$new/t-$tname-page$page-$threadid{$vbulletin->options['vRewrite_extension_showthread']}#post$getlastpost[postid]"); } else { exec_header_redirect("$myurl/$new/t-$tname-$threadid/page$page{$vbulletin->options['vRewrite_extension_showthread']}#post$getlastpost[postid]"); } } } else { exec_header_redirect("$myurl/showthread.php?t=$threadid&goto=lastpost"); }
} break; case 'lastpost': $threadid = $vbulletin->GPC['threadid']; if (!empty($threadid)) { if ($getlastpost = $db->query_first(" SELECT MAX(post.postid) AS postid, post2.dateline, t.title AS threadtitle, t.threadid, f.forumid, f.title AS forumtitle FROM " . TABLE_PREFIX . "post AS post, " . TABLE_PREFIX . "post AS post2, " . TABLE_PREFIX . "thread AS t, " . TABLE_PREFIX . "forum AS f WHERE post.threadid = " . intval($threadid) . " AND post.visible = 1 AND post2.postid=post.postid AND t.forumid= f.forumid AND t.threadid = " . intval($threadid) . "
GROUP BY post.postid DESC LIMIT 1 ")) { $dateline = $getlastpost['dateline']; $getpstcnt = $db->query_first(" SELECT COUNT(*) AS postcount FROM " . TABLE_PREFIX . "post WHERE threadid = $threadid AND visible = 1 AND dateline <= $dateline "); $postcount = $getpstcnt['postcount']; $pp = sanitize_maxposts($vbulletin->GPC['perpage']); $page = ceil($postcount / $pp); if ($page <= 0) { $page = 1; } $fname = urlize($getlastpost[forumtitle]); $tname = urlize($getlastpost[threadtitle]);
$parentid = $getlastpost[forumid]; $new = (($vbulletin->options['vRewrite_showthread'] == 1) ? $fname : 'f-' . $fname . '-' . $parentid); if ($page <= 1) { exec_header_redirect($myurl. '/' . $new . '/t-' . $tname. '-'. $threadid . $vbulletin->options['vRewrite_extension_showthread'] .'#post' . $getlastpost[postid]); } else { if($vbulletin->options['vRewrite_page'] == "1") { exec_header_redirect("$myurl/$new/t-$tname-page$page-$threadid{$vbulletin->options['vRewrite_extension_showthread']}#post$getlastpost[postid]"); } else { exec_header_redirect("$myurl/$new/t-$tname-$threadid/page$page{$vbulletin->options['vRewrite_extension_showthread']}#post$getlastpost[postid]"); }
}
} }
break;
} // end switch
if (!empty($vbulletin->GPC['pagenumber']) AND empty($vbulletin->GPC['goto'])) { $page = $vbulletin->GPC['pagenumber']; if ($getpageinfo = $db->query_first(" SELECT t.title as threadtitle, t.threadid AS threadid, f.title as forumtitle, f.forumid as forumid FROM " . TABLE_PREFIX . "post AS p JOIN " . TABLE_PREFIX . "thread as t ON (t.threadid=p.threadid) JOIN " . TABLE_PREFIX . "forum AS f ON (f.forumid=t.forumid) WHERE t.threadid= " . intval($threadid) . " AND p.visible = 1 LIMIT 1 ")) { $fname = urlize($getpageinfo[forumtitle]); $tname = urlize($getpageinfo[threadtitle]); $parentid = $getpageinfo[forumid]; $new = (($vbulletin->options['vRewrite_showthread'] == 1) ? $fname : 'f-' . $fname . '-' . $parentid);
if ($page <= 1) { exec_header_redirect("$myurl/$new/t-$tname-$threadid{$vbulletin->options['vRewrite_extension_showthread']}"); } else { if($vbulletin->options['vRewrite_page'] == "1") { exec_header_redirect("$myurl/$new/t-$tname-page$page-$threadid{$vbulletin->options['vRewrite_extension_showthread']}"); } else { exec_header_redirect("$myurl/$new/t-$tname-$threadid/page$page{$vbulletin->options['vRewrite_extension_showthread']}"); } } } }
$postid = $vbulletin->GPC['postid']; if (!empty($postid) AND empty($vbulletin->GPC['goto'])) { if ($getpostinfo = $db->query_first(" SELECT p.dateline AS dateline, t.title as threadtitle, t.threadid, f.title as forumtitle, t.replycount AS replycount, f.forumid AS forumid FROM " . TABLE_PREFIX . "post AS p JOIN " . TABLE_PREFIX . "thread as t ON (p.threadid=t.threadid) JOIN " . TABLE_PREFIX . "forum AS f ON (t.forumid=f.forumid) WHERE p.postid = $postid LIMIT 1 ")) { $threadid = $getpostinfo['threadid']; $date = $getpostinfo['dateline']; $getpstcnt = $db->query_first(" SELECT COUNT(*) AS postcount FROM " . TABLE_PREFIX . "post WHERE threadid = $threadid AND visible = 1 AND dateline <= $date "); $postcount = $getpstcnt['postcount']; $pp = sanitize_maxposts($vbulletin->GPC['perpage']); $page = ceil($postcount / $pp); if ($page <= 0) { $page = 1; } $ftitle = urlize($getpostinfo['forumtitle']); $tname = urlize($getpostinfo[threadtitle]); $parentid = $getpostinfo[forumid]; $new = (($vbulletin->options['vRewrite_showthread'] == 1) ? $ftitle : 'f-' . $ftitle . '-' . $parentid); //fix for linear and threaded mode selection by brett if(!empty($vbulletin->GPC['mode'])){ $modestring = "?mode=".$vbulletin->GPC['mode']; } //end fix for linear and threaded mode selection //note that $modestring has been added to the following three calls to exec_header_redirect() if ($page <= 1) { exec_header_redirect("$myurl/$new/t-$tname-$threadid{$vbulletin->options['vRewrite_extension_showthread']}$modestring#post" . $postid); } else { if($vbulletin->options['vRewrite_page'] == "1") { exec_header_redirect("$myurl/$new/t-$tname-page$page-$threadid{$vbulletin->options['vRewrite_extension_showthread']}$modestring#post" . $postid); } else { exec_header_redirect("$myurl/$new/t-$tname-$threadid/page$page{$vbulletin->options['vRewrite_extension_showthread']}$modestring#post" . $postid); } } } } // end post $tid = $vbulletin->GPC['threadid']; if (!empty($tid ) AND empty($vbulletin->GPC['goto'])) { if ($getthreadinfo = $db->query_first(" SELECT t.title as threadtitle, f.title as forumtitle, f.forumid AS forumid FROM " . TABLE_PREFIX . "forum AS f JOIN " . TABLE_PREFIX . "thread as t ON (t.forumid=f.forumid) WHERE t.threadid = $tid LIMIT 1 ")) { $ftitle = urlize($getthreadinfo['forumtitle']); $tname = urlize($getthreadinfo['threadtitle']); $parentid = $getthreadinfo[forumid]; $new = (($vbulletin->options['vRewrite_showthread'] == 1) ? $ftitle : 'f-' . $ftitle . '-' . $parentid); //fix for hybrid mode selection by brett if(!empty($vbulletin->GPC['mode'])){ $modestring = "?mode=".$vbulletin->GPC['mode']; } //end fix for hybrid mode selection //note that $modestring has been added to the following call to exec_header_redirect() exec_header_redirect("$myurl/$new/t-$tname-$threadid{$vbulletin->options['vRewrite_extension_showthread']}$modestring"); } }
} // end if rewrite isn't there } // end showthread
if(THIS_SCRIPT == 'forumdisplay') { if(!isset($_GET['is_vrewrite']) AND $vbulletin->options['vRewrite_redirect_forumdisplay']){
if (!($_REQUEST['do'] == 'doenterpwd')) { $vbulletin->input->clean_gpc('r', 'forumid', TYPE_UINT); $forumid = $vbulletin->GPC['forumid']; if ($getforum = $db->query_first(" SELECT title FROM " . TABLE_PREFIX . "forum WHERE forumid = $forumid ")) { $title = urlize($getforum[title]);
$x = $_SERVER['QUERY_STRING']; if (!empty($x)) { $x = preg_replace('/s=(&)f=([0-9]+)(&)/', '', $x); $x = preg_replace('/(&)s=(&)f=([0-9]+)/', '', $x); $x = preg_replace('/(&)f=([0-9]+)/', '', $x); $x = preg_replace('/f=([0-9]+)(&)/', '', $x);
// thisis really needed?: $x = preg_replace('/f=([0-9]+)/', '', $x); // ??
$x = preg_replace('/order=desc(&)/', '', $x);
$pg = preg_match('#page=([0-9]+)#i', $x, $matches); if ($pg) { $page = $matches[1]; $x = preg_replace('/page=([0-9]+)(&)/', '', $x); } if (!empty($x)) { $x = '?' . $x;
} } else { $x = ''; } $x = (($vbulletin->options['vRewrite_forumdisplay_slash'] == 1) ? '/' : '') . $x; if ($page >= 2) { exec_header_redirect("$myurl/f-$title-$forumid/page$page{$vbulletin->options['vRewrite_extension_forumdisplay']}$x"); } else { exec_header_redirect("$myurl/f-$title-$forumid{$vbulletin->options['vRewrite_extension_forumdisplay']}$x"); } } // end 'if' SQL check } } // end if rewrite isn't there } // end forumdisplay
if(THIS_SCRIPT == 'member') { if(!isset($_GET['is_vrewrite']) AND $vbulletin->options['vRewrite_redirect_member']){ $vbulletin->input->clean_array_gpc('r', array( 'userid' => TYPE_UINT, 'username' => TYPE_NOHTML )); if (!empty($vbulletin->GPC['userid'])) { $userinfo = verify_id('user', $vbulletin->GPC['userid'], 1, 1, 15); $uid = $userinfo['userid']; $uname = urlize($userinfo['username']); if($vbulletin->options['vRewrite_memberrewrite'] == 1) { exec_header_redirect("$myurl/u-$uname-$uid{$vbulletin->options['vRewrite_extension_member']}"); } else { exec_header_redirect("$myurl/members/$uname-$uid{$vbulletin->options['vRewrite_extension_member']}"); } } } } // end memberinfo
} // end redirect on
function urlize($txt) { global $vbulletin; if ($vbulletin->options['vrewrite_stopword_on']) { $stop_words = preg_split('#\s+#', $vbulletin->options['vrewrite_stopword_filter'] ); foreach ($stop_words AS $word) { $txt = preg_replace('#\s' . $word . '\s#i', ' ', $txt); } } $txt = unaccent($txt); $txt = html_entity_decode($txt); $txt = str_replace(' ', '-', $txt); $txt = str_replace('_', '-', $txt); $txt = preg_replace('#[^a-zA-Z0-9_\-]+#', '', $txt); $txt = preg_replace('#[\-]+#', '-', $txt); return strtolower($txt); }
function unaccent($txt) { $trans = get_html_translation_table(HTML_ENTITIES); foreach($trans as $literal => $entity) { if(ord($literal) >= 192) { $search[] = $literal; $replace[] = substr($entity, 1, 1); } }
return str_replace($search, $replace, $txt); } $version = $vbulletin->options['vrewriteversion']; global $vRewrite_copyright; $vRewrite_copyright = '<div align="center" class="smallfont">vRewrite ' . $version . ' SEOed URLs completed by <a href="http://www.techhelpforum.com">Tech Help Forum</a> and <a href="http://www.ChaloNa.com">Chalo Na</a>.</div>';
|