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