prefix . 'yarq_quotes'); define('YARQ_DB_VERSION', '2.5'); // // Install the plugin // function yarq_install() { global $wpdb; add_option('yarq_format', '

%quote%

by %author%

'); add_option("yarq_db_version", YARQ_DB_VERSION); // clean installation if ($wpdb->get_var("show tables like '" . YARQ_QUOTES_TABLE . "'") != YARQ_QUOTES_TABLE) { require_once(ABSPATH . 'wp-admin/includes/upgrade.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.');"); } // update table (if needed) $installed_ver = get_option("yarq_db_version"); if( $installed_ver != YARQ_DB_VERSION ) { require_once(ABSPATH . 'wp-admin/includes/upgrade.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) );"); update_option("yarq_db_version", YARQ_DB_VERSION); } } // // 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'), __('YARQ', 'yarq'), 10, basename(__FILE__), 'yarq_admin_options'); add_management_page(__('Manage Random Quotes', 'yarq'), __('Quotes', 'yarq'), 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.', 'yarq') . '

'; } echo '
' . "\n"; echo '

' . __('Yet Another Random Quote Options', 'yarq') . '

' . "\n"; echo '
' . "\n"; echo '
' . "\n"; echo '' . __('Format', 'yarq') . '' . "\n"; echo '

' . __('The format and style used to display the quote. %quote% is replaced with the random quote, %author% is replaced by the name of the author of the quote, and %source% is replaced by the source of the quote.', 'yarq') . '

' . "\n"; echo '

' . "\n"; echo '
' . "\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.', 'yarq'), intval($_GET['delete'])) . '

'; } // // Add a quote // if (isset($_POST['add'])) { $errors = array(); if (empty($_POST['yarq_quote'])) { $errors[] = __('You did not enter a quote.', 'yarq'); } if (empty($_POST['yarq_author'])) { $errors[] = __('You did not enter an author.', 'yarq'); } if (count($errors) > 0) { echo '
' . "\n"; } else { $wpdb->query("INSERT INTO " . YARQ_QUOTES_TABLE . " (author, source, quote) VALUES ('" . $wpdb->escape($_POST['yarq_author']) . "', '" . $wpdb->escape($_POST['yarq_source']) . "', '" . $wpdb->escape($_POST['yarq_quote']) . "');"); echo '

' . __('Quote added.', 'yarq') . '

'; } } // // List quotes // echo '
' . "\n"; echo '

' . __('Manage Quotes', 'yarq') . '

' . "\n"; $quotes = $wpdb->get_results("SELECT * FROM " . YARQ_QUOTES_TABLE); if ($quotes) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; $alternate = true; foreach($quotes as $quote) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; if (!empty($quote->source)) { echo '' . "\n"; } else { echo '' . "\n"; } echo '' . "\n"; echo '' . "\n"; } echo '
' . __('ID', 'yarq') . '' . __('Quote', 'yarq') . '' . __('Author', 'yarq') . '' . __('Source', 'yarq') . '
' . $quote->id . '' . $quote->quote . '' . $quote->author . '' . $quote->source . '' . __('Delete', 'yarq') . '
' . "\n"; } else { echo '

' . __('No quotes found.', 'yarq') . '

'; } echo '
' . "\n"; // // Add form // echo '
' . "\n"; echo '

' . __('Add Quote', 'yarq') . '

' . "\n"; echo '
' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
' . __('Quote', 'yarq') . '
' . __('Author', 'yarq') . '
' . __('Source URL', 'yarq') . '
' . "\n"; echo '
' . "\n"; echo '
' . "\n"; echo '' . "\n"; } // // Display a random quote // function yarq_display($format = '') { global $wpdb; if (empty($format)) { $format = stripslashes(get_option('yarq_format')); } $quote = $wpdb->get_row("SELECT * FROM " . YARQ_QUOTES_TABLE . " ORDER BY RAND() LIMIT 1"); $output = str_replace('%quote%', $quote->quote, $format); $output = str_replace('%author%', $quote->author, $output); echo str_replace('%source%', $quote->source, $output); } // // Display a random quote in a widget (if widgets are available) // function widget_yarq_register() { if ( function_exists('register_sidebar_widget') ) : function widget_yarq($args) { extract($args);?>