예제 #1
0
 /**
  * Rename page
  */
 function rename($a_new_name)
 {
     global $ilDB;
     // replace unallowed characters
     $a_new_name = str_replace(array("<", ">"), '', $a_new_name);
     // replace multiple whitespace characters by one single space
     $a_new_name = trim(preg_replace('!\\s+!', ' ', $a_new_name));
     $page_title = ilWikiUtil::makeDbTitle($a_new_name);
     $pg_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $page_title);
     $xml_new_name = str_replace("&", "&amp;", $a_new_name);
     if ($pg_id == 0 || $pg_id == $this->getId()) {
         include_once "./Services/COPage/classes/class.ilInternalLink.php";
         $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0);
         foreach ($sources as $s) {
             if ($s["type"] == "wpg:pg") {
                 $wpage = new ilWikiPage($s["id"]);
                 $col = ilWikiUtil::processInternalLinks($wpage->getXmlContent(), 0, IL_WIKI_MODE_EXT_COLLECT);
                 $new_content = $wpage->getXmlContent();
                 foreach ($col as $c) {
                     // this complicated procedure is needed due to the fact
                     // that depending on the collation e = é is true
                     // in the (mysql) database
                     // see bug http://www.ilias.de/mantis/view.php?id=11227
                     $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform);
                     $t2 = ilWikiUtil::makeDbTitle($this->getTitle());
                     // this one replaces C2A0 (&nbsp;) by a usual space
                     // otherwise the comparision will fail, since you
                     // get these characters from tiny if more than one
                     // space is repeated in a string. This may not be
                     // 100% but we do not store $t1 anywhere and only
                     // modify it for the comparison
                     $t1 = preg_replace('/\\xC2\\xA0/', ' ', $t1);
                     $t2 = preg_replace('/\\xC2\\xA0/', ' ', $t2);
                     $set = $ilDB->query($q = "SELECT " . $ilDB->quote($t1, "text") . " = " . $ilDB->quote($t2, "text") . " isequal");
                     $rec = $ilDB->fetchAssoc($set);
                     if ($rec["isequal"]) {
                         $new_content = str_replace("[[" . $c["nt"]->mTextform . "]]", "[[" . $xml_new_name . "]]", $new_content);
                         if ($c["text"] != "") {
                             $new_content = str_replace("[[" . $c["text"] . "]]", "[[" . $xml_new_name . "]]", $new_content);
                         }
                         $add = $c["text"] != "" ? "|" . $c["text"] : "";
                         $new_content = str_replace("[[" . $c["nt"]->mTextform . $add . "]]", "[[" . $xml_new_name . $add . "]]", $new_content);
                     }
                 }
                 $wpage->setXmlContent($new_content);
                 //echo htmlentities($new_content);
                 $wpage->update();
             }
         }
         include_once "./Modules/Wiki/classes/class.ilObjWiki.php";
         if (ilObjWiki::_lookupStartPage($this->getWikiId()) == $this->getTitle()) {
             ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name);
         }
         $this->setTitle($a_new_name);
         $this->update();
     }
     return $a_new_name;
 }
예제 #2
0
 /**
  * Clone wiki
  *
  * @param int target ref_id
  * @param int copy id
  */
 public function cloneObject($a_target_id, $a_copy_id = 0)
 {
     global $ilDB, $ilUser, $ilias;
     $new_obj = parent::cloneObject($a_target_id, $a_copy_id);
     $new_obj->setTitle($this->getTitle());
     $new_obj->setStartPage($this->getStartPage());
     $new_obj->setShortTitle($this->getShortTitle());
     $new_obj->setRating($this->getRating());
     $new_obj->setRatingAsBlock($this->getRatingAsBlock());
     $new_obj->setRatingForNewPages($this->getRatingForNewPages());
     $new_obj->setRatingCategories($this->getRatingCategories());
     $new_obj->setPublicNotes($this->getPublicNotes());
     $new_obj->setIntroduction($this->getIntroduction());
     $new_obj->setImportantPages($this->getImportantPages());
     $new_obj->setPageToc($this->getPageToc());
     $new_obj->update();
     // set/copy stylesheet
     include_once "./Services/Style/classes/class.ilObjStyleSheet.php";
     $style_id = $this->getStyleSheetId();
     if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) {
         $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
         $new_id = $style_obj->ilClone();
         $new_obj->setStyleSheetId($new_id);
         $new_obj->update();
     }
     // copy content
     include_once "./Modules/Wiki/classes/class.ilWikiPage.php";
     $pages = ilWikiPage::getAllPages($this->getId());
     if (count($pages) > 0) {
         // if we have any pages, delete the start page first
         $pg_id = ilWikiPage::getPageIdForTitle($new_obj->getId(), $new_obj->getStartPage());
         $start_page = new ilWikiPage($pg_id);
         $start_page->delete();
     }
     $map = array();
     foreach ($pages as $p) {
         $page = new ilWikiPage($p["id"]);
         $new_page = new ilWikiPage();
         $new_page->setTitle($page->getTitle());
         $new_page->setWikiId($new_obj->getId());
         $new_page->setTitle($page->getTitle());
         $new_page->setBlocked($page->getBlocked());
         $new_page->setRating($page->getRating());
         $new_page->create();
         $new_page->setXMLContent($page->copyXMLContent(true));
         $new_page->buildDom();
         $new_page->update();
         $map[$p["id"]] = $new_page->getId();
     }
     // copy important pages
     foreach (ilObjWiki::_lookupImportantPagesList($this->getId()) as $ip) {
         $new_obj->addImportantPage($map[$ip["page_id"]], $ip["ord"], $ip["indent"]);
     }
     // copy rating categories
     include_once "./Services/Rating/classes/class.ilRatingCategory.php";
     foreach (ilRatingCategory::getAllForObject($this->getId()) as $rc) {
         $new_rc = new ilRatingCategory();
         $new_rc->setParentId($new_obj->getId());
         $new_rc->setTitle($rc["title"]);
         $new_rc->setDescription($rc["description"]);
         $new_rc->save();
     }
     return $new_obj;
 }