Пример #1
0
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && !isLocalhost()) {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit;
}
// Load the Facebook PHP SDK
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.
Пример #2
0
<?php

// We're ready to save?
if (isset($_REQUEST['submit']) && !empty($_REQUEST['reportee_id'])) {
    $report = new PATIncident(array('reporter_id' => $user_id, 'reportee_id' => $_REQUEST['reportee_id'], 'report_title' => $_REQUEST['report_title'], 'report_text' => $_REQUEST['report_text'], 'report_visibility' => $_REQUEST['report_visibility'], 'contactable' => $_REQUEST['communication_preference']));
    if ($report->fieldsValidate()) {
        if ($rid = $report->save()) {
            // get list of other people who have reported this reportee.
            $result = pg_query_params($db->getHandle(), 'SELECT DISTINCT reporter_id FROM incidents WHERE reportee_id = $1 AND reporter_id <> $2', array($report->reportee_id, $report->reporter_id));
            // Check those other people's notification preference.
            while ($row = pg_fetch_assoc($result)) {
                $usr = new PATFacebookUser($FB, $row['reporter_id']);
                $prefs = $usr->getPreferences();
                // If their notification preference is on,
                if ($prefs['notify_on_same_reportee']) {
                    $report->setReader($usr);
                    if ($report->isVisible()) {
                        // send each of them a notification.
                        $FB->setAccessToken(getFacebookAppToken());
                        $FB->api("/{$usr->getId()}/notifications", 'post', array('template' => 'More information was shared about someone you previously shared about; click here to read the statement.', 'href' => "reports.php?action=lookup&id={$rid}"));
                    }
                }
            }
            header('Location: ' . AppInfo::getUrl($_SERVER['PHP_SELF'] . "?action=lookup&id={$rid}"));
            exit;
        }
    }
}
?>
<section id="MainContent">
    <h1>Share</h1>