ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilPCContentInclude.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPageContent.php");
5
18{
19 var $dom;
21
25 protected $access;
26
30 function init()
31 {
32 global $DIC;
33
34 $this->setType("incl");
35 $this->access = $DIC->access();
36 }
37
41 function setNode($a_node)
42 {
43 parent::setNode($a_node); // this is the PageContent node
44 $this->incl_node = $a_node->first_child(); // this is the snippet node
45 }
46
53 function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
54 {
55 $this->node = $this->createPageContentNode();
56 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
57 $this->incl_node = $this->dom->create_element("ContentInclude");
58 $this->incl_node = $this->node->append_child($this->incl_node);
59 }
60
64 function setContentId($a_id)
65 {
66 $this->setContentIncludeAttribute("ContentId", $a_id);
67 }
68
72 function getContentId()
73 {
74 return $this->getContentIncludeAttribute("ContentId");
75 }
76
81 {
82 $this->setContentIncludeAttribute("ContentType", $a_type);
83 }
84
88 function getContentType()
89 {
90 return $this->getContentIncludeAttribute("ContentType");
91 }
92
96 function setInstId($a_id)
97 {
98 $this->setContentIncludeAttribute("InstId", $a_id);
99 }
100
104 function getInstId()
105 {
106 return $this->getContentIncludeAttribute("InstId");
107 }
108
115 protected function setContentIncludeAttribute($a_attr, $a_value)
116 {
117 if (!empty($a_value))
118 {
119 $this->incl_node->set_attribute($a_attr, $a_value);
120 }
121 else
122 {
123 if ($this->incl_node->has_attribute($a_attr))
124 {
125 $this->incl_node->remove_attribute($a_attr);
126 }
127 }
128 }
129
136 {
137 if (is_object($this->incl_node))
138 {
139 return $this->incl_node->get_attribute($a_attr);
140 }
141 }
142
151 static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
152 {
153 // pc content include
154 self::saveContentIncludeUsage($a_page, $a_domdoc);
155 }
156
162 static function beforePageDelete($a_page)
163 {
164 include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
165 ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType().":pg", $a_page->getId(), false, $a_page->getLanguage());
166 }
167
176 static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
177 {
178 self::saveContentIncludeUsage($a_page, $a_old_domdoc, $a_old_nr);
179 }
180
184 static function saveContentIncludeUsage($a_page, $a_domdoc, $a_old_nr = 0)
185 {
186 include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
187 $ci_ids = self::collectContentIncludes($a_page, $a_domdoc);
188 ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
189 foreach($ci_ids as $ci_id)
190 {
191 if ((int) $ci_id["inst_id"] <= 0 || $ci_id["inst_id"] == IL_INST_ID)
192 {
193 ilPageContentUsage::saveUsage("incl", $ci_id["id"], $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
194 $a_page->getLanguage());
195 }
196 }
197 }
198
202 static function collectContentIncludes($a_page, $a_domdoc)
203 {
204 $xpath = new DOMXPath($a_domdoc);
205 $nodes = $xpath->query('//ContentInclude');
206
207 $ci_ids = array();
208 foreach ($nodes as $node)
209 {
210 $type = $node->getAttribute("ContentType");
211 $id = $node->getAttribute("ContentId");
212 $inst_id = $node->getAttribute("InstId");
213 $ci_ids[$type.":".$id.":".$inst_id] = array(
214 "type" => $type, "id" => $id, "inst_id" => $inst_id);
215 }
216
217 return $ci_ids;
218 }
219
223 function modifyPageContentPostXsl($a_html, $a_mode)
224 {
225 global $lng;
226
227 $end = 0;
228 $start = strpos($a_html, "{{{{{ContentInclude;");
229 if (is_int($start))
230 {
231 $end = strpos($a_html, "}}}}}", $start);
232 }
233 $i = 1;
234 while ($end > 0)
235 {
236 $param = substr($a_html, $start + 20, $end - $start - 20);
237 $param = explode(";", $param);
238
239 if ($param[0] == "mep" && is_numeric($param[1]))
240 {
241 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
242 $html = "";
243 $snippet_lang = $this->getPage()->getLanguage();
244 if (!ilPageObject::_exists("mep", $param[1], $snippet_lang))
245 {
246 $snippet_lang = "-";
247 }
248 if (($param[2] <= 0 || $param[2] == IL_INST_ID) && ilPageObject::_exists("mep", $param[1]))
249 {
250 $page_gui = new ilMediaPoolPageGUI($param[1], 0, true, $snippet_lang);
251 if ($a_mode != "offline")
252 {
253 $page_gui->setFileDownloadLink($this->getFileDownloadLink());
254 $page_gui->setFullscreenLink($this->getFullscreenLink());
255 $page_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadScript());
256 }
257 else
258 {
259 $page_gui->setOutputMode(IL_PAGE_OFFLINE);
260 }
261
262 $html = $page_gui->getRawContent();
263 if ($a_mode == "edit")
264 {
265 include_once("./Services/Link/classes/class.ilLink.php");
266 $par_id = $page_gui->getPageObject()->getParentId();
267 $info = "";
268 foreach (ilObject::_getAllReferences($par_id) as $ref_id)
269 {
270 if ($this->access->checkAccess("write", "", $ref_id))
271 {
272 $info = " ".$lng->txt("title").": ".ilMediaPoolItem::lookupTitle($page_gui->getPageObject()->getId()).
273 ", ".$lng->txt("obj_mep").": <a href='".ilLink::_getLink($ref_id)."'>".ilObject::_lookupTitle($par_id)."</a>";
274 }
275 }
276 $html = '<p class="small light">'.$lng->txt("copg_snippet_cannot_be_edited").$info.'</p>'.$html;
277 }
278 }
279 else
280 {
281 if ($a_mode == "edit")
282 {
283 if ($param[2] <= 0)
284 {
285 $html = "// ".$lng->txt("cont_missing_snippet")." //";
286 }
287 else
288 {
289 $html = "// ".$lng->txt("cont_snippet_from_another_installation")." //";
290 }
291 }
292 }
293 $h2 = substr($a_html, 0, $start).
294 $html.
295 substr($a_html, $end + 5);
296 $a_html = $h2;
297 $i++;
298 }
299
300 $start = strpos($a_html, "{{{{{ContentInclude;", $start + 5);
301 $end = 0;
302 if (is_int($start))
303 {
304 $end = strpos($a_html, "}}}}}", $start);
305 }
306 }
307 return $a_html;
308 }
309
310}
311
312?>
An exception for terminatinating execution or to throw for unit testing.
const IL_PAGE_OFFLINE
const IL_INSERT_AFTER
static lookupTitle($a_id)
Lookup title.
Class ilMediaPoolPage GUI class.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
Class ilPCContentInclude.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create content include node in xml.
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
getContentIncludeAttribute($a_attr)
Get content include tag attribute.
setInstId($a_id)
Set installation id.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
static saveContentIncludeUsage($a_page, $a_domdoc, $a_old_nr=0)
save content include usages
setContentType($a_type)
Set content type.
static collectContentIncludes($a_page, $a_domdoc)
get all content includes that are used within the page
modifyPageContentPostXsl($a_html, $a_mode)
Modify page content after xsl.string
setContentIncludeAttribute($a_attr, $a_value)
Set attribute of content include tag.
static beforePageDelete($a_page)
Before page is being deleted.
getInstId()
Get installation id.
setContentId($a_id)
Set content id.
getContentType()
Get content type.
init()
Init page content component.
static saveUsage($a_pc_type, $a_pc_id, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Save usages.
static deleteAllUsages($a_pc_type, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Delete all usages.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
getFileDownloadLink()
Get file download link.
getFullscreenLink()
Get fullscreen link.
getSourcecodeDownloadScript()
Get sourcecode download script.
setType($a_type)
Set Type.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
$html
Definition: example_001.php:87
$info
Definition: example_052.php:80
global $lng
Definition: privfeed.php:17
$ref_id
Definition: sahs_server.php:39
global $DIC
$a_type
Definition: workflow.php:93