ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_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  {
228  $lng = $this->lng;
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  $parent_lang = $this->getPage()->getLanguage();
237  if ($parent_lang == "-" && $this->getPage()->getConcreteLang() != "") {
238  $parent_lang = $this->getPage()->getConcreteLang();
239  }
240  while ($end > 0) {
241  $param = substr($a_html, $start + 20, $end - $start - 20);
242  $param = explode(";", $param);
243 
244  if ($param[0] == "mep" && is_numeric($param[1])) {
245  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
246  $html = "";
247  $snippet_lang = $parent_lang;
248  if (!ilPageObject::_exists("mep", $param[1], $snippet_lang)) {
249  $snippet_lang = "-";
250  }
251  if (($param[2] <= 0 || $param[2] == IL_INST_ID) && ilPageObject::_exists("mep", $param[1])) {
252  $page_gui = new ilMediaPoolPageGUI($param[1], 0, true, $snippet_lang);
253  if ($a_mode != "offline") {
254  $page_gui->setFileDownloadLink($this->getFileDownloadLink());
255  $page_gui->setProfileBackUrl($this->getProfileBackUrl());
256  $page_gui->setFullscreenLink($this->getFullscreenLink() . "&pg_type=mep");
257  $page_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadScript());
258  } else {
259  $page_gui->setOutputMode(ilPageObjectGUI::OFFLINE);
260  }
261 
262  $html = $page_gui->getRawContent();
263  if ($a_mode == "edit") {
264  include_once("./Services/Link/classes/class.ilLink.php");
265  $par_id = $page_gui->getPageObject()->getParentId();
266  $info = "";
267  foreach (ilObject::_getAllReferences($par_id) as $ref_id) {
268  if ($this->access->checkAccess("write", "", $ref_id)) {
269  $info = " " . $lng->txt("title") . ": " . ilMediaPoolItem::lookupTitle($page_gui->getPageObject()->getId()) .
270  ", " . $lng->txt("obj_mep") . ": <a href='" . ilLink::_getLink($ref_id) . "'>" . ilObject::_lookupTitle($par_id) . "</a>";
271  }
272  }
273  $html = '<p class="small light">' . $lng->txt("copg_snippet_cannot_be_edited") . $info . '</p>' . $html;
274  }
275  } else {
276  if ($a_mode == "edit") {
277  if ($param[2] <= 0) {
278  $html = "// " . $lng->txt("cont_missing_snippet") . " //";
279  } else {
280  $html = "// " . $lng->txt("cont_snippet_from_another_installation") . " //";
281  }
282  }
283  }
284  $h2 = substr($a_html, 0, $start) .
285  $html .
286  substr($a_html, $end + 5);
287  $a_html = $h2;
288  $i++;
289  }
290 
291  $start = strpos($a_html, "{{{{{ContentInclude;", $start + 5);
292  $end = 0;
293  if (is_int($start)) {
294  $end = strpos($a_html, "}}}}}", $start);
295  }
296  }
297  return $a_html;
298  }
299 }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
getSourcecodeDownloadScript()
Get sourcecode download script.
getInstId()
Get installation id.
getContentId()
Get content id.
const IL_INST_ID
Definition: constants.php:38
$type
static beforePageDelete($a_page)
Before page is being deleted.
modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only=false)
setType($a_type)
Set Type.
static _lookupTitle($a_id)
lookup object title
setContentId($a_id)
Set content id.
Class ilPageContent.
static _getAllReferences($a_id)
get all reference ids of object
static collectContentIncludes($a_page, $a_domdoc)
get all content includes that are used within the page
Class ilPCContentInclude.
$param
Definition: xapitoken.php:29
global $DIC
Definition: goto.php:24
static saveContentIncludeUsage($a_page, $a_domdoc, $a_old_nr=0)
save content include usages
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
setContentType($a_type)
Set content type.
setContentIncludeAttribute($a_attr, $a_value)
Set attribute of content include tag.
getFullscreenLink()
Get fullscreen link.
const IL_INSERT_AFTER
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create content include node in xml.
setNode($a_node)
Set node.
static deleteAllUsages($a_pc_type, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Delete all usages.
static lookupTitle($a_id)
Lookup title.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
setInstId($a_id)
Set installation id.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
getContentIncludeAttribute($a_attr)
Get content include tag attribute.
getFileDownloadLink()
Get file download link.
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.
Class ilMediaPoolPage GUI class.
$i
Definition: metadata.php:24
getContentType()
Get content type.