Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #21

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ Installation is very straight forward:

## Changelog

### 0.11.2
* Filter users by name in list view

### 0.11.1
* Changing name of user

### 0.11
* Using batch request in list page
* Update of facebook.php library
* Adding name when creating test user
* Name of app added in page header

### 0.10.3
* Removing deprecated permission 'physical_login'

Expand Down Expand Up @@ -50,3 +62,7 @@ Installation is very straight forward:
**Rafael Dohms** is a PHP Evangelist in Brazil and a very active member of the PHP Community. He helped found two PHP User Groups over the years and currently shares the lead of PHPSP. Developer, gamer and lover of code he also hosts Brazil’s first PHP Podcast: PHPSPCast.

Currently he works for MIH SWAT Team, a group of experts that provides technical knowledge to the MIH group as well as working on R&D in search of the new and exciting niches of the web. His role as a Senior PHP Developer is to code, train and aid other companies and to have fun doing so.

## About Author of Improvements

**Pawel 'lord_t' Maruszczyk** is a social integration ninja from the Upper Silesia (Poland). He works for Can't Stop Games as JavaScript/PHP programmer.
35 changes: 29 additions & 6 deletions library/App/Action/AjaxAddFriendAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@ public function run()
$uid_friend = $data_friend[0];
$token_friend = $data_friend[1];

//Request 1 in name or origin user
$fb->setAccessToken($token_user);
$resA = $fb->api('/'.$uid_user.'/friends/'.$uid_friend, "POST");
$batch = array();

//Request 2 in name or target user
$fb->setAccessToken($token_friend);
$resB = $fb->api('/'.$uid_friend.'/friends/'.$uid_user, "POST");
$batch[] = '{ "method": "POST", "relative_url": "/'.$uid_user.'/friends/'.$uid_friend.'?access_token='.$token_user.'"}';
$batch[] = '{ "method": "POST", "relative_url": "/'.$uid_friend.'/friends/'.$uid_user.'?access_token='.$token_friend.'"}';

$batched_request = '['.\implode(',', $batch).']';

//set POST variables
$url = "https://graph.facebook.com/?batch="
. \urlencode(\trim($batched_request))
. "&access_token=".$fb->getAppId().'|'.$fb->getApiSecret()."&method=post";

$ch = \curl_init();
\curl_setopt($ch, CURLOPT_URL, $url);
\curl_setopt($ch, CURLOPT_POST, 1);
\curl_setopt($ch, CURLOPT_POSTFIELDS, $batched_request);
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = \curl_exec($ch);
\curl_close($ch);

