19 declare(strict_types=1);
    31     protected \DOMDocument 
$dom;
    32     protected \ILIAS\COPage\Link\LinkManager 
$link;
    38         ?PCDefinition $def = null
    43         $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
    44         $this->pc_service = $DIC->copage()->internal()->domain()->pc($def);
    45         $this->
link = $DIC->copage()->internal()->domain()->link();
    47         $path = 
"//PageObject";
    48         $nodes = $this->dom_util->path($dom, 
$path);
    49         if (count($nodes) == 1) {
    50             $this->page_object_node = $nodes->item(0);
    61         if ($a_hier_id == 
"pg") {
    62             $path = 
"//PageObject";
    66                 $path = 
"//*[@PCID = '$a_pc_id']";
    69                 $path = 
"//*[@HierId = '$a_hier_id']";
    72         $nodes = $this->dom_util->path($this->dom, 
$path);
    73         if (count($nodes) === 1) {
    74             $cont_node = $nodes->item(0);
    84         bool $move_operation = 
false    88         $curr_node->parentNode->removeChild($curr_node);
    94         bool $a_self_ass = 
false,
    95         bool $move_operation = 
false    97         foreach ($a_hids as $a_hid) {
    98             $a_hid = explode(
":", $a_hid);
   101             if (!$this->
checkForTag(
"Question", $a_hid[0], (
string) ($a_hid[1] ?? 
"")) || $a_self_ass) {
   102                 $curr_node = $this->
getContentDomNode((
string) $a_hid[0], (
string) ($a_hid[1] ?? 
""));
   103                 if (is_object($curr_node)) {
   104                     $parent_node = $curr_node->parentNode;
   105                     if ($parent_node->nodeName != 
"TableRow") {
   107                         $curr_node->parentNode->removeChild($curr_node);
   115         string $a_content_tag,
   120         if ($a_pc_id != 
"") {
   121             $path = 
"//*[@PCID = '$a_pc_id']//" . $a_content_tag;
   123             $path = 
"//*[@HierId = '$a_hier_id']//" . $a_content_tag;
   126         $nodes = $this->dom_util->path($this->dom, 
$path);
   127         if (count($nodes) > 0) {
   136         if (!isset($a_node)) {
   137             $path = 
"//PageContent";
   138             $nodes = $this->dom_util->path($this->dom, 
$path);
   140             $nodes = array($a_node);
   143         foreach ($nodes as $node) {
   144             if ($node->firstChild->nodeName === 
'Plugged') {
   145                 \ilPCPlugged::handleDeletedPluggedNode($page, $node->firstChild, $move_operation);
   153         bool $a_self_ass = 
false   155         foreach ($a_hids as $a_hid) {
   156             $a_hid = explode(
":", $a_hid);
   158             if (is_object($curr_node)) {
   159                 if ($curr_node->nodeName == 
"PageContent") {
   160                     $cont_obj = $this->pc_service->getByNode($curr_node, $page);
   161                     if ($cont_obj->isEnabled()) {
   163                         if (!$this->
checkForTag(
"Question", $a_hid[0], (
string) ($a_hid[1] ?? 
"")) || $a_self_ass) {
   164                             $cont_obj->disable();
   177         string $a_target = 
""   183                 $link_type = 
"MediaObject";
   184                 $a_id = 
"il__mob_" . $a_id;
   188                 $link_type = 
"PageObject";
   189                 $a_id = 
"il__pg_" . $a_id;
   193                 $link_type = 
"GlossaryItem";
   194                 $a_id = 
"il__git_" . $a_id;
   195                 $a_target = 
"Glossary";
   199         $path = 
"//PageObject/InitOpenedContent";
   200         $nodes = $this->dom_util->path($this->dom, 
$path);
   201         if ($link_type == 
"" || $a_id == 
"") {
   202             if (count($nodes) > 0) {
   203                 $c = $nodes->item(0);
   204                 $c->parentNode->removeChild(
$c);
   207             if (count($nodes) > 0) {
   208                 $init_node = $nodes->item(0);
   209                 foreach ($init_node->childNodes as $child) {
   210                     if ($child->nodeName === 
"IntLink") {
   215                 $path = 
"//PageObject";
   216                 $nodes = $this->dom_util->path($this->dom, 
$path);
   217                 $page_node = $nodes->item(0);
   218                 $init_node = $this->dom->createElement(
"InitOpenedContent");
   219                 $init_node = $page_node->appendChild($init_node);
   220                 $il_node = $this->dom->createElement(
"IntLink");
   221                 $il_node = $init_node->appendChild($il_node);
   223             $il_node->setAttribute(
"Target", $a_id);
   224             $il_node->setAttribute(
"Type", $link_type);
   225             $il_node->setAttribute(
"TargetFrame", $a_target);
   235         $path = 
"//PageObject/InitOpenedContent";
   237         $nodes = $this->dom_util->path($this->dom, 
$path);
   238         if (count($nodes) > 0) {
   239             $init_node = $nodes->item(0);
   240             foreach ($init_node->childNodes as $child) {
   241                 if ($child->nodeName == 
"IntLink") {
   246         if (!is_null($il_node)) {
   247             $id = $il_node->getAttribute(
"Target");
   248             $link_type = $il_node->getAttribute(
"Type");
   249             $target = $il_node->getAttribute(
"TargetFrame");
   251             switch ($link_type) {
   265             return array(
"id" => 
$id, 
"type" => $type, 
"target" => $target);
   281         if ($this->
link->containsFileLinkId($dom, $file_link_id)) {
   282             $file_id = $this->
link->extractFileFromLinkId($file_link_id);
   284         if (in_array($file_link_id, $this->pc_service->fileList()->getAllFileObjIds($dom))) {
   285             $file_id = $this->
link->extractFileFromLinkId($file_link_id);
   289         foreach ($pcs as $pc) {
   290             $files = \ilObjFile::_getFilesOfObject(
"mep:pg", $pc[
"id"], 0);
   291             $c_file = $this->
link->extractFileFromLinkId($file_link_id);
   292             if (in_array($c_file, $files)) {
   298             $fileObj = new \ilObjFile($file_id, 
false);
   299             $fileObj->sendFile();
   312         bool $a_res_ref_to_obj_id = 
true   317         $nodes = $this->dom_util->path($dom, 
$path);
   318         foreach ($nodes as $node) {
   319             $target = $node->getAttribute(
"Target");
   320             $type = $node->getAttribute(
"Type");
   322             if (substr($target, 0, 4) == 
"il__") {
   323                 $id = substr($target, 4, strlen($target) - 4);
   327                 if ($a_res_ref_to_obj_id && $type == 
"RepositoryItem") {
   328                     $id_arr = explode(
"_", 
$id);
   346                 $new_target = 
"il_" . $a_inst . 
"_" . 
$id;
   347                 $node->setAttribute(
"Target", $new_target);
   352         $path = 
"//MediaAlias";
   353         $nodes = $this->dom_util->path($dom, 
$path);
   354         foreach ($nodes as $node) {
   355             $origin_id = $node->getAttribute(
"OriginId");
   356             if (substr($origin_id, 0, 4) == 
"il__") {
   357                 $new_id = 
"il_" . $a_inst . 
"_" . substr($origin_id, 4, strlen($origin_id) - 4);
   358                 $node->setAttribute(
"OriginId", $new_id);
   363         $path = 
"//FileItem/Identifier";
   364         $nodes = $this->dom_util->path($dom, 
$path);
   365         foreach ($nodes as $node) {
   366             $origin_id = $node->getAttribute(
"Entry");
   367             if (substr($origin_id, 0, 4) == 
"il__") {
   368                 $new_id = 
"il_" . $a_inst . 
"_" . substr($origin_id, 4, strlen($origin_id) - 4);
   369                 $node->setAttribute(
"Entry", $new_id);
   374         $path = 
"//Question";
   375         $nodes = $this->dom_util->path($dom, 
$path);
   376         foreach ($nodes as $node) {
   377             $qref = $node->getAttribute(
"QRef");
   379             if (substr($qref, 0, 4) == 
"il__") {
   380                 $new_id = 
"il_" . $a_inst . 
"_" . substr($qref, 4, strlen($qref) - 4);
   382                 $node->setAttribute(
"QRef", $new_id);
   387         $path = 
"//ContentInclude";
   388         $nodes = $this->dom_util->path($dom, 
$path);
   389         foreach ($nodes as $node) {
   390             $ci = $node->getAttribute(
"InstId");
   392                 $node->setAttribute(
"InstId", $a_inst);
   401         bool $a_self_ass = 
false   403         $a_hid = explode(
":", $a_hier_id);
   407         for ($i = count($content) - 1; $i >= 0; $i--) {
   410             $temp_dom = $this->dom_util->docFromString(
   411                 '<?xml version="1.0" encoding="UTF-8"?>' . 
$c,
   416                 $path = 
"/PageContent";
   417                 $nodes = $this->dom_util->path($temp_dom, 
$path);
   418                 foreach ($nodes as $node) {
   419                     $new_pc_node = $node;
   420                     $cloned_pc_node = $new_pc_node->cloneNode(
true);
   421                     $cloned_pc_node = $this->dom->importNode($cloned_pc_node, 
true);
   437         bool $a_clone_mobs = 
false,
   438         int $a_new_parent_id = 0,
   439         int $obj_copy_id = 0,
   440         bool $self_ass = 
true   442         $this->
handleCopiedContent($page, $this->dom, $self_ass, $a_clone_mobs, $a_new_parent_id, $obj_copy_id);
   443         $this->dom->documentElement;
   444         $xml = $this->dom_util->dump($this->dom->documentElement);
   445         $xml = preg_replace(
'/<\?xml[^>]*>/i', 
"", $xml);
   446         $xml = preg_replace(
'/<!DOCTYPE[^>]*>/i', 
"", $xml);
   462         bool $a_self_ass = 
true,
   463         bool $a_clone_mobs = 
false,
   464         int $new_parent_id = 0,
   467         $defs = $this->pc_service->definition()->getPCDefinitions();
   468         foreach ($defs as $def) {
   469             $cl = $def[
"pc_class"];
   470             if ($cl == 
'ilPCPlugged') {
   472                 \ilPCPlugged::handleCopiedPluggedContent($page, $dom);
   474                 $cl::handleCopiedContent($dom, $a_self_ass, $a_clone_mobs, $new_parent_id, $obj_copy_id);
   487         $curr_name = $curr_node->nodeName;
   489         if (($curr_name == 
"TableData") || ($curr_name == 
"PageObject") ||
   490             ($curr_name == 
"ListItem") || ($curr_name == 
"Section")
   491             || ($curr_name == 
"Tab") || ($curr_name == 
"ContentPopup")
   492             || ($curr_name == 
"GridCell")) {
   496         $hid = $curr_node->getAttribute(
"HierId");
   503             $pos = explode(
"_", $a_pos);
   504             $target_pos = array_pop($pos);
   505             $parent_pos = implode(
"_", $pos);
   508             $parent_pos = $a_pos;
   512         if ($parent_pos != 
"") {
   519         $parent_childs = $parent_node->childNodes;
   520         $cnt_parent_childs = count($parent_childs);
   525                 if ($succ_node = $curr_node->nextSibling) {
   526                     $a_cont_node = $succ_node->parentNode->insertBefore($a_cont_node, $succ_node);
   528                     $a_cont_node = $parent_node->appendChild($a_cont_node);
   536                 $a_cont_node = $succ_node->parentNode->insertBefore($a_cont_node, $succ_node);
   543                 if ($cnt_parent_childs == 0) {
   544                     $a_cont_node = $parent_node->appendChild($a_cont_node);
   546                     $a_cont_node = $parent_childs->item(0)->parentNode->insertBefore($a_cont_node, $parent_childs->item(0));
   558         bool $remove_placeholder = 
true,
   559         bool $placeholder_enabled = 
false   561         if ($a_pcid == 
"" && $a_pos == 
"") {
   566         $curr_name = $curr_node->nodeName;
   569         if (($curr_name == 
"TableData") || ($curr_name == 
"PageObject") ||
   570             ($curr_name == 
"ListItem") || ($curr_name == 
"Section")
   571             || ($curr_name == 
"Tab") || ($curr_name == 
"ContentPopup")
   572             || ($curr_name == 
"GridCell")) {
   576         $hid = $curr_node->getAttribute(
"HierId");
   584             $pos = explode(
"_", $a_pos);
   585             $target_pos = array_pop($pos);
   586             $parent_pos = implode(
"_", $pos);
   589             $parent_pos = $a_pos;
   593         if ($parent_pos != 
"") {
   600         $parent_childs = $parent_node->childNodes;
   601         $cnt_parent_childs = count($parent_childs);
   610                 if ($succ_node = $curr_node->nextSibling) {
   611                     $new_node = $succ_node->parentNode->insertBefore($new_node, $succ_node);
   614                     $new_node = $parent_node->appendChild($new_node);
   623                 $new_node = $succ_node->parentNode->insertBefore($new_node, $succ_node);
   631                 if ($cnt_parent_childs == 0) {
   632                     $new_node = $parent_node->appendChild($new_node);
   634                     $new_node = $parent_childs[0]->parentNode->insertBefore($new_node, $parent_childs[0]);
   642         if ($remove_placeholder && !$placeholder_enabled) {
   643             foreach ($curr_node->childNodes as $sub_node) {
   644                 if ($sub_node->nodeName == 
"PlaceHolder") {
   645                     $curr_node->parentNode->removeChild($curr_node);
   667         string $a_spcid = 
"",
   671         if ($a_source === $a_target) {
   677         $source_node = $content?->getDomNode();
   678         $clone_node = $source_node?->cloneNode(
true);
   685             $content->setDomNode($clone_node);
   699         if (!is_array($a_hids)) {
   703         $time = date(
"Y-m-d H:i:s", time());
   707         foreach ($a_hids as $a_hid) {
   711             $a_hid = explode(
":", $a_hid);
   715             foreach ($hier_ids as $h) {
   716                 if ($h . 
"_" == substr($a_hid[0], 0, strlen($h) + 1)) {
   719                 if ($a_hid[0] . 
"_" == substr($h, 0, strlen($a_hid[0]) + 1)) {
   723             $pc_id[$a_hid[0]] = $a_hid[1];
   724             if ($a_hid[0] != 
"") {
   725                 $hier_ids[$a_hid[0]] = $a_hid[0];
   728         foreach ($skip as $s) {
   729             unset($hier_ids[$s]);
   733         foreach ($hier_ids as $hid) {
   735             if (is_object($curr_node)) {
   736                 if ($curr_node->nodeName == 
"PageContent") {
   737                     $content = $this->dom_util->dump($curr_node);
   739                     $content = preg_replace(
'/PCID=\"[a-z0-9]*\"/i', 
"", $content);
   740                     $content = preg_replace(
'/HierId=\"[a-z0-9_]*\"/i', 
"", $content);
 static setAction(string $a_action)
 
buildDom(bool $a_force=false)
 
copyContents(array $a_hids, \ilObjUser $user)
Copy contents to clipboard. 
 
deleteContent(\ilPageObject $page, string $a_hid, string $a_pcid="", bool $move_operation=false)
 
static _extractObjIdOfTarget(string $a_target)
Extract object id out of target. 
 
checkForTag(string $a_content_tag, string $a_hier_id, string $a_pc_id="")
 
copyXmlContent(\ilPageObject $page, bool $a_clone_mobs=false, int $a_new_parent_id=0, int $obj_copy_id=0, bool $self_ass=true)
 
getContentDomNode(string $a_hier_id, string $a_pc_id="")
 
__construct(\DOMDocument $dom, ?PCDefinition $def=null)
 
pasteContents(\ilObjUser $user, string $a_hier_id, \ilPageObject $page, bool $a_self_ass=false)
 
addToPCClipboard(string $a_content, string $a_time, int $a_nr)
Add a page content item to PC clipboard (should go to another class) 
 
ILIAS COPage Link LinkManager $link
 
ILIAS COPage Dom DomUtil $dom_util
 
handleCopiedContent(\ilPageObject $page, \DOMDocument $dom, bool $a_self_ass=true, bool $a_clone_mobs=false, int $new_parent_id=0, int $obj_copy_id=0)
Handle copied content This function copies items, that must be copied, if page content is duplicated...
 
getDomDoc()
Get dom doc (DOMDocument) 
 
moveContentAfter(\ilPageObject $page, string $a_source, string $a_target, string $a_spcid="", string $a_tpcid="")
move content object from position $a_source before position $a_target (both hierarchical content ids)...
 
static getUsagesOfPage(int $a_usage_id, string $a_usage_type, int $a_hist_nr=0, bool $a_all_hist_nrs=false, string $a_lang="-")
Get page content usages for page. 
 
Content object of ilPageObject (see ILIAS DTD). 
 
static _lookupObjId(int $ref_id)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
getInitialOpenedContent()
Get initial opened content. 
 
switchEnableMultiple(\ilPageObject $page, array $a_hids, bool $a_self_ass=false)
 
downloadFile(\ilPageObject $page, string $file_link_id)
 
setDomNode(DOMNode $node)
 
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD) 
 
deleteContents(\ilPageObject $page, array $a_hids, bool $a_self_ass=false, bool $move_operation=false)
 
static sortHierIds(array $a_array)
Sort an array of Hier IDS in ascending order. 
 
insertContent(\ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true, bool $placeholder_enabled=false)
 
getContentObject(string $a_hier_id, string $a_pc_id="")
Get a content object of the page. 
 
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class) 
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
handleDeleteContent(\ilPageObject $page, $a_node=null, $move_operation=false)
 
DOMNode $page_object_node
 
ILIAS COPage PC DomainService $pc_service
 
link(string $caption, string $href, bool $new_viewport=false)
 
setInitialOpenedContent(string $a_type="", int $a_id=0, string $a_target="")
 
static _lookupType(int $id, bool $reference=false)
 
insertContentNode(\DOMNode $a_cont_node, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="")
 
insertInstIntoIDs(string $a_inst, bool $a_res_ref_to_obj_id=true)
inserts installation id into ids (e.g. 
 
const IL_INSERT_BEFORE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...