/[drupal]/contributions/modules/flickr/flickr.module
ViewVC logotype

Contents of /contributions/modules/flickr/flickr.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.42 - (show annotations) (download) (as text)
Wed Apr 2 20:09:05 2008 UTC (19 months, 3 weeks ago) by heine
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-alpha1, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.41: +2 -2 lines
File MIME type: text/x-php
Fixes an XSS vulnerability. See SA-2008-022 - Flickr - Cross site scripting at http://drupal.org/node/241939 for details.
1 <?php
2 // $Id: flickr.module,v 1.41 2008/04/01 06:17:11 drewish Exp $
3
4 require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
5
6 /**
7 * Implementation of hook_help().
8 */
9 function flickr_help($section, $arg) {
10 switch ($section) {
11 case 'admin/settings/flickr':
12 return t("You will need a Flickr API key to use this module. You can apply for one at <a href='@link'>@link</a>", array('@link' => url('http://www.flickr.com/services/api/keys/apply/')));
13 case 'admin/help#flickr':
14 return t('The flickr module uses XML-RPC to connect to Flickr\'s API and retreive photo information.');
15 }
16 }
17
18 /**
19 * Implementation of hook_perm().
20 */
21 function flickr_perm() {
22 return array(
23 'view own flickr photos',
24 'view all flickr photos',
25 'administer flickr',
26 );
27 }
28
29 /**
30 * Implementation of hook_theme().
31 */
32 function flickr_theme() {
33 return array(
34 'flickr_photo' => array(
35 'arguments' => array('size' => NULL, 'format' => NULL, 'attribs' => NULL),
36 ),
37 'flickr_photo_box' => array(
38 'arguments' => array('p', 'size' => NULL, 'format' => NULL, 'attribs' => NULL),
39 ),
40 'flickr_photos' => array(
41 'arguments' => array('uid' => NULL, 'photos' => NULL),
42 ),
43 'flickr_photoset' => array(
44 'arguments' => array('ps', 'owner', 'size', 'attribs' => NULL),
45 ),
46 );
47 }
48
49 /**
50 * Implementation of hook_menu().
51 */
52 function flickr_menu() {
53 $items['admin/settings/flickr'] = array(
54 'title' => 'Flickr',
55 'page callback' => 'drupal_get_form',
56 'page arguments' => array('flickr_admin_settings'),
57 'access arguments' => array('administer site configuration'),
58 'description' => 'Change settings for the flickr module.',
59 'file' => 'flickr.admin.inc',
60 );
61 $items['flickr'] = array(
62 'title' => 'Flickr photos',
63 'type' => MENU_CALLBACK,
64 'page callback' => 'flickr_photos',
65 'access callback' => TRUE,
66 'description' => 'Flickr photos of default user id.',
67 );
68 $items['flickr/%user'] = array(
69 'title' => 'Flickr photos',
70 'type' => MENU_CALLBACK,
71 'page callback' => 'flickr_photos',
72 'page arguments' => array(1),
73 'access callback' => 'flickr_photos_access',
74 'access arguments' => array(1),
75 'description' => 'Flickr photos of specified user.',
76 );
77 $items['flickr/auth'] = array(
78 'type' => MENU_CALLBACK,
79 'access callback' => TRUE,
80 'page callback' => 'flickr_auth_callback',
81 );
82 return $items;
83 }
84
85 function flickr_photos_access($account) {
86 $view_access = FALSE;
87 if (!empty($account) && !empty($account->uid)) {
88 if (isset($account->flickr['nsid'])) {
89 $view_access = user_access('administer flickr') ||
90 // Only admins can view blocked accounts
91 $account->status && (
92 user_access('view all flickr photos') ||
93 user_access('view own flickr photos') && $GLOBALS['user']->uid == $account->uid
94 );
95 }
96 else {
97 drupal_set_message(t('%user does not have a Flickr account', array('%user' => $account->name)), 'error');
98 }
99 }
100 return $view_access;
101 }
102
103 /**
104 * Implementation of the hook_user()
105 * Add an extra field for the user to enter his flickr identifier.
106 */
107 function flickr_user($op, &$edit, &$account, $category = NULL) {
108 if ($op == 'form') {
109 if ($category == 'account') {
110 $user = user_load(array('uid' => $account->uid));
111 $form['flickr'] = array(
112 '#type' => 'fieldset',
113 '#title' => t('Flickr settings'),
114 '#collapsible' => FALSE,
115 '#weight' => 4,
116 '#tree' => FALSE,
117 );
118 $form['flickr']['flickr_identifier'] = array(
119 '#type' => 'textfield',
120 '#title' => t('Flickr identifier'),
121 '#default_value' => empty($user->flickr['identifier']) ? '' : $user->flickr['identifier'],
122 '#description' => t('Enter either your Flickr username, the email address associated with your Flickr account, or your Flickr NSID. Leave this box empty to delete your Flickr page on this site.'),
123 '#maxlength' => 64,
124 );
125 return $form;
126 }
127 }
128 elseif ($op == 'validate') {
129 if (!empty($edit['flickr_identifier'])) {
130 if (!flickr_user_find_by_identifier($edit['flickr_identifier'])) {
131 form_set_error('flickr_identifier', t('%ident is not a valid Flickr username, email, or NSID.', array('%ident' => $edit['flickr_identifier'])));
132 }
133 }
134 }
135 elseif ($op == 'insert' || $op == 'update') {
136 if (isset($edit['flickr_identifier'])) {
137 db_query('DELETE FROM {flickr_users} WHERE uid=%d', $account->uid);
138 $user_affected = db_affected_rows();
139 if (!empty($edit['flickr_identifier'])) {
140 db_query("INSERT INTO {flickr_users} (uid, nsid, identifier) VALUES (%d, '%s', '%s')", $account->uid, flickr_user_find_by_identifier($edit['flickr_identifier']), $edit['flickr_identifier']);
141 }
142 else if ($user_affected) {
143 //flickr account deleted
144 drupal_set_message(t("%username's Flickr page has been deleted.", array('%username' => $account->name)));
145 }
146 }
147 $edit['flickr_identifier'] = NULL;
148 }
149 elseif ($op == 'load') {
150 $result = db_query('SELECT * FROM {flickr_users} WHERE uid=%d', $account->uid);
151 if ($flickr_info = db_fetch_object($result)) {
152 $account->flickr['identifier'] = $flickr_info->identifier;
153 $account->flickr['nsid'] = $flickr_info->nsid;
154 }
155 }
156 elseif ($op == 'delete') {
157 db_query('DELETE FROM {flickr_users} WHERE uid=%d', $account->uid);
158 }
159 }
160
161 function flickr_photos($user = NULL) {
162 drupal_add_css(drupal_get_path('module', 'flickr') .'/flickr.css');
163
164 global $pager_page_array, $pager_total, $pager_total_items;
165 //set this to something else if you want multiple pagers
166 $element = 0;
167 $pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
168
169 if ($user === NULL) {
170 $nsid = variable_get('flickr_default_userid', '');
171 if (!$nsid) {
172 drupal_set_message(t('No default Flickr user id has been set.'));
173 return FALSE;
174 }
175 $uid = 0;
176 }
177 else {
178 $account = $user;
179 if ($account->flickr['nsid']) {
180 $nsid = $account->flickr['nsid'];
181 }
182 else {
183 drupal_set_message(t('%user does not have a Flickr account', array('%user' => $account->name)), 'error');
184 return FALSE;
185 }
186 $uid = $account->uid;
187 }
188
189 $photos = flickr_photos_search($nsid, $pager_page_array[$element] + 1);
190 if (!$photos) {
191 drupal_set_message(t('No accessible photos found for Flickr %userid', array('%userid' => $nsid)));
192 return FALSE;
193 }
194
195 //set pager information we just acquired
196 $pager_total[$element] = $photos['pages'];
197 $pager_total_items[$element] = $photos['total'];
198
199 return theme('flickr_photos', $uid, $photos);
200 }
201
202 function theme_flickr_photo($p, $size = NULL, $format = NULL, $attribs = NULL) {
203 $img = flickr_img($p, $size, $attribs);
204 $photo_url = flickr_photo_page_url($p['owner'], $p['id']);
205 $title = is_array($p['title']) ? $p['title']['_content'] : $p['title'];
206 return l($img, $photo_url, array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE));
207 }
208
209 function theme_flickr_photo_box($p, $size = NULL, $format = NULL, $attribs = NULL) {
210 $img = flickr_img($p, $size, $attribs);
211 $title = is_array($p['title']) ? $p['title']['_content'] : $p['title'];
212 $photo_url = flickr_photo_page_url($p['owner'], $p['id']);
213
214 $output = "<div class='flickr-photo-box'>\n";
215 $output .= "<a href='$photo_url'>$img</a>";
216 $output .= "<a href='$photo_url'>";
217 $output .= '<div class="flickr-photo-title">'. check_plain($title) ."</div>\n";
218 $output .= "</a>";
219 $output .= "</div>\n";
220
221 return $output;
222 }
223
224 function theme_flickr_photos($uid, $photos) {
225 $output = theme('pager', NULL, variable_get('flickr_photos_per_page', 20));
226 $output .= "<div class='fickr-photoset'>\n";
227 foreach ($photos['photo'] as $photo) {
228 $output .= theme('flickr_photo_box', $photo, 'm');
229 }
230 $output .= '</div>';
231 $output .= theme('pager', NULL, variable_get('flickr_photos_per_page', 20));
232 return $output;
233 }
234
235 function theme_flickr_photoset($ps, $owner, $size, $attribs = NULL) {
236 $img = flickr_img($ps, $size, $attribs);
237 $photo_url = flickr_photoset_page_url($owner, $ps['id']);
238 $title = is_array($ps['title']) ? $ps['title']['_content'] : $ps['title'];
239 return l($img, $photo_url, array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE));
240 }
241

  ViewVC Help
Powered by ViewVC 1.1.2