Exemplo n.º 1
0
function PageMain()
{
    global $template, $templatesdir, $includesdir, $config;
    //Do any page logic here.
    //If $using_db is set in standard_page_logic.inc the global $db
    //will be set. Most db queries should be done in a class library, though.
    //This simple example does stuff internally. For complicated json, you
    //might be better off making a json template in templates/js
    $template['callback'] = getVar('callback');
    $template['echo'] = getVar('echo');
    if ($template['callback'] != "" && preg_match('/^\\w+$/', $template['callback'])) {
        //use jsonp
        header('Content-type: text/javascript');
    } else {
        //standard json
        header('Content-type: application/json');
    }
    $pid = getVar('plusid');
    if ($pid == "") {
        $pid = '109463793347920104139';
    }
    $person = new PlusPerson();
    $person->loadByGooglePlusID($pid);
    if ($person->plusperson_id == 0) {
        $person->googleplus_id = $pid;
        $person->updateFromGooglePlusService();
        $person->insertIntoDB();
    } else {
        if (strtotime($person->modified_dt) < strtotime("-6 hours")) {
            $person->updateFromGooglePlusService();
            $person->fetched_relationships = 0;
            $person->updateDB();
        }
    }
    //Get the posts from G+
    $posts = PlusPost::FetchActivityStream($person->googleplus_id);
    //Save them all into the DB (merge will try to update them if they exist already)
    foreach ($posts as $post) {
        $post->mergeStreamPostIntoDB();
    }
    $postsdata = array();
    foreach ($posts as $post) {
        $data = array('googleplus_postid' => $post->googleplus_postid, 'author_id' => $post->author_id, 'post_data' => $post->post_data, 'share_content' => $post->share_content, 'shared_postid' => $post->shared_postid);
        $postsdata[] = $data;
    }
    $persondata = array('googleplus_id' => $person->googleplus_id, 'first_name' => $person->first_name, 'last_name' => $person->last_name, 'profile_photo' => $person->profile_photo, 'introduction' => $person->introduction, 'subhead' => $person->subhead);
    $data = array('plusperson' => $persondata, 'posts' => $postsdata);
    $responsedata = json_encode($data);
    //wrap jsonp if necessary
    if ($template['callback'] != "" && preg_match('/^\\w+$/', $template['callback'])) {
        $responsedata = $template['callback'] . '(' . $responsedata . ');';
    }
    echo $responsedata;
}
Exemplo n.º 2
0
function getCachedPerson($pid)
{
    $person = new PlusPerson();
    $person->loadByGooglePlusID($pid);
    if ($person->plusperson_id == 0) {
        $person->googleplus_id = $pid;
        $person->updateFromGooglePlusService();
        $person->insertIntoDB();
    } else {
        if (strtotime($person->modified_dt) < strtotime("-6 hours")) {
            $person->updateFromGooglePlusService();
            $person->fetched_relationships = 0;
            $person->updateDB();
        }
    }
    return $person;
}
Exemplo n.º 3
0
function PageMain()
{
    global $template, $templatesdir, $includesdir, $config;
    //Do any page logic here.
    //If $using_db is set in standard_page_logic.inc the global $db
    //will be set. Most db queries should be done in a class library, though.
    $template['title'] = 'PlusActivity API Test';
    $pid = getVar('plusid');
    if ($pid == "") {
        $pid = '109463793347920104139';
    }
    $person = new PlusPerson();
    $person->loadByGooglePlusID($pid);
    if ($person->plusperson_id == 0) {
        $person->googleplus_id = $pid;
        $person->updateFromGooglePlusService();
        $person->insertIntoDB();
    } else {
        if (strtotime($person->modified_dt) < strtotime("-6 hours")) {
            $person->updateFromGooglePlusService();
            $person->updateDB();
        }
    }
    $template['title'] = $person->first_name . " " . $person->last_name . " // " . $template['title'];
    //Get the posts from G+
    $posts = PlusPost::FetchActivityStream($person->googleplus_id);
    //Save them all into the DB (merge will try to update them if they exist already)
    foreach ($posts as $post) {
        $post->mergeStreamPostIntoDB();
    }
    //Pull them back out of the db for display
    $posts = PlusPost::FetchPostsByGooglePlusID($person->googleplus_id);
    $template['person'] = $person;
    $template['posts'] = $posts;
    require_once $templatesdir . 'pages/tests/plusactivity.inc';
}
Exemplo n.º 4
0
function PageMain()
{
    global $template, $templatesdir, $includesdir, $config;
    //Do any page logic here.
    //If $using_db is set in standard_page_logic.inc the global $db
    //will be set. Most db queries should be done in a class library, though.
    $template['title'] = 'PlusUser API Test';
    $pid = getVar('plusid');
    if ($pid == "") {
        $pid = '109463793347920104139';
    }
    $person = new PlusPerson();
    $person->loadByGooglePlusID($pid);
    if ($person->plusperson_id == 0) {
        $person->googleplus_id = $pid;
        $person->updateFromGooglePlusService();
        $person->insertIntoDB();
    } else {
        if (strtotime($person->modified_dt) < strtotime("-6 hours")) {
            $person->updateFromGooglePlusService();
            $person->fetched_relationships = 0;
            $person->updateDB();
        }
    }
    $template['title'] = $person->first_name . " " . $person->last_name . " // " . $template['title'];
    $hascircled = array();
    $circledby = array();
    if ($person->fetched_relationships != 1) {
        $followees = PlusPerson::FetchVisiblePlusPeople($person->googleplus_id);
        $followers = PlusPerson::FetchIncomingPlusPeople($person->googleplus_id);
        $or = PlusRelationship::FetchRelationshipsByOwner($person->googleplus_id);
        foreach ($or as $r) {
            $r->deleteFromDB();
        }
        $cr = PlusRelationship::FetchRelationshipsByCircled($person->googleplus_id);
        foreach ($cr as $r) {
            $r->deleteFromDB();
        }
        //These could be easily sped up with a map that loads all existing in one db hit.
        //Leaving as-is to improve readability for demo.
        foreach ($followees as $fp) {
            $pid = $fp->googleplus_id;
            $fp->loadByGooglePlusID($pid);
            if ($fp->plusperson_id <= 0) {
                $fp->googleplus_id = $pid;
                $fp->updateFromGooglePlusService();
                $fp->insertIntoDB();
            }
            $hascircled[] = $fp;
            $rel = new PlusRelationship();
            $rel->owner_id = $person->googleplus_id;
            $rel->hasincircle_id = $fp->googleplus_id;
            $rel->insertIntoDB();
        }
        //Some people are circled by a ton of other people.
        //Let's not fetch these profiles if they aren't already cached.
        foreach ($followers as $fp) {
            $pid = $fp->googleplus_id;
            $fp->loadByGooglePlusID($pid);
            if ($fp->plusperson_id <= 0) {
                $fp->googleplus_id = $pid;
            }
            $circledby[] = $fp;
            $rel = new PlusRelationship();
            $rel->owner_id = $fp->googleplus_id;
            $rel->hasincircle_id = $person->googleplus_id;
            $rel->insertIntoDB();
        }
        $person->fetched_relationships = 1;
        $person->updateDB();
    } else {
        $or = PlusRelationship::FetchRelationshipsByOwner($person->googleplus_id);
        foreach ($or as $r) {
            $p = new PlusPerson();
            $p->loadByGooglePlusID($r->hasincircle_id);
            if ($p->plusperson_id <= 0) {
                $p->googleplus_id = $r->hasincircle_id;
            }
            $hascircled[] = $p;
        }
        $cr = PlusRelationship::FetchRelationshipsByCircled($person->googleplus_id);
        foreach ($cr as $r) {
            $p = new PlusPerson();
            $p->loadByGooglePlusID($r->owner_id);
            if ($p->plusperson_id <= 0) {
                $p->googleplus_id = $r->owner_id;
            }
            $circledby[] = $p;
        }
    }
    $template['person'] = $person;
    $template['circledby'] = $circledby;
    $template['hascircled'] = $hascircled;
    require_once $templatesdir . 'pages/tests/plususer.inc';
}
Exemplo n.º 5
0
function getCachedCircled($person)
{
    $circled = array();
    if ($person->fetched_relationships != 1) {
        $followees = PlusPerson::FetchVisiblePlusPeople($person->googleplus_id);
        $or = PlusRelationship::FetchRelationshipsByOwner($person->googleplus_id);
        foreach ($or as $r) {
            $r->deleteFromDB();
        }
        foreach ($followees as $fp) {
            $pid = $fp->googleplus_id;
            $followee = getCachedPerson($pid);
            $circled[] = $followee;
            $rel = new PlusRelationship();
            $rel->owner_id = $person->googleplus_id;
            $rel->hasincircle_id = $followee->googleplus_id;
            $rel->insertIntoDB();
        }
        $person->fetched_relationships = 1;
        $person->updateDB();
    } else {
        $or = PlusRelationship::FetchRelationshipsByOwner($person->googleplus_id);
        foreach ($or as $r) {
            $p = new PlusPerson();
            $p->loadByGooglePlusID($r->hasincircle_id);
            if ($p->plusperson_id <= 0) {
                $p->googleplus_id = $r->hasincircle_id;
            }
            $circled[] = $p;
        }
    }
    return $circled;
}