prefix . 'xmasb_quotes'); define('XMASB_QUOTES_PLUGIN_DIR', WP_PLUGIN_DIR .'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__))); define('XMASB_QUOTES_PLUGIN_URL', WP_PLUGIN_URL .'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__))); define('XMASB_QUOTES_IMAGE_TYPES', 'png,jpg,gif,jpeg'); 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, link tinytext NOT NULL, visible boolean NOT NULL default 1, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); } //Function to check if url exists function xmasb_quotes_url_exists($url) { return file_exists($url); } function xmasb_quotes_get_similar_image($author) { $imagetypes = explode(',',XMASB_QUOTES_IMAGE_TYPES); foreach($imagetypes as $imagetype){ if (file_exists($author . '/' . $imagetype)) { return $author . '/' . $imagetype; } } $dir = dirname($author); $fileBasename = basename($author); $files = glob($dir . '/*'); $lcaseFilename = strtolower($dir . '/' . $fileBasename); $lcaseFilenameStripped = strtolower($dir . '/' . preg_replace('/[^\w]/','', $fileBasename)); foreach($files as $file) { foreach($imagetypes as $imagetype){ if (strtolower($file) == $lcaseFilename . '.' . $imagetype) { return $file; } if (strtolower($file) == $lcaseFilenameStripped . '.' . $imagetype) { return $file; } } } return ""; } 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_codeforimage($quote) { $codeforimage = ""; if (empty($quote->imgsrc)) { $codeforimage .= xmasb_quotes_get_codeforimage_by_author($quote); } else { $codeforimage .= xmasb_quotes_get_codeforimage_by_imgsrc($quote); } return $codeforimage; } function xmasb_quotes_get_codeforimage_by_imgsrc($quote) { $imagelocation = XMASB_QUOTES_PLUGIN_DIR . "images/"; $options = get_option('widget_xmasb_quotes'); $defaultimage = htmlspecialchars($options['defaultimage'], ENT_QUOTES); $codeforimage = ""; $quoteimg = $imagelocation . $quote->imgsrc; if (xmasb_quotes_url_exists($quoteimg)) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg, $quote); } elseif (!empty($defaultimage)) { //$codeforimage .= ''; $quoteimg = $imagelocation . $defaultimage; if (xmasb_quotes_url_exists($quoteimg)) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg, $quote); } else { //$codeforimage .= ''; } } else { //$codeforimage .= ''; } return $codeforimage; } function xmasb_quotes_get_codeforimage_by_author($quote) { $imagelocation = XMASB_QUOTES_PLUGIN_DIR . "images/"; $options = get_option('widget_xmasb_quotes'); $defaultimage = htmlspecialchars($options['defaultimage'], ENT_QUOTES); $codeforimage = ""; $imagefound = false; $author = str_replace(' ', '', $quote->author); $quoteimg = $imagelocation . $author; $imageUrl = xmasb_quotes_get_similar_image($imagelocation . $quote->author); if(!empty($imageUrl)){ $imageUrl = str_replace(WP_PLUGIN_DIR,WP_PLUGIN_URL,$imageUrl); $codeforimage .= xmasb_quotes_get_showimage($imageUrl, $quote); $imagefound = true; } if(!$imagefound && !empty($defaultimage)) { //$codeforimage .= ''; $quoteimg = $imagelocation . $defaultimage; $rex = "/^.*\.(jpg|jpeg|png|gif)$/i"; if(preg_match($rex, $quoteimg)) { if (xmasb_quotes_url_exists($quoteimg)) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg, $quote); $imagefound = true; } else { //$codeforimage .= ''; } } elseif (xmasb_quotes_url_exists($quoteimg . '.png')) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg . '.png', $quote); } elseif (xmasb_quotes_url_exists($quoteimg . '.jpg')) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg . '.jpg', $quote); } elseif (xmasb_quotes_url_exists($quoteimg . '.jpeg')) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg . '.jpeg', $quote); } elseif (xmasb_quotes_url_exists($quoteimg . '.gif')) { $codeforimage .= xmasb_quotes_get_showimage($quoteimg . '.gif', $quote); } else { //$codeforimage .= ''; } } else { //$codeforimage .= ''; } return $codeforimage; } function xmasb_quotes_get_quote($quote, $showimage = false) { $quote->quote = stripslashes($quote->quote); $return = ""; if (is_plugin_page()) { $return .= '
'; } $options = get_option('widget_xmasb_quotes'); $showimages = htmlspecialchars($options['showimages'], ENT_QUOTES) == 'yes' ? true : false; $htmlbeforeimage = $options['htmlbeforeimage']; $htmlafterimage = $options['htmlafterimage']; $htmlbeforequote = $options['htmlbeforequote']; $htmlafterquote = $options['htmlafterquote']; $htmlbeforeauthor = $options['htmlbeforeauthor']; $htmlafterauthor = $options['htmlafterauthor']; $codeforimage = ""; if ( $showimage && $showimages) { $codeforimage .= xmasb_quotes_get_codeforimage($quote); } if ( !empty($codeforimage) ) { $codeforimage = str_replace(WP_PLUGIN_DIR, WP_PLUGIN_URL, $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 { if ( empty($quote->link) ) { $return .= '
' . $htmlbeforequote . $quote->quote . $htmlafterquote . '
'; } 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.png', 'htmlbeforequote'=>'', 'htmlafterquote'=>'', 'rolerequired'=>'administrator'); } 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']); $options['rolerequired'] = stripslashes($_POST['xmasb_quotes-rolerequired']); 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); $rolerequired = htmlspecialchars($options['rolerequired'], ENT_QUOTES); ?>