$batcheddata = \json_decode($result, true);
if (!empty($batcheddata)) {

foreach ($batcheddata as $result) {
$resultDecoded = \json_decode($result['body'], true);
}

} else {
throw new \Exception($result);
}

} catch(\Exception $e) {
$this->redirectToError($e, true);
Expand Down
27 changes: 27 additions & 0 deletions library/App/Action/AjaxAppNameAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Action;

class AjaxAppNameAction extends Base
{

public function run()
{

try{

$fb = $this->getFacebookClient();
$appdata = $fb->api('/'.$fb->getAppId().'?access_token='.$fb->getAccessToken());

} catch (\Exception $e) {
$this->redirectToError($e, true);
return;
}

$response = new \App\JsonResponse(200, null, $appdata);
$response->sendOutput();
}

}

?>
34 changes: 34 additions & 0 deletions library/App/Action/AjaxChangeNameAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Action;

class AjaxChangeNameAction extends Base
{

public function run()
{

try {

$fb = $this->getFacebookClient();
$uid = $this->getInspekt()->post->getRaw('uid');

$params = array();
$params['name'] = $this->getInspekt()->post->getRaw('name');

$changeName = $fb->api('/'.$uid, 'POST', $params);

} catch (\Exception $e) {

$this->redirectToError('Facebook exception: '.$e);
return;

}

$response = new \App\JsonResponse(200, null, null);
$response->sendOutput();

}

}

4 changes: 2 additions & 2 deletions library/App/Action/AjaxUserinfoAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function run()
{

try{

//Get list of users
$fb = $this->getFacebookClient();

Expand All @@ -30,7 +30,7 @@ public function run()
} else {
$details['perms'] = 'none defined';
}

$details['uid'] = $uid;
$details['access_token'] = $token;

Expand Down
99 changes: 99 additions & 0 deletions library/App/Action/AjaxUserinfoBatchAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace App\Action;

class AjaxUserinfoBatchAction extends Base
{

public function run()
{

try{

//Get list of users
$fb = $this->getFacebookClient();

//Get Input Params
$package = $this->getInspekt()->post->getRaw('package');
$tokens = array();
$batch = array();

foreach ($package as $p) {

$tokens[ $p['id'] ] = $p['access_token'];

$batch[] = '{ "method": "GET", "relative_url": "'.$p['id'].'?access_token='.$p['access_token'].'"}';
$batch[] = '{ "method": "POST", "relative_url": "method/fql.query?query=select+'.$fb->getFacebookPermissionList().'+from+permissions+where+uid='.$p['id'].'"}';

}

$batched_request = '['.\implode(',', $batch).']';

//set POST variables
$url = "https://graph.facebook.com/?batch="
. \urlencode(\trim($batched_request))
. "&access_token=".$fb->getAppId().'|'.$fb->getApiSecret()."&method=post";

$ch = \curl_init();
\curl_setopt($ch, CURLOPT_URL, $url);
\curl_setopt($ch, CURLOPT_POST, 1);
\curl_setopt($ch, CURLOPT_POSTFIELDS, $batched_request);
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = \curl_exec($ch);
\curl_close($ch);

$batcheddata = \json_decode($result, true);

$detailsArray = array();
$tmp;
if (!empty($batcheddata)) {

foreach ($batcheddata as $result) {

$resultDecoded = \json_decode($result['body'], true);

//user data
if ( isset($resultDecoded['id']) ) {

$tmp = $resultDecoded;

}
//user perms
else {

$tmp['uid'] = $tmp['id'];
$tmp['access_token'] = $tokens[ $tmp['id'] ];

$allPerms = $resultDecoded[0];
//error_log(var_export($allPerms,true));
if (\is_array($allPerms) && count($allPerms) > 0) {
$perms = implode(', ', \array_keys(\array_filter($allPerms)));
$tmp['perms'] = ($perms == '')? 'none defined':$perms;
} else {
$tmp['perms'] = 'none defined';
}

$detailsArray[] = $tmp;

}

}

} else {
throw new \Exception($result);
}

} catch (\Exception $e) {

$this->redirectToError($e, true);
return;

}

$response = new \App\JsonResponse(200, null, $detailsArray);
$response->sendOutput();
}

}

?>
12 changes: 10 additions & 2 deletions library/App/Action/CreateAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@

class CreateAction extends Base
{

public function run()
{
try {

$fb = $this->getFacebookClient();

$params = array();
$params['name'] = $this->getInspekt()->post->getRaw('name');
$params['installed'] = $this->getInspekt()->post->getInt('installed');
$params['permissions'] = $this->getInspekt()->post->getRaw('permissions');

if (empty($params['name'])) {
unset($params['name']);
}

$user = $fb->api('/'.$fb->getAppId().'/accounts/test-users', 'POST', $params);

if (is_array($user)){
Expand All @@ -23,7 +29,9 @@ public function run()

$user = \array_merge($user,$details);
$success = true;

}

} catch (\Exception $e) {
$this->redirectToError($e);
return;
Expand All @@ -33,7 +41,7 @@ public function run()
$tpl->display(array('error' => !isset($success), 'user' => $user));

}

}

?>
15 changes: 12 additions & 3 deletions library/App/Action/ListAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ListAction extends Base
{

public function run()
{
if (!$this->checkTokens()){
Expand All @@ -15,19 +15,28 @@ public function run()
//Get list of users
$fb = $this->getFacebookClient();
$fb->setAccessToken(null);

$response = $fb->api('/'.$fb->getAppId().'/accounts/test-users');
$testUsers = (\array_key_exists('data', $response))? $response['data']:array();


} catch (\Exception $e) {
$this->redirectToError($e);
return;
}

//Get Template for adding new user
$tplNewuser = $this->getTplEngine()->loadTemplate('new.html');

//Render Template
$tpl = $this->getTplEngine()->loadTemplate('list.html');
$tpl->display(array('users' => $testUsers));
$tpl->display(array(
'users' => $testUsers,
'newuser' => $tplNewuser
));

}

}

?>
8 changes: 4 additions & 4 deletions library/App/Action/NewAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

class NewAction extends Base
{

public function run()
{
{
//Render Template
$tpl = $this->getTplEngine()->loadTemplate('new.html');
$tpl->display(array());
$tpl->display(array('parent' => 'layout.html'));
}

}

?>
Loading