set_feed_url($google_feed); // Tell it to use our newly formatted url $feed->enable_order_by_date(true); // Self Explanatory $feed->enable_cache(true); // Self Explanatory $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/backlinks/cache'); //Save our rss cache in the backlinks plugin directory under /cache $feed->init(); // Initialize the feed with simplepie actions return $feed; // Return the result to the function that called it. } //This function returns the scriptaculous effect the user selected when called. function backlinks_effect() { global $backlinks_options; switch ($backlinks_options['backlinks_effect']) { case 1: $effect='slide'; break; case 2: $effect='blind'; break; case 3: $effect='appear'; break; default: $effect='slide'; } return ($effect); } //The Main function for use in templates function backlinks() { global $backlinks_options; if (!class_exists('SimplePie')) //Checks if the Simplepie Core plugin is installed and if not stops further calls which would b0rk the Universe. { echo '

Error: Backlinks requires SimplePie Core to be installed before use. Exiting gracefully...

'; return; } $feed = prepare_backlinks(); // Get the simplepie object for use if ($backlinks_options['bl_hide_when_empty'] == 1 && $feed->get_item_quantity() == 0) return; //If the user chose to hide the backlinks when there are none, we escape the call // We need this kind of echo as the onclick effects requires both kind of quotes. Within we include an anchor so that people can navigate directly to the results. // The onclick effect uses the blind effect and the toggle function allows it to be opened and closed. echo ''; echo $feed->get_item_quantity() .' ' . $backlinks_options['bl_title'] .' » '. ( ($backlinks_options['bl_more'] == 1)?''. $backlinks_options['bl_more_text'] .'':''); //The actual text link. It also returns the total number of results found. echo ''; // Closing our list and div. Leave the link you want to make me happy :) } // The widget. It basically does the same function as above but is not calling that directly. function add_backlinks_widget() { // First check if all is OK for widgets if (!function_exists('register_sidebar_widget')) return; function backlinks_widget($args) { global $backlinks_options; if (!class_exists('SimplePie')) { echo '

Error: Backlinks requires SimplePie Core to be installed before use. Exiting gracefully...

'; return; } extract($args); $feed = prepare_backlinks(); if ($backlinks_options['bl_hide_when_empty'] == 1 && $feed->get_item_quantity() == 0) return; $options = get_option('backlinks_widget'); echo $before_widget; echo $before_title . ($options['nr_checkbox']!=null?$feed->get_item_quantity():'') . ' ' . $options['title'] . $after_title; echo ''; echo $after_widget; } // This is the function that outputs the form to let the users edit // the widget's title. It's an optional feature that users cry for. function widget_backlinks_control() { // Get our options and see if we're handling a form submission. $options = get_option('backlinks_widget'); if ( !is_array($options) ) $options = array('title'=>'', 'number'=>'5', 'nr_checkbox'=>'1'); if ( $_POST['backlinks-submit'] ) { // Remember to sanitize and format use input appropriately. $options['title'] = strip_tags(stripslashes($_POST['backlinks-title'])); $options['number'] = strip_tags(stripslashes($_POST['backlinks-number'])); $options['nr_checkbox'] = $_POST['backlinks-title-nr-chk']; update_option('backlinks_widget', $options); } // Be sure you format your options to be valid HTML attributes. $title = htmlspecialchars($options['title'], ENT_QUOTES); $number = htmlspecialchars($options['number'], ENT_QUOTES); $nr_checkbox = $options['nr_number']; // Here is our little form segment. Notice that we don't need a // complete form. This will be embedded into the existing form. echo '

'; echo '

'; echo '

'; echo ''; } register_sidebar_widget('Backlinks (Experimental)', 'backlinks_widget'); register_widget_control('Backlinks (Experimental)', 'widget_backlinks_control', 250, 100); } //This function defines the predefined classes for the items function add_bl_stylesheet() { global $backlinks_options; if (!$backlinks_options['bl_ownstylesheet']) { echo << a.backlinks_title{ font-style:bold; font-size:150% } a.backlinks_title:hover{ text-decoration:underline; } a.morelink{ font-style:italic; font-size:75% color:#888; text-decoration:none; } ul.dates{ list-style-type:none; margin:1.5em 0 2em 0; border-top:1px solid #3D3D3D; } ul.dates .date{ color:#858585; padding:0 1.5em 0 0; } END; } } add_action('wp_head', 'add_bl_stylesheet'); ?>