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 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";
//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");
//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['basedir'] .'/'.sanitize_filename($link->link_url."_".$size.".png");
$img_url = $directory['baseurl'] .'/'.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)){
imagepng($i,$img_file,0);
}else{
continue;
}
}
echo '