[3609] | 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; |
---|
[9261] | 13 | $menu->register_block( new RegisteredBlock( 'mbAdditionalPages', 'Additional Pages', 'P@t')); |
---|
[3609] | 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 | { |
---|
[6227] | 24 | $template->set_template_dir(AP_PATH.'template/'); |
---|
[3609] | 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 |
---|
[9261] | 40 | $q = 'SELECT id, pos, title, users, groups, permalink |
---|
[3609] | 41 | FROM ' . ADD_PAGES_TABLE . ' |
---|
[9261] | 42 | WHERE (lang = "' . $user['language'] . '" OR lang IS NULL) |
---|
[9262] | 43 | AND pos >= 0 |
---|
[9261] | 44 | ORDER BY pos ASC, id ASC |
---|
| 45 | ;'; |
---|
[3609] | 46 | $result = pwg_query($q); |
---|
| 47 | |
---|
| 48 | while ($row = mysql_fetch_assoc($result)) |
---|
| 49 | { |
---|
| 50 | if ($row['pos'] != '0' or is_admin()) |
---|
| 51 | { |
---|
[9261] | 52 | $authorized_users = array(); |
---|
| 53 | $authorized_groups = array(); |
---|
| 54 | if (!empty($row['users'])) |
---|
[3609] | 55 | { |
---|
[9261] | 56 | $authorized_users = explode(',', $row['users']); |
---|
[3609] | 57 | } |
---|
[9261] | 58 | if (!empty($row['groups'])) |
---|
[3609] | 59 | { |
---|
[9261] | 60 | $auth = explode(',', $row['groups']); |
---|
[3609] | 61 | $authorized_groups = array_intersect($groups, $auth); |
---|
| 62 | } |
---|
| 63 | if (is_admin() or ( |
---|
[9261] | 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)))) |
---|
[3609] | 66 | { |
---|
[9272] | 67 | $url = make_index_url(); |
---|
| 68 | if ($row['id'] != $conf['additional_pages']['homepage']) |
---|
| 69 | { |
---|
| 70 | $url .= '/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']); |
---|
| 71 | } |
---|
[3609] | 72 | array_push($data, array( |
---|
[9272] | 73 | 'URL' => $url, |
---|
[3609] | 74 | 'LABEL' => $row['title'])); |
---|
| 75 | } |
---|
| 76 | unset($authorized_groups); |
---|
| 77 | unset($authorized_users); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | if (!empty($data)) |
---|
| 82 | { |
---|
[9261] | 83 | $block->set_title( |
---|
| 84 | isset($conf['additional_pages']['languages'][$user['language']]) ? |
---|
| 85 | $conf['additional_pages']['languages'][$user['language']] : |
---|
| 86 | @$conf['additional_pages']['languages']['default'] |
---|
| 87 | ); |
---|
[6227] | 88 | $block->template = 'AdditionalPages_menu.tpl'; |
---|
[3609] | 89 | $block->data = $data; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
[3292] | 93 | ?> |
---|