| 1 |
<?php |
<?php |
| 2 |
// $Id: flickr_block.module,v 1.14 2008/09/30 05:21:37 drewish Exp $ |
// $Id: flickr_block.module,v 1.15 2008/11/21 10:19:37 paulbooker Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_block(). |
* Implementation of hook_block(). |
| 17 |
$blocks[4]['info'] = t('Flickr recent photosets'); |
$blocks[4]['info'] = t('Flickr recent photosets'); |
| 18 |
$blocks[5]['info'] = t('Flickr random photos'); |
$blocks[5]['info'] = t('Flickr random photos'); |
| 19 |
|
|
| 20 |
|
// Photoset blocks |
| 21 |
|
$blocks[6]['info'] = t('Flickr random photo from photoset'); |
| 22 |
|
|
| 23 |
return $blocks; |
return $blocks; |
| 24 |
|
|
| 25 |
case 'configure': |
case 'configure': |
| 32 |
unset($size_options['b']); |
unset($size_options['b']); |
| 33 |
unset($size_options['o']); |
unset($size_options['o']); |
| 34 |
|
|
| 35 |
$settings = variable_get('flickr_block_'. $delta, array('user_id' => '', 'show_n' => 4, 'size' => 's')); |
$settings = variable_get('flickr_block_'. $delta, array('user_id' => '', 'show_n' => 4, 'size' => 's', 'photoset_id' => '')); |
| 36 |
|
|
| 37 |
$form = array(); |
$form = array(); |
| 38 |
$form["flickr_block_{$delta}_user_id"] = array( |
$form["flickr_block_{$delta}_user_id"] = array( |
| 44 |
$form["flickr_block_{$delta}_show_n"] = array( |
$form["flickr_block_{$delta}_show_n"] = array( |
| 45 |
'#type' => 'select', |
'#type' => 'select', |
| 46 |
'#options' => $count_options, |
'#options' => $count_options, |
| 47 |
'#title' => t('Show the last <em>n</em> photos'), |
'#title' => t('Show <em>n</em> photos'), |
| 48 |
'#default_value' => $settings['show_n'], |
'#default_value' => $settings['show_n'], |
| 49 |
'#description' => t("The block will display this many photos.") |
'#description' => t("The block will display this many photos.") |
| 50 |
); |
); |
| 78 |
break; |
break; |
| 79 |
case 5: // sitewide, random |
case 5: // sitewide, random |
| 80 |
break; |
break; |
| 81 |
|
case 6: // sitewide, random |
| 82 |
|
$form["flickr_block_{$delta}_photoset"] = array( |
| 83 |
|
'#type' => 'textfield', |
| 84 |
|
'#title' => t('Flickr Photoset Id'), |
| 85 |
|
'#default_value' => $settings['photoset_id'], |
| 86 |
|
'#description' => t("The id of a Flickr photoset."), |
| 87 |
|
'#required' => TRUE, |
| 88 |
|
); |
| 89 |
|
break; |
| 90 |
} |
} |
| 91 |
|
|
| 92 |
return $form; |
return $form; |
| 111 |
'size' => $edit["flickr_block_{$delta}_size"], |
'size' => $edit["flickr_block_{$delta}_size"], |
| 112 |
)); |
)); |
| 113 |
break; |
break; |
| 114 |
|
case 6: |
| 115 |
|
variable_set('flickr_block_'. $delta, array( |
| 116 |
|
'user_id' => $edit["flickr_block_{$delta}_user_id"], |
| 117 |
|
'show_n' => (int) $edit["flickr_block_{$delta}_show_n"], |
| 118 |
|
'size' => $edit["flickr_block_{$delta}_size"], |
| 119 |
|
'photoset_id' => $edit["flickr_block_{$delta}_photoset"], |
| 120 |
|
)); |
| 121 |
} |
} |
| 122 |
break; |
break; |
| 123 |
|
|
| 127 |
'user_id' => '', |
'user_id' => '', |
| 128 |
'show_n' => 4, |
'show_n' => 4, |
| 129 |
'size' => 's', |
'size' => 's', |
| 130 |
)); |
)); |
| 131 |
// Get the default user id as a fallback |
// Get the default user id as a fallback |
| 132 |
if (!isset($settings['user_id'])) { |
if ($settings['user_id'] == "") { |
| 133 |
$settings['user_id'] = variable_get('flickr_default_userid', ''); |
$settings['user_id'] = variable_get('flickr_default_userid', ''); |
| 134 |
} |
} |
| 135 |
|
$settings['user_id'] =flickr_user_find_by_identifier($settings['user_id']); |
| 136 |
|
|
| 137 |
$block = array(); |
$block = array(); |
| 138 |
|
|
| 139 |
// Get per user nsid if necessary |
// Get per user nsid if necessary |
| 169 |
$block['subject'] = t('Flickr random photos'); |
$block['subject'] = t('Flickr random photos'); |
| 170 |
$block['content'] = _flickr_block_random($settings['user_id'], $settings['show_n'], $settings['size']); |
$block['content'] = _flickr_block_random($settings['user_id'], $settings['show_n'], $settings['size']); |
| 171 |
} |
} |
| 172 |
|
elseif ($delta == 6) { |
| 173 |
|
$block['subject'] = t('Flickr random photoset photos'); |
| 174 |
|
$block['content'] = _flickr_block_photoset_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['photoset_id']); |
| 175 |
|
} |
| 176 |
return $block; |
return $block; |
| 177 |
} |
} |
| 178 |
} |
} |
| 224 |
return $output; |
return $output; |
| 225 |
} |
} |
| 226 |
|
|
| 227 |
|
function _flickr_block_photoset_random($nsid, $show_n, $size, $photoset_id) { |
| 228 |
|
// Get information about the photoset, including the owner. |
| 229 |
|
$info = flickr_photoset_get_info($photoset_id); |
| 230 |
|
if (!$info) { |
| 231 |
|
return; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
// Get a list of "all" the photos in the photoset. This is cached. |
| 235 |
|
$response = flickr_request('flickr.photosets.getPhotos', |
| 236 |
|
array( |
| 237 |
|
'photoset_id' => $photoset_id, |
| 238 |
|
'per_page' => 500, // get as many images as possible |
| 239 |
|
'extras' => 'owner', |
| 240 |
|
) |
| 241 |
|
); |
| 242 |
|
if (!$response) { |
| 243 |
|
return; |
| 244 |
|
} |
| 245 |
|
|
| 246 |
|
// Randomly display $show_n of them |
| 247 |
|
$photos = $response['photoset']['photo']; |
| 248 |
|
shuffle($photos); |
| 249 |
|
|
| 250 |
|
// we shouldn't try to return more than the total number of photos |
| 251 |
|
$output = ''; |
| 252 |
|
$to = min($show_n, count($photos)); |
| 253 |
|
for ($i = 0; $i < $to; $i++) { |
| 254 |
|
//insert owner into $photo because theme_flickr_photo needs it |
| 255 |
|
$photos[$i]['owner'] = $info['owner']; |
| 256 |
|
$output .= theme('flickr_block_photo', $photos[$i], $size); |
| 257 |
|
} |
| 258 |
|
return $output; |
| 259 |
|
} |
| 260 |
|
|
| 261 |
/** |
/** |
| 262 |
* Implementation of hook_theme(). |
* Implementation of hook_theme(). |
| 263 |
*/ |
*/ |