Skip to content

Commit

Permalink
fixed white screen on install
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed May 1, 2009
1 parent f8aa364 commit ae9091c
Show file tree
Hide file tree
Showing 26 changed files with 4,048 additions and 226 deletions.
1 change: 1 addition & 0 deletions app/facebook/Services/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PEAR package for interfacing with Facebook's API.
230 changes: 230 additions & 0 deletions app/facebook/Services/Services/Facebook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?php

/**
* PHP5 interface for Facebook's REST API
*
* PHP version 5.1.0+
*
* LICENSE: This source file is subject to the New BSD license that is
* available through the world-wide-web at the following URI:
* http://www.opensource.org/licenses/bsd-license.php. If you did not receive
* a copy of the New BSD License and are unable to obtain it through the web,
* please send a note to license@php.net so we can mail you a copy immediately.
*
* @category Services
* @package Services_Facebook
* @author Joe Stump <joe@joestump.net>
* @copyright 2007-2008 Joe Stump <joe@joestump.net>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/Services_Facebook
*/

require_once 'Services/Facebook/Common.php';
require_once 'Services/Facebook/Exception.php';

/**
* Services_Facebook
*
* @category Services
* @package Services_Facebook
* @author Joe Stump <joe@joestump.net>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://wiki.developers.facebook.com
*/
class Services_Facebook
{
/**
* Facebook API URL
*
* @var string $apiURL URL that that API calls will be sent to
* @static
*/
static public $apiURL = 'http://api.new.facebook.com/restserver.php';

/**
* Facebok application API key
*
* @var string $apiKey 32 character api_key from Facebook
* @static
*/
static public $apiKey = '';

/**
* Facebok application secret
*
* The Facebook secret token is used to both sign requests sent to
* Facebook and to verify requests sent from Facebook to your application.
*
* @var string $secret 32 character secret from Facebook
* @static
*/
static public $secret = '';

/**
* Timeout
*
* The amount in seconds for the curl http request timeout
*
* @var string $timeout Time in seconds for a request to timeout
* @static
*/
static public $timeout = 30;

/**
* Currently logged in user
*
* @var string $sessionKey
*/
public $sessionKey = '';

/**
* Instances of various drivers
*
* @var array $instances
*/
static protected $instances = array();

/**
* Instance of Services_Facebook
*
* @var Services_Facebook $instance
* @see Services_Facebook::singleton();
*/
static protected $instance;

/**
* Available drivers
*
* @var array $drivers
*/
static protected $drivers = array(
'admin' => 'Admin',
'application' => 'Application',
'auth' => 'Auth',
'connect' => 'Connect',
'data' => 'Data',
'events' => 'Events',
'fbml' => 'FBML',
'fql' => 'FQL',
'feed' => 'Feed',
'friends' => 'Friends',
'groups' => 'Friends',
'marketplace' => 'MarketPlace',
'notifications' => 'Notifications',
'pages' => 'Pages',
'photos' => 'Photos',
'profile' => 'Profile',
'share' => 'Share',
'users' => 'Users'
);

/**
* Create a facebook service
*
* @param string $endPoint Services to create
*
* @return object Instance of Facebook endpoint
* @throws Services_Facebook_Exception
*/
static protected function factory($endPoint)
{
$file = 'Services/Facebook/' . $endPoint . '.php';
include_once $file;
$class = 'Services_Facebook_' . $endPoint;
if (!class_exists($class)) {
throw new Services_Facebook_Exception('Class not found ' . $class);
}

$instance = new $class();
return $instance;
}

/**
* Singleton
*
* @return Services_Facebook
*/
static public function singleton()
{
if (self::$instance !== null) {
return self::$instance;
}

$instance = new Services_Facebook();
self::$instance = $instance;

return $instance;
}

/**
* Lazy loader for Facebook drivers
*
* @param string $driver The Facebook driver/endpoint to load
*
* @throws Services_Facebook_Exception
* @return object
*/
public function __get($driver)
{
$driver = strtolower($driver);
if (!isset(self::$drivers[$driver])) {
throw new Services_Facebook_Exception(
'The driver requested, ' . $driver . ', is not supported'
);
} else {
$driver = self::$drivers[$driver];
}

if (isset(self::$instances[$driver])) {
return self::$instances[$driver];
}

self::$instances[$driver] = self::factory($driver);
self::$instances[$driver]->sessionKey = $this->sessionKey;
return self::$instances[$driver];
}

/**
* Validates requests from Facebook
*
* Facebook sends a series of $_POST variables when it requests a canvas
* page or sends a user to the post removal URL. This function validates
* that request came from Facebook. This function returns true if the
* request came from Facebook.
*
* Both the signature of the request and the api_key is verified. If the
* api_key given doesn't match up to the current Services_Facebook::$apiKey
* then it will return false.
*
* @param array $args Normally the $_POST array
*
* @return boolean True if the request signature is valid
*/
static public function isValidRequest($args)
{
if ($args['fb_sig_api_key'] != Services_Facebook::$apiKey) {
return false;
}

ksort($args);

$sig = '';
foreach ($args as $k => $v) {
if ($k == 'fb_sig') {
continue;
}

// The signature is based on fb_sig_* fields only. Extra POST
// args are passed along, but don't alter the signature.
if (preg_match('/^fb_sig_/', $k)) {
$sig .= substr($k, 7) . '=' . $v;
}
}

return (md5($sig . Services_Facebook::$secret) == $args['fb_sig']);
}
}

