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

Revision 28649, 4.3 KB checked in by mistic100, 5 years ago (diff)

use trigger_change

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/');
24define('AP_BACKUP_DIR', PHPWG_ROOT_PATH . $conf['data_location'] . 'additional_pages_backup/');
25
26$conf['AP'] = @unserialize($conf['additional_pages']);
27
28// Need upgrade?
29if (!isset($conf['AP']['language_perm']))
30  include(AP_PATH.'admin/upgrade.inc.php');
31
32// Unset $conf['random_index_redirect'] if homepage is defined
33if (!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
39// Admin menu
40function additional_pages_admin_menu($menu)
41{
42    array_push($menu, array(
43      'NAME' => 'Additional Pages',
44      'URL' => get_root_url().'admin.php?page=plugin-'.AP_DIR,
45      )
46    );
47    return $menu;
48}
49
50// common
51function ap_common_init()
52{
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  }
58}
59
60// Section init
61function section_init_additional_page()
62{
63  global $tokens, $conf, $page;
64
65  $page['ap_homepage'] = (count($tokens) == 1 and empty($tokens[0]));
66
67  if (($tokens[0] == 'page' and !empty($tokens[1])) or ($page['ap_homepage'] and !is_null($conf['AP']['homepage'])))
68    include(AP_PATH . 'additional_page.php');
69
70  if ($tokens[0] == 'additional_page' and !empty($tokens[1]))
71    redirect(make_index_url(array('section'=>'page')).'/'.$tokens[1]);
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  }
84}
85
86// Menubar
87function register_ap_menubar_blocks($menu_ref_arr)
88{
89  global $conf, $user;
90
91  $menu = & $menu_ref_arr[0];
92  if ($menu->get_id() != 'menubar') return;
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'));
101}
102
103function 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  {
111    $query = 'SELECT DISTINCT id, title, permalink
112FROM ' . ADD_PAGES_TABLE . '
113LEFT JOIN ' . USER_GROUP_TABLE . '
114  ON user_id = '.$user['id'].'
115WHERE (lang IS NULL OR lang = "'.$user['language'].'")
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
120ORDER BY pos ASC
121;';
122    $result = pwg_query($query);
123    $data = array();
124    while ($row = pwg_db_fetch_assoc($result))
125    {
126      $url = make_index_url(array('section'=>'page')).'/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
127      array_push($data, array('URL' => $url, 'LABEL' => trigger_change('AP_render_title', $row['title'])));
128    }
129
130    if (!empty($data))
131    {
132      $template->set_template_dir(AP_PATH.'template/');
133      $block->set_title($conf['AP']['block_title']);
134      $block->template = 'menubar_additional_pages.tpl';
135      $block->data = $data;
136    }
137  }
138}
139
140add_event_handler('get_admin_plugin_menu_links', 'additional_pages_admin_menu');
141add_event_handler('init', 'ap_common_init');
142add_event_handler('loc_end_section_init', 'section_init_additional_page');
143add_event_handler('blockmanager_register_blocks', 'register_ap_menubar_blocks');
144add_event_handler('blockmanager_apply', 'ap_apply');
145
146?>
Note: See TracBrowser for help on using the repository browser.