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
{$hidden_input}

{$optional_text}

{$optional_text}

{$optional_text}, {$comma_separated_text}

{$back}

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 .= "
\n

Quotes Collection » ".__('Edit quote', 'quotes-collection')."

"; $display .= quotescollection_editform($_REQUEST['id']); $display .= "
"; echo $display; return; } else if($_REQUEST['action'] == 'delquote') { $msg = quotescollection_deletequote($_REQUEST['id']); } } else if(isset($_REQUEST['bulkactionsubmit'])) { if($_REQUEST['bulkaction'] == 'delete') $msg = quotescollection_bulkdelete($_REQUEST['bulkcheck']); if($_REQUEST['bulkaction'] == 'make_public') { $msg = quotescollection_changevisibility($_REQUEST['bulkcheck'], 'yes'); } if($_REQUEST['bulkaction'] == 'keep_private') { $msg = quotescollection_changevisibility($_REQUEST['bulkcheck'], 'no'); } } $display .= "
"; if($msg) $display .= "

{$msg}

"; $display .= "

Quotes Collection ".__('Add new quote', 'quotes-collection')."

"; $num_quotes = quotescollection_count(); if(!$num_quotes) { $display .= "

".__('No quotes in the database', 'quotes-collection')."

"; $display .= "
"; $display .= "
\n

".__('Add new quote', 'quotes-collection')."

"; $display .= quotescollection_editform(); $display .= "
"; echo $display; return; } global $wpdb; $sql = "SELECT quote_id, quote, author, source, tags, public FROM " . $wpdb->prefix . "quotescollection"; $option_selected = array ( 'quote_id' => '', 'quote' => '', 'author' => '', 'source' => '', 'time_added' => '', 'time_updated' => '', 'public' => '', 'ASC' => '', 'DESC' => '', ); if(isset($_REQUEST['orderby'])) { $sql .= " ORDER BY " . $_REQUEST['orderby'] . " " . $_REQUEST['order']; $option_selected[$_REQUEST['orderby']] = " selected=\"selected\""; $option_selected[$_REQUEST['order']] = " selected=\"selected\""; } else { $sql .= " ORDER BY quote_id ASC"; $option_selected['quote_id'] = " selected=\"selected\""; $option_selected['ASC'] = " selected=\"selected\""; } if(isset($_REQUEST['paged']) && $_REQUEST['paged'] && is_numeric($_REQUEST['paged'])) $paged = $_REQUEST['paged']; else $paged = 1; $limit_per_page = 20; $total_pages = ceil($num_quotes / $limit_per_page); if($paged > $total_pages) $paged = $total_pages; $admin_url = get_bloginfo('wpurl'). "/wp-admin/admin.php?page=quotes-collection"; if(isset($_REQUEST['orderby'])) $admin_url .= "&orderby=".$_REQUEST['orderby']."&order=".$_REQUEST['order']; $page_nav = quotescollection_pagenav($total_pages, $paged, 2, 'paged', $admin_url); $start = ($paged - 1) * $limit_per_page; $sql .= " LIMIT {$start}, {$limit_per_page}"; // Get all the quotes from the database $quotes = $wpdb->get_results($sql); foreach($quotes as $quote_data) { if($alternate) $alternate = ""; else $alternate = " class=\"alternate\""; $quotes_list .= ""; $quotes_list .= "quote_id."\" />"; $quotes_list .= "" . $quote_data->quote_id . ""; $quotes_list .= ""; $quotes_list .= wptexturize(nl2br(make_clickable($quote_data->quote))); $quotes_list .= "
quote_id."\" class=\"edit\">".__('Edit', 'quotes-collection')." | quote_id."\" onclick=\"return confirm( '".__('Are you sure you want to delete this quote?', 'quotes-collection')."');\" class=\"delete\">".__('Delete', 'quotes-collection')."
"; $quotes_list .= ""; $quotes_list .= "" . make_clickable($quote_data->author); if($quote_data->author && $quote_data->source) $quotes_list .= " / "; $quotes_list .= make_clickable($quote_data->source) .""; $quotes_list .= "" . implode(', ', explode(',', $quote_data->tags)) . ""; if($quote_data->public == 'no') $public = __('No', 'quotes-collection'); else $public = __('Yes', 'quotes-collection'); $quotes_list .= "" . $public .""; $quotes_list .= ""; } if($quotes_list) { $quotes_count = quotescollection_count(); $display .= "
"; $display .= "
"; $display .= "
"; $display .= ""; $display .= ""; $display .= "   "; $display .= __('Sort by: ', 'quotes-collection'); $display .= ""; $display .= ""; $display .= ""; $display .= "
"; $display .= '
'.sprintf(_n('%d quote', '%d quote', $quotes_count, 'quotes-collection'), $quotes_count).''. $page_nav. "
"; $display .= "
"; $display .= "
"; $display .= ""; $display .= ""; $display .= "{$quotes_list}"; $display .= "
ID".__('The quote', 'quotes-collection')." ".__('Author', 'quotes-collection')." / ".__('Source', 'quotes-collection')." ".__('Tags', 'quotes-collection')." ".__('Public?', 'quotes-collection')."
"; $display .= "
"; $display .= '
'.sprintf(_n('%d quote', '%d quote', $quotes_count, 'quotes-collection'), $quotes_count).''. $page_nav. "
"; $display .= "
"; $display .= "
"; $display .= "
"; $display .= "
"; } else $display .= "

".__('No quotes in the database', 'quotes-collection')."

"; $display .= ""; $display .= "
\n

".__('Add new quote', 'quotes-collection')."

"; $display .= quotescollection_editform(); $display .= "
"; echo $display; } function quotescollection_admin_footer() { ?>