1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | add_event_handler('blockmanager_register_blocks', 'register_ap_menubar_blocks'); |
---|
6 | add_event_handler('blockmanager_apply', 'ap_apply'); |
---|
7 | |
---|
8 | function register_ap_menubar_blocks( $menu_ref_arr ) |
---|
9 | { |
---|
10 | $menu = & $menu_ref_arr[0]; |
---|
11 | if ($menu->get_id() != 'menubar') |
---|
12 | return; |
---|
13 | $menu->register_block( new RegisteredBlock( 'mbAdditionalPages', 'Additional Pages', 'AP')); |
---|
14 | } |
---|
15 | |
---|
16 | function ap_apply($menu_ref_arr) |
---|
17 | { |
---|
18 | global $template, $conf, $user, $lang; |
---|
19 | |
---|
20 | $ap_conf = explode ("," , $conf['additional_pages']); |
---|
21 | |
---|
22 | $menu = & $menu_ref_arr[0]; |
---|
23 | |
---|
24 | if ( ($block = $menu->get_block( 'mbAdditionalPages' ) ) != null ) |
---|
25 | { |
---|
26 | $template->set_template_dir(AP_PATH.'template/'); |
---|
27 | |
---|
28 | load_language('plugin.lang', AP_PATH); |
---|
29 | |
---|
30 | // Gestion des langues pour le nom du menu |
---|
31 | $languages = explode('/', $ap_conf[0]); |
---|
32 | foreach($languages as $language) |
---|
33 | { |
---|
34 | $array = explode(':', $language); |
---|
35 | if (!isset($array[1])) $menu_langs['default'] = $array[0]; |
---|
36 | else $menu_langs[$array[0]] = $array[1]; |
---|
37 | } |
---|
38 | |
---|
39 | $data = array(); |
---|
40 | |
---|
41 | if (is_admin()) |
---|
42 | { |
---|
43 | array_push($data, array( |
---|
44 | 'URL' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . AP_DIR . '%2Fadmin%2Fadd_page.php', |
---|
45 | 'LABEL' => l10n('ap_add_page'))); |
---|
46 | $clauses = ''; |
---|
47 | } |
---|
48 | else |
---|
49 | { |
---|
50 | $clauses = 'WHERE (lang = "' . $user['language'] . '" OR lang = "ALL")'; |
---|
51 | } |
---|
52 | |
---|
53 | // Recupération des groupes de l'utilisateur |
---|
54 | $q = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; |
---|
55 | $result = pwg_query($q); |
---|
56 | $groups = array(); |
---|
57 | while ($row = mysql_fetch_assoc($result)) |
---|
58 | { |
---|
59 | array_push($groups, $row['group_id']); |
---|
60 | } |
---|
61 | |
---|
62 | // Récupération des pages |
---|
63 | $q = 'SELECT id , pos , title |
---|
64 | FROM ' . ADD_PAGES_TABLE . ' |
---|
65 | ' . $clauses . ' |
---|
66 | ORDER BY pos ASC;'; |
---|
67 | $result = pwg_query($q); |
---|
68 | |
---|
69 | while ($row = mysql_fetch_assoc($result)) |
---|
70 | { |
---|
71 | if ($row['pos'] != '0' or is_admin()) |
---|
72 | { |
---|
73 | if (strpos($row['title'] , '/user_id=')) |
---|
74 | { |
---|
75 | $array = explode('/user_id=' , $row['title']); |
---|
76 | $row['title'] = $array[0]; |
---|
77 | $authorized_users = explode(',', $array[1]); |
---|
78 | } |
---|
79 | if (strpos($row['title'] , '/group_id=')) |
---|
80 | { |
---|
81 | $array = explode('/group_id=' , $row['title']); |
---|
82 | $row['title'] = $array[0]; |
---|
83 | $auth = explode(',', $array[1]); |
---|
84 | $authorized_groups = array_intersect($groups, $auth); |
---|
85 | } |
---|
86 | if (is_admin() and isset($ap_conf[3]) and $ap_conf[3] == 'on') |
---|
87 | { |
---|
88 | $row['title'] .= '</a> --- <a href=' . PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . AP_DIR . '%2Fadmin%2Fadd_page.php&edit=' . $row['id'] . '>[edit]'; |
---|
89 | } |
---|
90 | if (is_admin() or ( |
---|
91 | (isset($ap_conf[6]) and $ap_conf[6] == 'off' or !isset($authorized_groups) or !empty($authorized_groups)) and |
---|
92 | (isset($ap_conf[7]) and $ap_conf[7] == 'off' or !isset($authorized_users) or in_array($user['status'], $authorized_users)))) |
---|
93 | { |
---|
94 | array_push($data, array( |
---|
95 | 'URL' => PHPWG_ROOT_PATH . 'index.php?/additional_page/' . $row['id'], |
---|
96 | 'LABEL' => $row['title'])); |
---|
97 | } |
---|
98 | unset($authorized_groups); |
---|
99 | unset($authorized_users); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | if (!empty($data)) |
---|
104 | { |
---|
105 | $block->set_title(isset($menu_langs[$user['language']]) ? $menu_langs[$user['language']] : $menu_langs['default']); |
---|
106 | $block->template = 'AdditionalPages_menu.tpl'; |
---|
107 | $block->data = $data; |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | ?> |
---|