Skip to content
Browse files

MDL-32990 - Repositories - Updating Box.net API calls to use HTTPS

  • Loading branch information...
1 parent 9841098 commit 0646f76fb6e3ed033efc7b48e317ea5e0eeb1b37 @jsnfwlr jsnfwlr committed with nebgor
Showing with 14 additions and 10 deletions.
  1. +11 −7 lib/boxlib.php
  2. +3 −3 repository/boxnet/lib.php
View
18 lib/boxlib.php
@@ -36,8 +36,10 @@ class boxclient {
/** @var string */
public $auth_token = '';
/** @var string */
- private $_box_api_url = 'http://box.net/api/1.0/rest';
- private $_box_api_upload_url = 'http://upload.box.net/api/1.0/upload';
+ private $_box_api_url = 'https://www.box.com/api/1.0/rest';
+ private $_box_api_upload_url = 'http://upload.box.com/api/1.0/upload';
+ private $_box_api_download_url = 'http://www.box.com/api/1.0/download';
+ private $_box_api_auth_url = 'http://www.box.com/api/1.0/auth';
private $_error_code = '';
private $_error_msg = '';
/** @var bool */
@@ -67,6 +69,7 @@ public function __construct($api_key, $auth_token = '', $debug = false) {
function makeRequest($method, $params = array()) {
$this->_clearErrors();
$c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
+ $c->setopt(array('CURLOPT_FOLLOWLOCATION'=>1));
try {
if ($method == 'upload'){
$request = $this->_box_api_upload_url.'/'.
@@ -141,7 +144,7 @@ function getAuthToken($ticket, $username, $password) {
'__login'=>1
);
try {
- $ret = $c->post('http://www.box.net/api/1.0/auth/'.$ticket, $param);
+ $ret = $c->post($this->_box_api_auth_url.$ticket, $param);
} catch (moodle_exception $e) {
$this->setError(0, 'connection time-out or invalid url');
return false;
@@ -174,6 +177,7 @@ function getfiletree($path, $params = array()) {
$params['onelevel'] = 1;
$params['params[]'] = 'nozip';
$c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
+ $c->setopt(array('CURLOPT_FOLLOWLOCATION'=>1));
try {
$args = array();
$xml = $c->get($this->_box_api_url, $params);
@@ -201,7 +205,7 @@ function buildtree($sax, &$tree){
foreach($o->folder as $z){
$tmp = array('title'=>(string)$z->attributes()->name,
'size'=>0, 'date'=>userdate(time()),
- 'thumbnail'=>'http://www.box.net/img/small_folder_icon.gif',
+ 'thumbnail'=>'https://www.box.com/img/small_folder_icon.gif',
'path'=>array('name'=>(string)$z->attributes()->name, 'path'=>(int)$z->attributes()->id));
$tmp['children'] = array();
$this->buildtree($z, $tmp['children']);
@@ -212,13 +216,13 @@ function buildtree($sax, &$tree){
foreach($val as $file){
$thumbnail = (string)$file->attributes()->thumbnail;
if (!preg_match('#^(?:http://)?([^/]+)#i', $thumbnail)) {
- $thumbnail = 'http://www.box.net'.$thumbnail;
+ $thumbnail = 'http://www.box.com'.$thumbnail;
}
$tmp = array('title'=>(string)$file->attributes()->file_name,
'size'=>display_size((int)$file->attributes()->size),
'thumbnail'=>$thumbnail,
'date'=>userdate((int)$file->attributes()->updated),
- 'source'=>'http://box.net/api/1.0/download/'
+ 'source'=> $this->_box_api_download_url
.$this->auth_token.'/'.(string)$file->attributes()->id,
'url'=>(string)$file->attributes()->shared_link);
$tree[] = $tmp;
@@ -267,7 +271,7 @@ function getAccountTree($params = array()) {
if (preg_match('#^(?:http://)?([^/]+)#i', $a['attributes']['THUMBNAIL'])) {
@$ret_array['thumbnail'][$i] = $a['attributes']['THUMBNAIL'];
} else {
- @$ret_array['thumbnail'][$i] = 'http://www.box.net'.$a['attributes']['THUMBNAIL'];
+ @$ret_array['thumbnail'][$i] = 'http://www.box.com'.$a['attributes']['THUMBNAIL'];
}
$entry_count++;
}
View
6 repository/boxnet/lib.php
@@ -130,7 +130,7 @@ public function search($search_text) {
$list[] = array('title'=>$v,
'size'=>$filesizes[$n],
'date'=>$filedates[$n],
- 'source'=>'http://box.net/api/1.0/download/'
+ 'source'=>'https://www.box.com/api/1.0/download/'
.$this->auth_token.'/'.$fileids[$n],
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($v, 32))->out(false));
}
@@ -151,7 +151,7 @@ public function get_listing($path = '/', $page = ''){
$ret = array();
$ret['list'] = array();
$tree = $this->boxclient->getfiletree($path);
- $ret['manage'] = 'http://www.box.net/files';
+ $ret['manage'] = 'http://www.box.com/files';
$ret['path'] = array(array('name'=>'Root', 'path'=>0));
if(!empty($tree)) {
$ret['list'] = array_filter($tree, array($this, 'filter'));
@@ -169,7 +169,7 @@ public function print_login(){
if ($this->options['ajax']) {
$popup_btn = new stdClass();
$popup_btn->type = 'popup';
- $popup_btn->url = ' https://www.box.net/api/1.0/auth/' . $t['ticket'];
+ $popup_btn->url = ' https://www.box.com/api/1.0/auth/' . $t['ticket'];
$ret = array();
$ret['login'] = array($popup_btn);

0 comments on commit 0646f76

Please sign in to comment.
Something went wrong with that request. Please try again.