ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
22 protected $lng;
23
24 public $incl_node;
25
29 protected $access;
30
34 public function init()
35 {
36 global $DIC;
37
38 $this->lng = $DIC->language();
39 $this->setType("incl");
40 $this->access = $DIC->access();
41 }
42
46 public function setNode($a_node)
47 {
48 parent::setNode($a_node); // this is the PageContent node
49 $this->incl_node = $a_node->first_child(); // this is the snippet node
50 }
51
58 public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
59 {
60 $this->node = $this->createPageContentNode();
61 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
62 $this->incl_node = $this->dom->create_element("ContentInclude");
63 $this->incl_node = $this->node->append_child($this->incl_node);
64 }
65
69 public function setContentId($a_id)
70 {
71 $this->setContentIncludeAttribute("ContentId", $a_id);
72 }
73
77 public function getContentId()
78 {
79 return $this->getContentIncludeAttribute("ContentId");
80 }
81
85 public function setContentType($a_type)
86 {
87 $this->setContentIncludeAttribute("ContentType", $a_type);
88 }
89
93 public function getContentType()
94 {
95 return $this->getContentIncludeAttribute("ContentType");
96 }
97
101 public function setInstId($a_id)
102 {
103 $this->setContentIncludeAttribute("InstId", $a_id);
104 }
105
109 public function getInstId()
110 {
111 return $this->getContentIncludeAttribute("InstId");
112 }
113
120 protected function setContentIncludeAttribute($a_attr, $a_value)
121 {
122 if (!empty($a_value)) {
123 $this->incl_node->set_attribute($a_attr, $a_value);
124 } else {
125 if ($this->incl_node->has_attribute($a_attr)) {
126 $this->incl_node->remove_attribute($a_attr);
127 }
128 }
129 }
130
136 public function getContentIncludeAttribute($a_attr)
137 {
138 if (is_object($this->incl_node)) {
139 return $this->incl_node->get_attribute($a_attr);
140 }
141 }
142
151 public 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 public 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 public 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 public 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 if ((int) $ci_id["inst_id"] <= 0 || $ci_id["inst_id"] == IL_INST_ID) {
192 "incl",
193 $ci_id["id"],
194 $a_page->getParentType() . ":pg",
195 $a_page->getId(),
196 $a_old_nr,
197 $a_page->getLanguage()
198 );
199 }
200 }
201 }
202
206 public static function collectContentIncludes($a_page, $a_domdoc)
207 {
208 $xpath = new DOMXPath($a_domdoc);
209 $nodes = $xpath->query('//ContentInclude');
210
211 $ci_ids = array();
212 foreach ($nodes as $node) {
213 $type = $node->getAttribute("ContentType");
214 $id = $node->getAttribute("ContentId");
215 $inst_id = $node->getAttribute("InstId");
216 $ci_ids[$type . ":" . $id . ":" . $inst_id] = array(
217 "type" => $type, "id" => $id, "inst_id" => $inst_id);
218 }
219
220 return $ci_ids;
221 }
222
226 public function modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only = false)
227 {
229
230 $end = 0;
231 $start = strpos($a_html, "{{{{{ContentInclude;");
232 if (is_int($start)) {
233 $end = strpos($a_html, "}}}}}", $start);
234 }
235 $i = 1;
236 while ($end > 0) {
237 $param = substr($a_html, $start + 20, $end - $start - 20);
238 $param = explode(";", $param);
239
240 if ($param[0] == "mep" && is_numeric($param[1])) {
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 $snippet_lang = "-";
246 }
247 if (($param[2] <= 0 || $param[2] == IL_INST_ID) && ilPageObject::_exists("mep", $param[1])) {
248 $page_gui = new ilMediaPoolPageGUI($param[1], 0, true, $snippet_lang);
249 if ($a_mode != "offline") {
250 $page_gui->setFileDownloadLink($this->getFileDownloadLink());
251 $page_gui->setFullscreenLink($this->getFullscreenLink()."&pg_type=mep");
252 $page_gui->setProfileBackUrl($this->getProfileBackUrl());
253 $page_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadScript());
254 } else {
255 $page_gui->setOutputMode(ilPageObjectGUI::OFFLINE);
256 }
257
258 $html = $page_gui->getRawContent();
259 if ($a_mode == "edit") {
260 include_once("./Services/Link/classes/class.ilLink.php");
261 $par_id = $page_gui->getPageObject()->getParentId();
262 $info = "";
263 foreach (ilObject::_getAllReferences($par_id) as $ref_id) {
264 if ($this->access->checkAccess("write", "", $ref_id)) {
265 $info = " " . $lng->txt("title") . ": " . ilMediaPoolItem::lookupTitle($page_gui->getPageObject()->getId()) .
266 ", " . $lng->txt("obj_mep") . ": <a href='" . ilLink::_getLink($ref_id) . "'>" . ilObject::_lookupTitle($par_id) . "</a>";
267 }
268 }
269 $html = '<p class="small light">' . $lng->txt("copg_snippet_cannot_be_edited") . $info . '</p>' . $html;
270 }
271 } else {
272 if ($a_mode == "edit") {
273 if ($param[2] <= 0) {
274 $html = "// " . $lng->txt("cont_missing_snippet") . " //";
275 } else {
276 $html = "// " . $lng->txt("cont_snippet_from_another_installation") . " //";
277 }
278 }
279 }
280 $h2 = substr($a_html, 0, $start) .
281 $html .
282 substr($a_html, $end + 5);
283 $a_html = $h2;
284 $i++;
285 }
286
287 $start = strpos($a_html, "{{{{{ContentInclude;", $start + 5);
288 $end = 0;
289 if (is_int($start)) {
290 $end = strpos($a_html, "}}}}}", $start);
291 }
292 }
293 return $a_html;
294 }
295}
An exception for terminatinating execution or to throw for unit testing.
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
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.
modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only=false)
@inheritDoc
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.
$i
Definition: metadata.php:24
$type
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46
$param
Definition: xapitoken.php:31