XmasB Quotes

/> />
exported quotes."; }else{ $exportStatus = "Export failed: $exportResponse"; } $mode = 'new'; } if ($mode == 'add') { $quote = !empty($_REQUEST['quote_quote']) ? $_REQUEST['quote_quote'] : ''; $author = !empty($_REQUEST['quote_author']) ? $_REQUEST['quote_author'] : ''; $imgsrc = !empty($_REQUEST['quote_imgsrc']) ? $_REQUEST['quote_imgsrc'] : ''; $link = !empty($_REQUEST['quote_link']) ? $_REQUEST['quote_link'] : ''; $visible = !empty($_REQUEST['quote_visible']) ? $_REQUEST['quote_visible'] : ''; /* if ( ini_get('magic_quotes_gpc') ) { $quote = stripslashes($quote); $author = stripslashes($author); $imgsrc = stripslashes($imgsrc); $link = stripslashes($link); } */ if (empty($quote)) { ?>

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) ) { ?>

quote = stripslashes($quote->quote); } } if ( $mode != "list" ) { ?>

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 . '
xmasb.com.
'XmasB Quotes', 'showimages'=>'yes', 'defaultimage'=>'quote.png'); } 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); ?>

open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } } */ /* function xmasb_quotes_sample_zip_usage(){ $files_to_zip = array( 'preload-images/1.jpg', 'preload-images/2.jpg', 'preload-images/5.jpg', 'kwicks/ringo.gif', 'rod.jpg', 'reddit.gif' ); //if true, good; if false, zip creation failed $result = create_zip($files_to_zip,'my-archive.zip'); } */ //Function will be available in a future release function xmasb_quotes_export_get_xml() { global $wpdb; $sql = 'SELECT DISTINCT author, quote, imgsrc, link, visible FROM ' . XMASB_QUOTES_TABLE . ' ORDER BY author, quote'; $quotes = $wpdb->get_results($sql); if ( empty($quotes)) { $return = __('No quotes found', 'xmasbquotes'); echo $return; } else { $document = new DomDocument("1.0"); $rootNode = $document->createElement('XmasBQuotes'); $document->appendChild($rootNode); //Just in case... $authorNode = $document->createElement("Author"); $previousAuthor = ""; foreach ($quotes as $quote) { if(strcmp($previousAuthor,$quote->author)!=0){ $authorNode = $document->createElement("Author"); } $quoteNode = $document->createElement("Quote"); $authorNode->appendChild($quoteNode); $rootNode->appendChild($authorNode); if(!empty($quote->author)) $authorNode->setAttribute("name", $quote->author); if(!empty($quote->imgsrc)) $quoteNode->setAttribute("image", $quote->imgsrc); if(empty($quote->visible) || $quote->visible == false) $quoteNode->setAttribute("visible", "false"); if(!empty($quote->link)) $quoteNode->setAttribute("link", $quote->link); $quoteNode->appendChild($document->createTextNode($quote->quote)); $previousAuthor = $quote->author; } return $document->saveXML(); } } //Function for writing to a file function xmasb_quotes_write_to_file($filename, $content){ if (!$handle = fopen($filename, 'w')) { return "Cannot open file ($filename)"; } // Write $content to our opened file. if (fwrite($handle, $content) === FALSE) { return "Cannot write to file ($filename)"; } //return "Success, wrote ($content) to file ($filename)"; fclose($handle); } ?>