1 <?php
2
3 4 5 6 7 8 9
10 class rex_plugin extends rex_package implements rex_plugin_interface
11 {
12 13 14 15 16
17 private $addon;
18
19 20 21 22 23 24
25 public function __construct($name, rex_addon $addon)
26 {
27 parent::__construct($name);
28 $this->addon = $addon;
29 }
30
31 32 33 34 35 36 37 38 39 40
41 public static function get($addon, $plugin = null)
42 {
43 if ($plugin === null) {
44 throw new InvalidArgumentException('Missing Argument 2 for ' . self::class . '::' . __METHOD__ . '()');
45 }
46 if (!is_string($addon)) {
47 throw new InvalidArgumentException('Expecting $addon to be string, but ' . gettype($addon) . ' given!');
48 }
49 if (!is_string($plugin)) {
50 throw new InvalidArgumentException('Expecting $plugin to be string, but ' . gettype($plugin) . ' given!');
51 }
52 return rex_addon::get($addon)->getPlugin($plugin);
53 }
54
55 56 57 58 59 60 61 62
63 public static function exists($addon, $plugin = null)
64 {
65 return rex_addon::exists($addon) && rex_addon::get($addon)->pluginExists($plugin);
66 }
67
68 69 70
71 public function getAddon()
72 {
73 return $this->addon;
74 }
75
76 77 78
79 public function getPackageId()
80 {
81 return $this->getAddon()->getName() . '/' . $this->getName();
82 }
83
84 85 86
87 public function getType()
88 {
89 return 'plugin';
90 }
91
92 93 94
95 public function getPath($file = '')
96 {
97 return rex_path::plugin($this->getAddon()->getName(), $this->getName(), $file);
98 }
99
100 101 102
103 public function getAssetsPath($file = '')
104 {
105 return rex_path::pluginAssets($this->getAddon()->getName(), $this->getName(), $file);
106 }
107
108 109 110
111 public function getAssetsUrl($file = '')
112 {
113 return rex_url::pluginAssets($this->getAddon()->getName(), $this->getName(), $file);
114 }
115
116 117 118
119 public function getDataPath($file = '')
120 {
121 return rex_path::pluginData($this->getAddon()->getName(), $this->getName(), $file);
122 }
123
124 125 126
127 public function getCachePath($file = '')
128 {
129 return rex_path::pluginCache($this->getAddon()->getName(), $this->getName(), $file);
130 }
131
132 133 134
135 public function isAvailable()
136 {
137 return $this->getAddon()->isAvailable() && parent::isAvailable();
138 }
139
140 141 142
143 public function isSystemPackage()
144 {
145 return in_array($this->getName(), (array) $this->addon->getProperty('system_plugins', []));
146 }
147
148 149 150
151 public function i18n($key)
152 {
153 $args = func_get_args();
154 $key = $this->getAddon()->getName() . '_' . $this->getName() . '_' . $key;
155 if (rex_i18n::hasMsgOrFallback($key)) {
156 $args[0] = $key;
157 return call_user_func_array('rex_i18n::msg', $args);
158 }
159 return call_user_func_array([$this->getAddon(), 'i18n'], $args);
160 }
161
162 163 164 165 166 167 168
169 public static function getRegisteredPlugins($addon)
170 {
171 return rex_addon::get($addon)->getRegisteredPlugins();
172 }
173
174 175 176 177 178 179 180
181 public static function getInstalledPlugins($addon)
182 {
183 return rex_addon::get($addon)->getInstalledPlugins();
184 }
185
186 187 188 189 190 191 192
193 public static function getAvailablePlugins($addon)
194 {
195 return rex_addon::get($addon)->getAvailablePlugins();
196 }
197
198 199 200 201 202 203 204
205 public static function getSystemPlugins($addon)
206 {
207 return rex_addon::get($addon)->getSystemPlugins();
208 }
209 }
210