. Version: 0.9 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($title,$size,$key){ global $wpdb; //Define dir & path to plugin components $snap_my_roll_url = dirname( __FILE__ ) . '/'; //store links in an array $my_query = "SELECT link_name, link_url FROM wp_links WHERE link_visible = 'Y'"; $links = $wpdb->get_results($my_query, OBJECT); //rand the the array and slice it to 12 elements shuffle($links); if (count($links)>30){ $links = array_slice($links,0,29); } //build the javascript echo "
  • \n\t

    ".$title."

    \n"; //echo ''."\n"; //echo ''."\n"; echo '\n"; //determine upload directory $home = get_option('siteurl'); $directory = get_option('upload_path'); //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 '\n
  • "; } function widget_snap_my_roll_init() { if (!function_exists('register_sidebar_widget')) { return; } function widget_snap_my_roll($args) { extract($args); echo $before_widget . $before_title . $after_title; if(!$options = get_option('snap_my_roll')) $options = array('title'=>'Snap My Roll', 'size'=>'s', 'key'=>'Enter your key'); snap_my_roll($options['title'], $options['size'], $options['key']); echo $after_widget; } function widget_snap_my_roll_options() { if(!$options = get_option('snap_my_roll')) $options = array('title'=>'Snap My Roll', 'size'=>'s', 'key'=>'Enter your key'); if($_POST['snap_my_roll-submit']) { $options = array('title' => $_POST['snap_my_roll-title'], 'size' => $_POST['snap_my_roll-size'], 'key' => $_POST['snap_my_roll-key']); update_option('snap_my_roll', $options); } echo '

    Widget Title:

    '; echo '

    Websnapr Key:

    '; echo 'No Key ? Get One !

    '; echo '

    Select a snapshot size
    '; echo ' Tiny [92x70 pixels]
    '; echo ' Small [202x152 pixels]
    '; echo ' Medium [400x300 pixels]

    '; echo ''; } register_sidebar_widget('Snap My Roll','widget_snap_my_roll'); register_widget_control('Snap My Roll','widget_snap_my_roll_options', 200, 200); } //Hooks add_action('plugins_loaded', 'widget_snap_my_roll_init'); add_action('get_header','add_javascript'); ?>