ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCPlugged.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilLanguage $lng;
30
31 public function init(): void
32 {
33 global $DIC;
34
35 $this->lng = $DIC->language();
36 $this->setType("plug");
37 $this->component_repository = $DIC["component.repository"] ?? null;
38 $this->component_factory = $DIC["component.factory"] ?? null;
39 }
40
44 public function create(
45 ilPageObject $a_pg_obj,
46 string $a_hier_id,
47 string $a_pc_id,
48 string $a_plugin_name,
49 string $a_plugin_version
50 ): void {
52 $a_hier_id,
53 $a_pc_id,
54 "Plugged",
55 ["PluginName" => $a_plugin_name, "PluginVersion" => $a_plugin_version]
56 );
57 }
58
62 public function setProperties(array $a_properties): void
63 {
64 if (!is_object($this->getChildNode())) {
65 return;
66 }
67
68 // delete properties
69 $this->dom_util->deleteAllChilds($this->getChildNode());
70 // set properties
71 foreach ($a_properties as $key => $value) {
72 $prop_node = $this->dom_doc->createElement("PluggedProperty");
73 $prop_node = $this->getChildNode()->appendChild($prop_node);
74 $prop_node->setAttribute("Name", $key);
75 if ($value != "") {
76 $this->dom_util->setContent($prop_node, $value);
77 }
78 }
79 }
80
84 public function getProperties(): array
85 {
86 $properties = array();
87
88 if (is_object($this->getChildNode())) {
89 foreach ($this->getChildNode()->childNodes as $c) {
90 if ($c->nodeName == "PluggedProperty") {
91 $properties[$c->getAttribute("Name")] =
92 $this->dom_util->getContent($c);
93 }
94 }
95 }
96
97 return $properties;
98 }
99
100 public function setPluginVersion(string $a_version): void
101 {
102 if (!empty($a_version)) {
103 $this->getChildNode()->setAttribute("PluginVersion", $a_version);
104 } else {
105 if ($this->getChildNode()->hasAttribute("PluginVersion")) {
106 $this->getChildNode()->removeAttribute("PluginVersion");
107 }
108 }
109 }
110
111 public function getPluginVersion(): string
112 {
113 if (is_object($this->getChildNode())) {
114 return $this->getChildNode()->getAttribute("PluginVersion");
115 }
116 return "";
117 }
118
119 public function setPluginName(string $a_name): void
120 {
121 if (!empty($a_name)) {
122 $this->getChildNode()->setAttribute("PluginName", $a_name);
123 } else {
124 if ($this->getChildNode()->hasAttribute("PluginName")) {
125 $this->getChildNode()->removeAttribute("PluginName");
126 }
127 }
128 }
129
130 public function getPluginName(): string
131 {
132 if (is_object($this->getChildNode())) {
133 return $this->getChildNode()->getAttribute("PluginName");
134 }
135 return "";
136 }
137
138 protected static function getActivePluginByName(string $name): ?ilPageComponentPlugin
139 {
140 global $DIC;
141 $component_repository = $DIC['component.repository'];
142 $component_factory = $DIC['component.factory'];
143 $plugin_info = null;
144 try {
145 $plugin_info = $component_repository->getPluginByName($name);
146 } catch (Exception $e) {
147 }
148 if (is_object($plugin_info) && $plugin_info->isActive()) {
150 $plugin_obj = $component_factory->getPlugin($plugin_info->getId());
151 return $plugin_obj;
152 }
153 return null;
154 }
155
160 public static function handleCopiedPluggedContent(
161 ilPageObject $a_page,
162 DOMDocument $a_domdoc
163 ): void {
164 global $DIC;
165 $dom_util = $DIC->copage()->internal()->domain()->domUtil();
166 $component_repository = $DIC['component.repository'];
167 $component_factory = $DIC['component.factory'];
168
169 $xpath = new DOMXPath($a_domdoc);
170 $nodes = $xpath->query("//Plugged");
171
173 foreach ($nodes as $node) {
174 $plugin_name = $node->getAttribute('PluginName');
175 $plugin_version = $node->getAttribute('PluginVersion');
176
177 $plugin_obj = self::getActivePluginByName($plugin_name);
178 if (is_object($plugin_obj)) {
179 $plugin_obj->setPageObj($a_page);
180
181 $properties = array();
183 foreach ($node->childNodes as $child) {
184 $properties[$child->getAttribute('Name')] = $child->nodeValue;
185 }
186
187 // let the plugin copy additional content
188 // and allow it to modify the saved parameters
189 $plugin_obj->onClone($properties, $plugin_version);
190
191 $dom_util->deleteAllChilds($node);
192 foreach ($properties as $name => $value) {
193 $child = new DOMElement(
194 'PluggedProperty',
195 str_replace("&", "&amp;", $value)
196 );
197 $node->appendChild($child);
198 $child->setAttribute('Name', $name);
199 }
200 }
201 }
202 }
203
207 public static function afterRepositoryCopy(ilPageObject $page, array $mapping, int $source_ref_id): void
208 {
209 global $DIC;
210
211 $dom_util = $DIC->copage()->internal()->domain()->domUtil();
212
213 $ilPluginAdmin = $DIC['ilPluginAdmin'];
214
216 $component_factory = $DIC["component.factory"];
217
219 $component_repository = $DIC["component.repository"];
220
221 $xpath = new DOMXPath($page->getDomDoc());
222 $nodes = $xpath->query("//Plugged");
223
225 foreach ($nodes as $node) {
226 $plugin_name = $node->getAttribute('PluginName');
227 $plugin_version = $node->getAttribute('PluginVersion');
228 $plugin_obj = self::getActivePluginByName($plugin_name);
229
230 if (is_object($plugin_obj)) {
231 $plugin_obj->setPageObj($page);
232
233 $properties = array();
235 foreach ($node->childNodes as $child) {
236 $properties[$child->getAttribute('Name')] = $child->nodeValue;
237 }
238
239 // let the plugin copy additional content
240 // and allow it to modify the saved parameters
241 $plugin_obj->afterRepositoryCopy($properties, $mapping, $source_ref_id, $plugin_version);
242
243 $dom_util->deleteAllChilds($node);
244 foreach ($properties as $name => $value) {
245 $child = new DOMElement(
246 'PluggedProperty',
247 str_replace("&", "&amp;", $value)
248 );
249 $node->appendChild($child);
250 $child->setAttribute('Name', $name);
251 }
252 }
253 }
254 }
255
260 public static function handleDeletedPluggedNode(
261 ilPageObject $a_page,
262 DOMNode $a_node,
263 bool $move_operation = false
264 ): void {
265 global $DIC;
266 $component_repository = $DIC['component.repository'];
267 $component_factory = $DIC['component.factory'];
268
269 $plugin_name = $a_node->getAttribute('PluginName');
270 $plugin_version = $a_node->getAttribute('PluginVersion');
271
272 $plugin_obj = self::getActivePluginByName($plugin_name);
273 if (is_object($plugin_obj)) {
274 $plugin_obj->setPageObj($a_page);
275
276 $properties = array();
278 foreach ($a_node->childNodes as $child) {
279 $properties[$child->getAttribute('Name')] = $child->nodeValue;
280 }
281
282 // let the plugin delete additional content
283 $plugin_obj->onDelete($properties, $plugin_version, $move_operation);
284 }
285 }
286
288 string $a_output,
289 string $a_mode,
290 bool $a_abstract_only = false
291 ): string {
292 $lng = $this->lng;
293
294 $end = 0;
295 $start = strpos($a_output, "{{{{{Plugged<pl");
296 //echo htmlentities($a_html)."-";
297 if (is_int($start)) {
298 $end = strpos($a_output, "}}}}}", $start);
299 }
300
301 while ($end > 0) {
302 $param = substr($a_output, $start + 5, $end - $start - 5);
303 $param = str_replace(' xmlns:xhtml="http://www.w3.org/1999/xhtml"', "", $param);
304 $param = explode("<pl/>", $param);
305 //var_dump($param); exit;
306 $plugin_name = $param[1];
307 $plugin_version = $param[2];
308 $properties = array();
309
310 for ($i = 3; $i < count($param); $i += 2) {
311 $properties[$param[$i]] = $param[$i + 1];
312 }
313
314 // get html from plugin
315 if ($a_mode == "edit") {
316 $plugin_html = '<div class="ilBox">' . $lng->txt("content_plugin_not_activated") . " (" . $plugin_name . ")</div>";
317 }
318
319 $plugin_obj = self::getActivePluginByName($plugin_name);
320 $plugin_html = '';
321 if (is_object($plugin_obj)) {
322 $plugin_obj->setPageObj($this->getPage());
323 $gui_obj = $plugin_obj->getUIClassInstance();
324 $plugin_html = $gui_obj->getElementHTML($a_mode, $properties, $plugin_version);
325 } else {
326 if ($a_mode === "edit") {
327 $plugin_html = sprintf($this->lng->txt("copg_plugin_not_avail"), $plugin_name);
328 } else {
329 $plugin_html = " ";
330 }
331 }
332
333 $a_output = substr($a_output, 0, $start) .
334 $plugin_html .
335 substr($a_output, $end + 5);
336
337 if (strlen($a_output) > $start + 5) {
338 $start = strpos($a_output, "{{{{{Plugged<pl", $start + 5);
339 } else {
340 $start = false;
341 }
342 $end = 0;
343 if (is_int($start)) {
344 $end = strpos($a_output, "}}}}}", $start);
345 }
346 }
347
348 return $a_output;
349 }
350
351 public function getJavascriptFiles(string $a_mode): array
352 {
353 $js_files = array();
354
355 foreach ($this->component_factory->getActivePluginsInSlot("pgcp") as $plugin) {
356 $plugin->setPageObj($this->getPage());
357 $pl_dir = $plugin->getDirectory();
358
359 $pl_js_files = $plugin->getJavascriptFiles($a_mode);
360 foreach ($pl_js_files as $pl_js_file) {
361 if (!is_int(strpos($pl_js_file, "//"))) {
362 $pl_js_file = $pl_dir . "/" . $pl_js_file;
363 }
364 if (!in_array($pl_js_file, $js_files)) {
365 $js_files[] = $pl_js_file;
366 }
367 }
368 }
369 //var_dump($js_files);
370 return $js_files;
371 }
372
373 public function getCssFiles(string $a_mode): array
374 {
375 $css_files = array();
376
377 foreach ($this->component_factory->getActivePluginsInSlot("pgcp") as $plugin) {
378 $plugin->setPageObj($this->getPage());
379 $pl_dir = $plugin->getDirectory();
380
381 $pl_css_files = $plugin->getCssFiles($a_mode);
382 foreach ($pl_css_files as $pl_css_file) {
383 if (!is_int(strpos($pl_css_file, "//"))) {
384 $pl_css_file = $pl_dir . "/" . $pl_css_file;
385 }
386 if (!in_array($pl_css_file, $css_files)) {
387 $css_files[] = $pl_css_file;
388 }
389 }
390 }
391
392 return $css_files;
393 }
394}
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, string $a_plugin_name, string $a_plugin_version)
Create plugged node in xml.
setPluginVersion(string $a_version)
init()
Init object.
setPluginName(string $a_name)
ilComponentFactory $component_factory
ilLanguage $lng
ilComponentRepository $component_repository
getProperties()
Get properties of plugged component.
getCssFiles(string $a_mode)
setProperties(array $a_properties)
Set properties of plugged component.
getJavascriptFiles(string $a_mode)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getDomDoc()
Get dom doc (DOMDocument)
$c
Definition: deliver.php:25
getPlugin(string $id)
Get the plugin for the given id.
Readable part of repository interface to ilComponentDataDB.
getPluginByName(string $name)
Get a plugin by name.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$param
Definition: xapitoken.php:46