mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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.
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user