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', 'P@t')); |
---|
14 | } |
---|
15 | |
---|
16 | function ap_apply($menu_ref_arr) |
---|
17 | { |
---|
18 | global $template, $conf, $user, $lang; |
---|
19 | |
---|
20 | $menu = & $menu_ref_arr[0]; |
---|
21 | |
---|
22 | if ( ($block = $menu->get_block( 'mbAdditionalPages' ) ) != null ) |
---|
23 | { |
---|
24 | $template->set_template_dir(AP_PATH.'template/'); |
---|
25 | |
---|
26 | load_language('plugin.lang', AP_PATH); |
---|
27 | |
---|
28 | $data = array(); |
---|
29 | |
---|
30 | // Recupération des groupes de l'utilisateur |
---|
31 | $q = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; |
---|
32 | $result = pwg_query($q); |
---|
33 | $groups = array(); |
---|
34 | while ($row = mysql_fetch_assoc($result)) |
---|
35 | { |
---|
36 | array_push($groups, $row['group_id']); |
---|
37 | } |
---|
38 | |
---|
39 | // Récupération des pages |
---|
40 | $q = 'SELECT id, pos, title, users, groups, permalink |
---|
41 | FROM ' . ADD_PAGES_TABLE . ' |
---|
42 | WHERE (lang = "' . $user['language'] . '" OR lang IS NULL) |
---|
43 | AND pos >= 0 |
---|
44 | ORDER BY pos ASC, id ASC |
---|
45 | ;'; |
---|
46 | $result = pwg_query($q); |
---|
47 | |
---|
48 | while ($row = mysql_fetch_assoc($result)) |
---|
49 | { |
---|
50 | if ($row['pos'] != '0' or is_admin()) |
---|
51 | { |
---|
52 | $authorized_users = array(); |
---|
53 | $authorized_groups = array(); |
---|
54 | if (!empty($row['users'])) |
---|
55 | { |
---|
56 | $authorized_users = explode(',', $row['users']); |
---|
57 | } |
---|
58 | if (!empty($row['groups'])) |
---|
59 | { |
---|
60 | $auth = explode(',', $row['groups']); |
---|
61 | $authorized_groups = array_intersect($groups, $auth); |
---|
62 | } |
---|
63 | if (is_admin() or ( |
---|
64 | (!$conf['additional_pages']['group_perm'] or empty($row['groups']) or !empty($authorized_groups)) and |
---|
65 | (!$conf['additional_pages']['user_perm'] or empty($row['users']) or in_array($user['status'], $authorized_users)))) |
---|
66 | { |
---|
67 | array_push($data, array( |
---|
68 | 'URL' => make_index_url().'/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']), |
---|
69 | 'LABEL' => $row['title'])); |
---|
70 | } |
---|
71 | unset($authorized_groups); |
---|
72 | unset($authorized_users); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | if (!empty($data)) |
---|
77 | { |
---|
78 | $block->set_title( |
---|
79 | isset($conf['additional_pages']['languages'][$user['language']]) ? |
---|
80 | $conf['additional_pages']['languages'][$user['language']] : |
---|
81 | @$conf['additional_pages']['languages']['default'] |
---|
82 | ); |
---|
83 | $block->template = 'AdditionalPages_menu.tpl'; |
---|
84 | $block->data = $data; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | ?> |
---|