function vbseo_post_url_row($thread_row, $post_row, $postcount)
{
    global $vbseo_gcache;
    $vbseo_gcache['post'][$post_row['postid']] = $post_row;
    $vbseo_gcache['thread'][$thread_row['threadid']] = $thread_row;
    $url = vbseo_post_url($post_row['postid'], $postcount);
    unset($vbseo_gcache['post'][$post_row['postid']]);
    unset($vbseo_gcache['thread'][$thread_row['threadid']]);
    return $url;
}
Esempio n. 2
0
 } else {
     if (VBSEO_REWRITE_SHOWPOST && VBSEO_BASEURL == 'showpost.' . VBSEO_VB_EXT) {
         define('THIS_SCRIPT', 'showpost');
         vbseo_get_options();
         vbseo_prepare_seo_replace();
         $r_post_id = $_GET[VBSEO_POSTID_URI];
         vbseo_get_forum_info();
         if (VBSEO_POSTBIT_PINGBACK == 2) {
             $found_object_ids['prepostthread_ids'] = array($r_post_id);
         }
         vbseo_get_post_thread_info($r_post_id, true);
         vbseo_get_thread_info($found_object_ids['postthreads']);
         if (VBSEO_POSTBIT_PINGBACK == 2) {
             $vbseo_url_ = vbseo_thread_url_postid($r_post_id);
         } else {
             $vbseo_url_ = vbseo_post_url($r_post_id, $_GET['postcount']);
         }
         vbseo_safe_redirect($vbseo_url_, array(VBSEO_POSTID_URI, 'postcount'));
     } else {
         if (VBSEO_REWRITE_ATTACHMENTS && VBSEO_BASEURL == 'attachment.' . VBSEO_VB_EXT) {
             if ($_REQUEST['attachmentid']) {
                 vbseo_get_attachments_info($_REQUEST['attachmentid']);
                 $newurl = vbseo_attachment_url($_REQUEST['attachmentid'], '', $_REQUEST['d'], $_REQUEST['thumb']);
                 $strip_params = array('attachmentid', 'd', 'thumb');
                 if ($newurl) {
                     vbseo_safe_redirect($newurl, $strip_params);
                 } else {
                     $vbseo_found_fn = 'attachment.' . VBSEO_VB_EXT;
                     $vbseo_found = true;
                 }
             }
Esempio n. 3
0
 function vbseo_replace_urls($preurl, $url, $mid_attribs = '', $posturl = '', $intag = '', $closetag = '')
 {
     global $vboptions, $vbseo_notop_url, $g_replace_cache, $vbseo_gcache, $vbseo_crules, $tempusagecache, $vbulletin, $bbuserinfo;
     $preurl = str_replace('\\"', '"', $preurl);
     $posturl = str_replace('\\"', '"', $posturl);
     $intag = str_replace('\\"', '"', $intag);
     $closetag = str_replace('\\"', '"', $closetag);
     $par_str = '';
     if ($preurl[strlen($preurl) - 1] != $posturl[0] && $posturl && !$GLOBALS['VBSEO_REWRITE_TEXTURLS'] && !$GLOBALS['VBSEO_REWRITE_PRINTTHREAD'] && !$GLOBALS['vbseo_proc_xml']) {
         return $preurl . $url . $posturl . $intag . $closetag;
     }
     if (isset($g_replace_cache[$url])) {
         return $preurl . $g_replace_cache[$url] . $posturl . $intag . $closetag;
     }
     if ($url[0] == '#') {
         return $preurl . (VBSEO_BASEDEPTH && defined('VBSEO_PREPROCESSED') ? VBSEO_REQURL_FULL : '') . $url . $posturl . $intag . $closetag;
     }
     if (VBSEO_REWRITE_THREADS_ADDTITLE && $url[0] == '!') {
         preg_match('#^\\!([mp])?(\\d+)#', $url, $um);
         $url = preg_replace('#^\\![mp]?\\d+\\!#', '', $url);
         $tid = $um[1] == 'p' ? $vbseo_gcache['post'][$um[2]]['threadid'] : $um[2];
         $tinfo = $vbseo_gcache['thread'][$tid];
         $ttitle = $tinfo['title'];
         $is_public = vbseo_forum_is_public($vbseo_gcache['forum'][$tinfo['forumid']]);
         if ($um[1] != 'p' && !strstr($url, 'showthread.' . VBSEO_VB_EXT)) {
             if ($um[1] == 'm') {
                 $rurl = vbseo_thread_url($tid, '#m#', VBSEO_URL_THREAD_PAGENUM);
                 if (!preg_match('#' . str_replace('#m#', '\\d+', preg_quote($rurl, '#')) . '#', $rurl)) {
                     $ttitle = '';
                 }
             } else {
                 $rurl = vbseo_thread_url($tid);
                 if (!$rurl || !strstr($url, $rurl)) {
                     $ttitle = '';
                 }
             }
         }
         if ($ttitle && $intag != $ttitle && ($is_public || $tinfo['forumid'] == $GLOBALS['forumid'])) {
             if (VBSEO_REWRITE_THREADS_ADDTITLE == 1) {
                 $preurl = preg_replace('#(<a\\s)#is', '\\1title="' . htmlspecialchars($ttitle) . '" ', $preurl);
             } else {
                 if (VBSEO_REWRITE_THREADS_ADDTITLE == 2) {
                     $intag = $intag . " ({$ttitle})";
                 } else {
                     if (VBSEO_REWRITE_THREADS_ADDTITLE == 3 && preg_match('#^http:#', $intag)) {
                         $intag = $ttitle;
                     }
                 }
             }
         }
     }
     $rn_q = $preurl[strlen($preurl) - 1];
     if ($rn_q != "'") {
         $rn_q = '"';
     }
     $relnofollow = 'rel=' . $rn_q . 'nofollow' . $rn_q;
     if (strstr($preurl, 'rel="novbseo"') || strstr($preurl, 'rel=\'novbseo\'')) {
         return preg_replace('#rel=[\'"]novbseo[\'"]#', '', $preurl) . $url . $posturl . $intag . $closetag;
     }
     $cproto = 0;
     if (substr($url, 0, 7) == 'mailto:' || substr($url, 0, 11) == 'javascript:' || ($cproto = 1) && strstr($url, '://') && !strstr($url, VBSEO_HTTP_HOST) && !strstr($url, $vboptions['bburl2'])) {
         preg_match('#(?:www\\.)?(.+)$#', VBSEO_HTTP_HOST, $hmatch);
         $vbseo_ext_url = !preg_match('#^[^/]*://(www\\.)?' . preg_quote($hmatch[1], '#') . '#', $url);
         if ($cproto && $vbseo_ext_url) {
             if (VBSEO_NOFOLLOW_EXTERNAL && (!VBSEO_DOMAINS_WHITELIST || !preg_match('#' . VBSEO_DOMAINS_WHITELIST . '#i', $url)) || !VBSEO_NOFOLLOW_EXTERNAL && (VBSEO_DOMAINS_BLACKLIST && preg_match('#' . VBSEO_DOMAINS_BLACKLIST . '#i', $url))) {
                 if (!strstr($preurl . $mid_attribs . $posturl, $relnofollow)) {
                     $preurl = preg_replace('#(<a\\s)#is', '\\1' . $relnofollow . ' ', $preurl);
                 }
             }
             vbseo_urchin_out($preurl, $url, $posturl, substr($intag, 0, 5) == 'Visit' ? 'onmouseup' : '');
         }
         if (VBSEO_REDIRECT_PRIV_EXTERNAL && (strstr($url, 'http://') || strstr($url, 'https://')) && in_array(THIS_SCRIPT, array('showthread', 'printthread', 'showpost', 'forumdisplay', 'newreply')) && strstr($preurl, '<a')) {
             $is_public = vbseo_forum_is_public($GLOBALS['forum'], $GLOBALS['foruminfo']);
             if (strstr($preurl, 'href') && !$is_public && $vbseo_ext_url) {
                 $url = $vboptions['bburl2'] . '/' . VBSEO_REDIRECT_URI . '?redirect=' . urlencode(vbseo_unhtmlentities($url));
             }
         }
         return $preurl . $url . $posturl . $intag . $closetag;
     }
     $url = preg_replace('#([^:]/)/+#', '$1', $url);
     $url_place = $url_append = '';
     if (strpos($url, '?') !== false) {
         list($url_script, $url_append) = explode('?', $url, 2);
     } else {
         $url_script = $url;
     }
     if ($url_append && $url_append[0] == '?') {
         $url_append = substr($url_append, 1);
     }
     if (THIS_SCRIPT == 'archive') {
         if ($url_script == '../index.php/') {
             $url_script = $vboptions['relbburl'] . VBSEO_ARCHIVE_ROOT;
         }
     }
     $url_script = preg_replace('#^(' . $vboptions['bburl2'] . '/?)?archive/(index\\.' . VBSEO_VB_EXT . '/?)?#', '${1}' . substr(VBSEO_ARCHIVE_ROOT, 1), $url_script);
     if (strpos($url_script, '#') !== false) {
         list($url_script, $url_place) = explode('#', $url_script, 2);
     } else {
         if (strpos($url_append, '#') !== false) {
             list($url_parameters, $url_place) = explode('#', $url_append, 2);
         } else {
             $url_parameters = $url_append;
         }
     }
     preg_match('#^(.*?)([^/]*)$#', $url_script, $um);
     $base_script = $um[2];
     $dir_script = $um[1];
     $is_vbdir = !$dir_script && (!VBSEO_BASEDEPTH || defined('VBSEO_AJAX') || defined('VBSEO_BASEHREF_INDIR') || defined('VBSEO_PREPROCESSED')) || strcasecmp($dir_script, VBSEO_TOPREL) == 0 || strcasecmp($dir_script, VBSEO_TOPREL_FULL) == 0 || strcasecmp($dir_script, $vboptions['bburl2'] . '/') == 0 || strcasecmp(str_replace('www.', '', $dir_script), VBSEO_TOPREL_FULL) == 0;
     $topurl = $is_vbdir ? $vboptions['relbburl'] . '/' : $vboptions['bburl2'] . '/';
     $is_vburl = strstr($url_script, $vboptions['bburl2']);
     $pars = explode('&', str_replace('&amp;', '&', $url_parameters));
     $apars = $spars = array();
     for ($i2 = 0; $i2 < count($pars); $i2++) {
         $v = '';
         if (strpos($pars[$i2], '=') !== false) {
             list($k, $v) = explode('=', $pars[$i2], 2);
         } else {
             $k = $pars[$i2];
         }
         if ($k) {
             $dec_v = urldecode($v);
             if (strstr($dec_v, 'http:') && strstr($dec_v, $vboptions['bburl2'])) {
                 $dec_v = vbseo_replace_urls('', $dec_v);
                 $v = urlencode($dec_v);
             }
             $apars[$k] = $v;
             $spars[] = array($k, $v);
         }
     }
     if (THIS_SCRIPT == 'online' && strstr($posturl, 'alt')) {
         $posturl = preg_replace('#(alt=")([^"]*)#se', "vbseo_replace_urls('\$1', '\$2')", $posturl);
     }
     if (VBSEO_IMAGES_DIM && strstr($preurl, '<img')) {
         $dexp = explode('/', $dir_script);
         $base_script2 = count($dexp) > 1 ? $dexp[count($dexp) - 2] . '/' . $base_script : '';
         $base_script3 = count($dexp) > 2 ? $dexp[count($dexp) - 3] . '/' . $base_script2 : '';
         $base_script4 = count($dexp) > 3 ? $dexp[count($dexp) - 4] . '/' . $base_script3 : '';
         if ((($imd = $GLOBALS['vbseo_images_dim'][$base_script]) || ($imd = $GLOBALS['vbseo_images_dim'][$base_script2]) || ($imd = $GLOBALS['vbseo_images_dim'][$base_script3]) || ($imd = $GLOBALS['vbseo_images_dim'][$base_script4])) && ($iw = $imd[0]) && ($ih = $imd[1]) && !strstr($posturl, 'width=')) {
             $preurl = preg_replace('#(<img\\s)#is', '\\1width="' . $iw . '" height="' . $ih . '" ', $preurl);
             return $preurl . $url . $posturl . $intag . $closetag;
         }
     }
     global $session, $vbulletin, $VBSEO_REWRITE_TEXTURLS;
     if (!isset($session) && isset($vbulletin->session)) {
         $session = $vbulletin->session->vars;
     }
     $vbseo_session_append = '';
     if (isset($apars['s'])) {
         $strip_sids = isset($session) && in_array($apars['s'], $session) && (!defined('VBSEO_STRIP_SIDS') || VBSEO_STRIP_SIDS) || isset($VBSEO_REWRITE_TEXTURLS);
         if (VBSEO_STRIPSID_GUESTS && !$bbuserinfo['userid']) {
             $strip_sids = true;
         }
         if (!$strip_sids) {
             $vbseo_session_append = 's=' . $apars['s'];
         }
         unset($apars['s']);
         $url_parameters = preg_replace('#^s=[\\da-z]+(&amp;|&)*#', '', $url_parameters);
         $url_parameters = preg_replace('#(&amp;|&)s=[\\da-z]+#', '', $url_parameters);
         if (count($spars) == 1 && $spars[0][0] == 's') {
             $spars = array();
         }
     }
     $clear_all_par = false;
     if (THIS_SCRIPT == 'archive') {
         if (VBSEO_REWRITE_ARCHIVE_URLS && !$_COOKIE[vbseo_vb_cprefix() . 'pda']) {
             if (preg_match('#\\bt-(\\d+)\\.html#', $base_script, $tmatch) || preg_match('#\\bt-(\\d+)\\.html#', $url_parameters, $tmatch)) {
                 $url_script = $topurl . (VBSEO_REWRITE_THREADS ? vbseo_thread_url($tmatch[1], 1) : 'showthread.' . VBSEO_VB_EXT . '?' . VBSEO_THREADID_URI . '=' . $tmatch[1]);
                 $clear_all_par = true;
             }
             if (!VBSEO_VB35X && preg_match('#^f-(\\d+)-p-1\\.html$#', $base_script, $tmatch)) {
                 $url_script = str_replace('-p-1.html', '.html', $url_script);
                 $clear_all_par = true;
             }
         }
     }
     if (!$clear_all_par && defined('VBSEO_ARCHIVE_ROOT') && VBSEO_ARCHIVE_ROOT) {
         if (preg_match('#index.' . VBSEO_VB_EXT . '\\?((t|f)-(\\d+)(-p-\\d+)?\\.html)#', $url, $tmatch)) {
             $url_script = $vboptions['relbburl'] . VBSEO_ARCHIVE_ROOT . $tmatch[1];
             $clear_all_par = true;
         }
     }
     if (!$clear_all_par) {
         if (count($apars) == 1 && preg_match('#^[ft]-#', $url_parameters)) {
             $par_str = $url_append;
             $topurl = '';
             $clear_all_par = true;
         }
     }
     $nofollow = $follow = $noproc = false;
     if (isset($apars['threadid'])) {
         $apars[VBSEO_THREADID_URI] = $apars['threadid'];
     }
     if (!$clear_all_par && $is_vbdir) {
         if ($base_script == 'index.' . VBSEO_VB_EXT && !$url_parameters && VBSEO_HP_FORCEINDEXROOT) {
             $url_script = (isset($VBSEO_REWRITE_TEXTURLS) || THIS_SCRIPT == 'sendmessage2' ? '' : $topurl) . VBSEO_HOMEPAGE;
         } else {
             switch ($base_script) {
                 case 'forumdisplay.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_FORUM) {
                         if (($fid = $apars[VBSEO_FORUMID_URI]) || ($fid = $apars[VBSEO_FORUMID_URI2])) {
                             $url_script = vbseo_forum_url($fid, isset($apars[VBSEO_PAGENUM_URI]) ? $apars[VBSEO_PAGENUM_URI] : 0);
                         } else {
                             $noproc = true;
                         }
                         $def_so = $vbseo_gcache['forum'][$fid]['defaultsortorder'] ? $vbseo_gcache['forum'][$fid]['defaultsortorder'] : VBSEO_DEFAULT_FORUMDISPLAY_ORDER;
                         $def_sf = $vbseo_gcache['forum'][$fid]['defaultsortfield'] ? $vbseo_gcache['forum'][$fid]['defaultsortfield'] : VBSEO_DEFAULT_FORUMDISPLAY_SORT;
                         if ((!isset($apars[VBSEO_SORT_URI]) || $apars[VBSEO_SORT_URI] == $def_sf) && (!isset($apars[VBSEO_SORTORDER_URI]) || $apars[VBSEO_SORTORDER_URI] == $def_so) && !isset($apars[VBSEO_ACTION_URI])) {
                             unset($apars[VBSEO_SORTORDER_URI]);
                             unset($apars[VBSEO_ACTION_URI]);
                             unset($apars[VBSEO_SORT_URI]);
                         }
                         if ($vbseo_gcache['forum'][$fid]['link']) {
                             preg_match('#(([^\\.]+\\.)?[^\\.]+)$#', VBSEO_HTTP_HOST, $hmatch);
                             if (!preg_match('#^[^/]*://[^/]*' . preg_quote($hmatch[1], '#') . '#', $url_script)) {
                                 vbseo_urchin_out($preurl, $url_script, $posturl);
                             }
                             $noproc = true;
                             $url_parameters = '';
                         }
                         if (isset($apars['daysprune']) && $GLOBALS['forumcache'][$fid]['daysprune'] == $apars['daysprune'] && $bbuserinfo['daysprune'] == $apars['daysprune']) {
                             unset($apars['daysprune']);
                         }
                         unset($apars['pp']);
                         unset($apars[VBSEO_FORUMID_URI]);
                         unset($apars[VBSEO_FORUMID_URI2]);
                         unset($apars[VBSEO_PAGENUM_URI]);
                     }
                     break;
                 case 'announcement.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_ANNOUNCEMENT) {
                         if (($fid = $apars[VBSEO_FORUMID_URI]) || ($fid = $apars[VBSEO_FORUMID_URI2])) {
                             $url_script = vbseo_announcement_url($fid, isset($apars['a']) ? $apars['a'] : $apars['announcementid']);
                             $clear_all_par = true;
                         }
                     }
                     break;
                 case 'showthread.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_THREADS) {
                         $tinfo = $vbseo_gcache['thread'][$apars[VBSEO_THREADID_URI]];
                         if ($tinfo['forumid']) {
                             $is_public = vbseo_forum_is_public($vbseo_gcache['forum'][$tinfo['forumid']], '', true);
                             if (!$is_public) {
                                 if (!($apars['goto'] == 'newpost' && $GLOBALS['VBSEO_REWRITE_TEXTURLS'])) {
                                     break;
                                 }
                             }
                         }
                         if (isset($apars['goto']) && $apars['goto'] == 'newpost' && ((defined('VBSEO_REWRITE_EXTERNAL') || !$bbuserinfo['userid']) && VBSEO_DIRECTLINKS_THREADS)) {
                             $posturl = preg_replace('#(title=)".*?"#i', '', $posturl);
                             unset($apars['goto']);
                         }
                         $newurl = '';
                         if (isset($apars[VBSEO_POSTID_URI]) && ($r_post_id = $apars[VBSEO_POSTID_URI]) || isset($apars['postid']) && ($r_post_id = $apars['postid'])) {
                             if ($apars['do'] || $apars[VBSEO_THREADID_URI]) {
                                 break;
                             }
                             if ($newurl = vbseo_thread_url_postid($r_post_id, isset($apars[VBSEO_PAGENUM_URI]) ? $apars[VBSEO_PAGENUM_URI] : 1)) {
                                 $tinfo = $vbseo_gcache['thread'][$vbseo_gcache['post'][$r_post_id]['threadid']];
                                 if ($tinfo['forumid']) {
                                     $is_public = vbseo_forum_is_public($vbseo_gcache['forum'][$tinfo['forumid']], '', true);
                                     if (!$is_public) {
                                         $newurl = '';
                                     }
                                 }
                                 if ($url_place) {
                                     $newurl = preg_replace('|#.*|', '', $newurl);
                                 }
                             }
                         } else {
                             if (isset($apars['goto'])) {
                                 if ($apars['goto'] == 'newpost') {
                                     $newurl = vbseo_thread_url($apars[VBSEO_THREADID_URI], '', VBSEO_URL_THREAD_NEWPOST);
                                 } else {
                                     if ($apars['goto'] == 'lastpost') {
                                         $newurl = vbseo_thread_url($apars[VBSEO_THREADID_URI], '', VBSEO_URL_THREAD_LASTPOST);
                                     } else {
                                         if ($apars['goto'] == 'nextnewest') {
                                             if (VBSEO_URL_THREAD_NEXT_DIRECT) {
                                                 $nthread = vbseo_get_next_thread($apars[VBSEO_THREADID_URI], false);
                                                 $follow = true;
                                                 if ($nthread['threadid']) {
                                                     $url_script = vbseo_thread_url($nthread['threadid']);
                                                     $intag = function_exists('fetch_censored_text') ? fetch_censored_text($nthread['title']) : '';
                                                     $clear_all_par = true;
                                                 } else {
                                                     return '-';
                                                 }
                                             } else {
                                                 $newurl = vbseo_thread_url($apars[VBSEO_THREADID_URI], '', VBSEO_URL_THREAD_NEXT);
                                             }
                                         } else {
                                             if ($apars['goto'] == 'nextoldest') {
                                                 if (VBSEO_URL_THREAD_PREV_DIRECT) {
                                                     $follow = true;
                                                     $nthread = vbseo_get_next_thread($apars[VBSEO_THREADID_URI], true);
                                                     if ($nthread['threadid']) {
                                                         $url_script = vbseo_thread_url($nthread['threadid']);
                                                         $intag = function_exists('fetch_censored_text') ? fetch_censored_text($nthread['title']) : '';
                                                         $clear_all_par = true;
                                                     } else {
                                                         return '-';
                                                     }
                                                 } else {
                                                     $newurl = vbseo_thread_url($apars[VBSEO_THREADID_URI], '', VBSEO_URL_THREAD_PREV);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (VBSEO_ENABLE_GARS && isset($apars[VBSEO_PAGENUM_URI_GARS])) {
                                     $newurl = vbseo_thread_url($apars[VBSEO_THREADID_URI], $apars[VBSEO_PAGENUM_URI_GARS], VBSEO_URL_THREAD_GARS_PAGENUM);
                                 } else {
                                     if (!isset($apars['goto'])) {
                                         $newurl = vbseo_thread_url($apars[VBSEO_THREADID_URI], isset($apars[VBSEO_PAGENUM_URI]) ? $apars[VBSEO_PAGENUM_URI] : 0);
                                     }
                                 }
                             }
                         }
                         if ($newurl) {
                             $url_script = $newurl;
                             unset($apars[VBSEO_POSTID_URI]);
                             unset($apars['postid']);
                             unset($apars[VBSEO_THREADID_URI]);
                             unset($apars[VBSEO_PAGENUM_URI]);
                             if (VBSEO_ENABLE_GARS) {
                                 unset($apars[VBSEO_PAGENUM_URI_GARS]);
                             }
                             unset($apars['threadid']);
                             unset($apars['pp']);
                             unset($apars['goto']);
                         }
                     }
                     break;
                 case 'printthread.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_PRINTTHREAD) {
                         $url_script = vbseo_thread_url($apars[VBSEO_THREADID_URI], $apars[VBSEO_PAGENUM_URI], $apars[VBSEO_PAGENUM_URI] + 0 > 1 ? VBSEO_URL_THREAD_PRINT_PAGENUM : VBSEO_URL_THREAD_PRINT);
                         unset($apars[VBSEO_THREADID_URI]);
                         unset($apars[VBSEO_PAGENUM_URI]);
                         if ($apars['pp'] == $vboptions['maxposts']) {
                             unset($apars['pp']);
                         }
                         if (VBSEO_NOFOLLOW_PRINTTHREAD) {
                             $nofollow = true;
                         }
                     }
                     break;
                 case 'showpost.' . VBSEO_VB_EXT:
                     $url_script2 = '';
                     if (VBSEO_POSTBIT_PINGBACK == 2 && $apars['postcount']) {
                         global $vbphrase;
                         $url_script2 = vbseo_thread_url_postid($apars[VBSEO_POSTID_URI], 1, false, $apars['postcount']);
                         $posturl = str_replace('>', ' title="' . $vbphrase['vbseo_permalink'] . '">', $posturl);
                         if ($url_script) {
                             $posturl = str_replace('target="new"', '', $posturl);
                             $clear_all_par = true;
                         }
                     }
                     if (VBSEO_REWRITE_SHOWPOST && $apars[VBSEO_POSTID_URI]) {
                         if (!$url_script2) {
                             $url_script2 = vbseo_post_url($apars[VBSEO_POSTID_URI], $apars['postcount']);
                         }
                         $clear_all_par = true;
                     }
                     if ($url_script2) {
                         $url_script = $url_script2;
                     }
                     if (VBSEO_NOFOLLOW_SHOWPOST == 2) {
                         global $threadinfo;
                         if ($threadinfo['replycount'] == $apars['postcount'] - 1 && $apars['postcount'] % $vboptions['maxposts'] == 1) {
                             $nofollow = true;
                         } else {
                             $follow = true;
                         }
                     } else {
                         if (VBSEO_NOFOLLOW_SHOWPOST == 1) {
                             $nofollow = true;
                         } else {
                             if (VBSEO_NOFOLLOW_SHOWPOST == 0) {
                                 $follow = true;
                             }
                         }
                     }
                     break;
                 case 'poll.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_POLLS) {
                         if ($apars[VBSEO_ACTION_URI] == 'showresults') {
                             $url_script = vbseo_poll_url($apars[VBSEO_POLLID_URI]);
                             $clear_all_par = true;
                         }
                     }
                     break;
                 case 'album.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_MEMBERS && !isset($apars['do'])) {
                         if (isset($apars['pictureid'])) {
                             $newurl = vbseo_album_url($apars['page'] > 1 ? 'VBSEO_URL_MEMBER_PICTURE_PAGE' : 'VBSEO_URL_MEMBER_PICTURE', $apars);
                         } else {
                             if (isset($apars['albumid']) && count($apars) == 1) {
                                 $newurl = vbseo_album_url('VBSEO_URL_MEMBER_ALBUM', $apars);
                             } else {
                                 if (isset($apars['u']) && count($apars) == 1) {
                                     $newurl = vbseo_album_url('VBSEO_URL_MEMBER_ALBUMS', $apars);
                                 }
                             }
                         }
                         if ($newurl) {
                             $url_script = $newurl;
                             unset($apars['pictureid']);
                             unset($apars['albumid']);
                             unset($apars['u']);
                             unset($apars['page']);
                         }
                     }
                     break;
                 case 'picture.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_MEMBERS && !isset($apars['do'])) {
                         if (isset($apars['albumid']) && isset($apars['pictureid'])) {
                             $newurl = vbseo_album_url('VBSEO_URL_MEMBER_PICTURE_IMG', $apars);
                         } else {
                             if (isset($apars['groupid']) && isset($apars['pictureid'])) {
                                 $newurl = vbseo_group_url(VBSEO_URL_GROUPS_PICTURE_IMG, $apars);
                             }
                         }
                         if ($newurl) {
                             $url_script = $newurl;
                             $clear_all_par = true;
                         }
                     }
                     break;
                 case 'member.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_MEMBERS) {
                         if (!isset($apars['u']) && isset($apars['userid'])) {
                             $apars['u'] = $apars['userid'];
                         }
                         if (isset($apars['find']) && $apars['find'] == 'lastposter') {
                             if ($apars[VBSEO_FORUMID_URI]) {
                                 $url_script = vbseo_member_url(0, $vbseo_gcache['forum'][$apars[VBSEO_FORUMID_URI]]['lastposter'] ? $vbseo_gcache['forum'][$apars[VBSEO_FORUMID_URI]]['lastposter'] : $intag);
                             } else {
                                 $url_script = vbseo_member_url(0, $vbseo_gcache['thread'][$apars[VBSEO_THREADID_URI]]['lastposter'] ? $vbseo_gcache['thread'][$apars[VBSEO_THREADID_URI]]['lastposter'] : $intag);
                             }
                             $clear_all_par = true;
                         } else {
                             if (isset($apars['username'])) {
                                 $url_script = vbseo_member_url(0, $apars['username']);
                                 $clear_all_par = true;
                             } else {
                                 if ($apars['tab'] == 'visitor_messaging' && $apars['page'] > 1) {
                                     $url_place = '';
                                     $url_script = vbseo_member_url($apars['u'], '', 'VBSEO_URL_MEMBER_MSGPAGE', array('%page%' => $apars['page']));
                                     $clear_all_par = true;
                                 } else {
                                     if ($apars['tab'] == 'friends' && $apars['page'] > 1) {
                                         $url_script = vbseo_member_url($apars['u'], '', 'VBSEO_URL_MEMBER_FRIENDSPAGE', array('%page%' => $apars['page']));
                                         $clear_all_par = true;
                                     } else {
                                         if (isset($apars['u']) && !isset($apars['do']) && !isset($apars['simple']) && !isset($apars['dozoints']) && !isset($apars['sort']) && !isset($apars['showignored'])) {
                                             $url_script = vbseo_member_url($apars['u']);
                                             if (isset($apars['nozoints']) || isset($apars['page']) || isset($apars['showall']) || isset($apars['explain'])) {
                                                 unset($apars['u']);
                                             } else {
                                                 $clear_all_par = true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($tempusagecache['SHOWTHREAD']) {
                         if (VBSEO_NOFOLLOW_MEMBER_POSTBIT) {
                             $nofollow = true;
                         } else {
                             $follow = true;
                         }
                     } else {
                         if ($tempusagecache['FORUMHOME'] || $tempusagecache['FORUMDISPLAY']) {
                             if (VBSEO_NOFOLLOW_MEMBER_FORUMHOME) {
                                 $nofollow = true;
                             } else {
                                 $follow = true;
                             }
                         }
                     }
                     break;
                 case 'converse.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_MEMBERS) {
                         $url_script = vbseo_member_url($apars['u'], '', $apars['page'] ? 'VBSEO_URL_MEMBER_CONVPAGE' : 'VBSEO_URL_MEMBER_CONV', array(), $apars);
                         if ($url_script) {
                             unset($apars['u']);
                             unset($apars['u2']);
                             unset($apars['page']);
                         }
                     }
                     break;
                 case 'image.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_AVATAR) {
                         if (isset($apars[VBSEO_USERID_URI]) && (!isset($apars['type']) || $apars['type'] != 'profile')) {
                             $url_script = vbseo_member_url($apars[VBSEO_USERID_URI], '', 'VBSEO_URL_AVATAR');
                             unset($apars[VBSEO_USERID_URI]);
                         }
                     }
                     break;
                 case 'memberlist.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_MEMBER_LIST) {
                         if (isset($apars['ltr']) || !isset($apars[VBSEO_ACTION_URI]) || $apars[VBSEO_ACTION_URI] == 'getall') {
                             $url_script = vbseo_memberlist_url(isset($apars['ltr']) ? $apars['ltr'] : '', isset($apars[VBSEO_PAGENUM_URI]) ? $apars[VBSEO_PAGENUM_URI] : '');
                             $apars2 = $apars;
                             $unsetpar = array('ltr', 'pp', VBSEO_SORT_URI, VBSEO_SORTORDER_URI, VBSEO_ACTION_URI, VBSEO_PAGENUM_URI);
                             foreach ($unsetpar as $i => $up) {
                                 unset($apars2[$up]);
                             }
                             if ((!isset($apars[VBSEO_SORT_URI]) || $apars[VBSEO_SORT_URI] == VBSEO_DEFAULT_MEMBERLIST_SORT) && (!isset($apars[VBSEO_SORTORDER_URI]) || stristr($apars[VBSEO_SORTORDER_URI], VBSEO_DEFAULT_MEMBERLIST_ORDER)) && count($apars2) == 0) {
                                 $clear_all_par = true;
                             } else {
                                 unset($apars['ltr']);
                                 unset($apars[VBSEO_ACTION_URI]);
                                 unset($apars[VBSEO_PAGENUM_URI]);
                             }
                         }
                     }
                     break;
                 case 'attachment.' . VBSEO_VB_EXT:
                     if ($apars['attachmentid']) {
                         if (VBSEO_REWRITE_ATTACHMENTS_ALT && $apars['thumb'] && ($newalt = vbseo_attachment_url($apars['attachmentid'], VBSEO_URL_ATTACHMENT_ALT))) {
                             $posturl = preg_replace('#(alt=)"[^"]*#is', '$1"' . htmlspecialchars($newalt), $posturl);
                         }
                         if (VBSEO_REWRITE_ATTACHMENTS && ($newurl = vbseo_attachment_url($apars['attachmentid'], '', $apars['d'], $apars['thumb']))) {
                             $url_script = $newurl;
                             unset($apars['attachmentid']);
                             unset($apars['stc']);
                             unset($apars['d']);
                             unset($apars['thumb']);
                         }
                     }
                     break;
                 case 'blog_attachment.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_BLOGS_ATT && ($newurl = vbseo_blog_url(VBSEO_URL_BLOG_ATT, $apars))) {
                         $url_script = $newurl;
                         unset($apars['attachmentid']);
                         unset($apars['stc']);
                         unset($apars['d']);
                         unset($apars['thumb']);
                     }
                     break;
                 case 'tags.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_TAGS) {
                         if ($apars['tag']) {
                             $newurl = vbseo_tags_url($apars['page'] ? VBSEO_URL_TAGS_ENTRYPAGE : VBSEO_URL_TAGS_ENTRY, $apars);
                         } else {
                             if (count($apars) == 0) {
                                 $newurl = vbseo_tags_url(VBSEO_URL_TAGS_HOME);
                             }
                         }
                         if ($newurl) {
                             $url_script = $newurl;
                             unset($apars['tag']);
                             unset($apars['page']);
                         }
                     }
                     break;
                 case 'blog_external.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_BLOGS_FEED) {
                         if ($apars['bloguserid']) {
                             $newurl = vbseo_blog_url(VBSEO_URL_BLOG_FEEDUSER, $apars);
                         } else {
                             $newurl = vbseo_blog_url(VBSEO_URL_BLOG_FEED);
                         }
                         if ($newurl) {
                             $url_script = $newurl;
                             $clear_all_par = true;
                         }
                     }
                     break;
                 case 'blog.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_BLOGS) {
                         if (count($apars) == 0) {
                             $newurl = vbseo_blog_url(VBSEO_URL_BLOG_HOME, $apars);
                         } else {
                             if ($apars['u']) {
                                 if (count($apars) == 1 || count($apars) == 2 && $apars['blogtype'] == 'recent') {
                                     $newurl = vbseo_blog_url(VBSEO_URL_BLOG_USER, $apars);
                                 } else {
                                     if ($apars['page'] && (count($apars) == 2 || count($apars) == 3 && $apars['blogtype'] == 'recent')) {
                                         $newurl = vbseo_blog_url(VBSEO_URL_BLOG_USER_PAGE, $apars);
                                     } else {
                                         if ($apars[VBSEO_BLOG_CATID_URI]) {
                                             if (VBSEO_REWRITE_BLOGS_CAT) {
                                                 $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_CAT_PAGE : VBSEO_URL_BLOG_CAT, $apars);
                                             }
                                         } else {
                                             if (VBSEO_REWRITE_BLOGS_LIST) {
                                                 if ($apars['d'] && !$apars['page']) {
                                                     $newurl = vbseo_blog_url(VBSEO_URL_BLOG_UDAY, $apars);
                                                 } else {
                                                     if ($apars['m'] && !$apars['page']) {
                                                         $newurl = vbseo_blog_url(VBSEO_URL_BLOG_UMONTH, $apars);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (($apars['b'] || $apars['blogid']) && (count($apars) == 1 || $apars['goto'] == 'newpost')) {
                                     if (VBSEO_REWRITE_BLOGS_ENT) {
                                         $newurl = vbseo_blog_url(VBSEO_URL_BLOG_ENTRY, $apars);
                                     }
                                 } else {
                                     if ($apars['b'] && $apars['goto']) {
                                         if (VBSEO_REWRITE_BLOGS_ENT) {
                                             $newurl = vbseo_blog_url($apars['goto'] == 'next' ? VBSEO_URL_BLOG_NEXT : VBSEO_URL_BLOG_PREV, $apars);
                                         }
                                     } else {
                                         if ($apars['bt'] && strstr($url, 'blog.') && count($apars) == 1) {
                                             if (VBSEO_REWRITE_BLOGS_ENT) {
                                                 $newurl = vbseo_blog_url(VBSEO_URL_BLOG_ENTRY_REDIR, $apars);
                                             }
                                         } else {
                                             if (VBSEO_REWRITE_BLOGS_LIST && $apars['do'] == 'bloglist') {
                                                 if (count($apars) == 1 || $apars['page']) {
                                                     $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_BLIST_PAGE : VBSEO_URL_BLOG_BLIST, $apars);
                                                 } else {
                                                     if ($apars['blogtype'] == 'best') {
                                                         $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_BEST_BLOGS_PAGE : VBSEO_URL_BLOG_BEST_BLOGS, $apars);
                                                     }
                                                 }
                                             } else {
                                                 if (VBSEO_REWRITE_BLOGS_LIST && $apars['do'] == 'comments') {
                                                     if (count($apars) == 1) {
                                                         $newurl = vbseo_blog_url(VBSEO_URL_BLOG_CLIST);
                                                     } else {
                                                         if ($apars['page']) {
                                                             $newurl = vbseo_blog_url(VBSEO_URL_BLOG_CLIST_PAGE, $apars);
                                                         }
                                                     }
                                                 } else {
                                                     if (VBSEO_REWRITE_BLOGS_LIST && $apars['do'] == 'list') {
                                                         if (!$apars['blogtype'] && !$apars['y'] || in_array($apars['blogtype'], array('recent', 'latest'))) {
                                                             $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_LIST_PAGE : VBSEO_URL_BLOG_LIST, $apars);
                                                         } else {
                                                             if ($apars['blogtype'] == 'best') {
                                                                 $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_BEST_ENT_PAGE : VBSEO_URL_BLOG_BEST_ENT, $apars);
                                                             } else {
                                                                 if ($apars['d']) {
                                                                     $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_DAY_PAGE : VBSEO_URL_BLOG_DAY, $apars);
                                                                 } else {
                                                                     if ($apars['m']) {
                                                                         $newurl = vbseo_blog_url($apars['page'] ? VBSEO_URL_BLOG_MONTH_PAGE : VBSEO_URL_BLOG_MONTH, $apars);
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($newurl) {
                         $url_script = $newurl;
                         $clear_all_par = true;
                     } else {
                         $noproc = true;
                     }
                     break;
                 case 'group.' . VBSEO_VB_EXT:
                     if (VBSEO_REWRITE_GROUPS) {
                         if ($apars['pp'] == $vboptions['vm_perpage']) {
                             unset($apars['pp']);
                         }
                         if ($apars['gmid'] && !isset($apars['do'])) {
                             $apars['page'] = vbseo_grp_pagenum($apars['groupid'], $apars['gmid']);
                             $url_place = 'gmessage' . $apars['gmid'];
                             unset($apars['gmid']);
                         }
                         if ($apars['do'] == 'grouplist' && $apars['sort'] == 'lastpost') {
                             unset($apars['sort']);
                         }
                         if (count($apars) == 0 || $apars['do'] == 'grouplist' && count($apars) == 1) {
                             $newurl = vbseo_group_url(VBSEO_URL_GROUPS_HOME, $apars);
                         } else {
                             if ($apars['do'] == 'grouplist' && $apars['page']) {
                                 $newurl = vbseo_group_url(VBSEO_URL_GROUPS_HOME_PAGE, $apars);
                             } else {
                                 if ($apars['do'] == 'viewmembers') {
                                     $newurl = vbseo_group_url($apars['page'] > 1 ? VBSEO_URL_GROUPS_MEMBERS_PAGE : VBSEO_URL_GROUPS_MEMBERS, $apars);
                                 } else {
                                     if ($apars['do'] == 'grouppictures') {
                                         $newurl = vbseo_group_url($apars['page'] > 1 ? VBSEO_URL_GROUPS_PIC_PAGE : VBSEO_URL_GROUPS_PIC, $apars);
                                     } else {
                                         if ($apars['do'] == 'picture') {
                                             $newurl = vbseo_group_url($apars['page'] > 1 ? VBSEO_URL_GROUPS_PICTURE_PAGE : VBSEO_URL_GROUPS_PICTURE, $apars);
                                         } else {
                                             if ($apars['groupid'] && (count($apars) == 1 || $apars['do'] == 'view' || $apars['page'] && $apars['page'] < 2)) {
                                                 $newurl = vbseo_group_url(VBSEO_URL_GROUPS, $apars);
                                             } else {
                                                 if ($apars['groupid'] && count($apars) == 2 && $apars['page']) {
                                                     $newurl = vbseo_group_url(VBSEO_URL_GROUPS_PAGE, $apars);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if ($newurl) {
                             $url_script = $newurl;
                             $clear_all_par = true;
                         } else {
                             $noproc = true;
                         }
                     }
                     break;
                 default:
                     $noproc = true;
                     if (isset($apars['do']) && $apars['do'] == 'getdaily') {
                         $follow = true;
                     }
                     break;
             }
         }
     } else {
         $noproc = true;
     }
     if ($noproc) {
         if ($newurl = vbseo_apply_crr(($is_vbdir ? $base_script : $url_script) . ($url_parameters ? '?' . $url_parameters : ''), $nofollow)) {
             $url_script = $newurl;
             $clear_all_par = true;
             if ($is_vbdir) {
                 $noproc = false;
             }
         }
     }
     if ($noproc && !$is_vbdir && (!VBSEO_INFORUMDIR || $url[0] == '/' || !(VBSEO_BASEDEPTH && defined('VBSEO_PREPROCESSED'))) || (isset($VBSEO_REWRITE_TEXTURLS) || THIS_SCRIPT == 'sendmessage') || !defined('VBSEO_PREPROCESSED') && !$is_vburl && !VBSEO_BASEDEPTH && THIS_SCRIPT != 'index') {
         $topurl = '';
     }
     $amp_sign = isset($VBSEO_REWRITE_TEXTURLS) && !defined('VBSEO_REWRITE_EXTERNAL') ? '&' : '&amp;';
     if (!$clear_all_par) {
         if ($url_parameters && $url_parameters[0] == '=' || !strstr($url_parameters, '=')) {
             $par_str .= $url_parameters;
         } else {
             if (count($spars) == 1 && (!strstr($url_parameters, '=') || $url_parameters[0] == '=')) {
                 $par_str .= $spars[0][0];
             } else {
                 for ($i = 0; $i < count($spars); $i++) {
                     $k = $spars[$i][0];
                     $v = $spars[$i][1];
                     if (isset($apars[$k])) {
                         $par_str .= ($par_str ? $amp_sign : '') . $k . '=' . $v;
                     }
                 }
             }
         }
     } else {
         unset($apars);
     }
     if ($vbseo_session_append) {
         $par_str .= ($par_str ? $amp_sign : '') . $vbseo_session_append;
     }
     if ($url_script[0] != '/' && !strstr(substr($url_script, 3, 5), ':')) {
         $url_script = ($preurl ? $topurl : $vboptions['bburl2'] . '/') . $url_script;
     }
     $newurl = $url_script . ($par_str ? '?' . $par_str : '') . ($url_place ? '#' . $url_place : '');
     if ($follow) {
         $posturl = str_replace($relnofollow, '', $posturl);
         $preurl = str_replace($relnofollow, '', $preurl);
     } else {
         if ($nofollow || isset($apars['sort']) && VBSEO_NOFOLLOW_SORT || $apars && VBSEO_NOFOLLOW_DYNA) {
             if (!strstr($preurl . $mid_attribs . $posturl, ' rel=')) {
                 $preurl = preg_replace('#(<a\\s)#is', '\\1' . $relnofollow . ' ', $preurl);
             }
         } else {
             $g_replace_cache[$url] = $newurl;
         }
     }
     if ($GLOBALS['VBSEO_REWRITE_TEXTURLS'] && strstr($newurl, 'http://') && strstr($preurl, 'http://')) {
         $preurl = '';
     }
     if ($url == $intag) {
         $intag = $newurl;
     }
     return $preurl . $newurl . $posturl . $intag . $closetag;
 }