/**
  * Singleton main method
  * @return FacebookAPI
  */
 public static function inst()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Given a possible action defined in $wgFbOpenGraphRegisteredActions,
  * this function translates the action into the proper Open Graph ID
  * (which usually looks like NAMESPACE:action).
  */
 private static function getAction($action)
 {
     global $wgFbOpenGraph, $wgFbNamespace, $wgFbOpenGraphRegisteredActions;
     if (FacebookAPI::isNamespaceSetup() && !empty($wgFbOpenGraph) && !empty($wgFbOpenGraphRegisteredActions) && !empty($wgFbOpenGraphRegisteredActions[$action])) {
         return $wgFbNamespace . ':' . $wgFbOpenGraphRegisteredActions[$action];
     }
     return false;
 }
 protected function getConfigurableField($dbField, $configField)
 {
     $value = FacebookAPI::get_config($configField);
     if ($value == 'SiteConfig') {
         return $this->owner->getField($dbField);
     }
     return $value;
 }
示例#4
0
 function checkUser()
 {
     $redirect_uri = Addons::createAddonShow('Login', 'no_register_display', array('type' => 'facebook', 'do' => "bind"));
     $facebook = new FacebookAPI(array('appId' => FACEBOOK_KEY, 'secret' => FACEBOOK_SECRET));
     $token = $facebook->getAccessTokenFromCode($_GET['code'], $redirect_uri);
     //dump($token);
     //exit;
     // if($user){
     // 	$_SESSION['baidu']['access_token']['oauth_token'] = $access_token;
     // 	$_SESSION['baidu']['access_token']['oauth_token_secret'] = $refresh_token;
     // 	$_SESSION['baidu']['isSync'] = 0;
     // 	$_SESSION['baidu']['uid'] = $user['uid'];
     // 	$_SESSION['open_platform_type'] = 'baidu';
     // 	return $user;
     // }else{
     // 	return false;
     // }
 }
 /**
  * Call the youtube factory function to get and update the video entries
  */
 public function handleSyncWithFacebook($gridField, $request = null)
 {
     // Trigger API to sync posts
     FacebookAPI::inst()->syncPosts();
     // Trigger API to sync pics
     FacebookAPI::inst()->syncPics();
     // Redirect to the grid overview
     Controller::curr()->redirectBack();
 }
 public function run($request)
 {
     echo "Facebook posts are being synced...\n";
     FacebookAPI::inst()->syncPosts();
     echo FacebookPost::get()->count() . " posts have been synced.\n\n";
     echo "Facebook timeline pics are being synced...\n";
     FacebookAPI::inst()->syncPics();
     echo FacebookTimelinePic::get()->count() . " pics have been synced.\n\n";
     echo "Facebook sync done!\n";
 }
 /**
  * @return Facebook Facebook API instance
  */
 public static function get()
 {
     if (self::$instance) {
         return self::$instance;
     }
     // Check application is configured
     $settings = SiteConfig::current_site_config();
     if (empty($settings->FacebookApplicationID)) {
         return null;
     }
     // Construct
     return self::$instance = new Facebook(array('appId' => $settings->FacebookApplicationID, 'secret' => $settings->FacebookApplicationSecret, 'cookie' => true));
 }
示例#8
0
文件: cron.php 项目: hoonio/wordpress
<?php

define('WP_USE_THEMES', false);
require '../../../wp-blog-header.php';
// handle cron request
if (isset($_GET['update']) && isset($_GET['secret']) && $_GET['secret'] == get_option('fb_secret')) {
    echo 'Updating Fotobook (be patient)...';
    ob_flush();
    flush();
    $facebook = new FacebookAPI();
    if ($facebook->link_active()) {
        $facebook->update_albums();
    }
    echo 'Done';
} else {
    echo 'Invalid URL';
}
示例#9
0
<?php

