ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPCPlugged.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPageContent.php");
6
17{
18 var $dom;
20
24 function init()
25 {
26 $this->setType("plug");
27 }
28
32 function setNode(&$a_node)
33 {
34 parent::setNode($a_node); // this is the PageContent node
35 $this->plug_node =& $a_node->first_child(); // this is the Plugged node
36 }
37
44 function create($a_pg_obj, $a_hier_id, $a_pc_id, $a_plugin_name,
45 $a_plugin_version)
46 {
47 $this->node = $this->createPageContentNode();
48 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
49 $this->plug_node =& $this->dom->create_element("Plugged");
50 $this->plug_node =& $this->node->append_child($this->plug_node);
51 $this->plug_node->set_attribute("PluginName", $a_plugin_name);
52 $this->plug_node->set_attribute("PluginVersion", $a_plugin_version);
53 }
54
60 function setProperties($a_properties)
61 {
62 if (!is_object($this->plug_node))
63 {
64 return;
65 }
66
67 // delete properties
68 $children = $this->plug_node->child_nodes();
69 for($i=0; $i<count($children); $i++)
70 {
71 $this->plug_node->remove_child($children[$i]);
72 }
73 // set properties
74 foreach($a_properties as $key => $value)
75 {
76 $prop_node = $this->dom->create_element("PluggedProperty");
77 $prop_node = $this->plug_node->append_child($prop_node);
78 $prop_node->set_attribute("Name", $key);
79 if ($value != "")
80 {
81 $prop_node->set_content($value);
82 }
83 }
84 }
85
91 function getProperties()
92 {
93 $properties = array();
94
95 if (is_object($this->plug_node))
96 {
97 // delete properties
98 $children = $this->plug_node->child_nodes();
99 for($i=0; $i<count($children); $i++)
100 {
101 if ($children[$i]->node_name() == "PluggedProperty")
102 {
103 $properties[$children[$i]->get_attribute("Name")] =
104 $children[$i]->get_content();
105 }
106 }
107 }
108
109 return $properties;
110 }
111
117 function setPluginVersion($a_version)
118 {
119 if (!empty($a_version))
120 {
121 $this->plug_node->set_attribute("PluginVersion", $a_version);
122 }
123 else
124 {
125 if ($this->plug_node->has_attribute("PluginVersion"))
126 {
127 $this->plug_node->remove_attribute("PluginVersion");
128 }
129 }
130 }
131
138 {
139 if (is_object($this->plug_node))
140 {
141 return $this->plug_node->get_attribute("PluginVersion");
142 }
143 }
144
150 function setPluginName($a_name)
151 {
152 if (!empty($a_name))
153 {
154 $this->plug_node->set_attribute("PluginName", $a_name);
155 }
156 else
157 {
158 if ($this->plug_node->has_attribute("PluginName"))
159 {
160 $this->plug_node->remove_attribute("PluginName");
161 }
162 }
163 }
164
170 function getPluginName()
171 {
172 if (is_object($this->plug_node))
173 {
174 return $this->plug_node->get_attribute("PluginName");
175 }
176 }
177
184 function modifyPageContentPostXsl($a_html, $a_mode)
185 {
186 global $lng, $ilPluginAdmin;
187
188 $c_pos = 0;
189 $start = strpos($a_html, "{{{{{Plugged<pl");
190//echo htmlentities($a_html)."-";
191 if (is_int($start))
192 {
193 $end = strpos($a_html, "}}}}}", $start);
194 }
195 $i = 1;
196
197 while ($end > 0)
198 {
199 $param = substr($a_html, $start + 5, $end - $start - 5);
200 $param = str_replace(' xmlns:xhtml="http://www.w3.org/1999/xhtml"', "", $param);
201 $param = explode("<pl/>", $param);
202//var_dump($param); exit;
203 $plugin_name = $param[1];
204 $plugin_version = $param[2];
205 $properties = array();
206
207 for ($i = 3; $i < count($param); $i+=2)
208 {
209 $properties[$param[$i]] = $param[$i+1];
210 }
211
212 // get html from plugin
213 if ($a_mode == "edit")
214 {
215 $plugin_html = '<div class="ilBox">'.$lng->txt("content_plugin_not_activated")." (".$plugin_name.")</div>";
216 }
217 if ($ilPluginAdmin->isActive(IL_COMP_SERVICE, "COPage", "pgcp", $plugin_name))
218 {
219 $plugin_obj = $ilPluginAdmin->getPluginObject(IL_COMP_SERVICE, "COPage",
220 "pgcp", $plugin_name);
221 $gui_obj = $plugin_obj->getUIClassInstance();
222 $plugin_html = $gui_obj->getElementHTML($a_mode, $properties, $plugin_version);
223 }
224
225 $a_html = substr($a_html, 0, $start).
226 $plugin_html.
227 substr($a_html, $end + 5);
228
229 if (strlen($a_html) > $start + 5)
230 {
231 $start = strpos($a_html, "{{{{{Plugged<pl", $start + 5);
232 }
233 else
234 {
235 $start = false;
236 }
237 $end = 0;
238 if (is_int($start))
239 {
240 $end = strpos($a_html, "}}}}}", $start);
241 }
242 }
243
244 return $a_html;
245 }
246
251 {
252 global $ilPluginAdmin;
253
254 $js_files = array();
255
256 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE,
257 "COPage", "pgcp");
258 foreach ($pl_names as $pl_name)
259 {
260 $plugin = $ilPluginAdmin->getPluginObject(IL_COMP_SERVICE,
261 "COPage", "pgcp", $pl_name);
262 $pl_dir = $plugin->getDirectory();
263
264 $pl_js_files = $plugin->getJavascriptFiles();
265 foreach ($pl_js_files as $pl_js_file)
266 {
267 if (!is_int(strpos($pl_js_file, "//")))
268 {
269 $pl_js_file = $pl_dir."/".$pl_js_file;
270 }
271 if (!in_array($pl_js_file, $js_files))
272 {
273 $js_files[] = $pl_js_file;
274 }
275 }
276 }
277//var_dump($js_files);
278 return $js_files;
279 }
280
284 function getCssFiles()
285 {
286 global $ilPluginAdmin;
287
288 $css_files = array();
289
290 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE,
291 "COPage", "pgcp");
292 foreach ($pl_names as $pl_name)
293 {
294 $plugin = $ilPluginAdmin->getPluginObject(IL_COMP_SERVICE,
295 "COPage", "pgcp", $pl_name);
296 $pl_dir = $plugin->getDirectory();
297
298 $pl_css_files = $plugin->getCssFiles();
299 foreach ($pl_css_files as $pl_css_file)
300 {
301 if (!is_int(strpos($pl_css_file, "//")))
302 {
303 $pl_css_file = $pl_dir."/".$pl_css_file;
304 }
305 if (!in_array($pl_css_file, $css_files))
306 {
307 $css_files[] = $pl_css_file;
308 }
309 }
310 }
311
312 return $css_files;
313 }
314
315}
316
317?>
const IL_COMP_SERVICE
const IL_INSERT_AFTER
Class ilPCPlugged Plugged content object (see ILIAS DTD)
getCssFiles()
Get css files.
modifyPageContentPostXsl($a_html, $a_mode)
Modify page content after xsl.
getPluginName()
Get name of plugged component.
setNode(&$a_node)
Set node.
init()
Init page content component.
setPluginName($a_name)
Set name of plugged component.
setProperties($a_properties)
Set properties of plugged component.
create($a_pg_obj, $a_hier_id, $a_pc_id, $a_plugin_name, $a_plugin_version)
Create plugged node in xml.
getJavascriptFiles()
Get javascript files.
getProperties()
Get properties of plugged component.
setPluginVersion($a_version)
Set version of plugged component.
getPluginVersion()
Get version of plugged component.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.
global $lng
Definition: privfeed.php:40