diff --git a/block/flickr_block.module b/block/flickr_block.module
index 9fe167d..98e9e41 100644
--- a/block/flickr_block.module
+++ b/block/flickr_block.module
@@ -4,6 +4,8 @@
* The Flickr block module
*/
+require_once(drupal_get_path('module', 'flickr') . '/flickr.inc');
+
/**
* Implements hook_help().
*/
@@ -691,7 +693,7 @@ function flickr_block_view($delta = '') {
'!username' => $people['name'],
'!map' => $map,
));
- $block['content'] = _flickr_block_photoset_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
+ $block['content'] = _flickr_photoset_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
break;
// Recent photos from a Flickr photoset.
@@ -717,7 +719,7 @@ function flickr_block_view($delta = '') {
'!username' => $people['name'],
'!map' => $map,
));
- $block['content'] = _flickr_block_photoset_recent($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
+ $block['content'] = _flickr_photoset_recent($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
break;
// Recent favorite public photos from a Flickr user.
@@ -992,86 +994,6 @@ function _flickr_block_random($nsid, $show_n, $size, $media, $delta, $people = N
}
/**
- * Random from photoset block. Block delta: 7.
- */
-function _flickr_block_photoset_random($nsid, $show_n, $size, $media, $photoset_id, $delta) {
- if ($cache = cache_get('flickr_block_' . $delta . '_' . $photoset_id)) {
- $output = $cache->data;
- }
- else {
- switch ($size) {
- case "x";
- $output = theme('flickr_flickrcomslideshow', array(
- 'id' => $photoset_id,
- ));
- drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order."), 'warning');
- break;
-
- case "y";
- $output = theme('flickr_flickrcomslideshow_simple', array(
- 'id' => $photoset_id,
- ));
- drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order."), 'warning');
- break;
-
- default:
- $output = '';
- // Get information about the photoset, including the owner.
- $info = flickr_photoset_get_info($photoset_id);
- if (!$info) {
- return;
- }
-
- // Get a list of "all" the photos in the photoset. This is cached.
- $response = flickr_photosets_getphotos($photoset_id, array(
- 'per_page' => $show_n,
- 'extras' => 'owner',
- 'media' => $media,
- ));
- if (!$response) {
- return;
- }
-
- // Randomly display $show_n of them.
- $photos = $response['photoset']['photo'];
- shuffle($photos);
- // We shouldn't try to return more than the total number of photos.
- $to = min($show_n, count($photos));
- for ($i = 0; $i < $to; $i++) {
- // Insert owner into $photo because theme_flickr_photo needs it.
- $photos[$i]['owner'] = $info['owner'];
- $output .= theme('flickr_block_photo', array(
- 'photo' => $photos[$i],
- 'size' => $size,
- ));
- }
- if ($i == 0) {
- $output .= t('No media found in the set posted on Flickr.');
- continue;
- }
- else {
- // A counter if set to show.
- $flickr = l(t("set on Flickr"), 'https://www.flickr.com/photos/' . $nsid . '/sets/' . $photoset_id, array(
- 'attributes' => array(
- 'title' => t('View set on Flickr.'),
- 'target' => '_blank',
- ),
- 'html' => TRUE,
- ));
- $count = t('@number out of @total in !flickr', array(
- '@number' => $i,
- '@total' => number_format($response['photoset']['total'], 0, ",", "."),
- '!flickr' => $flickr,
- ));
- $output .= variable_get('flickr_block_counter', 1) ? '
' . $count . '
' : '';
- }
- }
- cache_set('flickr_block_' . $delta . '_' . $photoset_id, $output, 'cache', time() + (variable_get('flickr_block_refresh_random', 21) * 60 * 60));
- }
- return $output;
-}
-
-/**
* Random from group block. Block delta: 10.
*/
function _flickr_block_group_random($group_id, $show_n, $size, $media, $delta, $total = NULL) {
@@ -1218,75 +1140,6 @@ function _flickr_block_tag_random($nsid, $show_n, $size, $media, $tag, $delta, $
}
/**
- * Recent from photoset block. Block delta: 8.
- */
-function _flickr_block_photoset_recent($nsid, $show_n, $size, $media, $photoset_id, $delta) {
- if ($cache = cache_get('flickr_block_' . $delta . '_' . $photoset_id)) {
- $output = $cache->data;
- }
- else {
- switch ($size) {
- case "x";
- $output = theme('flickr_flickrcomslideshow', array(
- 'id' => $photoset_id,
- ));
- break;
-
- case "y";
- $output = theme('flickr_flickrcomslideshow_simple', array(
- 'id' => $photoset_id,
- ));
- break;
-
- default:
- $output = '';
- $response = flickr_photosets_getphotos($photoset_id, array(
- 'per_page' => $show_n,
- 'media' => $media,
- ));
-
- if (!$response) {
- return;
- }
- // Only show the counter if the number of items is inferior to the total
- // available on Flickr.
- $i = 0;
- foreach ($response['photoset']['photo'] as $photo) {
- // Insert owner into $photo because theme_flickr_photo needs it.
- $photo['owner'] = $response['photoset']['owner'];
- $output .= theme('flickr_block_photo', array(
- 'photo' => $photo,
- 'size' => $size,
- ));
- $i++;
- }
- if ($i == 0) {
- $output .= t('No media found in the set posted on Flickr.');
- continue;
- }
- else {
- // A counter if set to show.
- $flickr = l(t("set on Flickr"), 'https://www.flickr.com/photos/' . $nsid . '/sets/' . $photoset_id, array(
- 'attributes' => array(
- 'title' => t('View set on Flickr.'),
- 'target' => '_blank',
- ),
- 'html' => TRUE,
- ));
- $count = t('@number out of @total in !flickr', array(
- '@number' => $i,
- '@total' => number_format($response['photoset']['total'], 0, ",", "."),
- '!flickr' => $flickr,
- ));
- $output .= variable_get('flickr_block_counter', 1) ? '' . $count . '
' : '';
- }
- }
- cache_set('flickr_block_' . $delta . '_' . $photoset_id, $output, 'cache', time() + (variable_get('flickr_block_refresh_others', 28) * 60 * 60));
- }
- return $output;
-}
-
-/**
* Favorites block. Block delta: 9.
*/
function _flickr_block_favorite_public($nsid, $show_n, $size, $media, $delta) {
diff --git a/filter/flickr_filter.module b/filter/flickr_filter.module
index ef5649b..509cd4b 100644
--- a/filter/flickr_filter.module
+++ b/filter/flickr_filter.module
@@ -23,7 +23,7 @@ function flickr_filter_help($path, $arg) {
function flickr_filter_info() {
$filters['flickr_filter'] = array(
'title' => t('Flickr linker'),
- 'description' => t('Allows you to Insert Flickr images: [flickr-photo:id=7357144724,size=m], [flickr-photoset:id=72157594262419167,size=s], [flickr-group:id=91484156@N00] or [flickr-user:id=98518260@N02, size=y].'),
+ 'description' => t('Allows you to Insert Flickr images: [flickr-photo:id=7357144724,size=m], [flickr-photoset:id=72157634563269642,size=s,num=8,media=all,random=true], [flickr-group:id=91484156@N00] or [flickr-user:id=98518260@N02, size=y].'),
'process callback' => 'flickr_filter',
'tips callback' => 'flickr_filter_tips',
'weight' => 9,
@@ -42,7 +42,7 @@ function flickr_filter_tips($filter, $format, $long = FALSE) {
),
));
- $output = t("Insert Flickr images: [flickr-photo:id=7357144724,size=m], [flickr-photoset:id=72157594262419167,size=s], [flickr-group:id=91484156@N00] or [flickr-user:id=98518260@N02, size=y].
!find_id If you ommit the size parameter 'size=@default_size' will be used.
Float photos:
Use [flickr-photo:id=9247386562, class=floatright], [flickr-photo:id=9247388074, size=m, style=float:left;] or use the AutoFloat module.
Common sizes:
s : small square 75
t : thumbnail, 100 on longest side
q : big square 150
m : small, 240 on longest side
n : small, 320 on longest side
- : medium, 500 on longest side
x: Flash responsive slideshow (for group, set and user IDs only)
y: Basic responsive slideshow (for set and user IDs only)
If the wrong size is applied, check if it exists on the Flickr photo page > Actions > View all sizes.", array('!find_id' => $idgettr, '@default_size' => variable_get('flickr_default_size', 'm')));
+ $output = t("Insert Flickr images: [flickr-photo:id=7357144724,size=m], [flickr-photoset:id=72157634563269642,size=s,num=8,media=all,random=true], [flickr-group:id=91484156@N00] or [flickr-user:id=98518260@N02, size=y].
!find_id If you ommit parameters the following values will be used: 'size=@default_size' (set in config). Only for sets: 'num=@default_number' (set in config), 'media=photos', 'random=false'.
Float photos:
Use [flickr-photo:id=9247386562, class=floatright], [flickr-photo:id=9247388074, size=m, style=float:left;] or use the AutoFloat module.
Common sizes:
s : small square 75
t : thumbnail, 100 on longest side
q : big square 150
m : small, 240 on longest side
n : small, 320 on longest side
- : medium, 500 on longest side
x: Flash responsive slideshow (for group, set and user IDs only)
y: Basic responsive slideshow (for set and user IDs only)
If the wrong size is applied, check if it exists on the Flickr photo page > Actions > View all sizes.", array('!find_id' => $idgettr, '@default_size' => variable_get('flickr_default_size', 'm'), '@default_number' => variable_get('flickr_photos_per_page', 20)));
if ($long) {
$output .= ' ' . t('The size parameter can be one of the following:');
$items = array();
@@ -67,13 +67,15 @@ function flickr_filter($text, $filter) {
/**
* Parse parameters to the fiter from a format like:
- * id=26159919@N00, size=m,show = 9, class=something,style=float:left;border:1px
+ * id=26159919@N00, size=m,num = 9, class=something,style=float:left;border:1px
* into an associative array with two sub-arrays. The first sub-array are
* parameters for the request, the second are HTML attributes (class and style).
*/
function flickr_filter_split_config($string) {
$config = array();
$attribs = array();
+ // Remove whitespace.
+ $string = preg_replace('/\s+/', '', $string);
// Put each setting on its own line.
$string = str_replace(',', "\n", $string);
// Break them up around commas.
@@ -130,24 +132,22 @@ function flickr_filter_callback_photoset($matches) {
if (!isset($config['size'])) {
$config['size'] = variable_get('flickr_default_size', 'm');
}
- switch ($config['size']) {
- case "x":
- return theme('flickr_flickrcomslideshow', array('id' => $photoset['id']));
-
- case "y":
- return theme('flickr_flickrcomslideshow_simple', array('id' => $photoset['id']));
-
- default:
- return theme('flickr_photoset', array(
- 'photoset' => $photoset,
- 'owner' => $photoset['owner'],
- 'size' => $config['size'],
- 'attribs' => $attribs,
- ));
+ if (!isset($config['num'])) {
+ $config['num'] = variable_get('flickr_photos_per_page', 20);
+ }
+ if (!isset($config['media'])) {
+ $config['media'] = 'photos';
}
+ if (!isset($config['random'])) {
+ $config['random'] = 'false';
+ }
+ $output = "\n";
+ $output .= ($config['random'] == 'false') ? _flickr_photoset_recent($photoset['owner'], $config['num'], $config['size'], $config['media'], $photoset['id']) : _flickr_photoset_random($photoset['owner'], $config['num'], $config['size'], $config['media'], $photoset['id']);
+ $output .= '
';
+ return $output;
}
}
- return '';
+ return '';
}
/**
diff --git a/flickr.inc b/flickr.inc
index 0e011f9..c031552 100644
--- a/flickr.inc
+++ b/flickr.inc
@@ -449,3 +449,158 @@ function flickr_get_user_info($nsid) {
$people['count'] = $info['photos']['count']['_content'];
return $people;
}
+
+/**
+ * Random from photoset. Used by block 7 and random Filter photoset-id.
+ */
+function _flickr_photoset_random($nsid, $show_n, $size, $media, $photoset_id, $delta = NULL) {
+ if ($cache = cache_get('flickr_block_' . $delta . '_' . $photoset_id) && !is_null($delta)) {
+ $output = $cache->data;
+ }
+ else {
+ switch ($size) {
+ case "x";
+ $output = theme('flickr_flickrcomslideshow', array(
+ 'id' => $photoset_id,
+ ));
+ drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order and ignore number and media settings."), 'warning');
+ break;
+
+ case "y";
+ $output = theme('flickr_flickrcomslideshow_simple', array(
+ 'id' => $photoset_id,
+ ));
+ drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order and ignore number and media settings."), 'warning');
+ break;
+
+ default:
+ $output = '';
+ // Get information about the photoset, including the owner.
+ $info = flickr_photoset_get_info($photoset_id);
+ if (!$info) {
+ return;
+ }
+
+ // Get a list of "all" the photos in the photoset. This is cached.
+ $response = flickr_photosets_getphotos($photoset_id, array(
+ 'per_page' => 500,
+ 'extras' => 'owner',
+ 'media' => $media,
+ ));
+ if (!$response) {
+ return;
+ }
+
+ // Randomly display $show_n of them.
+ $photos = $response['photoset']['photo'];
+ shuffle($photos);
+ // We shouldn't try to return more than the total number of photos.
+ $to = min($show_n, count($photos));
+ for ($i = 0; $i < $to; $i++) {
+ // Insert owner into $photo because theme_flickr_photo needs it.
+ $photos[$i]['owner'] = $info['owner'];
+ $output .= theme('flickr_block_photo', array(
+ 'photo' => $photos[$i],
+ 'size' => $size,
+ ));
+ }
+ if ($i == 0) {
+ $output .= t('No media found in the set posted on Flickr.');
+ continue;
+ }
+ else {
+ // A counter if set to show.
+ $flickr = l(t("set on Flickr"), 'https://www.flickr.com/photos/' . $nsid . '/sets/' . $photoset_id, array(
+ 'attributes' => array(
+ 'title' => t('View set on Flickr.'),
+ 'target' => '_blank',
+ ),
+ 'html' => TRUE,
+ ));
+ $count = t('@number out of @total in !flickr', array(
+ '@number' => $i,
+ '@total' => number_format($response['photoset']['total'], 0, ",", "."),
+ '!flickr' => $flickr,
+ ));
+ $output .= variable_get('flickr_block_counter', 1) ? '' . $count . '
' : '';
+ }
+ }
+ if (!is_null($delta)) {
+ cache_set('flickr_block_' . $delta . '_' . $photoset_id, $output, 'cache', time() + (variable_get('flickr_block_refresh_random', 21) * 60 * 60));
+ }
+ }
+ return $output;
+}
+
+/**
+ * Recent from photoset. Used by block 8 and not random Filter photoset-id.
+ */
+function _flickr_photoset_recent($nsid, $show_n, $size, $media, $photoset_id, $delta = NULL) {
+ if ($cache = cache_get('flickr_block_' . $delta . '_' . $photoset_id) && !is_null($delta)) {
+ $output = $cache->data;
+ }
+ else {
+ switch ($size) {
+ case "x";
+ $output = theme('flickr_flickrcomslideshow', array(
+ 'id' => $photoset_id,
+ ));
+ drupal_set_message(t("Note that slideshows ignore number and media settings."), 'warning');
+ break;
+
+ case "y";
+ $output = theme('flickr_flickrcomslideshow_simple', array(
+ 'id' => $photoset_id,
+ ));
+ drupal_set_message(t("Note that slideshows ignore number and media settings."), 'warning');
+ break;
+
+ default:
+ $output = '';
+ $response = flickr_photosets_getphotos($photoset_id, array(
+ 'per_page' => $show_n,
+ 'media' => $media,
+ ));
+
+ if (!$response) {
+ return;
+ }
+ // Only show the counter if the number of items is inferior to the total
+ // available on Flickr.
+ $i = 0;
+ foreach ($response['photoset']['photo'] as $photo) {
+ // Insert owner into $photo because theme_flickr_photo needs it.
+ $photo['owner'] = $response['photoset']['owner'];
+ $output .= theme('flickr_block_photo', array(
+ 'photo' => $photo,
+ 'size' => $size,
+ ));
+ $i++;
+ }
+ if ($i == 0) {
+ $output .= t('No media found in the set posted on Flickr.');
+ continue;
+ }
+ else {
+ // A counter if set to show.
+ $flickr = l(t("set on Flickr"), 'https://www.flickr.com/photos/' . $nsid . '/sets/' . $photoset_id, array(
+ 'attributes' => array(
+ 'title' => t('View set on Flickr.'),
+ 'target' => '_blank',
+ ),
+ 'html' => TRUE,
+ ));
+ $count = t('@number out of @total in !flickr', array(
+ '@number' => $i,
+ '@total' => number_format($response['photoset']['total'], 0, ",", "."),
+ '!flickr' => $flickr,
+ ));
+ $output .= variable_get('flickr_block_counter', 1) ? '' . $count . '
' : '';
+ }
+ }
+ if (!is_null($delta)) {
+ cache_set('flickr_block_' . $delta . '_' . $photoset_id, $output, 'cache', time() + (variable_get('flickr_block_refresh_others', 28) * 60 * 60));
+ }
+ }
+ return $output;
+}