1 | <?php |
||
16 | class main_module |
||
17 | { |
||
18 | /** @var \phpbb\cache\driver\driver_interface $cache */ |
||
19 | protected $cache; |
||
20 | |||
21 | /** @var \phpbb\config\config $config */ |
||
22 | protected $config; |
||
23 | |||
24 | /** @var \phpbb\config\db_text $config_text */ |
||
25 | protected $config_text; |
||
26 | |||
27 | /** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */ |
||
28 | protected $container; |
||
29 | |||
30 | /** @var \phpbb\language\language $language */ |
||
31 | protected $language; |
||
32 | |||
33 | /** @var \phpbb\log\log $log */ |
||
34 | protected $log; |
||
35 | |||
36 | /** @var \phpbb\request\request $request */ |
||
37 | protected $request; |
||
38 | |||
39 | /** @var \phpbb\template\template $template */ |
||
40 | protected $template; |
||
41 | |||
42 | /** @var \phpbb\user */ |
||
43 | protected $user; |
||
44 | |||
45 | /** @var array $enabled_sites */ |
||
46 | protected $enabled_sites; |
||
47 | |||
48 | /** @var string $form_key */ |
||
49 | protected $form_key; |
||
50 | |||
51 | /** @var string $page_title */ |
||
52 | public $page_title; |
||
53 | |||
54 | /** @var string $tpl_name */ |
||
55 | public $tpl_name; |
||
56 | |||
57 | /** @var string $u_action */ |
||
58 | public $u_action; |
||
59 | |||
60 | /** |
||
61 | * Constructor |
||
62 | */ |
||
63 | public function __construct() |
||
80 | |||
81 | /** |
||
82 | * Main ACP module |
||
83 | * |
||
84 | * @param int $id The module ID |
||
85 | * @param string $mode The module mode |
||
86 | */ |
||
87 | public function main($id, $mode) |
||
88 | { |
||
89 | $mode = strtolower($mode); |
||
90 | |||
91 | $this->tpl_name = 'acp_phpbb_mediaembed_' . $mode; |
||
92 | $this->page_title = $this->language->lang('ACP_MEDIA_' . strtoupper($mode)); |
||
93 | |||
94 | add_form_key($this->form_key); |
||
95 | |||
96 | if ($this->request->is_set_post('submit')) |
||
97 | { |
||
98 | $this->{'save_' . $mode}(); |
||
99 | } |
||
100 | |||
101 | $this->{'display_' . $mode}(); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Add settings template vars to the form |
||
106 | */ |
||
107 | protected function display_settings() |
||
108 | { |
||
109 | $this->template->assign_vars([ |
||
110 | 'S_MEDIA_EMBED_BBCODE' => $this->config['media_embed_bbcode'], |
||
111 | 'S_MEDIA_EMBED_ALLOW_SIG' => $this->config['media_embed_allow_sig'], |
||
112 | 'U_ACTION' => $this->u_action, |
||
113 | ]); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Add manage sites template vars to the form |
||
118 | */ |
||
119 | protected function display_manage() |
||
120 | { |
||
121 | $this->template->assign_vars([ |
||
122 | 'MEDIA_SITES' => $this->get_sites(), |
||
123 | 'U_ACTION' => $this->u_action, |
||
124 | ]); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Get a list of available sites |
||
129 | * |
||
130 | * @return array An array of available sites |
||
131 | */ |
||
132 | protected function get_sites() |
||
153 | |||
154 | /** |
||
155 | * Get enabled media sites stored in the database |
||
156 | * |
||
157 | * @return array An array of enabled sites |
||
158 | */ |
||
159 | protected function get_enabled_sites() |
||
169 | |||
170 | /** |
||
171 | * Save site managed data to the database |
||
172 | */ |
||
173 | protected function save_manage() |
||
186 | |||
187 | /** |
||
188 | * Save settings data to the database |
||
189 | */ |
||
190 | protected function save_settings() |
||
201 | |||
202 | /** |
||
203 | * Check the form key, trigger error if invalid |
||
204 | */ |
||
205 | protected function check_form_key() |
||
212 | } |
||
213 |
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