Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)
Paste
Pasted as PHP by registered user atmaca ( 6 months ago )
function vbseo_get_post_thread_info($ids, $implicit = false)
{
global $vbseo_gcache;
global $found_object_ids;
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
$lookupids = array();
foreach($ids as $id)
if($id)
{
if (isset($vbseo_gcache['post'][$id]) && $vbseo_gcache['post'][$id]['threadid'] && !$implicit) continue;
$vbseo_gcache['post'][$id] = array();
$lookupids[] = $id;
}
vbseo_int_var($lookupids);
if (empty($lookupids))return array();
$db = vbseo_get_db();
$db->vbseodb_select_db();
$rid = $db->vbseodb_query($q = "
select p.postid, t.threadid, t.title, p.dateline
from " . vbseo_tbl_prefix('thread') . " t, " . vbseo_tbl_prefix('post') . " p
where
p.postid in (" . join(',', $lookupids) . ")
AND p.threadid=t.threadid
");
$postids = array();
if ($rid)
{
while ($post = @$db->funcs['fetch_assoc']($rid))
{
if (@in_array($post['postid'], $found_object_ids['prepostthread_ids']))
{
$bbu = vbseo_vb_userinfo();
if(function_exists('fetch_coventry'))
{
if($coventry = fetch_coventry('string'))
$whr = " AND p.userid NOT IN ($coventry)";
}
$dbret = $db->vbseodb_query_first("
select count(*) as preposts
from " . vbseo_tbl_prefix('post') . " p
where
p.threadid='" . $post['threadid'] . "'
AND p.visible=1
AND p.dateline " . (($bbu['postorder'] == 0) ? '<=' : '>=') . $post['dateline'] . "
$whr
");
$post['preposts'] = $dbret['preposts'];
$post['prepostsproc'] = isset($bbu['postorder']);
}
$vbseo_gcache['post'][$post['postid']] = $post;
$found_object_ids['postthreads'][] = $post['threadid'];
}
$db->vbseodb_free_result($rid);
}
$arr = array();
foreach($ids as $id)
{
$arr[$id] = $vbseo_gcache['post'][$id];
}
return $arr;
}
function vbseo_get_forum_announcement($id, $aids = 0)
{
global $vboptions, $vbseo_gcache, $vbseo_precache, $usercache;
$ids = is_array($id) ? $id : array($id);
if (isset($vbseo_precache['announcements']))
{
foreach($vbseo_precache['announcements'] as $ann)
foreach($ids as $fid)
{
$vbseo_gcache['forum'][$fid]['announcement'][$ann['announcementid']] = $ann['title'];
$usercache[$ann['userid']] = array('userid' => $ann['userid'],
'username' => $ann['username']
);
}
return;
}
vbseo_int_var($ids);
$db = vbseo_get_db();
$idlist = '';
for($i = 0; $i < count($ids); $i++)
{
$idlist .= ($i?',':'') . $ids[$i];
$pl = $vbseo_gcache['forum'][$ids[$i]]['parentlist'];
if ($pl)
$idlist .= ',' . $pl;
}
$rid = $db->vbseodb_query($q = "
SELECT
forumid,announcementid,title
FROM " . vbseo_tbl_prefix('announcement') . " AS announcement
WHERE " . ($aids?"announcementid='$aids'":"startdate <= " . (time() - $vboptions['hourdiff']) . "
AND enddate >= " . (time() - $vboptions['hourdiff']) . "
AND forumid IN (" . $idlist . ",-1)
ORDER BY startdate DESC")
);
if ($rid)
{
while ($arr = @$db->funcs['fetch_assoc']($rid))
{
$fid = $arr['forumid'];
if ($aids)$ids = array($fid);
for($i = 0; $i < count($ids); $i++)
{
if (isset($vbseo_gcache['forum'][$ids[$i]]))
{
$forum = &$vbseo_gcache['forum'][$ids[$i]];
if (($fid == -1) ||
($ids[$i] == $fid) ||
preg_match('#\b' . $fid . '\b#', $forum['parentlist']))
$forum['announcement'][$arr['announcementid']] = $arr['title'];
}
}
if ($aids)return $arr;
}
$db->vbseodb_free_result($rid);
}
return $forum;
}
function vbseo_get_poll_info($ids)
{
global $vbseo_gcache, $pollinfo;
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
if ($pollinfo)
{
$vbseo_gcache['polls'][$pollinfo['pollid']] = $pollinfo;
$ids = array_diff($ids, array($pollinfo['pollid']));
}
if (isset($vbseo_gcache['polls']) && $vbseo_gcache['polls'])
$ids = array_diff($ids, array_keys($vbseo_gcache['polls']));
vbseo_int_var($ids);
if (!empty($ids))
{
$db = vbseo_get_db();
$rid = $db->vbseodb_query($q = "
SELECT
pollid, question
FROM " . vbseo_tbl_prefix('poll') . "
WHERE pollid IN (" . implode(',', $ids) . ")");
if ($rid)
{
while ($arr = @$db->funcs['fetch_assoc']($rid))
$vbseo_gcache['polls'][$arr['pollid']] = $arr;
$db->vbseodb_free_result($rid);
}
}
}
function vbseo_get_forum_info($implicit = false)
{
global $vbseo_gcache, $vbulletin, $vboptions, $usercache,
$forumcache, $threadcache, $vbseo_cache, $found_object_ids;
vbseo_cache_start();
$f_allow = (!$found_object_ids['forum_last'] ||
($found_object_ids['forum_last'][0] && $forumcache[$found_object_ids['forum_last'][0]] && $forumcache[$found_object_ids['forum_last'][0]]['lastposter'])
);
$fp_cached = $vboptions['vbseo_opt']['forumpaths'] ? true : false;
$vbseo_fp = $fp_cached ? $vboptions['vbseo_opt']['forumpaths'] : array();
$savecache = false;
if (!$vbseo_gcache['forum'])
$vbseo_gcache['forum'] = $vbseo_cache->cacheget('forum');
if (is_object($vbulletin) && $vbulletin->forumcache)
$fc = &$vbulletin->forumcache;
else
$fc = &$forumcache;
if (empty($vbseo_gcache['forum']) || ($implicit && $f_allow))
{
if (is_array($fc) && $f_allow)
{
foreach($fc as $forum_id => $arr)
{
$arr['parentlist'] = substr($arr['parentlist'], 0, -3);
$vbseo_gcache['forum'][$arr['forumid']] = $arr;
}
}
else
{
$db = vbseo_get_db();
$rid = $db->vbseodb_query("select forumid" . (VBSEO_GET_FORUM_TITLES ? ', title' : '') .
", parentlist, lastpost, lastposter, daysprune, parentid, threadcount, lastthreadid, lastthread, lastpostid from " . vbseo_tbl_prefix('forum') );
if ($rid)
{
while ($arr = @$db->funcs['fetch_assoc']($rid))
{
$arr['parentlist'] = substr($arr['parentlist'], 0, -3);
$vbseo_gcache['forum'][$arr['forumid']] = $arr;
}
$db->vbseodb_free_result($rid);
}
}
$forumids = $vbseo_gcache['forum'] ? array_keys($vbseo_gcache['forum']) : array();
foreach($forumids as $forumid)
{
$forum = &$vbseo_gcache['forum'][$forumid];
if (isset($forum['lastthreadid']) && ($tid = $forum['lastthreadid']) && !in_array(THIS_SCRIPT, array('showthread', 'printthread', 'showpost')))
{
$threadcache[$tid] = array_merge(isset($threadcache[$tid])?$threadcache[$tid]:array(),
array('threadid' => $forum['lastthreadid'],
'title' => $forum['lastthread'],
'forumid' => $forumid,
'lastpost' => $forum['lastpost'],
'lastpostid' => $forum['lastpostid'],
'lastposter' => $forum['lastposter']
));
}
if ($fp_cached)
continue;
$parentlist = array_reverse(explode(',', $forum['parentlist']));
$forum['patharr'] = array();
if (VBSEO_GET_FORUM_PATH)
for($i = 0; isset($parentlist[$i]) && ($id = $parentlist[$i]); $i++)
{
vbseo_forum_seotitle($vbseo_gcache['forum'][$id]);
$replace = array('%forum_id%' => $id,
'%forum_title%' => $vbseo_gcache['forum'][$id]['seotitle'],
);
$forum['patharr'] [] = str_replace(array_keys($replace), $replace, VBSEO_FORUM_TITLE_BIT);
}
$fc[$forumid]['path'] = $forum['path'] = @implode('/', $forum['patharr']);
}
$savecache = true;
}
if (!$fp_cached)
{
$vboptions['vbseo_opt'] = array();
vbseo_check_datastore();
}
if(is_array($vbseo_gcache['forum']))
foreach($vbseo_gcache['forum'] as $forumid => $arr)
{
if (isset($arr['lastposter']) && $found_object_ids['forum_last'] && in_array($arr['forumid'], $found_object_ids['forum_last']))
$found_object_ids['user_names'][] = $arr['lastposter'];
if (!isset($arr['path']) && $fp_cached)
$vbseo_gcache['forum'][$forumid]['path'] = $vbseo_fp[$forumid];
if (isset($arr['lastpostid']))
{
$lpostid = $arr['lastpostid'];
if (!isset($vbseo_gcache['post'][$lpostid]) && isset($arr['lastthreadid']))
$vbseo_gcache['post'][$lpostid] = array('postid' => $lpostid,
'threadid' => $arr['lastthreadid'],
);
}
}
if ($savecache)
{
if(is_array($vbseo_gcache['forum']))
foreach($vbseo_gcache['forum'] as $forumid=>$finfo)
if($finfo['forumread'])
unset($vbseo_gcache['forum'][$forumid]['forumread']);
$vbseo_cache->cacheset('forum', $vbseo_gcache['forum']);
}
vbseo_prepare_cat_anchors();
if (isset($id)) return $vbseo_gcache['forum'][$id];
return $vbseo_gcache['forum'];
}
function vbseo_get_thread_details($postid)
{
$db = vbseo_get_db();
vbseo_int_var($postid);
return $db->vbseodb_query_first("SELECT p.pagetext,p.postid FROM " . vbseo_tbl_prefix('post') . " p
WHERE p.postid='$postid'
"
);
}
function vbseo_get_attachments_info($ids)
{
global $vbseo_gcache, $found_object_ids;
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
global $postattach;
if (is_array($postattach))
foreach($postattach as $pid => $attarr)
{
if (is_array($attarr))
foreach($attarr as $id => $arr)
{
$vbseo_gcache['attach'][$id] = $arr;
$found_object_ids['postthread_ids'][] = $arr['postid'];
}
}
$lookupids = array();
foreach($ids as $id)
if($id)
{
if (isset($vbseo_gcache['attach'][$id])) continue;
$vbseo_gcache['attach'][$id] = array();
$lookupids[] = $id;
}
if (empty($lookupids))return array();
vbseo_int_var($lookupids);
$db = vbseo_get_db();
$rid = $db->vbseodb_query($q = "
select at.attachmentid,at.filename,".(VBSEO_VB4 ? 'contenttypeid, contentid, caption' : 'at.postid')."
from " . vbseo_tbl_prefix('attachment') . " at
where
at.attachmentid IN (" . implode(',', $lookupids) . ")
");
if ($rid)
{
while ($att = @$db->funcs['fetch_assoc']($rid))
{
if($att['contenttypeid'] == 1)
$att['postid'] = $att['contentid'];
if($att['postid'])
$found_object_ids['postthread_ids'][] = $att['postid'];
$vbseo_gcache['attach'][$att['attachmentid']] = $att;
}
$db->vbseodb_free_result($rid);
}
return $vbseo_gcache['attach'];
}
function vbseo_get_thread_info($ids)
{
global $vbseo_gcache, $found_object_ids;
$haslastpostid = vbseo_vbversion()>='3.6';
$hasthreadprefixes = vbseo_vbversion()>='3.8';
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
$lookupids = array();
foreach($ids as $id)
if ($id)
{
if (isset($vbseo_gcache['thread'][$id]))
{
if(!VBSEO_URL_THREAD_PREFIX || $vbseo_gcache['thread'][$id]['prefixid'])
continue;
}else
{
$vbseo_gcache['thread'][$id] = array();
}
$lookupids[] = $id;
}
vbseo_int_var($lookupids);
if (!empty($lookupids))
{
$where = array('');
$db = vbseo_get_db();
$rid = $db->vbseodb_query(
"select t.forumid, t.threadid, " .
(VBSEO_GET_THREAD_TITLES ? 't.title, ' : '') .
((VBSEO_URL_THREAD_PREFIX && $hasthreadprefixes) ? 't.prefixid, ' : '') .
"t.replycount, t.lastposter, ".($haslastpostid?"firstpostid,lastpostid, ":"").
(VBSEO_LIKE_POST ? "vbseo_likes,":"").
"lastpost, visible
from " . vbseo_tbl_prefix('thread') . " t
where
t.threadid in (" . join(',', $lookupids) . ")
");
if ($rid)
{
while ($thread = @$db->funcs['fetch_assoc']($rid))
{
vbseo_thread_seotitle($thread);
$vbseo_gcache['thread'][$thread['threadid']] = $thread;
if ($found_object_ids['thread_last'] && in_array($thread['threadid'], $found_object_ids['thread_last']))
$found_object_ids['user_names'][] = $thread['lastposter'];
}
$db->vbseodb_free_result($rid);
}
}
$arr = array();
foreach($ids as $id)
$arr[$id] = $vbseo_gcache['thread'][$id];
return $arr;
}
function vbseo_get_posts_info($postids)
{
global $vbseo_gcache;
if (!$postids)return;
$db = vbseo_get_db();
vbseo_int_var($postids);
$preq = "select postid, threadid
from " . vbseo_tbl_prefix('post') . "
where postid in ('" . implode("','", array_unique($postids)) . "')";
$rid = $db->vbseodb_query($preq);
if ($rid)
{
while ($arr = @$db->funcs['fetch_assoc']($rid))
{
$vbseo_gcache['post'][$arr['postid']] = $arr;
}
$db->vbseodb_free_result($rid);
}
}
function vbseo_get_user_info($userids, $user_names = array())
{
global $vbseo_gcache;
$whr = $whr2 = '';
vbseo_int_var($userids);
if(!is_array($userids))
$userids = array($userids);
if (!empty($userids))
$whr .= "u.userid in ('" . implode("','", $userids) . "')";
if (!empty($user_names) && strstr(VBSEO_URL_MEMBER, '%user_id%'))
{
$unw = '';
foreach($user_names as $uind => $uname)
$unw .= ($unw?',':'') . "'" . str_replace("'", "\\'", str_replace("\\", "\\\\", $uname)) . "'";
$whr2 = "u.username in ($unw)";
}
if ($whr || $whr2)
{
$db = vbseo_get_db();
$preq = "select u.userid, u.username
from " . vbseo_tbl_prefix('user') . " u
where ";
if ($db->mysql_version[0] > '3')
$rid = $db->vbseodb_query(($whr?"( $preq $whr )":"") . (($whr && $whr2)?"\nUNION ":"") . ($whr2?"( $preq $whr2 )":""));
else
$rid = $db->vbseodb_query($preq . $whr . (($whr && $whr2) ? ' OR ' : '') . $whr2);
if ($rid)
{
while ($arr = @$db->funcs['fetch_assoc']($rid))
{
$vbseo_gcache['user'][$arr['userid']] =
$vbseo_gcache['usernm'][strtolower($arr['username'])] =
$arr;
}
$db->vbseodb_free_result($rid);
}
}
}
function vbseo_get_blog_info($ids, $buser = false, $comment = false)
{
global $vbseo_gcache;
if($comment)
{
$cvar = 'blog_text';
$idvar = 'blogtextid';
$buser = 'bloguserid';
$fields = "b.userid, b.username, b.blogtextid, b.blogid, b.state";
}else
{
$cvar = 'blog';
$idvar = 'blogid';
$buser = 'userid';
$fields = "b.userid, b.username, b.blogid, b.title, b.state";
}
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
$lookupids = array();
foreach($ids as $id)
if($id)
{
$id = intval($id);
if (isset($vbseo_gcache[$cvar][$id]) && isset($vbseo_gcache[$cvar][$id]['userid'])) continue;
$lookupids[$id]++;
}
if (!empty($lookupids))
{
$db = vbseo_get_db();
$db->vbseodb_select_db();
$rid = $db->vbseodb_query($q="
select $fields ".
((VBSEO_VB4 && $buser) ? ",bu.options_member":"")."
from " . vbseo_tbl_prefix($cvar) . " b ".
($buser ? "left join ".vbseo_tbl_prefix('blog_user')." as bu on bu.bloguserid=b.".$buser : "")."
where
".$idvar." in (" . join(',', array_keys($lookupids)) . ")
");
if ($rid)
{
while ($bl = @$db->funcs['fetch_assoc']($rid))
$vbseo_gcache[$cvar][$bl[$idvar]] = $bl;
$db->vbseodb_free_result($rid);
}
}
if(count($ids)==1)
return $vbseo_gcache[$cvar][$ids[0]];
else
return;
}
function vbseo_get_blogatt_info($ids)
{
global $vbseo_gcache;
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
$lookupids = array();
foreach($ids as $id)
if($id)
{
$id = intval($id);
if (isset($vbseo_gcache['battach'][$id])) continue;
$lookupids[$id]++;
}
if (empty($lookupids))
return;
$db = vbseo_get_db();
$db->vbseodb_select_db();
$rid = $db->vbseodb_query($q="
select attachmentid, blogid, userid, filename, dateline
from " . vbseo_tbl_prefix('blog_attachment') . "
where
attachmentid in (" . join(',', array_keys($lookupids)) . ")
");
if ($rid)
{
while ($bl = @$db->funcs['fetch_assoc']($rid))
$vbseo_gcache['battach'][$bl['attachmentid']] = $bl;
$db->vbseodb_free_result($rid);
}
return;
}
function vbseo_get_blog_cats($ids)
{
global $vbseo_gcache;
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
$lookupids = array();
foreach($ids as $id)
if($id)
{
$id = intval($id);
if (isset($vbseo_gcache['blogcat'][$id])) continue;
$lookupids[] = $id;
}
if (empty($lookupids))return array();
$db = vbseo_get_db();
$db->vbseodb_select_db();
$rid = $db->vbseodb_query("
select blogcategoryid, title, userid
from " . vbseo_tbl_prefix('blog_category') . "
where
blogcategoryid in (" . join(',', $lookupids) . ")
");
if ($rid)
{
while ($bl = @$db->funcs['fetch_assoc']($rid))
$vbseo_gcache['blogcat'][$bl['blogcategoryid']] = $bl;
$db->vbseodb_free_result($rid);
}
return;
}
function vbseo_get_group_info($ids)
{
global $vbseo_gcache;
if (!$ids) return array();
if (!is_array($ids)) $ids = array($ids);
$lookupids = array();
foreach($ids as $id)
if($id)
{
$id = intval($id);
if (isset($vbseo_gcache['groups'][$id])) continue;
$lookupids[] = $id;
}
if (empty($lookupids))return array();
$db = vbseo_get_db();
$db->vbseodb_select_db();
$rid = $db->vbseodb_query("
select groupid, name, visible, deleted
from " . vbseo_tbl_prefix('socialgroup') . "
where
groupid in (" . join(',', $lookupids) . ")
");
if ($rid)
{
while ($bl = @$db->funcs['fetch_assoc']($rid))
$vbseo_gcache['groups'][$bl['groupid']] = $bl;
$db->vbseodb_free_result($rid);
}
return;
}
function vbseo_get_object_info($otype, $ids = array())
{
global $vbseo_gcache, $found_object_ids;
if($ids)
$found_object_ids[$otype] = $ids;
vbseo_clean_object_ids($otype);
if (!$ids = $found_object_ids[$otype])
return;
if(is_array($vbseo_gcache[$otype]))
$ids = array_diff($ids, array_keys($vbseo_gcache[$otype]));
$lookupids = array();
foreach($ids as $id)
if($id)
{
$id = intval($id);
$lookupids[] = $id;
}
if (empty($lookupids))return array();
$db = vbseo_get_db();
$db->vbseodb_select_db();
switch($otype)
{
case 'groupsdis':
$q = "select d.discussionid as tyid, d.discussionid, d.groupid, gm.title, gm.gmid
from " . vbseo_tbl_prefix('discussion') . " d
left join " . vbseo_tbl_prefix('groupmessage') ." gm on gm.gmid = d.firstpostid
where d.discussionid in (" . join(',', $lookupids) . ")";
break;
case 'blogcp_ids':
$q = "select customblockid as tyid, userid, title
from " . vbseo_tbl_prefix('blog_custom_block') . "
where customblockid in (" . join(',', $lookupids) . ")";
break;
case 'album':
$q = "select albumid as tyid, albumid, userid, title
from " . vbseo_tbl_prefix('album') . "
where albumid in (" . join(',', $lookupids) . ")";
break;
case 'cmscont':
$q = "select n.nodeid as tyid, n.url, n.parentnode, n.contenttypeid, n.userid, n.setpublish,
n.publishdate, n.hidden, n.permissionsfrom, ni.title
from " . vbseo_tbl_prefix('cms_node') . " as n
left join " . vbseo_tbl_prefix('cms_nodeinfo') . " as ni on n.nodeid=ni.nodeid
where n.nodeid in (" . join(',', $lookupids) . ")";
break;
case 'cms_cat':
$q = "select categoryid as tyid, categoryid, parentnode, category
from " . vbseo_tbl_prefix('cms_category') . "
where categoryid in (" . join(',', $lookupids) . ")";
break;
case VBSEO_PIC_STORAGE:
if(VBSEO_VB4)
return vbseo_get_attachments_info($lookupids);
$q = "select p.pictureid as tyid, p.pictureid, ap.albumid, caption, extension
from " . vbseo_tbl_prefix('picture') . " p
join " . vbseo_tbl_prefix('albumpicture') . " ap on ap.pictureid=p.pictureid
where p.pictureid in (" . join(',', $lookupids) . ")";
break;
}
$rid = $db->vbseodb_query($q);
if ($rid)
{
while ($bl = @$db->funcs['fetch_assoc']($rid))
$vbseo_gcache[$otype][$bl['tyid']] = $bl;
$db->vbseodb_free_result($rid);
}
return;
}
function vbseo_extract_msg_postbits()
{
global $vbulletin;
$msg = '';
$pbits = $GLOBALS['postbits'];
if(!$pbits)
$pbits = vBSEO_Storage::get('cms_text');
if($pbits)
{
preg_match('#<!--\s*message\s*-->(.*?)<!--\s*/\s*message\s*-->#s', $pbits, $post_match);
if(!$post_match || (isset($vbulletin) && $vbulletin->gars) )
preg_match('#post_message_.*?\>(.*?)'.(VBSEO_VB4? '</blockquote>' : '</div>').'#s', $pbits, $post_match);
$msg = preg_replace('#<!--.*?-->#s', '', $msg);
$msg = str_replace('>Quote:<', '', $post_match[1]);
$msg = preg_replace('#<div>Originally Posted by.*?</div>#', '', $msg);
$msg = preg_replace('#<script.*?\>.*?</script>#is', '', $msg);
$msg = preg_replace('#(<.*?\>)+#s', ' ', $msg);
$msg = trim($msg);
}
return $msg;
}
?>
Revise this Paste