public function __construct($FB, $who = 'me')
 {
     parent::__construct($FB, $who);
     $this->db = new PATFacebookDatabase('postgres');
     $this->db->connect(psqlConnectionStringFromDatabaseUrl());
     if (!($this->preferences = $this->loadPreferences())) {
         $this->createNewUser();
     }
     // Try again, should give us defaults now.
     $this->preferences = $this->loadPreferences();
 }
 function PATIncident($info)
 {
     $this->db = new PATFacebookDatabase('postgres');
     $this->db->connect(psqlConnectionStringFromDatabaseUrl());
     if (is_array($info)) {
         foreach ($info as $k => $v) {
             $this->{$k} = $v;
         }
         if (1 === count($info) && isset($this->id)) {
             $this->loadFromDatabase();
         }
     }
 }
Пример #3
0
require_once 'facebook/src/facebook.php';
// Load our own libraries.
require 'pat-fb/PATFacebookUser.class.php';
require 'pat-fb/PATIncident.class.php';
require 'pat-fb/template_functions.inc.php';
$FB = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret(), 'trustForwarded' => true));
$user_id = $FB->getUser();
if ($user_id) {
    try {
        // Fetch the viewer's basic information
        $me = new PATFacebookUser($FB);
        $me->loadFriends('id,name,gender,picture.type(square),bio,installed');
        $my_prefs = $me->getPreferences();
        date_default_timezone_set($my_prefs['user_timezone_name']);
    } catch (FacebookApiException $e) {
        error_log('Failed to set global variable $me.');
        error_log(serialize($e));
        // If the call fails we check if we still have a user. The user will be
        // cleared if the error is because of an invalid accesstoken
        if (!$FB->getAccessToken()) {
            header('Location: ' . AppInfo::getUrl($_SERVER['REQUEST_URI']));
            exit;
        }
    }
}
// Some global variables.
$FBApp = new AppInfo($FB->api('/' . AppInfo::appID()));
$db = new PATFacebookDatabase();
$db->connect(psqlConnectionStringFromDatabaseUrl());
// Links to "help" screens.
define('DOCUMENTATION_URL_BASE', 'https://github.com/meitar/pat-facebook/wiki');