.
Version: 0.8
Author: Denis Balencourt
Author URI: http://www.balencourt.com/blog/snap-my-roll
*/
include('functions.php');
function snap_my_roll($title,$size,$key){
global $wpdb;
$snap_my_roll_url = get_option('siteurl') . '/wp-content/plugins/snap-my-roll/';
$js_url = get_option('siteurl') . '/wp-content/plugins/snap-my-roll/' . 'js/';
//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";
foreach($links as $link){
$img_file = $directory .'/'.sanitize_filename($link->link_url."_".$size.".png");
// If file does not exist or is older than a week update it
if(!file_exists($img_file) || time() - fileatime($img_file) > 864000 ){
$f = curl_get_file_contents('http://images.websnapr.com/?size='.$size.'&key='.$key.'&url='.rawurlencode($link->link_url));
$i = imagecreatefromstring($f);
if(!imagecompare($i,$queued) && !imagecompare($i,$exceeded)){
// if(!imagecompare($i,$queued)){
imagepng($i,$img_file,0);
}else{
continue;
}
}
echo '