get_results($my_query, OBJECT);
//Rand the the array and slice it to 12 elements
if($links){
shuffle($links);
if (count($links)>20){
$links = array_slice($links,0,20);
}
//build the javascript
echo "
\n\t";
echo '
'.$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 '