| 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 | if (!file_exists(AP_PATH . 'template/' . $user['template'] . '.tpl')) |
|---|
| 27 | { |
|---|
| 28 | $user['template'] = 'yoga'; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | load_language('plugin.lang', AP_PATH); |
|---|
| 32 | |
|---|
| 33 | // Gestion des langues pour le nom du menu |
|---|
| 34 | $languages = explode('/', $ap_conf[0]); |
|---|
| 35 | foreach($languages as $language) |
|---|
| 36 | { |
|---|
| 37 | $array = explode(':', $language); |
|---|
| 38 | if (!isset($array[1])) $menu_langs['default'] = $array[0]; |
|---|
| 39 | else $menu_langs[$array[0]] = $array[1]; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | $data = array(); |
|---|
| 43 | |
|---|
| 44 | if (is_admin()) |
|---|
| 45 | { |
|---|
| 46 | array_push($data, array( |
|---|
| 47 | 'URL' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . AP_DIR . '%2Fadmin%2Fadd_page.php', |
|---|
| 48 | 'LABEL' => l10n('ap_add_page'))); |
|---|
| 49 | $clauses = ''; |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | $clauses = 'WHERE (lang = "' . $user['language'] . '" OR lang = "ALL")'; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | // Recup�ration des groupes de l'utilisateur |
|---|
| 57 | $q = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; |
|---|
| 58 | $result = pwg_query($q); |
|---|
| 59 | $groups = array(); |
|---|
| 60 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 61 | { |
|---|
| 62 | array_push($groups, $row['group_id']); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | // R�cup�ration des pages |
|---|
| 66 | $q = 'SELECT id , pos , title |
|---|
| 67 | FROM ' . ADD_PAGES_TABLE . ' |
|---|
| 68 | ' . $clauses . ' |
|---|
| 69 | ORDER BY pos ASC;'; |
|---|
| 70 | $result = pwg_query($q); |
|---|
| 71 | |
|---|
| 72 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 73 | { |
|---|
| 74 | if ($row['pos'] != '0' or is_admin()) |
|---|
| 75 | { |
|---|
| 76 | if (strpos($row['title'] , '/user_id=')) |
|---|
| 77 | { |
|---|
| 78 | $array = explode('/user_id=' , $row['title']); |
|---|
| 79 | $row['title'] = $array[0]; |
|---|
| 80 | $authorized_users = explode(',', $array[1]); |
|---|
| 81 | } |
|---|
| 82 | if (strpos($row['title'] , '/group_id=')) |
|---|
| 83 | { |
|---|
| 84 | $array = explode('/group_id=' , $row['title']); |
|---|
| 85 | $row['title'] = $array[0]; |
|---|
| 86 | $auth = explode(',', $array[1]); |
|---|
| 87 | $authorized_groups = array_intersect($groups, $auth); |
|---|
| 88 | } |
|---|
| 89 | if (is_admin() and isset($ap_conf[3]) and $ap_conf[3] == 'on') |
|---|
| 90 | { |
|---|
| 91 | $row['title'] .= '</a> --- <a href=' . PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . AP_DIR . '%2Fadmin%2Fadd_page.php&edit=' . $row['id'] . '>[edit]'; |
|---|
| 92 | } |
|---|
| 93 | if (is_admin() or ( |
|---|
| 94 | (isset($ap_conf[6]) and $ap_conf[6] == 'off' or !isset($authorized_groups) or !empty($authorized_groups)) and |
|---|
| 95 | (isset($ap_conf[7]) and $ap_conf[7] == 'off' or !isset($authorized_users) or in_array($user['status'], $authorized_users)))) |
|---|
| 96 | { |
|---|
| 97 | array_push($data, array( |
|---|
| 98 | 'URL' => PHPWG_ROOT_PATH . 'index.php?/additional_page/' . $row['id'], |
|---|
| 99 | 'LABEL' => $row['title'])); |
|---|
| 100 | } |
|---|
| 101 | unset($authorized_groups); |
|---|
| 102 | unset($authorized_users); |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | if (!empty($data)) |
|---|
| 107 | { |
|---|
| 108 | $block->set_title(isset($menu_langs[$user['language']]) ? $menu_langs[$user['language']] : $menu_langs['default']); |
|---|
| 109 | $block->template = dirname(__FILE__) . '/template/' . $user['template'] . '.tpl'; |
|---|
| 110 | $block->data = $data; |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | ?> |
|---|