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'; } $plookup = array(); $linklookup = array(); $people = array(); $links = array(); //This person $person = getCachedPerson($pid); $pdata = extractPersonData($person, 0); $plookup[$pdata['id']] = 1; //Followees $followees = PlusPerson::FetchVisiblePlusPeople($person->googleplus_id); foreach ($followees as $followee) { $pdata = extractPersonData($followee, 1); if (!isset($plookup[$pdata['id']])) { $people[] = $pdata; $plookup[$pdata['id']] = 1; } } $data = array('person' => extractPersonData($person, 0), 'relationships' => $people); $responsedata = json_encode($data); //wrap jsonp if necessary if ($template['callback'] != "" && preg_match('/^\\w+$/', $template['callback'])) { $responsedata = $template['callback'] . '(' . $responsedata . ');'; } echo $responsedata; }
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; }