mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-13766
1. Clean up source code 2. use search api replace old get_listing api
This commit is contained in:
parent
bddcd93318
commit
353d5cf39b
@ -10,45 +10,31 @@
|
||||
|
||||
require_once($CFG->libdir.'/boxlib.php');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class repository_boxnet extends repository {
|
||||
private $box;
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @param <type> $repositoryid
|
||||
* @param <type> $context
|
||||
* @param <type> $options
|
||||
*/
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()) {
|
||||
global $SESSION;
|
||||
|
||||
$options['username'] = optional_param('boxusername', '', PARAM_RAW);
|
||||
$options['password'] = optional_param('boxpassword', '', PARAM_RAW);
|
||||
$options['ticket'] = optional_param('ticket', '', PARAM_RAW);
|
||||
$reset = optional_param('reset', 0, PARAM_INT);
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
$this->api_key = $this->get_option('api_key');
|
||||
if (empty($this->api_key)) {
|
||||
}
|
||||
$sess_name = 'box_token'.$this->id;
|
||||
$this->sess_name = 'box_token'.$this->id;
|
||||
// do login
|
||||
if (!empty($options['username']) && !empty($options['password']) && !empty($options['ticket']) ) {
|
||||
if(!empty($options['username']) && !empty($options['password']) && !empty($options['ticket']) ) {
|
||||
$this->box = new boxclient($this->api_key);
|
||||
try {
|
||||
$SESSION->$sess_name = $this->box->getAuthToken($options['ticket'],
|
||||
$options['username'], $options['password']);
|
||||
$options['username'], $options['password']);
|
||||
} catch (repository_exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
// already logged
|
||||
if (!empty($SESSION->$sess_name)) {
|
||||
if (empty($this->box)) {
|
||||
if(!empty($SESSION->$sess_name)) {
|
||||
if(empty($this->box)) {
|
||||
$this->box = new boxclient($this->api_key, $SESSION->$sess_name);
|
||||
}
|
||||
$this->auth_token = $SESSION->$sess_name;
|
||||
@ -57,34 +43,17 @@ class repository_boxnet extends repository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @return <type>
|
||||
*/
|
||||
public function check_login() {
|
||||
global $SESSION;
|
||||
|
||||
return !empty($SESSION->{$this->sess_name});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @return <type>
|
||||
*/
|
||||
public function logout() {
|
||||
global $SESSION;
|
||||
|
||||
unset($SESSION->{$this->sess_name});
|
||||
return $this->print_login();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $options
|
||||
* @return <type>
|
||||
*/
|
||||
public function set_option($options = array()) {
|
||||
if (!empty($options['api_key'])) {
|
||||
set_config('api_key', trim($options['api_key']), 'boxnet');
|
||||
@ -94,13 +63,8 @@ class repository_boxnet extends repository {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $config
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_option($config = '') {
|
||||
if ($config==='api_key') {
|
||||
if($config==='api_key') {
|
||||
return trim(get_config('boxnet', 'api_key'));
|
||||
} else {
|
||||
$options['api_key'] = trim(get_config('boxnet', 'api_key'));
|
||||
@ -109,29 +73,17 @@ class repository_boxnet extends repository {
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @return <type>
|
||||
*/
|
||||
public function global_search() {
|
||||
global $SESSION;
|
||||
$sess_name = 'box_token'.$this->id;
|
||||
if (empty($SESSION->$sess_name)) {
|
||||
if (empty($SESSION->{$this->sess_name})) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $DB
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_login() {
|
||||
global $DB;
|
||||
|
||||
if ($entry = $DB->get_record('repository_instances', array('id'=>$this->id))) {
|
||||
$ret->username = $entry->username;
|
||||
$ret->password = $entry->password;
|
||||
@ -141,61 +93,46 @@ class repository_boxnet extends repository {
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $CFG
|
||||
* @global <type> $SESSION
|
||||
* @param <type> $path
|
||||
* @param <type> $search
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_listing($path = '/', $search = '') {
|
||||
global $CFG, $SESSION;
|
||||
|
||||
public function search($search_text) {
|
||||
global $CFG;
|
||||
$list = array();
|
||||
$ret = array();
|
||||
if (!empty($search)) {
|
||||
$tree = $this->box->getAccountTree();
|
||||
if (!empty($tree)) {
|
||||
$filenames = $tree['file_name'];
|
||||
$fileids = $tree['file_id'];
|
||||
$filesizes = $tree['file_size'];
|
||||
$filedates = $tree['file_date'];
|
||||
$fileicon = $tree['thumbnail'];
|
||||
foreach ($filenames as $n=>$v) {
|
||||
if (strstr($v, $search) !== false) {
|
||||
$list[] = array('title'=>$v,
|
||||
'size'=>$filesizes[$n],
|
||||
'date'=>$filedates[$n],
|
||||
'source'=>'http://box.net/api/1.0/download/'
|
||||
.$this->options['auth_token'].'/'.$fileids[$n],
|
||||
'thumbnail'=>$CFG->pixpath.'/f/'.mimeinfo('icon', $v));
|
||||
}
|
||||
$tree = $this->box->getAccountTree();
|
||||
if (!empty($tree)) {
|
||||
$filenames = $tree['file_name'];
|
||||
$fileids = $tree['file_id'];
|
||||
$filesizes = $tree['file_size'];
|
||||
$filedates = $tree['file_date'];
|
||||
$fileicon = $tree['thumbnail'];
|
||||
foreach ($filenames as $n=>$v){
|
||||
if(strstr($v, $search_text) !== false) {
|
||||
$list[] = array('title'=>$v,
|
||||
'size'=>$filesizes[$n],
|
||||
'date'=>$filedates[$n],
|
||||
'source'=>'http://box.net/api/1.0/download/'
|
||||
.$this->options['auth_token'].'/'.$fileids[$n],
|
||||
'thumbnail'=>$CFG->pixpath.'/f/'.mimeinfo('icon', $v));
|
||||
}
|
||||
}
|
||||
$ret['list'] = $list;
|
||||
return $ret;
|
||||
}
|
||||
$ret['list'] = $list;
|
||||
return $ret;
|
||||
}
|
||||
public function get_listing($path = '/'){
|
||||
global $CFG;
|
||||
$list = array();
|
||||
$ret = array();
|
||||
$ret['list'] = array();
|
||||
$tree = $this->box->getfiletree($path);
|
||||
if (!empty($tree)) {
|
||||
$ret['manage'] = 'http://www.box.net/files';
|
||||
$ret['path'] = array(array('name'=>'Root', 'path'=>0));
|
||||
if(!empty($tree)) {
|
||||
$ret['list'] = $tree;
|
||||
$ret['manage'] = 'http://www.box.net/files';
|
||||
$ret['path'] = array(array('name'=>'Root', 'path'=>0));
|
||||
$this->listing = $tree;
|
||||
return $ret;
|
||||
} else {
|
||||
$sess_name = 'box_token'.$this->id;
|
||||
unset($SESSION->$sess_name);
|
||||
throw new repository_exception('nullfilelist', 'repository_boxnet');
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_login() {
|
||||
public function print_login(){
|
||||
$t = $this->box->getTicket();
|
||||
$ret = $this->get_login();
|
||||
if ($this->options['ajax']) {
|
||||
@ -220,58 +157,26 @@ class repository_boxnet extends repository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_search() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_admin_config() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_instance_config() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_multiple_instances() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_admin_option_names() {
|
||||
return array('api_key');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_instance_option_names() {
|
||||
return array('share_url');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $
|
||||
*/
|
||||
public function admin_config_form(&$mform) {
|
||||
$public_account = get_config('boxnet', 'public_account');
|
||||
$api_key = get_config('boxnet', 'api_key');
|
||||
@ -283,10 +188,6 @@ class repository_boxnet extends repository {
|
||||
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $
|
||||
*/
|
||||
public function instance_config_form(&$mform) {
|
||||
//$share_url = get_config('boxnet', 'share_url');
|
||||
$mform->addElement('text', 'share_url', get_string('shareurl', 'repository_boxnet'));
|
||||
|
@ -10,24 +10,12 @@
|
||||
|
||||
require_once($CFG->libdir.'/flickrlib.php');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class repository_flickr extends repository {
|
||||
private $flickr;
|
||||
public $photos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @global <type> $CFG
|
||||
* @param <type> $repositoryid
|
||||
* @param <type> $context
|
||||
* @param <type> $options
|
||||
*/
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()) {
|
||||
global $SESSION, $CFG;
|
||||
|
||||
$options['page'] = optional_param('p', 1, PARAM_INT);
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
|
||||
@ -41,32 +29,19 @@ class repository_flickr extends repository {
|
||||
|
||||
$this->flickr = new phpFlickr($this->api_key, $this->secret, $this->token);
|
||||
|
||||
if (empty($this->token)) {
|
||||
$frob = optional_param('frob', '', PARAM_RAW);
|
||||
if (!empty($frob)) {
|
||||
$auth_info = $this->flickr->auth_getToken($frob);
|
||||
$this->token = $auth_info['token'];
|
||||
$this->nsid = $auth_info['user']['nsid'];
|
||||
set_user_preference($this->setting, $auth_info['token']);
|
||||
set_user_preference($this->setting.'_nsid', $auth_info['user']['nsid']);
|
||||
$this->perm = $auth_info['token'];
|
||||
}
|
||||
$frob = optional_param('frob', '', PARAM_RAW);
|
||||
if (empty($this->token) && !empty($frob)) {
|
||||
$auth_info = $this->flickr->auth_getToken($frob);
|
||||
$this->token = $auth_info['token'];
|
||||
$this->nsid = $auth_info['user']['nsid'];
|
||||
set_user_preference($this->setting, $auth_info['token']);
|
||||
set_user_preference($this->setting.'_nsid', $auth_info['user']['nsid']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function check_login() {
|
||||
return !empty($this->token);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function logout() {
|
||||
set_user_preference($this->setting, '');
|
||||
set_user_preference($this->setting.'_nsid', '');
|
||||
@ -74,12 +49,6 @@ class repository_flickr extends repository {
|
||||
$this->nsid = '';
|
||||
return $this->print_login();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $options
|
||||
* @return <type>
|
||||
*/
|
||||
public function set_option($options = array()) {
|
||||
if (!empty($options['api_key'])) {
|
||||
set_config('api_key', trim($options['api_key']), 'flickr');
|
||||
@ -93,11 +62,6 @@ class repository_flickr extends repository {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $config
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_option($config = '') {
|
||||
if ($config==='api_key') {
|
||||
return trim(get_config('flickr', 'api_key'));
|
||||
@ -111,31 +75,15 @@ class repository_flickr extends repository {
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @return <type>
|
||||
*/
|
||||
public function global_search() {
|
||||
global $SESSION;
|
||||
|
||||
if (empty($this->token)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @param <type> $ajax
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_login($ajax = true) {
|
||||
global $SESSION;
|
||||
|
||||
if($ajax){
|
||||
if ($ajax) {
|
||||
$ret = array();
|
||||
$popup_btn = new stdclass;
|
||||
$popup_btn->type = 'popup';
|
||||
@ -144,48 +92,20 @@ class repository_flickr extends repository {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $SESSION
|
||||
* @param <type> $path
|
||||
* @param <type> $search
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_listing($path = '1', $search = '') {
|
||||
global $SESSION;
|
||||
|
||||
$nsid = get_user_preferences($this->setting.'_nsid');
|
||||
$photos_url = $this->flickr->urls_getUserPhotos($nsid);
|
||||
|
||||
if (!empty($search)) {
|
||||
$photos = $this->flickr->photos_search(array(
|
||||
'user_id'=>$nsid,
|
||||
'per_page'=>25,
|
||||
'page'=>$path,
|
||||
'extras'=>'original_format',
|
||||
'text'=>$search
|
||||
));
|
||||
} elseif (!empty($path) && empty($search)) {
|
||||
$photos = $this->flickr->photos_search(array(
|
||||
'user_id'=>$nsid,
|
||||
'per_page'=>25,
|
||||
'page'=>$path,
|
||||
'extras'=>'original_format'
|
||||
));
|
||||
}
|
||||
private function build_list($photos, $path = 1) {
|
||||
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
|
||||
$ret = array();
|
||||
$ret['manage'] = $photos_url;
|
||||
$ret['list'] = array();
|
||||
$ret['pages'] = $photos['pages'];
|
||||
if (is_int($path) && $path <= $ret['pages']) {
|
||||
if(is_int($path) && $path <= $ret['pages']) {
|
||||
$ret['page'] = $path;
|
||||
} else {
|
||||
$ret['page'] = 1;
|
||||
}
|
||||
if (!empty($photos['photo'])) {
|
||||
foreach ($photos['photo'] as $p) {
|
||||
if (empty($p['title'])) {
|
||||
if(empty($p['title'])) {
|
||||
$p['title'] = get_string('notitle', 'repository_flickr');
|
||||
}
|
||||
if (isset($p['originalformat'])) {
|
||||
@ -193,52 +113,45 @@ class repository_flickr extends repository {
|
||||
} else {
|
||||
$format = 'jpg';
|
||||
}
|
||||
$ret['list'][] =
|
||||
array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
|
||||
$ret['list'][] = array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],
|
||||
'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'),
|
||||
'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
|
||||
}
|
||||
}
|
||||
if (empty($ret)) {
|
||||
throw new repository_exception('nullphotolist', 'repository_flickr');
|
||||
} else {
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
public function search($search_text) {
|
||||
$photos = $this->flickr->photos_search(array(
|
||||
'user_id'=>$this->nsid,
|
||||
'per_page'=>25,
|
||||
'extras'=>'original_format',
|
||||
'text'=>$search_text
|
||||
));
|
||||
return $this->build_list($photos);
|
||||
}
|
||||
public function get_listing($path = '1') {
|
||||
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
$photos = $this->flickr->photos_search(array(
|
||||
'user_id'=>$this->nsid,
|
||||
'per_page'=>25,
|
||||
'page'=>$path,
|
||||
'extras'=>'original_format'
|
||||
));
|
||||
return $this->build_list($photos, $path);
|
||||
}
|
||||
public function print_listing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_search() {
|
||||
echo '<input name="s" value="" />';
|
||||
parent::print_search();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $CFG
|
||||
* @param <type> $photo_id
|
||||
* @param <type> $file
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_file($photo_id, $file = '') {
|
||||
global $CFG;
|
||||
|
||||
$result = $this->flickr->photos_getSizes($photo_id);
|
||||
$url = '';
|
||||
if (!empty($result[4])) {
|
||||
if(!empty($result[4])) {
|
||||
$url = $result[4]['source'];
|
||||
} elseif (!empty($result[3])) {
|
||||
} elseif(!empty($result[3])) {
|
||||
$url = $result[3]['source'];
|
||||
} elseif (!empty($result[2])) {
|
||||
} elseif(!empty($result[2])) {
|
||||
$url = $result[2]['source'];
|
||||
}
|
||||
if (!file_exists($CFG->dataroot.'/repository/download')) {
|
||||
@ -248,10 +161,10 @@ class repository_flickr extends repository {
|
||||
$dir = $CFG->dataroot.'/repository/download/';
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
if(empty($file)) {
|
||||
$file = $photo_id.'_'.time().'.jpg';
|
||||
}
|
||||
if (file_exists($dir.$file)) {
|
||||
if(file_exists($dir.$file)) {
|
||||
$file = uniqid('m').$file;
|
||||
}
|
||||
$fp = fopen($dir.$file, 'w');
|
||||
@ -261,56 +174,29 @@ class repository_flickr extends repository {
|
||||
));
|
||||
return $dir.$file;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_admin_config() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_multiple_instances() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_instance_config() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $
|
||||
*/
|
||||
public function instance_config_form(&$mform) {
|
||||
$mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr'));
|
||||
$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_instance_option_names() {
|
||||
return array('email_address');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $CFG
|
||||
* @param <type> $
|
||||
*/
|
||||
public function admin_config_form(&$mform) {
|
||||
global $CFG;
|
||||
|
||||
$api_key = get_config('flickr', 'api_key');
|
||||
$secret = get_config('flickr', 'secret');
|
||||
|
||||
@ -339,10 +225,6 @@ class repository_flickr extends repository {
|
||||
$mform->addRule('secret', $strrequired, 'required', null, 'client');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_admin_option_names() {
|
||||
return array('api_key', 'secret');
|
||||
}
|
||||
|
@ -12,18 +12,10 @@
|
||||
|
||||
require_once($CFG->libdir.'/flickrlib.php');
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class repository_flickr_public extends repository {
|
||||
private $flickr;
|
||||
public $photos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $options
|
||||
* @return <type>
|
||||
*/
|
||||
public function set_option($options = array()) {
|
||||
if (!empty($options['api_key'])) {
|
||||
set_config('api_key', trim($options['api_key']), 'flickr_public');
|
||||
@ -33,11 +25,6 @@ class repository_flickr_public extends repository {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $config
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_option($config = '') {
|
||||
if ($config==='api_key') {
|
||||
return trim(get_config('flickr_public', 'api_key'));
|
||||
@ -48,10 +35,6 @@ class repository_flickr_public extends repository {
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function global_search() {
|
||||
if (empty($this->flickr_account)) {
|
||||
return false;
|
||||
@ -60,23 +43,16 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $CFG
|
||||
* @param <type> $repositoryid
|
||||
* @param <type> $context
|
||||
* @param <type> $options
|
||||
*/
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()) {
|
||||
global $CFG;
|
||||
|
||||
$options['page'] = optional_param('p', 1, PARAM_INT);
|
||||
$options['page'] = optional_param('p', 1, PARAM_INT);
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
$this->api_key = $this->get_option('api_key');
|
||||
$this->flickr = new phpFlickr($this->api_key);
|
||||
|
||||
$this->flickr_account = $this->get_option('email_address');
|
||||
|
||||
// when flickr account hasn't been set by admin, user can
|
||||
// submit a flickr account here.
|
||||
$account = optional_param('flickr_account', '', PARAM_RAW);
|
||||
if (!empty($account)) {
|
||||
$people = $this->flickr->people_findByEmail($account);
|
||||
@ -87,20 +63,9 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function check_login() {
|
||||
return !empty($this->flickr_account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $ajax
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_login($ajax = true) {
|
||||
if ($ajax) {
|
||||
$ret = array();
|
||||
@ -112,130 +77,82 @@ class repository_flickr_public extends repository {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function search() {
|
||||
public function search($search_text) {
|
||||
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
||||
$tag = optional_param('tag', '', PARAM_CLEANHTML);
|
||||
$search = optional_param('s', '', PARAM_CLEANHTML);
|
||||
$this->nsid = $people['nsid'];
|
||||
$tag = optional_param('tag', '', PARAM_CLEANHTML);
|
||||
if (!empty($tag)) {
|
||||
$photos = $this->flickr->photos_search(array(
|
||||
'tags'=>$tag
|
||||
));
|
||||
} else {
|
||||
$photos = $this->flickr->photos_search(array(
|
||||
'user_id'=>$people['nsid'],
|
||||
'text'=>$search));
|
||||
}
|
||||
$ret = array();
|
||||
$ret['list'] = array();
|
||||
$ret['nologin'] = true;
|
||||
$ret['pages'] = $photos['pages'];
|
||||
foreach ($photos['photo'] as $p) {
|
||||
if (empty($p['title'])) {
|
||||
$p['title'] = get_string('notitle', 'repository_flickr_public');
|
||||
}
|
||||
if (isset($p['originalformat'])) {
|
||||
$format = $p['originalformat'];
|
||||
} else {
|
||||
$format = 'jpg';
|
||||
}
|
||||
$ret['list'][] =
|
||||
array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id']);
|
||||
}
|
||||
if (empty($ret)) {
|
||||
throw new repository_exception('nullphotolist', 'repository_flickr_public');
|
||||
} else {
|
||||
return $ret;
|
||||
'user_id'=>$this->nsid,
|
||||
'text'=>$search_text));
|
||||
}
|
||||
return $this->build_list($photos);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $path
|
||||
* @param <type> $search
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_listing($path = '1', $search = '') {
|
||||
public function get_listing($path = '1') {
|
||||
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
||||
$photos_url = $this->flickr->urls_getUserPhotos($people['nsid']);
|
||||
|
||||
$this->nsid = $people['nsid'];
|
||||
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 25, $path);
|
||||
|
||||
return $this->build_list($photos, $path);
|
||||
}
|
||||
private function build_list($photos, $path = 1) {
|
||||
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
|
||||
$ret = array();
|
||||
$ret['manage'] = $photos_url;
|
||||
$ret['list'] = array();
|
||||
$ret['nologin'] = true;
|
||||
$ret['pages'] = $photos['pages'];
|
||||
if (is_int($path) && $path <= $ret['pages']) {
|
||||
$ret['page'] = $path;
|
||||
} else {
|
||||
$ret['page'] = 1;
|
||||
}
|
||||
foreach ($photos['photo'] as $p) {
|
||||
if (empty($p['title'])) {
|
||||
$p['title'] = get_string('notitle', 'repository_flickr_public');
|
||||
if (!empty($photos['photo'])) {
|
||||
foreach ($photos['photo'] as $p) {
|
||||
if(empty($p['title'])) {
|
||||
$p['title'] = get_string('notitle', 'repository_flickr');
|
||||
}
|
||||
if (isset($p['originalformat'])) {
|
||||
$format = $p['originalformat'];
|
||||
} else {
|
||||
$format = 'jpg';
|
||||
}
|
||||
$ret['list'][] = array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],
|
||||
'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'),
|
||||
'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
|
||||
}
|
||||
if (isset($p['originalformat'])) {
|
||||
$format = $p['originalformat'];
|
||||
} else {
|
||||
$format = 'jpg';
|
||||
}
|
||||
$ret['list'][] =
|
||||
array('title'=>$p['title'].'.'.$format,'source'=>$p['id'],'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), 'date'=>'', 'size'=>'unknown', 'url'=>$photos_url.$p['id']);
|
||||
}
|
||||
if (empty($ret)) {
|
||||
throw new repository_exception('nullphotolist', 'repository_flickr_public');
|
||||
} else {
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_listing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function print_search() {
|
||||
parent::print_search();
|
||||
echo '<label>Keyword: </label><input type="text" name="s" /><br />';
|
||||
echo '<label>Tag: </label><input type="text" name="tag" /><br />';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global <type> $CFG
|
||||
* @param <type> $photo_id
|
||||
* @param <type> $file
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_file($photo_id, $file = '') {
|
||||
global $CFG;
|
||||
|
||||
$result = $this->flickr->photos_getSizes($photo_id);
|
||||
$url = '';
|
||||
if (!empty($result[4])) {
|
||||
$url = $result[4]['source'];
|
||||
} elseif (!empty($result[3])) {
|
||||
} elseif(!empty($result[3])) {
|
||||
$url = $result[3]['source'];
|
||||
} elseif (!empty($result[2])) {
|
||||
} 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')) {
|
||||
if(is_dir($CFG->dataroot.'/repository/download')) {
|
||||
$dir = $CFG->dataroot.'/repository/download/';
|
||||
}
|
||||
|
||||
@ -247,57 +164,31 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
$fp = fopen($dir.$file, 'w');
|
||||
$c = new curl;
|
||||
$c->download(array(
|
||||
array('url'=>$url, 'file'=>$fp)
|
||||
));
|
||||
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
||||
|
||||
return $dir.$file;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_admin_config() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_multiple_instances() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function has_instance_config() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $
|
||||
*/
|
||||
public function instance_config_form(&$mform) {
|
||||
$mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr_public'));
|
||||
//$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_instance_option_names() {
|
||||
return array('email_address');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $
|
||||
*/
|
||||
public function admin_config_form(&$mform) {
|
||||
$api_key = get_config('flickr_public', 'api_key');
|
||||
if (empty($api_key)) {
|
||||
@ -308,17 +199,10 @@ class repository_flickr_public extends repository {
|
||||
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_admin_option_names() {
|
||||
return array('api_key');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function type_init() {
|
||||
//here we create a default instances for this type
|
||||
}
|
||||
|
@ -796,6 +796,7 @@ abstract class repository {
|
||||
* 'manage' => (string) link to file manager,
|
||||
* 'nologin' => (bool) requires login,
|
||||
* 'nosearch' => (bool) no search link,
|
||||
* 'search_result' => (bool) this list is a searching result,
|
||||
* 'upload' => array( // upload manager
|
||||
* 'name' => (string) label of the form element,
|
||||
* 'id' => (string) id of the form element
|
||||
@ -827,15 +828,19 @@ abstract class repository {
|
||||
* @param string $search The text will be searched.
|
||||
* @return array the list of files, including meta infomation
|
||||
*/
|
||||
abstract public function get_listing($parent = '/', $search = '');
|
||||
abstract public function get_listing($parent = '/');
|
||||
|
||||
/**
|
||||
* Search
|
||||
* Search files in repository
|
||||
* When doing global search, $search_text will be used as
|
||||
* keyword.
|
||||
*
|
||||
* @return mixed, see get_listing()
|
||||
*/
|
||||
public function search() {
|
||||
$search = optional_param('s', '', PARAM_CLEANHTML);
|
||||
return $this->get_listing(null, $search);
|
||||
public function search($search_text) {
|
||||
$list = array();
|
||||
$list['list'] = array();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -872,6 +877,7 @@ abstract class repository {
|
||||
echo '<input type="hidden" name="repo_id" value="'.$this->id.'" />';
|
||||
echo '<input type="hidden" name="ctx_id" value="'.$this->context->id.'" />';
|
||||
echo '<input type="hidden" name="seekey" value="'.sesskey().'" />';
|
||||
echo '<input name="s" value="" />';
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2011,7 +2017,7 @@ success: function(o) {
|
||||
postmethod: 'async',
|
||||
width : "30em",
|
||||
fixedcenter : true,
|
||||
zindex: 666667,
|
||||
zindex: 766667,
|
||||
visible : false,
|
||||
constraintoviewport : true,
|
||||
buttons : [ { text:"Submit",handler: function() {
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
class repository_local extends repository {
|
||||
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()){
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()) {
|
||||
global $SESSION, $action, $CFG;
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
// TODO:
|
||||
@ -40,6 +40,10 @@ class repository_local extends repository {
|
||||
return array('filearea' => $filearea, 'path' => $path);
|
||||
}
|
||||
|
||||
public function search($search_text) {
|
||||
return $this->get_listing('', $search_text);
|
||||
}
|
||||
|
||||
public function get_listing($encodedpath = '', $search = '') {
|
||||
global $CFG;
|
||||
$ret = array();
|
||||
@ -180,10 +184,6 @@ class repository_local extends repository {
|
||||
// will be used in non-javascript file picker
|
||||
}
|
||||
|
||||
public function print_search() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function has_admin_config() {
|
||||
return false;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); // context ID
|
||||
$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID
|
||||
$callback = optional_param('callback', '', PARAM_CLEANHTML);
|
||||
$search_text = optional_param('s', '', PARAM_CLEANHTML);
|
||||
|
||||
/// Headers to make it not cacheable
|
||||
header("Cache-Control: no-cache, must-revalidate");
|
||||
@ -40,7 +41,7 @@
|
||||
foreach($repos as $repo){
|
||||
if ($repo->global_search()) {
|
||||
try {
|
||||
$ret = $repo->get_listing(null, $search);
|
||||
$ret = $repo->search($search_text);
|
||||
array_walk($ret['list'], 'repository_attach_id', $repo->id); // See function below
|
||||
$tmp = array_merge($list, $ret['list']);
|
||||
$list = $tmp;
|
||||
@ -141,7 +142,7 @@ EOD;
|
||||
break;
|
||||
case 'search':
|
||||
try {
|
||||
echo json_encode($repo->search());
|
||||
echo json_encode($repo->search($search_text));
|
||||
} catch (repository_exception $e) {
|
||||
$err = new stdclass;
|
||||
$err->e = $e->getMessage();
|
||||
|
Loading…
x
Reference in New Issue
Block a user