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