prefix . "quotescollection"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) return __('Database table not found', 'quotes-collection'); else //Add the quote data to the database { $quote = stripslashes($quote); $author = stripslashes($author); $source = stripslashes($source); $tags = stripslashes($tags); $quote = "'".$wpdb->escape($quote)."'"; $author = $author?"'".$wpdb->escape($author)."'":"NULL"; $source = $source?"'".$wpdb->escape($source)."'":"NULL"; $tags = explode(',', $tags); foreach ($tags as $key => $tag) $tags[$key] = trim($tag); $tags = implode(',', $tags); $tags = $tags?"'".$wpdb->escape($tags)."'":"NULL"; if(!$public) $public = "'no'"; else $public = "'yes'"; $insert = "INSERT INTO " . $table_name . "(quote, author, source, tags, public, time_added)" . "VALUES ({$quote}, {$author}, {$source}, {$tags}, {$public}, NOW())"; $results = $wpdb->query( $insert ); if(FALSE === $results) return __('There was an error in the MySQL query', 'quotes-collection'); else return __('Quote added', 'quotes-collection'); } } function quotescollection_editquote($quote_id, $quote, $author = "", $source = "", $tags = "", $public = 'yes') { if(!$quote) return __('Quote not updated.', 'quotes-collection'); if(!$quote_id) return srgq_addquote($quote, $author, $source, $public); global $wpdb; $table_name = $wpdb->prefix . "quotescollection"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) return __('Database table not found', 'quotes-collection'); else //Update database { $quote = stripslashes($quote); $author = stripslashes($author); $source = stripslashes($source); $tags = stripslashes($tags); $quote = "'".$wpdb->escape($quote)."'"; $author = $author?"'".$wpdb->escape($author)."'":"NULL"; $source = $source?"'".$wpdb->escape($source)."'":"NULL"; $tags = explode(',', $tags); foreach ($tags as $key => $tag) $tags[$key] = trim($tag); $tags = implode(',', $tags); $tags = $tags?"'".$wpdb->escape($tags)."'":"NULL"; if(!$public) $public = "'no'"; else $public = "'yes'"; $update = "UPDATE " . $table_name . " SET quote = {$quote}, author = {$author}, source = {$source}, tags = {$tags}, public = {$public}, time_updated = NOW() WHERE quote_id = $quote_id"; $results = $wpdb->query( $update ); if(FALSE === $results) return __('There was an error in the MySQL query', 'quotes-collection'); else return __('Changes saved', 'quotes-collection'); } } function quotescollection_deletequote($quote_id) { if($quote_id) { global $wpdb; $sql = "DELETE from " . $wpdb->prefix ."quotescollection" . " WHERE quote_id = " . $quote_id; if(FALSE === $wpdb->query($sql)) return __('There was an error in the MySQL query', 'quotes-collection'); else return __('Quote deleted', 'quotes-collection'); } else return __('The quote cannot be deleted', 'quotes-collection'); } function quotescollection_getquotedata($quote_id) { global $wpdb; $sql = "SELECT quote_id, quote, author, source, tags, public FROM " . $wpdb->prefix . "quotescollection WHERE quote_id = {$quote_id}"; $quote_data = $wpdb->get_row($sql, ARRAY_A); return $quote_data; } function quotescollection_editform($quote_id = 0) { $public_selected = " checked=\"checked\""; $submit_value = __('Add Quote', 'quotes-collection'); $form_name = "addquote"; $action_url = get_bloginfo('wpurl')."/wp-admin/admin.php?page=quotes-collection#addnew"; $quote = $author = $source = $tags = $hidden_input = $back = ""; if($quote_id) { $form_name = "editquote"; $quote_data = quotescollection_getquotedata($quote_id); foreach($quote_data as $key => $value) $quote_data[$key] = $quote_data[$key]; extract($quote_data); $quote = htmlspecialchars($quote); $author = htmlspecialchars($author); $source = htmlspecialchars($source); $tags = implode(', ', explode(',', $tags)); $hidden_input = ""; if($public == 'no') $public_selected = ""; $submit_value = __('Save changes', 'quotes-collection'); $back = " "; $action_url = get_bloginfo('wpurl')."/wp-admin/admin.php?page=quotes-collection"; } $quote_label = __('The quote', 'quotes-collection'); $author_label = __('Author', 'quotes-collection'); $source_label = __('Source', 'quotes-collection'); $tags_label = __('Tags', 'quotes-collection'); $public_label = __('Public?', 'quotes-collection'); $optional_text = __('optional', 'quotes-collection'); $comma_separated_text = __('comma separated', 'quotes-collection'); $display =<<< EDITFORM
EDITFORM; return $display; } function quotescollection_changevisibility($quote_ids, $public = 'yes') { if(!$quote_ids) return __('Nothing done!', 'quotes-collection'); global $wpdb; $sql = "UPDATE ".$wpdb->prefix."quotescollection SET public = '".$public."', time_updated = NOW() WHERE quote_id IN (".implode(', ', $quote_ids).")"; $wpdb->query($sql); if($public == 'yes') return __("Selected quotes made public", 'quotes-collection'); else return __("Selected quotes made private", 'quotes-collection'); } function quotescollection_bulkdelete($quote_ids) { if(!$quote_ids) return __('Nothing done!', 'quotes-collection'); global $wpdb; $sql = "DELETE FROM ".$wpdb->prefix."quotescollection WHERE quote_id IN (".implode(', ', $quote_ids).")"; $wpdb->query($sql); return __('Quote(s) deleted', 'quotes-collection'); } function quotescollection_quotes_management() { global $quotescollection_db_version; $options = get_option('quotescollection'); $display = $msg = $quotes_list = $alternate = ""; if($options['db_version'] != $quotescollection_db_version ) quotescollection_install(); if(isset($_REQUEST['submit'])) { if($_REQUEST['submit'] == __('Add Quote', 'quotes-collection')) { extract($_REQUEST); $msg = quotescollection_addquote($quote, $author, $source, $tags, $public); } else if($_REQUEST['submit'] == __('Save changes', 'quotes-collection')) { extract($_REQUEST); $msg = quotescollection_editquote($quote_id, $quote, $author, $source, $tags, $public); } } else if(isset($_REQUEST['action'])) { if($_REQUEST['action'] == 'editquote') { $display .= "{$msg}
".__('No quotes in the database', 'quotes-collection')."
"; $display .= "".__('No quotes in the database', 'quotes-collection')."
"; $display .= ""; $display .= "