Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 21816)
+++ /trunk/admin/include/functions.php	(revision 21817)
@@ -1368,4 +1368,5 @@
     $inserts
     );
+  invalidate_user_cache_nb_tags();
 }
 
@@ -1398,4 +1399,6 @@
 ;';
   pwg_query($query);
+
+  invalidate_user_cache_nb_tags();
 }
 
@@ -1487,4 +1490,6 @@
         );
     }
+
+    invalidate_user_cache_nb_tags();
   }
 }
@@ -1693,4 +1698,15 @@
   }
   trigger_action('invalidate_user_cache', $full);
+}
+
+
+function invalidate_user_cache_nb_tags()
+{
+  global $user;
+  unset($user['nb_available_tags']);
+  $query = '
+UPDATE '.USER_CACHE_TABLE.'
+  SET nb_available_tags = NULL';
+  pwg_query($query);
 }
 
Index: /trunk/include/functions.inc.php
===================================================================
--- /trunk/include/functions.inc.php	(revision 21816)
+++ /trunk/include/functions.inc.php	(revision 21817)
@@ -1712,3 +1712,41 @@
   }
 }
+
+/** returns the number of available comments for the connected user */
+function get_nb_available_comments()
+{
+  global $user;
+  if (!isset($user['nb_available_comments']))
+  {
+    $where = array();
+    if ( !is_admin() )
+      $where[] = 'validated=\'true\'';
+    $where[] = get_sql_condition_FandF
+      (
+        array
+          (
+            'forbidden_categories' => 'category_id',
+            'visible_categories' => 'category_id',
+            'visible_images' => 'ic.image_id'
+          ),
+        '', true
+      );
+
+    $query = '
+SELECT COUNT(DISTINCT(com.id))
+  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
+    INNER JOIN '.COMMENTS_TABLE.' AS com
+    ON ic.image_id = com.image_id
+  WHERE '.implode('
+    AND ', $where);
+    list($user['nb_available_comments']) = pwg_db_fetch_row(pwg_query($query));
+
+    single_update(USER_CACHE_TABLE, 
+      array('nb_available_comments'=>$user['nb_available_comments']),
+      array('user_id'=>$user['id'])
+      );
+  }
+  return $user['nb_available_comments'];
+}
+
 ?>
Index: /trunk/include/functions_comment.inc.php
===================================================================
--- /trunk/include/functions_comment.inc.php	(revision 21816)
+++ /trunk/include/functions_comment.inc.php	(revision 21817)
@@ -221,8 +221,8 @@
   )
 ';
-
     pwg_query($query);
-
     $comm['id'] = pwg_db_insert_id(COMMENTS_TABLE);
+
+    invalidate_user_cache_nb_comments();
 
     if ( ($conf['email_admin_on_comment'] && 'validate' == $comment_action)
@@ -284,15 +284,15 @@
 $user_where_clause.'
 ;';
-  $result = pwg_query($query);
-  
-  if ($result) 
-  {
+  
+  if ( pwg_db_changes(pwg_query($query)) )
+  {
+    invalidate_user_cache_nb_comments();
+
     email_admin('delete', 
                 array('author' => $GLOBALS['user']['username'],
                       'comment_id' => $comment_id
                   ));
-  }
-  
-  trigger_action('user_comment_deletion', $comment_id);
+    trigger_action('user_comment_deletion', $comment_id);
+  }
 }
 
@@ -345,5 +345,5 @@
     if (!url_check_format($comment['website_url']))
     {
-      array_push($page['errors'], l10n('Your website URL is invalid'));
+      $page['errors'][] = l10n('Your website URL is invalid');
       $comment_action='reject';
     }
@@ -394,5 +394,5 @@
     }
     // just mail admin
