'.$exclude;
$sql = "SELECT quote_id, quote, author, source
FROM " . $wpdb->prefix . "quotescollection
WHERE visible = 'yes'
".$exclude_condition."
ORDER BY RAND()
LIMIT 1";
$random_quote = $wpdb->get_row($sql, ARRAY_A);
if ( !empty($random_quote) ) {
return $random_quote;
}
else
return 0;
}
function quotescollection_count($condition = "")
{
global $wpdb;
$sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . "quotescollection ".$condition;
$count = $wpdb->get_var($sql);
return $count;
}
function quotescollection_js_head() // this is a PHP function
{
if ( !defined('WP_PLUGIN_URL') )
$wp_plugin_url = get_bloginfo( 'url' )."/wp-content/plugins";
else
$wp_plugin_url = WP_PLUGIN_URL;
$requrl = $wp_plugin_url . "/quotes-collection/quotes-collection-ajax.php";
$nextquote = __('Next quote', 'quotes-collection');
$loading = __('Loading...', 'quotes-collection');
$error = __('Error getting quote', 'quotes-collection');
// use JavaScript SACK library for AJAX
wp_print_scripts( array( 'sack' ));
// Define custom JavaScript function
?>
". wptexturize(str_replace(array("\r\n", "\r", "\n"), '', nl2br(trim($random_quote['quote'])))) ."
";
if($show_author && $random_quote['author'])
$cite = "";
if($show_source && $random_quote['source']) {
if($cite) $cite .= ", ";
$cite .= "".wptexturize(str_replace(array("\r\n", "\r", "\n"), '', $random_quote['source']))."";
}
if($cite) $cite = " — {$cite}";
$display .= $cite."
".__('Next quote', 'quotes-collection')." »<\/a><\/p>";
return $display;
}
$display = " ".__('Manage your collection of quotes at', 'quotes-collection')." {$msg} ";
$quotes_count = quotescollection_count();
$display .= sprintf(__ngettext('Currently, you have %d quote.', 'Currently, you have %d quotes.', $quotes_count, 'quotes-collection'), $quotes_count);
// anchor to add new quote
$display .= " (".__('Add new quote', 'quotes-collection').")";
$display .= " ".__('No quotes in the database', 'quotes-collection')."
".__('Manage')."->Quotes CollectionQuotes Collection » ".__('Edit quote', 'quotes-collection')."
";
$display .= quotescollection_editform($_REQUEST['id']);
$display .= "Quotes Collection
";
// Get all the quotes from the database
global $wpdb;
$sql = "SELECT quote_id, quote, author, source, tags, visible
FROM " . $wpdb->prefix . "quotescollection";
if(isset($_REQUEST['orderby'])) {
$sql .= " ORDER BY " . $_REQUEST['criteria'] . " " . $_REQUEST['order'];
$option_selected[$_REQUEST['criteria']] = " 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\"";
}
$quotes = $wpdb->get_results($sql);
foreach($quotes as $quote_data) {
if($alternate) $alternate = "";
else $alternate = " class=\"alternate\"";
$quotes_list .= "";
$quotes_list .= " ";
}
if($quotes_list) {
$display .= "quote_id."\" /> ";
$quotes_list .= "" . $quote_data->quote_id . " ";
$quotes_list .= "" . wptexturize(nl2br($quote_data->quote)) ." ";
$quotes_list .= "" . $quote_data->author;
if($quote_data->author && $quote_data->source)
$quotes_list .= " / ";
$quotes_list .= $quote_data->source ." ";
$quotes_list .= "" . implode(', ', explode(',', $quote_data->tags)) . " ";
$quotes_list .= "" . $quote_data->visible ." ";
$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 .= "
";
}
else
$display .= "".__('Add new quote', 'quotes-collection')."
";
$display .= quotescollection_editform();
$display .= "
";
return $display;
}
else
return "";
}
function quotescollection_displayquotes($source = "")
{
global $wpdb;
$source = html_entity_decode($source);
$sql = "SELECT quote_id, quote, author, source
FROM " . $wpdb->prefix . "quotescollection
WHERE visible = 'yes' ";
if(!$source) {
$sql .= "ORDER BY quote";
}
else if($source == "Anonymous" || $source == "anonymous") {
$sql .= "AND (author IS NULL OR author = '' OR author ='Anonymous')";
}
else {
$sql .= "AND (source = '{$source}' OR author = '{$source}')";
}
$quotes = $wpdb->get_results($sql, ARRAY_A);
if ( !empty($quotes) ) {
foreach($quotes as $quote_data) {
$display .= "".wptexturize(nl2br($quote_data['quote']))."
";
if($quote_data['author'])
$cite = $quote_data['author'];
if($quote_data['source']) {
if($cite) $cite .= ", ";
$cite .= $quote_data['source'];
}
if($cite) $cite = " — {$cite}";
$display .= $cite."
";
}
return $display;
}
else
return "";
}
function quotescollection_displayquotes_tags($tags = "")
{
global $wpdb;
$tags = html_entity_decode($tags);
if(!$tags)
return "";
$taglist = explode(',', $tags);
foreach($taglist as $tag) {
$tag = trim($tag);
if($sql_condition) $sql_condition .= " OR ";
$sql_condition .= "tags = '{$tag}' OR tags LIKE '{$tag},%' OR tags LIKE '%,{$tag},%' OR tags LIKE '%,{$tag}'";
}
$sql = "SELECT quote_id, quote, author, source
FROM " . $wpdb->prefix . "quotescollection
WHERE visible = 'yes' AND ({$sql_condition})";
$quotes = $wpdb->get_results($sql, ARRAY_A);
if ( !empty($quotes) ) {
foreach($quotes as $quote_data) {
$display .= "".wptexturize(nl2br($quote_data['quote']))."
";
$cite = "";
if($quote_data['author'])
$cite = $quote_data['author'];
if($quote_data['source']) {
if($cite) $cite .= ", ";
$cite .= $quote_data['source'];
}
if($cite) $cite = " — {$cite}";
$display .= $cite."
";
}
return $display;
}
else
return "";
}
function quotescollection_inpost( $text ) {
$start = strpos($text,"[quote|id=");
if ($start !== FALSE) {
$text = preg_replace( "/\[quote\|id=(\d+)\]/ie", "quotescollection_displayquote('\\1')", $text );
}
$start = strpos($text,"[quote|random]");
if ($start !== FALSE) {
$text = preg_replace( "/\[quote\|random\]/ie", "quotescollection_displayquote()", $text );
}
$start = strpos($text,"[quote|all]");
if ($start !== FALSE) {
$text = preg_replace( "/\[quote\|all\]/ie", "quotescollection_displayquotes()", $text );
}
$start = strpos($text,"[quote|author=");
if($start !== FALSE) {
$text = preg_replace("/\[quote\|author=(.{1,})?\]/ie", "quotescollection_displayquotes(\"\\1\")", $text);
}
$start = strpos($text,"[quote|source=");
if($start !== FALSE) {
$text = preg_replace("/\[quote\|source=(.{1,})?\]/ie", "quotescollection_displayquotes(\"\\1\")", $text);
}
$start = strpos($text,"[quote|tags=");
if($start !== FALSE) {
$text = preg_replace("/\[quote\|tags=(.{1,})?\]/ie", "quotescollection_displayquotes_tags(\"\\1\")", $text);
} return $text;
}
function quotescollection_css_head()
{
if ( !defined('WP_PLUGIN_URL') )
$wp_plugin_url = get_bloginfo( 'url' )."/wp-content/plugins";
else
$wp_plugin_url = WP_PLUGIN_URL;
?>
".wptexturize(nl2br($quote_data['quote']))."
";
$cite = "";
if($quote_data['author'])
$cite = $quote_data['author'];
if($quote_data['source']) {
if($cite) $cite .= ", ";
$cite .= $quote_data['source'];
}
if($cite) $cite = " — {$cite}";
$display .= $cite."