[3609] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Additional Pages |
---|
[3825] | 4 | Version: auto |
---|
[3609] | 5 | Description: Add additional pages in menubar. |
---|
[9261] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=153 |
---|
[3609] | 7 | Author: P@t |
---|
| 8 | Author URI: http://www.gauchon.com |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | global $prefixeTable, $conf; |
---|
| 14 | |
---|
| 15 | define('AP_DIR' , basename(dirname(__FILE__))); |
---|
| 16 | define('AP_PATH' , PHPWG_PLUGINS_PATH . AP_DIR . '/'); |
---|
| 17 | define('ADD_PAGES_TABLE' , $prefixeTable . 'additionalpages'); |
---|
[16118] | 18 | define('AP_DISTRIBUED', AP_PATH . 'distribued/'); |
---|
[3609] | 19 | |
---|
[9323] | 20 | $conf['AP'] = @unserialize($conf['additional_pages']); |
---|
[9261] | 21 | |
---|
[9312] | 22 | // Need upgrade? |
---|
[9350] | 23 | if (!isset($conf['AP']['language_perm'])) |
---|
[9310] | 24 | include(AP_PATH.'admin/upgrade.inc.php'); |
---|
[9262] | 25 | |
---|
[9345] | 26 | // Unset $conf['random_index_redirect'] if homepage is defined |
---|
| 27 | if (!empty($conf['random_index_redirect']) and !is_null($conf['AP']['homepage'])) |
---|
| 28 | { |
---|
| 29 | $conf['ap_random_index_redirect'] = $conf['random_index_redirect']; |
---|
| 30 | $conf['random_index_redirect'] = array(); |
---|
| 31 | } |
---|
| 32 | |
---|
[9312] | 33 | // Admin menu |
---|
[3609] | 34 | function additional_pages_admin_menu($menu) |
---|
| 35 | { |
---|
| 36 | array_push($menu, array( |
---|
| 37 | 'NAME' => 'Additional Pages', |
---|
[9713] | 38 | 'URL' => get_root_url().'admin.php?page=plugin-'.AP_DIR, |
---|
| 39 | ) |
---|
| 40 | ); |
---|
[3609] | 41 | return $menu; |
---|
| 42 | } |
---|
| 43 | |
---|
[12502] | 44 | // common |
---|
| 45 | function ap_common_init() |
---|
[3609] | 46 | { |
---|
[9350] | 47 | if (defined('EXTENDED_DESC_PATH')) |
---|
| 48 | { |
---|
| 49 | add_event_handler('AP_render_content', 'get_extended_desc'); |
---|
| 50 | add_event_handler('AP_render_title', 'get_user_language_desc'); |
---|
| 51 | } |
---|
[12502] | 52 | } |
---|
[9350] | 53 | |
---|
[12502] | 54 | // Section init |
---|
| 55 | function section_init_additional_page() |
---|
| 56 | { |
---|
| 57 | global $tokens, $conf, $page; |
---|
| 58 | |
---|
[9272] | 59 | $page['ap_homepage'] = (count($tokens) == 1 and empty($tokens[0])); |
---|
[3609] | 60 | |
---|
[9323] | 61 | if (($tokens[0] == 'page' and !empty($tokens[1])) or ($page['ap_homepage'] and !is_null($conf['AP']['homepage']))) |
---|
[9261] | 62 | include(AP_PATH . 'additional_page.php'); |
---|
| 63 | |
---|
| 64 | if ($tokens[0] == 'additional_page' and !empty($tokens[1])) |
---|
[9660] | 65 | redirect(make_index_url(array('section'=>'page')).'/'.$tokens[1]); |
---|
[11574] | 66 | |
---|
| 67 | if (!is_null($conf['AP']['homepage'])) |
---|
| 68 | { |
---|
| 69 | $albums_url = make_index_url(array('section' => 'categories')); |
---|
| 70 | |
---|
| 71 | $page['title'] = preg_replace( |
---|
| 72 | '#/a>#', |
---|
| 73 | '/a>'.$conf['level_separator'].'<a href="'.$albums_url.'">'.l10n('Albums').'</a>', |
---|
| 74 | $page['title'], |
---|
| 75 | 1 // only replace the first occurence of "a/>" |
---|
| 76 | ); |
---|
| 77 | } |
---|
[3609] | 78 | } |
---|
| 79 | |
---|
[9312] | 80 | // Menubar |
---|
[9310] | 81 | function register_ap_menubar_blocks($menu_ref_arr) |
---|
| 82 | { |
---|
[9351] | 83 | global $conf, $user; |
---|
| 84 | |
---|
[9310] | 85 | $menu = & $menu_ref_arr[0]; |
---|
| 86 | if ($menu->get_id() != 'menubar') return; |
---|
[9351] | 87 | |
---|
| 88 | $conf['AP']['block_title'] = isset($conf['AP']['languages'][$user['language']]) ? |
---|
| 89 | $conf['AP']['languages'][$user['language']] : @$conf['AP']['languages']['default']; |
---|
| 90 | |
---|
| 91 | if (empty($conf['AP']['block_title'])) |
---|
| 92 | $conf['AP']['block_title'] = 'Additional Pages'; |
---|
| 93 | |
---|
| 94 | $menu->register_block( new RegisteredBlock( 'mbAdditionalPages', $conf['AP']['block_title'], 'Additional Pages')); |
---|
[9310] | 95 | } |
---|
[9261] | 96 | |
---|
[9310] | 97 | function ap_apply($menu_ref_arr) |
---|
| 98 | { |
---|
| 99 | global $template, $conf, $user; |
---|
| 100 | |
---|
| 101 | $menu = & $menu_ref_arr[0]; |
---|
| 102 | |
---|
| 103 | if ( ($block = $menu->get_block( 'mbAdditionalPages' ) ) != null ) |
---|
| 104 | { |
---|
[9312] | 105 | $query = 'SELECT DISTINCT id, title, permalink |
---|
[9310] | 106 | FROM ' . ADD_PAGES_TABLE . ' |
---|
| 107 | LEFT JOIN ' . USER_GROUP_TABLE . ' |
---|
| 108 | ON user_id = '.$user['id'].' |
---|
[9312] | 109 | WHERE (lang IS NULL OR lang = "'.$user['language'].'") |
---|
[9310] | 110 | AND (users IS NULL OR users LIKE "%'.$user['status'].'%") |
---|
| 111 | AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)")) |
---|
| 112 | AND level <= '.$user['level'].' |
---|
| 113 | AND pos >= 0 |
---|
| 114 | ORDER BY pos ASC |
---|
| 115 | ;'; |
---|
| 116 | $result = pwg_query($query); |
---|
| 117 | $data = array(); |
---|
| 118 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 119 | { |
---|
[9660] | 120 | $url = make_index_url(array('section'=>'page')).'/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']); |
---|
[9350] | 121 | array_push($data, array('URL' => $url, 'LABEL' => trigger_event('AP_render_title', $row['title']))); |
---|
[9310] | 122 | } |
---|
| 123 | |
---|
| 124 | if (!empty($data)) |
---|
| 125 | { |
---|
| 126 | $template->set_template_dir(AP_PATH.'template/'); |
---|
[9351] | 127 | $block->set_title($conf['AP']['block_title']); |
---|
[9310] | 128 | $block->template = 'menubar_additional_pages.tpl'; |
---|
| 129 | $block->data = $data; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
[3609] | 134 | add_event_handler('get_admin_plugin_menu_links', 'additional_pages_admin_menu'); |
---|
[12502] | 135 | add_event_handler('init', 'ap_common_init'); |
---|
[3609] | 136 | add_event_handler('loc_end_section_init', 'section_init_additional_page'); |
---|
[9310] | 137 | add_event_handler('blockmanager_register_blocks', 'register_ap_menubar_blocks'); |
---|
| 138 | add_event_handler('blockmanager_apply', 'ap_apply'); |
---|
[3609] | 139 | |
---|
[3292] | 140 | ?> |
---|