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