Index: /trunk/include/functions_tag.inc.php
===================================================================
--- /trunk/include/functions_tag.inc.php	(revision 18454)
+++ /trunk/include/functions_tag.inc.php	(revision 18455)
@@ -65,10 +65,10 @@
   while ($row = pwg_db_fetch_assoc($result))
   {
-    $counter = @$tag_counters[ $row['id'] ];
+    $counter = intval(@$tag_counters[ $row['id'] ]);
     if ( $counter )
     {
       $row['counter'] = $counter;
       $row['name'] = trigger_event('render_tag_name', $row['name']);
-      array_push($tags, $row);
+      $tags[] = $row;
     }
   }
@@ -92,5 +92,5 @@
   {
     $row['name'] = trigger_event('render_tag_name', $row['name']);
-    array_push($tags, $row);
+    $tags[] = $row;
   }
 
@@ -139,18 +139,19 @@
 
   // display sorted tags
-  foreach (array_keys($tags) as $k)
-  {
-    $tags[$k]['level'] = 1;
+  foreach ($tags as &$tag)
+  {
+    $tag['level'] = 1;
 
     // based on threshold, determine current tag level
     for ($i = $conf['tags_levels'] - 1; $i >= 1; $i--)
     {
-      if ($tags[$k]['counter'] > $threshold_of_level[$i])
+      if ($tag['counter'] > $threshold_of_level[$i])
       {
-        $tags[$k]['level'] = $i + 1;
+        $tag['level'] = $i + 1;
         break;
       }
     }
   }
+  unset($tag);
 
   return $tags;
@@ -255,5 +256,5 @@
   {
     $row['name'] = trigger_event('render_tag_name', $row['name']);
-    array_push($tags, $row);
+    $tags[] = $row;
   }
   usort($tags, 'tag_alpha_compare');
Index: /trunk/tags.php
===================================================================
--- /trunk/tags.php	(revision 18454)
+++ /trunk/tags.php	(revision 18455)
@@ -160,41 +160,39 @@
   }
 }
-
-// +-----------------------------------------------------------------------+
-// |                        tag cloud construction                         |
-// +-----------------------------------------------------------------------+
-
-// we want only the first most represented tags, so we sort them by counter
-// and take the first tags
-usort($tags, 'counter_compare');
-$tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
-
-// depending on its counter and the other tags counter, each tag has a level
-$tags = add_level_to_tags($tags);
-
-// we want tags diplayed in alphabetic order
-if ('letters' != $page['display_mode'])
-{
+else
+{
+  // +-----------------------------------------------------------------------+
+  // |                        tag cloud construction                         |
+  // +-----------------------------------------------------------------------+
+
+  // we want only the first most represented tags, so we sort them by counter
+  // and take the first tags
+  usort($tags, 'counter_compare');
+  $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
+
+  // depending on its counter and the other tags counter, each tag has a level
+  $tags = add_level_to_tags($tags);
+
+  // we want tags diplayed in alphabetic order
   usort($tags, 'tag_alpha_compare');
-}
-
-// display sorted tags
-foreach ($tags as $tag)
-{
-  $template->append(
-    'tags',
-    array_merge(
-      $tag,
-      array(
-        'URL' => make_index_url(
-          array(
-            'tags' => array($tag),
-            )
-          ),
+
+  // display sorted tags
+  foreach ($tags as $tag)
+  {
+    $template->append(
+      'tags',
+      array_merge(
+        $tag,
+        array(
+          'URL' => make_index_url(
+            array(
+              'tags' => array($tag),
+              )
+            ),
+          )
         )
-      )
-    );
-}
-
+      );
+  }
+}
 // include menubar
 $themeconf = $template->get_template_vars('themeconf');
Index: /trunk/themes/default/template/tags.tpl
===================================================================
--- /trunk/themes/default/template/tags.tpl	(revision 18454)
+++ /trunk/themes/default/template/tags.tpl	(revision 18455)
@@ -20,38 +20,37 @@
 {include file='infos_errors.tpl'}
 
-{if isset($tags)}
-	{if $display_mode == 'cloud'}
-	<div id="fullTagCloud">
-		{foreach from=$tags item=tag}
-		<span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
+
+{if $display_mode == 'cloud' and isset($tags)}
+<div id="fullTagCloud">
+	{foreach from=$tags item=tag}
+	<span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
+	{/foreach}
+</div>
+{/if}
+
+{if $display_mode == 'letters' and isset($letters)}
+<table>
+	<tr>
+		<td valign="top">
+	{foreach from=$letters item=letter}
+<fieldset class="tagLetter">
+	<legend class="tagLetterLegend">{$letter.TITLE}</legend>
+	<table class="tagLetterContent">
+		{foreach from=$letter.tags item=tag}
+		<tr class="tagLine">
+			<td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
+			<td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
+		</tr>
 		{/foreach}
-	</div>
-	{/if}
-
-  {if $display_mode == 'letters'}
-  <table>
-    <tr>
-      <td valign="top">
-    {foreach from=$letters item=letter}
-  <fieldset class="tagLetter">
-    <legend class="tagLetterLegend">{$letter.TITLE}</legend>
-    <table class="tagLetterContent">
-      {foreach from=$letter.tags item=tag}
-      <tr class="tagLine">
-        <td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
-        <td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
-      </tr>
-      {/foreach}
-    </table>
-  </fieldset>
-      {if isset($letter.CHANGE_COLUMN) }
-      </td>
-      <td valign="top">
-      {/if}
-    {/foreach}
-      </td>
-    </tr>
-  </table>
-  {/if}
+	</table>
+</fieldset>
+		{if isset($letter.CHANGE_COLUMN) }
+		</td>
+		<td valign="top">
+		{/if}
+	{/foreach}
+		</td>
+	</tr>
+</table>
 {/if}
 
