1. Implement downloading files from repositories to temp area, TODO, communicate with FILE API
2. Fix cookie bugs in curl class
3. Fix bugs of boxnet and flickr plugins
select.on('click', function(e){
var nodes = YAHOO.util.Selector.query('input:checked');
var str = '';
+ var files = [];
for(k in nodes){
- str += (nodes[k].value+'\n');
+ files.push(nodes[k].value);
}
- // TODO
- // Call ws.php to download these files
- alert(str);
+ loading();
+ var trans = YAHOO.util.Connect.asyncRequest('POST', 'ws.php?id='+repositoryid+'&action=download', loadfile, postdata({'files':files}));
})
var search = new YAHOO.util.Element('search');
- search.on('click', function(e){
+ search.on('click', function(e) {
if(repositoryid==0){
alert('Select a repository first.');
return;
}
- var data=window.prompt("What are you searching for?");
+ var data = window.prompt("What are you searching for?");
if(data != null && data != '') {
dosearch(data);
}
function postdata(obj) {
var str = '';
for(k in obj) {
- if(str == ''){
- str += '?';
+ if(obj[k] instanceof Array) {
+ for(i in obj[k]) {
+ str += (encodeURIComponent(k) +'[]='+encodeURIComponent(obj[k][i]));
+ str += '&';
+ }
} else {
+ str += encodeURIComponent(k) +'='+encodeURIComponent(obj[k]);
str += '&';
}
- str += encodeURIComponent(k) +'='+encodeURIComponent(obj[k]);
}
return str;
}
}
}
}
+var loadfile = {
+ success: function(o) {
+ try {
+ var ret = YAHOO.lang.JSON.parse(o.responseText);
+ } catch(e) {
+ alert('Invalid JSON String\n'+o.responseText);
+ }
+ var panel = new YAHOO.util.Element('panel');
+ panel.get('element').innerHTML = '<h1>Download Successfully!</h1>';
+ }
+}
function cr(id, path, reset){
viewbar.set('disabled', false);
<?php
/**
- * repository_box class
+ * repository_boxnet class
* This is a subclass of repository class
*
* @author Dongsheng Cai
if(!empty($SESSION->box_token)) {
$this->box = new boxclient($options['api_key'], $SESSION->box_token);
$options['auth_token'] = $SESSION->box_token;
- $action = 'list';
+ if(!empty($actio)) {
+ $action = 'list';
+ }
} else {
$this->box = new boxclient($options['api_key'], '');
- $action = '';
+ if(!empty($action)) {
+ $action = '';
+ }
}
parent::__construct($repositoryid, $context, $options);
}
$this->debug = true;
}
if(!empty($options['cookie'])) {
- if(file_exists($options['cookie'])) {
- $this->cookie = $options['cookie'];
- }
+ $this->cookie = $options['cookie'];
}
if(!empty($options['cache'])) {
if(class_exists('repository_cache')) {
* ));
*/
public function download($requests, $options = array()) {
+ $options['CURLOPT_BINARYTRANSFER'] = 1;
$options['RETURNTRANSFER'] = false;
return $this->mulit_request($requests, $options);
}
* 4. Clean up session code
*
*/
-require_once('../config.php');
class phpFlickr {
var $api_key;
$redirect = $_SERVER['REQUEST_URI'];
}
//$api_sig = md5($this->secret . "api_key" . $this->api_key . "extra" . $redirect . "perms" . $perms);
- echo $this->secret . "api_key" . $this->api_key . "perms" . $perms;
$api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms);
if ($this->service == "23") {
header("Location: http://www.23hq.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig);
} else {
- //header("Location: http://www.flickr.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig);
- echo '<a href="'."http://www.flickr.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig . '">Login</a>';
+ $url = 'http://www.flickr.com/services/auth/?api_key=' . $this->api_key . "&perms=" . $perms . '&api_sig='. $api_sig;
+ echo '<a href="'.$url.'">Authentication</a>';
}
//exit;
} else {
}
if(!empty($SESSION->flickrmail)) {
- $action = 'list';
+ if(empty($action)) {
+ $action = 'list';
+ }
} else {
$options['flickrmail'] = optional_param('flickrmail', '', PARAM_RAW);
if(!empty($options['flickrmail'])) {
set_user_preference('flickrmail', $options['flickrmail']);
}
$SESSION->flickrmail = $options['flickrmail'];
- $action = 'list';
+ if(empty($action)) {
+ $action = 'list';
+ }
}
} else {
if($account = get_user_preferences('flickrmail', '')){
$SESSION->flickrmail = $account;
- $action = 'list';
+ if(empty($action)) {
+ $action = 'list';
+ }
}
}
}
$p['title'] = get_string('notitle', 'repository_flickr');
}
$ret->list[] =
- array('title'=>$p['title'],'source'=>'http://farm2.static.flickr.com/'.$p['server'].'/'.$p['id'].'_'.$p['secret'].'_b.jpg','id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, "Square"));
+ array('title'=>$p['title'],'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'));
}
return $ret;
}
echo '<input type="text" name="Search" value="search terms..." size="40" class="right"/>';
return true;
}
+ public function get_file($photo_id){
+ global $CFG;
+ $result = $this->flickr->photos_getSizes($photo_id);
+ $url = '';
+ if(!empty($result[4])) {
+ $url = $result[4]['source'];
+ } elseif(!empty($result[3])) {
+ $url = $result[3]['source'];
+ } elseif(!empty($result[2])) {
+ $url = $result[2]['source'];
+ }
+ if (!file_exists($CFG->dataroot.'/repository/download')) {
+ mkdir($CFG->dataroot.'/repository/download/', 0777, true);
+ }
+ if(is_dir($CFG->dataroot.'/repository/download')) {
+ $dir = $CFG->dataroot.'/repository/download/';
+ }
+ if(file_exists($CFG->dirroot.'/repository/curl.class.php')) {
+ $file = $photo_id.'_'.time().'.jpg';
+ $fp = fopen($dir.$file, 'w');
+ require_once($CFG->dirroot.'/repository/curl.class.php');
+ $c = new curl;
+ $c->download(array(
+ array('url'=>$url, 'file'=>$fp)
+ ));
+ return $dir.$file;
+ } else {
+ return '!!!fail!!!';
+ }
+ return $result;
+ }
}
?>
* @param string $url the url of file
* @param string $file save location
*/
- public function get_file($url, $file) {
+ public function get_file($url) {
global $CFG;
+ if (!file_exists($CFG->dataroot.'/repository/download')) {
+ mkdir($CFG->dataroot.'/repository/download/', 0777, true);
+ }
+ if(is_dir($CFG->dataroot.'/repository/download')) {
+ $dir = $CFG->dataroot.'/repository/download/';
+ }
if(file_exists($CFG->dirroot.'/repository/curl.class.php')) {
- if(!file_exists($file)){
- return null;
- } else {
- $file = fopen($file, 'w');
- }
+ $file = uniqid('repo').'_'.time().'.tmp';
+ $fp = fopen($dir.$file, 'w');
require_once($CFG->dirroot.'/repository/curl.class.php');
$c = new curl;
$c->download(array(
- array('url'=>$url, 'file'=>$file)
+ array('url'=>$url, 'file'=>$fp)
));
- return true;
+ return $dir.$file;
} else {
return null;
}
<?php
+set_time_limit(0);
require_once('../config.php');
require_once('lib.php');
$CFG->repository_cache_expire = 12000;
// repository id
-$id = optional_param('id', PARAM_INT);
+$id = optional_param('id', PARAM_INT);
// action of client
-$action = optional_param('action', '', PARAM_RAW);
+$action = optional_param('action', '', PARAM_RAW);
// path
-$p = optional_param('p', '', PARAM_RAW);
+$p = optional_param('p', '', PARAM_RAW);
// Search text
-$search = optional_param('s', '', PARAM_RAW);
+$search = optional_param('s', '', PARAM_RAW);
+// files to be downloaded
+$files = optional_param('files', '', PARAM_RAW);
if(!$repository = $DB->get_record('repository', array('id'=>$id))) {
echo json_encode('wrong');
echo json_encode($repo->get_listing());
}
+} elseif($action == 'download') {
+ $ret = array();
+ foreach($files as $url) {
+ $ret[] = $repo->get_file($url);
+ // TODO
+ // Need to communicate with FILE API
+ // Copy the tmp file to final location
+ }
+ echo json_encode($ret);
} else {
echo json_encode($repo->print_login());
}