2008-09-12 03:32:31 +00:00
|
|
|
<?php
|
2009-12-17 03:40:38 +00:00
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2008-09-12 03:32:31 +00:00
|
|
|
/**
|
|
|
|
* repository_flickr_public class
|
|
|
|
* This one is used to create public repository
|
|
|
|
* You can set up a public account in admin page, so everyone can
|
|
|
|
* access photos in this public account
|
|
|
|
*
|
2009-12-17 03:40:38 +00:00
|
|
|
* @since 2.0
|
|
|
|
* @package moodlecore
|
|
|
|
* @subpackage repository
|
|
|
|
* @copyright 2009 Dongsheng Cai
|
2008-09-12 03:32:31 +00:00
|
|
|
* @author Dongsheng Cai <dongsheng@moodle.com>
|
2009-12-17 03:40:38 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-09-12 03:32:31 +00:00
|
|
|
*/
|
2010-03-29 03:39:08 +00:00
|
|
|
|
|
|
|
require_once($CFG->libdir.'/flickrlib.php');
|
|
|
|
|
2008-09-16 02:01:59 +00:00
|
|
|
class repository_flickr_public extends repository {
|
2008-09-12 03:32:31 +00:00
|
|
|
private $flickr;
|
|
|
|
public $photos;
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-11-21 04:19:51 +00:00
|
|
|
* save api_key in config table
|
|
|
|
* @param array $options
|
|
|
|
* @return boolean
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 02:01:59 +00:00
|
|
|
public function set_option($options = array()) {
|
2008-09-12 03:32:31 +00:00
|
|
|
if (!empty($options['api_key'])) {
|
|
|
|
set_config('api_key', trim($options['api_key']), 'flickr_public');
|
|
|
|
}
|
|
|
|
unset($options['api_key']);
|
2010-01-15 07:48:38 +00:00
|
|
|
return parent::set_option($options);
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-11-21 04:19:51 +00:00
|
|
|
* get api_key from config table
|
2010-01-15 07:48:38 +00:00
|
|
|
*
|
2008-11-21 04:19:51 +00:00
|
|
|
* @param string $config
|
|
|
|
* @return mixed
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 02:01:59 +00:00
|
|
|
public function get_option($config = '') {
|
|
|
|
if ($config==='api_key') {
|
2008-09-12 03:32:31 +00:00
|
|
|
return trim(get_config('flickr_public', 'api_key'));
|
|
|
|
} else {
|
|
|
|
$options['api_key'] = trim(get_config('flickr_public', 'api_key'));
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
return parent::get_option($config);
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-11-21 04:19:51 +00:00
|
|
|
* is global_search available?
|
2010-01-15 07:48:38 +00:00
|
|
|
*
|
2008-11-21 04:19:51 +00:00
|
|
|
* @return boolean
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 02:01:59 +00:00
|
|
|
public function global_search() {
|
2008-09-12 03:32:31 +00:00
|
|
|
if (empty($this->flickr_account)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2010-01-15 07:48:38 +00:00
|
|
|
* constructor method
|
2008-09-18 05:33:44 +00:00
|
|
|
*
|
2008-11-21 04:19:51 +00:00
|
|
|
* @global object $CFG
|
2010-01-15 07:48:38 +00:00
|
|
|
* @global object $SESSION
|
2008-11-21 04:19:51 +00:00
|
|
|
* @param int $repositoryid
|
|
|
|
* @param int $context
|
|
|
|
* @param array $options
|
|
|
|
* @param boolean $readonly
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2010-03-16 03:21:59 +00:00
|
|
|
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly=0) {
|
2008-11-21 04:19:51 +00:00
|
|
|
global $CFG, $SESSION;
|
2008-09-16 09:08:36 +00:00
|
|
|
parent::__construct($repositoryid, $context, $options,$readonly);
|
2008-09-12 03:32:31 +00:00
|
|
|
$this->api_key = $this->get_option('api_key');
|
2008-11-21 04:19:51 +00:00
|
|
|
$this->flickr = new phpFlickr($this->api_key);
|
2008-09-15 09:21:29 +00:00
|
|
|
$this->flickr_account = $this->get_option('email_address');
|
2008-09-12 03:32:31 +00:00
|
|
|
|
2008-11-21 04:19:51 +00:00
|
|
|
$account = optional_param('flickr_account', '', PARAM_RAW);
|
|
|
|
$fulltext = optional_param('flickr_fulltext', '', PARAM_RAW);
|
2009-04-24 04:54:47 +00:00
|
|
|
if (empty($fulltext)) {
|
|
|
|
$fulltext = optional_param('s', '', PARAM_RAW);
|
|
|
|
}
|
2008-11-21 04:19:51 +00:00
|
|
|
$tag = optional_param('flickr_tag', '', PARAM_RAW);
|
2009-04-24 04:54:47 +00:00
|
|
|
$license = optional_param('flickr_license', '', PARAM_RAW);
|
|
|
|
|
2008-11-21 04:19:51 +00:00
|
|
|
$this->sess_account = 'flickr_public_'.$this->id.'_account';
|
|
|
|
$this->sess_tag = 'flickr_public_'.$this->id.'_tag';
|
|
|
|
$this->sess_text = 'flickr_public_'.$this->id.'_text';
|
2009-04-24 04:54:47 +00:00
|
|
|
|
|
|
|
if (!empty($account) or !empty($fulltext) or !empty($tag) or !empty($license)) {
|
2008-11-21 04:19:51 +00:00
|
|
|
$SESSION->{$this->sess_tag} = $tag;
|
|
|
|
$SESSION->{$this->sess_text} = $fulltext;
|
2009-04-24 04:54:47 +00:00
|
|
|
$SESSION->{$this->sess_account} = $account;
|
2008-09-22 01:30:14 +00:00
|
|
|
}
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
2008-09-18 05:33:44 +00:00
|
|
|
|
|
|
|
/**
|
2008-11-21 04:19:51 +00:00
|
|
|
* check flickr account
|
|
|
|
* @return boolean
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 02:01:59 +00:00
|
|
|
public function check_login() {
|
2008-09-15 09:31:41 +00:00
|
|
|
return !empty($this->flickr_account);
|
|
|
|
}
|
2008-09-18 05:33:44 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-15 07:48:38 +00:00
|
|
|
* construct login form
|
2008-09-18 05:33:44 +00:00
|
|
|
*
|
2008-11-21 04:19:51 +00:00
|
|
|
* @param boolean $ajax
|
|
|
|
* @return array
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2009-06-18 07:58:37 +00:00
|
|
|
public function print_login() {
|
|
|
|
if ($this->options['ajax']) {
|
2008-09-15 09:31:41 +00:00
|
|
|
$ret = array();
|
2008-11-21 04:19:51 +00:00
|
|
|
$fulltext = new stdclass;
|
|
|
|
$fulltext->label = get_string('fulltext', 'repository_flickr_public').': ';
|
|
|
|
$fulltext->id = 'el_fulltext';
|
|
|
|
$fulltext->type = 'text';
|
|
|
|
$fulltext->name = 'flickr_fulltext';
|
|
|
|
|
|
|
|
$tag = new stdclass;
|
|
|
|
$tag->label = get_string('tag', 'repository_flickr_public').': ';
|
|
|
|
$tag->id = 'el_tag';
|
|
|
|
$tag->type = 'text';
|
|
|
|
$tag->name = 'flickr_tag';
|
|
|
|
|
|
|
|
$email_field = new stdclass;
|
2008-09-15 09:42:38 +00:00
|
|
|
$email_field->label = get_string('username', 'repository_flickr_public').': ';
|
|
|
|
$email_field->id = 'account';
|
|
|
|
$email_field->type = 'text';
|
|
|
|
$email_field->name = 'flickr_account';
|
2009-03-11 06:03:33 +00:00
|
|
|
|
2009-06-24 05:49:52 +00:00
|
|
|
$commercial = new stdclass;
|
|
|
|
$commercial->label = get_string('commercialuse', 'repository_flickr_public').': ';
|
|
|
|
$commercial->id = 'flickr_commercial_id';
|
2009-12-02 13:01:58 +00:00
|
|
|
$commercial->type = 'checkbox';
|
2009-06-24 05:49:52 +00:00
|
|
|
$commercial->name = 'flickr_commercial';
|
2009-12-02 13:01:58 +00:00
|
|
|
$commercial->value = 'yes';
|
2009-04-24 04:54:47 +00:00
|
|
|
|
2009-06-24 05:49:52 +00:00
|
|
|
$modification = new stdclass;
|
|
|
|
$modification->label = get_string('modification', 'repository_flickr_public').': ';
|
|
|
|
$modification->id = 'flickr_modification_id';
|
2009-12-02 13:01:58 +00:00
|
|
|
$modification->type = 'checkbox';
|
2009-06-24 05:49:52 +00:00
|
|
|
$modification->name = 'flickr_modification';
|
2009-12-02 13:01:58 +00:00
|
|
|
$modification->value = 'yes';
|
2009-06-24 05:49:52 +00:00
|
|
|
|
|
|
|
$ret['login'] = array($fulltext, $tag, $email_field, $commercial, $modification);
|
2009-03-11 06:03:33 +00:00
|
|
|
$ret['login_btn_label'] = get_string('search');
|
2009-05-18 03:51:09 +00:00
|
|
|
$ret['login_btn_action'] = 'search';
|
2008-09-15 09:31:41 +00:00
|
|
|
return $ret;
|
2009-06-18 07:58:37 +00:00
|
|
|
} else {
|
|
|
|
echo '<table>';
|
|
|
|
echo '<tr><td><label>'.get_string('fulltext', 'repository_flickr_public').'</label></td>';
|
|
|
|
echo '<td><input type="text" name="flickr_fulltext" /></td></tr>';
|
|
|
|
echo '<tr><td><label>'.get_string('tag', 'repository_flickr_public').'</label></td>';
|
|
|
|
echo '<td><input type="text" name="flickr_tag" /></td></tr>';
|
|
|
|
echo '<tr><td><label>'.get_string('username', 'repository_flickr_public').'</label></td>';
|
|
|
|
echo '<td><input type="text" name="flickr_account" /></td></tr>';
|
|
|
|
|
2009-06-24 05:49:52 +00:00
|
|
|
echo '<tr><td><label>'.get_string('commercialuse', 'repository_flickr_public').'</label></td>';
|
2009-06-18 07:58:37 +00:00
|
|
|
echo '<td>';
|
2009-12-02 13:01:58 +00:00
|
|
|
echo '<input type="checkbox" name="flickr_commercial" value="yes" />';
|
2009-06-24 05:49:52 +00:00
|
|
|
echo '</td></tr>';
|
|
|
|
|
|
|
|
echo '<tr><td><label>'.get_string('modification', 'repository_flickr_public').'</label></td>';
|
|
|
|
echo '<td>';
|
2009-12-02 13:01:58 +00:00
|
|
|
echo '<input type="checkbox" name="flickr_modification" value="yes" />';
|
2009-06-18 07:58:37 +00:00
|
|
|
echo '</td></tr>';
|
|
|
|
|
|
|
|
echo '</table>';
|
|
|
|
|
|
|
|
echo '<input type="hidden" name="action" value="search" />';
|
2009-06-22 03:45:24 +00:00
|
|
|
echo '<input type="submit" value="'.get_string('search', 'repository').'" />';
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-18 05:33:44 +00:00
|
|
|
|
2008-09-22 01:30:14 +00:00
|
|
|
/**
|
2010-01-15 07:48:38 +00:00
|
|
|
* destroy session
|
2008-09-22 01:30:14 +00:00
|
|
|
*
|
2010-01-15 07:48:38 +00:00
|
|
|
* @return object
|
2008-09-22 01:30:14 +00:00
|
|
|
*/
|
|
|
|
public function logout() {
|
2008-11-21 04:19:51 +00:00
|
|
|
global $SESSION;
|
|
|
|
unset($SESSION->{$this->sess_tag});
|
|
|
|
unset($SESSION->{$this->sess_text});
|
|
|
|
unset($SESSION->{$this->sess_account});
|
2008-09-22 01:30:14 +00:00
|
|
|
return $this->print_login();
|
|
|
|
}
|
|
|
|
|
2010-03-29 03:39:08 +00:00
|
|
|
public function license4moodle ($license_id) {
|
|
|
|
$license = array(
|
|
|
|
'1' => 'cc-nc-sa',
|
|
|
|
'2' => 'cc-nc',
|
|
|
|
'3' => 'cc-nc-nd',
|
|
|
|
'4' => 'cc',
|
|
|
|
'5' => 'cc-sa',
|
|
|
|
'6' => 'cc-nd',
|
|
|
|
'7' => 'allrightsreserved'
|
|
|
|
);
|
|
|
|
return $license[$license_id];
|
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2010-01-15 07:48:38 +00:00
|
|
|
* search images on flickr
|
2008-09-18 05:33:44 +00:00
|
|
|
*
|
2010-01-15 07:48:38 +00:00
|
|
|
* @param string $search_text
|
|
|
|
* @return array
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2010-01-15 07:48:38 +00:00
|
|
|
public function search($search_text, $page = 1) {
|
2008-09-19 04:44:37 +00:00
|
|
|
global $SESSION;
|
2009-06-25 04:12:43 +00:00
|
|
|
$ret = array();
|
2010-01-15 07:48:38 +00:00
|
|
|
if (empty($page)) {
|
|
|
|
$page = 1;
|
|
|
|
}
|
|
|
|
|
2008-11-21 04:19:51 +00:00
|
|
|
if (!empty($this->flickr_account)) {
|
|
|
|
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
|
|
|
$this->nsid = $people['nsid'];
|
|
|
|
}
|
|
|
|
if (!empty($SESSION->{$this->sess_account})) {
|
|
|
|
$people = $this->flickr->people_findByEmail($SESSION->{$this->sess_account});
|
|
|
|
$this->nsid = $people['nsid'];
|
|
|
|
}
|
|
|
|
if (empty($this->nsid)) {
|
|
|
|
$this->nsid = null;
|
2009-06-25 04:12:43 +00:00
|
|
|
// user specify a flickr account, but it is not valid
|
|
|
|
if (!empty($this->flickr_account) or !empty($SESSION->{$this->sess_account})) {
|
|
|
|
$ret['e'] = get_string('invalidemail', 'repository_flickr_public');
|
|
|
|
return $ret;
|
|
|
|
}
|
2008-11-21 04:19:51 +00:00
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2009-06-24 05:49:52 +00:00
|
|
|
// including all licenses by default
|
|
|
|
$licenses = array(1=>1, 2, 3, 4, 5, 6, 7);
|
|
|
|
|
|
|
|
$commercial = optional_param('flickr_commercial', '', PARAM_RAW);
|
|
|
|
$modification = optional_param('flickr_modification', '', PARAM_RAW);
|
|
|
|
|
|
|
|
if ($commercial == 'yes') {
|
|
|
|
// including
|
|
|
|
// 4: Attribution License
|
|
|
|
// 5: Attribution ShareAlike
|
|
|
|
// 6: Attribution NoDerives
|
|
|
|
// 7: unknown license
|
|
|
|
unset($licenses[1], $licenses[2], $licenses[3]);
|
|
|
|
}
|
|
|
|
if ($modification == 'yes') {
|
|
|
|
// including
|
|
|
|
// 1: Attribution NonCommercial ShareAlike
|
|
|
|
// 2: Attribution NonCommercial
|
|
|
|
// 4: Attribution License
|
|
|
|
// 5: Attribution ShareAlike
|
|
|
|
// 7: unknown license
|
|
|
|
unset($licenses[3], $licenses[6]);
|
|
|
|
}
|
2009-12-02 13:01:58 +00:00
|
|
|
//if ($modification == 'sharealike') {
|
2009-06-24 05:49:52 +00:00
|
|
|
// including
|
|
|
|
// 1: Attribution NonCommercial ShareAlike
|
|
|
|
// 5: Attribution ShareAlike
|
2009-12-02 13:01:58 +00:00
|
|
|
//unset($licenses[2], $licenses[3], $licenses[4], $licenses[6], $licenses[7]);
|
|
|
|
//}
|
2009-06-24 05:49:52 +00:00
|
|
|
|
|
|
|
$licenses = implode(',', $licenses);
|
|
|
|
|
|
|
|
if (!empty($SESSION->{$this->sess_tag}) // use tag to search
|
|
|
|
or !empty($SESSION->{$this->sess_text}) // use keyword to search
|
2009-12-16 22:22:37 +00:00
|
|
|
or !empty($this->nsid)/*use pre-defined accound*/) {
|
2009-06-24 05:49:52 +00:00
|
|
|
$photos = $this->flickr->photos_search(array(
|
|
|
|
'tags'=>$SESSION->{$this->sess_tag},
|
|
|
|
'page'=>$page,
|
|
|
|
'per_page'=>24,
|
|
|
|
'user_id'=>$this->nsid,
|
|
|
|
'license'=>$licenses,
|
|
|
|
'text'=>$SESSION->{$this->sess_text}
|
|
|
|
)
|
|
|
|
);
|
2008-09-12 08:16:09 +00:00
|
|
|
}
|
2009-06-19 07:22:37 +00:00
|
|
|
$ret['total'] = $photos['total'];
|
|
|
|
$ret['perpage'] = $photos['perpage'];
|
2009-04-24 04:54:47 +00:00
|
|
|
if (empty($photos)) {
|
|
|
|
$ret['list'] = array();
|
|
|
|
return $ret;
|
|
|
|
}
|
2009-02-25 03:46:49 +00:00
|
|
|
$ret = $this->build_list($photos, $page, $ret);
|
|
|
|
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
|
|
|
|
return $ret;
|
2008-09-12 08:16:09 +00:00
|
|
|
}
|
2008-09-18 05:33:44 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-15 07:48:38 +00:00
|
|
|
* return an image list
|
2008-09-18 05:33:44 +00:00
|
|
|
*
|
2009-02-18 06:52:54 +00:00
|
|
|
* @param string $path
|
|
|
|
* @param int $page
|
2010-01-15 07:48:38 +00:00
|
|
|
* @return array
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2009-02-18 06:52:54 +00:00
|
|
|
public function get_listing($path = '', $page = 1) {
|
2008-09-12 03:32:31 +00:00
|
|
|
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
2008-09-16 03:11:17 +00:00
|
|
|
$this->nsid = $people['nsid'];
|
2009-02-18 06:52:54 +00:00
|
|
|
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 24, $page);
|
2008-09-19 04:44:37 +00:00
|
|
|
$ret = array();
|
2008-09-12 03:32:31 +00:00
|
|
|
|
2009-02-18 06:52:54 +00:00
|
|
|
return $this->build_list($photos, $page, $ret);
|
2008-09-16 03:11:17 +00:00
|
|
|
}
|
2008-09-18 05:33:44 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-15 07:48:38 +00:00
|
|
|
* build an image list
|
2008-09-18 05:33:44 +00:00
|
|
|
*
|
2010-01-15 07:48:38 +00:00
|
|
|
* @param array $photos
|
|
|
|
* @param int $page
|
|
|
|
* @return array
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2009-02-18 06:52:54 +00:00
|
|
|
private function build_list($photos, $page = 1, &$ret) {
|
2008-11-21 04:19:51 +00:00
|
|
|
if (!empty($this->nsid)) {
|
|
|
|
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
|
|
|
|
$ret['manage'] = $photos_url;
|
|
|
|
}
|
2008-09-12 03:32:31 +00:00
|
|
|
$ret['list'] = array();
|
|
|
|
$ret['pages'] = $photos['pages'];
|
2009-02-18 06:52:54 +00:00
|
|
|
if (is_int($page) && $page <= $ret['pages']) {
|
|
|
|
$ret['page'] = $page;
|
2008-09-12 03:32:31 +00:00
|
|
|
} else {
|
|
|
|
$ret['page'] = 1;
|
|
|
|
}
|
2008-09-16 03:11:17 +00:00
|
|
|
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';
|
|
|
|
}
|
2009-02-25 02:06:06 +00:00
|
|
|
$format = '.'.$format;
|
|
|
|
if (substr($p['title'], strlen($p['title'])-strlen($format)) != $format) {
|
2009-06-25 04:12:43 +00:00
|
|
|
// append author id
|
2009-07-05 14:15:18 +00:00
|
|
|
// $p['title'] .= '-'.$p['owner'];
|
2009-06-25 04:12:43 +00:00
|
|
|
// append file extension
|
2009-11-01 12:51:40 +00:00
|
|
|
$p['title'] .= $format;
|
2009-02-25 02:06:06 +00:00
|
|
|
}
|
2010-03-29 03:39:08 +00:00
|
|
|
$ret['list'][] = array(
|
|
|
|
'title'=>$p['title'],
|
|
|
|
'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'],
|
|
|
|
'haslicense'=>true,
|
|
|
|
'hasauthor'=>true
|
|
|
|
);
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-16 03:11:17 +00:00
|
|
|
return $ret;
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
2008-09-16 02:01:59 +00:00
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2009-11-08 13:20:37 +00:00
|
|
|
* Print a search form
|
2008-09-18 05:33:44 +00:00
|
|
|
*
|
2009-11-08 13:20:37 +00:00
|
|
|
* @return string
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 02:01:59 +00:00
|
|
|
public function print_search() {
|
2009-04-21 05:53:35 +00:00
|
|
|
$str = '';
|
|
|
|
$str .= '<input type="hidden" name="repo_id" value="'.$this->id.'" />';
|
|
|
|
$str .= '<input type="hidden" name="ctx_id" value="'.$this->context->id.'" />';
|
|
|
|
$str .= '<input type="hidden" name="seekey" value="'.sesskey().'" />';
|
|
|
|
$str .= '<label>'.get_string('fulltext', 'repository_flickr_public').': </label><br/><input name="s" value="" /><br/>';
|
2010-03-16 06:05:24 +00:00
|
|
|
$str .= '<label>'.get_string('tag', 'repository_flickr_public').'</label><br /><input type="text" name="flickr_tag" /><br />';
|
2009-04-21 05:53:35 +00:00
|
|
|
return $str;
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
2008-09-16 02:01:59 +00:00
|
|
|
|
2009-11-08 13:20:37 +00:00
|
|
|
public function get_link($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'];
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
|
|
|
*
|
2009-06-19 07:22:37 +00:00
|
|
|
* @global object $CFG
|
|
|
|
* @param string $photo_id
|
|
|
|
* @param string $file
|
|
|
|
* @return string
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 02:01:59 +00:00
|
|
|
public function get_file($photo_id, $file = '') {
|
2008-09-12 03:32:31 +00:00
|
|
|
global $CFG;
|
2010-03-29 03:39:08 +00:00
|
|
|
$info = $this->flickr->photos_getInfo($photo_id);
|
2008-09-12 03:32:31 +00:00
|
|
|
$result = $this->flickr->photos_getSizes($photo_id);
|
2010-03-29 03:39:08 +00:00
|
|
|
// download link
|
|
|
|
$source = '';
|
|
|
|
// flickr photo page
|
2008-09-12 03:32:31 +00:00
|
|
|
$url = '';
|
2008-09-16 02:01:59 +00:00
|
|
|
if (!empty($result[4])) {
|
2010-03-29 03:39:08 +00:00
|
|
|
$source = $result[4]['source'];
|
|
|
|
$url = $result[4]['url'];
|
2008-09-16 03:11:17 +00:00
|
|
|
} elseif(!empty($result[3])) {
|
2010-03-29 03:39:08 +00:00
|
|
|
$source = $result[3]['source'];
|
|
|
|
$url = $result[3]['url'];
|
2008-09-16 03:11:17 +00:00
|
|
|
} elseif(!empty($result[2])) {
|
2010-03-29 03:39:08 +00:00
|
|
|
$source = $result[2]['source'];
|
|
|
|
$url = $result[2]['url'];
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
2009-03-16 02:16:50 +00:00
|
|
|
$path = $this->prepare_file($file);
|
|
|
|
$fp = fopen($path, 'w');
|
2008-09-12 03:32:31 +00:00
|
|
|
$c = new curl;
|
2010-03-29 03:39:08 +00:00
|
|
|
$c->download(array(array('url'=>$source, 'file'=>$fp)));
|
|
|
|
|
|
|
|
return array('path'=>$path, 'url'=>$url, 'author'=>$info['owner']['realname'], 'license'=>$this->license4moodle($info['license']));
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-09-18 05:43:38 +00:00
|
|
|
* Add Instance settings input to Moodle form
|
2010-01-15 07:48:38 +00:00
|
|
|
* @param object $mform
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2010-03-09 06:25:20 +00:00
|
|
|
public function instance_config_form($mform) {
|
2008-09-15 09:21:29 +00:00
|
|
|
$mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr_public'));
|
2008-11-20 06:24:21 +00:00
|
|
|
//$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
|
2008-09-15 09:21:29 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-09-18 05:43:38 +00:00
|
|
|
* Names of the instance settings
|
2010-01-15 07:48:38 +00:00
|
|
|
* @return array
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-15 09:21:29 +00:00
|
|
|
public static function get_instance_option_names() {
|
|
|
|
return array('email_address');
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-09-18 05:43:38 +00:00
|
|
|
* Add Plugin settings input to Moodle form
|
2010-01-15 07:48:38 +00:00
|
|
|
* @param object $mform
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2010-03-09 06:25:20 +00:00
|
|
|
public function type_config_form($mform) {
|
2008-09-12 03:32:31 +00:00
|
|
|
$api_key = get_config('flickr_public', 'api_key');
|
|
|
|
if (empty($api_key)) {
|
|
|
|
$api_key = '';
|
|
|
|
}
|
|
|
|
$strrequired = get_string('required');
|
2009-06-25 04:12:43 +00:00
|
|
|
|
2008-09-12 03:32:31 +00:00
|
|
|
$mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr_public'), array('value'=>$api_key,'size' => '40'));
|
|
|
|
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
|
2009-06-25 04:12:43 +00:00
|
|
|
|
2008-09-17 06:09:10 +00:00
|
|
|
$mform->addElement('static', null, '', get_string('information','repository_flickr_public'));
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|
2008-09-15 09:21:29 +00:00
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-09-18 05:43:38 +00:00
|
|
|
* Names of the plugin settings
|
2010-01-15 07:48:38 +00:00
|
|
|
* @return array
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-18 03:19:52 +00:00
|
|
|
public static function get_type_option_names() {
|
2010-03-29 03:39:08 +00:00
|
|
|
return array('api_key');
|
2008-09-15 09:21:29 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 05:33:44 +00:00
|
|
|
/**
|
2008-09-18 05:54:23 +00:00
|
|
|
* is run when moodle administrator add the plugin
|
2008-09-18 05:33:44 +00:00
|
|
|
*/
|
2008-09-16 09:08:36 +00:00
|
|
|
public static function plugin_init() {
|
2008-09-17 06:09:10 +00:00
|
|
|
//here we create a default instance for this type
|
2008-09-12 03:32:31 +00:00
|
|
|
|
2009-03-05 05:40:56 +00:00
|
|
|
$id = repository::static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => get_string('repositoryname', 'repository_flickr_public'),'email_address' => null), 1);
|
|
|
|
if (empty($id)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2008-11-26 07:03:10 +00:00
|
|
|
}
|
2008-12-08 05:19:09 +00:00
|
|
|
public function supported_filetypes() {
|
|
|
|
return array('web_image');
|
|
|
|
}
|
2009-11-02 06:45:12 +00:00
|
|
|
public function supported_returntypes() {
|
|
|
|
return (FILE_INTERNAL | FILE_EXTERNAL);
|
|
|
|
}
|
2008-09-12 03:32:31 +00:00
|
|
|
}
|