2010-06-10, 02:46 PM
So I've been getting this error:
I'm trying to make a thread that gives out a random thread link. It's nearly done, just need the random thread link bit working.
Here's my code:
Halp please.
MyBB has experienced an internal SQL error and cannot continue.
SQL Error:
1146 - Table 'dotrb_dotrb.mybb_mybb_threads' doesn't exist
Query:
SELECT tid FROM mybb_mybb_threads LIMIT 0, 1
I'm trying to make a thread that gives out a random thread link. It's nearly done, just need the random thread link bit working.
Here's my code:
<?php
/**
* Random Thread Generator 1.0
* Copyright 2010, Jordan Lovelle
* http://mybbrunway.com
*
* You may not redistribute this plugin without my consent.
* You must keep my copyright in at all times.
**/
if(!defined("IN_MYBB"))
{
die("Nice try. You can't access this file directly, idiot.");
}
$plugins->add_hook("index_start", "randomthread_index_start");
{
// select random thread
$rndnum = mt_rand(0, $threadcount-1);
$rndtid = $db->fetch_field($db->simple_select(TABLE_PREFIX. 'threads', 'tid', $where, array('limit' => 1, 'limit_start' => $rndnum)), 'tid');
if(!$rndtid)
die('Internal error');
header('Location: showthread.php?tid='.$rndtid);
exit;
}
function randomthread_info()
{
return array(
"name" => "Random Thread Generator",
"description" => "Generate a random thread and place it on the index.",
"website" => "http://mybbrunway.com",
"author" => "Jordan Lovelle",
"authorsite" => "http://mybbrunway.com",
"version" => "1.0",
"guid" => "",
"compatibility" => ""
);
}
function randomthread_activate()
{
global $db, $mybb, $settings;
$insertarray = array(
"title" => "randomthread",
"template" => "<style>
.randomthread {
background: {\$mybb->settings[\'bgcolour_randomthread\']};
border-top: 2px solid {\$mybb->settings[\'topborder_randomthread\']};
border-bottom: 2px solid {\$mybb->settings[\'bottomborder_randomthread\']};
text-align: center;
margin: 10px auto;
padding: 5px 20px;
}
</style>
<p class=\"randomthread\">
Lol sup
</p>
<br>",
"sid" => -1,
"dateline" => TIME_NOW
);
$db->insert_query("templates", $insertarray);
$randomthread_group = array(
'gid' => 'NULL',
'name' => 'randomthread',
'title' => 'Random Thread Generator',
'description' => 'Settings for the Random Thread Generator plugin.',
'disporder' => "1",
'isdefault' => 'no'
);
$db->insert_query('settinggroups', $randomthread_group);
$gid = $db->insert_id();
$randomthread_enable = array(
'sid' => 'NULL',
'name' => 'enabled_randomthread',
'title' => 'Enable?',
'description' => 'If yes, the random thread will be generated. If not, it will not be.',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => 1,
'gid' => intval($gid),
);
$randomthread_fid = array(
'sid' => 'NULL',
'name' => 'fid_randomthread',
'title' => 'Enter the FID',
'description' => 'Only enter the FID <i>Number</i>.',
'optionscode' => 'text',
'value' => '2',
'disporder' => 2,
'gid' => intval($gid),
);
$randomthread_bgcolour = array(
'sid' => 'NULL',
'name' => 'bgcolour_randomthread',
'title' => 'Background Colour',
'description' => 'Enter the background colour you want to use.',
'optionscode' => 'text',
'value' => '#FFF6BF',
'disporder' => 3,
'gid' => intval($gid),
);
$randomthread_topborder = array(
'sid' => 'NULL',
'name' => 'topborder_randomthread',
'title' => 'Top Border Colour',
'description' => 'Enter the top-border colour you want to use.',
'optionscode' => 'text',
'value' => '#FFD324',
'disporder' => 4,
'gid' => intval($gid),
);
$randomthread_bottomborder = array(
'sid' => 'NULL',
'name' => 'bottomborder_randomthread',
'title' => 'Bottom Border Colour',
'description' => 'Enter the bottom-border colour you want to use.',
'optionscode' => 'text',
'value' => '#FFD324',
'disporder' => 5,
'gid' => intval($gid),
);
$db->insert_query('settings', $randomthread_enable);
$db->insert_query('settings', $randomthread_fid);
$db->insert_query('settings', $randomthread_bgcolour);
$db->insert_query('settings', $randomthread_topborder);
$db->insert_query('settings', $randomthread_bottomborder);
rebuild_settings();
include MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("index", "#".preg_quote("{\$header}")."#i", "{\$header}\r\n{\$randomthread}");
}
function randomthread_deactivate()
{
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_randomthread')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='randomthread'");
rebuild_settings();
$db->delete_query("templates", "title = 'randomthread'");
include MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("index", "#".preg_quote("\r\n{\$randomthread}")."#i", "", 0);
}
function randomthread_index_start()
{
global $db, $mybb, $templates, $randomthread;
eval("\$randomthread = \"".$templates->get("randomthread")."\";");
}
?>
Halp please.