Changeset 21817


Ignore:
Timestamp:
Mar 24, 2013, 7:46:35 AM (7 years ago)
Author:
rvelices
Message:

feature 2836: display the number of comments/tags in the menubar

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r21567 r21817  
    13681368    $inserts
    13691369    );
     1370  invalidate_user_cache_nb_tags();
    13701371}
    13711372
     
    13981399;';
    13991400  pwg_query($query);
     1401
     1402  invalidate_user_cache_nb_tags();
    14001403}
    14011404
     
    14871490        );
    14881491    }
     1492
     1493    invalidate_user_cache_nb_tags();
    14891494  }
    14901495}
     
    16931698  }
    16941699  trigger_action('invalidate_user_cache', $full);
     1700}
     1701
     1702
     1703function invalidate_user_cache_nb_tags()
     1704{
     1705  global $user;
     1706  unset($user['nb_available_tags']);
     1707  $query = '
     1708UPDATE '.USER_CACHE_TABLE.'
     1709  SET nb_available_tags = NULL';
     1710  pwg_query($query);
    16951711}
    16961712
  • trunk/include/functions.inc.php

    r21515 r21817  
    17121712  }
    17131713}
     1714
     1715/** returns the number of available comments for the connected user */
     1716function get_nb_available_comments()
     1717{
     1718  global $user;
     1719  if (!isset($user['nb_available_comments']))
     1720  {
     1721    $where = array();
     1722    if ( !is_admin() )
     1723      $where[] = 'validated=\'true\'';
     1724    $where[] = get_sql_condition_FandF
     1725      (
     1726        array
     1727          (
     1728            'forbidden_categories' => 'category_id',
     1729            'visible_categories' => 'category_id',
     1730            'visible_images' => 'ic.image_id'
     1731          ),
     1732        '', true
     1733      );
     1734
     1735    $query = '
     1736SELECT COUNT(DISTINCT(com.id))
     1737  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
     1738    INNER JOIN '.COMMENTS_TABLE.' AS com
     1739    ON ic.image_id = com.image_id
     1740  WHERE '.implode('
     1741    AND ', $where);
     1742    list($user['nb_available_comments']) = pwg_db_fetch_row(pwg_query($query));
     1743
     1744    single_update(USER_CACHE_TABLE,
     1745      array('nb_available_comments'=>$user['nb_available_comments']),
     1746      array('user_id'=>$user['id'])
     1747      );
     1748  }
     1749  return $user['nb_available_comments'];
     1750}
     1751
    17141752?>
  • trunk/include/functions_comment.inc.php

    r19703 r21817  
    221221  )
    222222';
    223 
    224223    pwg_query($query);
    225 
    226224    $comm['id'] = pwg_db_insert_id(COMMENTS_TABLE);
     225
     226    invalidate_user_cache_nb_comments();
    227227
    228228    if ( ($conf['email_admin_on_comment'] && 'validate' == $comment_action)
     
    284284$user_where_clause.'
    285285;';
    286   $result = pwg_query($query);
    287  
    288   if ($result)
    289   {
     286 
     287  if ( pwg_db_changes(pwg_query($query)) )
     288  {
     289    invalidate_user_cache_nb_comments();
     290
    290291    email_admin('delete',
    291292                array('author' => $GLOBALS['user']['username'],
    292293                      'comment_id' => $comment_id
    293294                  ));
    294   }
    295  
    296   trigger_action('user_comment_deletion', $comment_id);
     295    trigger_action('user_comment_deletion', $comment_id);
     296  }
    297297}
    298298
     
    345345    if (!url_check_format($comment['website_url']))
    346346    {
    347       array_push($page['errors'], l10n('Your website URL is invalid'));
     347      $page['errors'][] = l10n('Your website URL is invalid');
    348348      $comment_action='reject';
    349349    }
     
    394394    }
    395395    // just mail admin
    396     else if ($result)
     396    elseif ($result)
    397397    {
    398398      email_admin('edit', array('author' => $GLOBALS['user']['username'],
     
    482482  pwg_query($query);
    483483 
     484  invalidate_user_cache_nb_comments();
    484485  trigger_action('user_comment_validation', $comment_id);
    485486}
     487
     488
     489function invalidate_user_cache_nb_comments()
     490{
     491  global $user;
     492  unset($user['nb_available_comments']);
     493  $query = '
     494UPDATE '.USER_CACHE_TABLE.'
     495  SET nb_available_comments = NULL';
     496  pwg_query($query);
     497}
     498
    486499?>
  • trunk/include/functions_tag.inc.php

    r19703 r21817  
    2323
    2424
     25/** returns the number of available tags for the connected user */
     26function get_nb_available_tags()
     27{
     28  global $user;
     29  if (!isset($user['nb_available_tags']))
     30  {
     31    $user['nb_available_tags'] = count(get_available_tags());
     32    single_update(USER_CACHE_TABLE,
     33      array('nb_available_tags'=>$user['nb_available_tags']),
     34      array('user_id'=>$user['id'])
     35      );
     36  }
     37  return $user['nb_available_tags'];
     38}
     39
    2540/**
    2641 * Tags available. Each return tag is represented as an array with its id,
  • trunk/include/menubar.inc.php

    r21040 r21817  
    192192    }
    193193
     194    $block->data['recent_pics'] =
     195      array(
     196        'URL' => make_index_url(array('section' => 'recent_pics')),
     197        'TITLE' => l10n('display most recent photos'),
     198        'NAME' => l10n('Recent photos'),
     199      );
     200
     201    $block->data['recent_cats'] =
     202      array(
     203        'URL' => make_index_url(array('section' => 'recent_cats')),
     204        'TITLE' => l10n('display recently updated albums'),
     205        'NAME' => l10n('Recent albums'),
     206      );
     207
    194208    $block->data['random'] =
    195209      array(
     
    199213        'REL'=> 'rel="nofollow"'
    200214      );
    201 
    202     $block->data['recent_pics'] =
    203       array(
    204         'URL' => make_index_url(array('section' => 'recent_pics')),
    205         'TITLE' => l10n('display most recent photos'),
    206         'NAME' => l10n('Recent photos'),
    207       );
    208 
    209     $block->data['recent_cats'] =
    210       array(
    211         'URL' => make_index_url(array('section' => 'recent_cats')),
    212         'TITLE' => l10n('display recently updated albums'),
    213         'NAME' => l10n('Recent albums'),
    214       );
    215 
    216215
    217216    $block->data['calendar'] =
     
    247246        'NAME' => l10n('Tags'),
    248247        'URL'=> get_root_url().'tags.php',
     248        'COUNTER' => get_nb_available_tags(),
    249249      );
    250250
     
    266266          'NAME'=>l10n('Comments'),
    267267          'URL'=> get_root_url().'comments.php',
     268          'COUNTER' => get_nb_available_comments(),
    268269        );
    269270    }
  • trunk/themes/default/template/menubar_menu.tpl

    r8774 r21817  
    1212        {foreach from=$block->data item=link}
    1313                {if is_array($link)}
    14                         <li><a href="{$link.URL}" title="{$link.TITLE}"{if isset($link.REL)} {$link.REL}{/if}>{$link.NAME}</a></li>
     14                        <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>
    1515                {/if}
    1616        {/foreach}
Note: See TracChangeset for help on using the changeset viewer.