aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--admin/include/functions.php16
-rw-r--r--include/functions.inc.php38
-rw-r--r--include/functions_comment.inc.php29
-rw-r--r--include/functions_tag.inc.php15
-rw-r--r--include/menubar.inc.php17
-rw-r--r--themes/default/template/menubar_menu.tpl2
6 files changed, 100 insertions, 17 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 4e53d09e6..02917394a 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1367,6 +1367,7 @@ DELETE
array_keys($inserts[0]),
$inserts
);
+ invalidate_user_cache_nb_tags();
}
/**
@@ -1397,6 +1398,8 @@ DELETE
WHERE id IN ('.implode(',', $tag_ids).')
;';
pwg_query($query);
+
+ invalidate_user_cache_nb_tags();
}
function tag_id_from_tag_name($tag_name)
@@ -1486,6 +1489,8 @@ DELETE
$inserts
);
}
+
+ invalidate_user_cache_nb_tags();
}
}
@@ -1694,6 +1699,17 @@ UPDATE '.USER_CACHE_TABLE.'
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);
+}
+
/**
* adds the caracter set to a create table sql query.
* all CREATE TABLE queries must call this function
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
diff --git a/include/functions_comment.inc.php b/include/functions_comment.inc.php
index dc218a2ff..42ceb5cc3 100644
--- a/include/functions_comment.inc.php
+++ b/include/functions_comment.inc.php
@@ -220,11 +220,11 @@ INSERT INTO '.COMMENTS_TABLE.'
'.(!empty($comm['email']) ? '\''.$comm['email'].'\'' : 'NULL').'
)
';
-
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)
or ($conf['email_admin_on_comment_validation'] and 'moderate' == $comment_action))
{
@@ -283,17 +283,17 @@ DELETE FROM '.COMMENTS_TABLE.'
WHERE '.$where_clause.
$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);
}
/**
@@ -344,7 +344,7 @@ function update_user_comment($comment, $post_key)
}
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';
}
}
@@ -393,7 +393,7 @@ $user_where_clause.'
);
}
// just mail admin
- else if ($result)
+ elseif ($result)
{
email_admin('edit', array('author' => $GLOBALS['user']['username'],
'content' => stripslashes($comment['content'])) );
@@ -481,6 +481,19 @@ UPDATE '.COMMENTS_TABLE.'
;';
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);
+}
+
?> \ No newline at end of file
diff --git a/include/functions_tag.inc.php b/include/functions_tag.inc.php
index 5766b9509..17ae996ab 100644
--- a/include/functions_tag.inc.php
+++ b/include/functions_tag.inc.php
@@ -22,6 +22,21 @@
// +-----------------------------------------------------------------------+
+/** 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,
* its name, its weight (count), its url name. Tags are not sorted.
diff --git a/include/menubar.inc.php b/include/menubar.inc.php
index bd75a0b44..b624111ca 100644
--- a/include/menubar.inc.php
+++ b/include/menubar.inc.php
@@ -191,14 +191,6 @@ function initialize_menu()
);
}
- $block->data['random'] =
- array(
- 'URL' => get_root_url().'random.php',
- 'TITLE' => l10n('display a set of random photos'),
- 'NAME' => l10n('Random photos'),
- 'REL'=> 'rel="nofollow"'
- );
-
$block->data['recent_pics'] =
array(
'URL' => make_index_url(array('section' => 'recent_pics')),
@@ -213,6 +205,13 @@ function initialize_menu()
'NAME' => l10n('Recent albums'),
);
+ $block->data['random'] =
+ array(
+ 'URL' => get_root_url().'random.php',
+ 'TITLE' => l10n('display a set of random photos'),
+ 'NAME' => l10n('Random photos'),
+ 'REL'=> 'rel="nofollow"'
+ );
$block->data['calendar'] =
array(
@@ -246,6 +245,7 @@ function initialize_menu()
'TITLE' => l10n('display available tags'),
'NAME' => l10n('Tags'),
'URL'=> get_root_url().'tags.php',
+ 'COUNTER' => get_nb_available_tags(),
);
// search link
@@ -265,6 +265,7 @@ function initialize_menu()
'TITLE'=>l10n('display last user comments'),
'NAME'=>l10n('Comments'),
'URL'=> get_root_url().'comments.php',
+ 'COUNTER' => get_nb_available_comments(),
);
}
diff --git a/themes/default/template/menubar_menu.tpl b/themes/default/template/menubar_menu.tpl
index 29276a48f..2eb2dd3a9 100644
--- a/themes/default/template/menubar_menu.tpl
+++ b/themes/default/template/menubar_menu.tpl
@@ -11,7 +11,7 @@
<ul>{strip}
{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}
{/strip}</ul>