1 | <?php |
||
22 | class wizard |
||
23 | { |
||
24 | /** @var string The default BBvideo site */ |
||
25 | const BBVIDEO_DEFAULT = 'youtube.com'; |
||
26 | |||
27 | /** @var helper */ |
||
28 | protected $helper; |
||
29 | |||
30 | /** @var request */ |
||
31 | protected $request; |
||
32 | |||
33 | /** @var template */ |
||
34 | protected $template; |
||
35 | |||
36 | /** @var user */ |
||
37 | protected $user; |
||
38 | |||
39 | /** @var string */ |
||
40 | protected $ext_root_path; |
||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | * |
||
45 | * @param helper $helper Controller helper object |
||
46 | * @param request $request Request object |
||
47 | * @param template $template Template object |
||
48 | * @param user $user User object |
||
49 | * @param string $ext_root_path Path to abbc3 extension root |
||
50 | * @access public |
||
51 | */ |
||
52 | 11 | public function __construct(helper $helper, request $request, template $template, user $user, $ext_root_path) |
|
60 | |||
61 | /** |
||
62 | * BBCode wizard controller accessed with the URL /wizard/bbcode/{mode} |
||
63 | * (where {mode} is a placeholder for a string of the bbcode tag name) |
||
64 | * intended to be accessed via AJAX only |
||
65 | * |
||
66 | * @param string $mode Mode taken from the URL |
||
67 | * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object |
||
68 | * @throws \phpbb\exception\http_exception An http exception |
||
69 | * @access public |
||
70 | */ |
||
71 | 8 | public function bbcode_wizard($mode) |
|
72 | { |
||
73 | // Only allow AJAX requests |
||
74 | 8 | if ($this->request->is_ajax()) |
|
75 | 8 | { |
|
76 | switch ($mode) |
||
77 | { |
||
78 | 4 | case 'bbvideo': |
|
79 | 1 | $this->generate_bbvideo_wizard(); |
|
80 | 1 | return $this->helper->render('abbc3_bbvideo_wizard.html'); |
|
81 | // no break here |
||
82 | |||
83 | 3 | case 'url': |
|
84 | 1 | return $this->helper->render('abbc3_url_wizard.html'); |
|
85 | // no break here |
||
86 | } |
||
87 | 2 | } |
|
88 | |||
89 | 6 | throw new \phpbb\exception\http_exception(404, 'GENERAL_ERROR'); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Set template variables for the BBvideo wizard |
||
94 | * |
||
95 | * @return null |
||
96 | * @access protected |
||
97 | */ |
||
98 | 1 | protected function generate_bbvideo_wizard() |
|
99 | { |
||
100 | // Construct BBvideo allowed site select options |
||
101 | 1 | $bbvideo_sites_array = $this->load_json_data('bbvideo.json'); |
|
102 | |||
103 | // Construct BBvideo size preset select options |
||
104 | $bbvideo_size_presets_array = array( |
||
105 | 1 | array('w' => '560', 'h' => '315'), |
|
106 | 1 | array('w' => '640', 'h' => '360'), |
|
107 | 1 | array('w' => '853', 'h' => '480'), |
|
108 | 1 | array('w' => '1280', 'h' => '720'), |
|
109 | 1 | ); |
|
110 | |||
111 | 1 | $this->template->assign_vars(array( |
|
112 | 1 | 'ABBC3_BBVIDEO_SITES' => $bbvideo_sites_array, |
|
113 | 1 | 'ABBC3_BBVIDEO_LINK_EX' => (isset($bbvideo_sites_array[self::BBVIDEO_DEFAULT])) ? $bbvideo_sites_array[self::BBVIDEO_DEFAULT] : '', |
|
114 | 1 | 'ABBC3_BBVIDEO_DEFAULT' => self::BBVIDEO_DEFAULT, |
|
115 | 1 | 'ABBC3_BBVIDEO_HEIGHT' => ext::BBVIDEO_HEIGHT, |
|
116 | 1 | 'ABBC3_BBVIDEO_WIDTH' => ext::BBVIDEO_WIDTH, |
|
117 | 1 | 'ABBC3_BBVIDEO_PRESETS' => $bbvideo_size_presets_array, |
|
118 | 1 | )); |
|
119 | 1 | } |
|
120 | |||
121 | /** |
||
122 | * Return decoded JSON data from a JSON file (stored in assets/) |
||
123 | * |
||
124 | * @param string $json_file The name of the JSON file to get |
||
125 | * @return array JSON data |
||
126 | * @throws \phpbb\exception\runtime_exception |
||
127 | * @access protected |
||
128 | */ |
||
129 | 4 | protected function load_json_data($json_file) |
|
152 | } |
||
153 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.