1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Advanced BBCode Box |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2013 Matt Friedman |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace vse\abbc3\controller; |
12
|
|
|
|
13
|
|
|
use phpbb\cache\driver\driver_interface as cache_driver; |
14
|
|
|
use phpbb\controller\helper; |
15
|
|
|
use phpbb\request\request; |
16
|
|
|
use phpbb\template\template; |
17
|
|
|
use phpbb\textformatter\s9e\factory as textformatter; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ABBC3 BBCode Wizard class |
21
|
|
|
*/ |
22
|
|
|
class wizard |
23
|
|
|
{ |
24
|
|
|
/** @var string The default BBvideo site */ |
25
|
|
|
const BBVIDEO_DEFAULT = 'youtube'; |
26
|
|
|
|
27
|
|
|
/** @var cache_driver */ |
28
|
|
|
protected $cache; |
29
|
|
|
|
30
|
|
|
/** @var helper */ |
31
|
|
|
protected $helper; |
32
|
|
|
|
33
|
|
|
/** @var request */ |
34
|
|
|
protected $request; |
35
|
|
|
|
36
|
|
|
/** @var template */ |
37
|
|
|
protected $template; |
38
|
|
|
|
39
|
|
|
/** @var textformatter */ |
40
|
|
|
protected $textformatter; |
41
|
|
|
|
42
|
|
|
/** @var string */ |
43
|
|
|
protected $ext_root_path; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor |
47
|
13 |
|
* |
48
|
|
|
* @param cache_driver $cache Cache driver |
49
|
13 |
|
* @param helper $helper Controller helper object |
50
|
13 |
|
* @param request $request Request object |
51
|
13 |
|
* @param template $template Template object |
52
|
13 |
|
* @param textformatter $textformatter TextFormatter Factory |
53
|
13 |
|
* @param string $ext_root_path Path to abbc3 extension root |
54
|
|
|
* @access public |
55
|
|
|
*/ |
56
|
|
|
public function __construct(cache_driver $cache, helper $helper, request $request, template $template, textformatter $textformatter, $ext_root_path) |
57
|
|
|
{ |
58
|
|
|
$this->cache = $cache; |
59
|
|
|
$this->helper = $helper; |
60
|
|
|
$this->request = $request; |
61
|
|
|
$this->template = $template; |
62
|
|
|
$this->textformatter = $textformatter; |
63
|
|
|
$this->ext_root_path = $ext_root_path; |
64
|
|
|
} |
65
|
|
|
|
66
|
10 |
|
/** |
67
|
|
|
* BBCode wizard controller accessed with the URL /wizard/bbcode/{mode} |
68
|
|
|
* (where {mode} is a placeholder for a string of the bbcode tag name) |
69
|
10 |
|
* intended to be accessed via AJAX only |
70
|
10 |
|
* |
71
|
3 |
|
* @param string $mode Mode taken from the URL |
72
|
3 |
|
* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object |
73
|
1 |
|
* @throws \phpbb\exception\http_exception An http exception |
74
|
1 |
|
* @throws \phpbb\exception\runtime_exception Runtime exception if JSON fails |
75
|
|
|
* @access public |
76
|
3 |
|
*/ |
77
|
|
|
public function bbcode_wizard($mode) |
78
|
|
|
{ |
79
|
7 |
|
// Only allow valid AJAX requests |
80
|
|
|
if ($this->request->is_ajax() && in_array($mode, array('bbvideo', 'pipes', 'url'))) |
81
|
|
|
{ |
82
|
|
|
if ($mode === 'bbvideo') |
83
|
|
|
{ |
84
|
|
|
$this->generate_bbvideo_wizard(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->helper->render("abbc3_{$mode}_wizard.html"); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
throw new \phpbb\exception\http_exception(404, 'GENERAL_ERROR'); |
91
|
1 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set template variables for the BBvideo wizard |
95
|
1 |
|
* |
96
|
1 |
|
* @access protected |
97
|
1 |
|
*/ |
98
|
1 |
|
protected function generate_bbvideo_wizard() |
99
|
1 |
|
{ |
100
|
|
|
if (($bbvideo_sites = $this->cache->get('bbvideo_sites')) === false) |
101
|
1 |
|
{ |
102
|
1 |
|
$configurator = $this->textformatter->get_configurator(); |
103
|
1 |
|
foreach ($configurator->MediaEmbed->defaultSites as $siteId => $siteConfig) |
104
|
1 |
|
{ |
105
|
1 |
|
if (!isset($configurator->BBCodes[$siteId])) |
106
|
1 |
|
{ |
107
|
1 |
|
$bbvideo_sites[$siteId] = isset($siteConfig['example']) ? current((array) $siteConfig['example']) : ''; |
108
|
1 |
|
} |
109
|
1 |
|
} |
110
|
|
|
|
111
|
|
|
$this->cache->put('bbvideo_sites', $bbvideo_sites); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$this->template->assign_vars(array( |
115
|
|
|
'ABBC3_BBVIDEO_SITES' => $bbvideo_sites, |
116
|
|
|
'ABBC3_BBVIDEO_LINK_EX' => isset($bbvideo_sites[self::BBVIDEO_DEFAULT]) ? $bbvideo_sites[self::BBVIDEO_DEFAULT] : '', |
117
|
|
|
'ABBC3_BBVIDEO_DEFAULT' => self::BBVIDEO_DEFAULT, |
118
|
|
|
)); |
119
|
4 |
|
} |
120
|
|
|
} |
121
|
|
|
|