Skip to content

Commit

Permalink
Restore "Pages You Manage" to Facebook Add Page setting
Browse files Browse the repository at this point in the history
The return value of the isAccoutPage function seems to be wrong. The 'type' attribute belongs to the account metadata.
With this new conditional expression, both places are evaluated, and if in any one the attribute is present and the value is 'page', then the return value is true.

DISCLAIMER: SOCIALMEDIA PROJECT - CEN-20101037 - This contribution has been kindly sponsored by the Centro para el Desarrollo Tecnológico Industrial within the Programa de Investigación Nacional Español CENIT. - http://www.cenitsocialmedia.es/

Co-authored by @ginatrapani: Added tests, cleaned up code style, added docblocks
Closes #1321, closes #1334
  • Loading branch information
perep authored and ginatrapani committed May 24, 2012
1 parent 1d94477 commit f6e0b19
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Expand Up @@ -83,12 +83,22 @@ public function authControl() {
}
return $this->generateView();
}

public function isAccountPage($account_id, $access_token) {
/**
* Return whether or not a Facebook account ID is a page.
* @param str $account_id
* @param str $access_token
* @return bool
*/
protected function isAccountPage($account_id, $access_token) {
$account = FacebookGraphAPIAccessor::apiRequest('/' . $account_id . '?metadata=true', $access_token);
return !empty($account) && !empty($account->type) && $account->type == 'page';
return !empty($account)
&& ((!empty($account->type) && (strcmp($account->type, 'page')==0))
|| (!empty($account->metadata->type) && (strcmp($account->metadata->type, 'page')==0)));
}

/**
* Populate view manager with Facebook interaction UI, like the Facebook Add User button and page dropdown.
* @param array $options 'facebook_app_id' and 'facebook_api_secret'
*/
protected function setUpFacebookInteractions($options) {
// Create our Facebook Application instance
$facebook = new Facebook(array(
Expand Down Expand Up @@ -160,14 +170,12 @@ protected function setUpFacebookInteractions($options) {

$this->addToView('owner_instances', $owner_instances);
}

/**
* Process actions based on $_GET parameters. Authorize FB user or add FB page.
* @param arr $options Facebook plugin options
* @param Facebook $facebook Facebook object
*/
protected function processPageActions($options, Facebook $facebook) {

//authorize user
if (isset($_GET["code"]) && isset($_GET["state"])) {
//validate state to avoid CSRF attacks
Expand Down Expand Up @@ -222,7 +230,6 @@ protected function processPageActions($options, Facebook $facebook) {
$page_data->picture);
}
}

/**
* Save newly-acquired OAuth access token
* @param int $fb_user_id
Expand Down Expand Up @@ -264,7 +271,6 @@ protected function saveAccessToken($fb_user_id, $fb_access_token, $fb_username)
}
$this->view_mgr->clear_all_cache();
}

/**
* Insert Facebook page instance into the data store
* @param str $fb_page_id
Expand Down
Expand Up @@ -211,7 +211,7 @@ public function testConfigOptionsIsAdminWithSSL() {
$this->assertPattern($expected_pattern, $output);
}

public function testConfiguredPluginWithOneFacebookUserWithSeveralLikedPages() {
public function testConfiguredPluginWithOneFacebookUserWithSeveralLikedAndManagedPages() {
self::buildInstanceData();
// build some options data
$options_arry = $this->buildPluginOptions();
Expand All @@ -229,9 +229,17 @@ public function testConfiguredPluginWithOneFacebookUserWithSeveralLikedPages() {
$this->assertNull($v_mgr->getTemplateDataItem('owner_instance_pages'));
$this->assertIsA($v_mgr->getTemplateDataItem('owner_instances'), 'Array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('owner_instances')), 1);
$this->assertPattern("/Pages You Like/", $output);
$this->assertPattern("/The Wire/", $output);
$this->assertPattern("/Glee/", $output);
$this->assertPattern("/Brooklyn, New York/", $output);

//The mock API accessor reads the page accounts JSON from the testdata/606837591_accounts file
$managed_pages = $v_mgr->getTemplateDataItem('user_admin_pages');
$this->assertIsA($managed_pages, 'Array');
$this->assertEqual($managed_pages[606837591][0]->name, 'Sample Cause');
$this->assertPattern("/Pages You Manage/", $output);
$this->assertPattern("/Sample Cause/", $output);
}

public function testConfiguredPluginWithOneFacebookUserNoLikedPages() {
Expand Down
@@ -1,11 +1,11 @@
{
"id": "107982202636989",
"name": "Sample Cause",
"picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/276798_107982202636989_4098521_s.jpg",
"link": "https://www.facebook.com/pages/Sample-Cause/107982202636989",
"likes": 1,
"category": "Cause",
"website": "<<not-applicable>>",
"can_post": true,
"id": "107982202636989",
"name": "Sample Cause",
"picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/276798_107982202636989_4098521_s.jpg",
"link": "https://www.facebook.com/pages/Sample-Cause/107982202636989",
"likes": 1,
"category": "Cause",
"is_published": true,
"can_post": true,
"type": "page"
}
}
2 changes: 1 addition & 1 deletion webapp/plugins/facebook/view/facebook.account.index.tpl
Expand Up @@ -86,7 +86,7 @@
{if $user_pages.$facebook_user_id or $user_admin_pages.$facebook_user_id}
<div class="clearfix article">
<div class="grid_4 right" style="padding-top:.5em;">
{$i->network_username}&nbsp;likes:
{$i->network_username}:
</div>
<form name="addpage" action="index.php?p=facebook">
<div class="grid_8">
Expand Down

0 comments on commit f6e0b19

Please sign in to comment.