source: extensions/AdditionalPages/trunk/main.inc.php @ 11574

Last change on this file since 11574 was 11574, checked in by plg, 13 years ago

add "Albums /" in the navigation path when the gallery has an homepage

File size: 4.0 KB
Line 
1<?php
2/*
3Plugin Name: Additional Pages
4Version: auto
5Description: Add additional pages in menubar.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=153
7Author: P@t
8Author URI: http://www.gauchon.com
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13global $prefixeTable, $conf;
14
15define('AP_DIR' , basename(dirname(__FILE__)));
16define('AP_PATH' , PHPWG_PLUGINS_PATH . AP_DIR . '/');
17define('ADD_PAGES_TABLE' , $prefixeTable . 'additionalpages');
18
19$conf['AP'] = @unserialize($conf['additional_pages']);
20
21// Need upgrade?
22if (!isset($conf['AP']['language_perm']))
23  include(AP_PATH.'admin/upgrade.inc.php');
24
25// Unset $conf['random_index_redirect'] if homepage is defined
26if (!empty($conf['random_index_redirect']) and !is_null($conf['AP']['homepage']))
27{
28  $conf['ap_random_index_redirect'] = $conf['random_index_redirect'];
29  $conf['random_index_redirect'] = array();
30}
31
32// Admin menu
33function additional_pages_admin_menu($menu)
34{
35    array_push($menu, array(
36      'NAME' => 'Additional Pages',
37      'URL' => get_root_url().'admin.php?page=plugin-'.AP_DIR,
38      )
39    );
40    return $menu;
41}
42
43// Section init
44function section_init_additional_page()
45{
46  global $tokens, $conf, $page;
47
48  if (defined('EXTENDED_DESC_PATH'))
49  {
50    add_event_handler('AP_render_content', 'get_extended_desc');
51    add_event_handler('AP_render_title', 'get_user_language_desc');
52  }
53
54  $page['ap_homepage'] = (count($tokens) == 1 and empty($tokens[0]));
55
56  if (($tokens[0] == 'page' and !empty($tokens[1])) or ($page['ap_homepage'] and !is_null($conf['AP']['homepage'])))
57    include(AP_PATH . 'additional_page.php');
58
59  if ($tokens[0] == 'additional_page' and !empty($tokens[1]))
60    redirect(make_index_url(array('section'=>'page')).'/'.$tokens[1]);
61
62  if (!is_null($conf['AP']['homepage']))
63  {
64    $albums_url = make_index_url(array('section' => 'categories'));
65   
66    $page['title'] = preg_replace(
67      '#/a>#',
68      '/a>'.$conf['level_separator'].'<a href="'.$albums_url.'">'.l10n('Albums').'</a>',
69      $page['title'],
70      1 // only replace the first occurence of "a/>"
71      );
72  }
73}
74
75// Menubar
76function register_ap_menubar_blocks($menu_ref_arr)
77{
78  global $conf, $user;
79
80  $menu = & $menu_ref_arr[0];
81  if ($menu->get_id() != 'menubar') return;
82
83  $conf['AP']['block_title'] = isset($conf['AP']['languages'][$user['language']]) ?
84    $conf['AP']['languages'][$user['language']] : @$conf['AP']['languages']['default'];
85
86  if (empty($conf['AP']['block_title']))
87    $conf['AP']['block_title'] = 'Additional Pages';
88
89  $menu->register_block( new RegisteredBlock( 'mbAdditionalPages', $conf['AP']['block_title'], 'Additional Pages'));
90}
91
92function ap_apply($menu_ref_arr)
93{
94  global $template, $conf, $user;
95
96  $menu = & $menu_ref_arr[0];
97 
98  if ( ($block = $menu->get_block( 'mbAdditionalPages' ) ) != null )
99  {
100    $query = 'SELECT DISTINCT id, title, permalink
101FROM ' . ADD_PAGES_TABLE . '
102LEFT JOIN ' . USER_GROUP_TABLE . '
103  ON user_id = '.$user['id'].'
104WHERE (lang IS NULL OR lang = "'.$user['language'].'")
105  AND (users IS NULL OR users LIKE "%'.$user['status'].'%")
106  AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)"))
107  AND level <= '.$user['level'].'
108  AND pos >= 0
109ORDER BY pos ASC
110;';
111    $result = pwg_query($query);
112    $data = array();
113    while ($row = pwg_db_fetch_assoc($result))
114    {
115      $url = make_index_url(array('section'=>'page')).'/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
116      array_push($data, array('URL' => $url, 'LABEL' => trigger_event('AP_render_title', $row['title'])));
117    }
118
119    if (!empty($data))
120    {
121      $template->set_template_dir(AP_PATH.'template/');
122      $block->set_title($conf['AP']['block_title']);
123      $block->template = 'menubar_additional_pages.tpl';
124      $block->data = $data;
125    }
126  }
127}
128
129add_event_handler('get_admin_plugin_menu_links', 'additional_pages_admin_menu');
130add_event_handler('loc_end_section_init', 'section_init_additional_page');
131add_event_handler('blockmanager_register_blocks', 'register_ap_menubar_blocks');
132add_event_handler('blockmanager_apply', 'ap_apply');
133
134?>
Note: See TracBrowser for help on using the repository browser.