Skip to content

Commit

Permalink
Cloud artefact release 2012121202
Browse files Browse the repository at this point in the history
  • Loading branch information
anzeljg committed Jan 4, 2013
1 parent 6007154 commit 2123c69
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 138 deletions.
35 changes: 5 additions & 30 deletions cloud/blocktype/box/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,17 +559,12 @@ public function get_filelist($folder_id=0, $selected=array()) {
'auth_token' => $usertoken['auth_token'],
'folder_id' => $folder_id,
);
$header = array();
$header[] = build_oauth_header($params, "Box API PHP Client");
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$config = array(
// Add parameters at the end: e.g.: params[]=nozip&params[]=onelevel
// Don't add them to $params array or the oauth_http_build_query function will urlencode [ and ] - We don't want that!
// Parameter 'nozip' is absolutely crucial! Without it, the response is base64-like encoded, but base64_decode won't work!
CURLOPT_URL => $url.'?'.oauth_http_build_query($params).'&params[]=nozip&params[]=onelevel',
CURLOPT_PORT => $port,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => 2,
Expand All @@ -578,7 +573,7 @@ public function get_filelist($folder_id=0, $selected=array()) {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml($result->data);
$output = array(
'folders' => array(),
'files' => array()
Expand Down Expand Up @@ -735,17 +730,12 @@ public function get_folder_content($folder_id=0, $options, $block=0, $fullpath='
'auth_token' => $usertoken['auth_token'],
'folder_id' => $folder_id,
);
$header = array();
$header[] = build_oauth_header($params, "Box API PHP Client");
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$config = array(
// Add parameters at the end: e.g.: params[]=nozip&params[]=onelevel
// Don't add them to $params array or the oauth_http_build_query function will urlencode [ and ] - We don't want that!
// Parameter 'nozip' is absolutely crucial! Without it, the response is base64-like encoded, but base64_decode won't work!
CURLOPT_URL => $url.'?'.oauth_http_build_query($params).'&params[]=nozip&params[]=onelevel',
CURLOPT_PORT => $port,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => 2,
Expand All @@ -754,7 +744,7 @@ public function get_folder_content($folder_id=0, $options, $block=0, $fullpath='
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml($result->data);
$output = array();
$count = 0;
// Add 'parent' row entry to jQuery Datatable...
Expand Down Expand Up @@ -863,17 +853,12 @@ public function get_folder_info($folder_id=0) {
'auth_token' => $usertoken['auth_token'],
'folder_id' => $folder_id,
);
$header = array();
$header[] = build_oauth_header($params, "Box API PHP Client");
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$config = array(
// Add parameters at the end: e.g.: params[]=nozip&params[]=onelevel&params[]=nofiles
// Don't add them to $params array or the oauth_http_build_query function will urlencode [ and ] - We don't want that!
// Parameter 'nozip' is absolutely crucial! Without it, the response is base64-like encoded, but base64_decode won't work!
CURLOPT_URL => $url.'?'.oauth_http_build_query($params).'&params[]=nozip&params[]=onelevel&params[]=nofiles',
CURLOPT_PORT => $port,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => 2,
Expand All @@ -882,7 +867,7 @@ public function get_folder_info($folder_id=0) {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml($result->data);
if (isset($data['status']) && $data['status'] == 'listing_ok') {
if (isset($data['tree']['folder']['@attributes']) && isset($data['tree']['folder']['@attributes']['id'])) {
$info = array(
Expand Down Expand Up @@ -933,14 +918,9 @@ public function get_file_info($file_id=0) {
'auth_token' => $usertoken['auth_token'],
'file_id' => $file_id,
);
$header = array();
$header[] = build_oauth_header($params, "Box API PHP Client");
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$config = array(
CURLOPT_URL => $url.'?'.oauth_http_build_query($params),
CURLOPT_PORT => $port,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => 2,
Expand All @@ -949,7 +929,7 @@ public function get_file_info($file_id=0) {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml($result->data);
if (isset($data['status']) && $data['status'] == 's_get_file_info') {
$info = array(
'id' => $data['info']['file_id'],
Expand Down Expand Up @@ -1015,14 +995,9 @@ public function embed_file($file_id=0, $options=array()) {
'auth_token' => $usertoken['auth_token'],
'file_id' => $file_id,
);
$header = array();
$header[] = build_oauth_header($params, "Box API PHP Client");
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$config = array(
CURLOPT_URL => $url.'?'.oauth_http_build_query($params),
CURLOPT_PORT => $port,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => 2,
Expand All @@ -1031,7 +1006,7 @@ public function embed_file($file_id=0, $options=array()) {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml($result->data);
if (isset($data['status']) && $data['status'] == 's_create_file_embed') {
$html = $data['file_embed_html'];
} else {
Expand Down
4 changes: 2 additions & 2 deletions cloud/blocktype/dropbox/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function request_token() {
// Store request_token (oauth_token) and request_token_secret (outh_token_secret)
// We'll need it later...
$body = substr($result->data, $result->info['header_size']);
$prefs = oauth_parse_str($body);
$prefs = oauth_parse_str($body);
ArtefactTypeCloud::set_user_preferences('dropbox', $USER->get('id'), $prefs);
redirect($cloud['wwwurl'].$cloud['version'].'/oauth/authorize?'.rfc3986_decode($body).'&oauth_callback='.$consumer['callback']);
} else {
Expand Down Expand Up @@ -818,7 +818,7 @@ public function embed_file($file_id='/', $options=array()) {
* SEE: https://www.dropbox.com/developers/reference/api#shares
*/
public function public_url($file_id='/') {
global $USER, $THEME;
global $USER;
$cloud = self::cloud_info();
$consumer = self::consumer_tokens();
$usertoken = self::user_tokens($USER->get('id'));
Expand Down
6 changes: 3 additions & 3 deletions cloud/blocktype/googledrive/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public function get_filelist($folder_id='root', $selected=array()) {
*
*/
public function get_folder_content($folder_id='root', $options, $block=0, $fullpath='root|@') {
global $USER, $THEME, $_SESSION;
global $USER, $THEME;

// Get selected artefacts (folders and/or files)
if ($block > 0) {
Expand Down Expand Up @@ -933,7 +933,7 @@ public function get_file_info($file_id='root') {
* SEE: https://developers.google.com/drive/v2/reference/files
*/
public function download_file($file_id=0) {
global $USER, $SESSION;
global $USER;
$cloud = self::cloud_info();
$consumer = self::consumer_tokens();
// Check if access token is still valid...
Expand Down Expand Up @@ -983,7 +983,7 @@ public function download_file($file_id=0) {
* SEE: https://developers.google.com/drive/v2/reference/files
*/
public function export_file($export_url) {
global $USER, $SESSION;
global $USER;
$cloud = self::cloud_info();
$consumer = self::consumer_tokens();
// Check if access token is still valid...
Expand Down
4 changes: 2 additions & 2 deletions cloud/blocktype/skydrive/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public function get_filelist($folder_id='0', $selected=array()) {
*
*/
public function get_folder_content($folder_id=0, $options, $block=0, $fullpath='0|@') {
global $USER, $THEME, $_SESSION;
global $USER, $THEME;

// Get selected artefacts (folders and/or files)
if ($block > 0) {
Expand Down Expand Up @@ -850,7 +850,7 @@ public function get_file_info($file_id=0) {
* SEE: http://msdn.microsoft.com/en-us/library/live/hh826531.aspx#downloading_files
*/
public function download_file($file_id=0) {
global $USER, $SESSION;
global $USER;
$cloud = self::cloud_info();
$consumer = self::consumer_tokens();
// Check if access token is still valid...
Expand Down
40 changes: 20 additions & 20 deletions cloud/blocktype/sugarsync/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function cloud_info() {
'ssl' => true,
'version' => '',
'baseurl' => 'https://api.sugarsync.com/',
'authurl' => 'https://api.sugarsync.com/authorization/',
'authurl' => 'https://api.sugarsync.com/authorization/',
'appauthurl' => 'https://api.sugarsync.com/app-authorization/',
);
}
Expand Down Expand Up @@ -294,16 +294,16 @@ public function access_token($refresh_token) {
$result = mahara_http_request($config);
if ($result->info['http_code'] == 201 /* HTTP/1.1 201 Created */ && !empty($result->data)) {
// Get user ID...
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data['userid'] = basename($data['user']); // Extract user ID part from the URL
// Get access token...
// Get access token...
$matches = array();
preg_match('#authorization\/([A-Za-z0-9\-\_\.]+)#', $result->data, $matches);
$data['access_token'] = $matches[1];
return $data;
} else {
$SESSION->add_error_msg(get_string('accesstokennotreturned', 'blocktype.cloud/sugarsync'));
}
}
} else {
throw new ConfigException('Can\'t find SugarSync consumer key and/or consumer secret.');
}
Expand Down Expand Up @@ -350,7 +350,7 @@ public function account_info() {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
return array(
'service_name' => 'sugarsync',
'service_auth' => true,
Expand All @@ -372,7 +372,7 @@ public function account_info() {
'space_amount' => null,
'space_ratio' => null,
);
}
}
} else {
throw new ConfigException('Can\'t find SugarSync consumer key and/or consumer secret.');
}
Expand All @@ -399,9 +399,9 @@ public function get_filelist($folder_id=0, $selected=array()) {
if (!empty($consumer['key']) && !empty($consumer['secret'])) {
if (strlen($folder_id) > 1) {
$url = $cloud['baseurl'].'folder/'.$folder_id.'/contents';
} else {
$url = $accesstoken['user'].'/folders/contents';
}
} else {
$url = $accesstoken['user'].'/folders/contents';
}
$method = 'GET';
$port = $cloud['ssl'] ? '443' : '80';
$header = array();
Expand All @@ -423,7 +423,7 @@ public function get_filelist($folder_id=0, $selected=array()) {
$result = mahara_http_request($config);
if (!empty($result)) {
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$output = array(
'folders' => array(),
'files' => array()
Expand Down Expand Up @@ -492,7 +492,7 @@ public function get_filelist($folder_id=0, $selected=array()) {
*
*/
public function get_folder_content($folder_id=0, $options, $block=0, $fullpath='0|@') {
global $USER, $THEME, $_SESSION;
global $USER, $THEME;

// Get selected artefacts (folders and/or files)
if ($block > 0) {
Expand Down Expand Up @@ -558,9 +558,9 @@ public function get_folder_content($folder_id=0, $options, $block=0, $fullpath='
if (!empty($consumer['key']) && !empty($consumer['secret'])) {
if (strlen($folder_id) > 1) {
$url = $cloud['baseurl'].'folder/'.$folder_id.'/contents';
} else {
$url = $accesstoken['user'].'/folders/contents';
}
} else {
$url = $accesstoken['user'].'/folders/contents';
}
$method = 'GET';
$port = $cloud['ssl'] ? '443' : '80';
$header = array();
Expand All @@ -582,7 +582,7 @@ public function get_folder_content($folder_id=0, $options, $block=0, $fullpath='
$result = mahara_http_request($config);
if (!empty($result)) {
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$output = array();
$count = 0;
// Add 'parent' row entry to jQuery Datatable...
Expand Down Expand Up @@ -652,7 +652,7 @@ public function get_folder_info($folder_id=0) {
$usertoken = self::user_tokens($USER->get('id'));
$accesstoken = self::access_token($usertoken['refresh_token']);
if (!empty($consumer['key']) && !empty($consumer['secret'])) {
$url = $cloud['baseurl'].'folder/'.$folder_id;
$url = $cloud['baseurl'].'folder/'.$folder_id;
$method = 'GET';
$port = $cloud['ssl'] ? '443' : '80';
$header = array();
Expand All @@ -673,7 +673,7 @@ public function get_folder_info($folder_id=0) {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$info = array(
'id' => str_replace('/', ':', $data['dsid']),
'name' => $data['displayName'],
Expand Down Expand Up @@ -701,7 +701,7 @@ public function get_file_info($file_id=0) {
$usertoken = self::user_tokens($USER->get('id'));
$accesstoken = self::access_token($usertoken['refresh_token']);
if (!empty($consumer['key']) && !empty($consumer['secret'])) {
$url = $cloud['baseurl'].'file/'.$file_id;
$url = $cloud['baseurl'].'file/'.$file_id;
$method = 'GET';
$port = $cloud['ssl'] ? '443' : '80';
$header = array();
Expand All @@ -722,7 +722,7 @@ public function get_file_info($file_id=0) {
);
$result = mahara_http_request($config);
if ($result->info['http_code'] == 200 && !empty($result->data)) {
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$data = oauth_parse_xml(substr($result->data, $result->info['header_size']));
$info = array(
'id' => str_replace('/', ':', $data['dsid']),
'name' => $data['displayName'],
Expand All @@ -749,7 +749,7 @@ public function get_file_info($file_id=0) {
* SEE: http://www.sugarsync.com/dev/download-file-example.html
*/
public function download_file($file_id=0) {
global $USER, $SESSION;
global $USER;
$cloud = self::cloud_info();
$consumer = self::consumer_tokens();
$usertoken = self::user_tokens($USER->get('id'));
Expand Down
Loading

0 comments on commit 2123c69

Please sign in to comment.