$string['error'] = 'An unknown error occurred!';
$string['filename'] = 'Filename';
$string['filesaved'] = 'The file has been saved';
+$string['getfile'] = 'Select this file';
$string['instance'] = 'instance';
$string['invalidrepositoryid'] = 'Invalid repository ID';
$string['invalidplugin'] = 'Invalid repository plug-in';
$string['repository'] = 'Repository';
$string['repositories'] = 'Repositories';
$string['save'] = 'Save';
+$string['saveas'] = 'Save As';
$string['saved'] = 'Saved';
$string['saving'] = 'Saving';
$string['settings'] = 'Settings';
class boxclient {
public $auth_token = '';
- private $_box_api_url = 'http://www.box.net/api/1.0/rest';
+ 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 $_error_code = '';
private $_error_msg = '';
} catch (Exception $e){
}
$ret = array();
- $o = simplexml_load_string($xml);
+ $o = simplexml_load_string(trim($xml));
if($o->status == 'listing_ok') {
$tree = $o->tree->folder;
$this->buildtree($tree, $ret);
* @param string file path in download folder
* @param string file name
* @param int itemid to identify a file in filepool
+ * @param string file area
+ * @param string filepath in file area
* @return array information of file in file pool
*/
-function move_to_filepool($path, $name, $itemid) {
+function move_to_filepool($path, $name, $itemid, $filearea = 'user_draft', $filepath = '/') {
global $DB, $CFG, $USER;
$context = get_context_instance(CONTEXT_USER, $USER->id);
$entry = new object();
- $entry->filearea = 'user_draft';
+ $entry->filearea = $filearea;
$entry->contextid = $context->id;
$entry->filename = $name;
- $entry->filepath = '/';
+ $entry->filepath = $filepath;
$entry->timecreated = time();
$entry->timemodified = time();
if(is_numeric($itemid)) {
$stradd = get_string('add', 'repository');
$strback = get_string('back', 'repository');
$strclose = get_string('close', 'repository');
- $strdownbtn = get_string('download', 'repository');
+ $strdownbtn = get_string('getfile', 'repository');
$strdownload = get_string('downloadsucc', 'repository');
$strdate = get_string('date', 'repository').': ';
$strerror = get_string('error', 'repository');
require_once('lib.php');
// set one hour here
$CFG->repository_cache_expire = 60*60;
-// page
+// page or path
$p = optional_param('p', '', PARAM_INT);
// opened in editor or moodleform
$env = optional_param('env', 'form', PARAM_ALPHA);
// what will happen if user use a fake ctx_id?
// Think about using $SESSION save it
$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT);
+$filearea = optional_param('filearea', 'user_draft', PARAM_RAW);
+$filepath = optional_param('filepath', '/', PARAM_RAW);
$userid = $USER->id;
if(!$repository = repository_instance($repo_id))
$path = $repo->get_file($file, $title);
$itemid = (int)substr(hexdec(uniqid()), 0, 9)+rand(1,100);
try {
- $info = move_to_filepool($path, $title, $itemid);
+ $info = move_to_filepool($path, $title, $itemid, $filearea, $filepath);
if($env == 'form'){
echo json_encode($info['id']);
} elseif($env == 'editor') {