source: trunk/include/menubar.inc.php @ 21817

Last change on this file since 21817 was 21817, checked in by rvelices, 11 years ago

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

  • Property svn:eol-style set to LF
File size: 10.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/**
25 * This file is included by the main page to show the menu bar
26 *
27 */
28
29include_once(PHPWG_ROOT_PATH.'include/block.class.php');
30
31initialize_menu();
32
33function initialize_menu()
34{
35  global $page, $conf, $user, $template, $filter;
36
37  $menu = new BlockManager("menubar");
38  $menu->load_registered_blocks();
39  $menu->prepare_display();
40
41//--------------------------------------------------------------- external links
42  if ( ($block=$menu->get_block('mbLinks')) and !empty($conf['links']) )
43  {
44    $block->data = array();
45    foreach ($conf['links'] as $url => $url_data)
46    {
47      if (!is_array($url_data))
48      {
49        $url_data = array('label' => $url_data);
50      }
51
52      if
53        (
54          (!isset($url_data['eval_visible']))
55          or
56          (eval($url_data['eval_visible']))
57        )
58      {
59        $tpl_var = array(
60            'URL' => $url,
61            'LABEL' => $url_data['label']
62          );
63
64        if (!isset($url_data['new_window']) or $url_data['new_window'])
65        {
66          $tpl_var['new_window'] =
67            array(
68              'NAME' => (isset($url_data['nw_name']) ? $url_data['nw_name'] : ''),
69              'FEATURES' => (isset($url_data['nw_features']) ? $url_data['nw_features'] : '')
70            );
71        }
72        $block->data[] = $tpl_var;
73      }
74    }
75    if ( !empty($block->data) )
76    {
77      $block->template = 'menubar_links.tpl';
78    }
79  }
80
81//-------------------------------------------------------------- categories
82  $block = $menu->get_block('mbCategories');
83//------------------------------------------------------------------------ filter
84  if ($conf['menubar_filter_icon'] and !empty($conf['filter_pages']) and get_filter_page_value('used'))
85  {
86    if ($filter['enabled'])
87    {
88      $template->assign(
89        'U_STOP_FILTER',
90        add_url_params(make_index_url(array()), array('filter' => 'stop'))
91        );
92    }
93    else
94    {
95      $template->assign(
96        'U_START_FILTER',
97        add_url_params(make_index_url(array()), array('filter' => 'start-recent-'.$user['recent_period']))
98        );
99    }
100  }
101
102  if ( $block!=null )
103  {
104    $block->data = array(
105      'NB_PICTURE' => $user['nb_total_images'],
106      'MENU_CATEGORIES' => get_categories_menu(),
107      'U_CATEGORIES' => make_index_url(array('section' => 'categories')),
108    );
109    $block->template = 'menubar_categories.tpl';
110  }
111
112//------------------------------------------------------------------------ tags
113  $block = $menu->get_block('mbTags');
114  if ( $block!=null and !empty($page['items']) and 'picture' != script_basename() )
115  {
116    if ('tags'==@$page['section'])
117    {
118      $tags = get_common_tags(
119        $page['items'],
120        $conf['menubar_tag_cloud_items_number'],
121        $page['tag_ids']
122        );
123      $tags = add_level_to_tags($tags);
124
125      foreach ($tags as $tag)
126      {
127        $block->data[] = array_merge(
128          $tag,
129          array(
130            'U_ADD' => make_index_url(
131              array(
132                'tags' => array_merge(
133                  $page['tags'],
134                  array($tag)
135                  )
136                )
137              ),
138            'URL' => make_index_url( array( 'tags' => array($tag) )
139              ),
140            )
141          );
142      }
143    }
144    else
145    {
146      $selection = array_slice( $page['items'], $page['start'], $page['nb_image_page'] );
147      $tags = add_level_to_tags( get_common_tags($selection, $conf['content_tag_cloud_items_number']) );
148      foreach ($tags as $tag)
149      {
150        $block->data[] =
151        array_merge( $tag,
152          array(
153            'URL' => make_index_url( array( 'tags' => array($tag) ) ),
154          )
155        );
156      }
157    }
158    if ( !empty($block->data) )
159    {
160      $block->template = 'menubar_tags.tpl';
161    }
162  }
163
164//----------------------------------------------------------- special categories
165  if ( ($block = $menu->get_block('mbSpecials')) != null )
166  {
167    if ( !is_a_guest() )
168    {// favorites
169      $block->data['favorites'] =
170        array(
171          'URL' => make_index_url(array('section' => 'favorites')),
172          'TITLE' => l10n('display your favorites photos'),
173          'NAME' => l10n('Your favorites')
174          );
175    }
176
177    $block->data['most_visited'] =
178      array(
179        'URL' => make_index_url(array('section' => 'most_visited')),
180        'TITLE' => l10n('display most visited photos'),
181        'NAME' => l10n('Most visited')
182      );
183
184    if ($conf['rate'])
185    {
186       $block->data['best_rated'] =
187        array(
188          'URL' => make_index_url(array('section' => 'best_rated')),
189          'TITLE' => l10n('display best rated photos'),
190          'NAME' => l10n('Best rated')
191        );
192    }
193
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
208    $block->data['random'] =
209      array(
210        'URL' => get_root_url().'random.php',
211        'TITLE' => l10n('display a set of random photos'),
212        'NAME' => l10n('Random photos'),
213        'REL'=> 'rel="nofollow"'
214      );
215
216    $block->data['calendar'] =
217      array(
218        'URL' =>
219          make_index_url(
220            array(
221              'chronology_field' => ($conf['calendar_datefield']=='date_available'
222                                      ? 'posted' : 'created'),
223               'chronology_style'=> 'monthly',
224               'chronology_view' => 'calendar'
225            )
226          ),
227        'TITLE' => l10n('display each day with photos, month per month'),
228        'NAME' => l10n('Calendar'),
229        'REL'=> 'rel="nofollow"'
230      );
231    $block->template = 'menubar_specials.tpl';
232  }
233
234
235//---------------------------------------------------------------------- summary
236  if ( ($block=$menu->get_block('mbMenu')) != null )
237  {
238    // quick search block will be displayed only if data['qsearch'] is set
239    // to "yes"
240    $block->data['qsearch']=true;
241
242    // tags link
243    $block->data['tags'] =
244      array(
245        'TITLE' => l10n('display available tags'),
246        'NAME' => l10n('Tags'),
247        'URL'=> get_root_url().'tags.php',
248        'COUNTER' => get_nb_available_tags(),
249      );
250
251    // search link
252    $block->data['search'] =
253      array(
254        'TITLE'=>l10n('search'),
255        'NAME'=>l10n('Search'),
256        'URL'=> get_root_url().'search.php',
257        'REL'=> 'rel="search"'
258      );
259
260    if ($conf['activate_comments'])
261    {
262      // comments link
263      $block->data['comments'] =
264        array(
265          'TITLE'=>l10n('display last user comments'),
266          'NAME'=>l10n('Comments'),
267          'URL'=> get_root_url().'comments.php',
268          'COUNTER' => get_nb_available_comments(),
269        );
270    }
271
272    // about link
273    $block->data['about'] =
274      array(
275        'TITLE'     => l10n('About Piwigo'),
276        'NAME'      => l10n('About'),
277        'URL' => get_root_url().'about.php',
278      );
279
280    // notification
281    $block->data['rss'] =
282      array(
283        'TITLE'=>l10n('RSS feed'),
284        'NAME'=>l10n('Notification'),
285        'URL'=> get_root_url().'notification.php',
286        'REL'=> 'rel="nofollow"'
287      );
288    $block->template = 'menubar_menu.tpl';
289  }
290
291
292//--------------------------------------------------------------- identification
293  if (is_a_guest())
294  {
295    $template->assign(
296        array(
297          'U_LOGIN' => get_root_url().'identification.php',
298          'U_LOST_PASSWORD' => get_root_url().'password.php',
299          'AUTHORIZE_REMEMBERING' => $conf['authorize_remembering']
300        )
301      );
302    if ($conf['allow_user_registration'])
303    {
304      $template->assign( 'U_REGISTER', get_root_url().'register.php');
305    }
306  }
307  else
308  {
309    $template->assign('USERNAME', stripslashes($user['username']));
310    if (is_autorize_status(ACCESS_CLASSIC))
311    {
312      $template->assign('U_PROFILE', get_root_url().'profile.php');
313    }
314
315    // the logout link has no meaning with Apache authentication : it is not
316    // possible to logout with this kind of authentication.
317    if (!$conf['apache_authentication'])
318    {
319      $template->assign('U_LOGOUT', get_root_url().'?act=logout');
320    }
321    if (is_admin())
322    {
323      $template->assign('U_ADMIN', get_root_url().'admin.php');
324    }
325  }
326  if ( ($block=$menu->get_block('mbIdentification')) != null )
327  {
328    $block->template = 'menubar_identification.tpl';
329  }
330  $menu->apply('MENUBAR',  'menubar.tpl' );
331}
332?>
Note: See TracBrowser for help on using the repository browser.