$tmpPoint = generatePointArround($lat1, $lon1, $range);
    $point->set($tmpPoint->lat, $tmpPoint->lng);
    $flag = isItWatter($point->lat, $point->lng);
    if ($flag == 1) {
        echo '<br>IN WATTER';
    } else {
        echo '<br>IN LAND';
    }
    if ($i > 10) {
        return;
    } else {
        $i++;
    }
}
// WEB LINK
echo "<br>ZONE" . $zone . "<br>";
$webArray = array("http://www.lemonde.fr/", "http://www.liberation.fr/", "http://lefigaro.fr/", "http://www.rue89.com/", "http://www.lesechos.fr/", "http://www.journaldunet.com/", "http://www.guardian.co.uk/", "http://www.washingtonpost.com/", "http://www.thetimes.co.uk/tto/news/", "http://www.huffingtonpost.fr/", "http://www.mediapart.fr/", "http://www.bakchich.info/", "http://www.slate.fr/", "http://www.20minutes.fr/", "http://www.arretsurimages.net/", "http://owni.fr/", "http://www.agoravox.fr/", "http://www.20minutes.fr/actus", "http://www.lexpress.fr/", "http://www.afp.com/", "http://www.monde-diplomatique.fr/");
$weburl = $webArray[rand(0, sizeof($webArray) - 1)];
$thumb = getApercite($weburl);
// TYPE
//$yakType = rand(1,4);
$yakType = 4;
$record = array("title" => $title, "content" => $content, "outGoingLink" => $weburl, "thumb" => $thumb, "origin" => "random generator", "access" => 2, "licence" => "reserved", "heat" => 80, "yakCat" => array(), "yakCatName" => array(), "freeTag" => array("yakwala"), "yakType" => $yakType, "pubDate" => new MongoDate(gmmktime()), "creationDate" => new MongoDate(gmmktime()), "lastModifDate" => new MongoDate(gmmktime()), "dateEndPrint" => new MongoDate(gmmktime() + 3 * 60 * 60), "print" => 1, "status" => 1, "user" => 0, "zone" => 1, "location" => array('lat' => $point->lat, 'lng' => $point->lng), "address" => "", "placeId" => new MongoId("506a9e011d22b3457800001e"));
//var_dump($record);
$info->save($record);
$info->ensureIndex(array("location" => "2d"));
$info->ensureIndex(array("yakType" => 1, "print" => 1, "status" => 1, "pubDate" => -1));
$info->ensureIndex(array("yakType" => 1, "print" => 1, "status" => 1, "pubDate" => -1, "user" => 1, "freeTag" => 1));
echo "<br>SAVE : " . $record['_id'];
echo $title . ' ' . $point->lat . ' , ' . $point->lng;
echo "<br><br>------------------To remove random data, call : ?cleanRandomInfo=1";
                     } else {
                         $thumb = "";
                         $thumbFlag = 0;
                     }
                 } else {
                     $size = getimagesize($img[0]);
                     if ($size[0] > 320) {
                         $thumbFlag = 2;
                     } else {
                         $thumbFlag = 1;
                     }
                     $thumb = $res;
                 }
             } else {
                 if (!empty($outGoingLink) && $outGoingLink[0] != "") {
                     $thumb = getApercite($outGoingLink, $conf);
                     $logPushToS3++;
                     $logCallToApercite++;
                     $thumbFlag = 1;
                 } else {
                     $thumb = "";
                     $thumbFlag = 0;
                 }
             }
         }
     }
 }
 // overwrite if set in the feed
 if (!empty($feed['thumbFlag'])) {
     $thumbFlag = $feed['thumbFlag'];
 }
Beispiel #3
0
function getApercite($link, $conf, $iter = 0)
{
    $iter++;
    echo '<br> Call Apercite';
    $imgName = md5($link) . '.jpg';
    //$fullpath = "thumb/".$imgName;
    $fullpath = ${$conf}->thumbpath() . $imgName;
    $img = "http://www.apercite.fr/api/apercite/120x90/oui/oui/" . $link;
    $ch = curl_init($img);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    $rawdata = curl_exec($ch);
    curl_close($ch);
    // check if the image is not in creation process with apercite
    $creationImgSignature = md5(file_get_contents($conf->batchthumbpath() . '120x90.jpg'));
    $infoImgSignature = md5($rawdata);
    if ($creationImgSignature == $infoImgSignature && $iter < 10) {
        echo '<br>IMG UNDER CREATION';
        sleep(20);
        getApercite($link, $conf, 1);
    } else {
        if (file_exists($fullpath)) {
            unlink($fullpath);
        }
        $fp = fopen($fullpath, 'x');
        fwrite($fp, $rawdata);
        fclose($fp);
        $s3 = new AmazonS3();
        if (file_exists($fullpath)) {
            $response = $s3->create_object($conf->bucket(), '120_90/' . $imgName, array('fileUpload' => $fullpath, 'contentType' => 'image/jpeg', 'acl' => AmazonS3::ACL_PUBLIC));
        }
        if ($response->status == 200) {
            unlink($fullpath);
        }
    }
    return $imgName;
}