ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
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  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());
252  $page_gui->setSourcecodeDownloadScript($this->getSourcecodeDownloadScript());
253  } else {
254  $page_gui->setOutputMode(IL_PAGE_OFFLINE);
255  }
256 
257  $html = $page_gui->getRawContent();
258  if ($a_mode == "edit") {
259  include_once("./Services/Link/classes/class.ilLink.php");
260  $par_id = $page_gui->getPageObject()->getParentId();
261  $info = "";
262  foreach (ilObject::_getAllReferences($par_id) as $ref_id) {
263  if ($this->access->checkAccess("write", "", $ref_id)) {
264  $info = " " . $lng->txt("title") . ": " . ilMediaPoolItem::lookupTitle($page_gui->getPageObject()->getId()) .
265  ", " . $lng->txt("obj_mep") . ": <a href='" . ilLink::_getLink($ref_id) . "'>" . ilObject::_lookupTitle($par_id) . "</a>";
266  }
267  }
268  $html = '<p class="small light">' . $lng->txt("copg_snippet_cannot_be_edited") . $info . '</p>' . $html;
269  }
270  } else {
271  if ($a_mode == "edit") {
272  if ($param[2] <= 0) {
273  $html = "// " . $lng->txt("cont_missing_snippet") . " //";
274  } else {
275  $html = "// " . $lng->txt("cont_snippet_from_another_installation") . " //";
276  }
277  }
278  }
279  $h2 = substr($a_html, 0, $start) .
280  $html .
281  substr($a_html, $end + 5);
282  $a_html = $h2;
283  $i++;
284  }
285 
286  $start = strpos($a_html, "{{{{{ContentInclude;", $start + 5);
287  $end = 0;
288  if (is_int($start)) {
289  $end = strpos($a_html, "}}}}}", $start);
290  }
291  }
292  return $a_html;
293  }
294 }
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_PAGE_OFFLINE
$type
global $DIC
Definition: saml.php:7
static beforePageDelete($a_page)
Before page is being deleted.
if(!array_key_exists('StateId', $_REQUEST)) $id
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
$start
Definition: bench.php:8
$a_type
Definition: workflow.php:92
static collectContentIncludes($a_page, $a_domdoc)
get all content includes that are used within the page
Class ilPCContentInclude.
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.
$i
Definition: disco.tpl.php:19
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.
$info
Definition: index.php:5
modifyPageContentPostXsl($a_html, $a_mode)
$html
Definition: example_001.php:87
Class ilMediaPoolPage GUI class.
getContentType()
Get content type.