Skip to content

Commit

Permalink
Adding features to remove user and create relationships, some UI twea…
Browse files Browse the repository at this point in the history
…ks and JS/CSS changes and action chaining
  • Loading branch information
rdohms committed Jan 17, 2011
1 parent a279db6 commit f6e0936
Show file tree
Hide file tree
Showing 23 changed files with 7,585 additions and 54 deletions.
44 changes: 44 additions & 0 deletions library/App/Action/AddfriendAction.php
@@ -0,0 +1,44 @@
<?php

namespace App\Action;

class AddfriendAction extends Base
{

public function run()
{

$fb = $this->getFacebookClient();

try{
//Get Ids and tokens
$uid_user = $this->getInspekt()->post->getInt('origin_user');
$token_user = $this->getInspekt()->post->getRaw('origin_user_token');

//Break down target info
$data_friend = $this->getInspekt()->post->getRaw('target_user');
$data_friend = \explode(" ", $data_friend);
$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);

//Request 2 in name or target user
$fb->setAccessToken($token_friend);
$resB = $fb->api('/'.$uid_friend.'/friends/'.$uid_user);

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

//Render Template
$tpl = $this->getTplEngine()->loadTemplate('add_friend.html');
$tpl->display(array());
}

}

?>
10 changes: 10 additions & 0 deletions library/App/Action/Base.php
Expand Up @@ -27,6 +27,16 @@ public function getInspekt()
{
return \Zend_Registry::get('input');
}

public function redirectToError($e)
{

$error = new ErrorAction();
$error->setError($e);
$error->run();


}
}

