mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-15349
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
This commit is contained in:
parent
23634bc72a
commit
1e28c767bc
@ -182,20 +182,20 @@ function openpicker(){
|
||||
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);
|
||||
}
|
||||
@ -205,12 +205,15 @@ function openpicker(){
|
||||
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;
|
||||
}
|
||||
@ -304,6 +307,17 @@ success: function(o) {
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* repository_box class
|
||||
* repository_boxnet class
|
||||
* This is a subclass of repository class
|
||||
*
|
||||
* @author Dongsheng Cai
|
||||
@ -53,10 +53,14 @@ class repository_boxnet extends repository{
|
||||
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);
|
||||
}
|
||||
|
@ -51,9 +51,7 @@ class curl {
|
||||
$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')) {
|
||||
@ -266,6 +264,7 @@ class curl {
|
||||
* ));
|
||||
*/
|
||||
public function download($requests, $options = array()) {
|
||||
$options['CURLOPT_BINARYTRANSFER'] = 1;
|
||||
$options['RETURNTRANSFER'] = false;
|
||||
return $this->mulit_request($requests, $options);
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
* 4. Clean up session code
|
||||
*
|
||||
*/
|
||||
require_once('../config.php');
|
||||
|
||||
class phpFlickr {
|
||||
var $api_key;
|
||||
@ -199,13 +198,12 @@ class phpFlickr {
|
||||
$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 {
|
||||
|
@ -29,7 +29,9 @@ class repository_flickr extends repository{
|
||||
}
|
||||
|
||||
if(!empty($SESSION->flickrmail)) {
|
||||
$action = 'list';
|
||||
if(empty($action)) {
|
||||
$action = 'list';
|
||||
}
|
||||
} else {
|
||||
$options['flickrmail'] = optional_param('flickrmail', '', PARAM_RAW);
|
||||
if(!empty($options['flickrmail'])) {
|
||||
@ -40,12 +42,16 @@ class repository_flickr extends repository{
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,7 +105,7 @@ EOD;
|
||||
$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;
|
||||
}
|
||||
@ -139,5 +145,36 @@ EOD;
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -104,20 +104,23 @@ abstract class repository {
|
||||
* @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;
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
<?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');
|
||||
@ -35,6 +38,15 @@ if($action == 'list') {
|
||||
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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user