1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Topic Preview |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2016 Matt Friedman |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace vse\topicpreview\core\trim; |
12
|
|
|
|
13
|
|
|
class manager |
14
|
|
|
{ |
15
|
|
|
/** @var array Array of tools from the service collection */ |
16
|
|
|
protected $tools = array(); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Constructor |
20
|
|
|
* |
21
|
|
|
* @param array $tools Array of tools from the service collection |
22
|
|
|
* @access public |
23
|
|
|
*/ |
24
|
|
|
public function __construct($tools) |
25
|
|
|
{ |
26
|
|
|
$this->tools = $tools; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get all available tools |
31
|
|
|
* |
32
|
|
|
* @return array Array of available tools |
33
|
|
|
*/ |
34
|
|
|
public function get_tools() |
35
|
|
|
{ |
36
|
|
|
$tools = array(); |
37
|
|
|
|
38
|
|
|
/** @var tools\tool_interface $tool */ |
39
|
|
|
foreach ($this->tools as $tool) |
40
|
|
|
{ |
41
|
|
|
if ($tool->is_available()) |
42
|
|
|
{ |
43
|
|
|
$tools[$tool->get_name()] = $tool; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$tools = $this->order_tools($tools); |
48
|
|
|
|
49
|
|
|
return $tools; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get tool by name |
54
|
|
|
* |
55
|
|
|
* @param string $name |
56
|
|
|
* @return null|tools\tool_interface |
57
|
|
|
*/ |
58
|
|
|
public function get_tool($name) |
59
|
|
|
{ |
60
|
|
|
/** @var tools\tool_interface $tool */ |
61
|
|
|
foreach ($this->tools as $tool) |
62
|
|
|
{ |
63
|
|
|
if ($tool->get_name() == $name) |
64
|
|
|
{ |
65
|
|
|
return $tool; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Configure tools in the proper order and remove |
74
|
|
|
* any conflicting tools |
75
|
|
|
* |
76
|
|
|
* @param $tools array Array of available tools |
77
|
|
|
* @return array Array of available tools |
78
|
|
|
*/ |
79
|
|
|
protected function order_tools(array $tools) |
80
|
|
|
{ |
81
|
|
|
if (isset($tools['remove_bbcodes'])) |
82
|
|
|
{ |
83
|
|
|
unset($tools['remove_bbcodes_legacy']); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
ksort($tools, SORT_STRING); |
87
|
|
|
|
88
|
|
|
return $tools; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|