require_once 'client/facebook.php';
$appapikey = 'd9750a5976aa776dbdc1b48dc31920ee';
$appsecret = '6219a0b85473cff9dcbe154eb3d3b64e';
$facebook = new FacebookAPI($appapikey, $appsecret);
$user = $facebook->require_login();
//[todo: change the following url to your callback url]
#$appcallbackurl = 'http://wikidiy.com/facebook-platform/';
$appcallbackurl = 'http://www.wikihow.com/Special:Facebook';
//catch the exception that gets thrown if the cookie has an invalid session_key in it
try {
    if (!$facebook->api_client->users_isAppAdded()) {
        $facebook->redirect($facebook->get_add_url());
    }
} catch (Exception $ex) {
    //this will clear cookies for your application and redirect them to a login prompt
    $facebook->set_user(null, null);
    $facebook->redirect($appcallbackurl);
}
示例#10
0
<?php

/*
Fotobook Management Panel
*/
// get facebook authorization token
$facebook = new FacebookAPI();
?>

<?php 
if (!$facebook->link_active()) {
    ?>
<div id="message" class="error fade"><p>There is no Facebook account linked to this plugin.  Change that in the <a href="<?php 
    echo FB_OPTIONS_URL;
    ?>
">settings panel</a>.</p></div>
<?php 
}
?>

