├── README.txt ├── block_course_publish.php ├── composer.json ├── db ├── access.php ├── install.php └── install.xml ├── edit_form.php ├── facebook-php-sdk-v4-4.0-dev ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── autoload.php ├── composer.json ├── phpunit.xml.dist └── src │ └── Facebook │ ├── Entities │ ├── AccessToken.php │ └── SignedRequest.php │ ├── FacebookAuthorizationException.php │ ├── FacebookCanvasLoginHelper.php │ ├── FacebookClientException.php │ ├── FacebookJavaScriptLoginHelper.php │ ├── FacebookOtherException.php │ ├── FacebookPageTabHelper.php │ ├── FacebookPermissionException.php │ ├── FacebookPermissions.php │ ├── FacebookRedirectLoginHelper.php │ ├── FacebookRequest.php │ ├── FacebookRequestException.php │ ├── FacebookResponse.php │ ├── FacebookSDKException.php │ ├── FacebookServerException.php │ ├── FacebookSession.php │ ├── FacebookSignedRequestFromInputHelper.php │ ├── FacebookThrottleException.php │ ├── GraphAlbum.php │ ├── GraphLocation.php │ ├── GraphObject.php │ ├── GraphPage.php │ ├── GraphSessionInfo.php │ ├── GraphUser.php │ ├── GraphUserPage.php │ └── HttpClients │ ├── FacebookCurl.php │ ├── FacebookCurlHttpClient.php │ ├── FacebookGuzzleHttpClient.php │ ├── FacebookHttpable.php │ ├── FacebookStream.php │ ├── FacebookStreamHttpClient.php │ └── certs │ └── DigiCertHighAssuranceEVRootCA.pem ├── image └── nopic.jpg ├── lang └── en │ └── block_course_publish.php ├── postlink.php ├── thirdpartylibs.xml └── version.php /README.txt: -------------------------------------------------------------------------------- 1 | Overview 2 | 3 | This plugin publishes a course link to a particular Facebook page. 4 | After create a course admin can add course_publish block in course page. 5 | Click "Login with Facebook" link and the course link "/course/view.php?id=?" is published in particular page. 6 | Using 7 | Some setting is require for this Block to publish course link. 8 | Setting Panel of block 9 | App ID, Secret Key, Message, Caption, Picture, Pageaccesstoken, Pageid set by site admin. 10 | 11 | Create a Facebook page 12 | 13 | 1. Go to facebook.com/pages/create. 14 | 2. Click to choose a Page category. 15 | 3. Select a more specific category from the dropdown menu and fill out the required information. 16 | 4. Click Get Started and follow the on-screen instructions. 17 | 18 | Facebook Application Setting 19 | 20 | Step 1: Goto https://developers.facebook.com/ > Login with you facebook account > 21 | Goto My Apps > Click Add a New app > Goto Facebook Canvas > 22 | Insert name of App > Choose category > Click create app id > Goto your created app 23 | Step 2: Goto settings > Enter Namespace > Enter App Domains > Enter Contact Email > 24 | Click add platform > Select website > Enter Site URL > Save changes. 25 | Step 3: Go To Status and review > Make this app visible to all. 26 | 27 | Graph API Explorer Setting 28 | 29 | Go To Tool & Support > Click on graph API Explorer > 30 | Select your app name from drop down list of graph API explorer > 31 | Copy Access token and paste it to "pageaccesstoken" field in block course_publish configuration page. 32 | Uninstall 33 | 34 | Admin can uninstall this admin tool from Site administration > Plugins > Blocks > Manage Blocks 35 | 36 | 37 | 38 | To install, place all files in /blocks/course_publish and visit /admin/index.php in your browser. 39 | 40 | This block is written by Dualcube 41 | -------------------------------------------------------------------------------- /block_course_publish.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | defined('MOODLE_INTERNAL') || die(); 18 | require_once($CFG->dirroot.'/blocks/course_publish/facebook-php-sdk-v4-4.0-dev/autoload.php'); 19 | use Facebook\FacebookSession; 20 | use Facebook\FacebookRedirectLoginHelper; 21 | /** 22 | * Course_publish block caps. 23 | * 24 | * @package block_course_publish 25 | * @author Sandipa Mukherjee 26 | * @copyright 2015 DUALCUBE {@link http://dualcube.com/} 27 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 28 | */ 29 | class block_course_publish extends block_base { 30 | 31 | /** 32 | * This is essential for all blocks, and its purpose is to give values to any class member variables that need instantiating. 33 | */ 34 | public function init() { 35 | $this->title = get_string('pluginname', 'block_course_publish'); 36 | } 37 | /** 38 | * Get block to actually display something on screen, we need to add this method to our class 39 | */ 40 | public function get_content() { 41 | global $CFG, $OUTPUT, $COURSE, $DB; 42 | $ischeck = ""; 43 | if ($this->content !== null) { 44 | return $this->content; 45 | } 46 | if (empty($this->instance)) { 47 | $this->content = ''; 48 | return $this->content; 49 | } 50 | $this->content = new stdClass(); 51 | $this->content->items = array(); 52 | $this->content->icons = array(); 53 | $this->content->text = ''; 54 | $this->content->footer = ''; 55 | $record = new stdClass(); 56 | $record->courseid = $COURSE->id; 57 | $record->link = $CFG->wwwroot."/course/view.php?id=".$COURSE->id; 58 | $record->callbackurl = $CFG->wwwroot."/blocks/course_publish/postlink.php?courseid=".$COURSE->id; 59 | $currentcontext = $this->page->context->get_course_context(false); 60 | 61 | if (! empty($this->config->text)) { 62 | $this->content->text = $this->config->text; 63 | } 64 | if (empty($currentcontext)) { 65 | return $this->content; 66 | } 67 | if ($this->page->course->id == SITEID) { 68 | $this->context->text .= "site context"; 69 | } 70 | if (! empty($this->config->text)) { 71 | $this->content->text .= $this->config->text; 72 | } 73 | if (! empty($this->config->appid)) { 74 | $record->appid = $this->config->appid; 75 | } 76 | if (! empty($this->config->secretkey)) { 77 | $record->secretkey = $this->config->secretkey; 78 | } 79 | if (! empty($this->config->message)) { 80 | $record->message = $this->config->message; 81 | } 82 | if (! empty($this->config->pageaccesstoken)) { 83 | $record->pageaccesstoken = $this->config->pageaccesstoken; 84 | } 85 | if (! empty($this->config->pageid)) { 86 | $record->pageid = $this->config->pageid; 87 | } 88 | if (! empty($this->config)) { 89 | $ischeck = $DB->get_record('block_course_publish', array('courseid' => $COURSE->id)); 90 | if (empty($ischeck)) { 91 | $lastinsertid = $DB->insert_record('block_course_publish', $record, false); 92 | } else { 93 | $record->id = $ischeck->id; 94 | $DB->update_record('block_course_publish', $record, $bulk = false); 95 | } 96 | } 97 | $ischeck = $DB->get_record('block_course_publish', array('courseid' => $COURSE->id)); 98 | if ($ischeck) { 99 | $helper = new FacebookRedirectLoginHelper($ischeck->callbackurl, $appid = $ischeck->appid, 100 | $appsecret = $ischeck->secretkey); 101 | $this->content->text .= html_writer::link($helper->getLoginUrl(), 102 | get_string('loginwithfacebook', 'block_course_publish')); 103 | } 104 | return $this->content; 105 | } 106 | /** 107 | * Some blocks are useful in some circumstances, but not in others. 108 | */ 109 | public function applicable_formats() { 110 | return array('all' => false, 'site' => true, 'site-index' => true, 'course-view' => true); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "danielneis/moodle-block_newblock", 3 | "description": "A block template for Moodle based on http://docs.moodle.org/dev/Blocks", 4 | "license": "GPLv3", 5 | "authors": [ 6 | { 7 | "name": "Daniel Neis Araujo", 8 | "email": "danielneis@gmail.com" 9 | } 10 | ], 11 | "type": "moodle-block", 12 | "require": { 13 | "composer/installers": "~1.0" 14 | }, 15 | "extra": { 16 | "installer-name": "newblock" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /db/access.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Course_publish block caps. 19 | * 20 | * @package block_course_publish 21 | * @author Sandipa Mukherjee 22 | * @copyright DUALCUBE {@link http://dualcube.com/} 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | $capabilities = array( 29 | 'block/course_publish:addinstance' => array( 30 | 'riskbitmask' => RISK_SPAM | RISK_XSS, 31 | 'captype' => 'write', 32 | 'contextlevel' => CONTEXT_BLOCK, 33 | 'archetypes' => array( 34 | 'editingteacher' => CAP_ALLOW, 35 | 'manager' => CAP_ALLOW 36 | ), 37 | 'clonepermissionsfrom' => 'moodle/site:manageblocks' 38 | ), 39 | ); 40 | -------------------------------------------------------------------------------- /db/install.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Feedback block installation Course_publish block caps. 18 | * @package block_course_publish 19 | * @author Sandipa Mukherjee 20 | * @copyright DUALCUBE {@link http://dualcube.com/} 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | /** 24 | * return the form 25 | */ 26 | function xmldb_block_course_publish_install() { 27 | global $DB, $CFG; 28 | } -------------------------------------------------------------------------------- /db/install.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 |
-------------------------------------------------------------------------------- /edit_form.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Course_publish block caps. 19 | * 20 | * @package block_course_publish 21 | * @author Sandipa Mukherjee 22 | * @copyright 2015 DUALCUBE {@link http://dualcube.com/} 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | /** 27 | * Form for editing tag block instances. 28 | * 29 | * @package block_course_publish 30 | * @author Sandipa Mukherjee 31 | * @copyright 2015 DUALCUBE {@link http://dualcube.com/} 32 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 | */ 34 | class block_course_publish_edit_form extends block_edit_form { 35 | /** 36 | * Called to define this moodle form 37 | * 38 | * @return void 39 | */ 40 | protected function specific_definition($mform) { 41 | // Section header title according to language file. 42 | $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); 43 | // A sample string variable with a default value. 44 | $mform->addElement('text', 'config_appid', get_string('appid', 'block_course_publish')); 45 | $mform->setType('config_appid', PARAM_INT); 46 | $mform->addRule('config_appid', null, 'required', null, 'appid'); 47 | $mform->addElement('text', 'config_secretkey', get_string('secretkey', 'block_course_publish')); 48 | $mform->setType('config_secretkey', PARAM_TEXT); 49 | $mform->addRule('config_secretkey', null, 'required', null, 'secretkey'); 50 | $mform->addElement('textarea', 'config_message', get_string('message', 'block_course_publish')); 51 | $mform->setType('config_message', PARAM_TEXT); 52 | $mform->addRule('config_message', null, 'required', null, 'message'); 53 | $mform->addElement('text', 'config_pageaccesstoken', get_string('pageaccesstoken', 'block_course_publish')); 54 | $mform->setType('config_pageaccesstoken', PARAM_TEXT); 55 | $mform->addRule('config_pageaccesstoken', null, 'required', null, 'pageaccesstoken'); 56 | $mform->addElement('text', 'config_pageid', get_string('pageid', 'block_course_publish')); 57 | $mform->setType('config_pageid', PARAM_INT); 58 | $mform->addRule('config_pageid', null, 'required', null, 'pageid'); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ------------ 3 | 4 | For us to accept contributions you will have to first have signed the 5 | [Contributor License Agreement](https://developers.facebook.com/opensource/cla). 6 | 7 | When committing, keep all lines to less than 80 characters, and try to 8 | follow the existing style. 9 | 10 | Before creating a pull request, squash your commits into a single commit. 11 | 12 | Add the comments where needed, and provide ample explanation in the 13 | commit message. 14 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Facebook, Inc. 2 | 3 | You are hereby granted a non-exclusive, worldwide, royalty-free license to 4 | use, copy, modify, and distribute this software in source code or binary 5 | form for use in connection with the web services and APIs provided by 6 | Facebook. 7 | 8 | As with any software that integrates with the Facebook platform, your use 9 | of this software is subject to the Facebook Developer Principles and 10 | Policies [http://developers.facebook.com/policy/]. This copyright notice 11 | shall be included in all copies or substantial portions of the software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/README.md: -------------------------------------------------------------------------------- 1 | Facebook SDK for PHP 2 | ==================== 3 | 4 | [![Latest Stable Version](http://img.shields.io/badge/Latest%20Stable-4.0.23-blue.svg)](https://packagist.org/packages/facebook/php-sdk-v4) 5 | 6 | 7 | This repository contains the open source PHP SDK that allows you to access Facebook 8 | Platform from your PHP app. 9 | 10 | 11 | Usage 12 | ----- 13 | 14 | This version of the Facebook SDK for PHP requires PHP 5.4 or greater. 15 | 16 | Minimal example: 17 | 18 | ```php 19 | execute()->getGraphObject(GraphUser::className()); 45 | echo $me->getName(); 46 | } catch (FacebookRequestException $e) { 47 | // The Graph API returned an error 48 | } catch (\Exception $e) { 49 | // Some other error occurred 50 | } 51 | 52 | ``` 53 | 54 | Complete documentation, installation instructions, and examples are available at: 55 | [https://developers.facebook.com/docs/php](https://developers.facebook.com/docs/php) 56 | 57 | 58 | Tests 59 | ----- 60 | 61 | 1) [Composer](https://getcomposer.org/) is a prerequisite for running the tests. 62 | 63 | Install composer globally, then run `composer install` to install required files. 64 | 65 | 2) Create a test app on [Facebook Developers](https://developers.facebook.com), then 66 | create `tests/FacebookTestCredentials.php` from `tests/FacebookTestCredentials.php.dist` 67 | and edit it to add your credentials. 68 | 69 | 3) The tests can be executed by running this command from the root directory: 70 | 71 | ```bash 72 | ./vendor/bin/phpunit 73 | ``` 74 | 75 | 76 | Contributing 77 | ------------ 78 | 79 | For us to accept contributions you will have to first have signed the 80 | [Contributor License Agreement](https://developers.facebook.com/opensource/cla). 81 | 82 | When committing, keep all lines to less than 80 characters, and try to 83 | follow the existing style. 84 | 85 | Before creating a pull request, squash your commits into a single commit. 86 | 87 | Add the comments where needed, and provide ample explanation in the 88 | commit message. 89 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/autoload.php: -------------------------------------------------------------------------------- 1 | =5.4.0" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "3.7.*", 19 | "mockery/mockery": "dev-master", 20 | "guzzlehttp/guzzle": "~4.0" 21 | }, 22 | "suggest": { 23 | "guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Facebook\\": "src/Facebook/" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests 12 | 13 | 14 | 15 | 16 | ./src/Facebook 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/Entities/AccessToken.php: -------------------------------------------------------------------------------- 1 | accessToken = $accessToken; 69 | if ($expiresAt) { 70 | $this->setExpiresAtFromTimeStamp($expiresAt); 71 | } 72 | $this->machineId = $machineId; 73 | } 74 | 75 | /** 76 | * Setter for expires_at. 77 | * 78 | * @param int $timeStamp 79 | */ 80 | protected function setExpiresAtFromTimeStamp($timeStamp) 81 | { 82 | $dt = new \DateTime(); 83 | $dt->setTimestamp($timeStamp); 84 | $this->expiresAt = $dt; 85 | } 86 | 87 | /** 88 | * Getter for expiresAt. 89 | * 90 | * @return \DateTime|null 91 | */ 92 | public function getExpiresAt() 93 | { 94 | return $this->expiresAt; 95 | } 96 | 97 | /** 98 | * Getter for machineId. 99 | * 100 | * @return string|null 101 | */ 102 | public function getMachineId() 103 | { 104 | return $this->machineId; 105 | } 106 | 107 | /** 108 | * Determines whether or not this is a long-lived token. 109 | * 110 | * @return bool 111 | */ 112 | public function isLongLived() 113 | { 114 | if ($this->expiresAt) { 115 | return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); 116 | } 117 | return false; 118 | } 119 | 120 | /** 121 | * Checks the validity of the access token. 122 | * 123 | * @param string|null $appId Application ID to use 124 | * @param string|null $appSecret App secret value to use 125 | * @param string|null $machineId 126 | * 127 | * @return boolean 128 | */ 129 | public function isValid($appId = null, $appSecret = null, $machineId = null) 130 | { 131 | $accessTokenInfo = $this->getInfo($appId, $appSecret); 132 | $machineId = $machineId ?: $this->machineId; 133 | return static::validateAccessToken($accessTokenInfo, $appId, $machineId); 134 | } 135 | 136 | /** 137 | * Ensures the provided GraphSessionInfo object is valid, 138 | * throwing an exception if not. Ensures the appId matches, 139 | * that the machineId matches if it's being used, 140 | * that the token is valid and has not expired. 141 | * 142 | * @param GraphSessionInfo $tokenInfo 143 | * @param string|null $appId Application ID to use 144 | * @param string|null $machineId 145 | * 146 | * @return boolean 147 | */ 148 | public static function validateAccessToken(GraphSessionInfo $tokenInfo, 149 | $appId = null, $machineId = null) 150 | { 151 | $targetAppId = FacebookSession::_getTargetAppId($appId); 152 | 153 | $appIdIsValid = $tokenInfo->getAppId() == $targetAppId; 154 | $machineIdIsValid = $tokenInfo->getProperty('machine_id') == $machineId; 155 | $accessTokenIsValid = $tokenInfo->isValid(); 156 | 157 | $accessTokenIsStillAlive = true; 158 | // Not all access tokens return an expiration. E.g. an app access token. 159 | if ($tokenInfo->getExpiresAt() instanceof \DateTime) { 160 | $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); 161 | } 162 | 163 | return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive; 164 | } 165 | 166 | /** 167 | * Get a valid access token from a code. 168 | * 169 | * @param string $code 170 | * @param string|null $appId 171 | * @param string|null $appSecret 172 | * @param string|null $machineId 173 | * 174 | * @return AccessToken 175 | */ 176 | public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) 177 | { 178 | $params = array( 179 | 'code' => $code, 180 | 'redirect_uri' => '', 181 | ); 182 | 183 | if ($machineId) { 184 | $params['machine_id'] = $machineId; 185 | } 186 | 187 | return static::requestAccessToken($params, $appId, $appSecret); 188 | } 189 | 190 | /** 191 | * Get a valid code from an access token. 192 | * 193 | * @param AccessToken|string $accessToken 194 | * @param string|null $appId 195 | * @param string|null $appSecret 196 | * 197 | * @return AccessToken 198 | */ 199 | public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) 200 | { 201 | $accessToken = (string) $accessToken; 202 | 203 | $params = array( 204 | 'access_token' => $accessToken, 205 | 'redirect_uri' => '', 206 | ); 207 | 208 | return static::requestCode($params, $appId, $appSecret); 209 | } 210 | 211 | /** 212 | * Exchanges a short lived access token with a long lived access token. 213 | * 214 | * @param string|null $appId 215 | * @param string|null $appSecret 216 | * 217 | * @return AccessToken 218 | */ 219 | public function extend($appId = null, $appSecret = null) 220 | { 221 | $params = array( 222 | 'grant_type' => 'fb_exchange_token', 223 | 'fb_exchange_token' => $this->accessToken, 224 | ); 225 | 226 | return static::requestAccessToken($params, $appId, $appSecret); 227 | } 228 | 229 | /** 230 | * Request an access token based on a set of params. 231 | * 232 | * @param array $params 233 | * @param string|null $appId 234 | * @param string|null $appSecret 235 | * 236 | * @return AccessToken 237 | * 238 | * @throws FacebookRequestException 239 | */ 240 | public static function requestAccessToken(array $params, $appId = null, $appSecret = null) 241 | { 242 | $response = static::request('/oauth/access_token', $params, $appId, $appSecret); 243 | $data = $response->getResponse(); 244 | 245 | /** 246 | * @TODO fix this malarkey - getResponse() should always return an object 247 | * @see https://github.com/facebook/facebook-php-sdk-v4/issues/36 248 | */ 249 | if (is_array($data)) { 250 | if (isset($data['access_token'])) { 251 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; 252 | return new static($data['access_token'], $expiresAt); 253 | } 254 | } elseif($data instanceof \stdClass) { 255 | if (isset($data->access_token)) { 256 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; 257 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; 258 | return new static((string) $data->access_token, $expiresAt, $machineId); 259 | } 260 | } 261 | 262 | throw FacebookRequestException::create( 263 | $response->getRawResponse(), 264 | $data, 265 | 401 266 | ); 267 | } 268 | 269 | /** 270 | * Request a code from a long lived access token. 271 | * 272 | * @param array $params 273 | * @param string|null $appId 274 | * @param string|null $appSecret 275 | * 276 | * @return string 277 | * 278 | * @throws FacebookRequestException 279 | */ 280 | public static function requestCode(array $params, $appId = null, $appSecret = null) 281 | { 282 | $response = static::request('/oauth/client_code', $params, $appId, $appSecret); 283 | $data = $response->getResponse(); 284 | 285 | if (isset($data->code)) { 286 | return (string) $data->code; 287 | } 288 | 289 | throw FacebookRequestException::create( 290 | $response->getRawResponse(), 291 | $data, 292 | 401 293 | ); 294 | } 295 | 296 | /** 297 | * Send a request to Graph with an app access token. 298 | * 299 | * @param string $endpoint 300 | * @param array $params 301 | * @param string|null $appId 302 | * @param string|null $appSecret 303 | * 304 | * @return \Facebook\FacebookResponse 305 | * 306 | * @throws FacebookRequestException 307 | */ 308 | protected static function request($endpoint, array $params, $appId = null, $appSecret = null) 309 | { 310 | $targetAppId = FacebookSession::_getTargetAppId($appId); 311 | $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret); 312 | 313 | if (!isset($params['client_id'])) { 314 | $params['client_id'] = $targetAppId; 315 | } 316 | if (!isset($params['client_secret'])) { 317 | $params['client_secret'] = $targetAppSecret; 318 | } 319 | 320 | // The response for this endpoint is not JSON, so it must be handled 321 | // differently, not as a GraphObject. 322 | $request = new FacebookRequest( 323 | FacebookSession::newAppSession($targetAppId, $targetAppSecret), 324 | 'GET', 325 | $endpoint, 326 | $params 327 | ); 328 | return $request->execute(); 329 | } 330 | 331 | /** 332 | * Get more info about an access token. 333 | * 334 | * @param string|null $appId 335 | * @param string|null $appSecret 336 | * 337 | * @return GraphSessionInfo 338 | */ 339 | public function getInfo($appId = null, $appSecret = null) 340 | { 341 | $params = array('input_token' => $this->accessToken); 342 | 343 | $request = new FacebookRequest( 344 | FacebookSession::newAppSession($appId, $appSecret), 345 | 'GET', 346 | '/debug_token', 347 | $params 348 | ); 349 | $response = $request->execute()->getGraphObject(GraphSessionInfo::className()); 350 | 351 | // Update the data on this token 352 | if ($response->getExpiresAt()) { 353 | $this->expiresAt = $response->getExpiresAt(); 354 | } 355 | 356 | return $response; 357 | } 358 | 359 | /** 360 | * Returns the access token as a string. 361 | * 362 | * @return string 363 | */ 364 | public function __toString() 365 | { 366 | return $this->accessToken; 367 | } 368 | 369 | /** 370 | * Returns true if the access token is an app session token. 371 | * 372 | * @return bool 373 | */ 374 | public function isAppSession() 375 | { 376 | return strpos($this->accessToken, '|') !== false; 377 | } 378 | 379 | } 380 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/Entities/SignedRequest.php: -------------------------------------------------------------------------------- 1 | rawSignedRequest = $rawSignedRequest; 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); 61 | } 62 | 63 | /** 64 | * Returns the raw signed request data. 65 | * 66 | * @return string|null 67 | */ 68 | public function getRawSignedRequest() 69 | { 70 | return $this->rawSignedRequest; 71 | } 72 | 73 | /** 74 | * Returns the parsed signed request data. 75 | * 76 | * @return array|null 77 | */ 78 | public function getPayload() 79 | { 80 | return $this->payload; 81 | } 82 | 83 | /** 84 | * Returns a property from the signed request data if available. 85 | * 86 | * @param string $key 87 | * @param mixed|null $default 88 | * 89 | * @return mixed|null 90 | */ 91 | public function get($key, $default = null) 92 | { 93 | if (isset($this->payload[$key])) { 94 | return $this->payload[$key]; 95 | } 96 | return $default; 97 | } 98 | 99 | /** 100 | * Returns user_id from signed request data if available. 101 | * 102 | * @return string|null 103 | */ 104 | public function getUserId() 105 | { 106 | return $this->get('user_id'); 107 | } 108 | 109 | /** 110 | * Checks for OAuth data in the payload. 111 | * 112 | * @return boolean 113 | */ 114 | public function hasOAuthData() 115 | { 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); 117 | } 118 | 119 | /** 120 | * Creates a signed request from an array of data. 121 | * 122 | * @param array $payload 123 | * @param string|null $appSecret 124 | * 125 | * @return string 126 | */ 127 | public static function make(array $payload, $appSecret = null) 128 | { 129 | $payload['algorithm'] = 'HMAC-SHA256'; 130 | $payload['issued_at'] = time(); 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); 132 | 133 | $hashedSig = static::hashSignature($encodedPayload, $appSecret); 134 | $encodedSig = static::base64UrlEncode($hashedSig); 135 | 136 | return $encodedSig.'.'.$encodedPayload; 137 | } 138 | 139 | /** 140 | * Validates and decodes a signed request and returns 141 | * the payload as an array. 142 | * 143 | * @param string $signedRequest 144 | * @param string|null $state 145 | * @param string|null $appSecret 146 | * 147 | * @return array 148 | */ 149 | public static function parse($signedRequest, $state = null, $appSecret = null) 150 | { 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); 152 | 153 | // Signature validation 154 | $sig = static::decodeSignature($encodedSig); 155 | $hashedSig = static::hashSignature($encodedPayload, $appSecret); 156 | static::validateSignature($hashedSig, $sig); 157 | 158 | // Payload validation 159 | $data = static::decodePayload($encodedPayload); 160 | static::validateAlgorithm($data); 161 | if ($state) { 162 | static::validateCsrf($data, $state); 163 | } 164 | 165 | return $data; 166 | } 167 | 168 | /** 169 | * Validates the format of a signed request. 170 | * 171 | * @param string $signedRequest 172 | * 173 | * @throws FacebookSDKException 174 | */ 175 | public static function validateFormat($signedRequest) 176 | { 177 | if (strpos($signedRequest, '.') !== false) { 178 | return; 179 | } 180 | 181 | throw new FacebookSDKException( 182 | 'Malformed signed request.', 606 183 | ); 184 | } 185 | 186 | /** 187 | * Decodes a raw valid signed request. 188 | * 189 | * @param string $signedRequest 190 | * 191 | * @returns array 192 | */ 193 | public static function split($signedRequest) 194 | { 195 | static::validateFormat($signedRequest); 196 | 197 | return explode('.', $signedRequest, 2); 198 | } 199 | 200 | /** 201 | * Decodes the raw signature from a signed request. 202 | * 203 | * @param string $encodedSig 204 | * 205 | * @returns string 206 | * 207 | * @throws FacebookSDKException 208 | */ 209 | public static function decodeSignature($encodedSig) 210 | { 211 | $sig = static::base64UrlDecode($encodedSig); 212 | 213 | if ($sig) { 214 | return $sig; 215 | } 216 | 217 | throw new FacebookSDKException( 218 | 'Signed request has malformed encoded signature data.', 607 219 | ); 220 | } 221 | 222 | /** 223 | * Decodes the raw payload from a signed request. 224 | * 225 | * @param string $encodedPayload 226 | * 227 | * @returns array 228 | * 229 | * @throws FacebookSDKException 230 | */ 231 | public static function decodePayload($encodedPayload) 232 | { 233 | $payload = static::base64UrlDecode($encodedPayload); 234 | 235 | if ($payload) { 236 | $payload = json_decode($payload, true); 237 | } 238 | 239 | if (is_array($payload)) { 240 | return $payload; 241 | } 242 | 243 | throw new FacebookSDKException( 244 | 'Signed request has malformed encoded payload data.', 607 245 | ); 246 | } 247 | 248 | /** 249 | * Validates the algorithm used in a signed request. 250 | * 251 | * @param array $data 252 | * 253 | * @throws FacebookSDKException 254 | */ 255 | public static function validateAlgorithm(array $data) 256 | { 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { 258 | return; 259 | } 260 | 261 | throw new FacebookSDKException( 262 | 'Signed request is using the wrong algorithm.', 605 263 | ); 264 | } 265 | 266 | /** 267 | * Hashes the signature used in a signed request. 268 | * 269 | * @param string $encodedData 270 | * @param string|null $appSecret 271 | * 272 | * @return string 273 | * 274 | * @throws FacebookSDKException 275 | */ 276 | public static function hashSignature($encodedData, $appSecret = null) 277 | { 278 | $hashedSig = hash_hmac( 279 | 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true 280 | ); 281 | 282 | if ($hashedSig) { 283 | return $hashedSig; 284 | } 285 | 286 | throw new FacebookSDKException( 287 | 'Unable to hash signature from encoded payload data.', 602 288 | ); 289 | } 290 | 291 | /** 292 | * Validates the signature used in a signed request. 293 | * 294 | * @param string $hashedSig 295 | * @param string $sig 296 | * 297 | * @throws FacebookSDKException 298 | */ 299 | public static function validateSignature($hashedSig, $sig) 300 | { 301 | $intSignatureLength = mb_strlen($sig); 302 | if (mb_strlen($hashedSig) === $intSignatureLength) { 303 | $validate = 0; 304 | for ($i = 0; $i < $intSignatureLength; $i++) { 305 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); 306 | } 307 | if ($validate === 0) { 308 | return; 309 | } 310 | } 311 | 312 | throw new FacebookSDKException( 313 | 'Signed request has an invalid signature.', 602 314 | ); 315 | } 316 | 317 | /** 318 | * Validates a signed request against CSRF. 319 | * 320 | * @param array $data 321 | * @param string $state 322 | * 323 | * @throws FacebookSDKException 324 | */ 325 | public static function validateCsrf(array $data, $state) 326 | { 327 | if (isset($data['state'])) { 328 | $savedLen = strlen($state); 329 | $givenLen = strlen($data['state']); 330 | if ($savedLen == $givenLen) { 331 | $result = 0; 332 | for ($i = 0; $i < $savedLen; $i++) { 333 | $result |= ord($state[$i]) ^ ord($data['state'][$i]); 334 | } 335 | if ($result === 0) { 336 | return; 337 | } 338 | } 339 | } 340 | 341 | throw new FacebookSDKException( 342 | 'Signed request did not pass CSRF validation.', 604 343 | ); 344 | } 345 | 346 | /** 347 | * Base64 decoding which replaces characters: 348 | * + instead of - 349 | * / instead of _ 350 | * @link http://en.wikipedia.org/wiki/Base64#URL_applications 351 | * 352 | * @param string $input base64 url encoded input 353 | * 354 | * @return string decoded string 355 | */ 356 | public static function base64UrlDecode($input) 357 | { 358 | $urlDecodedBase64 = strtr($input, '-_', '+/'); 359 | static::validateBase64($urlDecodedBase64); 360 | return base64_decode($urlDecodedBase64); 361 | } 362 | 363 | /** 364 | * Base64 encoding which replaces characters: 365 | * + instead of - 366 | * / instead of _ 367 | * @link http://en.wikipedia.org/wiki/Base64#URL_applications 368 | * 369 | * @param string $input string to encode 370 | * 371 | * @return string base64 url encoded input 372 | */ 373 | public static function base64UrlEncode($input) 374 | { 375 | return strtr(base64_encode($input), '+/', '-_'); 376 | } 377 | 378 | /** 379 | * Validates a base64 string. 380 | * 381 | * @param string $input base64 value to validate 382 | * 383 | * @throws FacebookSDKException 384 | */ 385 | public static function validateBase64($input) 386 | { 387 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; 388 | if (preg_match($pattern, $input)) { 389 | return; 390 | } 391 | 392 | throw new FacebookSDKException( 393 | 'Signed request contains malformed base64 encoding.', 608 394 | ); 395 | } 396 | 397 | } 398 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookAuthorizationException.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookCanvasLoginHelper extends FacebookSignedRequestFromInputHelper 33 | { 34 | 35 | /** 36 | * Returns the app data value. 37 | * 38 | * @return mixed|null 39 | */ 40 | public function getAppData() 41 | { 42 | return $this->signedRequest ? $this->signedRequest->get('app_data') : null; 43 | } 44 | 45 | /** 46 | * Get raw signed request from POST. 47 | * 48 | * @return string|null 49 | */ 50 | public function getRawSignedRequest() 51 | { 52 | $rawSignedRequest = $this->getRawSignedRequestFromPost(); 53 | if ($rawSignedRequest) { 54 | return $rawSignedRequest; 55 | } 56 | 57 | return null; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookClientException.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookJavaScriptLoginHelper extends FacebookSignedRequestFromInputHelper 33 | { 34 | 35 | /** 36 | * Get raw signed request from the cookie. 37 | * 38 | * @return string|null 39 | */ 40 | public function getRawSignedRequest() 41 | { 42 | return $this->getRawSignedRequestFromCookie(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookOtherException.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | class FacebookPageTabHelper extends FacebookCanvasLoginHelper 32 | { 33 | 34 | /** 35 | * @var array|null 36 | */ 37 | protected $pageData; 38 | 39 | /** 40 | * Initialize the helper and process available signed request data. 41 | * 42 | * @param string|null $appId 43 | * @param string|null $appSecret 44 | */ 45 | public function __construct($appId = null, $appSecret = null) 46 | { 47 | parent::__construct($appId, $appSecret); 48 | 49 | if (!$this->signedRequest) { 50 | return; 51 | } 52 | 53 | $this->pageData = $this->signedRequest->get('page'); 54 | } 55 | 56 | /** 57 | * Returns a value from the page data. 58 | * 59 | * @param string $key 60 | * @param mixed|null $default 61 | * 62 | * @return mixed|null 63 | */ 64 | public function getPageData($key, $default = null) 65 | { 66 | if (isset($this->pageData[$key])) { 67 | return $this->pageData[$key]; 68 | } 69 | return $default; 70 | } 71 | 72 | /** 73 | * Returns true if the page is liked by the user. 74 | * 75 | * @return boolean 76 | */ 77 | public function isLiked() 78 | { 79 | return $this->getPageData('liked') === true; 80 | } 81 | 82 | /** 83 | * Returns true if the user is an admin. 84 | * 85 | * @return boolean 86 | */ 87 | public function isAdmin() 88 | { 89 | return $this->getPageData('admin') === true; 90 | } 91 | 92 | /** 93 | * Returns the page id if available. 94 | * 95 | * @return string|null 96 | */ 97 | public function getPageId() 98 | { 99 | return $this->getPageData('id'); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookPermissionException.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookRedirectLoginHelper 33 | { 34 | 35 | /** 36 | * @var string The application id 37 | */ 38 | private $appId; 39 | 40 | /** 41 | * @var string The application secret 42 | */ 43 | private $appSecret; 44 | 45 | /** 46 | * @var string The redirect URL for the application 47 | */ 48 | private $redirectUrl; 49 | 50 | /** 51 | * @var string Prefix to use for session variables 52 | */ 53 | private $sessionPrefix = 'FBRLH_'; 54 | 55 | /** 56 | * @var string State token for CSRF validation 57 | */ 58 | protected $state; 59 | 60 | /** 61 | * @var boolean Toggle for PHP session status check 62 | */ 63 | protected $checkForSessionStatus = true; 64 | 65 | /** 66 | * Constructs a RedirectLoginHelper for a given appId and redirectUrl. 67 | * 68 | * @param string $redirectUrl The URL Facebook should redirect users to 69 | * after login 70 | * @param string $appId The application id 71 | * @param string $appSecret The application secret 72 | */ 73 | public function __construct($redirectUrl, $appId = null, $appSecret = null) 74 | { 75 | $this->appId = FacebookSession::_getTargetAppId($appId); 76 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); 77 | $this->redirectUrl = $redirectUrl; 78 | } 79 | 80 | /** 81 | * Stores CSRF state and returns a URL to which the user should be sent to 82 | * in order to continue the login process with Facebook. The 83 | * provided redirectUrl should invoke the handleRedirect method. 84 | * 85 | * @param array $scope List of permissions to request during login 86 | * @param string $version Optional Graph API version if not default (v2.0) 87 | * @param boolean $displayAsPopup Indicate if the page will be displayed as a popup 88 | * @param bool|string $authType 'reauthenticate' or 'https', true is equivalent to 'reauthenticate', 89 | * false or invalid value will not add auth type parameter 90 | * 91 | * @return string 92 | */ 93 | public function getLoginUrl(array $scope = array(), $version = null, $displayAsPopup = false, $authType = false) 94 | { 95 | if (session_status() !== PHP_SESSION_ACTIVE) {@session_start();} 96 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); 97 | $this->state = $this->random(16); 98 | $this->storeState($this->state); 99 | $params = array( 100 | 'client_id' => $this->appId, 101 | 'redirect_uri' => $this->redirectUrl, 102 | 'state' => $this->state, 103 | 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, 104 | 'scope' => implode(',', $scope) 105 | ); 106 | 107 | if (in_array($authType, array(true, 'reauthenticate', 'https'), true)) { 108 | $params['auth_type'] = $authType === true ? 'reauthenticate' : $authType; 109 | } 110 | 111 | if ($displayAsPopup) 112 | { 113 | $params['display'] = 'popup'; 114 | } 115 | 116 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . 117 | http_build_query($params, null, '&'); 118 | } 119 | 120 | /** 121 | * Returns a URL to which the user should be sent to re-request permissions. 122 | * 123 | * @param array $scope List of permissions to re-request 124 | * @param string $version Optional Graph API version if not default (v2.0) 125 | * 126 | * @return string 127 | */ 128 | public function getReRequestUrl(array $scope = array(), $version = null) 129 | { 130 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); 131 | $this->state = $this->random(16); 132 | $this->storeState($this->state); 133 | $params = array( 134 | 'client_id' => $this->appId, 135 | 'redirect_uri' => $this->redirectUrl, 136 | 'state' => $this->state, 137 | 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, 138 | 'auth_type' => 'rerequest', 139 | 'scope' => implode(',', $scope) 140 | ); 141 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . 142 | http_build_query($params, null, '&'); 143 | } 144 | 145 | /** 146 | * Returns the URL to send the user in order to log out of Facebook. 147 | * 148 | * @param FacebookSession $session The session that will be logged out 149 | * @param string $next The url Facebook should redirect the user to after 150 | * a successful logout 151 | * 152 | * @return string 153 | * 154 | * @throws FacebookSDKException 155 | */ 156 | public function getLogoutUrl(FacebookSession $session, $next) 157 | { 158 | if ($session->getAccessToken()->isAppSession()) { 159 | throw new FacebookSDKException( 160 | 'Cannot generate a Logout URL with an App Session.', 722 161 | ); 162 | } 163 | $params = array( 164 | 'next' => $next, 165 | 'access_token' => $session->getToken() 166 | ); 167 | return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&'); 168 | } 169 | 170 | /** 171 | * Handles a response from Facebook, including a CSRF check, and returns a 172 | * FacebookSession. 173 | * 174 | * @return FacebookSession|null 175 | */ 176 | public function getSessionFromRedirect() 177 | { 178 | if ($this->isValidRedirect()) { 179 | $params = array( 180 | 'client_id' => FacebookSession::_getTargetAppId($this->appId), 181 | 'redirect_uri' => $this->redirectUrl, 182 | 'client_secret' => 183 | FacebookSession::_getTargetAppSecret($this->appSecret), 184 | 'code' => $this->getCode() 185 | ); 186 | $response = (new FacebookRequest( 187 | FacebookSession::newAppSession($this->appId, $this->appSecret), 188 | 'GET', 189 | '/oauth/access_token', 190 | $params 191 | ))->execute()->getResponse(); 192 | 193 | // Graph v2.3 and greater return objects on the /oauth/access_token endpoint 194 | $accessToken = null; 195 | if (is_object($response) && isset($response->access_token)) { 196 | $accessToken = $response->access_token; 197 | } elseif (is_array($response) && isset($response['access_token'])) { 198 | $accessToken = $response['access_token']; 199 | } 200 | 201 | if (isset($accessToken)) { 202 | return new FacebookSession($accessToken); 203 | } 204 | } 205 | return null; 206 | } 207 | 208 | /** 209 | * Check if a redirect has a valid state. 210 | * 211 | * @return bool 212 | */ 213 | protected function isValidRedirect() 214 | { 215 | $savedState = $this->loadState(); 216 | if (!$this->getCode() || !isset($_GET['state'])) { 217 | return false; 218 | } 219 | $givenState = $_GET['state']; 220 | $savedLen = mb_strlen($savedState); 221 | $givenLen = mb_strlen($givenState); 222 | if ($savedLen !== $givenLen) { 223 | return false; 224 | } 225 | $result = 0; 226 | for ($i = 0; $i < $savedLen; $i++) { 227 | $result |= ord($savedState[$i]) ^ ord($givenState[$i]); 228 | } 229 | return $result === 0; 230 | } 231 | 232 | /** 233 | * Return the code. 234 | * 235 | * @return string|null 236 | */ 237 | protected function getCode() 238 | { 239 | return isset($_GET['code']) ? $_GET['code'] : null; 240 | } 241 | 242 | /** 243 | * Stores a state string in session storage for CSRF protection. 244 | * Developers should subclass and override this method if they want to store 245 | * this state in a different location. 246 | * 247 | * @param string $state 248 | * 249 | * @throws FacebookSDKException 250 | */ 251 | protected function storeState($state) 252 | { 253 | if ($this->checkForSessionStatus === true 254 | && session_status() !== PHP_SESSION_ACTIVE) { 255 | throw new FacebookSDKException( 256 | 'Session not active, could not store state.', 720 257 | ); 258 | } 259 | $_SESSION[$this->sessionPrefix . 'state'] = $state; 260 | } 261 | 262 | /** 263 | * Loads a state string from session storage for CSRF validation. May return 264 | * null if no object exists. Developers should subclass and override this 265 | * method if they want to load the state from a different location. 266 | * 267 | * @return string|null 268 | * 269 | * @throws FacebookSDKException 270 | */ 271 | protected function loadState() 272 | { 273 | if ($this->checkForSessionStatus === true 274 | && session_status() !== PHP_SESSION_ACTIVE) { 275 | throw new FacebookSDKException( 276 | 'Session not active, could not load state.', 721 277 | ); 278 | } 279 | if (isset($_SESSION[$this->sessionPrefix . 'state'])) { 280 | $this->state = $_SESSION[$this->sessionPrefix . 'state']; 281 | return $this->state; 282 | } 283 | return null; 284 | } 285 | 286 | /** 287 | * Generate a cryptographically secure pseudrandom number 288 | * 289 | * @param integer $bytes - number of bytes to return 290 | * 291 | * @return string 292 | * 293 | * @throws FacebookSDKException 294 | * 295 | * @todo Support Windows platforms 296 | */ 297 | public function random($bytes) 298 | { 299 | if (!is_numeric($bytes)) { 300 | throw new FacebookSDKException( 301 | 'random() expects an integer' 302 | ); 303 | } 304 | if ($bytes < 1) { 305 | throw new FacebookSDKException( 306 | 'random() expects an integer greater than zero' 307 | ); 308 | } 309 | $buf = ''; 310 | // http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ 311 | if (!ini_get('open_basedir') 312 | && is_readable('/dev/urandom')) { 313 | $fp = fopen('/dev/urandom', 'rb'); 314 | if ($fp !== FALSE) { 315 | $buf = fread($fp, $bytes); 316 | fclose($fp); 317 | if($buf !== FALSE) { 318 | return bin2hex($buf); 319 | } 320 | } 321 | } 322 | 323 | if (function_exists('mcrypt_create_iv')) { 324 | $buf = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); 325 | if ($buf !== FALSE) { 326 | return bin2hex($buf); 327 | } 328 | } 329 | 330 | while (strlen($buf) < $bytes) { 331 | $buf .= md5(uniqid(mt_rand(), true), true); 332 | // We are appending raw binary 333 | } 334 | return bin2hex(substr($buf, 0, $bytes)); 335 | } 336 | 337 | /** 338 | * Disables the session_status() check when using $_SESSION 339 | */ 340 | public function disableSessionStatusCheck() 341 | { 342 | $this->checkForSessionStatus = false; 343 | } 344 | 345 | } 346 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookRequest.php: -------------------------------------------------------------------------------- 1 | 34 | * @author David Poll 35 | */ 36 | class FacebookRequest 37 | { 38 | 39 | /** 40 | * @const string Version number of the Facebook PHP SDK. 41 | */ 42 | const VERSION = '4.0.23'; 43 | 44 | /** 45 | * @const string Default Graph API version for requests 46 | */ 47 | const GRAPH_API_VERSION = 'v2.3'; 48 | 49 | /** 50 | * @const string Graph API URL 51 | */ 52 | const BASE_GRAPH_URL = 'https://graph.facebook.com'; 53 | 54 | /** 55 | * @const string Graph API URL 56 | */ 57 | const BASE_VIDEO_GRAPH_URL = 'https://graph-video.facebook.com'; 58 | 59 | /** 60 | * @var FacebookSession The session used for this request 61 | */ 62 | private $session; 63 | 64 | /** 65 | * @var string The HTTP method for the request 66 | */ 67 | private $method; 68 | 69 | /** 70 | * @var string The path for the request 71 | */ 72 | private $path; 73 | 74 | /** 75 | * @var array The parameters for the request 76 | */ 77 | private $params; 78 | 79 | /** 80 | * @var string The Graph API version for the request 81 | */ 82 | private $version; 83 | 84 | /** 85 | * @var string ETag sent with the request 86 | */ 87 | private $etag; 88 | 89 | /** 90 | * @var FacebookHttpable HTTP client handler 91 | */ 92 | private static $httpClientHandler; 93 | 94 | /** 95 | * @var int The number of calls that have been made to Graph. 96 | */ 97 | public static $requestCount = 0; 98 | 99 | /** 100 | * getSession - Returns the associated FacebookSession. 101 | * 102 | * @return FacebookSession 103 | */ 104 | public function getSession() 105 | { 106 | return $this->session; 107 | } 108 | 109 | /** 110 | * getPath - Returns the associated path. 111 | * 112 | * @return string 113 | */ 114 | public function getPath() 115 | { 116 | return $this->path; 117 | } 118 | 119 | /** 120 | * getParameters - Returns the associated parameters. 121 | * 122 | * @return array 123 | */ 124 | public function getParameters() 125 | { 126 | return $this->params; 127 | } 128 | 129 | /** 130 | * getMethod - Returns the associated method. 131 | * 132 | * @return string 133 | */ 134 | public function getMethod() 135 | { 136 | return $this->method; 137 | } 138 | 139 | /** 140 | * getETag - Returns the ETag sent with the request. 141 | * 142 | * @return string 143 | */ 144 | public function getETag() 145 | { 146 | return $this->etag; 147 | } 148 | 149 | /** 150 | * setHttpClientHandler - Returns an instance of the HTTP client 151 | * handler 152 | * 153 | * @param \Facebook\HttpClients\FacebookHttpable 154 | */ 155 | public static function setHttpClientHandler(FacebookHttpable $handler) 156 | { 157 | static::$httpClientHandler = $handler; 158 | } 159 | 160 | /** 161 | * getHttpClientHandler - Returns an instance of the HTTP client 162 | * data handler 163 | * 164 | * @return FacebookHttpable 165 | */ 166 | public static function getHttpClientHandler() 167 | { 168 | if (static::$httpClientHandler) { 169 | return static::$httpClientHandler; 170 | } 171 | return function_exists('curl_init') ? new FacebookCurlHttpClient() : new FacebookStreamHttpClient(); 172 | } 173 | 174 | /** 175 | * FacebookRequest - Returns a new request using the given session. optional 176 | * parameters hash will be sent with the request. This object is 177 | * immutable. 178 | * 179 | * @param FacebookSession $session 180 | * @param string $method 181 | * @param string $path 182 | * @param array|null $parameters 183 | * @param string|null $version 184 | * @param string|null $etag 185 | */ 186 | public function __construct( 187 | FacebookSession $session, $method, $path, $parameters = null, $version = null, $etag = null 188 | ) 189 | { 190 | $this->session = $session; 191 | $this->method = $method; 192 | $this->path = $path; 193 | if ($version) { 194 | $this->version = $version; 195 | } else { 196 | $this->version = static::GRAPH_API_VERSION; 197 | } 198 | $this->etag = $etag; 199 | 200 | $params = ($parameters ?: array()); 201 | if ($session 202 | && ! isset($params['access_token'])) { 203 | $params['access_token'] = $session->getToken(); 204 | } 205 | // if (! isset($params['appsecret_proof']) 206 | // && FacebookSession::useAppSecretProof()) { 207 | // $params['appsecret_proof'] = $this->getAppSecretProof( 208 | // $params['access_token'] 209 | // ); 210 | // } 211 | $this->params = $params; 212 | } 213 | 214 | /** 215 | * Returns the base Graph URL. 216 | * 217 | * @return string 218 | */ 219 | protected function getRequestURL() 220 | { 221 | $pathElements = explode('/', $this->path); 222 | $lastInPath = end($pathElements); 223 | if ($lastInPath == 'videos' && $this->method === 'POST') { 224 | $baseUrl = static::BASE_VIDEO_GRAPH_URL; 225 | } else { 226 | $baseUrl = static::BASE_GRAPH_URL; 227 | } 228 | return $baseUrl . '/' . $this->version . $this->path; 229 | } 230 | 231 | /** 232 | * execute - Makes the request to Facebook and returns the result. 233 | * 234 | * @return FacebookResponse 235 | * 236 | * @throws FacebookSDKException 237 | * @throws FacebookRequestException 238 | */ 239 | public function execute() 240 | { 241 | $url = $this->getRequestURL(); 242 | $params = $this->getParameters(); 243 | 244 | if ($this->method === 'GET') { 245 | $url = self::appendParamsToUrl($url, $params); 246 | $params = array(); 247 | } 248 | 249 | $connection = self::getHttpClientHandler(); 250 | $connection->addRequestHeader('User-Agent', 'fb-php-' . self::VERSION); 251 | $connection->addRequestHeader('Accept-Encoding', '*'); // Support all available encodings. 252 | 253 | // ETag 254 | if (null !== $this->etag) { 255 | $connection->addRequestHeader('If-None-Match', $this->etag); 256 | } 257 | 258 | // Should throw `FacebookSDKException` exception on HTTP client error. 259 | // Don't catch to allow it to bubble up. 260 | $result = $connection->send($url, $this->method, $params); 261 | 262 | static::$requestCount++; 263 | 264 | $etagHit = 304 === $connection->getResponseHttpStatusCode(); 265 | 266 | $headers = $connection->getResponseHeaders(); 267 | $etagReceived = isset($headers['ETag']) ? $headers['ETag'] : null; 268 | 269 | $decodedResult = json_decode($result); 270 | if ($decodedResult === null) { 271 | $out = array(); 272 | parse_str($result, $out); 273 | return new FacebookResponse($this, $out, $result, $etagHit, $etagReceived); 274 | } 275 | if (isset($decodedResult->error)) { 276 | throw FacebookRequestException::create( 277 | $result, 278 | $decodedResult->error, 279 | $connection->getResponseHttpStatusCode() 280 | ); 281 | } 282 | 283 | return new FacebookResponse($this, $decodedResult, $result, $etagHit, $etagReceived); 284 | } 285 | 286 | /** 287 | * Generate and return the appsecret_proof value for an access_token 288 | * 289 | * @param string $token 290 | * 291 | * @return string 292 | */ 293 | public function getAppSecretProof($token) 294 | { 295 | return hash_hmac('sha256', $token, FacebookSession::_getTargetAppSecret()); 296 | } 297 | 298 | /** 299 | * appendParamsToUrl - Gracefully appends params to the URL. 300 | * 301 | * @param string $url 302 | * @param array $params 303 | * 304 | * @return string 305 | */ 306 | public static function appendParamsToUrl($url, array $params = array()) 307 | { 308 | if (!$params) { 309 | return $url; 310 | } 311 | 312 | if (strpos($url, '?') === false) { 313 | return $url . '?' . http_build_query($params, null, '&'); 314 | } 315 | 316 | list($path, $query_string) = explode('?', $url, 2); 317 | parse_str($query_string, $query_array); 318 | 319 | // Favor params from the original URL over $params 320 | $params = array_merge($params, $query_array); 321 | 322 | return $path . '?' . http_build_query($params, null, '&'); 323 | } 324 | 325 | } 326 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookRequestException.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookRequestException extends FacebookSDKException 33 | { 34 | 35 | /** 36 | * @var int Status code for the response causing the exception 37 | */ 38 | private $statusCode; 39 | 40 | /** 41 | * @var string Raw response 42 | */ 43 | private $rawResponse; 44 | 45 | /** 46 | * @var array Decoded response 47 | */ 48 | private $responseData; 49 | 50 | /** 51 | * Creates a FacebookRequestException. 52 | * 53 | * @param string $rawResponse The raw response from the Graph API 54 | * @param array $responseData The decoded response from the Graph API 55 | * @param int $statusCode 56 | */ 57 | public function __construct($rawResponse, $responseData, $statusCode) 58 | { 59 | $this->rawResponse = $rawResponse; 60 | $this->statusCode = $statusCode; 61 | $this->responseData = self::convertToArray($responseData); 62 | parent::__construct( 63 | $this->get('message', 'Unknown Exception'), $this->get('code', -1), null 64 | ); 65 | } 66 | 67 | /** 68 | * Process an error payload from the Graph API and return the appropriate 69 | * exception subclass. 70 | * 71 | * @param string $raw the raw response from the Graph API 72 | * @param array $data the decoded response from the Graph API 73 | * @param int $statusCode the HTTP response code 74 | * 75 | * @return FacebookRequestException 76 | */ 77 | public static function create($raw, $data, $statusCode) 78 | { 79 | $data = self::convertToArray($data); 80 | if (!isset($data['error']['code']) && isset($data['code'])) { 81 | $data = array('error' => $data); 82 | } 83 | $code = (isset($data['error']['code']) ? (int) $data['error']['code'] : null); 84 | 85 | if (isset($data['error']['error_subcode'])) { 86 | switch ($data['error']['error_subcode']) { 87 | // Other authentication issues 88 | case 458: 89 | case 459: 90 | case 460: 91 | case 463: 92 | case 464: 93 | case 467: 94 | return new FacebookAuthorizationException($raw, $data, $statusCode); 95 | break; 96 | } 97 | } 98 | 99 | switch ($code) { 100 | // Login status or token expired, revoked, or invalid 101 | case 100: 102 | case 102: 103 | case 190: 104 | return new FacebookAuthorizationException($raw, $data, $statusCode); 105 | break; 106 | 107 | // Server issue, possible downtime 108 | case 1: 109 | case 2: 110 | return new FacebookServerException($raw, $data, $statusCode); 111 | break; 112 | 113 | // API Throttling 114 | case 4: 115 | case 17: 116 | case 341: 117 | return new FacebookThrottleException($raw, $data, $statusCode); 118 | break; 119 | 120 | // Duplicate Post 121 | case 506: 122 | return new FacebookClientException($raw, $data, $statusCode); 123 | break; 124 | } 125 | 126 | // Missing Permissions 127 | if ($code === 10 || ($code >= 200 && $code <= 299)) { 128 | return new FacebookPermissionException($raw, $data, $statusCode); 129 | } 130 | 131 | // OAuth authentication error 132 | if (isset($data['error']['type']) 133 | and $data['error']['type'] === 'OAuthException') { 134 | return new FacebookAuthorizationException($raw, $data, $statusCode); 135 | } 136 | 137 | // All others 138 | return new FacebookOtherException($raw, $data, $statusCode); 139 | } 140 | 141 | /** 142 | * Checks isset and returns that or a default value. 143 | * 144 | * @param string $key 145 | * @param mixed $default 146 | * 147 | * @return mixed 148 | */ 149 | private function get($key, $default = null) 150 | { 151 | if (isset($this->responseData['error'][$key])) { 152 | return $this->responseData['error'][$key]; 153 | } 154 | return $default; 155 | } 156 | 157 | /** 158 | * Returns the HTTP status code 159 | * 160 | * @return int 161 | */ 162 | public function getHttpStatusCode() 163 | { 164 | return $this->statusCode; 165 | } 166 | 167 | /** 168 | * Returns the sub-error code 169 | * 170 | * @return int 171 | */ 172 | public function getSubErrorCode() 173 | { 174 | return $this->get('error_subcode', -1); 175 | } 176 | 177 | /** 178 | * Returns the error type 179 | * 180 | * @return string 181 | */ 182 | public function getErrorType() 183 | { 184 | return $this->get('type', ''); 185 | } 186 | 187 | /** 188 | * Returns the raw response used to create the exception. 189 | * 190 | * @return string 191 | */ 192 | public function getRawResponse() 193 | { 194 | return $this->rawResponse; 195 | } 196 | 197 | /** 198 | * Returns the decoded response used to create the exception. 199 | * 200 | * @return array 201 | */ 202 | public function getResponse() 203 | { 204 | return $this->responseData; 205 | } 206 | 207 | /** 208 | * Converts a stdClass object to an array 209 | * 210 | * @param mixed $object 211 | * 212 | * @return array 213 | */ 214 | private static function convertToArray($object) 215 | { 216 | if ($object instanceof \stdClass) { 217 | return get_object_vars($object); 218 | } 219 | return $object; 220 | } 221 | 222 | } -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookResponse.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookResponse 33 | { 34 | 35 | /** 36 | * @var FacebookRequest The request which produced this response 37 | */ 38 | private $request; 39 | 40 | /** 41 | * @var array The decoded response from the Graph API 42 | */ 43 | private $responseData; 44 | 45 | /** 46 | * @var string The raw response from the Graph API 47 | */ 48 | private $rawResponse; 49 | 50 | /** 51 | * @var bool Indicates whether sent ETag matched the one on the FB side 52 | */ 53 | private $etagHit; 54 | 55 | /** 56 | * @var string ETag received with the response. `null` in case of ETag hit. 57 | */ 58 | private $etag; 59 | 60 | /** 61 | * Creates a FacebookResponse object for a given request and response. 62 | * 63 | * @param FacebookRequest $request 64 | * @param array $responseData JSON Decoded response data 65 | * @param string $rawResponse Raw string response 66 | * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side 67 | * @param string|null $etag ETag received with the response. `null` in case of ETag hit. 68 | */ 69 | public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null) 70 | { 71 | $this->request = $request; 72 | $this->responseData = $responseData; 73 | $this->rawResponse = $rawResponse; 74 | $this->etagHit = $etagHit; 75 | $this->etag = $etag; 76 | } 77 | 78 | /** 79 | * Returns the request which produced this response. 80 | * 81 | * @return FacebookRequest 82 | */ 83 | public function getRequest() 84 | { 85 | return $this->request; 86 | } 87 | 88 | /** 89 | * Returns the decoded response data. 90 | * 91 | * @return array 92 | */ 93 | public function getResponse() 94 | { 95 | return $this->responseData; 96 | } 97 | 98 | /** 99 | * Returns the raw response 100 | * 101 | * @return string 102 | */ 103 | public function getRawResponse() 104 | { 105 | return $this->rawResponse; 106 | } 107 | 108 | /** 109 | * Returns true if ETag matched the one sent with a request 110 | * 111 | * @return bool 112 | */ 113 | public function isETagHit() 114 | { 115 | return $this->etagHit; 116 | } 117 | 118 | /** 119 | * Returns the ETag 120 | * 121 | * @return string 122 | */ 123 | public function getETag() 124 | { 125 | return $this->etag; 126 | } 127 | 128 | /** 129 | * Gets the result as a GraphObject. If a type is specified, returns the 130 | * strongly-typed subclass of GraphObject for the data. 131 | * 132 | * @param string $type 133 | * 134 | * @return mixed 135 | */ 136 | public function getGraphObject($type = 'Facebook\GraphObject') { 137 | return (new GraphObject($this->responseData))->cast($type); 138 | } 139 | 140 | /** 141 | * Returns an array of GraphObject returned by the request. If a type is 142 | * specified, returns the strongly-typed subclass of GraphObject for the data. 143 | * 144 | * @param string $type 145 | * 146 | * @return mixed 147 | */ 148 | public function getGraphObjectList($type = 'Facebook\GraphObject') { 149 | $out = array(); 150 | $data = $this->responseData->data; 151 | $dataLength = count($data); 152 | for ($i = 0; $i < $dataLength; $i++) { 153 | $out[] = (new GraphObject($data[$i]))->cast($type); 154 | } 155 | return $out; 156 | } 157 | 158 | /** 159 | * If this response has paginated data, returns the FacebookRequest for the 160 | * next page, or null. 161 | * 162 | * @return FacebookRequest|null 163 | */ 164 | public function getRequestForNextPage() 165 | { 166 | return $this->handlePagination('next'); 167 | } 168 | 169 | /** 170 | * If this response has paginated data, returns the FacebookRequest for the 171 | * previous page, or null. 172 | * 173 | * @return FacebookRequest|null 174 | */ 175 | public function getRequestForPreviousPage() 176 | { 177 | return $this->handlePagination('previous'); 178 | } 179 | 180 | /** 181 | * Returns the FacebookRequest for the previous or next page, or null. 182 | * 183 | * @param string $direction 184 | * 185 | * @return FacebookRequest|null 186 | */ 187 | private function handlePagination($direction) { 188 | if (isset($this->responseData->paging->$direction)) { 189 | $url = parse_url($this->responseData->paging->$direction); 190 | parse_str($url['query'], $params); 191 | 192 | if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){ 193 | unset($params['type']); 194 | } 195 | return new FacebookRequest( 196 | $this->request->getSession(), 197 | $this->request->getMethod(), 198 | $this->request->getPath(), 199 | $params 200 | ); 201 | } else { 202 | return null; 203 | } 204 | } 205 | 206 | } 207 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookSDKException.php: -------------------------------------------------------------------------------- 1 | 33 | * @author David Poll 34 | */ 35 | class FacebookSession 36 | { 37 | 38 | /** 39 | * @var string 40 | */ 41 | private static $defaultAppId; 42 | 43 | /** 44 | * @var string 45 | */ 46 | private static $defaultAppSecret; 47 | 48 | /** 49 | * @var AccessToken The AccessToken entity for this connection. 50 | */ 51 | private $accessToken; 52 | 53 | /** 54 | * @var SignedRequest 55 | */ 56 | private $signedRequest; 57 | 58 | /** 59 | * @var bool 60 | */ 61 | protected static $useAppSecretProof = true; 62 | 63 | /** 64 | * When creating a Session from an access_token, use: 65 | * var $session = new FacebookSession($accessToken); 66 | * This will validate the token and provide a Session object ready for use. 67 | * It will throw a SessionException in case of error. 68 | * 69 | * @param AccessToken|string $accessToken 70 | * @param SignedRequest $signedRequest The SignedRequest entity 71 | */ 72 | public function __construct($accessToken, SignedRequest $signedRequest = null) 73 | { 74 | $this->accessToken = $accessToken instanceof AccessToken ? $accessToken : new AccessToken($accessToken); 75 | $this->signedRequest = $signedRequest; 76 | } 77 | 78 | /** 79 | * Returns the access token. 80 | * 81 | * @return string 82 | */ 83 | public function getToken() 84 | { 85 | return (string) $this->accessToken; 86 | } 87 | 88 | /** 89 | * Returns the access token entity. 90 | * 91 | * @return AccessToken 92 | */ 93 | public function getAccessToken() 94 | { 95 | return $this->accessToken; 96 | } 97 | 98 | /** 99 | * Returns the SignedRequest entity. 100 | * 101 | * @return SignedRequest 102 | */ 103 | public function getSignedRequest() 104 | { 105 | return $this->signedRequest; 106 | } 107 | 108 | /** 109 | * Returns the signed request payload. 110 | * 111 | * @return null|array 112 | */ 113 | public function getSignedRequestData() 114 | { 115 | return $this->signedRequest ? $this->signedRequest->getPayload() : null; 116 | } 117 | 118 | /** 119 | * Returns a property from the signed request data if available. 120 | * 121 | * @param string $key 122 | * 123 | * @return null|mixed 124 | */ 125 | public function getSignedRequestProperty($key) 126 | { 127 | return $this->signedRequest ? $this->signedRequest->get($key) : null; 128 | } 129 | 130 | /** 131 | * Returns user_id from signed request data if available. 132 | * 133 | * @return null|string 134 | */ 135 | public function getUserId() 136 | { 137 | return $this->signedRequest ? $this->signedRequest->getUserId() : null; 138 | } 139 | 140 | // @TODO Remove getSessionInfo() in 4.1: can be accessed from AccessToken directly 141 | /** 142 | * getSessionInfo - Makes a request to /debug_token with the appropriate 143 | * arguments to get debug information about the sessions token. 144 | * 145 | * @param string|null $appId 146 | * @param string|null $appSecret 147 | * 148 | * @return GraphSessionInfo 149 | */ 150 | public function getSessionInfo($appId = null, $appSecret = null) 151 | { 152 | return $this->accessToken->getInfo($appId, $appSecret); 153 | } 154 | 155 | // @TODO Remove getLongLivedSession() in 4.1: can be accessed from AccessToken directly 156 | /** 157 | * getLongLivedSession - Returns a new Facebook session resulting from 158 | * extending a short-lived access token. If this session is not 159 | * short-lived, returns $this. 160 | * 161 | * @param string|null $appId 162 | * @param string|null $appSecret 163 | * 164 | * @return FacebookSession 165 | */ 166 | public function getLongLivedSession($appId = null, $appSecret = null) 167 | { 168 | $longLivedAccessToken = $this->accessToken->extend($appId, $appSecret); 169 | return new static($longLivedAccessToken, $this->signedRequest); 170 | } 171 | 172 | // @TODO Remove getExchangeToken() in 4.1: can be accessed from AccessToken directly 173 | /** 174 | * getExchangeToken - Returns an exchange token string which can be sent 175 | * back to clients and exchanged for a device-linked access token. 176 | * 177 | * @param string|null $appId 178 | * @param string|null $appSecret 179 | * 180 | * @return string 181 | */ 182 | public function getExchangeToken($appId = null, $appSecret = null) 183 | { 184 | return AccessToken::getCodeFromAccessToken($this->accessToken, $appId, $appSecret); 185 | } 186 | 187 | // @TODO Remove validate() in 4.1: can be accessed from AccessToken directly 188 | /** 189 | * validate - Ensures the current session is valid, throwing an exception if 190 | * not. Fetches token info from Facebook. 191 | * 192 | * @param string|null $appId Application ID to use 193 | * @param string|null $appSecret App secret value to use 194 | * @param string|null $machineId 195 | * 196 | * @return boolean 197 | * 198 | * @throws FacebookSDKException 199 | */ 200 | public function validate($appId = null, $appSecret = null, $machineId = null) 201 | { 202 | if ($this->accessToken->isValid($appId, $appSecret, $machineId)) { 203 | return true; 204 | } 205 | 206 | // @TODO For v4.1 this should not throw an exception, but just return false. 207 | throw new FacebookSDKException( 208 | 'Session has expired, or is not valid for this app.', 601 209 | ); 210 | } 211 | 212 | // @TODO Remove validateSessionInfo() in 4.1: can be accessed from AccessToken directly 213 | /** 214 | * validateTokenInfo - Ensures the provided GraphSessionInfo object is valid, 215 | * throwing an exception if not. Ensures the appId matches, 216 | * that the token is valid and has not expired. 217 | * 218 | * @param GraphSessionInfo $tokenInfo 219 | * @param string|null $appId Application ID to use 220 | * @param string|null $machineId 221 | * 222 | * @return boolean 223 | * 224 | * @throws FacebookSDKException 225 | */ 226 | public static function validateSessionInfo(GraphSessionInfo $tokenInfo, 227 | $appId = null, 228 | $machineId = null) 229 | { 230 | if (AccessToken::validateAccessToken($tokenInfo, $appId, $machineId)) { 231 | return true; 232 | } 233 | 234 | // @TODO For v4.1 this should not throw an exception, but just return false. 235 | throw new FacebookSDKException( 236 | 'Session has expired, or is not valid for this app.', 601 237 | ); 238 | } 239 | 240 | /** 241 | * newSessionFromSignedRequest - Returns a FacebookSession for a 242 | * given signed request. 243 | * 244 | * @param SignedRequest $signedRequest 245 | * 246 | * @return FacebookSession 247 | */ 248 | public static function newSessionFromSignedRequest(SignedRequest $signedRequest) 249 | { 250 | if ($signedRequest->get('code') 251 | && !$signedRequest->get('oauth_token')) { 252 | return self::newSessionAfterValidation($signedRequest); 253 | } 254 | $accessToken = $signedRequest->get('oauth_token'); 255 | $expiresAt = $signedRequest->get('expires', 0); 256 | $accessToken = new AccessToken($accessToken, $expiresAt); 257 | return new static($accessToken, $signedRequest); 258 | } 259 | 260 | /** 261 | * newSessionAfterValidation - Returns a FacebookSession for a 262 | * validated & parsed signed request. 263 | * 264 | * @param SignedRequest $signedRequest 265 | * 266 | * @return FacebookSession 267 | */ 268 | protected static function newSessionAfterValidation(SignedRequest $signedRequest) 269 | { 270 | $code = $signedRequest->get('code'); 271 | $accessToken = AccessToken::getAccessTokenFromCode($code); 272 | return new static($accessToken, $signedRequest); 273 | } 274 | 275 | /** 276 | * newAppSession - Returns a FacebookSession configured with a token for the 277 | * application which can be used for publishing and requesting app-level 278 | * information. 279 | * 280 | * @param string|null $appId Application ID to use 281 | * @param string|null $appSecret App secret value to use 282 | * 283 | * @return FacebookSession 284 | */ 285 | public static function newAppSession($appId = null, $appSecret = null) 286 | { 287 | $targetAppId = static::_getTargetAppId($appId); 288 | $targetAppSecret = static::_getTargetAppSecret($appSecret); 289 | return new FacebookSession( 290 | $targetAppId . '|' . $targetAppSecret 291 | ); 292 | } 293 | 294 | /** 295 | * setDefaultApplication - Will set the static default appId and appSecret 296 | * to be used for API requests. 297 | * 298 | * @param string $appId Application ID to use by default 299 | * @param string $appSecret App secret value to use by default 300 | */ 301 | public static function setDefaultApplication($appId, $appSecret) 302 | { 303 | self::$defaultAppId = $appId; 304 | self::$defaultAppSecret = $appSecret; 305 | } 306 | 307 | /** 308 | * _getTargetAppId - Will return either the provided app Id or the default, 309 | * throwing if neither are populated. 310 | * 311 | * @param string $appId 312 | * 313 | * @return string 314 | * 315 | * @throws FacebookSDKException 316 | */ 317 | public static function _getTargetAppId($appId = null) { 318 | $target = ($appId ?: self::$defaultAppId); 319 | if (!$target) { 320 | throw new FacebookSDKException( 321 | 'You must provide or set a default application id.', 700 322 | ); 323 | } 324 | return $target; 325 | } 326 | 327 | /** 328 | * _getTargetAppSecret - Will return either the provided app secret or the 329 | * default, throwing if neither are populated. 330 | * 331 | * @param string $appSecret 332 | * 333 | * @return string 334 | * 335 | * @throws FacebookSDKException 336 | */ 337 | public static function _getTargetAppSecret($appSecret = null) { 338 | $target = ($appSecret ?: self::$defaultAppSecret); 339 | if (!$target) { 340 | throw new FacebookSDKException( 341 | 'You must provide or set a default application secret.', 701 342 | ); 343 | } 344 | return $target; 345 | } 346 | 347 | /** 348 | * Enable or disable sending the appsecret_proof with requests. 349 | * 350 | * @param bool $on 351 | */ 352 | public static function enableAppSecretProof($on = true) 353 | { 354 | static::$useAppSecretProof = ($on ? true : false); 355 | } 356 | 357 | /** 358 | * Get whether or not appsecret_proof should be sent with requests. 359 | * 360 | * @return bool 361 | */ 362 | public static function useAppSecretProof() 363 | { 364 | return static::$useAppSecretProof; 365 | } 366 | 367 | } 368 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookSignedRequestFromInputHelper.php: -------------------------------------------------------------------------------- 1 | appId = FacebookSession::_getTargetAppId($appId); 64 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); 65 | 66 | $this->instantiateSignedRequest(); 67 | } 68 | 69 | /** 70 | * Instantiates a new SignedRequest entity. 71 | * 72 | * @param string|null $rawSignedRequest 73 | */ 74 | public function instantiateSignedRequest($rawSignedRequest = null) 75 | { 76 | $rawSignedRequest = $rawSignedRequest ?: $this->getRawSignedRequest(); 77 | 78 | if (!$rawSignedRequest) { 79 | return; 80 | } 81 | 82 | $this->signedRequest = new SignedRequest($rawSignedRequest, $this->state, $this->appSecret); 83 | } 84 | 85 | /** 86 | * Instantiates a FacebookSession from the signed request from input. 87 | * 88 | * @return FacebookSession|null 89 | */ 90 | public function getSession() 91 | { 92 | if ($this->signedRequest && $this->signedRequest->hasOAuthData()) { 93 | return FacebookSession::newSessionFromSignedRequest($this->signedRequest); 94 | } 95 | return null; 96 | } 97 | 98 | /** 99 | * Returns the SignedRequest entity. 100 | * 101 | * @return \Facebook\Entities\SignedRequest|null 102 | */ 103 | public function getSignedRequest() 104 | { 105 | return $this->signedRequest; 106 | } 107 | 108 | /** 109 | * Returns the user_id if available. 110 | * 111 | * @return string|null 112 | */ 113 | public function getUserId() 114 | { 115 | return $this->signedRequest ? $this->signedRequest->getUserId() : null; 116 | } 117 | 118 | /** 119 | * Get raw signed request from input. 120 | * 121 | * @return string|null 122 | */ 123 | abstract public function getRawSignedRequest(); 124 | 125 | /** 126 | * Get raw signed request from GET input. 127 | * 128 | * @return string|null 129 | */ 130 | public function getRawSignedRequestFromGet() 131 | { 132 | if (isset($_GET['signed_request'])) { 133 | return $_GET['signed_request']; 134 | } 135 | 136 | return null; 137 | } 138 | 139 | /** 140 | * Get raw signed request from POST input. 141 | * 142 | * @return string|null 143 | */ 144 | public function getRawSignedRequestFromPost() 145 | { 146 | if (isset($_POST['signed_request'])) { 147 | return $_POST['signed_request']; 148 | } 149 | 150 | return null; 151 | } 152 | 153 | /** 154 | * Get raw signed request from cookie set from the Javascript SDK. 155 | * 156 | * @return string|null 157 | */ 158 | public function getRawSignedRequestFromCookie() 159 | { 160 | $strCookieKey = 'fbsr_' . $this->appId; 161 | if (isset($_COOKIE[$strCookieKey])) { 162 | return $_COOKIE[$strCookieKey]; 163 | } 164 | return null; 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookThrottleException.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | 32 | class GraphAlbum extends GraphObject 33 | { 34 | /** 35 | * Returns the ID for the album. 36 | * 37 | * @return string|null 38 | */ 39 | public function getId() 40 | { 41 | return $this->getProperty('id'); 42 | } 43 | 44 | /** 45 | * Returns whether the viewer can upload photos to this album. 46 | * 47 | * @return boolean|null 48 | */ 49 | public function canUpload() 50 | { 51 | return $this->getProperty('can_upload'); 52 | } 53 | 54 | /** 55 | * Returns the number of photos in this album. 56 | * 57 | * @return int|null 58 | */ 59 | public function getCount() 60 | { 61 | return $this->getProperty('count'); 62 | } 63 | 64 | /** 65 | * Returns the ID of the album's cover photo. 66 | * 67 | * @return string|null 68 | */ 69 | public function getCoverPhoto() 70 | { 71 | return $this->getProperty('cover_photo'); 72 | } 73 | 74 | /** 75 | * Returns the time the album was initially created. 76 | * 77 | * @return \DateTime|null 78 | */ 79 | public function getCreatedTime() 80 | { 81 | $value = $this->getProperty('created_time'); 82 | if ($value) { 83 | return new \DateTime($value); 84 | } 85 | return null; 86 | } 87 | 88 | /** 89 | * Returns the time the album was updated. 90 | * 91 | * @return \DateTime|null 92 | */ 93 | public function getUpdatedTime() 94 | { 95 | $value = $this->getProperty('updated_time'); 96 | if ($value) { 97 | return new \DateTime($value); 98 | } 99 | return null; 100 | } 101 | 102 | /** 103 | * Returns the description of the album. 104 | * 105 | * @return string|null 106 | */ 107 | public function getDescription() 108 | { 109 | return $this->getProperty('description'); 110 | } 111 | 112 | /** 113 | * Returns profile that created the album. 114 | * 115 | * @return GraphUser|null 116 | */ 117 | public function getFrom() 118 | { 119 | return $this->getProperty('from', GraphUser::className()); 120 | } 121 | 122 | /** 123 | * Returns a link to this album on Facebook. 124 | * 125 | * @return string|null 126 | */ 127 | public function getLink() 128 | { 129 | return $this->getProperty('link'); 130 | } 131 | 132 | /** 133 | * Returns the textual location of the album. 134 | * 135 | * @return string|null 136 | */ 137 | public function getLocation() 138 | { 139 | return $this->getProperty('location'); 140 | } 141 | 142 | /** 143 | * Returns the title of the album. 144 | * 145 | * @return string|null 146 | */ 147 | public function getName() 148 | { 149 | return $this->getProperty('name'); 150 | } 151 | 152 | /** 153 | * Returns the privacy settings for the album. 154 | * 155 | * @return string|null 156 | */ 157 | public function getPrivacy() 158 | { 159 | return $this->getProperty('privacy'); 160 | } 161 | 162 | /** 163 | * Returns the type of the album. enum{profile, mobile, wall, normal, album} 164 | * 165 | * @return string|null 166 | */ 167 | public function getType() 168 | { 169 | return $this->getProperty('type'); 170 | } 171 | 172 | //TODO: public function getPlace() that should return GraphPage 173 | } 174 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphLocation.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphLocation extends GraphObject 33 | { 34 | 35 | /** 36 | * Returns the street component of the location 37 | * 38 | * @return string|null 39 | */ 40 | public function getStreet() 41 | { 42 | return $this->getProperty('street'); 43 | } 44 | 45 | /** 46 | * Returns the city component of the location 47 | * 48 | * @return string|null 49 | */ 50 | public function getCity() 51 | { 52 | return $this->getProperty('city'); 53 | } 54 | 55 | /** 56 | * Returns the state component of the location 57 | * 58 | * @return string|null 59 | */ 60 | public function getState() 61 | { 62 | return $this->getProperty('state'); 63 | } 64 | 65 | /** 66 | * Returns the country component of the location 67 | * 68 | * @return string|null 69 | */ 70 | public function getCountry() 71 | { 72 | return $this->getProperty('country'); 73 | } 74 | 75 | /** 76 | * Returns the zipcode component of the location 77 | * 78 | * @return string|null 79 | */ 80 | public function getZip() 81 | { 82 | return $this->getProperty('zip'); 83 | } 84 | 85 | /** 86 | * Returns the latitude component of the location 87 | * 88 | * @return float|null 89 | */ 90 | public function getLatitude() 91 | { 92 | return $this->getProperty('latitude'); 93 | } 94 | 95 | /** 96 | * Returns the street component of the location 97 | * 98 | * @return float|null 99 | */ 100 | public function getLongitude() 101 | { 102 | return $this->getProperty('longitude'); 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphObject.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphObject 33 | { 34 | 35 | /** 36 | * @var array - Holds the raw associative data for this object 37 | */ 38 | protected $backingData; 39 | 40 | /** 41 | * Creates a GraphObject using the data provided. 42 | * 43 | * @param array $raw 44 | */ 45 | public function __construct($raw) 46 | { 47 | if ($raw instanceof \stdClass) { 48 | $raw = get_object_vars($raw); 49 | } 50 | $this->backingData = $raw; 51 | 52 | if (isset($this->backingData['data']) && count($this->backingData) === 1) { 53 | if ($this->backingData['data'] instanceof \stdClass) { 54 | $this->backingData = get_object_vars($this->backingData['data']); 55 | } else { 56 | $this->backingData = $this->backingData['data']; 57 | } 58 | } 59 | } 60 | 61 | /** 62 | * cast - Return a new instance of a FacebookGraphObject subclass for this 63 | * objects underlying data. 64 | * 65 | * @param string $type The GraphObject subclass to cast to 66 | * 67 | * @return GraphObject 68 | * 69 | * @throws FacebookSDKException 70 | */ 71 | public function cast($type) 72 | { 73 | if ($this instanceof $type) { 74 | return $this; 75 | } 76 | if (is_subclass_of($type, GraphObject::className())) { 77 | return new $type($this->backingData); 78 | } else { 79 | throw new FacebookSDKException( 80 | 'Cannot cast to an object that is not a GraphObject subclass', 620 81 | ); 82 | } 83 | } 84 | 85 | /** 86 | * asArray - Return a key-value associative array for the given graph object. 87 | * 88 | * @return array 89 | */ 90 | public function asArray() 91 | { 92 | return $this->backingData; 93 | } 94 | 95 | /** 96 | * getProperty - Gets the value of the named property for this graph object, 97 | * cast to the appropriate subclass type if provided. 98 | * 99 | * @param string $name The property to retrieve 100 | * @param string $type The subclass of GraphObject, optionally 101 | * 102 | * @return mixed 103 | */ 104 | public function getProperty($name, $type = 'Facebook\GraphObject') 105 | { 106 | if (isset($this->backingData[$name])) { 107 | $value = $this->backingData[$name]; 108 | if (is_scalar($value)) { 109 | return $value; 110 | } else { 111 | return (new GraphObject($value))->cast($type); 112 | } 113 | } else { 114 | return null; 115 | } 116 | } 117 | 118 | /** 119 | * getPropertyAsArray - Get the list value of a named property for this graph 120 | * object, where each item has been cast to the appropriate subclass type 121 | * if provided. 122 | * 123 | * Calling this for a property that is not an array, the behavior 124 | * is undefined, so don’t do this. 125 | * 126 | * @param string $name The property to retrieve 127 | * @param string $type The subclass of GraphObject, optionally 128 | * 129 | * @return array 130 | */ 131 | public function getPropertyAsArray($name, $type = 'Facebook\GraphObject') 132 | { 133 | $target = array(); 134 | if (isset($this->backingData[$name]['data'])) { 135 | $target = $this->backingData[$name]['data']; 136 | } else if (isset($this->backingData[$name]) 137 | && !is_scalar($this->backingData[$name])) { 138 | $target = $this->backingData[$name]; 139 | } 140 | $out = array(); 141 | foreach ($target as $key => $value) { 142 | if (is_scalar($value)) { 143 | $out[$key] = $value; 144 | } else { 145 | $out[$key] = (new GraphObject($value))->cast($type); 146 | } 147 | } 148 | return $out; 149 | } 150 | 151 | /** 152 | * getPropertyNames - Returns a list of all properties set on the object. 153 | * 154 | * @return array 155 | */ 156 | public function getPropertyNames() 157 | { 158 | return array_keys($this->backingData); 159 | } 160 | 161 | /** 162 | * Returns the string class name of the GraphObject or subclass. 163 | * 164 | * @return string 165 | */ 166 | public static function className() 167 | { 168 | return get_called_class(); 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphPage.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | class GraphPage extends GraphObject 32 | { 33 | 34 | /** 35 | * Returns the ID for the user's page as a string if present. 36 | * 37 | * @return string|null 38 | */ 39 | public function getId() 40 | { 41 | return $this->getProperty('id'); 42 | } 43 | 44 | /** 45 | * Returns the Category for the user's page as a string if present. 46 | * 47 | * @return string|null 48 | */ 49 | public function getCategory() 50 | { 51 | return $this->getProperty('category'); 52 | } 53 | 54 | /** 55 | * Returns the Name of the user's page as a string if present. 56 | * 57 | * @return string|null 58 | */ 59 | public function getName() 60 | { 61 | return $this->getProperty('name'); 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphSessionInfo.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphSessionInfo extends GraphObject 33 | { 34 | 35 | /** 36 | * Returns the application id the token was issued for. 37 | * 38 | * @return string|null 39 | */ 40 | public function getAppId() 41 | { 42 | return $this->getProperty('app_id'); 43 | } 44 | 45 | /** 46 | * Returns the application name the token was issued for. 47 | * 48 | * @return string|null 49 | */ 50 | public function getApplication() 51 | { 52 | return $this->getProperty('application'); 53 | } 54 | 55 | /** 56 | * Returns the date & time that the token expires. 57 | * 58 | * @return \DateTime|null 59 | */ 60 | public function getExpiresAt() 61 | { 62 | $stamp = $this->getProperty('expires_at'); 63 | if ($stamp) { 64 | return (new \DateTime())->setTimestamp($stamp); 65 | } else { 66 | return null; 67 | } 68 | } 69 | 70 | /** 71 | * Returns whether the token is valid. 72 | * 73 | * @return boolean 74 | */ 75 | public function isValid() 76 | { 77 | return $this->getProperty('is_valid'); 78 | } 79 | 80 | /** 81 | * Returns the date & time the token was issued at. 82 | * 83 | * @return \DateTime|null 84 | */ 85 | public function getIssuedAt() 86 | { 87 | $stamp = $this->getProperty('issued_at'); 88 | if ($stamp) { 89 | return (new \DateTime())->setTimestamp($stamp); 90 | } else { 91 | return null; 92 | } 93 | } 94 | 95 | /** 96 | * Returns the scope permissions associated with the token. 97 | * 98 | * @return array 99 | */ 100 | public function getScopes() 101 | { 102 | return $this->getPropertyAsArray('scopes'); 103 | } 104 | 105 | /** 106 | * Returns the login id of the user associated with the token. 107 | * 108 | * @return string|null 109 | */ 110 | public function getId() 111 | { 112 | return $this->getProperty('user_id'); 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphUser.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphUser extends GraphObject 33 | { 34 | 35 | /** 36 | * Returns the ID for the user as a string if present. 37 | * 38 | * @return string|null 39 | */ 40 | public function getId() 41 | { 42 | return $this->getProperty('id'); 43 | } 44 | 45 | /** 46 | * Returns the name for the user as a string if present. 47 | * 48 | * @return string|null 49 | */ 50 | public function getName() 51 | { 52 | return $this->getProperty('name'); 53 | } 54 | 55 | public function getEmail() 56 | { 57 | return $this->getProperty('email'); 58 | } 59 | 60 | /** 61 | * Returns the first name for the user as a string if present. 62 | * 63 | * @return string|null 64 | */ 65 | public function getFirstName() 66 | { 67 | return $this->getProperty('first_name'); 68 | } 69 | 70 | /** 71 | * Returns the middle name for the user as a string if present. 72 | * 73 | * @return string|null 74 | */ 75 | public function getMiddleName() 76 | { 77 | return $this->getProperty('middle_name'); 78 | } 79 | 80 | /** 81 | * Returns the last name for the user as a string if present. 82 | * 83 | * @return string|null 84 | */ 85 | public function getLastName() 86 | { 87 | return $this->getProperty('last_name'); 88 | } 89 | 90 | /** 91 | * Returns the gender for the user as a string if present. 92 | * 93 | * @return string|null 94 | */ 95 | public function getGender() 96 | { 97 | return $this->getProperty('gender'); 98 | } 99 | 100 | /** 101 | * Returns the Facebook URL for the user as a string if available. 102 | * 103 | * @return string|null 104 | */ 105 | public function getLink() 106 | { 107 | return $this->getProperty('link'); 108 | } 109 | 110 | /** 111 | * Returns the users birthday, if available. 112 | * 113 | * @return \DateTime|null 114 | */ 115 | public function getBirthday() 116 | { 117 | $value = $this->getProperty('birthday'); 118 | if ($value) { 119 | return new \DateTime($value); 120 | } 121 | return null; 122 | } 123 | 124 | /** 125 | * Returns the current location of the user as a FacebookGraphLocation 126 | * if available. 127 | * 128 | * @return GraphLocation|null 129 | */ 130 | public function getLocation() 131 | { 132 | return $this->getProperty('location', GraphLocation::className()); 133 | } 134 | 135 | /** 136 | * Returns the timezone for the user as a int if present. 137 | * 138 | * @return string|null 139 | */ 140 | public function getTimezone() 141 | { 142 | return $this->getProperty('timezone'); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphUserPage.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | class GraphUserPage extends GraphObject 32 | { 33 | 34 | /** 35 | * Returns the ID for the user's page as a string if present. 36 | * 37 | * @return string|null 38 | */ 39 | public function getId() 40 | { 41 | return $this->getProperty('id'); 42 | } 43 | 44 | /** 45 | * Returns the Category for the user's page as a string if present. 46 | * 47 | * @return string|null 48 | */ 49 | public function getCategory() 50 | { 51 | return $this->getProperty('category'); 52 | } 53 | 54 | /** 55 | * Returns the Name of the user's page as a string if present. 56 | * 57 | * @return string|null 58 | */ 59 | public function getName() 60 | { 61 | return $this->getProperty('name'); 62 | } 63 | 64 | /** 65 | * Returns the Access Token used to access the user's page as a string if present. 66 | * 67 | * @return string|null 68 | */ 69 | public function getAccessToken() 70 | { 71 | return $this->getProperty('access_token'); 72 | } 73 | 74 | /** 75 | * Returns the Permissions for the user's page as an array if present. 76 | * 77 | * @return array|null 78 | */ 79 | public function getPermissions() 80 | { 81 | return $this->getProperty('perms'); 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookCurl.php: -------------------------------------------------------------------------------- 1 | curl === null) { 46 | $this->curl = curl_init(); 47 | } 48 | } 49 | 50 | /** 51 | * Set a curl option 52 | * 53 | * @param $key 54 | * @param $value 55 | */ 56 | public function setopt($key, $value) 57 | { 58 | curl_setopt($this->curl, $key, $value); 59 | } 60 | 61 | /** 62 | * Set an array of options to a curl resource 63 | * 64 | * @param array $options 65 | */ 66 | public function setopt_array(array $options) 67 | { 68 | curl_setopt_array($this->curl, $options); 69 | } 70 | 71 | /** 72 | * Send a curl request 73 | * 74 | * @return mixed 75 | */ 76 | public function exec() 77 | { 78 | return curl_exec($this->curl); 79 | } 80 | 81 | /** 82 | * Return the curl error number 83 | * 84 | * @return int 85 | */ 86 | public function errno() 87 | { 88 | return curl_errno($this->curl); 89 | } 90 | 91 | /** 92 | * Return the curl error message 93 | * 94 | * @return string 95 | */ 96 | public function error() 97 | { 98 | return curl_error($this->curl); 99 | } 100 | 101 | /** 102 | * Get info from a curl reference 103 | * 104 | * @param $type 105 | * 106 | * @return mixed 107 | */ 108 | public function getinfo($type) 109 | { 110 | return curl_getinfo($this->curl, $type); 111 | } 112 | 113 | /** 114 | * Get the currently installed curl version 115 | * 116 | * @return array 117 | */ 118 | public function version() 119 | { 120 | return curl_version(); 121 | } 122 | 123 | /** 124 | * Close the resource connection to curl 125 | */ 126 | public function close() 127 | { 128 | curl_close($this->curl); 129 | 130 | // closed handle has to be initialized again 131 | $this->curl = null; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookCurlHttpClient.php: -------------------------------------------------------------------------------- 1 | facebookCurl = $facebookCurl ?: new FacebookCurl(); 91 | self::$disableIPv6 = self::$disableIPv6 ?: false; 92 | } 93 | 94 | /** 95 | * Disable IPv6 resolution 96 | */ 97 | public static function disableIPv6() 98 | { 99 | self::$disableIPv6 = true; 100 | } 101 | 102 | /** 103 | * The headers we want to send with the request 104 | * 105 | * @param string $key 106 | * @param string $value 107 | */ 108 | public function addRequestHeader($key, $value) 109 | { 110 | $this->requestHeaders[$key] = $value; 111 | } 112 | 113 | /** 114 | * The headers returned in the response 115 | * 116 | * @return array 117 | */ 118 | public function getResponseHeaders() 119 | { 120 | return $this->responseHeaders; 121 | } 122 | 123 | /** 124 | * The HTTP status response code 125 | * 126 | * @return int 127 | */ 128 | public function getResponseHttpStatusCode() 129 | { 130 | return $this->responseHttpStatusCode; 131 | } 132 | 133 | /** 134 | * Sends a request to the server 135 | * 136 | * @param string $url The endpoint to send the request to 137 | * @param string $method The request method 138 | * @param array $parameters The key value pairs to be sent in the body 139 | * 140 | * @return string Raw response from the server 141 | * 142 | * @throws \Facebook\FacebookSDKException 143 | */ 144 | public function send($url, $method = 'GET', $parameters = array()) 145 | { 146 | $this->openConnection($url, $method, $parameters); 147 | $this->tryToSendRequest(); 148 | 149 | if ($this->curlErrorCode) { 150 | throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode); 151 | } 152 | 153 | // Separate the raw headers from the raw body 154 | list($rawHeaders, $rawBody) = $this->extractResponseHeadersAndBody(); 155 | 156 | $this->responseHeaders = self::headersToArray($rawHeaders); 157 | 158 | $this->closeConnection(); 159 | 160 | return $rawBody; 161 | } 162 | 163 | /** 164 | * Opens a new curl connection 165 | * 166 | * @param string $url The endpoint to send the request to 167 | * @param string $method The request method 168 | * @param array $parameters The key value pairs to be sent in the body 169 | */ 170 | public function openConnection($url, $method = 'GET', array $parameters = array()) 171 | { 172 | $options = array( 173 | CURLOPT_URL => $url, 174 | CURLOPT_CONNECTTIMEOUT => 10, 175 | CURLOPT_TIMEOUT => 60, 176 | CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects 177 | CURLOPT_HEADER => true, // Enable header processing 178 | CURLOPT_SSL_VERIFYHOST => 2, 179 | CURLOPT_SSL_VERIFYPEER => true, 180 | CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', 181 | ); 182 | 183 | if ($method !== 'GET') { 184 | $options[CURLOPT_POSTFIELDS] = !$this->paramsHaveFile($parameters) ? http_build_query($parameters, null, '&') : $parameters; 185 | } 186 | if ($method === 'DELETE' || $method === 'PUT') { 187 | $options[CURLOPT_CUSTOMREQUEST] = $method; 188 | } 189 | 190 | if (count($this->requestHeaders) > 0) { 191 | $options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders(); 192 | } 193 | 194 | if (self::$disableIPv6) { 195 | $options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; 196 | } 197 | 198 | $this->facebookCurl->init(); 199 | $this->facebookCurl->setopt_array($options); 200 | } 201 | 202 | /** 203 | * Closes an existing curl connection 204 | */ 205 | public function closeConnection() 206 | { 207 | $this->facebookCurl->close(); 208 | } 209 | 210 | /** 211 | * Try to send the request 212 | */ 213 | public function tryToSendRequest() 214 | { 215 | $this->sendRequest(); 216 | $this->curlErrorMessage = $this->facebookCurl->error(); 217 | $this->curlErrorCode = $this->facebookCurl->errno(); 218 | $this->responseHttpStatusCode = $this->facebookCurl->getinfo(CURLINFO_HTTP_CODE); 219 | } 220 | 221 | /** 222 | * Send the request and get the raw response from curl 223 | */ 224 | public function sendRequest() 225 | { 226 | $this->rawResponse = $this->facebookCurl->exec(); 227 | } 228 | 229 | /** 230 | * Compiles the request headers into a curl-friendly format 231 | * 232 | * @return array 233 | */ 234 | public function compileRequestHeaders() 235 | { 236 | $return = array(); 237 | 238 | foreach ($this->requestHeaders as $key => $value) { 239 | $return[] = $key . ': ' . $value; 240 | } 241 | 242 | return $return; 243 | } 244 | 245 | /** 246 | * Extracts the headers and the body into a two-part array 247 | * 248 | * @return array 249 | */ 250 | public function extractResponseHeadersAndBody() 251 | { 252 | $headerSize = self::getHeaderSize(); 253 | 254 | $rawHeaders = mb_substr($this->rawResponse, 0, $headerSize); 255 | $rawBody = mb_substr($this->rawResponse, $headerSize); 256 | 257 | return array(trim($rawHeaders), trim($rawBody)); 258 | } 259 | 260 | /** 261 | * Converts raw header responses into an array 262 | * 263 | * @param string $rawHeaders 264 | * 265 | * @return array 266 | */ 267 | public static function headersToArray($rawHeaders) 268 | { 269 | $headers = array(); 270 | 271 | // Normalize line breaks 272 | $rawHeaders = str_replace("\r\n", "\n", $rawHeaders); 273 | 274 | // There will be multiple headers if a 301 was followed 275 | // or a proxy was followed, etc 276 | $headerCollection = explode("\n\n", trim($rawHeaders)); 277 | // We just want the last response (at the end) 278 | $rawHeader = array_pop($headerCollection); 279 | 280 | $headerComponents = explode("\n", $rawHeader); 281 | foreach ($headerComponents as $line) { 282 | if (strpos($line, ': ') === false) { 283 | $headers['http_code'] = $line; 284 | } else { 285 | list ($key, $value) = explode(': ', $line); 286 | $headers[$key] = $value; 287 | } 288 | } 289 | 290 | return $headers; 291 | } 292 | 293 | /** 294 | * Return proper header size 295 | * 296 | * @return integer 297 | */ 298 | private function getHeaderSize() 299 | { 300 | $headerSize = $this->facebookCurl->getinfo(CURLINFO_HEADER_SIZE); 301 | // This corrects a Curl bug where header size does not account 302 | // for additional Proxy headers. 303 | if ( $this->needsCurlProxyFix() ) { 304 | // Additional way to calculate the request body size. 305 | if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { 306 | $headerSize = mb_strlen($this->rawResponse) - $m[1]; 307 | } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { 308 | $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); 309 | } 310 | } 311 | 312 | return $headerSize; 313 | } 314 | 315 | /** 316 | * Detect versions of Curl which report incorrect header lengths when 317 | * using Proxies. 318 | * 319 | * @return boolean 320 | */ 321 | private function needsCurlProxyFix() 322 | { 323 | $ver = $this->facebookCurl->version(); 324 | $version = $ver['version_number']; 325 | 326 | return $version < self::CURL_PROXY_QUIRK_VER; 327 | } 328 | 329 | /** 330 | * Detect if the params have a file to upload. 331 | * 332 | * @param array $params 333 | * 334 | * @return boolean 335 | */ 336 | private function paramsHaveFile(array $params) 337 | { 338 | foreach ($params as $value) { 339 | if ($value instanceof \CURLFile) { 340 | return true; 341 | } 342 | } 343 | 344 | return false; 345 | } 346 | 347 | } 348 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookGuzzleHttpClient.php: -------------------------------------------------------------------------------- 1 | requestHeaders[$key] = $value; 71 | } 72 | 73 | /** 74 | * The headers returned in the response 75 | * 76 | * @return array 77 | */ 78 | public function getResponseHeaders() 79 | { 80 | return $this->responseHeaders; 81 | } 82 | 83 | /** 84 | * The HTTP status response code 85 | * 86 | * @return int 87 | */ 88 | public function getResponseHttpStatusCode() 89 | { 90 | return $this->responseHttpStatusCode; 91 | } 92 | 93 | /** 94 | * Sends a request to the server 95 | * 96 | * @param string $url The endpoint to send the request to 97 | * @param string $method The request method 98 | * @param array $parameters The key value pairs to be sent in the body 99 | * 100 | * @return string Raw response from the server 101 | * 102 | * @throws \Facebook\FacebookSDKException 103 | */ 104 | public function send($url, $method = 'GET', $parameters = array()) 105 | { 106 | $options = array(); 107 | if ($parameters) { 108 | $options = array('body' => $parameters); 109 | } 110 | 111 | $options['verify'] = __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem'; 112 | 113 | $request = self::$guzzleClient->createRequest($method, $url, $options); 114 | 115 | foreach($this->requestHeaders as $k => $v) { 116 | $request->setHeader($k, $v); 117 | } 118 | 119 | try { 120 | $rawResponse = self::$guzzleClient->send($request); 121 | } catch (RequestException $e) { 122 | if ($e->getPrevious() instanceof AdapterException) { 123 | throw new FacebookSDKException($e->getMessage(), $e->getCode()); 124 | } 125 | $rawResponse = $e->getResponse(); 126 | } 127 | 128 | $this->responseHttpStatusCode = $rawResponse->getStatusCode(); 129 | $this->responseHeaders = $rawResponse->getHeaders(); 130 | 131 | return $rawResponse->getBody(); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookHttpable.php: -------------------------------------------------------------------------------- 1 | stream = stream_context_create($options); 53 | } 54 | 55 | /** 56 | * The response headers from the stream wrapper 57 | * 58 | * @return array|null 59 | */ 60 | public function getResponseHeaders() 61 | { 62 | return $this->responseHeaders; 63 | } 64 | 65 | /** 66 | * Send a stream wrapped request 67 | * 68 | * @param string $url 69 | * 70 | * @return mixed 71 | */ 72 | public function fileGetContents($url) 73 | { 74 | $rawResponse = file_get_contents($url, false, $this->stream); 75 | $this->responseHeaders = $http_response_header; 76 | return $rawResponse; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookStreamHttpClient.php: -------------------------------------------------------------------------------- 1 | requestHeaders[$key] = $value; 67 | } 68 | 69 | /** 70 | * The headers returned in the response 71 | * 72 | * @return array 73 | */ 74 | public function getResponseHeaders() 75 | { 76 | return $this->responseHeaders; 77 | } 78 | 79 | /** 80 | * The HTTP status response code 81 | * 82 | * @return int 83 | */ 84 | public function getResponseHttpStatusCode() 85 | { 86 | return $this->responseHttpStatusCode; 87 | } 88 | 89 | /** 90 | * Sends a request to the server 91 | * 92 | * @param string $url The endpoint to send the request to 93 | * @param string $method The request method 94 | * @param array $parameters The key value pairs to be sent in the body 95 | * 96 | * @return string Raw response from the server 97 | * 98 | * @throws \Facebook\FacebookSDKException 99 | */ 100 | public function send($url, $method = 'GET', $parameters = array()) 101 | { 102 | $options = array( 103 | 'http' => array( 104 | 'method' => $method, 105 | 'timeout' => 60, 106 | 'ignore_errors' => true 107 | ), 108 | 'ssl' => array( 109 | 'verify_peer' => true, 110 | 'verify_peer_name' => true, 111 | 'allow_self_signed' => true, // All root certificates are self-signed 112 | 'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', 113 | ), 114 | ); 115 | 116 | if ($parameters) { 117 | $options['http']['content'] = http_build_query($parameters, null, '&'); 118 | 119 | $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 120 | } 121 | 122 | $options['http']['header'] = $this->compileHeader(); 123 | 124 | self::$facebookStream->streamContextCreate($options); 125 | $rawResponse = self::$facebookStream->fileGetContents($url); 126 | $rawHeaders = self::$facebookStream->getResponseHeaders(); 127 | 128 | if ($rawResponse === false || !$rawHeaders) { 129 | throw new FacebookSDKException('Stream returned an empty response', 660); 130 | } 131 | 132 | $this->responseHeaders = self::formatHeadersToArray($rawHeaders); 133 | $this->responseHttpStatusCode = self::getStatusCodeFromHeader($this->responseHeaders['http_code']); 134 | 135 | return $rawResponse; 136 | } 137 | 138 | /** 139 | * Formats the headers for use in the stream wrapper 140 | * 141 | * @return string 142 | */ 143 | public function compileHeader() 144 | { 145 | $header = []; 146 | foreach($this->requestHeaders as $k => $v) { 147 | $header[] = $k . ': ' . $v; 148 | } 149 | 150 | return implode("\r\n", $header); 151 | } 152 | 153 | /** 154 | * Converts array of headers returned from the wrapper into 155 | * something standard 156 | * 157 | * @param array $rawHeaders 158 | * 159 | * @return array 160 | */ 161 | public static function formatHeadersToArray(array $rawHeaders) 162 | { 163 | $headers = array(); 164 | 165 | foreach ($rawHeaders as $line) { 166 | if (strpos($line, ':') === false) { 167 | $headers['http_code'] = $line; 168 | } else { 169 | list ($key, $value) = explode(': ', $line); 170 | $headers[$key] = $value; 171 | } 172 | } 173 | 174 | return $headers; 175 | } 176 | 177 | /** 178 | * Pulls out the HTTP status code from a response header 179 | * 180 | * @param string $header 181 | * 182 | * @return int 183 | */ 184 | public static function getStatusCodeFromHeader($header) 185 | { 186 | preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $header, $match); 187 | return (int) $match[1]; 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/certs/DigiCertHighAssuranceEVRootCA.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs 3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 4 | d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j 5 | ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL 6 | MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 7 | LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug 8 | RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm 9 | +9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW 10 | PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM 11 | xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB 12 | Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3 13 | hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg 14 | EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF 15 | MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA 16 | FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec 17 | nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z 18 | eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF 19 | hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2 20 | Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe 21 | vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep 22 | +OkuE6N36B9K 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /image/nopic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kndnsow/moodle-block_course_publish/3a2ff48f52e5cb277cf6ee21cb9ab7afe01a2e45/image/nopic.jpg -------------------------------------------------------------------------------- /lang/en/block_course_publish.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Strings for component 'block_course_publish', language 'en' 18 | * 19 | * @package block_course_publish 20 | * @author Sandipa Mukherjee 21 | * @copyright DUALCUBE {@link http://dualcube.com/} 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | $string['appid'] = 'App ID'; 25 | $string['secretkey'] = 'Secret Key'; 26 | $string['callbackurl'] = 'Callback Url'; 27 | $string['link'] = 'Link'; 28 | $string['message'] = 'Message'; 29 | $string['description'] = 'Description'; 30 | $string['pageaccesstoken'] = 'Pageaccesstoken'; 31 | $string['pageid'] = 'Pageid'; 32 | $string['descconfig'] = 'Description of the config section'; 33 | $string['descfoo'] = 'Config description'; 34 | $string['headerconfig'] = 'Config section header'; 35 | $string['labelfoo'] = 'Config label'; 36 | $string['course_publish:addinstance'] = 'Add a course publish block'; 37 | $string['course_publish:myaddinstance'] = 'Add a course publish block to my moodle'; 38 | $string['pluginname'] = 'Course publish'; 39 | $string['loginwithfacebook'] = 'Login with Facebook'; -------------------------------------------------------------------------------- /postlink.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Course_publish block caps. 19 | * 20 | * @package block_course_publish 21 | * @author Sandipa Mukherjee 22 | * @copyright 2015 DUALCUBE {@link http://dualcube.com/} 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); 27 | require_login(); 28 | require_once($CFG->dirroot.'/blocks/course_publish/facebook-php-sdk-v4-4.0-dev/autoload.php'); 29 | use Facebook\FacebookSession; 30 | use Facebook\FacebookRequest; 31 | use Facebook\GraphUser; 32 | use Facebook\FacebookRequestException; 33 | use Facebook\FacebookRedirectLoginHelper; 34 | GLOBAL $DB; 35 | $plugin = 'block_course_publish'; 36 | $courseid = optional_param('courseid', 0, PARAM_INT); 37 | if ($courseid != 0) { 38 | $coursepublish = $DB->get_record('block_course_publish', array('courseid' => $courseid)); 39 | $coursenamepublish = $DB->get_record('course', array('id' => $courseid)); 40 | $coursecontext = context_course::instance($courseid); 41 | $isfile = $DB->get_records_sql("Select * from {files} where contextid = ? and filename != ? and filearea = ?", array($coursecontext->id, ".", "overviewfiles")); 42 | if ($isfile) { 43 | foreach ($isfile as $key1 => $isfilevalue) { 44 | $courseimage = $CFG->wwwroot . "/pluginfile.php/" . $isfilevalue->contextid . "/" . $isfilevalue->component . "/" . $isfilevalue->filearea . "/" . $isfilevalue->filename; 45 | } 46 | } 47 | if (!empty($courseimage)) { 48 | $coursepublishpicture = $courseimage; 49 | } else { 50 | $coursepublishpicture = $CFG->wwwroot . "/blocks/course_publish/image/nopic.jpg"; 51 | } 52 | FacebookSession::setDefaultApplication($coursepublish->appid, $coursepublish->secretkey); 53 | // If you already have a valid access token. 54 | $session = new FacebookSession($coursepublish->pageaccesstoken); 55 | if ($session) { 56 | try { 57 | $response = (new FacebookRequest( 58 | $session, 'POST', '/'.$coursepublish->pageid.'/feed', array( 59 | 'link' => $coursepublish->link, 60 | 'message' => $coursepublish->message, 61 | 'picture' => $coursepublishpicture, 62 | 'caption' => $coursenamepublish->fullname 63 | )))->execute()->getGraphObject(); 64 | echo 'Successfully Posted '; 65 | echo "Posted with id: " . $response->getProperty('id'); 66 | } catch (FacebookRequestException $e) { 67 | echo "Exception occured, code: " . $e->getCode(); 68 | echo " with message: " . $e->getMessage(); 69 | } 70 | } 71 | redirect($CFG->wwwroot.'/course/view.php?id='.$courseid); 72 | } 73 | redirect($CFG->wwwroot); 74 | -------------------------------------------------------------------------------- /thirdpartylibs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | facebook-php-sdk-v4-4.0-dev/ 5 | Facebook SDK for PHP 6 | v4.0.0 7 | Apache 8 | 2.0 9 | 10 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Course_publish block caps. 19 | * 20 | * @package block_course_publish 21 | * @author Dualcube 22 | * @copyright 2022 DUALCUBE {@link http://dualcube.com/} 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | $plugin->version = 2022050606; // The current plugin version (Date: YYYYMMDDXX). 29 | $plugin->requires = 2012112900; // Requires this Moodle version. 30 | $plugin->component = 'block_course_publish'; // Full name of the plugin (used for diagnostics). 31 | $plugin->maturity = MATURITY_STABLE; 32 | $plugin->release = 'v2.8-r4'; 33 | --------------------------------------------------------------------------------