PHP Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # QuoteIt! 3.0 by Steve Cygan - steve@monkeycrap.com ||
|| # (Cap'n Steve on vbulletin.org) ||
|| # ---------------------------------------------------------------- # ||
|| # Based on the original QuoteIt! hack by magnus. "Submit Post" code ||
|| # based on an addon by CtrlAltDel. Location code based on code by ||
|| # Acido. You may release translations of this hack as long as the ||
|| # original credits are included. Otherwise, you not redistribute this||
|| # hack without permission from me. ||
|| # ||
|| # Dedicated to Matt Cygan ||
|| #################################################################### ||
\*======================================================================*/
// in case this is included from a function
global $vbulletin, $quoteitoptions, $quoteitpermissions, $permissions;
// merge the quote settings with the global options ($vbulletin->quote_settings will be undefined on other pages)
$mainsettings = @unserialize($vbulletin->quote_settings);
$mainsettings = is_array($mainsettings) ? $mainsettings : array();
// super-duper extra failsafe
if (!isset($vbulletin->languagecache['quoteit_settings'])) {
build_global_options();
}
$quoteitoptions = array_merge($mainsettings, unserialize($vbulletin->languagecache['quoteit_settings']));
// clean up quote_settings, but keep backwards compatabilty
$settings[1] =& $quoteitoptions['ratings'];
$settings[3] =& $quoteitoptions['moderatequotes'];
$settings[0] =& $quoteitoptions['showrandomquote'];
$settings[4] =& $quoteitoptions['numbertomoderate'];
$settings[2] =& $quoteitoptions['averagethreshold'];
$settings[7] =& $quoteitoptions['totalthreshold'];
$settings[5] =& $quoteitoptions['enablecontext'];
$quoteitpermissions = convert_bits_to_array($permissions['quoteitpermissions'], $vbulletin->bf_ugp_quoteitpermissions);
$quoteitpermissions['canmoderatequotes'] = ($quoteitpermissions['canapprovequotes'] OR $quoteitpermissions['candeleteownquotes'] OR $quoteitpermissions['candeleteotherquotes'] OR $quoteitpermissions['caneditownquotes'] OR $quoteitpermissions['caneditotherquotes']);
// global references for built-in functions
$vbulletin->options['quoteitoptions'] =& $quoteitoptions;
$vbulletin->options['quoteitpermissions'] =& $quoteitpermissions;
$show['quotecount'] =& $quoteitoptions['showquotecount'];
$stylevar['canaddquotes'] =& $quoteitpermissions['canaddquotes'];
// check guest permissions
$quoteitoptions['enableguestvoting'] = $permissions['quoteitpermissions'] & $vbulletin->usergroupcache[1]['canratequotes'];
// just to make sure the template conditionals work properly
$sidebar = false;
$bbcode = false;
$globalcounter = 0;
/**
* Parses context using only the default ([post]) bbcode
*
* @param string Context with bbcode.
*
* @return string Context with HTML, ready for display.
*/
function parse_quote_context(&$text) {
global $vbulletin, $quoteitoptions;
static $parser;
static $tag_list = array('option' => array('post' => array(
'callback' => 'handle_bbcode_post',
'strip_empty' => true
)));
require_once(DIR . '/includes/class_bbcode.php');
if (!is_object($parser)) {
$parser =& new vB_BbCodeParser($vbulletin, $tag_list);
}
$text = $parser->do_parse($text, $quoteitoptions['allowhtml'], $quoteitoptions['allowsmilies'], $quoteitoptions['allowbbcode'], $quoteitoptions['allowimages'], $quoteitoptions['allowlinebreaks'], false);
return $text;
}
/**
* Parses quote text to be inserted into a template. TODO: make this work on bbcode and random quotes
*
* @param string Quote text with bbcode.
* @param string The type: quote, author, or context
*
* @return string Quote with HTML, ready for display.
*/
function parse_quote($text, $type = 'quote') {
global $vbulletin, $quoteitoptions;
static $tag_list, $parser;
require_once(DIR . '/includes/class_bbcode.php');
// at least allow [post] tags so submitting a post works with context
if ($type == 'context' AND !$quoteitoptions['allowbbcode']) {
return parse_quote_context($text);
}
if (!is_array($tag_list)) {
$tag_list = fetch_tag_list();
// quotes cause layout problems
unset($tag_list['no_option']['quote']);
unset($tag_list['option']['quote']);
}
if (!is_object($parser)) {
$parser =& new vB_BbCodeParser($vbulletin, $tag_list);
}
$text = $parser->do_parse($text, $quoteitoptions['allowhtml'], $quoteitoptions['allowsmilies'], $quoteitoptions['allowbbcode'], $quoteitoptions['allowimages'], $quoteitoptions['allowlinebreaks'], false);
return $text;
}
/**
* Adds a new quote to the database, taking care of permissions, escaping, etc.
*
* @param string Quote text
* @param string Quote author
* @param string Quote context
* @param integer Userid of the submitter
* @param integer Category ID
* @param integer Post ID it was submitted from
*
*/
function add_quote($quote, $author, $context = '', $userid = 1, $category = 'NULL', $postid = 'NULL') {
global $vbulletin, $quoteitpermissions, $quoteitoptions;
if (!$quoteitpermissions['canaddquotes']) {
print_quote_no_permission();
}
if ((empty($author) AND $quoteitoptions['requireauthor']) OR empty($quote)) {
eval(standard_error(fetch_error('requiredfields')));
}
($hook = vBulletinHook::fetch_hook('quoteit_add_quote')) ? eval($hook) : false;
// optional fields
$approved = $quoteitoptions['moderatequotes'] ? 0 : 1;
$context = $quoteitoptions['enablecontext'] ? '"' . $vbulletin->db->escape_string(trim($context)) . '"' : 'NULL';
// clean up extra quotes and spaces
$author = $vbulletin->db->escape_string(preg_replace('/"$/', '', preg_replace('/^"/', '', trim($author))));
$quote = $vbulletin->db->escape_string(preg_replace('/"$/', '', preg_replace('/^"/', '', trim($quote))));
$userid = intval($userid);
$category = preg_match('/^(\d+|NULL)$/', $category) ? $category : 'NULL';
$vbulletin->db->query_write('
INSERT INTO ' . TABLE_PREFIX . 'quotes
(quote, author, userid, approved, categoryid, ' . ($quoteitoptions['enablecontext'] ? 'context, ' : '') . 'date, postid) VALUES
("' . $quote . '", "' . $author . '", ' . $userid . ', ' . $approved . ', ' . $category . ', ' . ($quoteitoptions['enablecontext'] ? $context . ', ' : '') . TIMENOW . ', ' . $postid . ')
');
if ($userid) {
// update the number of quotes submitted
$vbulletin->db->shutdown_query('
UPDATE ' . TABLE_PREFIX . 'user SET
quotes = quotes + 1
WHERE userid = ' . $userid
);
}
// if this is the first quote added, it's not a fresh install anymore (yes, I know it's ugly)
if ($quoteitoptions['freshinstall']) {
$globaloptions = unserialize($vbulletin->languagecache['quoteit_settings']);
$globaloptions['freshinstall'] = 0;
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'datastore SET
data = "' . $vbulletin->db->escape_string(serialize($globaloptions)) . '"
WHERE title = "languagecache"
');
}
}
/**
* Updates an existing quote, taking care of permissions, escaping, etc.
*
* @param string Id of the quote
* @param string Quote text
* @param string Quote author
* @param string Quote context
* @param integer Category ID
* @param integer Approval status
*
*/
function update_quote($quoteid, $quote, $author, $context = '', $category = 'NULL', $approved = 1) {
global $vbulletin, $quoteitoptions, $quoteitpermissions, $vbphrase, $permissions;
$quoteid = intval($quoteid);
$approved = intval($approved);
$category = preg_match('/^(\d+|NULL)$/', $category) ? $category : 'NULL';
$oldquote = $vbulletin->db->query_first('
SELECT quotes.*, user.username AS username FROM ' . TABLE_PREFIX . 'quotes AS quotes
LEFT JOIN ' . TABLE_PREFIX . 'user AS user on user.userid = quotes.userid
WHERE quotes.quoteid = ' . $quoteid
);
// check quote ownership for permissions
if ($vbulletin->userinfo['userid'] == $oldquote['userid'] AND !$quoteitpermissions['caneditownquotes']) {
print_quote_no_permission();
}
else if ($vbulletin->userinfo['userid'] != $oldquote['userid'] AND !$quoteitpermissions['caneditotherquotes']) {
print_quote_no_permission();
}
($hook = vBulletinHook::fetch_hook('quoteit_update_quote')) ? eval($hook) : false;
if ((empty($author) AND $quoteitoptions['requireauthor']) OR empty($quote)) {
eval(standard_error(fetch_error('requiredfields')));
}
if ($quoteitoptions['enablecontext']) {
$context = 'context = "' . $vbulletin->db->escape_string(trim($context)) . '",';
}
elseif (!is_really_set($context)) {
$context = 'context = NULL,';
}
$author = $vbulletin->db->escape_string(trim($author));
$quote = $vbulletin->db->escape_string(trim($quote));
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'quotes SET
quote = "' . $quote . '",
author = "' . $author . '",
' . $context . '
approved = ' . $approved . ',
categoryid = ' . $category . '
WHERE quoteid = ' . $quoteid
);
DEVDEBUG('Updated quote #' . $quoteid);
// PM notification on approval
if ($approved AND $vbulletin->userinfo['quotepmnotify']) {
if ($approved) {
$quoteaction = $vbphrase['approved'];
$quotelink = '[url=' . $vbulletin->options['bburl'] . '/quotes.php?' . $vbulletin->session->vars['sessionurl'] . 'do=view"eid=' . $quoteid . ']#' . $quoteid . '[/url]';
}
else {
$quoteaction = $vbphrase['updated'];
$quotelink = '#' . $quoteid;
}
$pm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pm->set('fromuserid', $vbulletin->userinfo['userid']);
$pm->set('fromusername', $vbulletin->userinfo['username']);
$pm->set('title', $vbphrase['your_quote_has_been_moderated']);
$pm->set('message', construct_phrase($vbphrase['your_quote_x_has_been_y'], $quotelink, $quoteaction));
$pm->set_recipients($oldquote['username'], $permissions);
$pm->set('dateline', TIMENOW);
//$pm->set('showsmilie', 0);
if (count($pm->errors) > 0) {
DEVDEBUG('Error(s) sending PM: ' . implode(', ', $pm->errors));
}
else {
$pm->save();
}
}
}
/**
* Sets up the [quotes] and [randomquote] BBCodes
*
* @param array Reference to the tag list
*
*/
function init_quoteit_bbcode(&$tag_list) {
global $quoteitoptions, $sidebar;
if ($quoteitoptions['enablebbcode'] AND THIS_SCRIPT != 'quotes' AND !defined('THIS_IS_A_QUOTE')) {
$tag_list['no_option']['quotes'] = array(
'callback' => 'handle_external',
'strip_empty' => true,
'stop_parse' => false,
'disable_smilies' => true,
'disable_wordwrap' => true,
'strip_space_after' => 1,
'external_callback' => 'handle_bbcode_quotes'
);
$tag_list['no_option']['randomquote'] = array(
'callback' => 'handle_external',
'strip_empty' => false,
'stop_parse' => false,
'disable_smilies' => true,
'disable_wordwrap' => true,
'strip_space_after' => 1,
'external_callback' => 'handle_bbcode_randomquote'
);
define('QUOTE_BBCODE_ID', TIMENOW);
}
}
/**
* Handles the [quote]$quoteid[/quote] tags.
*
* @param object A reference to this BB code parser
* @param integer The quoteid
* @param null The nonexistent option
*
* @return string Placeholder for the quote
*/
function handle_bbcode_quotes(&$parser, $quoteid, $option = null) {
global $vbulletin, $quotebbcodeids, $bgclass, $quotebbcodeclasses, $quoteitoptions, $numberofquotes;
$globalcounter = 0;
if (!is_numeric(trim($quoteid))) {
return '[quotes]' . $quoteid . '[/quotes]';
}
if (!isset($quotebbcodeids)) {
$quotebbcodeids = array();
}
if (!$quoteitoptions['cachebbcode']) {
$parser->options['cachable'] = false;
}
$quoteid = intval($quoteid);
if (!isset($numberofquotes[$quoteid])) {
$numberofquotes[$quoteid] = 1;
}
else {
$numberofquotes[$quoteid]++;
}
$quotebbcodeids[] = $quoteid;
$quotebbcodeclasses[$quoteid] = $bgclass;
return '{Q' . QUOTE_BBCODE_ID . ':' . $quoteid . '}';
}
/**
* Handles the tags.
*
* @param object A reference to this BB code parser
* @param null Just here for compatibility
* @param null The nonexistent option
*
* @return string Placeholder for the quote
*/
function handle_bbcode_randomquote(&$parser, $nothing = null, $option = null) {
global $vbulletin, $randomquotes, $postswithquotes, $bgclass, $post, $quotebbcodeclasses, $quoteitoptions;
if (!$quoteitoptions['cachebbcode']) {
$parser->options['cachable'] = false;
}
// I don't remember why this starts at -1, but let's keep it
if (!isset($randomquotes)) {
$randomquotes = -1;
}
$randomquotes++;
$quotebbcodeclasses['R' . $randomquotes] = $bgclass;
return '{R' . QUOTE_BBCODE_ID . ':' . $randomquotes . '}';
}
/**
* Performs queries and replaces the placeholders with actual quotes.
*
* @param object A reference to the variable containing all the posts
* @param bool Whether this is being called from the AJAX quick reply or not
*
*/
function finalize_quoteit_bbcode(&$postbits, $ajax = false) {
global $vbulletin, $headinclude, $randomquotes, $quotebbcodeids, $quotebbcodeclasses, $stylevar, $vbphrase, $quoteitoptions, $quoteitpermissions, $numberofquotes, $globalcounter;
$quotecount = 0;
($hook = vBulletinHook::fetch_hook('quoteit_bbcode_begin')) ? eval($hook) : false;
if (is_array($quotebbcodeids)) {
$bbcode = true;
if ($quoteitoptions['ratings'] AND !$storable AND $quoteitoptions['usemegaquery'] AND !$quoteitoptions['cachebbcode']) {
if ($vbulletin->userinfo['userid']) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'quoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.userid = ' . $vbulletin->userinfo['userid'];
}
else if (get_decent_ip()) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'guestquoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"';
}
}
$results = $vbulletin->db->query_read('
SELECT quotes.*, categories.title AS category, ' . ($ratingsjoin ? 'ratings.rating AS yourvote, ' : '') . 'users.username FROM ' . TABLE_PREFIX . 'quotes AS quotes
LEFT JOIN ' . TABLE_PREFIX . 'user AS users ON quotes.userid = users.userid
LEFT JOIN ' . TABLE_PREFIX . 'quotecategories AS categories ON categories.categoryid = quotes.categoryid
' . $ratingsjoin . '
WHERE quotes.quoteid IN (' . implode(', ', $quotebbcodeids) . ')
');
while ($quote = $vbulletin->db->fetch_array($results)) {
if (!isset($globalcounters[$quote['quoteid']])) {
$globalcounters[$quote['quoteid']] = 0;
}
$globalcounter =& $globalcounters[$quote['quoteid']];
// avoid quotes within quotes
if (!defined('THIS_IS_A_QUOTE')) {
define('THIS_IS_A_QUOTE', true);
}
// hide unapproved quotes
if (!$quote['approved'] AND (!$quoteitpermissions['canapprovequotes'] OR !$quoteitoptions['showunapproved'])) {
$postbits = str_replace('{Q' . QUOTE_BBCODE_ID . ':' . $quote['quoteid'] . '}', '', $postbits);
continue;
}
if ($quoteitoptions['ratings'] AND !is_really_set($quote['yourvote']) AND !$quoteitoptions['cachebbcode']) {
if ($vbulletin->userinfo['userid']) {
$ratings = $vbulletin->db->query_first('
SELECT rating AS yourvote FROM ' . TABLE_PREFIX . 'quoteratings
WHERE quoteid = ' . $quote['quoteid'] . ' AND userid = ' . $vbulletin->userinfo['userid']
);
$quote['yourvote'] = $ratings['yourvote'];
}
else if (get_decent_ip()) {
$ratings = $vbulletin->db->query_first('
SELECT rating AS yourvote FROM ' . TABLE_PREFIX . 'guestquoteratings
WHERE quoteid = ' . $quote['quoteid'] . ' AND ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"
');
$quote['yourvote'] = $ratings['yourvote'];
}
}
($hook = vBulletinHook::fetch_hook('quoteit_list_quote')) ? eval($hook) : false;
$quote['quote'] = parse_quote($quote['quote']);
$quote['author'] = !empty($quote['author']) ? parse_quote($quote['author'], 'author') : '';
$quote['context'] = ($quoteitoptions['enablecontext'] AND !empty($quote['context'])) ? parse_quote($quote['context'], 'context') : '';
$quote['date'] = vbdate($vbulletin->options['dateformat'], $quote['date'], true);
$quotedisplayid =& $quote['quoteid'];
if ($quote['userid'] == 0) {
$quote['username'] = $vbphrase['guest'];
}
else if (empty($quote['username'])) {
$quote['username'] = $vbphrase['unknown'];
}
// take care of duplicate quotes (no conflicting ids, etc.)
$i = 1;
while ($i <= $numberofquotes[$quote['quoteid']]) {
$quoteclass = isset($quotebbcodeclasses[$quote['quoteid']]) ? $quotebbcodeclasses[$quote['quoteid']] : 'alt2';
unset($quotebbcodeclasses[$quote['quoteid']]);
$ids[] = $quote['quoteid'];
if (!is_really_set($quote['yourvote']) AND $quoteitoptions['ratings'] AND $quoteitpermissions['canratequotes'] AND !$quoteitoptions['cachebbcode']) {
if ($quoteitoptions['ratings'] == 1) {
eval('$ratethis = "' . fetch_template('quote_rating1') . '";');
}
else if ($quoteitoptions['ratings'] == 2) {
eval('$ratethis = "' . fetch_template('quote_rating5') . '";');
}
}
else if ($quoteitoptions['ratings'] AND is_really_set($quote['yourvote']) AND !$quoteitoptions['cachebbcode']) {
$ratethis = $vbphrase['you_rated_this_quote'] . $quote['yourvote'];
}
else {
$ratethis = '';
}
eval('$quotelistbit = "' . fetch_template('quote_listbit') . '";');
eval('$parsedbbcode = "' . fetch_template('quote_bbcode') . '";');
$postbits = preg_replace('/{Q' . QUOTE_BBCODE_ID . ':' . $quote['quoteid'] . '}/', $parsedbbcode, $postbits, 1);
$quotecount++;
$globalcounters[$quote['quoteid']]++;
$i++;
}
}
$vbulletin->db->free_result($results);
// take care of nonexistent quotes
foreach ($quotebbcodeclasses AS $quoteid => $class) {
if (substr($quoteid, 0, 1) != 'R') {
$postbits = str_replace('{Q' . QUOTE_BBCODE_ID . ':' . $quoteid . '}', '[quotes]' . $quoteid . '[/quotes]', $postbits);
}
}
}
if ($randomquotes > -1) {
$bbcode = true;
$randomquote = true;
$i = 0;
if ($quoteitoptions['ratings'] AND !$storable AND $quoteitoptions['usemegaquery'] AND !$quoteitoptions['cachebbcode']) {
if ($vbulletin->userinfo['userid']) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'quoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.userid = ' . $vbulletin->userinfo['userid'];
}
else if (get_decent_ip()) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'guestquoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"';
}
}
// we can't do proper randomization as it would require queries for each quote :(
$results = $vbulletin->db->query_read('
SELECT RAND() AS random, quotes.*, categories.title AS category, ' . ($ratingsjoin ? 'ratings.rating AS yourvote, ' : '') . 'users.username FROM ' . TABLE_PREFIX . 'quotes AS quotes
LEFT JOIN ' . TABLE_PREFIX . 'user AS users ON quotes.userid = users.userid
LEFT JOIN ' . TABLE_PREFIX . 'quotecategories AS categories ON categories.categoryid = quotes.categoryid
' . $ratingsjoin . ($quoteitoptions['showunapproved'] AND $quotitpermissions['canapprovequotes'] ? '' : ' WHERE quotes.approved = 1') . '
ORDER BY random LIMIT ' . ($randomquotes + 1)
);
while ($quote = $vbulletin->db->fetch_array($results)) {
if (!isset($globalcounters[$quote['quoteid']])) {
$globalcounters[$quote['quoteid']] = 0;
}
$globalcounter =& $globalcounters[$quote['quoteid']];
// avoid quotes within quotes
if (!defined('THIS_IS_A_QUOTE')) {
define('THIS_IS_A_QUOTE', true);
}
if ($quoteitoptions['ratings'] AND !is_really_set($quote['yourvote']) AND !$quoteitoptions['cachebbcode']) {
if ($vbulletin->userinfo['userid']) {
$ratings = $vbulletin->db->query_first('
SELECT rating AS yourvote FROM ' . TABLE_PREFIX . 'quoteratings
WHERE quoteid = ' . $quote['quoteid'] . ' AND userid = ' . $vbulletin->userinfo['userid']
);
$quote['yourvote'] = $ratings['yourvote'];
}
else if (get_decent_ip() AND !$quoteitoptions['cachebbcode']) {
$ratings = $vbulletin->db->query_first('
SELECT rating AS yourvote FROM ' . TABLE_PREFIX . 'guestquoteratings
WHERE quoteid = ' . $quote['quoteid'] . ' AND ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"
');
$quote['yourvote'] = $ratings['yourvote'];
}
}
($hook = vBulletinHook::fetch_hook('quoteit_list_quote')) ? eval($hook) : false;
$quote['quote'] = parse_quote($quote['quote']);
$quote['author'] = !empty($quote['author']) ? parse_quote($quote['author'], 'author') : '';
$quote['context'] = ($quoteitoptions['enablecontext'] AND !empty($quote['context'])) ? parse_quote($quote['context'], 'context') : ''; $quote['date'] = vbdate($vbulletin->options['dateformat'], $quote['date'], true);
$quotedisplayid =& $quote['quoteid'];
if ($quote['userid'] == 0) {
$quote['username'] = $vbphrase['guest'];
}
else if (empty($quote['username'])) {
$quote['username'] = $vbphrase['unknown'];
}
$quoteclass = isset($quotebbcodeclasses['R' . $i]) ? $quotebbcodeclasses['R' . $i] : 'alt2';
$ids[] = $quote['quoteid'];
if (!is_really_set($quote['yourvote']) AND $quoteitoptions['ratings'] AND $quoteitpermissions['canratequotes'] AND !$quoteitoptions['cachebbcode']) {
if ($quoteitoptions['ratings'] == 1) {
eval('$ratethis = "' . fetch_template('quote_rating1') . '";');
}
else if ($quoteitoptions['ratings'] == 2) {
eval('$ratethis = "' . fetch_template('quote_rating5') . '";');
}
}
else if ($quoteitoptions['ratings'] AND is_really_set($quote['yourvote']) AND !$quoteitoptions['cachebbcode']) {
$ratethis = $vbphrase['you_rated_this_quote'] . $quote['yourvote'];
}
else {
$ratethis = '';
}
// continue if there aren't enough quotes to fill in all the bbcode
$totalreturned = $vbulletin->db->num_rows($results);
if ($totalreturned < $randomquotes) {
if ($i == $totalreturned - 1) {
// replace all remaining random quotes
$totalreplaced = preg_match_all('/\{R' . QUOTE_BBCODE_ID . ':\d+\}/', $postbits, $nomatchesplease);
}
else {
$totalreplaced = floor($randomquotes / $totalreturned);
}
}
else {
$totalreplaced = 1;
$replacenumber = $i;
}
eval('$quotelistbit = "' . fetch_template('quote_listbit') . '";');
eval('$parsedbbcode = "' . fetch_template('quote_bbcode') . '";');
$x = 0;
while ($x < $totalreplaced) {
$replacenumber = $x + $i;
$postbits = str_replace('{R' . QUOTE_BBCODE_ID . ':' . $replacenumber . '}', $parsedbbcode, $postbits);
$x++;
}
$i++;
$quotecount++;
$globalcounters[$quote['quoteid']]++;
unset($replacenumber);
}
$vbulletin->db->free_result($results);
}
if ($bbcode) {
$headinclude .= get_js_quote_phrases() . '<script type="text/javascript" src="clientscript/quoteit_bbcode.js"></script>';
$headinclude .= '<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="clientscript/vbulletin_css/quoteit_ie_lt7.css" />
<style type="text/css">
.openquote {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src="' . $stylevar['imgdir_misc'] . '/quotation-open.png", sizingMethod="image");
}
.closequote {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src="' . $stylevar['imgdir_misc'] . '/quotation-close.png", sizingMethod="image");
}
</style>
<![endif]-->
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="clientscript/vbulletin_css/quoteit_ie_all.css" />
<![endif]-->';
$headinclude .= '<link rel="stylesheet" type="text/css" href="clientscript/vbulletin_css/quoteit_main.css" />';
$headinclude .= ($quoteitoptions['ratings'] OR $quoteitpermissions['canmoderatequotes'] OR $quoteitoptions['enablecategories'] OR $quoteitpermissions['canreportquotes']) ? '<script type="text/javascript" src="clientscript/quoteit_common.js"></script>' : '';
$headinclude .= ($quoteitoptions['ratings'] AND $quoteitpermissions['canratequotes']) ? '<script type="text/javascript" src="clientscript/quoteit_voting.js"></script>' : '';
$headinclude .= $quoteitpermissions['canmoderatequotes'] ? '<script type="text/javascript" src="clientscript/quoteit_moderation.js"></script>' : '';
$vbulletin->db->shutdown_query('
UPDATE ' . TABLE_PREFIX . 'quotes SET
views = views + 1
WHERE quoteid IN (' . implode(', ', $ids) . ')
');
$numberofquotes = is_array($numberofquotes) ? $numberofquotes : array();
DEVDEBUG('BBCode quotes finished. ' . (array_sum($numberofquotes) + $randomquotes + 1) . ' total, ' . (count($numberofquotes) + $randomquotes + 1). ' (probably) unique.');
}
($hook = vBulletinHook::fetch_hook('quoteit_bbcode_end')) ? eval($hook) : false;
}
/**
* Rebuilds the ratings in the quotes table based on the quoteratings table.
*
* @param integer The offset where the rebuilding left off
* @param integer The number of quotes to update per page
*
*/
function rebuild_quote_ratings($offset = 0, $limit = 50) {
global $vbulletin, $vbphrase;
$offset = intval($offset);
$limit = intval($limit);
DEVDEBUG('Rebuilding ' . $limit . ' quotes starting at quote ' . $offset);
$counter = $vbulletin->db->query_read('
SELECT quoteid, SUM(rating) AS total FROM ' . TABLE_PREFIX . 'quoteratings
GROUP BY quoteid ORDER BY quoteid ASC
LIMIT ' . $offset . ', ' . $limit
);
$total = $vbulletin->db->num_rows($counter);
if ($total == 0) {
print_cp_message($vbphrase['done'], 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=util', 3);
}
if ($total < $limit) {
$lastdone = $total + $offset;
$next = $vbphrase['done'];
$redirect = 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=util';
}
else {
$lastdone = $limit + $offset;
$next = construct_phrase($vbphrase['continuing_next_x'], $limit);
$redirect = 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=rebuildratings&offset=' . ($offset + $limit) . '&limit=' . $limit;
}
while ($total = $vbulletin->db->fetch_array($counter)) {
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'quotes SET
rating = ' . $total['total'] . ',
average = rating / votes
WHERE quoteid = ' . $total['quoteid']
);
}
$vbulletin->db->free_result($counter);
print_cp_message(construct_phrase($vbphrase['quotes_x_rebuilt_next_y'], $vbphrase['quotes'], ($offset + 1) . '-' . $lastdone, $next), $redirect, 3);
}
/**
* Gets a random quote
*
* @param bool Whether this quote is to be stored
*
* @return array An array containing all the quote information
*
*/
function randomize_quote($storable = false) {
global $vbulletin, $quoteitpermissions, $quoteitoptions, $vbphrase, $globalcounter, $quoteitdebug, $quotesfetched;
if (is_really_set($quoteitoptions['averagethreshold'])) {
$threshold[] = 'quotes.average >= ' . floatval($quoteitoptions['averagethreshold']) . ' ';
}
if (is_really_set($quoteitoptions['totalthreshold'])) {
$threshold[] = 'quotes.rating >= ' . intval($quoteitoptions['totalthreshold']) . ' ';
}
if (is_really_set($quoteitoptions['randomcategory']) AND $quoteitoptions['randomcategory'] != 'all') {
$threshold[] = 'quotes.categoryid = ' . $quoteitoptions['randomcategory'];
}
// hardcode the approved status in case it's being stored
if ($quoteitpermissions['canapprovequotes'] AND $quoteitoptions['showunapproved'] AND !$storable) {
$threshold[] = 'quotes.approved = 1';
}
$threshold = is_array($threshold) ? 'WHERE ' . implode(' AND ', $threshold) : '';
($hook = vBulletinHook::fetch_hook('quoteit_randomize_quote')) ? eval($hook) : false;
$count = $vbulletin->db->query_first('
SELECT COUNT(*) AS count FROM ' . TABLE_PREFIX . 'quotes AS quotes
' . $threshold
);
$quoteitdebug .= 'Threshold: ' . $threshold . "\n";
// workaround if no quotes exist
// $quoteitoptions['freshinstall'] is unreliable
if ($count['count'] == 0) {
$all = $vbulletin->db->query_first('
SELECT COUNT(*) AS quotes FROM ' . TABLE_PREFIX . 'quotes
' . ((!$quoteitoptions['showunapproved'] OR !$quoteitpermissions['canapprovequotes']) ? 'WHERE approved = 1' : '')
);
$quoteitdebug .= 'Total possible quotes: ' . $all['quotes'] . "\n";
if ($all['quotes'] < 1) {
$quote['quote'] = '<h3 id="quoteerror"><a href="quotes.php?' . $vbulletin->session->vars['sessionurl'] . 'do=addquote">' . $vbphrase['add_a_quote'] . '</a></h3>';
}
else {
$quote['quote'] = '<h3 id="quoteerror">' . $vbphrase['no_quotes_matched'] . '</h3>';
}
}
else {
if ($quoteitoptions['ratings'] AND !$storable AND $quoteitoptions['usemegaquery']) {
if ($vbulletin->userinfo['userid']) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'quoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.userid = ' . $vbulletin->userinfo['userid'];
}
else if (get_decent_ip()) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'guestquoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"';
}
}
$row = vbrand(0, $count['count'] - 1);
$quote = $vbulletin->db->query_first('
SELECT quotes.*, categories.title AS category, ' . ($ratingsjoin ? 'ratings.rating AS yourvote, ' : '') . 'users.username FROM ' . TABLE_PREFIX . 'quotes AS quotes
LEFT JOIN ' . TABLE_PREFIX . 'user AS users ON quotes.userid = users.userid
LEFT JOIN ' . TABLE_PREFIX . 'quotecategories AS categories ON categories.categoryid = quotes.categoryid
' . $ratingsjoin . '
' . $threshold . ' LIMIT ' . $row . ', 1
');
$quotesfetched[] = $quote['quoteid'];
}
return $quote;
}
/**
* Gets a random quote for display on the forum home page
*
* @param bool Whether this quote is for a side (narrow) block or the center
*
* @return string The quote_randomquote template, ready for display
*
*/
function get_random_quote($sidebar = false) {
global $vbulletin, $headinclude, $quoteitpermissions, $quoteitoptions, $stylevar, $vbphrase, $vbcollapse, $globalcounter, $quoteitdebug, $quotesfetched;
static $quotecount = 0;
if (!$quoteitpermissions['canviewquotes']) {
return '';
}
// add the stylesheet, then see if we need either Javascript file
if (!defined('THIS_IS_A_QUOTE')) {
$path = (defined('VBA_PORTAL') OR defined('QUOTEIT_GLOBAL')) ? $vbulletin->options['bburl'] . '/' : '';
$tempinclude = get_js_quote_phrases() . '
<script type="text/javascript" src="' . $path . 'clientscript/quoteit_bbcode.js"></script>
';
$tempinclude .= '<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="' . $path . 'clientscript/vbulletin_css/quoteit_ie_lt7.css" />
<style type="text/css">
.openquote {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src="' . $path . $stylevar['imgdir_misc'] . '/quotation-open.png", sizingMethod="image");
}
.closequote {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src="' . $path . $stylevar['imgdir_misc'] . '/quotation-close.png", sizingMethod="image");
}
</style>
<![endif]-->
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="' . $path . 'clientscript/vbulletin_css/quoteit_ie_all.css" />
<![endif]-->';
$tempinclude .= '<link rel="stylesheet" type="text/css" href="' . $path . 'clientscript/vbulletin_css/quoteit_main.css" />';
$tempinclude .= ($quoteitoptions['ratings'] OR $quoteitpermissions['canmoderatequotes'] OR $quoteitoptions['enablecategories'] OR $quoteitpermissions['canreportquotes']) ? '<script type="text/javascript" src="' . $path . 'clientscript/quoteit_common.js"></script>' : '';
$tempinclude .= ($quoteitoptions['ratings'] AND $quoteitpermissions['canratequotes']) ? '<script type="text/javascript" src="' . $path . 'clientscript/quoteit_voting.js"></script>' : '';
$tempinclude .= $quoteitpermissions['canmoderatequotes'] ? '<script type="text/javascript" src="' . $path . 'clientscript/quoteit_moderation.js"></script>' : '';
// portal layout can't seem to coexist with forum layout
if (defined('VBA_PORTAL')) {
$tempinclude .= '<link rel="stylesheet" type="text/css" href="' . $path . 'clientscript/vbulletin_css/quoteit_vbadvanced.css" />';
}
}
// complete the sneakiness for vBadvanced and global quotes
if ($quotecount == 0 AND (defined('VBA_PORTAL') OR defined('QUOTEIT_GLOBAL'))) {
$templates = array('quote_listbit', 'quote_randomquote', 'quote_rating1', 'quote_rating5');
foreach ($templates AS $template) {
//$vbulletin->templatecache[$template] = str_replace('src=\"', 'src=\"' . $vbulletin->options['bburl'] . '/', $vbulletin->templatecache[$template]);
$vbulletin->templatecache[$template] = str_replace('quotes.php', $vbulletin->options['bburl'] . '/quotes.php', $vbulletin->templatecache[$template]);
$vbulletin->templatecache[$template] = str_replace('member.php', $vbulletin->options['bburl'] . '/member.php', $vbulletin->templatecache[$template]);
}
$tempinclude = str_replace('"', '\"', $tempinclude);
}
$headinclude .= $tempinclude;
// avoid quotes within quotes (and duplicate Javascript)
define('THIS_IS_A_QUOTE', true);
if ($quoteitoptions['randomquotefrequency'] != 'every') {
if (isset($quoteitoptions['lastquote'])) {
$quote = unserialize($quoteitoptions['lastquote']);
}
else {
$quote = randomize_quote(true);
$quoteitsettings = unserialize($vbulletin->languagecache['quoteit_settings']);
$quoteitsettings['lastquote'] = serialize($quote);
$vbulletin->languagecache['quoteit_settings'] = serialize($quoteitsettings);
build_datastore('languagecache', serialize($vbulletin->languagecache), 1);
}
}
else {
$quote = randomize_quote();
}
// in case two show up on the same page
if (is_array($quotesfetched) AND in_array($quote['quoteid'], $quotesfetched)) {
$globalcounter = normal_array_count_values($quote['quoteid'], $quotesfetched);
}
else {
$globalcounter = 0;
}
// workaround if no quotes exist
if (count($quote) == 1) {
return $quote['quote'];
}
$quotedisplayid =& $quote['quoteid'];
$quoteclass = 'alt1';
if ($quoteitoptions['ratings'] AND !is_really_set($quote['yourvote']) AND $quote['quoteid']) {
if ($vbulletin->userinfo['userid']) {
$ratings = $vbulletin->db->query_first('
SELECT rating AS yourvote FROM ' . TABLE_PREFIX . 'quoteratings
WHERE quoteid = ' . $quote['quoteid'] . ' AND userid = ' . $vbulletin->userinfo['userid']
);
$quote['yourvote'] = $ratings['yourvote'];
}
else if (get_decent_ip()) {
$ratings = $vbulletin->db->query_first('
SELECT rating AS yourvote FROM ' . TABLE_PREFIX . 'guestquoteratings
WHERE quoteid = ' . $quote['quoteid'] . ' AND ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"
');
$quote['yourvote'] = $ratings['yourvote'];
}
}
// handle quote parsing
$quote['quote'] = parse_quote($quote['quote']);
$quote['author'] = !empty($quote['author']) ? parse_quote($quote['author'], 'author') : '';
$quote['context'] = ($quoteitoptions['enablecontext'] AND !empty($quote['context'])) ? parse_quote($quote['context'], 'context') : '';
$quote['date'] = vbdate($vbulletin->options['dateformat'], $quote['date'], true);
if (!is_really_set($quote['yourvote']) AND $quoteitoptions['ratings'] AND $quoteitpermissions['canratequotes']) {
if ($quoteitoptions['ratings'] == 1) {
eval('$ratethis = "' . fetch_template('quote_rating1') . '";');
}
else if ($quoteitoptions['ratings'] == 2) {
eval('$ratethis = "' . fetch_template('quote_rating5') . '";');
}
}
else if ($quoteitoptions['ratings'] AND is_really_set($quote['yourvote'])) {
$ratethis = $vbphrase['you_rated_this_quote'] . $quote['yourvote'];
}
else {
$ratethis = '';
}
eval('$quotelistbit = "' . fetch_template('quote_listbit') . '";');
eval('$showrandomquote = "' . fetch_template('quote_randomquote') . '";');
if (!defined('QUOTE_FORM_ADDED')) {
define('QUOTE_FORM_ADDED', true);
}
$quotecount++;
return $showrandomquote;
}
/**
* Checks if a variable is set to something useful (allows 0, disallows blank)
*
* @return boolean Whether the variable is really set
*
*/
function is_really_set(&$variable) {
return (($variable !== '' AND $variable !== null) ? true : false);
}
/**
* Counts the how many times the value shows up in the array (the built-in one is weird)
*
* @param string What to search for
* @param array The array to be searched
*
* @return integer How many times the value was found
*
*/
function normal_array_count_values($item, $array) {
if (!is_array($array)) {
return 0;
}
$count = 0;
foreach ($array AS $key => $value) {
if ($value === $item) {
$count++;
}
}
return $count;
}
/**
* Checks if AJAX was used and sends the appropriate "no permission" message
*
*/
function print_quote_no_permission() {
// we need separate permissions checks for AJAX
if ($_REQUEST['ajax'] == 'y') {
header('Content-type: text/plain', true);
echo 'NoPermission';
}
else if (THIS_SCRIPT == 'quotemod' OR THIS_SCRIPT == 'quoteadmin') {
print_cp_no_permission();
}
else {
print_no_permission();
}
exit;
}
/**
* Generates the Javascript to pass some phrases along
*
* @param string Additional Javascript that needs to be added
*
* @return string <script> tags to be inserted in the head of the template
*
*/
function get_js_quote_phrases($extra = '') {
global $vbphrase, $quoteitoptions;
return '<script type="text/javascript">
<!--
var quoteIds;
var specialClasses;
var quotesPage = \'' . THIS_SCRIPT . '\';
var quotes_option_softdelete = ' . ($quoteitoptions['softdelete'] ? 'true' : 'false') . ';
var quotes_phrase_javascript_error = \'' . addslashes_js($vbphrase['ajax_error']) . '\';
var quotes_phrase_server_error = \'' . addslashes_js($vbphrase['ajax_server_error']) . '\';
var quotes_phrase_total = \'' . addslashes_js($vbphrase['total_rating']) . '\';
var quotes_phrase_average = \'' . addslashes_js($vbphrase['average']) . '\';
var quotes_phrase_votes = \'' . addslashes_js($vbphrase['votes']) . '\';
var quotes_phrase_you_rated_this = \'' . addslashes_js($vbphrase['you_rated_this_quote']) . '\';
var quotes_phrase_no_permission = \'' . addslashes_js($vbphrase['quotes_no_permission']) . '\';
var quotes_phrase_are_you_sure = \'' . addslashes_js($vbphrase['confirm_delete_quote']) . '\';
var quotes_phrase_no_quotes_matched = \'' . addslashes_js($vbphrase['no_quotes_matched']) . '\';
var quotes_phrase_successfully_deleted = \'' . addslashes_js($vbphrase['quote_deleted']) . '\';
var quotes_phrase_reporting_reason = \'' . addslashes_js($vbphrase['quote_reporting_reason']) . '\';
var quotes_phrase_save = \'' . addslashes_js($vbphrase['save']) . '\';
var quotes_phrase_cancel = \'' . addslashes_js($vbphrase['cancel']) . '\';
var quotes_phrase_go_advanced = \'' . addslashes_js($vbphrase['go_advanced']) . '\';
var quotes_phrase_go = \'' . addslashes_js($vbphrase['go']) . '\';' .
$extra . '
//-->
</script>';
}
/**
* Makes sure the pagination options passed in are valid
*
* @return array The page number and number of results per page
*
*/
function validate_pagination_settings() {
if ($_REQUEST['perpage'] < 1 OR $_REQUEST['perpage'] > 200 OR empty($_REQUEST['perpage'])) {
$perpage = 25;
}
else {
$perpage = intval($_REQUEST['perpage']);
}
if ($_REQUEST['pagenumber'] < 1 OR empty($_REQUEST['pagenumber'])) {
$pagenumber = 1;
}
else {
$pagenumber = intval($_REQUEST['pagenumber']);
}
return array($pagenumber, $perpage);
}
/**
* Takes the quote filtering options and compiles them into useable form
*
* @return mixed An array containing everything needed to display quote_listquote and actually query for quotes, or null if no quotes matched
*
*/
function build_quote_display_options() {
global $vbulletin, $quoteitoptions, $quoteitpermissions, $stylevar, $vbphrase, $quoteitdebug;
list($pagenumber, $perpage) = validate_pagination_settings();
($hook = vBulletinHook::fetch_hook('quoteit_build_options')) ? eval($hook) : false;
// handle searches
if ($quoteitpermissions['cansearchquotes']) {
if (!empty($_REQUEST['all'])) {
$search[] = '(quotes.quote LIKE "%' . $vbulletin->db->escape_string_like($_REQUEST['all']) . '%" OR quotes.author LIKE "%' . $vbulletin->db->escape_string_like($_REQUEST['all']) . '%"' . ($quoteitoptions['enablecontext'] ? ' OR quotes.context LIKE "%' . $vbulletin->db->escape_string_like($_REQUEST['all']) . '%")' : ')');
$querystring .= '&all=' . htmlspecialchars_uni($_REQUEST['all']);
$sneaky['all'] = htmlspecialchars_uni($_REQUEST['all']);
}
if (!empty($_REQUEST['searchtext'])) {
$search[] = 'quotes.quote LIKE "%' . $vbulletin->db->escape_string_like($_REQUEST['searchtext']) . '%"';
$querystring .= '&searchtext=' . htmlspecialchars_uni($_REQUEST['searchtext']);
$sneaky['searchtext'] = htmlspecialchars_uni($_REQUEST['searchtext']);
}
if (!empty($_REQUEST['searchauthor'])) {
if ($_REQUEST['exact'] == 'y') {
$search[] = 'quotes.author = "' . $vbulletin->db->escape_string($_REQUEST['author']) . '"';
$querystring .= '&exact=y';
}
else {
$search[] = 'quotes.author LIKE "%' . $vbulletin->db->escape_string_like($_REQUEST['searchauthor']) . '%"';
$querystring .= '&exact=n';
}
$querystring .= '&searchauthor=' . htmlspecialchars_uni($_REQUEST['searchauthor']);
$sneaky['searchauthor'] = htmlspecialchars_uni($_REQUEST['searchauthor']);
}
if (!empty($_REQUEST['searchcontext']) AND $quoteitoptions['enablecontext']) {
$search[] = 'quotes.context LIKE "%' . $vbulletin->db->escape_string_like($_REQUEST['searchcontext']) . '%"';
$querystring .= '&searchcontext=' . htmlspecialchars_uni($_REQUEST['searchcontext']);
$sneaky['searchcontext'] = htmlspecialchars_uni($_REQUEST['searchcontext']);
}
if (is_array($search)) {
$whereclause .= ' ' . implode(' AND ', $search);
}
}
// allow moderators to see unapproved quotes
$whereclause .= ($quoteitpermissions['canapprovequotes'] AND $quoteitoptions['showunapproved']) ? '' : ' AND quotes.approved = 1';
// handle sorting order
$orderof = array('username' => 'asc', 'quotes.quoteid' => 'asc', 'quotes.rating' => 'asc', 'quotes.author' => 'asc', 'quotes.average' => 'asc', 'quotes.quote' => 'asc');
$images = array('username' => $stylevar['imgdir_button'] . '/collapse_tcat.gif', 'quotes.quoteid' => $stylevar['imgdir_button'] . '/collapse_tcat.gif', 'quotes.rating' => $stylevar['imgdir_button'] . '/collapse_tcat.gif', 'quotes.author' => $stylevar['imgdir_button'] . '/collapse_tcat.gif', 'quotes.average' => $stylevar['imgdir_button'] . '/collapse_tcat.gif', 'quotes.quote' => $stylevar['imgdir_button'] . '/collapse_tcat.gif');
if ($_REQUEST['sortby'] == 'random') {
$order = 'RAND()';
}
else if ($_REQUEST['sortby'] == 'username' OR $_REQUEST['sortby'] == 'rating' OR $_REQUEST['sortby'] == 'author' OR $_REQUEST['sortby'] == 'quote' OR $_REQUEST['sortby'] == 'average') {
$order = $_REQUEST['sortby'] == 'username' ? 'username' : 'quotes.' . $_REQUEST['sortby'];
$orderstring = '&sortby=' . $_REQUEST['sortby'];
$sneaky['sortby'] = $_REQUEST['sortby'];
}
else {
$order = 'quotes.quoteid';
$orderstring = '&sortby=quoteid';
$sneaky['sortby'] = 'quoteid';
}
if ($_REQUEST['order'] == 'desc') {
$orderof[$order] = 'asc';
$order .= ' DESC';
$orderstring .= '&order=desc';
$sneaky['order'] = 'desc';
}
else {
$orderof[$order] = 'desc';
$order .= ' ASC';
$orderstring .= '&order=asc';
$sneaky['order'] = 'asc';
}
// generate the "sort by" row with appropriate images
foreach ($orderof AS $sortedby => $type) {
if ($type == 'asc') {
$images[$sortedby] = $stylevar['imgdir_button'] . '/collapse_tcat_collapsed.gif';
}
else {
$images[$sortedby] = $stylevar['imgdir_button'] . '/collapse_tcat.gif';
}
}
// generate an appropriate WHERE clause
if (is_really_set($_REQUEST['total'])) {
$total = intval($_REQUEST['total']);
$operator = preg_match('/^(<=?|>=?|=)$/', $_REQUEST['totaloperator']) ? $_REQUEST['totaloperator'] : '=';
$whereclause .= ' AND quotes.rating ' . $operator . ' ' . $total;
$querystring .= '&total=' . $total . '&totaloperator=' . $operator;
$values['total'] = $total;
$checked['total'][$operator] = ' selected="selected"';
}
if (is_really_set($_REQUEST['average'])) {
$average = floatval($_REQUEST['average']);
$operator = preg_match('/^(<=?|>=?|=)$/', $_REQUEST['averageoperator']) ? $_REQUEST['averageoperator'] : '=';
$whereclause .= ' AND quotes.average ' . $operator . ' ' . $average;
$querystring .= '&average=' . $average . '&averageoperator=' . $operator;
$values['average'] = $average;
$checked['average'][$operator] = ' selected="selected"';
}
if (is_really_set($_REQUEST['votes'])) {
$votes = intval($_REQUEST['votes']);
$operator = preg_match('/^(<=?|>=?|=)$/', $_REQUEST['votesoperator']) ? $_REQUEST['votesoperator'] : '=';
$whereclause .= ' AND quotes.votes ' . $operator . ' ' . $votes;
$querystring .= '&votes=' . $votes . '&votesoperator=' . $operator;
$values['votes'] = $votes;
$checked['votes'][$operator] = ' selected="selected"';
}
if (is_array($_REQUEST['category'])) {
foreach ($_REQUEST['category'] AS $categoryid) {
if ($categoryid != -1) {
$categories[] = intval($categoryid);
}
}
if (is_array($categories)) {
$whereclause .= ' AND quotes.categoryid IN (' . implode(', ', $categories) . ')';
$querystring .= '&category[]=' . implode('&category[]=', $categories);
}
}
// handle special viewing cases (new quotes, unrated quotes)
if ($_REQUEST['newquotes'] == 'y') {
$lastquotesvisit = ($quoteitoptions['saveascookie'] OR !$vbulletin->userinfo['userid']) ? intval($_COOKIE['lastquotesvisit']) : $vbulletin->userinfo['lastquotesvisit'];
// make sure they've actually visited before
$lastquotesvisit = is_numeric($lastquotesvisit) ? $lastquotesvisit : 0;
$whereclause .= ' AND quotes.date > ' . $lastquotesvisit;
$querystring .= '&date=' . $lastquotesvisit . '&dateorder=newer';
$checked['newquotes'] = ' checked="checked"';
}
else if (isset($_REQUEST['date'])) {
$lastquotesvisit = intval($_REQUEST['date']);
$dateop = $_REQUEST['dateorder'] == 'older' ? '<' : '>';
$whereclause .= ' AND quotes.date ' . $dateop . ' ' . $lastquotesvisit;
$querystring .= '&date=' . $lastquotesvisit . '&dateorder=' . ($_REQUEST['dateorder'] == 'older' ? 'older' : 'newer');
$checked['newquotes'] = ' checked="checked"';
}
// get only quotes that haven't been rated
if ($_REQUEST['unrated'] == 'y') {// AND $vbulletin->userinfo['userid']) {
$whereclause .= ' AND ratings.rating IS NULL';
$querystring .= '&unrated=y';
$checked['unrated'] = ' checked="checked"';
}
$whereclause = preg_replace('/^ AND /', '', $whereclause);
$whereclause = !empty($whereclause) ? 'WHERE ' . $whereclause : '';
if ($quoteitoptions['ratings'] AND $_REQUEST['unrated'] == 'y') {
if ($vbulletin->userinfo['userid']) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'quoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.userid = ' . $vbulletin->userinfo['userid'];
}
else if (get_decent_ip()) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'guestquoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"';
}
}
$quotecount = $vbulletin->db->query_first('
SELECT COUNT(*) AS quotes FROM ' . TABLE_PREFIX . 'quotes AS quotes
' . $ratingsjoin . '
' . $whereclause
);
// finish page dividing
$numberpages = ceil($quotecount['quotes'] / $perpage);
if (!isset($pagenumber) OR $pagenumber < 1 OR $pagenumber > $numberpages) {
$pagenumber = 1;
}
$quoteposition = ($pagenumber - 1) * $perpage;
if ($quotecount['quotes'] < 1) {
$all = $vbulletin->db->query_first('
SELECT COUNT(*) AS quotes FROM ' . TABLE_PREFIX . 'quotes
' . ((!$quoteitoptions['showunapproved'] OR !$quoteitpermissions['canapprovequotes']) ? 'WHERE approved = 1' : '')
);
$quoteitdebug .= 'Total possible quotes: ' . $all['quotes'] . "\n";
if ($all['quotes'] < 1) {
if ($_REQUEST['ajax'] == 'y') {
header('Content-type: text/plain', true);
echo 'NoQuotes';
}
else {
header('Location: ' . $vbulletin->options['bburl'] . '/quotes.php?' . $vbulletin->session->vars['sessionurl'] . 'do=addquote', true, 303);
}
exit;
}
else if (get_decent_referer(true)) {
$vbulletin->url = preg_replace('|^/|', '', get_decent_referer(true));
}
else {
$vbulletin->url = 'quotes.php?' . $vbulletin->session->vars['sessionurl'] . 'do=list';
}
eval(print_standard_redirect('no_quotes_matched', true, true));
}
$querystring .= '&perpage=' . $perpage;
$pagenav = construct_page_nav($pagenumber, $perpage, $quotecount['quotes'], 'quotes.php?' . $vbulletin->session->vars['sessionurl'] . $querystring . '&' . $orderstring);
// leading &s are ugly
$querystring = substr($querystring, 1);
DEVDEBUG('Query string = "' . $querystring . '"');
DEVDEBUG('Order string = "' . str_replace('&', '&', $orderstring) . '"');
DEVDEBUG('SQL where clause = "' . $whereclause . '"');
$querystring = htmlspecialchars_uni($querystring);
return array(
'querystring' => $querystring,
'orderstring' => $orderstring,
'whereclause' => $whereclause,
'perpage' => $perpage,
'orderof' => $orderof,
'images' => $images,
'pagenav' => $pagenav,
'position' => $quoteposition,
'order' => $order,
'checked' => $checked,
'values' => $values,
'sneaky' => $sneaky,
'page' => $pagenumber
);
}
/**
* Fetches the quick quote stats for display on the control panel home page
*
*/
function admincp_quote_stats() {
global $vbulletin, $quoteitoptions, $vbphrase;
if ($quoteitoptions['showquotestats']) {
$unapproved = $vbulletin->db->query_first('
SELECT COUNT(*) AS waiting FROM ' . TABLE_PREFIX . 'quotes
WHERE approved = 0
');
$total = $vbulletin->db->query_first('
SELECT COUNT(*) AS total FROM ' . TABLE_PREFIX . 'quotes
');
$quotes = $vbulletin->db->query_first('
SELECT COUNT(*) AS recent FROM ' . TABLE_PREFIX . 'quotes
WHERE date >= ' . (TIMENOW - 60 * 60 * 24)
);
print_table_start();
print_table_header($vbphrase['quoteit_stats'], 6);
print_cells_row(
array(
$vbphrase['quoteit_version'], $quoteitoptions['version'],
$vbphrase['number_of_quotes'], $total['total'],
$vbphrase['quotes_awaiting_moderation'], vb_number_format($unapproved['waiting']) . '<br /><a href="../' . $vbulletin->config['Misc']['modcpdir'] . '/quotemod.php?' . $vbulletin->session->vars['sessionurl'] . 'do=moderate">[' . $vbphrase['view'] . ']</a>'
), 0, 0, -5, 'top', 1, 1
);
print_cells_row(
array(
$vbphrase['quotes_today'], $quotes['recent'], ' ', ' ', ' ', ' '
), 0, 0, -5, 'top', 1, 1
);
($hook = vBulletinHook::fetch_hook('quoteit_admin_show_stats')) ? eval($hook) : false;
print_table_footer();
}
}
/**
* Fetches all quote categories that the user can see
*
* @param bool Whether to allow multiple selections (for viewing) or not (for adding)
* @param array The selected categories
* @param integer What to add to the id attribute (or null for nothing)
*
* @return string A <select> box containing all currently viewable categories
*
*/
function fetch_quote_categories($multiple = true, $selected = null, $unique = null) {
global $vbulletin, $quoteitoptions, $quoteitpermissions, $vbphrase;
$selected = $selected === null ? $_REQUEST['category'] : $selected;
if ($quoteitoptions['enablecategories']) {
$catlist = $vbulletin->db->query_read('
SELECT * FROM ' . TABLE_PREFIX . 'quotecategories
' . ($quoteitpermissions['canviewhiddencategories'] ? '' : 'WHERE public = 1') . '
ORDER BY displayorder ASC
');
$selected['category'] = is_array($selected) ? $selected : array();
while ($category = $vbulletin->db->fetch_array($catlist)) {
$quotecategories .= '<option onmouseover="showCatDescription(this);" onmouseout="hideCatDescription();" title="' . htmlspecialchars_uni($category['description']) . '" value="' . $category['categoryid'] . '"' . (in_array($category['categoryid'], $selected) ? ' selected="selected"' : '') . '>' . htmlspecialchars_uni($category['title']) . '</option>';
}
$vbulletin->db->free_result($catlist);
}
// sorry about all the ternary operators
if (!empty($quotecategories)) {
$quotecategories = '<select class="bginput" name="category[]" id="categories' . ($unique === null ? '' : $unique) . '"' . ($multiple ? ' multiple="multiple"' : '') . ' size="' . ($multiple ? 4 : 1) . '" onchange="manageCatList();">
' . ($multiple ? '<option value="-1"' . ((in_array(-1, $selected) OR count($selected) < 1) ? ' selected="selected"' : '') . '>' . $vbphrase['all_categories'] . '</option>
<option value=""> </option>' : '')
. $quotecategories .
'</select></label>';
}
return $quotecategories;
}
/**
* Gets the actual quotes and ratings
*
* @return array The $rated array and the final result set
*
*/
function get_quotes_list() {
global $vbulletin, $quoteitoptions, $quotedisplay, $quoteitdebug;
// the one query method doesn't work on some MySQL versions apparently :(
if ($quoteitoptions['usemegaquery']) {
if ($quoteitoptions['ratings']) {
if ($vbulletin->userinfo['userid']) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'quoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.userid = ' . $vbulletin->userinfo['userid'];
}
else if (get_decent_ip()) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'guestquoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"';
}
}
$result_quote = $vbulletin->db->query_read('
SELECT quotes.*, categories.title AS category, ' . ($ratingsjoin ? 'ratings.rating AS yourvote, ' : '') . 'user.username AS username FROM ' . TABLE_PREFIX . 'quotes AS quotes
' . $ratingsjoin . '
LEFT JOIN ' . TABLE_PREFIX . 'user AS user ON quotes.userid = user.userid
LEFT JOIN ' . TABLE_PREFIX . 'quotecategories AS categories ON categories.categoryid = quotes.categoryid
' . $quotedisplay['whereclause'] . '
ORDER BY ' . $quotedisplay['order'] . ' LIMIT ' . $quotedisplay['position'] . ', ' . $quotedisplay['perpage']
);
}
else {
// we still need the join if they want to view unrated quotes
if ($_REQUEST['unrated'] == 'y') {
if ($vbulletin->userinfo['userid']) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'quoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.userid = ' . $vbulletin->userinfo['userid'];
}
else if (get_decent_ip()) {
$ratingsjoin = 'LEFT JOIN ' . TABLE_PREFIX . 'guestquoteratings AS ratings ON quotes.quoteid = ratings.quoteid AND ratings.ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"';
}
}
$sql = $vbulletin->db->query_read('
SELECT quotes.quoteid FROM ' . TABLE_PREFIX . 'quotes AS quotes
LEFT JOIN ' . TABLE_PREFIX . 'user AS user ON quotes.userid = user.userid
' . $ratingsjoin . '
' . $quotedisplay['whereclause'] . '
ORDER BY ' . $quotedisplay['order'] . ' LIMIT ' . $quotedisplay['position'] . ', ' . $quotedisplay['perpage']
);
while ($tempids = $vbulletin->db->fetch_array($sql)) {
$prefetched[] = $tempids['quoteid'];
}
$vbulletin->db->free_result($sql);
$prefetched = is_array($prefetched) ? implode(', ', $prefetched) : null;
if ($quoteitoptions['ratings'] AND $prefetched) {
if ($vbulletin->userinfo['userid']) {
$sql = $vbulletin->db->query_read('
SELECT * FROM ' . TABLE_PREFIX . 'quoteratings
WHERE quoteid IN (' . $prefetched . ') AND userid = ' . $vbulletin->userinfo['userid']
);
}
else if (get_decent_ip()) {
$sql = $vbulletin->db->query_read('
SELECT * FROM ' . TABLE_PREFIX . 'guestquoteratings
WHERE quoteid IN (' . $prefetched . ') AND ip = "' . $vbulletin->db->escape_string(get_decent_ip()) . '"
');
}
if ($sql) {
while ($ratings = $vbulletin->db->fetch_array($sql)) {
$rated[$ratings['quoteid']] = $ratings['rating'];
}
$vbulletin->db->free_result($sql);
}
}
if ($prefetched) {
$result_quote = $vbulletin->db->query_read('
SELECT quotes.*, categories.title AS category, user.username AS username FROM ' . TABLE_PREFIX . 'quotes AS quotes
LEFT JOIN ' . TABLE_PREFIX . 'user AS user ON quotes.userid = user.userid
LEFT JOIN ' . TABLE_PREFIX . 'quotecategories AS categories ON categories.categoryid = quotes.categoryid
WHERE quotes.quoteid IN (' . $prefetched . ')
');
}
else {
if (get_decent_referer(true)) {
$vbulletin->url = get_decent_referer(true);
}
else {
$vbulletin->url = 'quotes.php?' . $vbulletin->session->vars['sessionurl'] . 'do=list';
}
eval(print_standard_redirect('no_quotes_matched', true, true));
}
}
DEVDEBUG('Found ' . $vbulletin->db->num_rows($result_quote) . ' quotes.');
return array($result_quote, $rated);
}
/**
* Cleans up quotes, taking care of some shortsightedness in older versions
*
* @param integer The offset where the rebuilding left off
* @param integer The number of quotes to update per page
*
*/
function rebuild_quote_text($offset = 0, $limit = 50) {
global $vbulletin, $vbphrase;
$offset = intval($offset);
$limit = intval($limit);
DEVDEBUG('Rebuilding ' . $limit . ' quotes starting at quote ' . $offset);
// I'm so sorry, please don't read this part
// replace HTML with BBCode and unescape entities
$evilness = $vbulletin->db->query_read('
SELECT * FROM ' . TABLE_PREFIX . 'quotes
WHERE context LIKE "%<a href=%" OR context LIKE "%&%" OR quote LIKE "%&%" OR quote LIKE "%<br%" OR author LIKE "%&%" OR quote LIKE "\"%\""
ORDER BY quoteid ASC LIMIT ' . $offset . ', ' . $limit
);
$total = $vbulletin->db->num_rows($evilness);
if ($total == 0) {
print_cp_message($vbphrase['done'], 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=util', 3);
}
if ($total < $limit) {
$lastdone = $total + $offset;
$next = $vbphrase['done'];
$redirect = 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=util';
}
else {
$lastdone = $limit + $offset;
$next = construct_phrase($vbphrase['continuing_next_x'], $limit);
$redirect = 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=quotecleanup&offset=' . ($offset + $limit) . '&limit=' . $limit;
}
while ($badrow = $vbulletin->db->fetch_array($evilness)) {
// replace leading/trailing quotes, line breaks, entities, and links to posts
$newcontext = preg_replace('|<a href=".+?/showthread\.php\?p=(\d+).*?>(.+?)</a>|', '[post=$1]$2[/post]', $badrow['context']);
$newquote = preg_replace('/\n+/', "\n", preg_replace('|<br( /)?>|i', "\n", preg_replace('/"$/', '', preg_replace('/^"/', '', unhtmlspecialchars($badrow['quote'])))));
$newauthor = unhtmlspecialchars($badrow['author']);
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'quotes SET
quote = "' . $vbulletin->db->escape_string($newquote) . '",
context = "' . $vbulletin->db->escape_string($newcontext) . '",
author = "' . $vbulletin->db->escape_string($newauthor) . '"
WHERE quoteid = ' . $badrow['quoteid']
);
}
$vbulletin->db->free_result($evilness);
print_cp_message(construct_phrase($vbphrase['quotes_x_rebuilt_next_y'], $vbphrase['quotes'], ($offset + 1) . '-' . $lastdone, $next), $redirect, 3);
}
/**
* Updates every users quote count
*
* @param integer The offset where the rebuilding left off
* @param integer The number of quotes to update per page
*
*/
function rebuild_quote_count($offset = 0, $limit = 50) {
global $vbulletin, $vbphrase;
$offset = intval($offset);
$limit = intval($limit);
DEVDEBUG('Rebuilding ' . $limit . ' quotes starting at quote ' . $offset);
// update number of quotes added for each user
$sql = $vbulletin->db->query_read('
SELECT userid, COUNT(*) AS total FROM ' . TABLE_PREFIX . 'quotes
GROUP BY userid ORDER BY userid ASC
LIMIT ' . $offset . ', ' . $limit
);
$total = $vbulletin->db->num_rows($sql);
if ($total == 0) {
print_cp_message($vbphrase['done'], 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=util', 3);
}
if ($total < $limit) {
$lastdone = $total + $offset;
$next = $vbphrase['done'];
$redirect = 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=util';
}
else {
$lastdone = $limit + $offset;
$next = construct_phrase($vbphrase['continuing_next_x'], $limit);
$redirect = 'quoteadmin.php?' . $vbulletin->session->vars['sessionurl'] . 'do=quotecounts&offset=' . ($offset + $limit) . '&limit=' . $limit;
}
while ($counts = $vbulletin->db->fetch_array($sql)) {
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'user SET
quotecount = ' . $counts['total'] . '
WHERE userid = ' . $counts['userid']
);
}
$vbulletin->db->free_result($sql);
print_cp_message(construct_phrase($vbphrase['quotes_x_rebuilt_next_y'], $vbphrase['users'], ($offset + 1) . '-' . $lastdone, $next), $redirect, 3);
}
/**
* Checks $_SERVER and $_ENV to pick out a likely IP address
*
* @return string The user's IP
*
*/
function get_decent_ip() {
static $ip;
if (isset($ip)) {
return $ip;
}
// because I'm still not sure of the difference between $_SERVER and $_ENV or what getenv() actually does :/
if (!empty($_ENV['REMOTE_ADDR'])) {
if (!empty($_ENV['HTTP_X_FORWARDED_FOR'])) {
if (strpos($_ENV['HTTP_X_FORWARDED_FOR'], ',')) {
$possible = explode(',', $_ENV['HTTP_X_FORWARDED_FOR']);
$i = count($possible);
while ($possible[$i]) {
if (check_for_valid_ip(trim($possible[$i]))) {
$ip = trim($possible[$i]);
break;
}
$i--;
}
}
else if (check_for_valid_ip($_ENV['HTTP_X_FORWARDED_FOR'])) {
$ip = $_ENV['HTTP_X_FORWARDED_FOR'];
}
}
else {
$ip = $_ENV['REMOTE_ADDR'];
}
}
else if (!empty($_SERVER['REMOTE_ADDR'])) {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')) {
$possible = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$i = count($possible);
while ($possible[$i]) {
// the last one is the most likely
if (check_for_valid_ip(trim($possible[$i]))) {
$ip = trim($possible[$i]);
break;
}
$i--;
}
}
else if (check_for_valid_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
}
if (!isset($ip)) {
$ip = false;
}
DEVDEBUG('IP address is ' . $ip);
return $ip;
}
/**
* Checks $_SERVER and $_ENV to pick out HTTP_REFERER
*
* @param boolean If the URL should be relative or not
*
* @return string The refering page
*
*/
function get_decent_referer($relative = false) {
global $vbulletin;
static $ref;
if (isset($ref)) {
return $ref;
}
if (!empty($_ENV['HTTP_REFERER'])) {
$ref = $_ENV['HTTP_REFERER'];
}
else if (!empty($_SERVER['HTTP_REFERER'])) {
$ref = $_SERVER['HTTP_REFERER'];
}
else {
$ref = false;
}
if ($ref AND !$relative AND !preg_match('#^(https?|ftp)://#i', $ref)) {
$ref = $vbulletin->options['bburl'] . '/' . $ref;
}
if ($relative) {
$ref = preg_replace('|^' . preg_quote($vbulletin->options['bburl'], '/|') . '|', '', $ref);
}
DEVDEBUG('Referer is ' . $ref);
return $ref;
}
/**
* Checks to make sure we have a usable IP address
*
* @param string The possible IP address
*
* @return bool Whether the IP is valid or not
*
*/
function check_for_valid_ip($ip) {
// no IPv6 for now
if (preg_match('/[^\d\.]/', $ip) OR $ip == '127.0.0.1') {
return false;
}
$bytes = explode('.', $ip);
if (count($bytes) != 4) {
return false;
}
$i = 0;
while ($i < 4) {
if ($bytes[$i] > 255 OR $bytes[$i] < 0) {
return false;
}
$i++;
}
// check for unrouteable addresses (leaving 127.0.0.1 for testing)
if ($bytes[0] == 10 OR ($bytes[0] == 192 AND $bytes[1] == 168) OR ($bytes[0] == 172 AND $bytes[1] >= 16 AND $bytes[1] <= 31)) {
return false;
}
return true;
}
/**
* Updates or deletes the cron job to clean up after guests
*
*/
function manage_guest_cron() {
global $vbulletin;
$cronexists = $vbulletin->db->query_first('
SELECT * FROM ' . TABLE_PREFIX . 'cron
WHERE filename = "./includes/cron/guestquotes.php"
');
if ($vbulletin->GPC['usergroupid'] == 1) {
require_once(DIR . '/includes/functions_cron.php');
if (is_array($cronexists) AND $vbulletin->GPC['usergroup']['quoteitpermissions'] & $vbulletin->bf_ugp_quoteitpermissions['canratequotes']) {
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'cron SET
active = 1
WHERE cronid = ' . $cronexists['cronid']
);
}
else if (!is_array($cronexists) AND $vbulletin->GPC['usergroup']['quoteitpermissions'] & $vbulletin->bf_ugp_quoteitpermissions['canratequotes']) {
$vbulletin->db->query_write('
INSERT INTO ' . TABLE_PREFIX . 'cron
(weekday, day, hour, minute, filename, loglevel, volatile, product, varname, active) VALUES
(-1, -1, -1, "a:1:{i:0;i:0;}", "./includes/cron/guestquotes.php", 1, 1, "quoteit", "guestvotingcleaner", 1)
');
build_cron_item($vbulletin->db->insert_id());
}
else {
$vbulletin->db->query_write('
UPDATE ' . TABLE_PREFIX . 'cron SET
active = 0
WHERE cronid = ' . $cronexists['cronid']
);
}
build_cron_next_run();
}
}
/**
* Rebuilds $globaloptions after it's been cleared by a language rebuild
*
*/
function build_global_options() {
global $vbulletin;
$globalkeys = array(
'averagethreshold',
'enablecontext',
'totalthreshold',
'showrandomquote',
'showquotecount',
'ratings',
'enablebbcode',
'version',
'showquotestats',
'freshinstall',
'averageoperator',
'totaloperator',
'ageoperator',
'randomquotefrequency',
'votesoperator',
'average',
'total',
'age',
'days',
'allowhtml',
'allowbbcode',
'allowsmilies',
'allowimages',
'allowlinebreaks',
'reportquotes',
'usemegaquery',
'cachebbcode',
'randomcategory'
);
$vbulletin->datastore->fetch(array('quote_settings'));
$quoteitoptions = unserialize($vbulletin->quote_settings);
foreach ($quoteitoptions AS $key => $value) {
if (in_array($key, $globalkeys)) {
$globaloptions[$key] = $value;
}
}
$lang = $vbulletin->db->query_first('
SELECT COUNT(*) AS total FROM ' . TABLE_PREFIX . 'language
');
$globaloptions['languagecount'] = $lang['total'];
$vbulletin->languagecache['quoteit_settings'] = serialize($globaloptions);
build_datastore('languagecache', serialize($vbulletin->languagecache), 1);
}
?>