prefix . 'xmasb_quotes'); function filter_xmasb_quotes_random_quote($content) { $codetoreplace = "[XmasBRandomQuote]"; $content=str_replace($codetoreplace,xmasb_get_random_quote(),$content); return $content; } function xmasb_quotes_install () { $sql = "CREATE TABLE " . XMASB_QUOTES_TABLE . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, author tinytext NOT NULL, quote text NOT NULL, imgsrc tinytext NOT NULL, visible boolean NOT NULL default 1, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); } //Function will be available in a future release function xmasb_quotes_export_quotes() { echo "Exporting quotes!"; $dom = new DomDocument("1.0"); $root = $doc->createElement('XmasBQuotes'); $root = $doc->appendChild($root); $sql = 'SELECT * FROM ' . XMASB_QUOTES_TABLE . ' ORDER BY author'; $quotes = $wpdb->get_results($sql); if ( empty($quotes)) { } else { foreach ($quotes as $quote) { //xmasb_quotes_print_quote($quote); } } } function xmasb_quotes_print_showimage($quoteimg, $quote) { echo xmasb_quotes_get_showimage($quoteimg, $quote); } function xmasb_quotes_get_showimage($quoteimg, $quote) { $siteurl = get_option("siteurl"); if ($siteurl[strlen($siteurl)-1] != "/") $siteurl .= "/"; return '
' . $quote->author . '
'; } function xmasb_print_random_quote() { echo xmasb_get_random_quote(); } function xmasb_get_random_quote() { $return = ""; global $wpdb; $table_name = $wpdb->prefix . "xmasb_quotes"; $sql = "SELECT * FROM " . XMASB_QUOTES_TABLE . " where visible = 1 ORDER BY RAND() limit 1"; //Ineffective code - Slow with large tables //$sql = 'SELECT * FROM ' . XMASB_QUOTES_TABLE . ' T JOIN (SELECT FLOOR(MAX(ID)*RAND()) AS ID FROM ' . XMASB_QUOTES_TABLE . ') AS x ON T.ID >= x.ID and visible = 1 LIMIT 1'; $quotes = $wpdb->get_results($sql); if ( !empty($quotes) ) { $return .= xmasb_quotes_get_quote($quotes[0], true); } else { $return .= __('No quotes found', 'xmasbquotes'); } return $return; } function xmasb_quotes_print_quote($quote, $showimage = false) { echo xmasb_quotes_get_quote($quote, $showimage = false); } function xmasb_quotes_get_quote($quote, $showimage = false) { $return = ""; if (is_plugin_page()) { $return .= '
'; } $options = get_option('widget_xmasb_quotes'); $showimages = htmlspecialchars($options['showimages'], ENT_QUOTES) == 'yes' ? true : false; $plugin_path = "wp-content/plugins/" . dirname(plugin_basename(__FILE__)) . "/"; $imagelocation = $plugin_path . "images/"; $defaultimage = htmlspecialchars($options['defaultimage'], ENT_QUOTES); $htmlbeforeimage = $options['htmlbeforeimage']; $htmlafterimage = $options['htmlafterimage']; $htmlbeforequote = $options['htmlbeforequote']; $htmlafterquote = $options['htmlafterquote']; $htmlbeforeauthor = $options['htmlbeforeauthor']; $htmlafterauthor = $options['htmlafterauthor']; $codeforimage = ""; if ( $showimage && $showimages) { if (empty($quote->imgsrc)) { if (file_exists($imagelocation . $quote->author . '.jpg')) { $codeforimage .= xmasb_quotes_get_showimage($imagelocation . $quote->author . '.jpg', $quote); } elseif (file_exists($imagelocation . $quote->author . '.gif')) { $codeforimage .= xmasb_quotes_get_showimage($imagelocation . $quote->author . '.gif', $quote); } elseif (file_exists($imagelocation . $quote->author . '.png')) { $codeforimage .= xmasb_quotes_get_showimage($imagelocation . $quote->author . '.png', $quote); } elseif (!empty($defaultimage)) { $codeforimage .= ''; $quoteimg = $imagelocation . $defaultimage; if (file_exists($quoteimg)) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg, $quote); } else { $codeforimage .= ''; } } else { $codeforimage .= ''; } } else { $quoteimg = $imagelocation . $quote->imgsrc; if (file_exists($quoteimg)) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg, $quote); } elseif (!empty($defaultimage)) { $codeforimage .= ''; $quoteimg = $imagelocation . $defaultimage; if (file_exists($quoteimg)) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg, $quote); } else { $codeforimage .= ''; } } else { $codeforimage .= ''; } } } if ( !empty($codeforimage) ) { $return .= $htmlbeforeimage . $codeforimage . $htmlafterimage; } if (is_plugin_page()) { $codeforquote = ""; if ( $quote->visible ) { $codeforquote .= '
' . $quote->quote . '
'; } else { $codeforquote .= '
' . $quote->quote . '
'; } if ( !empty($codeforquote) ) { $return .= $codeforquote; } } else { $return .= '
' . $htmlbeforequote . $quote->quote . $htmlafterquote . '
'; } if ( !empty($quote->author) ) { if (is_plugin_page()) { $return .= '
' . $quote->author . '
'; } else { $return .= '
' . $htmlbeforeauthor . $quote->author . $htmlafterauthor . '
'; } } if (is_plugin_page()) { if ( !empty($quote->imgsrc) ) { $return .= '
' . $quote->imgsrc . '
'; } $return .= '
'; } return $return; } function xmasb_quotes_options_page() { $options = get_option('widget_xmasb_quotes'); if ( !is_array($options) ) $options = array('title'=>'XmasB Quotes', 'showimages'=>'yes', 'defaultimage'=>'quote.gif', 'htmlbeforequote'=>'', 'htmlafterquote'=>''); if ( $_POST['xmasb_quotes-submit'] ) { $options['showimages'] = strip_tags(stripslashes($_POST['xmasb_quotes-showimages'])); $options['defaultimage'] = strip_tags(stripslashes($_POST['xmasb_quotes-defaultimage'])); $options['htmlbeforeimage'] = stripslashes($_POST['xmasb_quotes-htmlbeforeimage']); $options['htmlafterimage'] = stripslashes($_POST['xmasb_quotes-htmlafterimage']); $options['htmlbeforequote'] = stripslashes($_POST['xmasb_quotes-htmlbeforequote']); $options['htmlafterquote'] = stripslashes($_POST['xmasb_quotes-htmlafterquote']); $options['htmlbeforeauthor'] = stripslashes($_POST['xmasb_quotes-htmlbeforeauthor']); $options['htmlafterauthor'] = stripslashes($_POST['xmasb_quotes-htmlafterauthor']); update_option('widget_xmasb_quotes', $options); } $showimages = htmlspecialchars($options['showimages'], ENT_QUOTES); $defaultimage = htmlspecialchars($options['defaultimage'], ENT_QUOTES); $htmlbeforeimage = htmlspecialchars($options['htmlbeforeimage'], ENT_QUOTES); $htmlafterimage = htmlspecialchars($options['htmlafterimage'], ENT_QUOTES); $htmlbeforequote = htmlspecialchars($options['htmlbeforequote'], ENT_QUOTES); $htmlafterquote = htmlspecialchars($options['htmlafterquote'], ENT_QUOTES); $htmlbeforeauthor = htmlspecialchars($options['htmlbeforeauthor'], ENT_QUOTES); $htmlafterauthor = htmlspecialchars($options['htmlafterauthor'], ENT_QUOTES); ?>

