From 2123c698ee9a55df8ab1b354c7e9ebaec5a3c176 Mon Sep 17 00:00:00 2001 From: Gregor Anzelj Date: Fri, 4 Jan 2013 06:37:02 +0100 Subject: [PATCH] Cloud artefact release 2012121202 --- cloud/blocktype/box/lib.php | 35 ++------ cloud/blocktype/dropbox/lib.php | 4 +- cloud/blocktype/googledrive/lib.php | 6 +- cloud/blocktype/skydrive/lib.php | 4 +- cloud/blocktype/sugarsync/lib.php | 40 +++++----- cloud/blocktype/zotero/lib.php | 119 +++++++++------------------- cloud/lib.php | 20 +++++ 7 files changed, 90 insertions(+), 138 deletions(-) diff --git a/cloud/blocktype/box/lib.php b/cloud/blocktype/box/lib.php index 13e1e3f..19d3615 100644 --- a/cloud/blocktype/box/lib.php +++ b/cloud/blocktype/box/lib.php @@ -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¶ms[]=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).'¶ms[]=nozip¶ms[]=onelevel', CURLOPT_PORT => $port, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => $header, CURLOPT_POST => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => 2, @@ -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() @@ -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¶ms[]=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).'¶ms[]=nozip¶ms[]=onelevel', CURLOPT_PORT => $port, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => $header, CURLOPT_POST => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => 2, @@ -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... @@ -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¶ms[]=onelevel¶ms[]=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).'¶ms[]=nozip¶ms[]=onelevel¶ms[]=nofiles', CURLOPT_PORT => $port, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => $header, CURLOPT_POST => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => 2, @@ -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( @@ -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, @@ -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'], @@ -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, @@ -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 { diff --git a/cloud/blocktype/dropbox/lib.php b/cloud/blocktype/dropbox/lib.php index aec947c..f16dc32 100644 --- a/cloud/blocktype/dropbox/lib.php +++ b/cloud/blocktype/dropbox/lib.php @@ -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 { @@ -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')); diff --git a/cloud/blocktype/googledrive/lib.php b/cloud/blocktype/googledrive/lib.php index ad114c5..50575d8 100644 --- a/cloud/blocktype/googledrive/lib.php +++ b/cloud/blocktype/googledrive/lib.php @@ -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) { @@ -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... @@ -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... diff --git a/cloud/blocktype/skydrive/lib.php b/cloud/blocktype/skydrive/lib.php index 5f37eb8..515ad32 100644 --- a/cloud/blocktype/skydrive/lib.php +++ b/cloud/blocktype/skydrive/lib.php @@ -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) { @@ -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... diff --git a/cloud/blocktype/sugarsync/lib.php b/cloud/blocktype/sugarsync/lib.php index aaa9124..d8f9c67 100644 --- a/cloud/blocktype/sugarsync/lib.php +++ b/cloud/blocktype/sugarsync/lib.php @@ -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/', ); } @@ -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.'); } @@ -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, @@ -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.'); } @@ -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(); @@ -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() @@ -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) { @@ -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(); @@ -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... @@ -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(); @@ -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'], @@ -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(); @@ -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'], @@ -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')); diff --git a/cloud/blocktype/zotero/lib.php b/cloud/blocktype/zotero/lib.php index d75855b..76948a3 100644 --- a/cloud/blocktype/zotero/lib.php +++ b/cloud/blocktype/zotero/lib.php @@ -56,12 +56,12 @@ public static function render_instance(BlockInstance $instance, $editing=false) // $connection = $data[1] which will actually hold the ID of collection $data = explode('-', $configdata['artefacts'][0]); $collection = $data[1]; - $bibstyle = $configdata['bibstyle']; + $bibstyle = $configdata['bibstyle']; } // User selected to display all items in the library... else { $collection = '0'; - $bibstyle = 'iso690-author-date-en'; + $bibstyle = 'iso690-author-date-en'; } $result = self::get_filelist($collection, $bibstyle); @@ -218,8 +218,8 @@ public function cloud_info() { return array( 'ssl' => true, 'version' => '', - // Don't forget to add trailing slash character '/' - // to both URLs below, when you set version! + // Don't forget to add trailing slash character '/' + // to both URLs below, when you set version! 'baseurl' => 'https://api.zotero.org', 'wwwurl' => 'https://www.zotero.org', ); @@ -247,7 +247,7 @@ public function service_list() { $usertoken = self::user_tokens($USER->get('id')); if (!empty($consumer['key']) && !empty($consumer['secret'])) { if (isset($usertoken['oauth_token']) && !empty($usertoken['oauth_token'])) { - // Check if the oauth_token has been revoked or not... + // Check if the oauth_token has been revoked or not... $url = $cloud['baseurl'].$cloud['version'].'/users/'.$usertoken['userID'].'/keys/'.$usertoken['oauth_token']; $method = 'GET'; $port = $cloud['ssl'] ? '443' : '80'; @@ -276,22 +276,22 @@ public function service_list() { ); $result = mahara_http_request($config); if ($result->info['http_code'] == 200 && !empty($result->data)) { - // oauth_token hasn't been revoked yet, so... + // oauth_token hasn't been revoked yet, so... return array( 'service_name' => 'zotero', 'service_url' => 'http://www.zotero.com', 'service_auth' => true, //'revoke_access' => false, ); - } else { - // oauth_token has been revoked, so... + } else { + // oauth_token has been revoked, so... return array( 'service_name' => 'zotero', 'service_url' => 'http://www.zotero.com', 'service_auth' => false, //'revoke_access' => false, ); - } + } } else { return array( 'service_name' => 'zotero', @@ -345,7 +345,7 @@ public function request_token() { $prefs = oauth_parse_str($body); ArtefactTypeCloud::set_user_preferences('zotero', $USER->get('id'), $prefs); redirect($cloud['wwwurl'].$cloud['version'].'/oauth/authorize?'.rfc3986_decode($body).'&oauth_callback='.$consumer['callback']); - } else { + } else { $SESSION->add_error_msg(get_string('requesttokennotreturned', 'blocktype.cloud/zotero')); } } else { @@ -354,7 +354,7 @@ public function request_token() { } public function access_token($usertoken) { - global $USER, $SESSION; + global $USER; $cloud = self::cloud_info(); $consumer = self::consumer_tokens(); if (!empty($consumer['key']) && !empty($consumer['secret'])) { @@ -366,8 +366,8 @@ public function access_token($usertoken) { 'oauth_nonce' => mt_rand(), 'oauth_timestamp' => time(), 'oauth_consumer_key' => $consumer['key'], - 'oauth_token' => $usertoken['oauth_token'], - 'oauth_verifier' => $usertoken['oauth_verifier'], + 'oauth_token' => $usertoken['oauth_token'], + 'oauth_verifier' => $usertoken['oauth_verifier'], 'oauth_signature_method' => 'HMAC-SHA1', ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); @@ -393,7 +393,7 @@ public function access_token($usertoken) { $body = substr($result->data, $result->info['header_size']); $prefs = oauth_parse_str($body); ArtefactTypeCloud::set_user_preferences('zotero', $USER->get('id'), $prefs); - } + } } else { throw new ConfigException('Can\'t find Zotero consumer key and/or consumer secret.'); } @@ -430,14 +430,9 @@ public function account_info() { 'oauth_signature_method' => 'HMAC-SHA1', ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); - $header = array(); - $header[] = build_oauth_header($params, "Zotero 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, @@ -446,8 +441,7 @@ public function account_info() { ); $result = mahara_http_request($config); if ($result->info['http_code'] == 200 && !empty($result->data)) { - $body = substr($result->data, $result->info['header_size']); - $data = json_decode($body); + $data = json_decode($result->data); return array( 'service_name' => 'zotero', 'service_auth' => true, @@ -457,7 +451,7 @@ public function account_info() { 'space_amount' => null, 'space_ratio' => null, ); - } else { + } else { return array( 'service_name' => 'zotero', 'service_auth' => false, @@ -467,7 +461,7 @@ public function account_info() { 'space_amount' => null, 'space_ratio' => null, ); - } + } } else { throw new ConfigException('Can\'t find Zotero consumer key and/or consumer secret.'); } @@ -483,7 +477,7 @@ public function account_info() { * get_filelist basically corresponds to get_formatted_list_of_references_in_collection! */ public function get_filelist($folder_id='0', $style='apa') { - global $USER, $SESSION; + global $USER; $cloud = self::cloud_info(); $consumer = self::consumer_tokens(); $usertoken = self::user_tokens($USER->get('id')); @@ -507,20 +501,15 @@ public function get_filelist($folder_id='0', $style='apa') { 'oauth_consumer_key' => $consumer['key'], 'oauth_token' => $usertoken['oauth_token'], 'oauth_signature_method' => 'HMAC-SHA1', - // Method specific prameters... - 'key' => $usertoken['oauth_token'], + // Method specific prameters... + 'key' => $usertoken['oauth_token'], 'format' => 'bib', 'style' => $style ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); - $header = array(); - $header[] = build_oauth_header($params, "Zotero 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, @@ -529,9 +518,8 @@ public function get_filelist($folder_id='0', $style='apa') { ); $result = mahara_http_request($config); if ($result->info['http_code'] == 200 && !empty($result->data)) { - $body = substr($result->data, $result->info['header_size']); - return $body; - } + return $result->data; + } } else { throw new ConfigException('Can\'t find Zotero consumer key and/or consumer secret.'); } @@ -636,20 +624,15 @@ public function get_folder_content($folder_id='0', $options, $block=0, $fullpath 'oauth_consumer_key' => $consumer['key'], 'oauth_token' => $usertoken['oauth_token'], 'oauth_signature_method' => 'HMAC-SHA1', - // Method specific prameters... - 'key' => $usertoken['oauth_token'], + // Method specific prameters... + 'key' => $usertoken['oauth_token'], 'format' => 'atom', 'content' => 'json' ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); - $header = array(); - $header[] = build_oauth_header($params, "Zotero 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, @@ -658,8 +641,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)) { - $body = substr($result->data, $result->info['header_size']); - $xml = simplexml_load_string($body); + $xml = simplexml_load_string($result->data); //Use that namespace $namespaces = $xml->getNameSpaces(true); //Now we don't have the URL hard-coded @@ -725,8 +707,8 @@ public function get_folder_content($folder_id='0', $options, $block=0, $fullpath /* * SEE: http://www.zotero.org/support/dev/server_api/read_api * get_folder_info basically corresponds to get_collection_info! - * - * NOTE: Working, but not actually used yet! + * + * NOTE: Working, but not actually used yet! */ public function get_folder_info($folder_id='0') { global $USER, $SESSION; @@ -749,20 +731,15 @@ public function get_folder_info($folder_id='0') { 'oauth_consumer_key' => $consumer['key'], 'oauth_token' => $usertoken['oauth_token'], 'oauth_signature_method' => 'HMAC-SHA1', - // Method specific prameters... - 'key' => $usertoken['oauth_token'], + // Method specific prameters... + 'key' => $usertoken['oauth_token'], 'format' => 'atom', 'content' => 'json' ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); - $header = array(); - $header[] = build_oauth_header($params, "Zotero 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, @@ -772,8 +749,7 @@ public function get_folder_info($folder_id='0') { $result = mahara_http_request($config); if (!empty($result) && strlen($folder_id) > 0) { if ($result->info['http_code'] == 200 && !empty($result->data)) { - $body = substr($result->data, $result->info['header_size']); - $xml = simplexml_load_string($body); + $xml = simplexml_load_string($result->data); $content = json_decode($xml->content); $collectionTitle = $content->name; } else { @@ -794,20 +770,15 @@ public function get_folder_info($folder_id='0') { 'oauth_consumer_key' => $consumer['key'], 'oauth_token' => $usertoken['oauth_token'], 'oauth_signature_method' => 'HMAC-SHA1', - // Method specific prameters... - 'key' => $usertoken['oauth_token'], + // Method specific prameters... + 'key' => $usertoken['oauth_token'], 'format' => 'atom', 'content' => 'json' ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); - $header = array(); - $header[] = build_oauth_header($params, "Zotero 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, @@ -817,8 +788,7 @@ public function get_folder_info($folder_id='0') { $result = mahara_http_request($config); if (!empty($result) && strlen($folder_id) > 0) { if ($result->info['http_code'] == 200 && !empty($result->data)) { - $body = substr($result->data, $result->info['header_size']); - $xml = simplexml_load_string($body); + $xml = simplexml_load_string($result->data); //Use that namespace $namespaces = $xml->getNameSpaces(true); //Now we don't have the URL hard-coded @@ -871,21 +841,14 @@ public function get_folder_info($folder_id='0') { /* * SEE: http://www.zotero.org/support/dev/server_api/read_api * get_file_info basically corresponds to get_item_info! - * - * NOTE: Working, but not actually used yet! + * + * NOTE: Working, but not actually used yet! */ public function get_file_info($file_id='0') { global $USER, $SESSION; $cloud = self::cloud_info(); $consumer = self::consumer_tokens(); $usertoken = self::user_tokens($USER->get('id')); - /* - $params = array( - 'key' => $usertoken['oauth_token'], - 'format' => 'atom', - 'content' => 'json' - ); - */ if (!empty($consumer['key']) && !empty($consumer['secret'])) { $url = $cloud['baseurl'].$cloud['version'].'/users/'.$usertoken['userID'].'/items/'.$file_id; $method = 'GET'; @@ -897,20 +860,15 @@ public function get_file_info($file_id='0') { 'oauth_consumer_key' => $consumer['key'], 'oauth_token' => $usertoken['oauth_token'], 'oauth_signature_method' => 'HMAC-SHA1', - // Method specific prameters... - 'key' => $usertoken['oauth_token'], + // Method specific prameters... + 'key' => $usertoken['oauth_token'], 'format' => 'atom', 'content' => 'json' ); $params['oauth_signature'] = oauth_compute_hmac_sig($method, $url, $params, $consumer['secret'], $usertoken['oauth_token_secret']); - $header = array(); - $header[] = build_oauth_header($params, "Zotero 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, @@ -920,8 +878,7 @@ public function get_file_info($file_id='0') { $result = mahara_http_request($config); if (!empty($result) && strlen($file_id) > 0) { if ($result->info['http_code'] == 200 && !empty($result->data)) { - $body = substr($result->data, $result->info['header_size']); - $xml = simplexml_load_string($body); + $xml = simplexml_load_string($result->data); $content = json_decode($xml->content); $creatorsList = array(); diff --git a/cloud/lib.php b/cloud/lib.php index 1d386d4..1aefac6 100644 --- a/cloud/lib.php +++ b/cloud/lib.php @@ -259,6 +259,26 @@ function bytes_to_size1024($bytes, $precision=2) { return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision).''.$unit[$i]; } +/** + * Converts seconds into human readable format (HH:MM:SS), + * even if there are more than 24 hours... + * @param integer $seconds + * @return string time formated as HH:MM:SS + * @link http://bytes.com/topic/php/answers/3917-seconds-converted-hh-mm-ss + */ +function seconds_to_hms($seconds) { +if ($seconds < 0) return '00:00:00'; +$minutes = (int)($seconds / 60); +$seconds = $seconds % 60; +$hours = (int)($minutes / 60); +$minutes = $minutes % 60; +$time = array( + str_pad($hours, 2, "0", STR_PAD_LEFT), + str_pad($minutes, 2, "0", STR_PAD_LEFT), + str_pad($seconds, 2, "0", STR_PAD_LEFT), +); +return implode(':', $time); +} /** * Returns folder tree as options for web form select element