?>
31 changes: 23 additions & 8 deletions library/App/Action/CreateAction.php
Expand Up @@ -6,16 +6,31 @@ class CreateAction extends Base
{

public function run()
{
$fb = $this->getFacebookClient();
{
try {
$fb = $this->getFacebookClient();

$params = array();
$params['installed'] = $this->getInspekt()->post->getInt('installed');
$params['permissions'] = $this->getInspekt()->post->getRaw('permissions');
var_dump($fb->getAppId());
$user = $fb->api('/'.$fb->getAppId().'/accounts/test-users', 'POST', $params);
$params = array();
$params['installed'] = $this->getInspekt()->post->getInt('installed');
$params['permissions'] = $this->getInspekt()->post->getRaw('permissions');

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

if (is_array($user)){

$fb->setAccessToken($user['access_token']);
$details = $fb->api('/me');

$user = \array_merge($user,$details);
$success = true;
}
} catch (\Exception $e) {
$this->redirectToError($e);
return;
}

$tpl = $this->getTplEngine()->loadTemplate('create.html');
$tpl->display(array('error' => !isset($success), 'user' => $user));

}

Expand Down
36 changes: 36 additions & 0 deletions library/App/Action/DeleteAction.php
@@ -0,0 +1,36 @@
<?php

namespace App\Action;

class DeleteAction extends Base
{

public function run()
{
try {
$fb = $this->getFacebookClient();

//Get Posted Data
$uid = $this->getInspekt()->post->getInt('del_user');
$token = $this->getInspekt()->post->getRaw('del_user_token');

//API call
$fb->setAccessToken($token);
$res = $fb->api('/'.$uid, 'DELETE');

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

//Render List action
$list = new ListAction();
$list->run();

return;

}

}

?>
5 changes: 1 addition & 4 deletions library/App/Action/ErrorAction.php
Expand Up @@ -8,12 +8,9 @@ class ErrorAction extends Base

public function run()
{
$error = new \stdClass();
$error->message = $this->error->getMessage();
var_dump($error);
//Render Template
$tpl = $this->getTplEngine()->loadTemplate('error.html');
$tpl->display(array('error' => (array) $error));
$tpl->display(array('error' => $this->error));
}

public function setError($e)
Expand Down
44 changes: 25 additions & 19 deletions library/App/Action/ListAction.php
Expand Up @@ -7,25 +7,31 @@ class ListAction extends Base

public function run()
{
//Get list of users
$fb = $this->getFacebookClient();
$response = $fb->api('/'.$fb->getAppId().'/accounts/test-users');
$testUsers = (\array_key_exists('data', $response))? $response['data']:array();

//Get extra data
$users = array();
foreach($testUsers as $user){
$fb->setAccessToken($user['access_token']);
$details = $fb->api('/me');

//Get Available perms
$allPerms = $fb->fql('SELECT '.$fb->getFacebookPermissionList().' FROM permissions WHERE uid = "'.$user['id'].'"');
$user['perms'] = \array_filter(array_shift($allPerms));


//Add to user list with full data
$users[] = \array_merge($user, $details);

try{
//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();

//Get extra data
$users = array();
foreach($testUsers as $user){
$fb->setAccessToken($user['access_token']);
$details = $fb->api('/me');

//Get Available perms
$allPerms = $fb->fql('SELECT '.$fb->getFacebookPermissionList().' FROM permissions WHERE uid = "'.$user['id'].'"');
$user['perms'] = \array_filter(array_shift($allPerms));


//Add to user list with full data
$users[] = \array_merge($user, $details);

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

//Render Template
Expand Down
66 changes: 66 additions & 0 deletions public/css/form.css
@@ -0,0 +1,66 @@

fieldset{
border:solid 1px #DEDEDE;
padding: 10px;
}
fieldset legend {
font-weight:bold; padding: 0 10px; margin-left: 10px;
}

fieldset ul, fieldset li{
border:0; margin:0; padding:0; list-style:none;
}

fieldset li{
clear:both;
list-style:none;
padding:10px;
}

fieldset input[type=text]{
float:left;
width: 250px;
}

fieldset input[type=file]{
float:left;
width: 250px;
}

fieldset select{
float:left;
width: 250px;
}

fieldset textarea{
float:left;
width: 250px;
}

fieldset label{
width:140px;
float:left;
}

fieldset button{
border:0; margin:0; padding:0;
clear:both;
width:125px;
height:31px;
background:#666666 url(img/button.png) no-repeat;
text-align:center;
line-height:31px;
color:#FFFFFF;
font-size:11px;
font-weight:bold;
}

fieldset .note {
float: right;
color: #C3C3C3;
font-size: 10px;
}

fieldset .instructions {
padding: 10px;
}
32 changes: 31 additions & 1 deletion public/css/site.css
Expand Up @@ -29,14 +29,40 @@ div#menu a:hover { color: #FFF;}


h1 { font-size: 24px; font-weight: bold; margin: 8px 0 10px 0; }
a { color: #3F4959; text-decoration: none; }

.hidden { display: none;}

.modal {
display: none;

/* standard decorations */
width:400px;
border:10px solid #666;

/* for modern browsers use semi-transparent color on the border. nice! */
border:10px solid rgba(82, 82, 82, 0.698);

/* hot CSS3 features for mozilla and webkit-based browsers (rounded borders) */
-moz-border-radius:10px;
-webkit-border-radius:10px;
}

.loading {
width: 125px;
background-color: #FFF;
padding: 20px;
}

.loading img { margin:0 auto; }

.about {}
.about p { padding:10px 0;}
.about ul { }
.about ul li { padding:3px 0; }
.about strong {font-weight: bold;}

.form_div { background-color:#FFF; padding: 10px; }

.user_list ul {}
.user_list ul li { margin: 10px 10px; float:left; width:48%;}
Expand All @@ -49,5 +75,9 @@ h1 { font-size: 24px; font-weight: bold; margin: 8px 0 10px 0; }
.user_list .perm_list {}
.user_list .perm_list li { margin: 0; padding: 0 5px; float:left; width: 15%;}

.xdebug-var-dump{ background-color: #FFF; padding: 10px; }

.xdebug-var-dump{ background-color: #FFF; padding: 10px; }
.centered { margin:0px auto; }
.warning { width: 50%; padding:10px; margin-top: 10px; margin-bottom: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; border: 1px solid #000; }
.warning img { padding-right: 10px; vertical-align: middle; }
.warning p { height: 48px; font-size: 14px; vertical-align: middle;}
Binary file added public/images/error-48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/help.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/loading.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ok-48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/user_add.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions public/js/cmds.js
@@ -0,0 +1,47 @@
function addFriend(origin_id, access_token)
{

$('#origin_user').val(origin_id);
$('#origin_user_token').val(access_token);
$('#add_friend').overlay({

mask: {
color: '#000',
loadSpeed: 200,
opacity: 0.7
},
closeOnClick: false,
load: true
});

}

function deleteUser(uid, access_token)
{
openLoading();
$('#del_user').val(uid);
$('#del_user_token').val(access_token);
$('#delete_user_form').submit();

}

function openLoading()
{

$("#loading").overlay({

mask: {
color: '#000',
loadSpeed: 200,
opacity: 0.7
},
closeOnClick: false,
load: true
});

}

function closeLoading()
{
$("#loading").close();
}

0 comments on commit f6e0936

Please sign in to comment.