widget randomly displays a snapshot of websites from your blogroll. Version: 1.0.7 Author: Denis Balencourt Author URI: http://www.balencourt.com/blog/snap-my-roll */ include('functions.php'); function add_javascript(){ $js_url = get_option('siteurl') . '/wp-content/plugins/'. dirname( plugin_basename(__FILE__)) . '/js/'; wp_enqueue_script('jquery'); wp_enqueue_script('innerfade',$js_url."jquery.innerfade.js",array('jquery'),'1.0' ); } function snap_my_roll($size,$key,$category,$timeout){ global $wpdb; if($key == 'Enter your key'){ echo 'Please register to websnapr'; return; } //Transform seconds into milliseconds if($timeout < 1){ $timeout = 1000; }else{ $timeout = $timeout * 1000; } //Define dir & path to plugin components $snap_my_roll_url = dirname( __FILE__ ) . '/'; // Create SQL request & get links from DB according to category if($category){ $my_query = "SELECT ".$wpdb->prefix."links.link_name, ".$wpdb->prefix."links.link_url FROM ".$wpdb->prefix."term_relationships, ".$wpdb->prefix."links WHERE link_visible = 'Y' and ".$wpdb->prefix."links.link_id = ".$wpdb->prefix."term_relationships.object_id and ".$wpdb->prefix."term_relationships.term_taxonomy_id = $category"; }else{ $my_query = "SELECT ".$wpdb->prefix."links.link_name, ".$wpdb->prefix."links.link_url FROM ".$wpdb->prefix."links WHERE link_visible = 'Y'"; } $links = $wpdb->get_results($my_query, OBJECT); //Rand the the array of links and slice it to 20 elements to reduce loading time and ensure that all links have a chance if($links){ shuffle($links); if (count($links)>20){ $links = array_slice($links,0,20); } //build the javascript echo '\n"; //determine upload directory $directory = array(); $directory = wp_upload_dir(); $charset = get_option('blog_charset'); if (!is_writable($directory['basedir']. '/')){ echo("Wordpress upload directory is not writable"); return; } //create error image to compare them with file downloaded $queued = imagecreatefromjpeg($snap_my_roll_url.$size."queued.jpg"); $exceeded = imagecreatefrompng($snap_my_roll_url.$size."exceeded.png"); //echo "$snap_my_roll_url$size"."queued.jpg"; //lets print the list of images echo '
Widget Title:
'; echo 'Websnapr Key:
'; echo 'No Key ? Get One !Select a snapshot size
';
echo ' Tiny [92x70 pixels]
';
echo ' Small [202x152 pixels]
';
echo '
Not available for free
';
echo ' Medium [400x300 pixels]
Limit to one category of links
';
echo '
Diplay snapshot for seconds
'; echo ''; } register_sidebar_widget('Snap My Roll','widget_snap_my_roll'); register_widget_control('Snap My Roll','widget_snap_my_roll_options', 200, 300); } //Hooks add_action('plugins_loaded', 'widget_snap_my_roll_init'); add_action('get_header','add_javascript'); function snap_my_roll_deactivate(){ global $wpdb; remove_action('plugins_loaded', 'widget_snap_my_roll_init'); remove_action('get_header','add_javascript'); $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."options` WHERE `option_name` = 'snap_my_roll'")); } register_deactivation_hook( __FILE__, 'snap_my_roll_deactivate' ); ?>