Changeset 2488 for trunk/include


Ignore:
Timestamp:
Aug 28, 2008, 2:32:39 AM (16 years ago)
Author:
rvelices
Message:
  • based on test_menu by grum (thanks to you) - integration of dynamic menu bar to pwg
  • the menubar is composed now of dynamic blocks that can be ordered/hidden
  • plugins can add their own blocks
Location:
trunk/include
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/common.inc.php

    r2484 r2488  
    284284add_event_handler('render_comment_content', 'parse_comment_content');
    285285add_event_handler('render_comment_author', 'strip_tags');
     286add_event_handler('blockmanager_register_blocks', 'register_default_menubar_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL-1);
    286287trigger_action('init');
    287288?>
  • trunk/include/functions_html.inc.php

    r2433 r2488  
    773773}
    774774
     775/*event handler for menu*/
     776function register_default_menubar_blocks( $menu_ref_arr )
     777{
     778  $menu = & $menu_ref_arr[0];
     779  if ($menu->get_id() != 'menubar')
     780    return;
     781  $menu->register_block( new RegisteredBlock( 'mbLinks', 'Links', 'piwigo'));
     782  $menu->register_block( new RegisteredBlock( 'mbCategories', 'Categories', 'piwigo'));
     783  $menu->register_block( new RegisteredBlock( 'mbTags', 'Related tags', 'piwigo'));
     784  $menu->register_block( new RegisteredBlock( 'mbSpecials', 'special_categories', 'piwigo'));
     785  $menu->register_block( new RegisteredBlock( 'mbMenu', 'title_menu', 'piwigo'));
     786  $menu->register_block( new RegisteredBlock( 'mbIdentification', 'identification', 'piwigo') );
     787}
     788
    775789?>
  • trunk/include/menubar.inc.php

    r2409 r2488  
    2626 *
    2727 */
    28 $template->set_filenames(
    29   array(
    30     'menubar' => 'menubar.tpl',
    31     )
    32   );
    33 
    34 trigger_action('loc_begin_menubar');
    35 
    36 $template->assign(
    37   array(
    38     'NB_PICTURE' => $user['nb_total_images'],
    39     'MENU_CATEGORIES_CONTENT' => get_categories_menu(),
    40     'U_CATEGORIES' => make_index_url(array('section' => 'categories')),
    41     'U_LOST_PASSWORD' => get_root_url().'password.php',
    42     'U_UPLOAD' => get_upload_menu_link()
    43     )
    44   );
    45 
    46 //-------------------------------------------------------------- external links
    47 foreach ($conf['links'] as $url => $url_data)
     28
     29include_once(PHPWG_ROOT_PATH.'include/block.class.php');
     30
     31initialize_menu();
     32
     33function initialize_menu()
    4834{
    49   if (!is_array($url_data))
    50   {
    51     $url_data = array('label' => $url_data);
    52   }
    53 
    54   if
    55     (
    56       (!isset($url_data['eval_visible']))
    57       or
    58       (eval($url_data['eval_visible']))
    59     )
    60   {
    61     $tpl_var = array(
    62         'URL' => $url,
    63         'LABEL' => $url_data['label']
    64       );
    65 
    66     if (!isset($url_data['new_window']) or $url_data['new_window'])
    67     {
    68       $tpl_var['new_window'] =
     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    $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        $data[] = $tpl_var;
     73      }
     74    }
     75    $block->template = 'menubar_links.tpl';
     76    $block->data = $data;
     77  }
     78
     79//-------------------------------------------------------------- categories
     80  $block = $menu->get_block('mbCategories');
     81//------------------------------------------------------------------------ filter
     82  if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
     83  {
     84    if ($filter['enabled'])
     85    {
     86      $template->assign(
     87        'U_STOP_FILTER',
     88        add_url_params(make_index_url(array()), array('filter' => 'stop'))
     89        );
     90    }
     91    else
     92    {
     93      $template->assign(
     94        'U_START_FILTER',
     95        add_url_params(make_index_url(array()), array('filter' => 'start-recent-'.$user['recent_period']))
     96        );
     97    }
     98  }
     99
     100  if ( $block!=null )
     101  {
     102    $block->data = array(
     103      'NB_PICTURE' => $user['nb_total_images'],
     104      'MENU_CATEGORIES_CONTENT' => get_categories_menu(),
     105      'U_CATEGORIES' => make_index_url(array('section' => 'categories')),
     106      'U_UPLOAD' => get_upload_menu_link()
     107    );
     108    $block->template = 'menubar_categories.tpl';
     109  }
     110
     111//------------------------------------------------------------------------ tags
     112  $block = $menu->get_block('mbTags');
     113  if ( $block!=null and 'tags'==@$page['section'] and !empty($page['items']) )
     114  {
     115    $tags = get_common_tags($page['items'],
     116          $conf['menubar_tag_cloud_items_number'], $page['tag_ids']);
     117    $tags = add_level_to_tags($tags);
     118
     119    foreach ($tags as $tag)
     120    {
     121      $block->data[] =
     122        array_merge( $tag,
     123          array(
     124            'URL' => make_index_url(
     125              array(
     126                'tags' => array($tag)
     127                )
     128              ),
     129            'U_ADD' => make_index_url(
     130                  array(
     131                    'tags' => array_merge(
     132                      $page['tags'],
     133                      array($tag)
     134                      )
     135                    )
     136                  ),
     137            )
     138        );
     139    }
     140    $block->template = 'menubar_tags.tpl';
     141  }
     142
     143//----------------------------------------------------------- special categories
     144  if ( ($block = $menu->get_block('mbSpecials')) != null )
     145  {
     146    if ( !is_a_guest() )
     147    {// favorites
     148      $block->data['favorites'] =
    69149        array(
    70           'NAME' => (isset($url_data['nw_name']) ? $url_data['nw_name'] : ''),
    71           'FEATURES' => (isset($url_data['nw_features']) ? $url_data['nw_features'] : '')
     150          'URL' => make_index_url(array('section' => 'favorites')),
     151          'TITLE' => l10n('favorite_cat_hint'),
     152          'NAME' => l10n('favorite_cat')
     153          );
     154    }
     155
     156    $block->data['most_visited'] =
     157      array(
     158        'URL' => make_index_url(array('section' => 'most_visited')),
     159        'TITLE' => l10n('most_visited_cat_hint'),
     160        'NAME' => l10n('most_visited_cat')
     161      );
     162
     163    if ($conf['rate'])
     164    {
     165       $block->data['best_rated'] =
     166        array(
     167          'URL' => make_index_url(array('section' => 'best_rated')),
     168          'TITLE' => l10n('best_rated_cat_hint'),
     169          'NAME' => l10n('best_rated_cat')
    72170        );
    73171    }
    74     $template->append('links', $tpl_var);
    75   }
     172
     173    $block->data['random'] =
     174      array(
     175        'URL' => get_root_url().'random.php',
     176        'TITLE' => l10n('random_cat_hint'),
     177        'NAME' => l10n('random_cat'),
     178        'REL'=> 'rel="nofollow"'
     179      );
     180
     181    $block->data['recent_pics'] =
     182      array(
     183        'URL' => make_index_url(array('section' => 'recent_pics')),
     184        'TITLE' => l10n('recent_pics_cat_hint'),
     185        'NAME' => l10n('recent_pics_cat'),
     186      );
     187
     188    $block->data['recent_cats'] =
     189      array(
     190        'URL' => make_index_url(array('section' => 'recent_cats')),
     191        'TITLE' => l10n('recent_cats_cat_hint'),
     192        'NAME' => l10n('recent_cats_cat'),
     193      );
     194
     195
     196    $block->data['calendar'] =
     197      array(
     198        'URL' =>
     199          make_index_url(
     200            array(
     201              'chronology_field' => ($conf['calendar_datefield']=='date_available'
     202                                      ? 'posted' : 'created'),
     203               'chronology_style'=> 'monthly',
     204               'chronology_view' => 'calendar'
     205            )
     206          ),
     207        'TITLE' => l10n('calendar_hint'),
     208        'NAME' => l10n('calendar'),
     209        'REL'=> 'rel="nofollow"'
     210      );
     211    $block->template = 'menubar_specials.tpl';
     212  }
     213
     214
     215//---------------------------------------------------------------------- summary
     216  if ( ($block=$menu->get_block('mbMenu')) != null )
     217  {
     218    // tags link
     219    $block->data['tags'] =
     220      array(
     221        'TITLE' => l10n('See available tags'),
     222        'NAME' => l10n('Tags'),
     223        'URL'=> get_root_url().'tags.php',
     224      );
     225
     226    // search link
     227    $block->data['search'] =
     228      array(
     229        'TITLE'=>l10n('hint_search'),
     230        'NAME'=>l10n('Search'),
     231        'URL'=> get_root_url().'search.php',
     232        'REL'=> 'rel="search"'
     233      );
     234
     235    // comments link
     236    $block->data['comments'] =
     237      array(
     238        'TITLE'=>l10n('hint_comments'),
     239        'NAME'=>l10n('comments'),
     240        'URL'=> get_root_url().'comments.php',
     241      );
     242
     243    // about link
     244    $block->data['about'] =
     245      array(
     246        'TITLE'     => l10n('about_page_title'),
     247        'NAME'      => l10n('About'),
     248        'URL' => get_root_url().'about.php',
     249      );
     250
     251    // notification
     252    $block->data['rss'] =
     253      array(
     254        'TITLE'=>l10n('RSS feed'),
     255        'NAME'=>l10n('Notification'),
     256        'URL'=> get_root_url().'notification.php',
     257        'REL'=> 'rel="nofollow"'
     258      );
     259    $block->template = 'menubar_menu.tpl';
     260  }
     261
     262
     263//--------------------------------------------------------------- identification
     264  if (is_a_guest())
     265  {
     266    $template->assign(
     267        array(
     268          'U_LOGIN' => get_root_url().'identification.php',
     269          'AUTHORIZE_REMEMBERING' => $conf['authorize_remembering']
     270        )
     271      );
     272    if ($conf['allow_user_registration'])
     273    {
     274      $template->assign( 'U_REGISTER', get_root_url().'register.php');
     275    }
     276  }
     277  else
     278  {
     279    $template->assign('USERNAME', $user['username']);
     280    if (is_autorize_status(ACCESS_CLASSIC))
     281    {
     282      $template->assign('U_PROFILE', get_root_url().'profile.php');
     283    }
     284
     285    // the logout link has no meaning with Apache authentication : it is not
     286    // possible to logout with this kind of authentication.
     287    if (!$conf['apache_authentication'])
     288    {
     289      $template->assign('U_LOGOUT', get_root_url().'?act=logout');
     290    }
     291    if (is_admin())
     292    {
     293      $template->assign('U_ADMIN', get_root_url().'admin.php');
     294    }
     295  }
     296  if ( ($block=$menu->get_block('mbIdentification')) != null )
     297  {
     298    $block->template = 'menubar_identification.tpl';
     299  }
     300  $menu->apply('MENUBAR',  'menubar.tpl' );
    76301}
    77 
    78 //------------------------------------------------------------------------ filter
    79 if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
    80 {
    81   if ($filter['enabled'])
    82   {
    83     $template->assign(
    84       'U_STOP_FILTER',
    85       add_url_params(make_index_url(array()), array('filter' => 'stop'))
    86       );
    87   }
    88   else
    89   {
    90     $template->assign(
    91       'U_START_FILTER',
    92       add_url_params(make_index_url(array()), array('filter' => 'start-recent-'.$user['recent_period']))
    93       );
    94   }
    95 }
    96 
    97 //------------------------------------------------------------------------ tags
    98 if ('tags' == @$page['section'])
    99 {
    100   // display tags associated to currently tagged items, less current tags
    101   $tags = array();
    102   if ( !empty($page['items']) )
    103   {
    104     $tags = get_common_tags($page['items'],
    105         $conf['menubar_tag_cloud_items_number'], $page['tag_ids']);
    106   }
    107 
    108   $tags = add_level_to_tags($tags);
    109 
    110   foreach ($tags as $tag)
    111   {
    112     $template->append(
    113       'related_tags',
    114       array_merge( $tag,
    115         array(
    116           'URL' => make_index_url(
    117             array(
    118               'tags' => array($tag)
    119               )
    120             ),
    121 
    122           'U_ADD' => make_index_url(
    123                 array(
    124                   'tags' => array_merge(
    125                     $page['tags'],
    126                     array($tag)
    127                     )
    128                   )
    129                 ),
    130           )
    131         )
    132       );
    133   }
    134 }
    135 //---------------------------------------------------------- special categories
    136 // favorites categories
    137 if ( !is_a_guest() )
    138 {
    139   $template->append(
    140     'special_categories',
    141     array(
    142       'URL' => make_index_url(array('section' => 'favorites')),
    143       'TITLE' => l10n('favorite_cat_hint'),
    144       'NAME' => l10n('favorite_cat')
    145       ));
    146 }
    147 // most visited
    148 $template->append(
    149   'special_categories',
    150   array(
    151     'URL' => make_index_url(array('section' => 'most_visited')),
    152     'TITLE' => l10n('most_visited_cat_hint'),
    153     'NAME' => l10n('most_visited_cat')
    154     ));
    155 // best rated
    156 if ($conf['rate'])
    157 {
    158   $template->append(
    159     'special_categories',
    160     array(
    161       'URL' => make_index_url(array('section' => 'best_rated')),
    162       'TITLE' => l10n('best_rated_cat_hint'),
    163       'NAME' => l10n('best_rated_cat')
    164       )
    165     );
    166 }
    167 // random
    168 $template->append(
    169   'special_categories',
    170   array(
    171     'URL' => get_root_url().'random.php',
    172     'TITLE' => l10n('random_cat_hint'),
    173     'NAME' => l10n('random_cat'),
    174     'REL'=> 'rel="nofollow"'
    175     ));
    176 
    177 // recent pics
    178 $template->append(
    179   'special_categories',
    180   array(
    181     'URL' => make_index_url(array('section' => 'recent_pics')),
    182     'TITLE' => l10n('recent_pics_cat_hint'),
    183     'NAME' => l10n('recent_pics_cat'),
    184     ));
    185 // recent cats
    186 $template->append(
    187   'special_categories',
    188   array(
    189     'URL' => make_index_url(array('section' => 'recent_cats')),
    190     'TITLE' => l10n('recent_cats_cat_hint'),
    191     'NAME' => l10n('recent_cats_cat'),
    192     ));
    193 
    194 // calendar
    195 $template->append(
    196   'special_categories',
    197   array(
    198     'URL' =>
    199       make_index_url(
    200         array(
    201           'chronology_field' => ($conf['calendar_datefield']=='date_available'
    202                                   ? 'posted' : 'created'),
    203            'chronology_style'=> 'monthly',
    204            'chronology_view' => 'calendar'
    205         )
    206       ),
    207     'TITLE' => l10n('calendar_hint'),
    208     'NAME' => l10n('calendar'),
    209     'REL'=> 'rel="nofollow"'
    210     )
    211   );
    212 //--------------------------------------------------------------------- summary
    213 
    214 if (is_a_guest())
    215 {
    216   $template->assign(
    217       array(
    218         'U_IDENTIFY' => get_root_url().'identification.php',
    219         'AUTHORIZE_REMEMBERING' => $conf['authorize_remembering']
    220       )
    221     );
    222 
    223   if ($conf['allow_user_registration'])
    224   {
    225     $template->assign( 'U_REGISTER', get_root_url().'register.php');
    226   }
    227 }
    228 else
    229 {
    230   $template->assign('USERNAME', $user['username']);
    231 
    232   if (is_autorize_status(ACCESS_CLASSIC))
    233   {
    234     $template->assign('U_PROFILE', get_root_url().'profile.php');
    235   }
    236 
    237   // the logout link has no meaning with Apache authentication : it is not
    238   // possible to logout with this kind of authentication.
    239   if (!$conf['apache_authentication'])
    240   {
    241     $template->assign('U_LOGOUT', get_root_url().'?act=logout');
    242   }
    243 
    244   if (is_admin())
    245   {
    246     $template->assign('U_ADMIN', get_root_url().'admin.php');
    247   }
    248 }
    249 
    250 // tags link
    251 $template->append(
    252   'summaries',
    253   array(
    254     'TITLE' => l10n('See available tags'),
    255     'NAME' => l10n('Tags'),
    256     'U_SUMMARY'=> get_root_url().'tags.php',
    257     )
    258   );
    259 
    260 // search link
    261 $template->append(
    262   'summaries',
    263   array(
    264     'TITLE'=>l10n('hint_search'),
    265     'NAME'=>l10n('Search'),
    266     'U_SUMMARY'=> get_root_url().'search.php',
    267     'REL'=> 'rel="search"'
    268     )
    269   );
    270 
    271 // comments link
    272 $template->append(
    273   'summaries',
    274   array(
    275     'TITLE'=>l10n('hint_comments'),
    276     'NAME'=>l10n('comments'),
    277     'U_SUMMARY'=> get_root_url().'comments.php',
    278     )
    279   );
    280 
    281 // about link
    282 $template->append(
    283   'summaries',
    284   array(
    285     'TITLE'     => l10n('about_page_title'),
    286     'NAME'      => l10n('About'),
    287     'U_SUMMARY' => get_root_url().'about.php',
    288     )
    289   );
    290 
    291 // notification
    292 $template->append(
    293   'summaries',
    294   array(
    295     'TITLE'=>l10n('RSS feed'),
    296     'NAME'=>l10n('Notification'),
    297     'U_SUMMARY'=> get_root_url().'notification.php',
    298     'REL'=> 'rel="nofollow"'
    299     )
    300   );
    301 
    302 trigger_action('loc_end_menubar');
    303 $template->assign_var_from_handle('MENUBAR', 'menubar');
    304 
    305302?>
Note: See TracChangeset for help on using the changeset viewer.