require_once($CFG->libdir.'/flickrlib.php');
-class repository_flickr extends repository{
+/**
+ *
+ */
+class repository_flickr extends repository {
private $flickr;
public $photos;
- public function __construct($repositoryid, $context = SITEID, $options = array()){
+ /**
+ *
+ * @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);
$this->flickr = new phpFlickr($this->api_key, $this->secret, $this->token);
- if(empty($this->token)){
+ if (empty($this->token)) {
$frob = optional_param('frob', '', PARAM_RAW);
- if(!empty($frob)){
+ if (!empty($frob)) {
$auth_info = $this->flickr->auth_getToken($frob);
$this->token = $auth_info['token'];
$this->nsid = $auth_info['user']['nsid'];
}
}
- public function check_login(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function check_login() {
return !empty($this->token);
}
- public function logout(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function logout() {
set_user_preference($this->setting, '');
set_user_preference($this->setting.'_nsid', '');
$this->token = '';
$this->nsid = '';
return $this->print_login();
}
- public function set_option($options = array()){
+
+ /**
+ *
+ * @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');
}
return $ret;
}
- public function get_option($config = ''){
- if($config==='api_key'){
+ /**
+ *
+ * @param <type> $config
+ * @return <type>
+ */
+ public function get_option($config = '') {
+ if ($config==='api_key') {
return trim(get_config('flickr', 'api_key'));
} elseif ($config ==='secret') {
return trim(get_config('flickr', 'secret'));
return $options;
}
- public function global_search(){
+ /**
+ *
+ * @global <type> $SESSION
+ * @return <type>
+ */
+ public function global_search() {
global $SESSION;
+
if (empty($this->token)) {
return false;
} else {
return true;
}
}
- public function print_login($ajax = true){
+
+ /**
+ *
+ * @global <type> $SESSION
+ * @param <type> $ajax
+ * @return <type>
+ */
+ public function print_login($ajax = true) {
global $SESSION;
+
if($ajax){
$ret = array();
$popup_btn = new stdclass;
return $ret;
}
}
- public function get_listing($path = '1', $search = ''){
+
+ /**
+ *
+ * @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)) {
+ if (!empty($search)) {
$photos = $this->flickr->photos_search(array(
'user_id'=>$nsid,
'per_page'=>25,
'extras'=>'original_format',
'text'=>$search
));
- } elseif(!empty($path) && empty($search)) {
+ } elseif (!empty($path) && empty($search)) {
$photos = $this->flickr->photos_search(array(
'user_id'=>$nsid,
'per_page'=>25,
$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'])){
+ 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'])) {
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)) {
+ if (empty($ret)) {
throw new repository_exception('nullphotolist', 'repository_flickr');
} else {
return $ret;
}
}
- public function print_listing(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function print_listing() {
return false;
}
- public function print_search(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function print_search() {
echo '<input name="s" value="" />';
parent::print_search();
return true;
}
- public function get_file($photo_id, $file = ''){
+
+ /**
+ *
+ * @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')) {
$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');
));
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');
}
- public static function get_instance_option_names(){
+ /**
+ *
+ * @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');
//retrieve the flickr instances
$instances = repository_get_instances(array(),null,false,"flickr");
- if (empty($instances)){
+ if (empty($instances)) {
$callbackurl = get_string("callbackwarning","repository_flickr");
}
else {
$mform->addRule('secret', $strrequired, 'required', null, 'client');
}
- public static function get_admin_option_names(){
+ /**
+ *
+ * @return <type>
+ */
+ public static function get_admin_option_names() {
return array('api_key', 'secret');
}
require_once($CFG->libdir.'/flickrlib.php');
-class repository_flickr_public extends repository{
+/**
+ *
+ */
+class repository_flickr_public extends repository {
private $flickr;
public $photos;
- public function set_option($options = array()){
+ /**
+ *
+ * @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');
}
return $ret;
}
- public function get_option($config = ''){
- if($config==='api_key'){
+ /**
+ *
+ * @param <type> $config
+ * @return <type>
+ */
+ public function get_option($config = '') {
+ if ($config==='api_key') {
return trim(get_config('flickr_public', 'api_key'));
} else {
$options['api_key'] = trim(get_config('flickr_public', 'api_key'));
return $options;
}
- public function global_search(){
+ /**
+ *
+ * @return <type>
+ */
+ public function global_search() {
if (empty($this->flickr_account)) {
return false;
} else {
}
}
- public function __construct($repositoryid, $context = SITEID, $options = array()){
+ /**
+ *
+ * @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);
parent::__construct($repositoryid, $context, $options);
$this->api_key = $this->get_option('api_key');
$this->flickr_account = $this->get_option('email_address');
$account = optional_param('flickr_account', '', PARAM_RAW);
- if(!empty($account)) {
+ if (!empty($account)) {
$people = $this->flickr->people_findByEmail($account);
- if(!empty($people)) {
+ if (!empty($people)) {
$this->flickr_account = $account;
} else {
throw new repository_exception('invalidemail', 'repository_flickr_public');
}
}
}
- public function check_login(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function check_login() {
return !empty($this->flickr_account);
}
- public function print_login($ajax = true){
- if($ajax){
+
+ /**
+ *
+ * @param <type> $ajax
+ * @return <type>
+ */
+ public function print_login($ajax = true) {
+ if ($ajax) {
$ret = array();
$email_field->label = get_string('username', 'repository_flickr_public').': ';
$email_field->id = 'account';
return $ret;
}
}
- public function search(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function search() {
$people = $this->flickr->people_findByEmail($this->flickr_account);
$tag = optional_param('tag', '', PARAM_CLEANHTML);
$search = optional_param('s', '', PARAM_CLEANHTML);
- if(!empty($tag)){
+ if (!empty($tag)) {
$photos = $this->flickr->photos_search(array(
'tags'=>$tag
));
$ret['nologin'] = true;
$ret['pages'] = $photos['pages'];
foreach ($photos['photo'] as $p) {
- if(empty($p['title'])) {
+ if (empty($p['title'])) {
$p['title'] = get_string('notitle', 'repository_flickr_public');
}
if (isset($p['originalformat'])) {
$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)) {
+ if (empty($ret)) {
throw new repository_exception('nullphotolist', 'repository_flickr_public');
} else {
return $ret;
}
}
- public function get_listing($path = '1', $search = ''){
+
+ /**
+ *
+ * @param <type> $path
+ * @param <type> $search
+ * @return <type>
+ */
+ public function get_listing($path = '1', $search = '') {
$people = $this->flickr->people_findByEmail($this->flickr_account);
$photos_url = $this->flickr->urls_getUserPhotos($people['nsid']);
$ret['list'] = array();
$ret['nologin'] = true;
$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;
}
foreach ($photos['photo'] as $p) {
- if(empty($p['title'])) {
+ if (empty($p['title'])) {
$p['title'] = get_string('notitle', 'repository_flickr_public');
}
if (isset($p['originalformat'])) {
$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)) {
+ if (empty($ret)) {
throw new repository_exception('nullphotolist', 'repository_flickr_public');
} else {
return $ret;
}
}
- public function print_listing(){
+
+ /**
+ *
+ * @return <type>
+ */
+ public function print_listing() {
return false;
}
- public function print_search(){
+
+ /**
+ *
+ * @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;
}
- public function get_file($photo_id, $file = ''){
+
+ /**
+ *
+ * @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')) {
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/';
}
- 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');
));
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)) {
$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
}