function vbseo_is_threadedmode()
{
$tmode = vbseo_vb_userinfo("threadedmode");
if(!$tmode) $tmode = $_COOKIE[vbseo_vb_cprefix() . "threadedmode"];
$mode_nonlinear = ($tmode == 'threaded' || $tmode == '1' || $tmode == '2' || $tmode == 'hybrid');
return $mode_nonlinear;
}
function vbseo_check_highlight($type)
{
$hlpar = 'highlight';
$vbseo_hlpar = 'vbseo_highlight';
if (($type==1) && VBSEO_SEARCH_REDIRECT && isset($_COOKIE) && isset($_GET[$hlpar]))
{
setcookie($vbseo_hlpar, $_GET[$hlpar]);
return $hlpar;
}
if($type ==2)
{
if (isset($_COOKIE[$vbseo_hlpar]))
{
setcookie($vbseo_hlpar, '');
$_GET[$hlpar] = $_REQUEST[$hlpar] = $_COOKIE[$vbseo_hlpar];
}
}
}
function vbseo_clean_basehref()
{
global $headinclude;
if(defined('VBSEO_PREPROCESSED') || vbseo_is_https())
$headinclude = preg_replace(&#039;#<base href[^>]*?>(\s*?<!--\[if IE\]><\/base><!\[endif\]-->)?#is&#039;, &#039;&#039;, $headinclude);
}
function vbseo_fb_meta(&$newtext, $meta, $content)
{
if(function_exists(&#039;is_facebookenabled&#039;) && is_facebookenabled() && $content)
{
$newtext = preg_replace(&#039;#("og\:&#039;.$meta.&#039;"\s*content=")[^"]*#&#039;, &#039;$1&#039;.htmlspecialchars($content), $newtext);
}
}
function vbseo_add_canonic_url($url)
{
global $headinclude;
vBSEO_Storage::set(&#039;canonical&#039;, $url);
$url = preg_replace(&#039;#&page=$#&#039;, &#039;&#039;, $url);
if(VBSEO_CANONIC_LINK_TAG && $headinclude && $url)
{
$hfullurl = htmlspecialchars(vbseo_create_full_url($url));
$headinclude = &#039;<link rel="canonical" href="&#039;.$hfullurl.&#039;" />&#039; . "\n" . $headinclude;
vbseo_fb_meta($headinclude, &#039;url&#039;, $hfullurl);
}
}
function vbseo_vbversion()
{
global $vbulletin, $versionnumber, $vboptions;
return is_object($vbulletin) ? $vbulletin->versionnumber : 
($versionnumber ? $versionnumber : $vboptions[&#039;templateversion&#039;]);
}
function vbseo_code_template($tplname, $tplcode, $append = false)
{
if(VBSEO_VB4 && vbseo_tpl_search($tplname, &#039;final_rendered&#039;))
$tplcode .= &#039;;&#039;;
else
$tplcode = &#039;".((&#039;.$tplcode.&#039;) ? "":"")."&#039;;
if($append)
return vbseo_append_template($tplname, $tplcode);
else
return vbseo_prepend_template($tplname, $tplcode);
}
function vbseo_append_template($tplname, $tplcode, $show = false)
{
global $vbulletin;
if (vbseo_tpl_exists($tplname))
{
$_thistpl = & $vbulletin->templatecache[$tplname];
$_thistpl1 = $_thistpl;
$_thistpl = $_thistpl . $tplcode;
}
if($show)echo $_thistpl;
return ($_thistpl != $_thistpl1);
}
function vbseo_prepend_template($tplname, $tplcode, $show = false)
{
global $vbulletin;
if (vbseo_tpl_exists($tplname))
{
$_thistpl = & $vbulletin->templatecache[$tplname];
$_thistpl1 = $_thistpl;
$_thistpl = $tplcode . $_thistpl;
}
if($show)echo $_thistpl;
return ($_thistpl != $_thistpl1);
}
function vbseo_tpl_exists($tplname)
{
global $vbulletin;
return isset($vbulletin->templatecache[$tplname]);
}
function vbseo_tpl_search($tplname, $searchfor)
{
global $vbulletin;
return strstr($vbulletin->templatecache[$tplname], $searchfor);
}
function vbseo_tpl_match($tplname, $snr)
{
global $vbulletin;
preg_match($snr, $vbulletin->templatecache[$tplname], $pm);
return $pm;
}
function vbseo_get_postbit_tpl()
{
global $vbulletin;     
if (is_object($GLOBALS[&#039;postbit_obj&#039;]) && $GLOBALS[&#039;postbit_obj&#039;]->templatename)
$tplpostbit = $GLOBALS[&#039;postbit_obj&#039;]->templatename;
else
if (isset($vbulletin) && $vbulletin->gars)
$tplpostbit = $vbulletin->gars->process_postbit();
else
$tplpostbit = $vbulletin->options[&#039;legacypostbit&#039;] ? &#039;postbit_legacy&#039; : &#039;postbit&#039;;
return $tplpostbit;
}
function vbseo_vb_gpc($varname)
{
if(is_object($vbulletin) && $vbulletin->GPC)
return $vbulletin->GPC[$varname];
else
return $_REQUEST[$varname];
}
function vbseo_vb_cprefix()
{
global $vbulletin;
if (VBSEO_VB35X)
{
if (!$config && isset($vbulletin))
$config = $vbulletin->config;
$cprefix = $config[&#039;Misc&#039;][&#039;cookieprefix&#039;];
if (VBSEO_VB4)
$cprefix .= &#039;_&#039;;
}
else
$cprefix = $GLOBALS[&#039;cookieprefix&#039;];
return $cprefix;
}
function vbseo_bbarray_cookie($cookiename, $id = &#039;&#039;)
{
global $_COOKIE;
$cookie_name = vbseo_vb_cprefix() . $cookiename;
$cookie = isset($_COOKIE["$cookie_name"]) ? $_COOKIE["$cookie_name"] : "";
if (get_magic_quotes_gpc())
$cookie = stripslashes($cookie);
if (isset($cookie) && $id)
{
if (VBSEO_VB35X)
$cookie = str_replace(array(&#039;.&#039;, &#039;-&#039;, &#039;_&#039;), array(&#039;"&#039;, &#039;:&#039;, &#039;;&#039;), $cookie);
else
$cookie = str_replace(array(&#039;-&#039;, &#039;_&#039;, &#039;x&#039;, &#039;y&#039;), array(&#039;{&#039;, &#039;}&#039;, &#039;:&#039;, &#039;;&#039;), $cookie);
if (!($uncookie = @unserialize($cookie)))
{
$cookie = substr($cookie, 32);
$uncookie = @unserialize($cookie);
}
$cookie = $uncookie[$id];
}
return $cookie;
}
function vbseo_allowed_blog($bloginfo)
{
global $vbulletin;
if (!($vbulletin->userinfo[&#039;permissions&#039;][&#039;vbblog_general_permissions&#039;] & $vbulletin->bf_ugp_vbblog_general_permissions[&#039;blog_canviewothers&#039;]))
{
if (!$vbulletin->userinfo[&#039;userid&#039;] OR !($vbulletin->userinfo[&#039;permissions&#039;][&#039;vbblog_general_permissions&#039;] & $vbulletin->bf_ugp_vbblog_general_permissions[&#039;blog_canviewown&#039;]))
return false;
}
if(!$bloginfo[&#039;userid&#039;])
return false;
if($bloginfo[&#039;state&#039;] != &#039;visible&#039;)
return false;
if (!$bloginfo[&#039;options_member&#039;] & $vbulletin->bf_misc_vbblogsocnetoptions[&#039;canviewmyblog&#039;])
return false;
return true;
}
function vbseo_has_cms()
{
if(VBSEO_VB_CMS)
{
if(!class_exists(&#039;vB&#039;) && function_exists(&#039;bootstrap_framework&#039;))
bootstrap_framework();
if(class_exists(&#039;vB&#039;))
{
require_once DIR . &#039;/packages/vbcms/permissions.&#039;.VBSEO_VB_EXT;
if(class_exists(&#039;vB_Types&#039;) &&
vB_Types::instance()->getContentTypeID(&#039;vBCms_Section&#039;))
return true;
}
}
return false;
}
function vbseo_permissions_cms_str()
{
if(vbseo_has_cms())
return vBCMS_Permissions::getPermissionString();
}
function vbseo_permissions_cms()
{
global $vbulletin;
if(!vbseo_has_cms())
return;
if(!$cperm = $vbulletin->userinfo[&#039;permissions&#039;][&#039;cms&#039;])
{
vBCMS_Permissions::getUserPerms();
$cperm = $vbulletin->userinfo[&#039;permissions&#039;][&#039;cms&#039;];
}
return $cperm;
}
function vbseo_allowed_cms($cmsinfo)
{
global $vbulletin;
if(!$cperm = vbseo_permissions_cms())
return false;
if (!$cmsinfo[&#039;parentnode&#039;] ||
(!in_array($cmsinfo[&#039;parentnode&#039;], $cperm[&#039;canview&#039;]) &&
!in_array($cmsinfo[&#039;permissionsfrom&#039;], $cperm[&#039;canview&#039;])
)
)
{
return false;
}
if(!$cmsinfo[&#039;setpublish&#039;] || !$cmsinfo[&#039;userid&#039;] || $cmsinfo[&#039;hidden&#039;] 
|| ($cmsinfo[&#039;publishdate&#039;] > TIMENOW)
)
return false;
return true;
}
function vbseo_allowed_forums()
{
global $vbulletin;
$forums = $vbulletin->forumcache;
$flist  = array();
foreach ($forums AS $forumid => $null)
{
$forumperms = $vbulletin->userinfo[&#039;forumpermissions&#039;]["$forumid"];
if (
$forumperms & $vbulletin->bf_ugp_forumpermissions[&#039;canview&#039;]
AND $forumperms & $vbulletin->bf_ugp_forumpermissions[&#039;canviewthreads&#039;]
AND $forumperms & $vbulletin->bf_ugp_forumpermissions[&#039;canviewothers&#039;]
)
{
$flist[] = $forumid;
}
}
return $flist;
}
function vbseo_forum_is_public(&$foruminfo, $foruminfo2 = &#039;&#039;, $fullcheck = false, $canread = false, $tinfo = array())
{
global $vbulletin, $vbseo_bitfields, $forum_is_public;
$f_perms = -1;
$fullcheck_ind = $fullcheck ? 0 : 1;
$check_groups = array(1);
vbseo_cache_start();
if (!$forum_is_public)
{
$forum_is_public = array();
if (!$fullcheck)
$forum_is_public[$fullcheck_ind] = $GLOBALS[&#039;vbseo_cache&#039;]->cacheget(&#039;forum_is_public&#039;);
}
if (!$fullcheck && isset($forum_is_public[$fullcheck_ind][$foruminfo[&#039;forumid&#039;]]))
return $forum_is_public[$fullcheck_ind][$foruminfo[&#039;forumid&#039;]];
if ($fullcheck && vbseo_vb_userinfo(&#039;usergroupid&#039;))
{
$check_groups[] = vbseo_vb_userinfo(&#039;usergroupid&#039;);
$check_groups = array_merge($check_groups,
explode(&#039;,&#039;, vbseo_vb_userinfo(&#039;membergroupids&#039;))
);
$fperm = vbseo_vb_userinfo(&#039;forumpermissions&#039;);
$check_groups[] = - $fperm[$foruminfo[&#039;forumid&#039;]];
}
$ugp_perm = isset($vbseo_bitfields[&#039;ugp&#039;][&#039;forumpermissions&#039;]) ?
$vbseo_bitfields[&#039;ugp&#039;][&#039;forumpermissions&#039;] :
$vbulletin->bf_ugp_forumpermissions;
$ispub = false;
foreach($check_groups as $gid)
{
if ($gid < 0)
$f_perms = - $gid;
else
if (@isset($foruminfo[&#039;permissions&#039;][$gid]))
$f_perms = $foruminfo[&#039;permissions&#039;][$gid];
else
if (@isset($foruminfo2[&#039;permissions&#039;][$gid]))
$f_perms = $foruminfo2[&#039;permissions&#039;][$gid];
$is_public =
($f_perms < 0) ||
(
($f_perms &(defined(&#039;CANVIEW&#039;) ? CANVIEW : 
($ugp_perm[&#039;canview&#039;] ? $ugp_perm[&#039;canview&#039;] : 1))) 
&& 
(
($f_perms &(defined(&#039;CANVIEWOTHERS&#039;) ? CANVIEWOTHERS : 
($ugp_perm[&#039;canviewothers&#039;] ? $ugp_perm[&#039;canviewothers&#039;]:2))) 
||
($tinfo[&#039;postuserid&#039;] && ($tinfo[&#039;postuserid&#039;] == vbseo_vb_userid()))
)	
&& 
(!$canread || ($ugp_perm[&#039;canviewthreads&#039;] ? $f_perms & $ugp_perm[&#039;canviewthreads&#039;] : 1))
);
if ($is_public)
{
$ispub = true;
break;
}
}
if (!$fullcheck)
{
$forum_is_public[$fullcheck_ind][$foruminfo[&#039;forumid&#039;]] = $ispub;
$GLOBALS[&#039;vbseo_cache&#039;]->cacheset(&#039;forum_is_public&#039;, $forum_is_public[$fullcheck_ind]);
}
return $ispub;
}
function vbseo_vmsg_pagenum($userid, $vmid)
{
global $vboptions;
$db = vbseo_get_db();
$vmsg = $db->vbseodb_query_first("SELECT *
FROM " . vbseo_tbl_prefix(&#039;visitormessage&#039;)." AS visitormessage
WHERE visitormessage.vmid = ".intval($vmid)."
");
$getpagenum = $db->vbseodb_query_first($q="
SELECT COUNT(*) AS comments
FROM " . vbseo_tbl_prefix(&#039;visitormessage&#039;)." AS visitormessage
WHERE userid = " . intval($userid) . "
AND state in (&#039;visible&#039;)
AND dateline >= $vmsg[dateline]
");
$perpage = intval($vboptions[&#039;vm_perpage&#039;]);
$pg = $perpage ? ceil($getpagenum[&#039;comments&#039;] / $perpage) : 1;
return $pg;
}
function vbseo_gmsg_pagenum(&$disid, $gmid)
{
global $vboptions;
$db = vbseo_get_db();
$commno = 0;
if($GLOBALS[&#039;vbseo_gcache&#039;][&#039;groupsdis&#039;])
{
foreach($GLOBALS[&#039;vbseo_gcache&#039;][&#039;groupsdis&#039;] as $gid=>$ginfo)
{
if( ($ginfo[&#039;gmid&#039;] == $gmid) || ($ginfo[&#039;lastpostid&#039;] == $gmid) )
{
if(!$disid)
$disid = $ginfo[&#039;discussionid&#039;];
if(isset($ginfo[&#039;replies&#039;]))
$commno = $ginfo[&#039;replies&#039;]+1;
break;
}
}
}
if(!$commno)
{
$gmsg = $db->vbseodb_query_first("SELECT *
FROM " . vbseo_tbl_prefix(&#039;groupmessage&#039;)."
WHERE gmid = ".intval($gmid)."
");
if(vbseo_vbversion() < &#039;3.8&#039;)
return vbseo_grp_pagenum($gmsg[&#039;groupid&#039;], $gmid);
if(!$disid)
$disid = $gmsg[&#039;discussionid&#039;];
$getpagenum = $db->vbseodb_query_first($q="
SELECT COUNT(*) AS comments
FROM " . vbseo_tbl_prefix(&#039;groupmessage&#039;)."
WHERE discussionid = " . intval($disid) . "
AND state in (&#039;visible&#039;)
AND dateline <= $gmsg[dateline]
");
$commno = $getpagenum[&#039;comments&#039;];
}
$perpage = intval($vboptions[&#039;gm_perpage&#039;]);
$pg = $perpage ? ceil($commno / $perpage) : 1;
return $pg;
}
function vbseo_grp_pagenum($groupid, $gmid)
{
global $vboptions;
$db = vbseo_get_db();
vbseo_int_var($groupid);
vbseo_int_var($gmid);
$vmsg = $db->vbseodb_query_first($q1="SELECT *
FROM " . vbseo_tbl_prefix(&#039;groupmessage&#039;)." AS comments
WHERE gmid = &#039;".intval($gmid)."&#039; AND groupid = &#039;$groupid&#039;
");
$getpagenum = $db->vbseodb_query_first($q="
SELECT COUNT(*) AS comments
FROM " . vbseo_tbl_prefix(&#039;groupmessage&#039;) . " AS gm
WHERE groupid = &#039;$groupid&#039;
AND state in (&#039;visible&#039;)
AND dateline >= $vmsg[dateline]
");
$perpage = intval($vboptions[&#039;vm_perpage&#039;]);
$pg = $perpage ? ceil($getpagenum[&#039;comments&#039;] / $perpage) : 1;
return $pg;
}
function vbseo_pic_pagenum($picid, $commentid)
{
global $vboptions;
$db = vbseo_get_db();
vbseo_int_var($picid);
vbseo_int_var($commentid);
if(VBSEO_VB4)
{
$w = &#039;a.attachmentid = &#039; . intval($picid) ;
$j = &#039;LEFT JOIN &#039;.vbseo_tbl_prefix(&#039;attachment&#039;).&#039; a on a.filedataid = pc.filedataid&#039;;
}else
{
$w = &#039;pictureid = &#039; . intval($picid) ;
$j = &#039;&#039;;
}
$getpagenum = $db->vbseodb_query_first($q="
SELECT COUNT(*) AS comments
FROM " . vbseo_tbl_prefix(&#039;picturecomment&#039;)." pc
$j
WHERE $w
AND pc.state in (&#039;visible&#039;)
AND pc.commentid <= &#039;$commentid&#039;
");
$perpage = intval($vboptions[&#039;pc_perpage&#039;]);
$pg = $perpage ? ceil($getpagenum[&#039;comments&#039;] / $perpage) : 1;
return $pg;
}
function vbseo_get_next_thread($threadid, $older)
{
global $vbseo_gcache;
vbseo_int_var($threadid);   
$thread = $vbseo_gcache[&#039;thread&#039;][$threadid];
$db = vbseo_get_db();
$hasthreadprefixes = vbseo_vbversion()>=&#039;3.8&#039;;
$getnextoldest = $db->vbseodb_query_first("
SELECT t.forumid, t.threadid, " . (VBSEO_GET_THREAD_TITLES ? &#039;t.title, &#039; : &#039;&#039;) . "t.replycount, t.lastposter, t.lastpost".
((VBSEO_URL_THREAD_PREFIX && $hasthreadprefixes) ? &#039;, t.prefixid&#039; : &#039;&#039;)."
FROM " . vbseo_tbl_prefix(&#039;thread&#039;) . " AS t
WHERE forumid = $thread[forumid] AND lastpost " . ($older?&#039;<&#039;:&#039;>&#039;) . " $thread[lastpost] AND visible = 1 AND open <> 10
ORDER BY lastpost " . ($older?&#039;DESC&#039;:&#039;&#039;) . "
LIMIT 1
");
vbseo_thread_seotitle($getnextoldest);
$vbseo_gcache[&#039;thread&#039;][$getnextoldest[&#039;threadid&#039;]] = $getnextoldest;
return $getnextoldest;
}
function vbseo_get_post_info($postid)
{
global $vbseo_gcache;
if (isset($vbseo_gcache[&#039;post&#039;][$postid]) && $vbseo_gcache[&#039;post&#039;][$postid][&#039;threadid&#039;]) 
return $vbseo_gcache[&#039;post&#039;][$postid];
$db = vbseo_get_db();
$postarr = $db->vbseodb_query_first("
SELECT postid,threadid,dateline,userid,visible
FROM " . vbseo_tbl_prefix(&#039;post&#039;) . " 
WHERE postid = " . intval($postid) . " 
LIMIT 1
");
$vbseo_gcache[&#039;post&#039;][$postid] = $postarr;
return $postarr;
}
function vbseo_get_last_post($threadid)
{
$db = vbseo_get_db();
$postarr = $db->vbseodb_query_first("
SELECT MAX(postid) AS postid
FROM " . vbseo_tbl_prefix(&#039;post&#039;) . " AS post
WHERE threadid = " . intval($threadid) . " AND visible = 1
LIMIT 1
");
return $postarr[&#039;postid&#039;];
}
function vbseo_get_new_post($threadid)
{
global $vboptions, $vbseo_gcache;
$db = vbseo_get_db();
vbseo_int_var($threadid);
$lvisit = vbseo_vb_userinfo(&#039;lastvisit&#039;);
if ($vboptions[&#039;threadmarking&#039;] AND vbseo_vb_userid())
{
$threadinfo = $db->vbseodb_query_first($q = "
SELECT
threadread.readtime AS threadread, forumread.readtime AS forumread
FROM " . vbseo_tbl_prefix(&#039;thread&#039;) . " AS thread
LEFT JOIN " . vbseo_tbl_prefix(&#039;threadread&#039;) . " AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = " . vbseo_vb_userid() . ")
LEFT JOIN " . vbseo_tbl_prefix(&#039;forumread&#039;) . " AS forumread ON (forumread.forumid = thread.forumid AND forumread.userid = " . vbseo_vb_userid() . ")
WHERE thread.threadid = &#039;$threadid&#039;
");
$lvisit = max($threadinfo[&#039;threadread&#039;], $threadinfo[&#039;forumread&#039;], TIMENOW - ($vboptions[&#039;markinglimit&#039;] * 86400));
}
else
if (($tview = vbseo_bbarray_cookie(&#039;thread_lastview&#039;, $threadid)) > $lvisit)
$lvisit = $tview;
$postarr = $db->vbseodb_query_first($q = "
SELECT MIN(postid) AS postid
FROM " . vbseo_tbl_prefix(&#039;post&#039;) . "
WHERE threadid = $threadid
AND visible = 1
AND dateline > " . intval($lvisit) . "
LIMIT 1
");
return $postarr[&#039;postid&#039;] ? $postarr[&#039;postid&#039;] :
vbseo_get_last_post($threadid);
}

Add a code snippet to your website: www.paste.org