diff --git a/block/flickr_block.module b/block/flickr_block.module
index fe4d3d7..3882733 100644
--- a/block/flickr_block.module
+++ b/block/flickr_block.module
@@ -22,7 +22,7 @@ function flickr_block_help($path, $arg) {
  */
 function flickr_block_info() {
   // User blocks.
-  $blocks[0]['info'] = t("User recent Flickr photos");
+  $blocks[0]['info'] = t("User recent Flickr photos by term from node");
   $blocks[1]['info'] = t("User recent Flickr photosets");
   $blocks[2]['info'] = t("User random Flickr photos by term from node");
 
@@ -178,12 +178,6 @@ function flickr_block_configure($delta = '') {
 
   // Build the block form - use unset to hide unwanted form elements.
   switch ($delta) {
-    // User recent Flickr photos.
-    case 0:
-      unset($form["flickr_block_{$delta}_user_id"]);
-      unset($form["flickr_block_{$delta}_group_id"]);
-      break;
-
     // User recent Flickr photosets.
     case 1:
       unset($form["flickr_block_{$delta}_user_id"]);
@@ -194,6 +188,7 @@ function flickr_block_configure($delta = '') {
       break;
 
     // User random Flickr photos.
+    case 0:
     case 2:
       unset($form["flickr_block_{$delta}_user_id"]);
       unset($form["flickr_block_{$delta}_group_id"]);
@@ -295,16 +290,6 @@ function flickr_shown_block_validate($element) {
  */
 function flickr_block_save($delta = '', $edit = array()) {
   switch ($delta) {
-    // User recent Flickr photos.
-    case 0:
-      variable_set('flickr_block_' . $delta, array(
-        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
-        'size' => $edit["flickr_block_{$delta}_size"],
-        'media' => $edit["flickr_block_{$delta}_media"],
-      ));
-      cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
-      break;
-
     // User recent Flickr photosets.
     case 1:
       variable_set('flickr_block_' . $delta, array(
@@ -315,7 +300,8 @@ function flickr_block_save($delta = '', $edit = array()) {
       cache_clear_all('flickr_block_' . $delta, 'cache', TRUE);
       break;
 
-    // User random Flickr photos.
+    // User Flickr photos.
+    case 0:
     case 2:
       if (module_exists('taxonomy')) {
         variable_set('flickr_block_' . $delta, array(
@@ -596,22 +582,6 @@ function flickr_block_view($delta = '') {
           ),
         )) . ')' : '';
         switch ($delta) {
-          // User recent Flickr photos.
-          case 0:
-            $recent_photos = l(t('Recent Flickr @media', array('@media' => $media)), $people['photosurl'], array(
-              'attributes' => array(
-                'title' => t('View on Flickr.'),
-                'target' => '_blank',
-              ),
-            ));
-            $block['subject'] = t("!recent_photos by !username !map", array(
-              '!recent_photos' => $recent_photos,
-              '!username' => $people['name'],
-              '!map' => $map,
-            ));
-            $block['content'] = _flickr_block_recent($user->flickr['nsid'], $settings['show_n'], $settings['size'], $settings['media'], $delta, $people);
-            break;
-
           // User recent Flickr photosets.
           case 1:
             $recent_sets = l(t('Recent Flickr sets'), $people['photosurl'] . 'sets/', array(
@@ -624,9 +594,11 @@ function flickr_block_view($delta = '') {
             $block['content'] = _flickr_block_photosets($user->flickr['nsid'], $settings['show_n'], $settings['size'], $settings['media'], $delta);
             break;
 
-          // User random Flickr photos.
+          // User Flickr photos.
+          case 0:
           case 2:
-            $photos = l(t('Flickr @media', array('@media' => $media)), $people['photosurl'], array(
+            $recent = $delta == 2 ? '' : 'Recent ';
+            $photos = l(t('@recentFlickr @media', array('@recent' => $recent, '@media' => $media)), $people['photosurl'], array(
               'attributes' => array(
                 'title' => t('View Flickr photostream.'),
                 'target' => '_blank',
@@ -647,7 +619,8 @@ function flickr_block_view($delta = '') {
               '!username' => $people['name'],
               '!map' => $map,
             ));
-            $block['content'] = _flickr_block_tag_random($user->flickr['nsid'], $settings['show_n'], $settings['size'], $settings['media'], $tags, $delta, $people);
+            $random = $delta == 2 ? 1 : 0;
+            $block['content'] = _flickr_user($user->flickr['nsid'], $settings['show_n'], $settings['size'], $settings['media'], $tags, $delta, $people, $random);
             break;
 
         }
@@ -675,7 +648,7 @@ function flickr_block_view($delta = '') {
         '!username' => $people['name'],
         '!map' => $map,
       ));
-      $block['content'] = _flickr_block_recent($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $delta, $people);
+      $block['content'] = _flickr_user($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], '', $delta, $people);
       break;
 
     // Recent photosets from a Flickr user.
@@ -713,7 +686,7 @@ function flickr_block_view($delta = '') {
         '!username' => $people['name'],
         '!map' => $map,
       ));
-      $block['content'] = _flickr_block_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $delta, $people);
+      $block['content'] = _flickr_user($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], '', $delta, $people, 1);
       break;
 
     // Recent photos from a Flickr group.
@@ -763,7 +736,7 @@ function flickr_block_view($delta = '') {
         '!username' => $people['name'],
         '!map' => $map,
       ));
-      $block['content'] = _flickr_photoset_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
+      $block['content'] = _flickr_photoset($info['owner'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta, 1);
       break;
 
     // Recent photos from a Flickr photoset.
@@ -789,7 +762,7 @@ function flickr_block_view($delta = '') {
         '!username' => $people['name'],
         '!map' => $map,
       ));
-      $block['content'] = _flickr_photoset_recent($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
+      $block['content'] = _flickr_photoset($info['owner'], $settings['show_n'], $settings['size'], $settings['media'], $settings['photoset_id'], $delta);
       break;
 
     // Recent favorite public photos from a Flickr user.
@@ -853,68 +826,13 @@ function flickr_block_view($delta = '') {
         '!tagged' => $tagged,
         '!map' => $map,
       ));
-      $block['content'] = _flickr_block_tag_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['tag'], $delta, $people);
+      $block['content'] = _flickr_user($settings['user_id'], $settings['show_n'], $settings['size'], $settings['media'], $settings['tag'], $delta, $people, 1);
       break;
   }
   return $block;
 }
 
 /**
- * Recent block. Block delta: 0 and 3.
- */
-function _flickr_block_recent($nsid, $show_n, $size, $media, $delta, $people = NULL) {
-  if ($cache = cache_get('flickr_block_' . $delta . '_' . $nsid)) {
-    $output = $cache->data;
-  }
-  else {
-    switch ($size) {
-      case "x":
-        $output = theme('flickr_flickrcomslideshow', array(
-          'id' => $nsid,
-        ));
-        break;
-
-      case "y":
-        $output = theme('flickr_flickrcomslideshow_simple', array(
-          'id' => $nsid,
-        ));
-        break;
-
-      default:
-        $output = '';
-        if ($photos = flickr_photos_search($nsid, 1, array(
-          'per_page' => $show_n,
-          'media' => $media,
-        ))) {
-          $i = 0;
-          foreach ($photos['photo'] as $photo) {
-            $output .= theme('flickr_block_photo', array(
-              'photo' => $photo,
-              'size' => $size,
-            ));
-            $i++;
-          }
-          if ($i == 0) {
-            $output .= t('No media found !flickr.', array('!flickr' => $people['photostream']));
-            continue;
-          }
-          else {
-            // A counter if set to show.
-            $count = t('@number out of @total by !flickr', array(
-              '@number' => $i,
-              '@total' => number_format($people['count'], 0, ",", "."),
-              '!flickr' => $people['photostream'],
-            ));
-            $output .= variable_get('flickr_block_counter', 1) ? '<div class="flickr-counter">' . $count . '</div>' : '';
-          }
-        }
-    }
-    cache_set('flickr_block_' . $delta . '_' . $nsid, $output, 'cache', time() + (variable_get('flickr_block_refresh_others', 31) * 60 * 60));
-  }
-  return $output;
-}
-
-/**
  * Photoset block. Block delta: 1 and 4.
  */
 function _flickr_block_photosets($nsid, $show_n, $size, $media, $delta, $people = NULL) {
@@ -991,81 +909,6 @@ function _flickr_block_photosets($nsid, $show_n, $size, $media, $delta, $people
 }
 
 /**
- * Random from user block. Block delta: 5.
- */
-function _flickr_block_random($nsid, $show_n, $size, $media, $delta, $people = NULL) {
-  if ($cache = cache_get('flickr_block_' . $delta . '_' . $nsid)) {
-    $output = $cache->data;
-  }
-  else {
-    switch ($size) {
-      case "x":
-        $output = theme('flickr_flickrcomslideshow', array(
-          'id' => $nsid,
-        ));
-        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' => $nsid,
-        ));
-        drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order."), 'warning');
-        break;
-
-      default:
-        $output = '';
-        $random_photos = array();
-        if ($photos = flickr_photos_search($nsid, 1, array(
-          'per_page' => 500,
-          'media' => $media,
-        ))) {
-          $page_count = $photos['pages'];
-          // Do not try to return more than the total number of photos.
-          $to = min($show_n, $photos['total']);
-          for ($i = 0; $i < $to; $i++) {
-            sleep(0.125);
-            // Request a random page.
-            $photos = flickr_photos_search($nsid, rand(1, $page_count), array(
-              'per_page' => 500,
-              'media' => $media,
-            ));
-            // Select a random photo.
-            $index = rand(0, count($photos['photo']) - 1);
-            $photo_id = $photos['photo'][$index]['id'];
-            if (in_array($photo_id, $random_photos)) {
-              // Photo already added.
-              $i--;
-            }
-            else {
-              $random_photos[] = $photo_id;
-              $output .= theme('flickr_block_photo', array(
-                'photo' => $photos['photo'][$index],
-                'size' => $size,
-              ));
-            }
-          }
-          if ($i == 0) {
-            $output .= t('No media found !flickr.', array('!flickr' => $people['photostream']));
-            continue;
-          }
-          else {
-            // A counter if set to show.
-            $count = t('@number out of @total by !flickr', array(
-              '@number' => $i,
-              '@total' => number_format($people['count'], 0, ",", "."),
-              '!flickr' => $people['photostream'],
-            ));
-            $output .= variable_get('flickr_block_counter', 1) ? '<div class="flickr-counter">' . $count . '</div>' : '';
-          }
-        }
-    }
-    cache_set('flickr_block_' . $delta . '_' . $nsid, $output, 'cache', time() + (variable_get('flickr_block_refresh_random', 23) * 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) {
@@ -1143,99 +986,6 @@ function _flickr_block_group_random($group_id, $show_n, $size, $media, $delta, $
 }
 
 /**
- * Random by tag block. Block delta:2 and 11.
- */
-function _flickr_block_tag_random($nsid, $show_n, $size, $media, $tags, $delta, $people = NULL) {
-  if ($cache = cache_get('flickr_block_' . $delta . '_' . $nsid . '_' . $tags)) {
-    $output = $cache->data;
-  }
-  else {
-    switch ($size) {
-      case "x":
-        $output = t('You cannot choose a slideshow for this block. Select a size.');
-        drupal_set_message(t('You cannot choose a slideshow for this block.'), 'error');
-        break;
-
-      case "y":
-        $output = t('You cannot choose a slideshow for this block. Select a size.');
-        drupal_set_message(t('You cannot choose a slideshow for this block.'), 'error');
-        break;
-
-      default:
-        $output = '';
-        if ($photos = flickr_photos_search($nsid, 1, array(
-          'per_page' => 500,
-          'extras' => 'tags',
-          'media' => $media,
-        ))) {
-          $i = 0;
-          $j = 0;
-          $response = $photos['photo'];
-          shuffle($response);
-          $terms = is_array($tags) ? $tags : explode(",", $tags);
-          if (empty($tags)) {
-            foreach ($response as $photo) {
-              if ($i < $show_n) {
-                $output .= theme('flickr_block_photo', array(
-                  'photo' => $photo,
-                  'size' => $size,
-                ));
-                $i++;
-                $j++;
-              }
-            }
-          }
-          else {
-            foreach ($terms as $term) {
-              foreach ($response as $key => $photo) {
-                if ($i >= $show_n && stripos($photo['tags'], $term) !== FALSE) {
-                  $j++;
-                }
-                elseif (stripos($photo['tags'], $term) !== FALSE) {
-                  $output .= theme('flickr_block_photo', array(
-                    'photo' => $photo,
-                    'size' => $size,
-                  ));
-                  // Avoid this image gets repeated by removing it from the
-                  // array.
-                  unset($response[$key]);
-                  $i++;
-                  $j++;
-                }
-              }
-            }
-          }
-          // A counter if set to show.
-          // The used tags with a space forced after the comma and the last
-          // one replaced by 'or'. In the link all whitespace is removed.
-          $flickr = (!empty($tags)) ? l(t("tagged <em>@tag</em>", array(
-            '@tag' => preg_replace('/(.*),/', '$1 ' . t('or'), preg_replace("/,([^\s])/", ", $1", $tags)))), $people['photosurl'] . '/tags/' . $tags, array(
-              'attributes' => array(
-                'title' => t('View tagged photos on Flickr.'),
-                'target' => '_blank',
-              ),
-              'html' => TRUE,
-            )) : '';
-          $total = (empty($tags)) ? (int) $people['count'] : $j;
-          $count = t('@number out of @total !flickr by !user', array(
-            '@number' => $i,
-            '@total' => number_format($total, 0, ",", "."),
-            '!flickr' => $flickr,
-            '!user' => $people['photostream'],
-          ));
-          $output .= variable_get('flickr_block_counter', 1) ? '<div class="flickr-counter">' . $count . '</div>' : '';
-        }
-        if ($i == 0) {
-          $output .= t('No media found in the last 500 posted on Flickr.');
-          continue;
-        }
-    }
-    cache_set('flickr_block_' . $delta . '_' . $nsid . '_' . $tags, $output, 'cache', time() + (variable_get('flickr_block_refresh_random', 23) * 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 a78ef00..8f0e0a6 100644
--- a/filter/flickr_filter.module
+++ b/filter/flickr_filter.module
@@ -47,7 +47,7 @@ function flickr_filter_tips($filter, $format, $long = FALSE) {
     ),
   ));
   $count = variable_get('flickr_block_counter', 1) ? 'true' : 'false';
-  $output = t("Insert Flickr images: [flickr-photo:id=7357144724,size=m], [flickr-photoset:id=72157634563269642,size=s,num=8,media=all,random=true,count=false], [flickr-group:id=91484156@N00] or [flickr-user:id=98518260@N02, size=y].<br />!find_id If you ommit parameters the following values will be used: <em>size=@default_size</em> (!config). Only for sets: <em>num=@default_number</em> (!config), <em>media=photos</em>, <em>random=false</em>, <em>count=@default_count</em> (!config).<br />Float photos:<br />Use [flickr-photo:id=9247386562, class=floatright], [flickr-photo:id=9247388074, size=m, style=float:left;] or use the <a href='https://drupal.org/project/autofloat'>AutoFloat module</a>.<br />Common sizes:<br /> s : small square 75<br /> t : thumbnail, 100 on longest side<br /> q : big square 150<br /> m : small, 240 on longest side<br /> n : small, 320 on longest side<br /> - : medium, 500 on longest side<br /> x: Flash responsive slideshow (for group, set and user IDs only)<br /> y: Basic responsive slideshow (for set and user IDs only)<br /> 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), '@default_count' => $count, '!config' => $config));
+  $output = t("Insert Flickr images: [flickr-photo:id=7357144724, size=m], [flickr-photoset:id=72157634563269642, size=s, num=8, media=all, random=true, count=false], [flickr-group:id=91484156@N00] or [flickr-user:id=98518260@N02, size=q, num=8, tags=kids-men, media=all, random=true, count=false].<br />!find_id If you ommit parameters the following values will be used: <em>size=@default_size</em> (!config). Only for sets: <em>num=@default_number</em> (!config), <em>media=photos</em>, <em>random=false</em>, <em>count=@default_count</em> (!config).<br />Float photos:<br />Use [flickr-photo:id=9247386562, class=floatright], [flickr-photo:id=9247388074, size=m, style=float:left;] or use the <a href='https://drupal.org/project/autofloat'>AutoFloat module</a>.<br />Common sizes:<br /> s : small square 75<br /> t : thumbnail, 100 on longest side<br /> q : big square 150<br /> m : small, 240 on longest side<br /> n : small, 320 on longest side<br /> - : medium, 500 on longest side<br /> x: Flash responsive slideshow (for group, set and user IDs only)<br /> y: Basic responsive slideshow (for set and user IDs only)<br /> 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), '@default_count' => $count, '!config' => $config));
   if ($long) {
     $output .= ' ' . t('The size parameter can be one of the following:');
     $items = array();
@@ -72,7 +72,7 @@ function flickr_filter($text, $filter) {
 
 /**
  * Parse parameters to the fiter from a format like:
- * id=26159919@N00, size=m,num = 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).
  */
@@ -149,10 +149,11 @@ function flickr_filter_callback_photoset($matches) {
       if (!isset($config['count'])) {
         $config['count'] = variable_get('flickr_block_counter', 1) ? 'true' : 'false';
       }
+      settype($config['random'], "boolean");
       $output = "<div class='flickr-photoset'>\n";
       // Choose between 'recent' or 'random' based on 'random' parameter.
       // We abuse $delta parameter to override preference of counter display.
-      $output .=  ($config['random'] == 'false') ? _flickr_photoset_recent($photoset['owner'], $config['num'], $config['size'], $config['media'], $photoset['id'], $config['count']) : _flickr_photoset_random($photoset['owner'], $config['num'], $config['size'], $config['media'], $photoset['id'], $config['count']);
+      $output .= _flickr_photoset($photoset['owner'], $config['num'], $config['size'], $config['media'], $photoset['id'], $config['count'], $config['random']);
       $output .= '</div>';
       return $output;
     }
@@ -186,21 +187,35 @@ function flickr_filter_callback_user($matches) {
   list($config, $attribs) = flickr_filter_split_config($matches[1]);
 
   if (isset($config['id'])) {
-    if ($photoset = flickr_people_getpublicphotos($config['id'])) {
+    if ($people = flickr_get_user_info($config['id'])) {
       if (!isset($config['size'])) {
-        $config['size'] = 'x';
+        $config['size'] = variable_get('flickr_default_size', 'm');
       }
-      switch ($config['size']) {
-        case "x":
-          return theme('flickr_flickrcomslideshow', array('id' => $config['id']));
-
-        case "y":
-          return theme('flickr_flickrcomslideshow_simple', array('id' => $config['id']));
-
-        default:
-          drupal_set_message(t("You can only use a slideshow for a user's photostream (size = x or y)."), 'error');
-          return theme('flickr_flickrcomslideshow', array('id' => $config['id']));
+      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';
+      }
+      if (!isset($config['tags'])) {
+        $config['tags'] = '';
+      }
+      else {
+        $config['tags'] = str_replace("-" ,"," , $config['tags']);
+      }
+      if (!isset($config['count'])) {
+        $config['count'] = variable_get('flickr_block_counter', 1) ? 'true' : 'false';
+      }
+      settype($config['random'], "boolean");
+      $output = "<div class='flickr-photoset'>\n";
+      // Choose between 'recent' or 'random' based on 'random' parameter.
+      // We abuse $delta parameter to override preference of counter display.
+      $output .=  _flickr_user($config['id'], $config['num'], $config['size'], $config['media'], $config['tags'], $config['count'], $people, $config['random']);
+      $output .= '</div>';
+      return $output;
     }
   }
   return '';
diff --git a/flickr.inc b/flickr.inc
index 6ac032c..999102b 100644
--- a/flickr.inc
+++ b/flickr.inc
@@ -451,9 +451,9 @@ function flickr_get_user_info($nsid) {
 }
 
 /**
- * Random from photoset. Used by block 7 and random Filter photoset-id.
+ * Media from photoset. Used by blocks 7, 8 and text filter photoset-id.
  */
-function _flickr_photoset_random($nsid, $show_n, $size, $media, $photoset_id, $delta = NULL) {
+function _flickr_photoset($nsid, $show_n, $size, $media, $photoset_id, $delta = NULL, $random = 0) {
   $cache = cache_get('flickr_block_' . $delta . '_' . $photoset_id);
   // If $delta is a number it is a block that could be cached.
   if ($cache && is_numeric($delta)) {
@@ -495,7 +495,9 @@ function _flickr_photoset_random($nsid, $show_n, $size, $media, $photoset_id, $d
 
         // Randomly display $show_n of them.
         $photos = $response['photoset']['photo'];
-        shuffle($photos);
+        if ($random == 1) {
+          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++) {
@@ -528,7 +530,7 @@ function _flickr_photoset_random($nsid, $show_n, $size, $media, $photoset_id, $d
           $output .= ((variable_get('flickr_block_counter', 1) && $delta != 'false') || $delta == 'true') ? '<div class="flickr-counter">' . $count . '</div>' : '';
         }
     }
-    if (!is_null($delta)) {
+    if (is_numeric($delta)) {
       cache_set('flickr_block_' . $delta . '_' . $photoset_id, $output, 'cache', time() + (variable_get('flickr_block_refresh_random', 23) * 60 * 60));
     }
   }
@@ -536,10 +538,10 @@ function _flickr_photoset_random($nsid, $show_n, $size, $media, $photoset_id, $d
 }
 
 /**
- * Recent from photoset. Used by block 8 and not random Filter photoset-id.
+ * User media by tags. Used by blocks 2, 5, 11 and text filter user-id.
  */
-function _flickr_photoset_recent($nsid, $show_n, $size, $media, $photoset_id, $delta = NULL) {
-  $cache = cache_get('flickr_block_' . $delta . '_' . $photoset_id);
+function _flickr_user($nsid, $show_n, $size, $media, $tags, $delta, $people = NULL, $random = 0) {
+  $cache = cache_get('flickr_block_' . $delta . '_' . $nsid . '_' . $tags . '_' . $random);
   // If $delta is a number it is a block that could be cached.
   if ($cache && is_numeric($delta)) {
     $output = $cache->data;
@@ -548,64 +550,91 @@ function _flickr_photoset_recent($nsid, $show_n, $size, $media, $photoset_id, $d
     switch ($size) {
       case "x";
         $output = theme('flickr_flickrcomslideshow', array(
-          'id' => $photoset_id,
+          'id' => $nsid,
         ));
-        drupal_set_message(t("Note that slideshows ignore number and media settings."), 'warning');
+        drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order and ignore number, tags and media settings."), 'warning');
         break;
 
       case "y";
         $output = theme('flickr_flickrcomslideshow_simple', array(
-          'id' => $photoset_id,
+          'id' => $nsid,
         ));
-        drupal_set_message(t("Note that slideshows ignore number and media settings."), 'warning');
+        drupal_set_message(t("Note that slideshows don't show in random but in reverse chronological order and ignore number, tags 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 {
+        if ($photos = flickr_photos_search($nsid, 1, array(
+          'per_page' => 500,
+          'extras' => 'tags',
+          'media' => $media,
+        ))) {
+          $i = 0;
+          $j = 0;
+          $response = $photos['photo'];
+          if ($random == 1) {
+            shuffle($response);
+          }
+          $terms = is_array($tags) ? $tags : explode(",", $tags);
+          if (empty($tags)) {
+            foreach ($response as $photo) {
+              if ($i < $show_n) {
+                $output .= theme('flickr_block_photo', array(
+                  'photo' => $photo,
+                  'size' => $size,
+                ));
+                $i++;
+                $j++;
+              }
+            }
+          }
+          else {
+            foreach ($terms as $term) {
+              foreach ($response as $key => $photo) {
+                if ($i >= $show_n && stripos($photo['tags'], $term) !== FALSE) {
+                  $j++;
+                }
+                elseif (stripos($photo['tags'], $term) !== FALSE) {
+                  $output .= theme('flickr_block_photo', array(
+                    'photo' => $photo,
+                    'size' => $size,
+                  ));
+                  // Avoid this image gets repeated by removing it from the
+                  // array.
+                  unset($response[$key]);
+                  $i++;
+                  $j++;
+                }
+              }
+            }
+          }
           // 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(
+          // The used tags with a space forced after the comma and the last
+          // one replaced by 'or'. In the link all whitespace is removed.
+          $flickr = (!empty($tags)) ? l(t("tagged <em>@tag</em>", array(
+            '@tag' => preg_replace('/(.*),/', '$1 ' . t('or'), preg_replace("/,([^\s])/", ", $1", $tags)))), $people['photosurl'] . '/tags/' . $tags, array(
+              'attributes' => array(
+                'title' => t('View tagged photos on Flickr.'),
+                'target' => '_blank',
+              ),
+              'html' => TRUE,
+            )) : '';
+          $total = (empty($tags)) ? (int) $people['count'] : $j;
+          $count = t('@number out of @total !flickr by !user', array(
             '@number' => $i,
-            '@total' => number_format($response['photoset']['total'], 0, ",", "."),
+            '@total' => number_format($total, 0, ",", "."),
             '!flickr' => $flickr,
+            '!user' => $people['photostream'],
           ));
-          // If $delta is non numeric allow counter override from filter module.
           $output .= ((variable_get('flickr_block_counter', 1) && $delta != 'false') || $delta == 'true') ? '<div class="flickr-counter">' . $count . '</div>' : '';
         }
+        if ($i == 0) {
+          $output .= t('No media found in the last 500 posted on Flickr.');
+          continue;
+        }
     }
-    if (!is_null($delta)) {
-      cache_set('flickr_block_' . $delta . '_' . $photoset_id, $output, 'cache', time() + (variable_get('flickr_block_refresh_others', 31) * 60 * 60));
+    if (is_numeric($delta)) {
+      cache_set('flickr_block_' . $delta . '_' . $nsid . '_' . $tags . '_' . $random, $output, 'cache', time() + (variable_get('flickr_block_refresh_random', 23) * 60 * 60));
     }
   }
   return $output;
