ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCContentInclude.php
Go to the documentation of this file.
1 <?php
2 
28 {
29  protected ilLanguage $lng;
32 
36  public function init(): void
37  {
38  global $DIC;
39 
40  $this->lng = $DIC->language();
41  $this->setType("incl");
42  $this->access = $DIC->access();
43  }
44 
45  public function setNode(php4DOMElement $a_node): void
46  {
47  parent::setNode($a_node); // this is the PageContent node
48  $this->incl_node = $a_node->first_child(); // this is the snippet node
49  }
50 
51  public function create(
52  ilPageObject $a_pg_obj,
53  string $a_hier_id,
54  string $a_pc_id = ""
55  ): void {
56  $this->node = $this->createPageContentNode();
57  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
58  $this->incl_node = $this->dom->create_element("ContentInclude");
59  $this->incl_node = $this->node->append_child($this->incl_node);
60  }
61 
65  public function setContentId(int $a_id): void
66  {
67  $this->setContentIncludeAttribute("ContentId", (string) $a_id);
68  }
69 
73  public function getContentId(): int
74  {
75  return (int) $this->getContentIncludeAttribute("ContentId");
76  }
77 
81  public function setContentType(string $a_type): void
82  {
83  $this->setContentIncludeAttribute("ContentType", $a_type);
84  }
85 
89  public function getContentType(): string
90  {
91  return $this->getContentIncludeAttribute("ContentType");
92  }
93 
97  public function setInstId(string $a_id): void
98  {
99  $this->setContentIncludeAttribute("InstId", $a_id);
100  }
101 
105  public function getInstId(): string
106  {
107  return $this->getContentIncludeAttribute("InstId");
108  }
109 
113  protected function setContentIncludeAttribute(
114  string $a_attr,
115  string $a_value
116  ): void {
117  if (!empty($a_value)) {
118  $this->incl_node->set_attribute($a_attr, $a_value);
119  } else {
120  if ($this->incl_node->has_attribute($a_attr)) {
121  $this->incl_node->remove_attribute($a_attr);
122  }
123  }
124  }
125 
129  public function getContentIncludeAttribute(string $a_attr): string
130  {
131  if (is_object($this->incl_node)) {
132  return $this->incl_node->get_attribute($a_attr);
133  }
134  return "";
135  }
136 
140  public static function afterPageUpdate(
141  ilPageObject $a_page,
142  DOMDocument $a_domdoc,
143  string $a_xml,
144  bool $a_creation
145  ): void {
146  // pc content include
147  self::saveContentIncludeUsage($a_page, $a_domdoc);
148  }
149 
153  public static function beforePageDelete(ilPageObject $a_page): void
154  {
155  ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType() . ":pg", $a_page->getId(), 0, $a_page->getLanguage());
156  }
157 
161  public static function afterPageHistoryEntry(
162  ilPageObject $a_page,
163  DOMDocument $a_old_domdoc,
164  string $a_old_xml,
165  int $a_old_nr
166  ): void {
167  self::saveContentIncludeUsage($a_page, $a_old_domdoc, $a_old_nr);
168  }
169 
173  public static function saveContentIncludeUsage(
174  ilPageObject $a_page,
175  DOMDocument $a_domdoc,
176  int $a_old_nr = 0
177  ): void {
178  $ci_ids = self::collectContentIncludes($a_page, $a_domdoc);
179  ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
180  foreach ($ci_ids as $ci_id) {
181  if ((int) $ci_id["inst_id"] <= 0 || $ci_id["inst_id"] == IL_INST_ID) {
183  "incl",
184  $ci_id["id"],
185  $a_page->getParentType() . ":pg",
186  $a_page->getId(),
187  $a_old_nr,
188  $a_page->getLanguage()
189  );
190  }
191  }
192  }
193 
197  public static function collectContentIncludes(
198  ilPageObject $a_page,
199  DOMDocument $a_domdoc
200  ): array {
201  $xpath = new DOMXPath($a_domdoc);
202  $nodes = $xpath->query('//ContentInclude');
203 
204  $ci_ids = array();
205  foreach ($nodes as $node) {
206  $type = $node->getAttribute("ContentType");
207  $id = $node->getAttribute("ContentId");
208  $inst_id = $node->getAttribute("InstId");
209  $ci_ids[$type . ":" . $id . ":" . $inst_id] = array(
210  "type" => $type, "id" => $id, "inst_id" => $inst_id);
211  }
212 
213  return $ci_ids;
214  }
215 
216  public function modifyPageContentPostXsl(
217  string $a_output,
218  string $a_mode,
219  bool $a_abstract_only = false
220  ): string {
221  $lng = $this->lng;
222 
223  $end = 0;
224  $start = strpos($a_output, "{{{{{ContentInclude;");
225  if (is_int($start)) {
226  $end = strpos($a_output, "}}}}}", $start);
227  }
228  $i = 1;
229  $parent_lang = $this->getPage()->getLanguage();
230  if ($parent_lang == "-" && $this->getPage()->getConcreteLang() != "") {
231  $parent_lang = $this->getPage()->getConcreteLang();
232  }
233  while ($end > 0) {
234  $param = substr($a_output, $start + 20, $end - $start - 20);
235  $param = explode(";", $param);
236 
237  if ($param[0] == "mep" && is_numeric($param[1])) {
238  $html = "";
239  $snippet_lang = $parent_lang;
240  if (!ilPageObject::_exists("mep", $param[1], $snippet_lang)) {
241  $snippet_lang = "-";
242  }
243  if (($param[2] <= 0 || $param[2] == IL_INST_ID) && ilPageObject::_exists("mep", $param[1])) {
244  $page_gui = new ilMediaPoolPageGUI($param[1], 0, true, $snippet_lang);
245  if ($a_mode != "offline") {
246  $page_gui->setFileDownloadLink($this->getFileDownloadLink());
247  $page_gui->setProfileBackUrl($this->getProfileBackUrl());
248  $page_gui->setFullscreenLink($this->getFullscreenLink() . "&pg_type=mep");
249  $page_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadScript());
250  } else {
251  $page_gui->setOutputMode(ilPageObjectGUI::OFFLINE);
252  }
253 
254  $html = $page_gui->getRawContent();
255  if ($a_mode == "edit") {
256  $par_id = $page_gui->getPageObject()->getParentId();
257  $info = "";
258  foreach (ilObject::_getAllReferences($par_id) as $ref_id) {
259  if ($this->access->checkAccess("write", "", $ref_id)) {
260  $info = " " . $lng->txt("title") . ": " . ilMediaPoolItem::lookupTitle($page_gui->getPageObject()->getId()) .
261  ", " . $lng->txt("obj_mep") . ": <a href='" . ilLink::_getLink($ref_id) . "'>" . ilObject::_lookupTitle($par_id) . "</a>";
262  }
263  }
264  $html = '<p class="small light">' . $lng->txt("copg_snippet_cannot_be_edited") . $info . '</p>' . $html;
265  }
266  } else {
267  if ($a_mode == "edit") {
268  if ($param[2] <= 0) {
269  $html = "// " . $lng->txt("cont_missing_snippet") . " //";
270  } else {
271  $html = "// " . $lng->txt("cont_snippet_from_another_installation") . " //";
272  }
273  }
274  }
275  $h2 = substr($a_output, 0, $start) .
276  $html .
277  substr($a_output, $end + 5);
278  $a_output = $h2;
279  $i++;
280  }
281 
282  $start = strpos($a_output, "{{{{{ContentInclude;", $start + 5);
283  $end = 0;
284  if (is_int($start)) {
285  $end = strpos($a_output, "}}}}}", $start);
286  }
287  }
288  return $a_output;
289  }
290 
291  public static function deleteHistoryLowerEqualThan(
292  string $parent_type,
293  int $page_id,
294  string $lang,
295  int $delete_lower_than_nr
296  ): void {
297  global $DIC;
298 
299  $usage_repo = $DIC->copage()
300  ->internal()
301  ->repo()
302  ->usage();
303 
304  $usage_repo->deleteHistoryUsagesLowerEqualThan(
305  "incl",
306  $parent_type . ":pg",
307  $page_id,
308  $delete_lower_than_nr,
309  $lang
310  );
311  }
312 }
php4DOMElement $node
getInstId()
Get installation id.
setType(string $a_type)
Set Type.
getContentId()
Get content id.
static afterPageHistoryEntry(ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
After page history entry has been created.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
const IL_INST_ID
Definition: constants.php:40
static collectContentIncludes(ilPageObject $a_page, DOMDocument $a_domdoc)
get all content includes that are used within the page
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _getAllReferences(int $id)
get all reference ids for object ID
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
setNode(php4DOMElement $a_node)
static lookupTitle(int $a_id)
static saveUsage(string $a_pc_type, int $a_pc_id, string $a_usage_type, int $a_usage_id, int $a_usage_hist_nr=0, string $a_lang="-")
static beforePageDelete(ilPageObject $a_page)
Before page is being deleted.
setContentType(string $a_type)
Set content type.
static deleteHistoryLowerEqualThan(string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setInstId(string $a_id)
Set installation id.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
php4DomElement
static _lookupTitle(int $obj_id)
setContentIncludeAttribute(string $a_attr, string $a_value)
Set attribute of content include tag.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static deleteAllUsages(string $a_pc_type, string $a_usage_type, int $a_usage_id, int $a_usage_hist_nr=0, string $a_lang="-")
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
$param
Definition: xapitoken.php:46
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
const IL_INSERT_AFTER
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
static saveContentIncludeUsage(ilPageObject $a_page, DOMDocument $a_domdoc, int $a_old_nr=0)
save content include usages
$lang
Definition: xapiexit.php:26
setContentId(int $a_id)
Set content id.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getContentIncludeAttribute(string $a_attr)
Get content include tag attribute.
init()
Init page content component.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
Class ilMediaPoolPage GUI class.
$i
Definition: metadata.php:41
getContentType()
Get content type.