1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\acp; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
13
|
|
|
use blitze\sitemaker\services\menus\nestedset; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @package acp |
17
|
|
|
*/ |
18
|
|
|
class menu_module |
19
|
|
|
{ |
20
|
|
|
/** @var \phpbb\controller\helper */ |
21
|
|
|
protected $controller_helper; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\event\dispatcher_interface */ |
24
|
|
|
protected $phpbb_dispatcher; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\request\request_interface */ |
27
|
|
|
protected $request; |
28
|
|
|
|
29
|
|
|
/** @var \phpbb\template\template */ |
30
|
|
|
protected $template; |
31
|
|
|
|
32
|
|
|
/** @var \blitze\sitemaker\services\icon_picker */ |
33
|
|
|
protected $icon; |
34
|
|
|
|
35
|
|
|
/** @var \blitze\sitemaker\model\mapper_factory */ |
36
|
|
|
protected $mapper_factory; |
37
|
|
|
|
38
|
|
|
/** @var \blitze\sitemaker\services\util */ |
39
|
|
|
protected $util; |
40
|
|
|
|
41
|
|
|
/** @var string phpBB root path */ |
42
|
|
|
protected $phpbb_root_path; |
43
|
|
|
|
44
|
|
|
/** @var string phpEx */ |
45
|
|
|
protected $php_ext; |
46
|
|
|
|
47
|
|
|
/** @var string */ |
48
|
|
|
public $tpl_name; |
49
|
|
|
|
50
|
|
|
/** @var string */ |
51
|
|
|
public $page_title; |
52
|
|
|
|
53
|
|
|
/** @var string */ |
54
|
|
|
public $u_action; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* menu_module constructor. |
58
|
|
|
*/ |
59
|
2 |
|
public function __construct() |
60
|
|
|
{ |
61
|
2 |
|
global $phpbb_container, $phpbb_dispatcher, $request, $template, $phpbb_root_path, $phpEx; |
|
|
|
|
62
|
|
|
|
63
|
2 |
|
$this->phpbb_dispatcher = $phpbb_dispatcher; |
64
|
2 |
|
$this->request = $request; |
65
|
2 |
|
$this->template = $template; |
66
|
2 |
|
$this->phpbb_root_path = $phpbb_root_path; |
67
|
2 |
|
$this->php_ext = $phpEx; |
68
|
|
|
|
69
|
2 |
|
$this->controller_helper = $phpbb_container->get('controller.helper'); |
70
|
2 |
|
$this->mapper_factory = $phpbb_container->get('blitze.sitemaker.mapper.factory'); |
71
|
2 |
|
$this->icon = $phpbb_container->get('blitze.sitemaker.icon_picker'); |
72
|
2 |
|
$this->util = $phpbb_container->get('blitze.sitemaker.util'); |
73
|
2 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
2 |
|
public function main() |
79
|
|
|
{ |
80
|
2 |
|
$menu_id = $this->request->variable('menu_id', 0); |
81
|
|
|
|
82
|
2 |
|
nestedset::load_scripts($this->util); |
83
|
2 |
|
$this->util->add_assets(array( |
84
|
2 |
|
'js' => array('@blitze_sitemaker/assets/menu/admin.min.js'), |
85
|
2 |
|
'css' => array('@blitze_sitemaker/assets/menu/admin.min.css') |
86
|
2 |
|
)); |
87
|
|
|
|
88
|
2 |
|
$this->list_menus($menu_id); |
89
|
2 |
|
$this->build_bulk_options(); |
90
|
|
|
|
91
|
2 |
|
$this->template->assign_vars(array( |
92
|
2 |
|
'S_MENU' => true, |
93
|
2 |
|
'MENU_ID' => $menu_id, |
94
|
2 |
|
'ICON_PICKER' => $this->icon->picker(), |
95
|
2 |
|
'T_PATH' => $this->phpbb_root_path, |
96
|
2 |
|
'UA_AJAX_URL' => $this->controller_helper->route('blitze_sitemaker_menus_admin', array(), true, '') . '/', |
97
|
2 |
|
)); |
98
|
|
|
|
99
|
2 |
|
$this->tpl_name = 'acp_menu'; |
100
|
2 |
|
$this->page_title = 'ACP_MENU'; |
101
|
2 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param int $menu_id |
105
|
|
|
* @return void |
106
|
|
|
*/ |
107
|
2 |
|
protected function list_menus(&$menu_id) |
108
|
|
|
{ |
109
|
2 |
|
$menu_mapper = $this->mapper_factory->create('menus'); |
110
|
|
|
|
111
|
|
|
// Get all menus |
112
|
2 |
|
$collection = $menu_mapper->find(); |
113
|
|
|
|
114
|
2 |
|
if ($collection->valid()) |
115
|
2 |
|
{ |
116
|
2 |
|
$menu = (isset($collection[$menu_id])) ? $collection[$menu_id] : $collection->current(); |
117
|
2 |
|
$menu_id = $menu->get_menu_id(); |
118
|
|
|
|
119
|
2 |
|
foreach ($collection as $entity) |
120
|
|
|
{ |
121
|
2 |
|
$id = $entity->get_menu_id(); |
122
|
2 |
|
$this->template->assign_block_vars('menu', array( |
123
|
2 |
|
'ID' => $id, |
124
|
2 |
|
'NAME' => $entity->get_menu_name(), |
125
|
2 |
|
'S_ACTIVE' => ($id == $menu_id) ? true : false, |
126
|
2 |
|
)); |
127
|
2 |
|
} |
128
|
2 |
|
} |
129
|
2 |
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return void |
133
|
|
|
*/ |
134
|
2 |
|
protected function build_bulk_options() |
135
|
|
|
{ |
136
|
2 |
|
$bulk_options = array(); |
137
|
2 |
|
$forumslist = make_forum_select(false, false, true, false, false, false, true); |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Event to add bulk menu options |
141
|
|
|
* |
142
|
|
|
* @event blitze_sitemaker.acp_add_bulk_menu_options |
143
|
|
|
* @var array bulk_options Array of bulk menu options |
144
|
|
|
* @since 3.1.0-RC1 |
145
|
|
|
*/ |
146
|
2 |
|
$vars = array('bulk_options', 'forumslist'); |
147
|
2 |
|
extract($this->phpbb_dispatcher->trigger_event('blitze_sitemaker.acp_add_bulk_menu_options', compact($vars))); |
|
|
|
|
148
|
|
|
|
149
|
2 |
|
$bulk_options['FORUMS'] = $this->get_forums_string($forumslist); |
150
|
|
|
|
151
|
2 |
|
$this->template->assign_var('bulk_options', $bulk_options); |
152
|
2 |
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param array $forumslist |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
2 |
|
protected function get_forums_string(array $forumslist) |
159
|
|
|
{ |
160
|
2 |
|
$text = ''; |
161
|
2 |
|
foreach ($forumslist as $forum_id => $row) |
162
|
|
|
{ |
163
|
2 |
|
$text .= str_replace(' ', "\t", $row['padding']); |
164
|
2 |
|
$text .= $row['forum_name'] . '|'; |
165
|
2 |
|
$text .= "viewforum.{$this->php_ext}?f=$forum_id\n"; |
166
|
2 |
|
} |
167
|
|
|
|
168
|
2 |
|
return trim($text); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state