示例#1
0
    $expiryInterval = 60 * 60;
    // someone tried to search 1 hr ago, 1 hr is where fb updates quotas
    if (fileValid($bucket, $token, $expiryInterval)) {
        // someone else is searching, so retrieve existing file
        // XXX: IF I forcefully remove this events file, and if token says someone else is searching, then
        // console will have an error saying 404 (file not found). This will go to client and client says
        // (I print in jsonStore function) that client has a problem try later. This should be ok. Just
        // forcefully remove token file to start search.
        retrieveFile($bucket, $file);
        // if this fails, do nothing
    } else {
        // either token is not there, or its old and carried over from previous search
        // or someone created token, tried to search but aborted search
        // renew token
        $content = "foo";
        if (storeGCS($content, $bucket, $token) != 0) {
            $msg = 'zouk calendar: failed to store token ' . $file;
            syslog(LOG_EMERG, $msg);
            sendMail($msg);
        }
        // file not valid, send json object as error
        echo "{ \"error\": \"zouk calendar: file not found\" }";
    }
} else {
    if ($type == 'cache') {
        // check if cache is expired
        $valStr = (string) $_GET['value'];
        $tuples = json_decode($valStr);
        if (count($tuples) < 3) {
            $retVal = json_encode(array('result' => false));
            echo $retVal;
示例#2
0
// $buckets = $storage->buckets->listBuckets($projectId);
//
// foreach ($buckets['items'] as $bucket) {
//     printf("%s\n", $bucket->getName());
//     syslog(LOG_INFO, $bucket->getName());
// }
/** Get tokens already stored **/
$tokensStr = retrieveGCS($bucket, $tokenFile);
if (empty($tokensStr)) {
    $tokens = array();
} else {
    $tokens = json_decode($tokensStr, true);
    // 'true' will turn this into associative array instead of object
}
// Limit size of array to 50
if (count($tokens) > 50) {
    array_shift($tokens);
    // remove one element from beginning
}
// add the new token to end of array
array_push($tokens, $longLivedAccessToken);
//var_dump($tokens);
/***
 * Write file to Google Storage
 */
$fileContent = json_encode($tokens);
//var_dump($fileContent);
//echo $fileContent;
if (storeGCS($fileContent, $bucket, $tokenFile) !== 0) {
    syslog(LOG_ERR, "Failed to store " . $tokenFile);
}
    }
}
if ($proceed) {
    if (fileExists($bucket, $pagesFile)) {
        $mTime = lastModifiedTime($bucket, $pagesFile);
        $date = new DateTime();
        $curTime = $date->getTimestamp();
        if ($curTime - $mTime < $interval) {
            $proceed = false;
        }
    }
}
if ($proceed) {
    $pages = array();
    fbBatchSearch($pages, $fb, $pageSearchStrings, 'nextFullBatchPages', 'validatePage');
    $pagesContent = json_encode($pages);
    if (storeGCS($pagesContent, $bucket, $pagesFile) != 0) {
        syslog(LOG_ERR, "Failed to store " . $pagesFile);
    }
    if (count($pages) > 0) {
        $events = array();
        fbSearchPageEvents($fb, $events, $pages);
        if (count($events) > 0) {
            $pageEventsContent = json_encode($events);
            if (storeGCS($pageEventsContent, $bucket, $pageEventsFile) != 0) {
                syslog(LOG_ERR, "Failed to store " . $pageEventsFile);
            }
        }
    }
}
//    echo "{ \"error\": \"zouk calendar: file not found\" }";