<?php 
if ($fb_message) {
    ?>
<div id="message" class="<?php 
    echo $facebook->error ? 'error' : 'updated';
    ?>
 fade"><p><?php 
    echo $fb_message;
    ?>
</p></div>
<?php 
示例#11
0
<?php

/*
Fotobook Options Panel
*/
// get facebook authorization token
$facebook = new FacebookAPI();
// authorize session
if (isset($_POST['activate-facebook'])) {
    $facebook->get_auth_session($_POST['activate-facebook']);
}
// remove the user
if (isset($_GET['deactivate-facebook']) && isset($facebook->sessions[$_GET['deactivate-facebook']])) {
    $facebook->remove_user($_GET['deactivate-facebook']);
}
$this_page = $_SERVER['PHP_SELF'] . '?page=' . $_GET['page'];
// get styles
$styles = fb_get_styles();
// update options if form is submitted
if (isset($_POST['submit'])) {
    fb_options_update_albums_page($_POST['fb_albums_page']);
    update_option('fb_number_rows', $_POST['fb_number_rows']);
    update_option('fb_style', $_POST['fb_style']);
    if ($_POST['fb_number_cols'] != 0) {
        update_option('fb_number_cols', $_POST['fb_number_cols']);
    }
    if (is_numeric($_POST['fb_embedded_width'])) {
        update_option('fb_embedded_width', $_POST['fb_embedded_width']);
    }
    update_option('fb_thumb_size', $_POST['fb_thumb_size']);
    update_option('fb_albums_per_page', $_POST['fb_albums_per_page']);
示例#12
0
function fb_ajax_handler()
{
    if (!isset($_POST['action']) || $_POST['action'] != 'fotobook') {
        return false;
    }
    // handle hide/unhide requests
    if (isset($_POST['hide'])) {
        fb_toggle_album_hiding($_POST['hide']);
        echo 'success';
    } elseif (isset($_POST['order'])) {
        fb_update_album_order($_POST['order']);
        echo 'success';
    } elseif (isset($_POST['reset_order'])) {
        fb_reset_album_order();
        echo 'The albums have been ordered by their modification date.';
    } elseif (isset($_POST['remove_all'])) {
        fb_remove_all();
        echo 'All albums have been removed.';
    } elseif (isset($_POST['progress'])) {
        echo round(get_option('fb_update_progress'));
    } elseif (isset($_POST['update'])) {
        $facebook = new FacebookAPI();
        if ($facebook->link_active()) {
            $facebook->update_albums();
            echo $facebook->msg;
        } else {
            echo 'There are no accounts linked to Fotobook.';
        }
    } elseif (isset($_POST['albums_list'])) {
        fb_display_manage_list($_POST['message']);
    }
    exit;
}
 /**
  * Retrieves the list of all authorised permissions for the current user
  * with the most updated version from the server
  * @return array List of approved permissions, or empty array if none are approved
  */
 public function updateGrantedFacebookPermissions()
 {
     // Check user is logged in
     $user = FacebookAPI::get()->getUser();
     if (empty($user)) {
         return array();
     }
     // Check permissions are retrieveable
     $permissions = FacebookAPI::get()->api("/{$user}/permissions");
     if (empty($permissions['data'])) {
         return array();
     }
     // $permissions should look something like the below
     // $permissions = array('data' => array(array('installed' => 1, 'email' => 1)), 'paging' => array())
     // Merge each array element in data
     $permissionItems = call_user_func_array('array_merge', $permissions['data']);
     return array_keys($permissionItems);
 }
示例#14
0
 public static function getPermissions()
 {
     global $wgEnableEmail, $wgFbUserRightsFromGroup, $wgFbOpenGraph, $wgFbOpenGraphRegisteredActions;
     if (self::$scope === NULL) {
         $scope = array();
         if (!empty($wgEnableEmail)) {
             $scope[] = 'email';
         }
         if (!empty($wgFbUserRightsFromGroup)) {
             $scope[] = 'user_groups';
         }
         if (!empty($wgFbOpenGraph) && !empty($wgFbOpenGraphRegisteredActions)) {
             $scope[] = 'publish_actions';
         }
         wfRunHooks('FacebookPermissions', array(&$scope));
         self::$scope = $scope;
     }
     return implode(',', self::$scope);
 }
 /**
 * Modify the preferences form. At the moment, we simply turn the user name
 * into a link to the user's facebook profile.
 * 
 * TODO: This hook no longer seems to work...
 *
 	public static function RenderPreferencesForm( $form, $output ) {
 		global $facebook, $wgUser;
 		
 		$ids = FacebookDB::getFacebookIDs($wgUser);
 		
 		$fb_user = $facebook->getUser();
 		if( $fb_user && count($ids) > 0 && in_array( $fb_user, $ids )) {
 			$html = $output->getHTML();
 			$name = $wgUser->getName();
 			$i = strpos( $html, $name );
 			if ($i !== FALSE) {
 				// If the user has a valid Facebook ID, link to the Facebook profile
 				try {
 					$fbUser = $facebook->api('/me');
 					// Replace the old output with the new output
 					$html = substr( $html, 0, $i ) .
 					        preg_replace("/$name/", "$name (<a href=\"$fbUser[link]\" " .
 					                     "class='mw-userlink mw-facebookuser'>" .
 					                     wfMsg('facebook-link-to-profile') . "</a>)",
 					                     substr( $html, $i ), 1);
 					$output->clearHTML();
 					$output->addHTML( $html );
 				} catch (FacebookApiException $e) {
 					error_log($e);
 				}
 			}
 		}
 		return true;
 	} // RenderPreferencesForm hook
 	
 	/**
 * Add several meta property namespace attributes to the <head> tag.
 * 
 * This hook follows the steps outlined in the Open Graph Beta tutorial:
 * https://developers.facebook.com/docs/beta/opengraph/tutorial/
 */
 static function SkinTemplateOutputPageBeforeExec(&$skin, &$tpl)
 {
     global $wgFbOpenGraph, $wgFbNamespace, $wgFbOpenGraphRegisteredObjects;
     // If there are no Open Graph tags, we can skip this step
     if (!empty($wgFbOpenGraph)) {
         $head = '<head prefix="og: http://ogp.me/ns#';
         // I think this is for the fb:app_id and fp:page_id meta tags (see link),
         // but your guess is as good as mine
         // https://developers.facebook.com/docs/opengraph/objects/builtin/
         $head .= ' fb: http://ogp.me/ns/fb#';
         if (FacebookAPI::isNamespaceSetup()) {
             $head .= " {$wgFbNamespace}: http://ogp.me/ns/fb/{$wgFbNamespace}#";
         }
         // Use article prefix for built-in type (when $wgFbOpenGraphRegisteredObjects['article'] is empty)
         if (empty($wgFbOpenGraphRegisteredObjects) || empty($wgFbOpenGraphRegisteredObjects['article'])) {
             $head .= ' article: http://ogp.me/ns/article#';
         }
         $head .= '">';
         $headElement = $tpl->data['headelement'];
         $headElement = str_replace('<head>', $head, $headElement);
         $tpl->set('headelement', $headElement);
     }
     return true;
 }
 /**
  * Performs the translation between generic Open Graph object types and
  * custom ones defined by this Facebook application.
  * 
  * @param string $generic
  */
 protected function translateType($generic)
 {
     global $wgFbNamespace, $wgFbOpenGraphRegisteredObjects;
     if (FacebookAPI::isNamespaceSetup()) {
         if (!empty($wgFbOpenGraphRegisteredObjects) && isset($wgFbOpenGraphRegisteredObjects[$generic])) {
             return $wgFbNamespace . ':' . $wgFbOpenGraphRegisteredObjects[$generic];
         } else {
             // "article" is special because it's a built-in type
             return $generic == 'article' ? $generic : $wgFbNamespace . ':' . $generic;
         }
     }
     return $generic;
 }
 public function post_request($method, $params)
 {
     $params['method'] = $method;
     $params['session_key'] = $this->session_key;
     $params['api_key'] = $this->api_key;
     $params['call_id'] = microtime(true);
     if ($params['call_id'] <= $this->last_call_id) {
         $params['call_id'] = $this->last_call_id + 0.001;
     }
     $this->last_call_id = $params['call_id'];
     if (!isset($params['v'])) {
         $params['v'] = '1.0';
     }
     $post_params = array();
     foreach ($params as $key => &$val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $post_params[] = $key . '=' . urlencode($val);
     }
     $secret = $this->secret;
     $post_params[] = 'sig=' . FacebookAPI::generate_sig($params, $secret);
     $post_string = implode('&', $post_params);
     if (function_exists('curl_init')) {
         // Use CURL if installed...
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $this->server_addr);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion());
         $result = curl_exec($ch);
         curl_close($ch);
     } else {
         // Non-CURL based version...
         $context = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n" . 'User-Agent: Facebook API PHP5 Client 1.1 (non-curl) ' . phpversion() . "\r\n" . 'Content-length: ' . strlen($post_string), 'content' => $post_string));
         $contextid = stream_context_create($context);
         $sock = fopen($this->server_addr, 'r', false, $contextid);
         if ($sock) {
             $result = '';
             while (!feof($sock)) {
                 $result .= fgets($sock, 4096);
             }
             fclose($sock);
         }
     }
     return $result;
 }
 /**
  * Helper function to create name-value pairs from the list of attributes passed to the
  * parser hook.
  */
 static function implodeAttrs($args)
 {
     $attrs = '';
     // The default action is to strip all event handlers and allow the tag
     foreach ($args as $name => $value) {
         // Disable all event handlers (e.g. onClick, onLogin)
         if (substr($name, 0, 2) == 'on') {
             continue;
         }
         // Render perms="auto" and scope="auto" with the correct permissions
         // TODO: allow fields param to be "auto" for <fb:registration>
         if (($name == 'perms' || $name == 'scope') && $value == 'auto') {
             $value = FacebookAPI::getPermissions();
         }
         // Otherwise, pass the attribute through htmlspecialchars unmodified
         $attrs .= " {$name}=\"" . htmlspecialchars($value) . '"';
     }
     return $attrs;
 }
    /**
     * This view is sent when $wgFbDisableLogin is true. In this case, the user
     * must be logged in to Facebook to view the wiki, so we present a single
     * login button.
     */
    private function exclusiveLoginToFacebookView()
    {
        global $wgOut, $wgSitename, $wgUser;
        $loginFormWidth = 400;
        // pixels
        $this->outputHeader();
        $html = '
<div id="userloginForm">
	<form style="width: ' . $loginFormWidth . 'px;">
		<h2>' . wfMsg('userlogin') . '</h2>
		<p>' . wfMsg('facebook-only-text', $wgSitename) . '<br/><br/></p>' . "\n";
        // Compatiblity with MW < 1.18
        global $wgVersion;
        if (version_compare($wgVersion, '1.18', '>=')) {
            $skin = $this->getSkin();
        } else {
            global $wgUser;
            $skin = $wgUser->getSkin();
        }
        $html .= '<fb:login-button show-faces="true" width="' . $loginFormWidth . '" max-rows="3" scope="' . FacebookAPI::getPermissions() . '" colorscheme="' . FacebookXFBML::getColorScheme($skin->getSkinName()) . '"></fb:login-button><br/><br/><br/>' . "\n";
        // Add a pretty Like box to entice the user to log in
        $html .= '<fb:like href="' . Title::newMainPage()->getFullURL() . '" send="false" width="' . $loginFormWidth . '" show_faces="true"></fb:like>';
        $html .= '
	</form>
</div>';
        $wgOut->addHTML($html);
    }