"MDL-15488, flickr plug-in added"
[moodle.git] / repository / flickr / repository.class.php
CommitLineData
36ea9a6c 1<?php
2/**
3 * repository_flickr class
4 * This is a subclass of repository class
5 *
6 * @author Dongsheng Cai
7 * @version 0.1 dev
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 */
10
11require_once($CFG->dirroot.'/repository/lib.php');
12require_once($CFG->dirroot.'/repository/flickr/'.'phpFlickr.php');
13
14class repository_flickr extends repository{
15 var $flickr;
16 var $photos;
17 public function __construct($repositoryid, $context = SITEID, $options = array()){
18 global $SESSION, $action;
19 $options['page'] = optional_param('p', 1, PARAM_INT);
20 $options['api_key'] = 'bf85ae2b5b105a2c645f32a32cd6ad59';
21 $options['secret'] = '7cb2f9d7cf70aebe';
22 parent::__construct($repositoryid, $context, $options);
23 $this->flickr = new phpFlickr($this->options['api_key'], $this->options['secret']);
24
25 $reset = optional_param('reset', 0, PARAM_INT);
26 if(!empty($reset)) {
27 unset($SESSION->flickrmail);
28 set_user_preference('flickrmail', '');
29 }
30
31 if(!empty($SESSION->filckrmail)){
32 $action = 'list';
33 } else {
34 $options['flickrmail'] = optional_param('flickrmail', '', PARAM_RAW);
35 if(!empty($options['flickrmail'])) {
36 $people = $this->flickr->people_findByEmail($options['flickrmail']);
37 if(!empty($people)) {
38 $remember = optional_param('remember', '', PARAM_RAW);
39 if(!empty($remember)) {
40 set_user_preference('flickrmail', $options['flickrmail']);
41 }
42 $SESSION->flickrmail = $options['flickrmail'];
43 $action = 'list';
44 }
45 } else {
46 if($account = get_user_preferences('flickrmail', '')){
47 $SESSION->flickrmail = $account;
48 $action = 'list';
49 }
50 }
51 }
52 }
53 public function print_login(){
54 global $SESSION;
55 if(empty($SESSION->flickrmail)) {
56 echo <<<EOD
57 <form action="picker.php">
58 <label for="account">Flickr Account (Email)</lable>
59 <input type='text' name='flickrmail' id='account' />
60 <input type='hidden' name='id' value='$this->repositoryid' />
61 <input type='checkbox' name='remember' value='true' /> Remember <br/>
62 <input type='submit' value='Go' />
63 </form>
64EOD;
65 } else {
66 $this->print_listing();
67 }
68 //echo '<a href="?id='.$this->repositoryid.'&action=list">See flickr photos list</a>';
69 return true;
70 }
71 public function get_listing($path = '0', $search = ''){
72 global $SESSION;
73 $people = $this->flickr->people_findByEmail($SESSION->flickrmail);
74 $photos_url = $this->flickr->urls_getUserPhotos($people['nsid']);
75 $photos = $this->flickr->people_getPublicPhotos($people['nsid'], null, 36, $this->page);
76 $this->photos = array('a'=>$SESSION->flickrmail, 'u'=>$photos_url, 'p'=>$photos);
77 return $this->photos;
78 }
79 public function print_listing(){
80 if(empty($this->photos)){
81 $this->get_listing();
82 }
83 echo '<h2>Account: <span>'.$this->photos['a'].'</span></h2>';
84 echo '<a href="picker.php?id='.$this->repositoryid.'&reset=1">Change user</a>';
85 echo '<hr/>';
86 foreach ((array)$this->photos['p']['photo'] as $photo) {
87 echo "<a href='".$this->photos['u'].$photo[id]."'>";
88 echo "<img border='0' alt='$photo[title]' ".
89 "src=" . $this->flickr->buildPhotoURL($photo, "Square") . ">";
90 echo "</a>";
91 $i++;
92 // If it reaches the sixth photo, insert a line break
93 if ($i % 6 == 0) {
94 echo "<br/>";
95 }
96 }
97 echo <<<EOD
98<style type='text/css'>
99#paging{margin-top: 10px; clear:both}
100#paging a{padding: 4px; border: 1px solid gray}
101</style>
102EOD;
103 echo '<div id="paging">';
104 for($i=1; $i <= $this->photos['p']['pages']; $i++) {
105 echo '<a href="picker.php?id='.$this->repositoryid.'&action=list&p='.$i.'">';
106 echo $i;
107 echo '</a> ';
108 }
109 echo '</div>';
110 }
111 public function print_search(){
112 echo '<input type="text" name="Search" value="search terms..." size="40" class="right"/>';
113 return true;
114 }
115}
116?>