XmasB Quotes

/> />

query($sql); if ( $sqlresponse > 0 ) { if (empty($author)) { ?>

query($sql); if ( $sqlresponse == 1 ) { $sql = "select id from " . XMASB_QUOTES_TABLE . " where quote='" . mysql_real_escape_string($quote) . "'" . " and author='" . mysql_real_escape_string($author) . "' and visible='" . mysql_real_escape_string($visible) . "' limit 1"; $quotes = $wpdb->get_results($sql); if ( empty($quotes) || empty($quotes[0]->id) ) { ?>

id?>.

1 ) { ?>

.

get_results($sql); $sql = 'SELECT * FROM ' . XMASB_QUOTES_TABLE . ' ORDER BY author'; $quotes = $wpdb->get_results($sql); if ( empty($quotes)) { _e('No quotes found', 'xmasbquotes'); $mode = "new"; } else { ?>

XmasB Quotes

query($sql); if ( $sqlresponse == 1 ) { ?>

.

query($sql); if ( $sqlresponse == 1 ) { ?>

". __('Mode:','xmasbquotes') ." " . $mode . "

"; } if ( $quoteID !== false ) { if ( intval($quoteID) != $quoteID ) { ?>

get_results("select * from " . XMASB_QUOTES_TABLE . " where id='" . mysql_real_escape_string($quoteID) . "' limit 1"); if ( empty($quote) ) { ?>

XmasB Quotes

WTF?!?
">
()
()
quote) || $quote->visible==1 ) echo "checked" ?> /> quote) && $quote->visible==0 ) echo "checked" ?> />
get_results($sql); if ( empty($quotes)) { _e('No quotes found', 'xmasbquotes'); } else { ?>
    "; xmasb_quotes_print_quote($quote); echo ""; } ?>
get_results($sql); ?>
1'; $duplicates = $wpdb->get_results($sql); if (!empty($duplicates)) { ?>
    " . $duplicate->quote . ""; $sql = 'SELECT id, author FROM ' . XMASB_QUOTES_TABLE . ' WHERE quote = "' . $duplicate->quote . '"'; $authors = $wpdb->get_results($sql); ?>'; } ?>
    ' . $author->author . '
\n"; # JS inclusion echo "\n"; } /* Widget code */ function widget_xmasb_quotes_init() { load_plugin_textdomain('xmasbquotes', "/wp-content/plugins/xmasbquotes/"); if ( !function_exists('register_sidebar_widget') ) return; function widget_xmasb_quotes($args) { extract($args); $options = get_option('widget_xmasb_quotes'); $title = $options['title']; echo $before_widget . $before_title . $title . $after_title; if ( !function_exists('xmasb_print_random_quote') ) { ?>
xmasb.com.
'XmasB Quotes', 'showimages'=>'yes', 'defaultimage'=>'quote.gif'); if ( $_POST['xmasb_quotes-submit'] ) { $options['title'] = strip_tags(stripslashes($_POST['xmasb_quotes-title'])); update_option('widget_xmasb_quotes', $options); } $title = htmlspecialchars($options['title'], ENT_QUOTES); ?>