aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
4 files changed, 83 insertions, 16 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
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(),
);
}