Skip to content

Commit

Permalink
added ability to connect account, and do social post :)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnvk committed Aug 13, 2012
1 parent 6bcd335 commit cc4a2f7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 82 deletions.
14 changes: 8 additions & 6 deletions config/install.php
Expand Up @@ -10,17 +10,19 @@
*/

/* Settings */
$config['appnet_settings']['widgets'] = 'TRUE';
$config['appnet_settings']['enabled'] = 'TRUE';
$config['appnet_settings']['widgets'] = 'TRUE';
$config['appnet_settings']['enabled'] = 'TRUE';
$config['appnet_settings']['create_permission'] = '3';
$config['appnet_settings']['publish_permission'] = '2';
$config['appnet_settings']['manage_permission'] = '2';
$config['appnet_settings']['manage_permission'] = '2';
$config['appnet_settings']['client_id'] = '';
$config['appnet_settings']['client_secret'] = '';
$config['appnet_settings']['client_secret'] = '';
$config['appnet_settings']['social_login'] = 'TRUE';
$config['appnet_settings']['login_redirect'] = 'home/';
$config['appnet_settings']['social_connection'] = 'TRUE';
$config['appnet_settings']['login_redirect'] = 'home/';
$config['appnet_settings']['social_connection'] = 'TRUE';
$config['appnet_settings']['connections_redirect'] = 'settings/connections/';
$config['appnet_settings']['social_post'] = 'TRUE';

/* Sites */
$config['appnet_sites'][] = array(
'url' => 'http://alpha.app.net/',
Expand Down
103 changes: 33 additions & 70 deletions controllers/api.php
Expand Up @@ -40,82 +40,45 @@ function install_get()
$this->response($message, 200);
}

function view_get()
{
$this->load->model('data_model');
function social_post_authd_post()
{
if ($connection = $this->social_auth->check_connection_user($this->oauth_user_id, 'appnet', 'primary'))
{
// Load Library
$req = 'https://alpha-api.app.net/stream/0/posts';

$data = $this->data_model->get_data($this->get('id'));

if($data)
{
$message = array('status' => 'success', 'message' => 'Activity has been found', 'data' => $data);
}
else
{
$message = array('status' => 'error', 'message' => 'Could not find any Data');
}
// Post Update
$params = array(
'text' => $this->input->post('content'),
'reply_to' => '',
'annotations' => '',
'links' => ''
);

$ch = curl_init($req);
curl_setopt($ch, CURLOPT_POST, true);
$access_token = $connection->auth_one;

curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: Bearer '.$access_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$this->response($message, 200);
}
$qs = http_build_query($params);

function create_authd_post()
{
$this->load->model('data_model');
curl_setopt($ch, CURLOPT_POSTFIELDS, $qs);
$response = curl_exec($ch);

curl_close($ch);
$response = json_decode($response, true);

$data = array(
'user_id' => $this->oauth_user_id,
'text' => $this->input->post('text')
);

// Add Data
if ($add_data = $this->data_model->add_data($data))
$message = array('status' => 'success', 'message' => 'Posted to App.net successfully', 'data' => $response);
}
else
{
$message = array('status' => 'success', 'message' => 'Data successfully created', 'data' => $add_data);
}
else
{
$message = array('status' => 'error', 'message' => 'Oops unable to add data');
}
$message = array('status' => 'error', 'message' => 'Oops, could not post to App.net');
}

$this->response($message, 200);
}

function update_authd_get()
{
$this->load->model('data_model');

$udpate_data = array(
'text' => $this->input->post('text')
);

$update = $this->social_tools->update_data($this->get('id'), $update_data);

if($update)
{
$message = array('status' => 'success', 'message' => 'Data was update');
}
else
{
$message = array('status' => 'error', 'message' => 'Could not update data');
}

$this->response($message, 200);
}

function destroy_authd_get()
{
$this->load->model('data_model');

if ($this->data_model->delete_data($this->get('id')))
{
$message = array('status' => 'success', 'message' => 'Data was deleted');
}
else
{
$message = array('status' => 'error', 'message' => 'Oops Data was not deleted');
}

$this->response($message, 200);
}
$this->response($message, 200);
}

}
2 changes: 1 addition & 1 deletion controllers/connections.php
Expand Up @@ -29,7 +29,7 @@ function add()
$provider = $this->oauth2->provider('appnet', array(
'id' => config_item('appnet_client_id'),
'secret' => config_item('appnet_client_secret'),
'scope' => 'stream','email','write_post','follow','messages','export'
'scope' => 'stream, email, write_post, follow, messages, export'
));

if (!isset($_GET['code']))
Expand Down
8 changes: 3 additions & 5 deletions libraries/oauth2_provider.php
Expand Up @@ -5,14 +5,14 @@ class OAuth2_Provider_Appnet extends OAuth2_Provider {
/**
* @array scope items for App.net
*/
protected $scope = array('stream','email','write_post','follow','messages','export');
//protected $scope = array('stream','email','write_post','follow','messages','export');

public $name = 'appnet';

/**
* @var string scope separator, most use "," but some like Google are spaces
*/
public $scope_seperator = '+';
public $scope_seperator = ',';

/**
* @var string the method to use when requesting tokens
Expand All @@ -30,9 +30,7 @@ public function url_access_token()
}

public function get_user_info(OAuth2_Token_Access $token)
{
//https://alpha-api.app.net/stream/0/users/[user_id]

{
$url = 'https://alpha-api.app.net/stream/0/users/me?'.http_build_query(array(
'access_token' => $token->access_token,
));
Expand Down
29 changes: 29 additions & 0 deletions views/settings/index.php
Expand Up @@ -28,6 +28,35 @@
<p><input type="text" name="client_id" value="<?= $settings['appnet']['client_id'] ?>"> Client ID </p>
<p><input type="text" name="client_secret" value="<?= $settings['appnet']['client_secret'] ?>"> Client Secret</p>

</div>


<span class="item_separator"></span>

<div class="content_wrap_inner">

<h3>Social</h3>

<p>Login
<?= form_dropdown('social_login', config_item('yes_or_no'), $settings['appnet']['social_login']) ?>
</p>

<p>Login Redirect<br>
<?= base_url() ?> <input type="text" size="30" name="login_redirect" value="<?= $settings['appnet']['login_redirect'] ?>" />
</p>

<p>Connections
<?= form_dropdown('social_connection', config_item('yes_or_no'), $settings['appnet']['social_connection']) ?>
</p>

<p>Connections Redirect<br>
<?= base_url() ?> <input type="text" size="30" name="connections_redirect" value="<?= $settings['appnet']['connections_redirect'] ?>" />
</p>

<p>Post
<?= form_dropdown('social_post', config_item('yes_or_no'), $settings['appnet']['social_post']) ?>
</p>

<input type="hidden" name="module" value="<?= $this_module ?>">

<p><input type="submit" name="save" value="Save" /></p>
Expand Down

0 comments on commit cc4a2f7

Please sign in to comment.