?>
146 changes: 146 additions & 0 deletions app/facebook/Services/Services/Facebook/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

/**
* PHP5 interface for Facebook's REST API
*
* PHP version 5.1.0+
*
* LICENSE: This source file is subject to the New BSD license that is
* available through the world-wide-web at the following URI:
* http://www.opensource.org/licenses/bsd-license.php. If you did not receive
* a copy of the New BSD License and are unable to obtain it through the web,
* please send a note to license@php.net so we can mail you a copy immediately.
*
* @category Services
* @package Services_Facebook
* @author Joe Stump <joe@joestump.net>
* @copyright 2007-2008 Joe Stump <joe@joestump.net>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/Services_Facebook
*/


/**
* Facebook Admin Interface
*
* <code>
* <?php
* require_once 'Services/Facebook.php';
* $api = new Services_Facebook();
* echo 'Notifications that we can send per day, behalf
* of a user: ' . $api->admin->getNotificationsPerDay() . '<br />';
* echo 'Requests that we can send per day, behalf of a user: ' .
* $api->admin->getRequestsPerDay(). '<br />';
* ?>
* </code>
*
* @category Services
* @package Services_Facebook
* @author Jeff Hodsdon <jeffhodsdon@gmail.com>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://wiki.developers.facebook.com
*/
class Services_Facebook_Admin extends Services_Facebook_Common
{
/**
* Default application property fields
*
* @link http://wiki.developers.facebook.com/index.php/ApplicationProperties
*/
protected $applicationFields = array(
'application_name', 'callback_url', 'post_install_url', 'edit_url',
'dashboard_url', 'uninstall_url', 'ip_list', 'email', 'description',
'use_iframe', 'desktop', 'is_mobile', 'default_fbml', 'default_column',
'message_url', 'message_action', 'about_url', 'private_install',
'installable', 'privacy_url', 'help_url', 'see_all_url', 'tos_url',
'dev_mode', 'preload_fql'
);

/**
* Gets property values previously set for an application.
*
* @param array $properties The properties to get, default is all
*
* @return array Array with all requested properties
*
* @link http://wiki.developers.facebook.com/index.php/Admin.getAppProperties
*/
public function getAppProperties($properties = array())
{
if (!count($properties)) {
$properties = $this->applicationFields;
}

//FB accepts the app properties as a json array
$jsonProperties = json_encode($properties);

$result = $this->callMethod('admin.getAppProperties', array(
'properties' => $jsonProperties
));

//The response from Facebook is in JSON
return json_decode((string)$result);
}

/**
* Sets multiple properties for an application.
*
* @param array $properties Property / value assocative array of properties
*
* @return boolean True on success
*
* @link http://wiki.developers.facebook.com/index.php/Admin.setAppProperties
*/
public function setAppProperties($properties = array())
{
$jsonArray = array();
foreach ($properties as $property => $value) {
if (in_array($property, $this->applicationFields)) {
$jsonArray[$property] = $value;
}
}
$jsonProperties = json_encode($jsonArray);

$result = $this->callMethod('admin.setAppProperties', array(
'properties' => $jsonProperties
));

return (intval((string) $result) == 1);
}


/**
* Get the number of notifications your application can send on
* behalf of a user per day.
*
* @return int Number of notifications
*
* @link http://wiki.developers.facebook.com/index.php/Admin.getAllocation
*/
public function getNotificationsPerDay()
{
return (int)$this->callMethod('admin.getAllocation', array(
'session_key' => $this->sessionKey,
'integration_point_name' => 'notifications_per_day'
));
}

/**
* Get the number of requests your application can send on behalf
* of a user per day.
*
* @return int Number of requests
*
* @link http://wiki.developers.facebook.com/index.php/Admin.getAllocation
**/
public function getRequestsPerDay()
{
return (int)$this->callMethod('admin.getAllocation', array(
'session_key' => $this->sessionKey,
'integration_point_name' => 'requests_per_day'
));
}

}

0 comments on commit ae9091c

Please sign in to comment.