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