source: extensions/AdditionalPages/trunk/main.inc.php @ 16247

Last change on this file since 16247 was 16247, checked in by plg, 12 years ago

bypass Additional Pages when SmartPocket is active

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