-    else if ($result)
+    elseif ($result)
     {
       email_admin('edit', array('author' => $GLOBALS['user']['username'],
@@ -482,5 +482,18 @@
   pwg_query($query);
   
+  invalidate_user_cache_nb_comments();
   trigger_action('user_comment_validation', $comment_id);
 }
+
+
+function invalidate_user_cache_nb_comments()
+{
+  global $user;
+  unset($user['nb_available_comments']);
+  $query = '
+UPDATE '.USER_CACHE_TABLE.'
+  SET nb_available_comments = NULL';
+  pwg_query($query);
+}
+
 ?>
Index: /trunk/include/functions_tag.inc.php
===================================================================
--- /trunk/include/functions_tag.inc.php	(revision 21816)
+++ /trunk/include/functions_tag.inc.php	(revision 21817)
@@ -23,4 +23,19 @@
 
 
+/** returns the number of available tags for the connected user */
+function get_nb_available_tags()
+{
+  global $user;
+  if (!isset($user['nb_available_tags']))
+  {
+    $user['nb_available_tags'] = count(get_available_tags());
+    single_update(USER_CACHE_TABLE, 
+      array('nb_available_tags'=>$user['nb_available_tags']),
+      array('user_id'=>$user['id'])
+      );
+  }
+  return $user['nb_available_tags'];
+}
+
 /**
  * Tags available. Each return tag is represented as an array with its id,
Index: /trunk/include/menubar.inc.php
===================================================================
--- /trunk/include/menubar.inc.php	(revision 21816)
+++ /trunk/include/menubar.inc.php	(revision 21817)
@@ -192,4 +192,18 @@
     }
 
+    $block->data['recent_pics'] =
+      array(
+        'URL' => make_index_url(array('section' => 'recent_pics')),
+        'TITLE' => l10n('display most recent photos'),
+        'NAME' => l10n('Recent photos'),
+      );
+
+    $block->data['recent_cats'] =
+      array(
+        'URL' => make_index_url(array('section' => 'recent_cats')),
+        'TITLE' => l10n('display recently updated albums'),
+        'NAME' => l10n('Recent albums'),
+      );
+
     $block->data['random'] =
       array(
@@ -199,19 +213,4 @@
         'REL'=> 'rel="nofollow"'
       );
-
-    $block->data['recent_pics'] =
-      array(
-        'URL' => make_index_url(array('section' => 'recent_pics')),
-        'TITLE' => l10n('display most recent photos'),
-        'NAME' => l10n('Recent photos'),
-      );
-
-    $block->data['recent_cats'] =
-      array(
-        'URL' => make_index_url(array('section' => 'recent_cats')),
-        'TITLE' => l10n('display recently updated albums'),
-        'NAME' => l10n('Recent albums'),
-      );
-
 
     $block->data['calendar'] =
@@ -247,4 +246,5 @@
         'NAME' => l10n('Tags'),
         'URL'=> get_root_url().'tags.php',
+        'COUNTER' => get_nb_available_tags(),
       );
 
@@ -266,4 +266,5 @@
           'NAME'=>l10n('Comments'),
           'URL'=> get_root_url().'comments.php',
+          'COUNTER' => get_nb_available_comments(),
         );
     }
Index: /trunk/themes/default/template/menubar_menu.tpl
===================================================================
--- /trunk/themes/default/template/menubar_menu.tpl	(revision 21816)
+++ /trunk/themes/default/template/menubar_menu.tpl	(revision 21817)
@@ -12,5 +12,5 @@
 	{foreach from=$block->data item=link}
 		{if is_array($link)}
-			<li><a href="{$link.URL}" title="{$link.TITLE}"{if isset($link.REL)} {$link.REL}{/if}>{$link.NAME}</a></li>
+			<li><a href="{$link.URL}" title="{$link.TITLE}"{if isset($link.REL)} {$link.REL}{/if}>{$link.NAME}</a>{if isset($link.COUNTER)} ({$link.COUNTER}){/if}</li>
 		{/if}
 	{/foreach}
