');
if ($wpdb->get_var("show tables like '" . YARQ_QUOTES_TABLE . "'") != YARQ_QUOTES_TABLE)
{
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta("CREATE TABLE " . YARQ_QUOTES_TABLE . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
author VARCHAR(255) NOT NULL,
source VARCHAR(255) NOT NULL,
quote TEXT NOT NULL,
UNIQUE KEY id (id)
);");
$wpdb->query("INSERT INTO " . YARQ_QUOTES_TABLE . " (author, source, quote) VALUES ('WordPress', 'http://wordpress.org', 'Code is poetry.');");
}
}
//
// Generate links in the admin menu to the YARQ admin pages
//
function yarq_generate_admin_menu()
{
if (function_exists('add_options_page'))
{
add_options_page('Yet Another Random Quote', 'YARQ', 10, basename(__FILE__), 'yarq_admin_options');
add_management_page('Manage Random Quotes', 'Quotes', 10, basename(__FILE__), 'yarq_admin_manage');
}
}
//
// YARQ Admin options panel
//
function yarq_admin_options()
{
if (isset($_POST['update_options']))
{
update_option('yarq_format', $_POST['yarq_format']);
echo '
' . __('Options updated.') . '
';
}
echo '
' . "\n";
echo '
' . __('Yet Another Random Quote Options') . '
' . "\n";
echo '
' . "\n";
}
//
// YARQ Admin manage quotes panel
//
function yarq_admin_manage()
{
global $wpdb;
//
// Delete a quote
//
if (isset($_GET['delete']))
{
$wpdb->query("DELETE FROM " . YARQ_QUOTES_TABLE . " WHERE id = '" . intval($_GET['delete']) . "'");
echo '
' . sprintf(__('Quote %d has been deleted.'), intval($_GET['delete'])) . '
';
}
//Default values
$yarq_author = '';
$yarq_source = '';
$yarq_quote = '';
$yarq_id = '';
$is_edit = false;
//Check if we're editing and haven't run into errors yet. Then we should
//have the id in the querystring.
if (isset($_GET['id']))
{
$yarq_id = intval($_GET['id']);
$quotes = $wpdb->get_results("SELECT * FROM " . YARQ_QUOTES_TABLE . " WHERE id = $yarq_id;");
$quote = $quotes[0];
$yarq_source = $quote->source;
$yarq_quote = $quote->quote;
$yarq_author = $quote->author;
$is_edit = true;
}
//
// Add a quote
//
if (isset($_POST['save']))
{
$errors = array();
if (empty($_POST['yarq_quote']))
{
$errors[] = __('You did not enter a quote.');
}
if (empty($_POST['yarq_author']))
{
$errors[] = __('You did not enter an author.');
}
$yarq_author = yarq_sql_post_value('yarq_author');
$yarq_source = yarq_sql_post_value('yarq_source');
$yarq_quote = yarq_sql_post_value('yarq_quote');
if (!empty($_POST['yarq_id']))
{
$yarq_id = intval($_POST['yarq_id']);
$is_edit = true;
}
if (count($errors) > 0)
{
echo '