aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2013-03-24 06:46:35 +0000
committerrvelices <rv-github@modusoptimus.com>2013-03-24 06:46:35 +0000
commitea10c19ac5a1f6e89627497e5a6bfdefa37b5053 (patch)
tree7b59e8ae7a426b524ba8a13a6e2be38bffe6e791 /include/functions.inc.php
parent55275efb66cf6a2b0c874a1d05915fdc83d9cc48 (diff)
feature 2836: display the number of comments/tags in the menubar
git-svn-id: http://piwigo.org/svn/trunk@21817 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions.inc.php')
-rw-r--r--include/functions.inc.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 5b676f87c..8d43049b0 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -1711,4 +1711,42 @@ function email_check_format($mail_address)
return (bool)preg_match($regex, $mail_address);
}
}
+
+/** 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'];
+}
+
?> \ No newline at end of file