| 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 | $authorized_users = array(); |
|---|
| 51 | $authorized_groups = array(); |
|---|
| 52 | if (!empty($row['users'])) |
|---|
| 53 | { |
|---|
| 54 | $authorized_users = explode(',', $row['users']); |
|---|
| 55 | } |
|---|
| 56 | if (!empty($row['groups'])) |
|---|
| 57 | { |
|---|
| 58 | $auth = explode(',', $row['groups']); |
|---|
| 59 | $authorized_groups = array_intersect($groups, $auth); |
|---|
| 60 | } |
|---|
| 61 | if (is_admin() or ( |
|---|
| 62 | (!$conf['additional_pages']['group_perm'] or empty($row['groups']) or !empty($authorized_groups)) and |
|---|
| 63 | (!$conf['additional_pages']['user_perm'] or empty($row['users']) or in_array($user['status'], $authorized_users)))) |
|---|
| 64 | { |
|---|
| 65 | $url = make_index_url(); |
|---|
| 66 | if ($row['id'] != $conf['additional_pages']['homepage']) |
|---|
| 67 | { |
|---|
| 68 | $url .= '/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']); |
|---|
| 69 | } |
|---|
| 70 | array_push($data, array( |
|---|
| 71 | 'URL' => $url, |
|---|
| 72 | 'LABEL' => $row['title'])); |
|---|
| 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 | ?> |
|---|