ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPCParagraph Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilPCParagraph:
+ Collaboration diagram for ilPCParagraph:

Public Member Functions

 init ()
 
 setNode (php4DOMElement $a_node)
 
 createAtNode (php4DOMElement $node)
 Create new page content (incl. More...
 
 createBeforeNode (php4DOMElement $node)
 Create new page content (incl. More...
 
 createAfter (php4DOMElement $node)
 Create paragraph node (incl. More...
 
 create (ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="", bool $from_placeholder=false)
 Create paragraph node (incl. More...
 
 setText (string $a_text, bool $a_auto_split=false)
 Set (xml) content of text paragraph. More...
 
 getText (bool $a_short_mode=false)
 Get (xml) content of paragraph. More...
 
 getParagraphSequenceContent (ilPageObject $a_pg_obj)
 Get paragraph sequenc of current paragraph. More...
 
 setCharacteristic (string $a_char)
 Set Characteristic of paragraph. More...
 
 getCharacteristic ()
 
 setSubCharacteristic (string $a_char)
 
 getAutoIndent ()
 
 setAutoIndent (string $a_char)
 
 getSubCharacteristic ()
 
 setDownloadTitle (string $a_char)
 
 getDownloadTitle ()
 
 setShowLineNumbers (string $a_char)
 
 getShowLineNumbers ()
 
 setLanguage (string $a_lang)
 
 getLanguage ()
 
 input2xml (string $a_text, bool $a_wysiwyg=false, bool $a_handle_lists=true)
 
 autoSplit (string $a_text)
 This function splits a paragraph text that has been already processed with input2xml at each header position =header1=, ==header2== or ===header3=== and returns an array that contains the single chunks. More...
 
 handleNextBr (string $a_str)
 Remove preceding
More...
 
 removeTrailingBr (string $a_str)
 Remove trailing
More...
 
 getType ()
 Need to override getType from ilPageContent to distinguish between Pararagraph and Source. More...
 
 saveJS (ilPageObject $a_pg_obj, string $a_content, string $a_char, string $a_pc_id, string $a_insert_at="", bool $from_placeholder=false)
 Save input coming from ajax. More...
 
 getLastSavedPCId (ilPageObject $a_pg_obj, bool $a_as_ajax_str=false)
 Get last inserted pc ids. More...
 
 updatePage (ilPageObject $a_page)
 Update page object (it would be better to have this centralized and to change the constructors and pass the page object instead the dom object) More...
 
 autoLinkGlossaries (array $a_glos)
 
 getJavascriptFiles (string $a_mode)
 
 getOnloadCode (string $a_mode)
 
 getModel ()
 
 insert (\ilPageObject $page, string $a_content, string $a_char, string $a_pc_id, string $a_insert_at="", string $a_new_pc_id="")
 Save input coming from ajax. More...
 
- Public Member Functions inherited from ilPageContent
 __construct (ilPageObject $a_pg_obj)
 
 setPage (ilPageObject $a_val)
 
 getPage ()
 
 init ()
 Init object. More...
 
 getType ()
 
 setNode (php4DOMElement $a_node)
 Set xml node of page content. More...
 
 getNode ()
 
 getJavascriptFiles (string $a_mode)
 
 getCssFiles (string $a_mode)
 
 getOnloadCode (string $a_mode)
 
 setHierId (string $a_hier_id)
 
 getHierId ()
 
 lookupHierId ()
 
 readHierId ()
 
 setPcId (string $a_pcid)
 
 getPCId ()
 
 setFileDownloadLink (string $a_download_link)
 
 getFileDownloadLink ()
 
 setProfileBackUrl (string $url)
 
 getProfileBackUrl ()
 
 setFullscreenLink (string $a_fullscreen_link)
 
 getFullscreenLink ()
 
 setSourcecodeDownloadScript (string $script_name)
 
 getSourcecodeDownloadScript ()
 
 readPCId ()
 
 writePCId (string $a_pc_id)
 
 setEnabled (string $value)
 Set Enabled value for page content component. More...
 
 enable ()
 
 disable ()
 
 isEnabled ()
 
 createPageContentNode (bool $a_set_this_node=true)
 Create page content node (always use this method first when adding a new element) More...
 
 modifyPageContentPostXsl (string $a_output, string $a_mode, bool $a_abstract_only=false)
 Modify page content after xsl. More...
 
 getModel ()
 Get model as needed for the front-end editor. More...
 

Static Public Member Functions

static attribsToArray (string $a_str)
 converts a string of format var1 = "val1" var2 = "val2" ... More...
 
static _input2xml (string $a_text, string $a_lang, bool $a_wysiwyg=false, bool $a_handle_lists=true)
 Converts user input to xml User input comes as bb code information, e.g. More...
 
static intLinks2xml (string $a_text)
 internal links to xml More...
 
static input2xmlReplaceLists (string $a_text)
 Converts xml from DB to output in edit textarea. More...
 
static xml2outputReplaceLists (string $a_text)
 Replaces

with *. More...

 
static segmentString (string $a_haystack, array $a_needles)
 Segments a string into an array at each position of a substring. More...
 
static xml2output (string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
 Converts xml from DB to output in edit textarea. More...
 
static handleAjaxContent (string $a_content)
 Handle ajax content. More...
 
static handleAjaxContentPost (string $text)
 Post input2xml handling of ajax content. More...
 
static autoLinkGlossariesPage (ilPageObject $a_page, array $a_terms)
 Auto link glossary of whole page. More...
 
static afterPageUpdate (ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
 After page has been updated (or created) More...
 
static beforePageDelete (ilPageObject $a_page)
 Before page is being deleted. More...
 
static afterPageHistoryEntry (ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
 After page history entry has been created. More...
 
static saveAnchors (ilPageObject $a_page, DOMDocument $a_domdoc)
 Save anchors. More...
 
static _deleteAnchors (string $a_parent_type, int $a_page_id, string $a_page_lang)
 Delete anchors of a page. More...
 
static _saveAnchor (string $a_parent_type, int $a_page_id, string $a_page_lang, string $a_anchor_name)
 Save an anchor. More...
 
static _readAnchors (string $a_parent_type, int $a_page_id, string $a_page_lang="-")
 Read anchors of a page. More...
 
static saveMetaKeywords (ilPageObject $a_page, DOMDocument $a_domdoc)
 save all keywords More...
 
- Static Public Member Functions inherited from ilPageContent
static incEdId (string $ed_id)
 Increases an hierarchical editing id at lowest level (last number) More...
 
static decEdId (string $ed_id)
 Decreases an hierarchical editing id at lowest level (last number) More...
 
static sortHierIds (array $a_array)
 Sort an array of Hier IDS in ascending order. More...
 
static isGreaterHierId (string $a, string $b)
 Check whether Hier ID $a is greater than Hier ID $b. More...
 
static getLangVars ()
 Get lang vars needed for editing. More...
 
static handleCopiedContent (DOMDocument $a_domdoc, bool $a_self_ass=true, bool $a_clone_mobs=false, int $new_parent_id=0, int $obj_copy_id=0)
 Handle copied content. More...
 
static afterPageUpdate (ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
 After page has been updated (or created) More...
 
static beforePageDelete (ilPageObject $a_page)
 Before page is being deleted. More...
 
static afterRepositoryCopy (ilPageObject $page, array $mapping, int $source_ref_id)
 After repository (container) copy action. More...
 
static afterPageHistoryEntry (ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
 After page history entry has been created. More...
 
static deleteHistoryLowerEqualThan (string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
 Overwrite in derived classes, if old history entries are being deleted. More...
 

Data Fields

php4DOMElement $par_node = null
 
- Data Fields inherited from ilPageContent
string $hier_id = ""
 
php4DOMElement $node = null
 
php4DOMDocument $dom = null
 
string $page_lang = ""
 

Protected Member Functions

 checkTextArray (array $text)
 Check text array. More...
 
 fixTextArray (array $text)
 
- Protected Member Functions inherited from ilPageContent
 setType (string $a_type)
 Set Type. More...
 

Static Protected Member Functions

static getBBMap ()
 Get bb to xml tag map. More...
 
static getXMLTagMap ()
 Get tag to bb map. More...
 
static replaceBBCode (string $a_text, string $a_bb, string $a_tag)
 
static isValidTagContent (string $content)
 
static replaceBBTagByMatching (string $start_tag, string $end_tag, string $xml_tag_name, string $text, array $attribs)
 Transforms [iln...]...[] to <IntLink...>...</IntLink>, if content is valid, otherwise it removes the bb tags. More...
 
static linkTermsInDom (php4DOMDocument $a_dom, array $a_terms, php4DOMElement $a_par_node=null)
 Link terms in a dom page object in bb style. More...
 

Protected Attributes

string $inserted_pc_id
 
ilObjUser $user
 
ilLanguage $lng
 
- Protected Attributes inherited from ilPageContent
string $pcid
 
string $type = ""
 
ilPageObject $pg_obj
 
string $file_download_link
 
string $fullscreen_link
 
string $sourcecode_download_script
 
ilLogger $log
 
string $profile_back_url = ""
 

Static Protected Attributes

static array $bb_tags
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilPCParagraph

Paragraph of ilPageObject

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.ilPCParagraph.php.

Member Function Documentation

◆ _deleteAnchors()

static ilPCParagraph::_deleteAnchors ( string  $a_parent_type,
int  $a_page_id,
string  $a_page_lang 
)
static

Delete anchors of a page.

Definition at line 2051 of file class.ilPCParagraph.php.

References $DIC, and $ilDB.

2055  : void {
2056  global $DIC;
2057 
2058  $ilDB = $DIC->database();
2059 
2060  $ilDB->manipulate(
2061  "DELETE FROM page_anchor WHERE " .
2062  " page_parent_type = " . $ilDB->quote($a_parent_type, "text") .
2063  " AND page_id = " . $ilDB->quote($a_page_id, "integer") .
2064  " AND page_lang = " . $ilDB->quote($a_page_lang, "text")
2065  );
2066  }
global $DIC
Definition: feed.php:28

◆ _input2xml()

static ilPCParagraph::_input2xml ( string  $a_text,
string  $a_lang,
bool  $a_wysiwyg = false,
bool  $a_handle_lists = true 
)
static

Converts user input to xml User input comes as bb code information, e.g.

"Hello [str]world[/str]."

Definition at line 534 of file class.ilPCParagraph.php.

References ilPageContent\$log, ilLogger\debug(), ilLoggerFactory\getLogger(), input2xmlReplaceLists(), and ilUtil\stripSlashes().

Referenced by input2xml(), PCParagraphTest\test_input2xmlEmpty(), PCParagraphTest\test_input2xmlResult(), PCParagraphTest\test_input2xmlValidXml(), ilPCDataTableGUI\update(), ILIAS\COPage\Editor\Components\Table\TableCommandActionHandler\updateData(), and ilPCDataTableGUI\updateJS().

539  : string {
540  $log = null;
541  if (!defined('COPAGE_TEST')) {
543  $log->debug("_input2xml");
544  $log->debug("...start ");
545  $log->debug("...text: " . substr($a_text, 0, 1000));
546  $log->debug("...lang: " . $a_lang);
547  $log->debug("...wysiwyg: " . $a_wysiwyg);
548  $log->debug("...handle_lists: " . $a_handle_lists);
549  }
550 
551  if (!$a_wysiwyg) {
552  $a_text = ilUtil::stripSlashes($a_text, false);
553  }
554 
555  if ($a_wysiwyg) {
556  $a_text = str_replace("<br />", chr(10), $a_text);
557  }
558 
559  // note: the order of the processing steps is crucial
560  // and should be the same as in xml2output() in REVERSE order!
561  $a_text = trim($a_text);
562 
563  //echo "<br>between:".htmlentities($a_text);
564 
565  // mask html
566  if (!$a_wysiwyg) {
567  $a_text = str_replace("&", "&amp;", $a_text);
568  }
569  $a_text = str_replace("<", "&lt;", $a_text);
570  $a_text = str_replace(">", "&gt;", $a_text);
571 
572  // mask curly brackets
573  /*
574  echo htmlentities($a_text);
575  $a_text = str_replace("{", "&#123;", $a_text);
576  $a_text = str_replace("}", "&#125;", $a_text);
577  echo htmlentities($a_text);*/
578 
579  // linefeed to br
580  $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
581  $a_text = str_replace(chr(13), "<br />", $a_text);
582  $a_text = str_replace(chr(10), "<br />", $a_text);
583 
584  if ($a_handle_lists) {
585  $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
586  }
587 
588  foreach (self::getBBMap() as $bb => $tag) {
589  // remove empty tags
590  $a_text = str_replace("[" . $bb . "][/" . $bb . "]", "", $a_text);
591 
592  // replace bb code by tag
593  $a_text = self::replaceBBCode($a_text, $bb, $tag);
594  }
595 
596  $a_text = self::intLinks2xml($a_text);
597 
598  // external link
599  $ws = "[ \t\r\f\v\n]*";
600  // remove empty external links
601  while (preg_match("~\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]\[\/xln\]~i", $a_text, $found)) {
602  $a_text = str_replace($found[0], "", $a_text);
603  }
604  while (preg_match('~\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]\[\/xln\]~i', $a_text, $found)) {
605  $a_text = str_replace($found[0], "", $a_text);
606  }
607  // external links
608  while (preg_match("~\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]~i", $a_text, $found)) {
609  $old_text = $a_text;
610  $attribs = self::attribsToArray($found[2]);
611  if (isset($attribs["url"])) {
612  $a_text = self::replaceBBTagByMatching(
613  "[" . $found[1] . "]",
614  "[/xln]",
615  "ExtLink",
616  $a_text,
617  [
618  "Href" => $attribs["url"]
619  ]
620  );
621  }
622  if ($old_text === $a_text) {
623  $a_text = str_replace("[" . $found[1] . "]", "[error: " . $found[1] . "]", $a_text);
624  }
625  }
626 
627  // ie/tinymce fix for links without "", see bug #8391
628  /* deprecated, should be removed soon, old IE not supported anymore
629  while (preg_match('~\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]~i', $a_text, $found)) {
630  if ($found[3] != "") {
631  $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $found[3] . "\">", $a_text);
632  } else {
633  $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
634  }
635  }
636  $a_text = preg_replace('~\[\/xln\]~i', "</ExtLink>", $a_text);*/
637 
638  // anchor
639  $ws = "[ \t\r\f\v\n]*";
640  while (preg_match("~\[(anc$ws(name$ws=$ws\"([^\"])*\")$ws)\]~i", $a_text, $found)) {
641  $attribs = self::attribsToArray($found[2]);
642  $a_text = self::replaceBBTagByMatching(
643  "[" . $found[1] . "]",
644  "[/anc]",
645  "Anchor",
646  $a_text,
647  [
648  "Name" => $attribs["name"]
649  ]
650  );
651  }
652 
653  // marked text
654  while (preg_match("~\[(marked$ws(class$ws=$ws\"([^\"])*\")$ws)\]~i", $a_text, $found)) {
655  $attribs = self::attribsToArray($found[2]);
656  if (isset($attribs["class"])) {
657  $a_text = self::replaceBBTagByMatching(
658  "[" . $found[1] . "]",
659  "[/marked]",
660  "Marked",
661  $a_text,
662  [
663  "Class" => $attribs["class"]
664  ]
665  );
666  } else {
667  $a_text = str_replace("[" . $found[1] . "]", "[error:marked" . $found[1] . "]", $a_text);
668  }
669  }
670 
671  if (!is_null($log)) {
672  $log->debug("...finish: " . substr($a_text, 0, 1000));
673  }
674 
675  return $a_text;
676  }
static getLogger(string $a_component_id)
Get component logger.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
debug(string $a_message, array $a_context=array())
static input2xmlReplaceLists(string $a_text)
Converts xml from DB to output in edit textarea.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _readAnchors()

static ilPCParagraph::_readAnchors ( string  $a_parent_type,
int  $a_page_id,
string  $a_page_lang = "-" 
)
static

Read anchors of a page.

Definition at line 2093 of file class.ilPCParagraph.php.

References $DIC, and $ilDB.

Referenced by ilInternalLinkGUI\showLinkHelp().

2097  : array {
2098  global $DIC;
2099 
2100  $ilDB = $DIC->database();
2101 
2102  $and_lang = ($a_page_lang != "")
2103  ? " AND page_lang = " . $ilDB->quote($a_page_lang, "text")
2104  : "";
2105 
2106  $set = $ilDB->query(
2107  "SELECT * FROM page_anchor " .
2108  " WHERE page_parent_type = " . $ilDB->quote($a_parent_type, "text") .
2109  " AND page_id = " . $ilDB->quote($a_page_id, "integer") .
2110  $and_lang
2111  );
2112  $anchors = array();
2113  while ($rec = $ilDB->fetchAssoc($set)) {
2114  $anchors[] = $rec["anchor_name"];
2115  }
2116  return $anchors;
2117  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ _saveAnchor()

static ilPCParagraph::_saveAnchor ( string  $a_parent_type,
int  $a_page_id,
string  $a_page_lang,
string  $a_anchor_name 
)
static

Save an anchor.

Definition at line 2071 of file class.ilPCParagraph.php.

References $DIC, and $ilDB.

2076  : void {
2077  global $DIC;
2078 
2079  $ilDB = $DIC->database();
2080 
2081  $ilDB->manipulate("INSERT INTO page_anchor " .
2082  "(page_parent_type, page_id, page_lang, anchor_name) VALUES (" .
2083  $ilDB->quote($a_parent_type, "text") . "," .
2084  $ilDB->quote($a_page_id, "integer") . "," .
2085  $ilDB->quote($a_page_lang, "text") . "," .
2086  $ilDB->quote($a_anchor_name, "text") .
2087  ")");
2088  }
global $DIC
Definition: feed.php:28

◆ afterPageHistoryEntry()

static ilPCParagraph::afterPageHistoryEntry ( ilPageObject  $a_page,
DOMDocument  $a_old_domdoc,
string  $a_old_xml,
int  $a_old_nr 
)
static

After page history entry has been created.

Definition at line 2018 of file class.ilPCParagraph.php.

2023  : void {
2024  }

◆ afterPageUpdate()

static ilPCParagraph::afterPageUpdate ( ilPageObject  $a_page,
DOMDocument  $a_domdoc,
string  $a_xml,
bool  $a_creation 
)
static

After page has been updated (or created)

Definition at line 1994 of file class.ilPCParagraph.php.

1999  : void {
2000  // pc paragraph
2001  self::saveMetaKeywords($a_page, $a_domdoc);
2002  self::saveAnchors($a_page, $a_domdoc);
2003  }

◆ attribsToArray()

static ilPCParagraph::attribsToArray ( string  $a_str)
static

converts a string of format var1 = "val1" var2 = "val2" ...

into an array

Parameters
string$a_strstring in format: var1 = "val1" var2 = "val2" ...
Returns
array array of variable value pairs

Definition at line 57 of file class.ilPCParagraph.php.

Referenced by ilPCParagraphGUI\xml2outputJS().

57  : array
58  {
59  $attribs = [];
60  while (is_int(strpos($a_str, "="))) {
61  $eq_pos = strpos($a_str, "=");
62  $qu1_pos = strpos($a_str, "\"");
63  $qu2_pos = strpos(substr($a_str, $qu1_pos + 1), "\"") + $qu1_pos + 1;
64  if (is_int($eq_pos) && is_int($qu1_pos) && is_int($qu2_pos)) {
65  $var = trim(substr($a_str, 0, $eq_pos));
66  $val = trim(substr($a_str, $qu1_pos + 1, ($qu2_pos - $qu1_pos) - 1));
67  $attribs[$var] = $val;
68  $a_str = substr($a_str, $qu2_pos + 1);
69  } else {
70  $a_str = "";
71  }
72  }
73  return $attribs;
74  }
+ Here is the caller graph for this function:

◆ autoLinkGlossaries()

ilPCParagraph::autoLinkGlossaries ( array  $a_glos)

Definition at line 1804 of file class.ilPCParagraph.php.

References ilObject\_getAllReferences(), ilObject\_lookupType(), ilGlossaryTerm\getTermList(), and getText().

1806  : void {
1807  if (is_array($a_glos) && count($a_glos) > 0) {
1808  // check which terms occur in the text (we may
1809  // get some false positives due to the strip_tags, but
1810  // we do not want to find strong or list or other stuff
1811  // within the tags
1812  $text = strip_tags($this->getText());
1813  $found_terms = array();
1814  foreach ($a_glos as $glo) {
1815  if (ilObject::_lookupType($glo) == "glo") {
1816  $ref_ids = ilObject::_getAllReferences($glo);
1817  $glo_ref_id = current($ref_ids);
1818  if ($glo_ref_id > 0) {
1819  $terms = ilGlossaryTerm::getTermList([$glo_ref_id]);
1820  foreach ($terms as $t) {
1821  if (is_int(stripos($text, $t["term"]))) {
1822  $found_terms[$t["id"]] = $t;
1823  }
1824  }
1825  }
1826  }
1827  }
1828  // did we find anything? -> modify content
1829  if (count($found_terms) > 0) {
1830  self::linkTermsInDom($this->dom, $found_terms, $this->par_node);
1831  }
1832  }
1833  }
static _getAllReferences(int $id)
get all reference ids for object ID
static getTermList(array $a_glo_ref_id, string $searchterm="", string $a_first_letter="", string $a_def="", int $a_tax_node=0, bool $a_add_amet_fields=false, array $a_amet_filter=null, bool $a_include_references=false)
Get all terms for given set of glossary ids.
getText(bool $a_short_mode=false)
Get (xml) content of paragraph.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ autoLinkGlossariesPage()

static ilPCParagraph::autoLinkGlossariesPage ( ilPageObject  $a_page,
array  $a_terms 
)
static

Auto link glossary of whole page.

Exceptions
ilDateTimeException

Definition at line 1979 of file class.ilPCParagraph.php.

References ilPageObject\buildDom(), ilPageObject\getDom(), and ilPageObject\update().

Referenced by ilObjGlossary\autoLinkGlossaryTerms(), and ilObjContentObject\autoLinkGlossaryTerms().

1982  : void {
1983  $a_page->buildDom();
1984  $a_dom = $a_page->getDom();
1985 
1986  self::linkTermsInDom($a_dom, $a_terms);
1987 
1988  $a_page->update();
1989  }
buildDom(bool $a_force=false)
update(bool $a_validate=true, bool $a_no_history=false)
update complete page content in db (dom xml content is used)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ autoSplit()

ilPCParagraph::autoSplit ( string  $a_text)

This function splits a paragraph text that has been already processed with input2xml at each header position =header1=, ==header2== or ===header3=== and returns an array that contains the single chunks.

Definition at line 1333 of file class.ilPCParagraph.php.

References handleNextBr(), and removeTrailingBr().

Referenced by setText().

1333  : array
1334  {
1335  $a_text = str_replace("=<SimpleBulletList>", "=<br /><SimpleBulletList>", $a_text);
1336  $a_text = str_replace("=<SimpleNumberedList>", "=<br /><SimpleNumberedList>", $a_text);
1337  $a_text = str_replace("</SimpleBulletList>=", "</SimpleBulletList><br />=", $a_text);
1338  $a_text = str_replace("</SimpleNumberedList>=", "</SimpleNumberedList><br />=", $a_text);
1339  $a_text = "<br />" . $a_text . "<br />"; // add preceding and trailing br
1340 
1341  $chunks = array();
1342  $c_text = $a_text;
1343  $head = "";
1344  while ($c_text != "") {
1345  //var_dump($c_text); flush();
1346  //echo "1";
1347  $s1 = strpos($c_text, "<br />=");
1348  if (is_int($s1)) {
1349  //echo "2";
1350  $s2 = strpos($c_text, "<br />==");
1351  if (is_int($s2) && $s2 <= $s1) {
1352  //echo "3";
1353  $s3 = strpos($c_text, "<br />===");
1354  if (is_int($s3) && $s3 <= $s2) { // possible level three header
1355  //echo "4";
1356  $n = strpos($c_text, "<br />", $s3 + 1);
1357  if ($n > ($s3 + 9) && substr($c_text, $n - 3, 9) == "===<br />") {
1358  //echo "5";
1359  // found level three header
1360  if ($s3 > 0 || $head != "") {
1361  //echo "6";
1362  $chunks[] = array("level" => 0,
1363  "text" => $this->removeTrailingBr($head . substr($c_text, 0, $s3)));
1364  $head = "";
1365  }
1366  $chunks[] = array("level" => 3,
1367  "text" => trim(substr($c_text, $s3 + 9, $n - $s3 - 12)));
1368  $c_text = $this->handleNextBr(substr($c_text, $n + 6));
1369  } else {
1370  //echo "7";
1371  $head .= substr($c_text, 0, $n);
1372  $c_text = substr($c_text, $n);
1373  }
1374  } else { // possible level two header
1375  //echo "8";
1376  $n = strpos($c_text, "<br />", $s2 + 1);
1377  if ($n > ($s2 + 8) && substr($c_text, $n - 2, 8) == "==<br />") {
1378  //echo "9";
1379  // found level two header
1380  if ($s2 > 0 || $head != "") {
1381  //echo "A";
1382  $chunks[] = array("level" => 0,
1383  "text" => $this->removeTrailingBr($head . substr($c_text, 0, $s2)));
1384  $head = "";
1385  }
1386  $chunks[] = array("level" => 2, "text" => trim(substr($c_text, $s2 + 8, $n - $s2 - 10)));
1387  $c_text = $this->handleNextBr(substr($c_text, $n + 6));
1388  } else {
1389  //echo "B";
1390  $head .= substr($c_text, 0, $n);
1391  $c_text = substr($c_text, $n);
1392  }
1393  }
1394  } else { // possible level one header
1395  $n = strpos($c_text, "<br />", $s1 + 1);
1396  if ($n > ($s1 + 7) && substr($c_text, $n - 1, 7) == "=<br />") {
1397  // found level one header
1398  if ($s1 > 0 || $head != "") {
1399  $chunks[] = array("level" => 0,
1400  "text" => $this->removeTrailingBr($head . substr($c_text, 0, $s1)));
1401  $head = "";
1402  }
1403  $chunks[] = array("level" => 1, "text" => trim(substr($c_text, $s1 + 7, $n - $s1 - 8)));
1404  $c_text = $this->handleNextBr(substr($c_text, $n + 6));
1405  //echo "<br>ctext:".htmlentities($c_text)."<br>";
1406  } else {
1407  $head .= substr($c_text, 0, $n);
1408  $c_text = substr($c_text, $n);
1409  //echo "<br>head:".$head."c_text:".$c_text."<br>";
1410  }
1411  }
1412  } else {
1413  //echo "G";
1414  $chunks[] = array("level" => 0, "text" => $head . $c_text);
1415  $head = "";
1416  $c_text = "";
1417  }
1418  }
1419  if (count($chunks) == 0) {
1420  $chunks[] = array("level" => 0, "text" => "");
1421  }
1422 
1423 
1424  // remove preceding br
1425  if (substr($chunks[0]["text"], 0, 6) == "<br />") {
1426  $chunks[0]["text"] = substr($chunks[0]["text"], 6);
1427  }
1428 
1429  // remove trailing br
1430  if (substr(
1431  $chunks[count($chunks) - 1]["text"],
1432  strlen($chunks[count($chunks) - 1]["text"]) - 6,
1433  6
1434  ) == "<br />") {
1435  $chunks[count($chunks) - 1]["text"] =
1436  substr($chunks[count($chunks) - 1]["text"], 0, strlen($chunks[count($chunks) - 1]["text"]) - 6);
1437  if ($chunks[count($chunks) - 1]["text"] == "") {
1438  unset($chunks[count($chunks) - 1]);
1439  }
1440  }
1441  return $chunks;
1442  }
removeTrailingBr(string $a_str)
Remove trailing
handleNextBr(string $a_str)
Remove preceding
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ beforePageDelete()

static ilPCParagraph::beforePageDelete ( ilPageObject  $a_page)
static

Before page is being deleted.

Definition at line 2008 of file class.ilPCParagraph.php.

References ilPageObject\getId(), ilPageObject\getLanguage(), and ilPageObject\getParentType().

2010  : void {
2011  // delete anchors
2012  self::_deleteAnchors($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage());
2013  }
+ Here is the call graph for this function:

◆ checkTextArray()

ilPCParagraph::checkTextArray ( array  $text)
protected

Check text array.

Definition at line 296 of file class.ilPCParagraph.php.

References $check, DOMXML_LOAD_PARSING, and domxml_open_mem().

Referenced by setText().

296  : ?array
297  {
298  $check = "";
299  foreach ($text as $t) {
300  $check .= "<Paragraph>" . $t["text"] . "</Paragraph>";
301  }
302  $error = null;
303  //try {
304  $temp_dom = domxml_open_mem(
305  '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $check . '</Paragraph>',
307  $error
308  );
309  //} catch (Exception $e) {
310 
311  //}
312  if (is_string($error) && $error != "") {
313  $error = [$error];
314  }
315  return $error;
316  }
domxml_open_mem($str, $mode=0, &$error=null)
$check
Definition: buildRTE.php:81
const DOMXML_LOAD_PARSING
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

ilPCParagraph::create ( ilPageObject  $a_pg_obj,
string  $a_hier_id,
string  $a_pc_id = "",
bool  $from_placeholder = false 
)

Create paragraph node (incl.

page content node) at given hierarchical ID.

Definition at line 159 of file class.ilPCParagraph.php.

References IL_INSERT_AFTER, and ilPageObject\insertContent().

164  : void {
165  //echo "-$a_pc_id-";
166  //echo "<br>-".htmlentities($a_pg_obj->getXMLFromDom())."-<br><br>"; mk();
167  $this->node = $this->dom->create_element("PageContent");
168 
169  // this next line kicks out placeholders, if something is inserted
170  $a_pg_obj->insertContent(
171  $this,
172  $a_hier_id,
174  $a_pc_id,
175  $from_placeholder
176  );
177 
178  $this->par_node = $this->dom->create_element("Paragraph");
179  $this->par_node = $this->node->append_child($this->par_node);
180  $this->par_node->set_attribute("Language", "");
181  }
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
const IL_INSERT_AFTER
+ Here is the call graph for this function:

◆ createAfter()

ilPCParagraph::createAfter ( php4DOMElement  $node)

Create paragraph node (incl.

page content node) after given node.

Definition at line 141 of file class.ilPCParagraph.php.

References ilPageContent\createPageContentNode(), php4DOMNode\next_sibling(), and php4DOMNode\parent_node().

141  : void
142  {
143  $this->node = $this->createPageContentNode(false);
144  if ($succ_node = $node->next_sibling()) {
145  $this->node = $succ_node->insert_before($this->node, $succ_node);
146  } else {
147  $parent_node = $node->parent_node();
148  $this->node = $parent_node->append_child($this->node);
149  }
150  $this->par_node = $this->dom->create_element("Paragraph");
151  $this->par_node = $this->node->append_child($this->par_node);
152  $this->par_node->set_attribute("Language", "");
153  }
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
+ Here is the call graph for this function:

◆ createAtNode()

ilPCParagraph::createAtNode ( php4DOMElement  $node)

Create new page content (incl.

paragraph) node at node

Definition at line 116 of file class.ilPCParagraph.php.

References php4DOMNode\append_child(), and ilPageContent\createPageContentNode().

116  : void
117  {
118  $this->node = $this->createPageContentNode();
119  $this->par_node = $this->dom->create_element("Paragraph");
120  $this->par_node = $this->node->append_child($this->par_node);
121  $this->par_node->set_attribute("Language", "");
122  $node->append_child($this->node);
123  }
append_child($newnode)
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
+ Here is the call graph for this function:

◆ createBeforeNode()

ilPCParagraph::createBeforeNode ( php4DOMElement  $node)

Create new page content (incl.

paragraph) node at node

Definition at line 128 of file class.ilPCParagraph.php.

References ilPageContent\createPageContentNode(), and php4DOMNode\insert_before().

128  : void
129  {
130  $this->node = $this->createPageContentNode();
131  $this->par_node = $this->dom->create_element("Paragraph");
132  $this->par_node = $this->node->append_child($this->par_node);
133  $this->par_node->set_attribute("Language", "");
134  $node->insert_before($this->node, $node);
135  }
insert_before($newnode, $refnode)
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
+ Here is the call graph for this function:

◆ fixTextArray()

ilPCParagraph::fixTextArray ( array  $text)
protected

Definition at line 318 of file class.ilPCParagraph.php.

References ilPageContent\$dom, $i, and ilPageContent\$node.

318  : array
319  {
320  $dom = new DOMDocument();
321  $dom->recover = true;
322  // try to fix
323  for ($i = 0, $iMax = count($text); $i < $iMax; $i++) {
324  $dom->loadXML(
325  '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text[$i]["text"] . '</Paragraph>',
326  LIBXML_NOWARNING | LIBXML_NOERROR
327  );
328  foreach ($dom->childNodes as $node) {
329  if ($node->nodeName == "Paragraph") {
330  $inner = "";
331  foreach ($node->childNodes as $child) {
332  $inner .= $dom->saveXML($child);
333  }
334  $text[$i]["text"] = $inner;
335  }
336  }
337  }
338  return $text;
339  }
php4DOMElement $node
php4DOMDocument $dom
$i
Definition: metadata.php:41

◆ getAutoIndent()

ilPCParagraph::getAutoIndent ( )

Definition at line 450 of file class.ilPCParagraph.php.

450  : string
451  {
452  return (string) $this->par_node->get_attribute("AutoIndent");
453  }

◆ getBBMap()

static ilPCParagraph::getBBMap ( )
staticprotected

Get bb to xml tag map.

Definition at line 88 of file class.ilPCParagraph.php.

88  : array
89  {
90  return self::$bb_tags;
91  }

◆ getCharacteristic()

ilPCParagraph::getCharacteristic ( )

Definition at line 431 of file class.ilPCParagraph.php.

Referenced by getModel(), getType(), and setText().

431  : string
432  {
433  if (is_object($this->par_node)) {
434  return $this->par_node->get_attribute("Characteristic");
435  }
436  return "";
437  }
+ Here is the caller graph for this function:

◆ getDownloadTitle()

ilPCParagraph::getDownloadTitle ( )

Definition at line 482 of file class.ilPCParagraph.php.

482  : string
483  {
484  return $this->par_node->get_attribute("DownloadTitle");
485  }

◆ getJavascriptFiles()

ilPCParagraph::getJavascriptFiles ( string  $a_mode)

Definition at line 2182 of file class.ilPCParagraph.php.

References ilLinkifyUtil\getLocalJsPaths().

2182  : array
2183  {
2184  $adve_settings = new ilSetting("adve");
2185 
2186  if ($a_mode != "edit" && $adve_settings->get("auto_url_linking")) {
2188  }
2189 
2190  return array();
2191  }
static getLocalJsPaths()
Get paths of necessary js files.
+ Here is the call graph for this function:

◆ getLanguage()

ilPCParagraph::getLanguage ( )

Definition at line 506 of file class.ilPCParagraph.php.

Referenced by input2xml(), and setText().

506  : string
507  {
508  return $this->par_node->get_attribute("Language");
509  }
+ Here is the caller graph for this function:

◆ getLastSavedPCId()

ilPCParagraph::getLastSavedPCId ( ilPageObject  $a_pg_obj,
bool  $a_as_ajax_str = false 
)

Get last inserted pc ids.

Definition at line 1563 of file class.ilPCParagraph.php.

References ilPageContent\$hier_id, $inserted_pc_id, ilPageObject\addHierIDs(), ilPageObject\getHierIdsForPCIds(), and ilPageObject\stripHierIDs().

1566  : string {
1567  $sep = "";
1568 
1569  if ($a_as_ajax_str) {
1570  $a_pg_obj->stripHierIDs();
1571  $a_pg_obj->addHierIDs();
1572  $ids = "###";
1573  $combined = $a_pg_obj->getHierIdsForPCIds(
1574  array($this->inserted_pc_id)
1575  );
1576  foreach ($combined as $pc_id => $hier_id) {
1577  //echo "1";
1578  $ids .= $sep . $hier_id . ":" . $pc_id;
1579  $sep = ";";
1580  }
1581  $ids .= "###";
1582  return $ids;
1583  }
1584 
1585  return $this->inserted_pc_id;
1586  }
stripHierIDs()
strip all hierarchical id attributes out of the dom tree
getHierIdsForPCIds(array $a_pc_ids)
Get hier ids for a set of pc ids.
addHierIDs()
Add hierarchical ID (e.g.
+ Here is the call graph for this function:

◆ getModel()

ilPCParagraph::getModel ( )

Definition at line 2204 of file class.ilPCParagraph.php.

References getCharacteristic(), getText(), xml2output(), and ilPCParagraphGUI\xml2outputJS().

2204  : ?stdClass
2205  {
2206  $model = new \stdClass();
2207  $s_text = $this->getText();
2208  $s_text = $this->xml2output($s_text, true, false);
2209  $s_text = ilPCParagraphGUI::xml2outputJS($s_text);
2210  $char = $this->getCharacteristic();
2211  if ($char == "") {
2212  $char = "Standard";
2213  }
2214  $model->characteristic = $char;
2215  $model->text = $s_text;
2216 
2217  return $model;
2218  }
static xml2outputJS(string $s_text)
Prepare content for js output.
static xml2output(string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
Converts xml from DB to output in edit textarea.
getText(bool $a_short_mode=false)
Get (xml) content of paragraph.
+ Here is the call graph for this function:

◆ getOnloadCode()

ilPCParagraph::getOnloadCode ( string  $a_mode)

Definition at line 2193 of file class.ilPCParagraph.php.

2193  : array
2194  {
2195  $adve_settings = new ilSetting("adve");
2196 
2197  if ($a_mode != "edit" && $adve_settings->get("auto_url_linking")) {
2198  return array("il.ExtLink.autolink('.ilc_Paragraph, .ilc_page_fn_Footnote','ilc_link_ExtLink');");
2199  }
2200 
2201  return array();
2202  }

◆ getParagraphSequenceContent()

ilPCParagraph::getParagraphSequenceContent ( ilPageObject  $a_pg_obj)

Get paragraph sequenc of current paragraph.

Definition at line 361 of file class.ilPCParagraph.php.

References ilPageContent\$hier_id, $i, ilPageObject\getContentObject(), ilPageContent\readHierId(), ilPageContent\readPCId(), and ilPCParagraphGUI\xml2outputJS().

363  : string {
364  $childs = $this->par_node->parent_node()->parent_node()->child_nodes();
365  $seq = array();
366  $cur_seq = array();
367  $found = false;
368  $pc_id = $this->readPCId();
369  $hier_id = $this->readHierId();
370  for ($i = 0, $iMax = count($childs); $i < $iMax; $i++) {
371  $pchilds = $childs[$i]->child_nodes();
372  if ($pchilds[0]->node_name() == "Paragraph" &&
373  $pchilds[0]->get_attribute("Characteristic") != "Code") {
374  $cur_seq[] = $childs[$i];
375 
376  // check whether this is the sequence of the current paragraph
377  if ($childs[$i]->get_attribute("PCID") == $pc_id &&
378  $childs[$i]->get_attribute("HierId") == $hier_id) {
379  $found = true;
380  }
381 
382  // if this is the current sequenc, get it
383  if ($found) {
384  $seq = $cur_seq;
385  }
386  } else {
387  // non-paragraph element found -> init the current sequence
388  $cur_seq = array();
389  $found = false;
390  }
391  }
392 
393  $content = "";
394  $ids = "###";
395  $id_sep = "";
396  foreach ($seq as $p_node) {
397  $ids .= $id_sep . $p_node->get_attribute("HierId") . ":" . $p_node->get_attribute("PCID");
398  $po = $a_pg_obj->getContentObject(
399  $p_node->get_attribute("HierId"),
400  $p_node->get_attribute("PCID")
401  );
402  $s_text = $po->getText();
403  $s_text = $po->xml2output($s_text, true, false);
404  $char = $po->getCharacteristic();
405  if ($char == "") {
406  $char = "Standard";
407  }
408  $s_text = ilPCParagraphGUI::xml2outputJS($s_text);
409  $content .= $s_text;
410  $id_sep = ";";
411  }
412  $ids .= "###";
413 
414  return $ids . $content;
415  }
static xml2outputJS(string $s_text)
Prepare content for js output.
getContentObject(string $a_hier_id, string $a_pc_id="")
Get a content object of the page.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ getShowLineNumbers()

ilPCParagraph::getShowLineNumbers ( )

Definition at line 496 of file class.ilPCParagraph.php.

496  : string
497  {
498  return $this->par_node->get_attribute("ShowLineNumbers");
499  }

◆ getSubCharacteristic()

ilPCParagraph::getSubCharacteristic ( )

Definition at line 466 of file class.ilPCParagraph.php.

466  : string
467  {
468  return $this->par_node->get_attribute("SubCharacteristic");
469  }

◆ getText()

ilPCParagraph::getText ( bool  $a_short_mode = false)

Get (xml) content of paragraph.

Definition at line 344 of file class.ilPCParagraph.php.

References $i.

Referenced by autoLinkGlossaries(), and getModel().

344  : string
345  {
346  if (is_object($this->par_node)) {
347  $content = "";
348  $childs = $this->par_node->child_nodes();
349  for ($i = 0, $iMax = count($childs); $i < $iMax; $i++) {
350  $content .= $this->dom->dump_node($childs[$i]);
351  }
352  return $content;
353  } else {
354  return "";
355  }
356  }
$i
Definition: metadata.php:41
+ Here is the caller graph for this function:

◆ getType()

ilPCParagraph::getType ( )

Need to override getType from ilPageContent to distinguish between Pararagraph and Source.

Definition at line 1477 of file class.ilPCParagraph.php.

References getCharacteristic().

1477  : string
1478  {
1479  return ($this->getCharacteristic() == "Code")
1480  ? "src"
1481  : parent::getType();
1482  }
+ Here is the call graph for this function:

◆ getXMLTagMap()

static ilPCParagraph::getXMLTagMap ( )
staticprotected

Get tag to bb map.

Definition at line 96 of file class.ilPCParagraph.php.

96  : array
97  {
98  return array_flip(self::$bb_tags);
99  }

◆ handleAjaxContent()

static ilPCParagraph::handleAjaxContent ( string  $a_content)
static

Handle ajax content.

Definition at line 1592 of file class.ilPCParagraph.php.

References $i, $id, $res, ilPageContentGUI\_getCommonBBButtons(), ilDOM2Util\addParent(), ilDOM2Util\changeName(), ilDOM2Util\replaceByChilds(), and ilUtil\stripSlashes().

Referenced by ILIAS\COPage\Editor\Components\Table\TableCommandActionHandler\updateData(), and ilPCDataTableGUI\updateJS().

1594  : ?array {
1595  $a_content = "<dummy>" . $a_content . "</dummy>";
1596 
1597  $doc = new DOMDocument();
1598 
1599  $content = ilUtil::stripSlashes($a_content, false);
1600 
1601  // $content = str_replace("&lt;", "<", $content);
1602  // $content = str_replace("&gt;", ">", $content);
1603  //echo "\n\n".$content;
1604  $res = $doc->loadXML($content);
1605 
1606  if (!$res) {
1607  return null;
1608  }
1609 
1610  // convert tags
1611  $xpath = new DOMXpath($doc);
1612 
1613  $tags = self::getXMLTagMap();
1614 
1615  $elements = $xpath->query("//span");
1616  while (!is_null($elements) && !is_null($element = $elements->item(0))) {
1617  //$element = $elements->item(0);
1618  $class = $element->getAttribute("class");
1619  if (substr($class, 0, 16) == "ilc_text_inline_") {
1620  $class_arr = explode(" ", $class);
1621  $tag = substr($class_arr[0], 16);
1622  if (isset($tags[$tag])) { // known tag like strong
1623  $cnode = ilDOM2Util::changeName($element, "il" . substr($class_arr[0], 16), false);
1624  } else { // unknown tag -> marked text
1625  $cnode = ilDOM2Util::changeName($element, "ilMarked", false);
1626  $cnode->setAttribute("Class", substr($class_arr[0], 16));
1627  }
1628  for ($i = 1, $iMax = count($class_arr); $i < $iMax; $i++) {
1629  $tag = substr($class_arr[$i], 16);
1630  if (isset($tags[$tag])) { // known tag like strong
1631  $cnode = ilDOM2Util::addParent($cnode, "il" . substr($class_arr[$i], 16));
1632  } else { // unknown tag -> marked element
1633  $cnode = ilDOM2Util::addParent($cnode, "ilMarked");
1634  $cnode->setAttribute("Class", substr($class_arr[$i], 16));
1635  }
1636  }
1637  } else {
1638  ilDOM2Util::replaceByChilds($element);
1639  }
1640 
1641  $elements = $xpath->query("//span");
1642  }
1643 
1644  // convert tags
1645  $xpath = new DOMXpath($doc);
1646  $elements = $xpath->query("/dummy/div");
1647 
1648  $ret = array();
1649  if (!is_null($elements)) {
1650  foreach ($elements as $element) {
1651  $id = $element->getAttribute("id");
1652  $class = $element->getAttribute("class");
1653  $class = substr($class, 15);
1654  if (trim($class) == "") {
1655  $class = "Standard";
1656  }
1657 
1658  $text = $doc->saveXML($element);
1659  $text = str_replace("<br/>", "\n", $text);
1660 
1661  // remove wrapping div
1662  $pos = strpos($text, ">");
1663  $text = substr($text, $pos + 1);
1664  $pos = strrpos($text, "<");
1665  $text = substr($text, 0, $pos);
1666 
1667  // todo: remove empty spans <span ...> </span>
1668 
1669  // replace tags by bbcode
1670  foreach (ilPageContentGUI::_getCommonBBButtons() as $bb => $cl) {
1671  if (!in_array($bb, array("code", "tex", "fn", "xln"))) {
1672  $text = str_replace(
1673  "<il" . $cl . ">",
1674  "[" . $bb . "]",
1675  $text
1676  );
1677  $text = str_replace(
1678  "</il" . $cl . ">",
1679  "[/" . $bb . "]",
1680  $text
1681  );
1682  $text = str_replace("<il" . $cl . "/>", "", $text);
1683  }
1684  }
1685  $text = str_replace(
1686  array("<code>", "</code>"),
1687  array("[code]", "[/code]"),
1688  $text
1689  );
1690  $text = str_replace(
1691  array('<sup class="ilc_sup_Sup">', '<sup>', "</sup>"),
1692  array("[sup]", "[sup]", "[/sup]"),
1693  $text
1694  );
1695  $text = str_replace(
1696  array('<sub class="ilc_sub_Sub">', '<sub>', "</sub>"),
1697  array("[sub]", "[sub]", "[/sub]"),
1698  $text
1699  );
1700 
1701  $text = str_replace("<code/>", "", $text);
1702  $text = str_replace('<ul class="ilc_list_u_BulletedList"/>', "", $text);
1703  $text = str_replace('<ul class="ilc_list_o_NumberedList"/>', "", $text);
1704 
1705  // replace marked text
1706  // external links
1707  $any = "[^>]*";
1708  while (preg_match('~<ilMarked(' . $any . ')>~i', $text, $found)) {
1709  $attribs = self::attribsToArray($found[1]);
1710  $text = str_replace("<ilMarked" . $found[1] . ">", "[marked class=\"" . $attribs["Class"] . "\"]", $text);
1711  }
1712  $text = str_replace("</ilMarked>", "[/marked]", $text);
1713 
1714 
1715  $ret[] = array("text" => $text, "id" => $id, "class" => $class);
1716  }
1717  }
1718 
1719  // we should only have one here!
1720  return $ret[0];
1721  }
$res
Definition: ltiservices.php:69
static replaceByChilds(DOMNode $node)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static changeName(DOMNode $node, string $name, bool $keep_attributes=true)
static addParent(DOMNode $node, string $name)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleAjaxContentPost()

static ilPCParagraph::handleAjaxContentPost ( string  $text)
static

Post input2xml handling of ajax content.

Definition at line 1726 of file class.ilPCParagraph.php.

Referenced by insert(), saveJS(), PCParagraphTest\testHandleAjaxContentPost(), ILIAS\COPage\Editor\Components\Table\TableCommandActionHandler\updateData(), and ilPCDataTableGUI\updateJS().

1726  : string
1727  {
1728  $text = str_replace(
1729  array("&lt;ul&gt;", "&lt;/ul&gt;"),
1730  array("<SimpleBulletList>", "</SimpleBulletList>"),
1731  $text
1732  );
1733  $text = str_replace(
1734  array("&lt;ul class='ilc_list_u_BulletedList'&gt;", "&lt;/ul&gt;"),
1735  array("<SimpleBulletList>", "</SimpleBulletList>"),
1736  $text
1737  );
1738  $text = str_replace(
1739  array("&lt;ul class=\"ilc_list_u_BulletedList\"&gt;", "&lt;/ul&gt;"),
1740  array("<SimpleBulletList>", "</SimpleBulletList>"),
1741  $text
1742  );
1743  $text = str_replace(
1744  array("&lt;ol&gt;", "&lt;/ol&gt;"),
1745  array("<SimpleNumberedList>", "</SimpleNumberedList>"),
1746  $text
1747  );
1748  $text = str_replace(
1749  array("&lt;ol class='ilc_list_o_NumberedList'&gt;", "&lt;/ol&gt;"),
1750  array("<SimpleNumberedList>", "</SimpleNumberedList>"),
1751  $text
1752  );
1753  $text = str_replace(
1754  array("&lt;ol class=\"ilc_list_o_NumberedList\"&gt;", "&lt;/ol&gt;"),
1755  array("<SimpleNumberedList>", "</SimpleNumberedList>"),
1756  $text
1757  );
1758  $text = str_replace(
1759  array("&lt;li&gt;", "&lt;/li&gt;"),
1760  array("<SimpleListItem>", "</SimpleListItem>"),
1761  $text
1762  );
1763  $text = str_replace(
1764  array("&lt;li class='ilc_list_item_StandardListItem'&gt;", "&lt;/li&gt;"),
1765  array("<SimpleListItem>", "</SimpleListItem>"),
1766  $text
1767  );
1768  $text = str_replace(
1769  array("&lt;li class=\"ilc_list_item_StandardListItem\"&gt;", "&lt;/li&gt;"),
1770  array("<SimpleListItem>", "</SimpleListItem>"),
1771  $text
1772  );
1773 
1774  $text = str_replace(
1775  array("&lt;li class=\"ilc_list_item_StandardListItem\"/&gt;"),
1776  array("<SimpleListItem></SimpleListItem>"),
1777  $text
1778  );
1779 
1780  $text = str_replace("<SimpleBulletList><br />", "<SimpleBulletList>", $text);
1781  $text = str_replace("<SimpleNumberedList><br />", "<SimpleNumberedList>", $text);
1782  $text = str_replace("<br /><SimpleBulletList>", "<SimpleBulletList>", $text);
1783  $text = str_replace("<br /><SimpleNumberedList>", "<SimpleNumberedList>", $text);
1784  $text = str_replace("</SimpleBulletList><br />", "</SimpleBulletList>", $text);
1785  $text = str_replace("</SimpleNumberedList><br />", "</SimpleNumberedList>", $text);
1786  $text = str_replace("</SimpleListItem><br />", "</SimpleListItem>", $text);
1787 
1788  return $text;
1789  }
+ Here is the caller graph for this function:

◆ handleNextBr()

ilPCParagraph::handleNextBr ( string  $a_str)

Remove preceding

Definition at line 1447 of file class.ilPCParagraph.php.

Referenced by autoSplit().

1447  : string
1448  {
1449  // do not remove, if next line starts with a "=", otherwise two
1450  // headlines in a row will not be recognized
1451  if (substr($a_str, 0, 6) == "<br />" && substr($a_str, 6, 1) != "=") {
1452  $a_str = substr($a_str, 6);
1453  } else {
1454  // if next line starts with a "=" we need to reinsert the <br />
1455  // otherwise it will not be recognized
1456  if (substr($a_str, 0, 1) == "=") {
1457  $a_str = "<br />" . $a_str;
1458  }
1459  }
1460  return $a_str;
1461  }
+ Here is the caller graph for this function:

◆ init()

ilPCParagraph::init ( )

Definition at line 76 of file class.ilPCParagraph.php.

References $DIC, ILIAS\Repository\lng(), ilPageContent\setType(), and ILIAS\Repository\user().

76  : void
77  {
78  global $DIC;
79 
80  $this->user = $DIC->user();
81  $this->lng = $DIC->language();
82  $this->setType("par");
83  }
setType(string $a_type)
Set Type.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ input2xml()

ilPCParagraph::input2xml ( string  $a_text,
bool  $a_wysiwyg = false,
bool  $a_handle_lists = true 
)

Definition at line 511 of file class.ilPCParagraph.php.

References _input2xml(), and getLanguage().

515  : string {
516  return $this->_input2xml($a_text, $this->getLanguage(), $a_wysiwyg, $a_handle_lists);
517  }
static _input2xml(string $a_text, string $a_lang, bool $a_wysiwyg=false, bool $a_handle_lists=true)
Converts user input to xml User input comes as bb code information, e.g.
+ Here is the call graph for this function:

◆ input2xmlReplaceLists()

static ilPCParagraph::input2xmlReplaceLists ( string  $a_text)
static

Converts xml from DB to output in edit textarea.

Parameters
string$a_textxml from db
Returns
string string ready for edit textarea

Definition at line 974 of file class.ilPCParagraph.php.

References $i, and $rows.

Referenced by _input2xml().

976  : string {
977  $rows = explode("<br />", $a_text . "<br />");
978  //var_dump($a_text);
979 
980  $old_level = 0;
981 
982  $text = "";
983  $clist = [];
984 
985  foreach ($rows as $row) {
986  $level = 0;
987  if (str_replace("#", "*", substr($row, 0, 3)) == "***") {
988  $level = 3;
989  } elseif (str_replace("#", "*", substr($row, 0, 2)) == "**") {
990  $level = 2;
991  } elseif (str_replace("#", "*", substr($row, 0, 1)) == "*") {
992  $level = 1;
993  }
994 
995  // end previous line
996  if ($level < $old_level) {
997  for ($i = $old_level; $i > $level; $i--) {
998  $text .= "</SimpleListItem></" . $clist[$i] . ">";
999  }
1000  if ($level > 0) {
1001  $text .= "</SimpleListItem>";
1002  }
1003  } elseif ($old_level > 0 && $level > 0 && ($level == $old_level)) {
1004  $text .= "</SimpleListItem>";
1005  } elseif (($level == $old_level) && $text != "") {
1006  $text .= "<br />";
1007  }
1008 
1009  // start next line
1010  if ($level > $old_level) {
1011  for ($i = $old_level + 1; $i <= $level; $i++) {
1012  if (substr($row, $i - 1, 1) == "*") {
1013  $clist[$i] = "SimpleBulletList";
1014  } else {
1015  $clist[$i] = "SimpleNumberedList";
1016  }
1017  $text .= "<" . $clist[$i] . "><SimpleListItem>";
1018  }
1019  } elseif ($old_level > 0 && $level > 0) {
1020  $text .= "<SimpleListItem>";
1021  }
1022  $text .= substr($row, $level);
1023 
1024  $old_level = $level;
1025  }
1026 
1027  // remove "<br />" at the end
1028  if (substr($text, strlen($text) - 6) == "<br />") {
1029  $text = substr($text, 0, strlen($text) - 6);
1030  }
1031 
1032  return $text;
1033  }
$rows
Definition: xhr_table.php:10
$i
Definition: metadata.php:41
+ Here is the caller graph for this function:

◆ insert()

ilPCParagraph::insert ( \ilPageObject  $page,
string  $a_content,
string  $a_char,
string  $a_pc_id,
string  $a_insert_at = "",
string  $a_new_pc_id = "" 
)

Save input coming from ajax.

Returns
array|bool|string
Exceptions
ilCOPagePCEditException
ilCOPageUnknownPCTypeException
ilDateTimeException

Definition at line 2227 of file class.ilPCParagraph.php.

References $ilUser, ILIAS\LTI\ToolProvider\$updated, $user, exit, ilPageObject\generatePcId(), ilPageObject\getContentObject(), ilPageContent\getPage(), and handleAjaxContentPost().

2234  {
2235  $ilUser = $this->user;
2236 
2237  $this->log->debug("step 1: " . substr($a_content, 0, 1000));
2238 
2239  try {
2240  $t = self::handleAjaxContent($a_content);
2241  } catch (Exception $ex) {
2242  return $ex->getMessage() . ": " . htmlentities($a_content);
2243  }
2244 
2245  $this->log->debug("step 2: " . substr($t["text"], 0, 1000));
2246  if ($t === false) {
2247  return false;
2248  }
2249 
2250  $pc_id = explode(":", $a_pc_id);
2251  $insert_at = explode(":", $a_insert_at);
2252  $t_id = explode(":", $t["id"]);
2253 
2254  // insert new paragraph
2255  if ($a_insert_at != "") {
2256  $par = new ilPCParagraph($this->getPage());
2257  $par->create($page, $insert_at[0], $insert_at[1]);
2258  } else {
2259  $par = $page->getContentObject($pc_id[0], $pc_id[1]);
2260  }
2261 
2262  if ($a_insert_at != "") {
2263  $pc_id = ($a_new_pc_id != "")
2264  ? $a_new_pc_id
2265  : $page->generatePcId();
2266  $par->writePCId($pc_id);
2267  $this->inserted_pc_id = $pc_id;
2268  } else {
2269  $this->inserted_pc_id = $pc_id[1];
2270  }
2271 
2272  $par->setLanguage($ilUser->getLanguage());
2273  $par->setCharacteristic($t["class"]);
2274 
2275  $t2 = $par->input2xml($t["text"], true, false);
2276  $this->log->debug("step 3: " . substr($t2, 0, 1000));
2277 
2279  $this->log->debug("step 4: " . substr($t2, 0, 1000));
2280 
2281  $updated = $par->setText($t2, true);
2282 
2283  if ($updated !== true) {
2284  echo $updated;
2285  exit;
2286  }
2287  $updated = $par->updatePage($page);
2288  return $updated;
2289  }
exit
Definition: login.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static handleAjaxContentPost(string $text)
Post input2xml handling of ajax content.
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:

◆ intLinks2xml()

static ilPCParagraph::intLinks2xml ( string  $a_text)
static

internal links to xml

Definition at line 768 of file class.ilPCParagraph.php.

References $DIC, and ilObjUser\_lookupId().

770  : string {
771  global $DIC;
772 
773  $objDefinition = $DIC["objDefinition"];
774  $obj_id = 0;
775  $rtypes = $objDefinition->getAllRepositoryTypes();
776 
777  // internal links
778  //$any = "[^\]]*"; // this doesn't work :-(
779  $ws = "[ \t\r\f\v\n]*";
780  $ltypes = "page|chap|term|media|obj|dfile|sess|wpage|ppage|" . implode("|", $rtypes);
781  // empty internal links
782  while (preg_match('~\[(iln' . $ws . '((inst' . $ws . '=' . $ws . '([\"0-9])*)?' . $ws .
783  "((" . $ltypes . ")$ws=$ws([\"0-9])*)$ws" .
784  "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]\[\/iln\]~i", $a_text, $found)) {
785  $a_text = str_replace($found[0], "", $a_text);
786  }
787  while (preg_match('~\[(iln' . $ws . '((inst' . $ws . '=' . $ws . '([\"0-9])*)?' . $ws .
788  "((" . $ltypes . ")$ws=$ws([\"0-9])*)$ws" .
789  "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]~i", $a_text, $found)) {
790  $attribs = self::attribsToArray($found[2]);
791  $inst_str = $attribs["inst"] ?? "";
792  // pages
793  if (isset($attribs["page"])) {
794  $a_text = self::replaceBBTagByMatching(
795  "[" . $found[1] . "]",
796  "[/iln]",
797  "IntLink",
798  $a_text,
799  [
800  "Target" => "il_" . $inst_str . "_pg_" . $attribs['page'],
801  "Type" => "PageObject",
802  "TargetFrame" => $found[10] ?? "",
803  "Anchor" => $attribs["anchor"] ?? ""
804  ]
805  );
806  }
807  // chapters
808  elseif (isset($attribs["chap"])) {
809  $a_text = self::replaceBBTagByMatching(
810  "[" . $found[1] . "]",
811  "[/iln]",
812  "IntLink",
813  $a_text,
814  [
815  "Target" => "il_" . $inst_str . "_st_" . $attribs['chap'],
816  "Type" => "StructureObject",
817  "TargetFrame" => $found[10] ?? ""
818  ]
819  );
820  }
821  // glossary terms
822  elseif (isset($attribs["term"])) {
823  $a_text = self::replaceBBTagByMatching(
824  "[" . $found[1] . "]",
825  "[/iln]",
826  "IntLink",
827  $a_text,
828  [
829  "Target" => "il_" . $inst_str . "_git_" . $attribs['term'],
830  "Type" => "GlossaryItem",
831  "TargetFrame" => (($found[10] ?? "") == "New")
832  ? "New"
833  : "Glossary"
834  ]
835  );
836  }
837  // wiki pages
838  elseif (isset($attribs["wpage"])) {
839  $a_text = self::replaceBBTagByMatching(
840  "[" . $found[1] . "]",
841  "[/iln]",
842  "IntLink",
843  $a_text,
844  [
845  "Target" => "il_" . $inst_str . "_wpage_" . $attribs['wpage'],
846  "Type" => "WikiPage",
847  "Anchor" => $attribs["anchor"] ?? ""
848  ]
849  );
850  }
851  // portfolio pages
852  elseif (isset($attribs["ppage"])) {
853  $a_text = self::replaceBBTagByMatching(
854  "[" . $found[1] . "]",
855  "[/iln]",
856  "IntLink",
857  $a_text,
858  [
859  "Target" => "il_" . $inst_str . "_ppage_" . $attribs['ppage'],
860  "Type" => "PortfolioPage"
861  ]
862  );
863  }
864  // media object
865  elseif (isset($attribs["media"])) {
866  $a_text = self::replaceBBTagByMatching(
867  "[" . $found[1] . "]",
868  "[/iln]",
869  "IntLink",
870  $a_text,
871  [
872  "Target" => "il_" . $inst_str . "_mob_" . $attribs['media'],
873  "Type" => "MediaObject",
874  "TargetFrame" => $found[10] ?? ""
875  ]
876  );
877  }
878  // direct download file (no repository object)
879  elseif (isset($attribs["dfile"])) {
880  $a_text = self::replaceBBTagByMatching(
881  "[" . $found[1] . "]",
882  "[/iln]",
883  "IntLink",
884  $a_text,
885  [
886  "Target" => "il_" . $inst_str . "_dfile_" . $attribs['dfile'],
887  "Type" => "File"
888  ]
889  );
890  }
891  // repository items (id is ref_id (will be used internally but will
892  // be replaced by object id for export purposes)
893  else {
894  foreach ($objDefinition->getAllRepositoryTypes() as $t) {
895  if (isset($attribs[$t])) {
896  $obj_id = $attribs[$t];
897  }
898  }
899  if (isset($attribs["obj"])) {
900  $obj_id = $attribs["obj"];
901  }
902 
903  if ($obj_id > 0) {
904  if ($inst_str == "") {
905  $a_text = self::replaceBBTagByMatching(
906  "[" . $found[1] . "]",
907  "[/iln]",
908  "IntLink",
909  $a_text,
910  [
911  "Target" => "il_" . $inst_str . "_obj_" . $obj_id,
912  "Type" => "RepositoryItem"
913  ]
914  );
915  } else {
916  $a_text = self::replaceBBTagByMatching(
917  "[" . $found[1] . "]",
918  "[/iln]",
919  "IntLink",
920  $a_text,
921  [
922  "Target" => "il_" . $inst_str . "_" . $found[6] . "_" . $obj_id,
923  "Type" => "RepositoryItem"
924  ]
925  );
926  }
927  } else {
928  $a_text = preg_replace('/\[' . $found[1] . '\]/i', "[error: iln" . $found[1] . "]", $a_text);
929  }
930  }
931  }
932 
933  while (preg_match("~\[(iln$ws((inst$ws=$ws([\"0-9])*)?" . $ws . "media$ws=$ws([\"0-9])*)$ws)/\]~i", $a_text, $found)) {
934  $attribs = self::attribsToArray($found[2]);
935  $inst_str = $attribs["inst"] ?? "";
936  $a_text = self::replaceBBTagByMatching(
937  "[" . $found[1] . "/]",
938  "",
939  "IntLink",
940  $a_text,
941  [
942  "Target" => "il_" . $inst_str . "_mob_" . $attribs['media'],
943  "Type" => "MediaObject"
944  ]
945  );
946  }
947 
948  // user
949  while (preg_match("~\[(iln$ws((inst$ws=$ws([\"0-9])*)?" . $ws . "user$ws=$ws(\"([^\"])*)\")$ws)/\]~i", $a_text, $found)) {
950  $attribs = self::attribsToArray($found[2]);
951  $inst_str = $attribs["inst"] ?? "";
952  $user_id = ilObjUser::_lookupId($attribs['user']);
953  $a_text = self::replaceBBTagByMatching(
954  "[" . $found[1] . "/]",
955  "",
956  "IntLink",
957  $a_text,
958  [
959  "Target" => "il_" . $inst_str . "_user_" . $user_id,
960  "Type" => "User"
961  ]
962  );
963  }
964 
965  return $a_text;
966  }
static _lookupId($a_user_str)
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ isValidTagContent()

static ilPCParagraph::isValidTagContent ( string  $content)
staticprotected

Definition at line 678 of file class.ilPCParagraph.php.

678  : bool
679  {
680  $use_internal_errors = libxml_use_internal_errors(true);
681  $sxe = simplexml_load_string("<?xml version='1.0'?><dummy>" . $content . "</dummy>");
682  libxml_use_internal_errors($use_internal_errors);
683  return ($sxe !== false);
684  }

◆ linkTermsInDom()

static ilPCParagraph::linkTermsInDom ( php4DOMDocument  $a_dom,
array  $a_terms,
php4DOMElement  $a_par_node = null 
)
staticprotected

Link terms in a dom page object in bb style.

Definition at line 1838 of file class.ilPCParagraph.php.

References Vendor\Package\$a, Vendor\Package\$b, ilPageContent\$node, DOMXML_LOAD_PARSING, domxml_open_mem(), ilArrayUtil\sortArray(), ilStr\strIPos(), ilStr\strLen(), ilStr\strPos(), and ilStr\subStr().

1842  : void {
1843  $par_node = null;
1844  // sort terms by their length (shortes first)
1845  // to prevent that nested tags are builded
1846  foreach ($a_terms as $k => $t) {
1847  $a_terms[$k]["termlength"] = strlen($t["term"]);
1848  }
1849  $a_terms = ilArrayUtil::sortArray($a_terms, "termlength", "asc", true);
1850 
1851 
1852  if ($a_dom instanceof php4DOMDocument) {
1853  $a_dom = $a_dom->myDOMDocument;
1854  }
1855  if ($a_par_node instanceof php4DOMElement) {
1856  $par_node = $a_par_node->myDOMNode;
1857  }
1858 
1859  $xpath = new DOMXPath($a_dom);
1860 
1861  if ($par_node == null) {
1862  $parnodes = $xpath->query("//Paragraph[@Characteristic != 'Code']");
1863  } else {
1864  $parnodes = $xpath->query(".//Paragraph[@Characteristic != 'Code']", $par_node->parentNode);
1865  }
1866 
1867  $strrPos = function (string $a_haystack, string $a_needle, ?int $a_offset = null): int {
1868  if (function_exists("mb_strpos")) {
1869  return mb_strrpos($a_haystack, $a_needle, $a_offset, "UTF-8");
1870  } else {
1871  return strrpos($a_haystack, $a_needle, $a_offset);
1872  }
1873  };
1874 
1875  foreach ($parnodes as $parnode) {
1876  $textnodes = $xpath->query('.//text()', $parnode);
1877  foreach ($textnodes as $node) {
1878  $p = $node->getNodePath();
1879 
1880  // we do not change text nodes inside of links
1881  if (!is_int(strpos($p, "/IntLink")) &&
1882  !is_int(strpos($p, "/ExtLink"))) {
1883  $node_val = $node->nodeValue;
1884 
1885  // all terms
1886  foreach ($a_terms as $t) {
1887  $pos = ilStr::strIPos($node_val, $t["term"]);
1888 
1889  // if term found
1890  while (is_int($pos)) {
1891  // check if we are in a tex tag, see #22261
1892  $tex_bpos = $strrPos(ilStr::subStr($node_val, 0, $pos), "[tex]");
1893  $tex_epos = ilStr::strPos($node_val, "[/tex]", $tex_bpos);
1894  if ($tex_bpos > 0 && $tex_epos > 0 && $tex_bpos < $pos && $tex_epos > $pos) {
1895  $pos += ilStr::strLen($t["term"]);
1896  } else {
1897 
1898  // check if the string is not included in another word
1899  // note that []
1900  $valid_limiters = array("", " ", "&nbsp;", ".", ",", ":", ";", "!", "?", "\"", "'", "(", ")");
1901  $b = ($pos > 0)
1902  ? ilStr::subStr($node_val, $pos - 1, 1)
1903  : "";
1904  $a = ilStr::subStr($node_val, $pos + ilStr::strLen($t["term"]), 1);
1905  if ((in_array($b, $valid_limiters) || htmlentities($b, null, 'utf-8') == "&nbsp;") && in_array($a, $valid_limiters)) {
1906  $mid = '[iln term="' . $t["id"] . '"]' .
1907  ilStr::subStr($node_val, $pos, ilStr::strLen($t["term"])) .
1908  "[/iln]";
1909 
1910  $node_val = ilStr::subStr($node_val, 0, $pos) .
1911  $mid .
1912  ilStr::subStr($node_val, $pos + ilStr::strLen($t["term"]));
1913 
1914  $pos += ilStr::strLen($mid);
1915  } else {
1916  $pos += ilStr::strLen($t["term"]);
1917  }
1918  }
1919  $pos = ilStr::strIPos($node_val, $t["term"], $pos);
1920  }
1921 
1922  // insert [iln] tags
1923  }
1924 
1925  $node->nodeValue = $node_val;
1926  }
1927 
1928  // var_dump($p);
1929 // var_dump($node->nodeValue);
1930  }
1931 
1932 
1933  // dump paragraph node
1934  $text = $a_dom->saveXML($parnode);
1935  $text = substr($text, 0, strlen($text) - strlen("</Paragraph>"));
1936  $text = substr($text, strpos($text, ">") + 1);
1937 
1938  // replace [iln] by tags with xml representation
1939  $text = self::intLinks2xml($text);
1940 
1941  // "set text"
1942  $temp_dom = domxml_open_mem(
1943  '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text . '</Paragraph>',
1945  $error
1946  );
1947  $temp_dom = $temp_dom->myDOMDocument;
1948 
1949  if (empty($error)) {
1950  // delete children of paragraph node
1951  $children = $parnode->childNodes;
1952  while ($parnode->hasChildNodes()) {
1953  $parnode->removeChild($parnode->firstChild);
1954  }
1955 
1956  // copy new content children in paragraph node
1957  $xpath_temp = new DOMXPath($temp_dom);
1958  $temp_pars = $xpath_temp->query("//Paragraph");
1959 
1960  foreach ($temp_pars as $new_par_node) {
1961  $new_childs = $new_par_node->childNodes;
1962 
1963  foreach ($new_childs as $new_child) {
1964  //$cloned_child = $new_child->cloneNode(true);
1965  $cloned_child = $a_dom->importNode($new_child, true);
1966  $parnode->appendChild($cloned_child);
1967  }
1968  }
1969  }
1970  }
1971  // exit;
1972  }
php4DOMElement $node
static strPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
Definition: class.ilStr.php:42
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
static strLen(string $a_string)
Definition: class.ilStr.php:63
php4DomElement
domxml_open_mem($str, $mode=0, &$error=null)
php4DOMElement $par_node
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static strIPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
Definition: class.ilStr.php:54
const DOMXML_LOAD_PARSING
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
+ Here is the call graph for this function:

◆ removeTrailingBr()

ilPCParagraph::removeTrailingBr ( string  $a_str)

Remove trailing

Definition at line 1466 of file class.ilPCParagraph.php.

Referenced by autoSplit().

1466  : string
1467  {
1468  if (substr($a_str, strlen($a_str) - 6) == "<br />") {
1469  $a_str = substr($a_str, 0, strlen($a_str) - 6);
1470  }
1471  return $a_str;
1472  }
+ Here is the caller graph for this function:

◆ replaceBBCode()

static ilPCParagraph::replaceBBCode ( string  $a_text,
string  $a_bb,
string  $a_tag 
)
staticprotected

Definition at line 519 of file class.ilPCParagraph.php.

523  : string {
524  $a_text = preg_replace('/\[' . $a_bb . '\]/i', "<" . $a_tag . ">", $a_text);
525  $a_text = preg_replace('/\[\/' . $a_bb . '\]/i', "</" . $a_tag . ">", $a_text);
526  return $a_text;
527  }

◆ replaceBBTagByMatching()

static ilPCParagraph::replaceBBTagByMatching ( string  $start_tag,
string  $end_tag,
string  $xml_tag_name,
string  $text,
array  $attribs 
)
staticprotected

Transforms [iln...]...[] to <IntLink...>...</IntLink>, if content is valid, otherwise it removes the bb tags.

Parameters
string$start_tage.g. [iln page="30"]

Definition at line 691 of file class.ilPCParagraph.php.

References ILIAS\LTI\ToolProvider\$key.

697  : string {
698  $attrib_str = "";
699  foreach ($attribs as $key => $value) {
700  if ($value != "") {
701  $attrib_str .= ' ' . $key . '="' . $value . '"';
702  }
703  }
704 
705  $ok = false;
706 
707  $pos1 = strpos($text, $start_tag);
708 
709  $pos2 = null;
710  if ($end_tag != "") {
711  $pos2 = strpos($text, $end_tag, $pos1 + strlen($start_tag));
712  if (is_int($pos1) && is_int($pos2)) {
713  $between = substr($text, $pos1 + strlen($start_tag), $pos2 - ($pos1 + strlen($start_tag)));
714  $ok = self::isValidTagContent($between);
715  }
716  } else { // no end tag
717  if (is_int($pos1)) {
718  $ok = true;
719  }
720  }
721  $short = ($end_tag == "")
722  ? "/"
723  : "";
724 
725  $slash_chars = '/[]?()$*';
726 
727  if ($ok) {
728  $replace_str = addcslashes($start_tag, $slash_chars);
729  $replace_str = str_replace("+", "\\+", $replace_str);
730  // replace start tag
731  $text = preg_replace(
732  '/' . $replace_str . '/i',
733  "<" . $xml_tag_name . $attrib_str . $short . ">",
734  $text,
735  1
736  );
737 
738  // replace end tag
739  if ($end_tag != "") {
740  $text = preg_replace('~' . addcslashes($end_tag, $slash_chars) . '~i', "</" . $xml_tag_name . ">", $text, 1);
741  }
742  } else {
743  // remove start tag
744  if (is_int($pos1)) {
745  $text = preg_replace(
746  '/' . addcslashes($start_tag, $slash_chars) . '/i',
747  "",
748  $text,
749  1
750  );
751  }
752  // remove end tag
753  if (is_int($pos2)) {
754  $text = preg_replace(
755  '~' . addcslashes($end_tag, $slash_chars) . '~i',
756  "",
757  $text,
758  1
759  );
760  }
761  }
762  return $text;
763  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ saveAnchors()

static ilPCParagraph::saveAnchors ( ilPageObject  $a_page,
DOMDocument  $a_domdoc 
)
static

Save anchors.

Definition at line 2029 of file class.ilPCParagraph.php.

References $name, ilPageContent\$node, ilPageObject\getId(), ilPageObject\getLanguage(), and ilPageObject\getParentType().

2032  : void {
2033  self::_deleteAnchors($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage());
2034 
2035  // get all anchors
2036  $xpath = new DOMXPath($a_domdoc);
2037  $nodes = $xpath->query('//Anchor');
2038  $saved = array();
2039  foreach ($nodes as $node) {
2040  $name = $node->getAttribute("Name");
2041  if (trim($name) != "" && !in_array($name, $saved)) {
2042  self::_saveAnchor($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage(), $name);
2043  $saved[] = $name;
2044  }
2045  }
2046  }
php4DOMElement $node
if($format !==null) $name
Definition: metadata.php:247
+ Here is the call graph for this function:

◆ saveJS()

ilPCParagraph::saveJS ( ilPageObject  $a_pg_obj,
string  $a_content,
string  $a_char,
string  $a_pc_id,
string  $a_insert_at = "",
bool  $from_placeholder = false 
)

Save input coming from ajax.

Returns
bool|string
Exceptions
ilCOPagePCEditException
ilCOPageUnknownPCTypeException

Definition at line 1494 of file class.ilPCParagraph.php.

References $ilUser, ILIAS\LTI\ToolProvider\$updated, $user, exit, ilPageObject\getContentObject(), ilPageContent\getPage(), handleAjaxContentPost(), and ILIAS\Repository\lng().

1501  {
1502  $ilUser = $this->user;
1503 
1504  $a_content = str_replace("<br>", "<br />", $a_content);
1505 
1506  $this->log->debug("step 1: " . substr($a_content, 0, 1000));
1507  try {
1508  $t = self::handleAjaxContent($a_content);
1509  } catch (Exception $ex) {
1510  return $ex->getMessage() . ": " . htmlentities($a_content);
1511  }
1512  $this->log->debug("step 2: " . substr($t["text"], 0, 1000));
1513  if ($t === false) {
1514  return false;
1515  }
1516  $pc_id = explode(":", $a_pc_id);
1517  $insert_at = explode(":", $a_insert_at);
1518  $t_id = explode(":", $t["id"]);
1519 
1520  // insert new paragraph
1521  if ($a_insert_at != "") {
1522  $par = new ilPCParagraph($this->getPage());
1523  $par->create($a_pg_obj, $insert_at[0], $insert_at[1], $from_placeholder);
1524  $par->writePCId($pc_id[1]);
1525  } else {
1526  $par = $a_pg_obj->getContentObject($pc_id[0], $pc_id[1]);
1527 
1528  if (!$par) {
1529  return $this->lng->txt("copg_page_element_not_found") . " (saveJS): " . $pc_id[0] . ":" . $pc_id[1] . ".";
1530  }
1531  }
1532  /*
1533  if ($a_insert_at != "") {
1534  $pc_id = $a_pg_obj->generatePCId();
1535  $par->writePCId($pc_id);
1536  $this->inserted_pc_id = $pc_id;
1537  } else {
1538  $this->inserted_pc_id = $pc_id[1];
1539  }*/
1540 
1541  $par->setLanguage($ilUser->getLanguage());
1542  $par->setCharacteristic($t["class"]);
1543 
1544  $t2 = $par->input2xml($t["text"], true, false);
1545  $this->log->debug("step 3: " . substr($t2, 0, 1000));
1546 
1548  $this->log->debug("step 4: " . substr($t2, 0, 1000));
1549 
1550  $updated = $par->setText($t2, true);
1551 
1552  if ($updated !== true) {
1553  echo $updated;
1554  exit;
1555  }
1556  $updated = $par->updatePage($a_pg_obj);
1557  return $updated;
1558  }
exit
Definition: login.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static handleAjaxContentPost(string $text)
Post input2xml handling of ajax content.
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
getContentObject(string $a_hier_id, string $a_pc_id="")
Get a content object of the page.
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:

◆ saveMetaKeywords()

static ilPCParagraph::saveMetaKeywords ( ilPageObject  $a_page,
DOMDocument  $a_domdoc 
)
static

save all keywords

Definition at line 2122 of file class.ilPCParagraph.php.

References $id, $lang, ilPageContent\$node, ilPageObject\getId(), ilPageObject\getParentId(), ilPageObject\getParentType(), and ilUtil\stripSlashes().

2125  : void {
2126  // not nice, should be set by context per method
2127  if ($a_page->getParentType() == "gdf" ||
2128  $a_page->getParentType() == "lm") {
2129  // get existing keywords
2130  $keywords = array();
2131 
2132  // find all Keyw tags
2133  $xpath = new DOMXPath($a_domdoc);
2134  $nodes = $xpath->query('//Keyw');
2135  foreach ($nodes as $node) {
2136  $k = trim(strip_tags($node->nodeValue));
2137  if (!in_array($k, $keywords)) {
2138  $keywords[] = $k;
2139  }
2140  }
2141 
2142  $meta_type = ($a_page->getParentType() == "gdf")
2143  ? "gdf"
2144  : "pg";
2145  $meta_rep_id = $a_page->getParentId();
2146  $meta_id = $a_page->getId();
2147 
2148  $md_obj = new ilMD($meta_rep_id, $meta_id, $meta_type);
2149  $mkeywords = array();
2150  $lang = "";
2151  if (is_object($md_section = $md_obj->getGeneral())) {
2152  foreach ($ids = $md_section->getKeywordIds() as $id) {
2153  $md_key = $md_section->getKeyword($id);
2154  $mkeywords[] = strtolower($md_key->getKeyword());
2155  if ($lang == "") {
2156  $lang = $md_key->getKeywordLanguageCode();
2157  }
2158  }
2159  if ($lang == "") {
2160  foreach ($ids = $md_section->getLanguageIds() as $id) {
2161  $md_lang = $md_section->getLanguage($id);
2162  if ($lang == "") {
2163  $lang = $md_lang->getLanguageCode();
2164  }
2165  }
2166  }
2167  foreach ($keywords as $k) {
2168  if (!in_array(strtolower($k), $mkeywords)) {
2169  if (trim($k) != "" && $lang != "") {
2170  $md_key = $md_section->addKeyword();
2171  $md_key->setKeyword(ilUtil::stripSlashes($k));
2172  $md_key->setKeywordLanguage(new ilMDLanguageItem($lang));
2173  $md_key->save();
2174  }
2175  $mkeywords[] = strtolower($k);
2176  }
2177  }
2178  }
2179  }
2180  }
php4DOMElement $node
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$lang
Definition: xapiexit.php:26
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ segmentString()

static ilPCParagraph::segmentString ( string  $a_haystack,
array  $a_needles 
)
static

Segments a string into an array at each position of a substring.

Definition at line 1115 of file class.ilPCParagraph.php.

Referenced by xml2outputReplaceLists().

1118  : array {
1119  $segments = array();
1120  $found_needle = "";
1121 
1122  $nothing_found = false;
1123  while (!$nothing_found) {
1124  $nothing_found = true;
1125  $found = -1;
1126  foreach ($a_needles as $needle) {
1127  $pos = stripos($a_haystack, $needle);
1128  if (is_int($pos) && ($pos < $found || $found == -1)) {
1129  $found = $pos;
1130  $found_needle = $needle;
1131  $nothing_found = false;
1132  }
1133  }
1134  if ($found > 0) {
1135  $segments[] = substr($a_haystack, 0, $found);
1136  $a_haystack = substr($a_haystack, $found);
1137  }
1138  if ($found > -1) {
1139  $segments[] = substr($a_haystack, 0, strlen($found_needle));
1140  $a_haystack = substr($a_haystack, strlen($found_needle));
1141  }
1142  }
1143  if ($a_haystack != "") {
1144  $segments[] = $a_haystack;
1145  }
1146 
1147  return $segments;
1148  }
+ Here is the caller graph for this function:

◆ setAutoIndent()

ilPCParagraph::setAutoIndent ( string  $a_char)

Definition at line 455 of file class.ilPCParagraph.php.

455  : void
456  {
457  if (!empty($a_char)) {
458  $this->par_node->set_attribute("AutoIndent", $a_char);
459  } else {
460  if ($this->par_node->has_attribute("AutoIndent")) {
461  $this->par_node->remove_attribute("AutoIndent");
462  }
463  }
464  }

◆ setCharacteristic()

ilPCParagraph::setCharacteristic ( string  $a_char)

Set Characteristic of paragraph.

Definition at line 420 of file class.ilPCParagraph.php.

420  : void
421  {
422  if (!empty($a_char)) {
423  $this->par_node->set_attribute("Characteristic", $a_char);
424  } else {
425  if ($this->par_node->has_attribute("Characteristic")) {
426  $this->par_node->remove_attribute("Characteristic");
427  }
428  }
429  }

◆ setDownloadTitle()

ilPCParagraph::setDownloadTitle ( string  $a_char)

Definition at line 471 of file class.ilPCParagraph.php.

471  : void
472  {
473  if (!empty($a_char)) {
474  $this->par_node->set_attribute("DownloadTitle", $a_char);
475  } else {
476  if ($this->par_node->has_attribute("DownloadTitle")) {
477  $this->par_node->remove_attribute("DownloadTitle");
478  }
479  }
480  }

◆ setLanguage()

ilPCParagraph::setLanguage ( string  $a_lang)

Definition at line 501 of file class.ilPCParagraph.php.

501  : void
502  {
503  $this->par_node->set_attribute("Language", $a_lang);
504  }

◆ setNode()

ilPCParagraph::setNode ( php4DOMElement  $a_node)

Definition at line 101 of file class.ilPCParagraph.php.

References $i, and php4DOMNode\child_nodes().

101  : void
102  {
103  parent::setNode($a_node); // this is the PageContent node
104 
105  $childs = $a_node->child_nodes();
106  for ($i = 0, $iMax = count($childs); $i < $iMax; $i++) {
107  if ($childs[$i]->node_name() == "Paragraph") {
108  $this->par_node = $childs[$i]; //... and this the Paragraph node
109  }
110  }
111  }
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ setShowLineNumbers()

ilPCParagraph::setShowLineNumbers ( string  $a_char)

Definition at line 487 of file class.ilPCParagraph.php.

487  : void
488  {
489  $a_char = empty($a_char)
490  ? "n"
491  : $a_char;
492 
493  $this->par_node->set_attribute("ShowLineNumbers", $a_char);
494  }

◆ setSubCharacteristic()

ilPCParagraph::setSubCharacteristic ( string  $a_char)

Definition at line 439 of file class.ilPCParagraph.php.

439  : void
440  {
441  if (!empty($a_char)) {
442  $this->par_node->set_attribute("SubCharacteristic", $a_char);
443  } else {
444  if ($this->par_node->has_attribute("SubCharacteristic")) {
445  $this->par_node->remove_attribute("SubCharacteristic");
446  }
447  }
448  }

◆ setText()

ilPCParagraph::setText ( string  $a_text,
bool  $a_auto_split = false 
)

Set (xml) content of text paragraph.

Parameters
string$a_texttext content
bool$a_auto_splitauto split paragraph at headlines true/false
Returns
bool|string

Definition at line 189 of file class.ilPCParagraph.php.

References $check, Vendor\Package\$e, $i, ilPageContent\$node, $path, $res, autoSplit(), checkTextArray(), DOMXML_LOAD_PARSING, domxml_open_mem(), getCharacteristic(), getLanguage(), ilPageContent\getPage(), xpath_eval(), and xpath_new_context().

192  {
193  $text = $a_text;
194  if ($a_auto_split) {
195  $text = $this->autoSplit($a_text);
196  } else {
197  $text = [["level" => 0, "text" => $text]];
198  }
199  $error = $this->checkTextArray($text);
200 
201  $orig_characteristic = "";
202 
203  // remove all childs
204  if (empty($error)) {
205  $t = $text[0]["text"] ?? "";
206  $temp_dom = domxml_open_mem(
207  '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $t . '</Paragraph>',
209  $error
210  );
211 
212  // delete children of paragraph node
213  $children = $this->par_node->child_nodes();
214  for ($i = 0, $iMax = count($children); $i < $iMax; $i++) {
215  $this->par_node->remove_child($children[$i]);
216  }
217 
218  // copy new content children in paragraph node
219  $xpc = xpath_new_context($temp_dom);
220  $path = "//Paragraph";
221  $res = xpath_eval($xpc, $path);
222  if (count($res->nodeset) == 1) {
223  $new_par_node = $res->nodeset[0];
224  $new_childs = $new_par_node->child_nodes();
225 
226  for ($i = 0, $iMax = count($new_childs); $i < $iMax; $i++) {
227  $cloned_child = $new_childs[$i]->clone_node(true);
228  $this->par_node->append_child($cloned_child);
229  }
230  $orig_characteristic = $this->getCharacteristic();
231 
232  // if headlines are entered and current characteristic is a headline
233  // use no characteristic as standard
234  if ((count($text) > 1) && (substr($orig_characteristic, 0, 8) == "Headline")) {
235  $orig_characteristic = "";
236  }
237  if (isset($text[0]["level"]) && $text[0]["level"] > 0) {
238  $this->par_node->set_attribute("Characteristic", 'Headline' . $text[0]["level"]);
239  }
240  }
241 
242  $ok = true;
243 
244  $c_node = $this->node;
245  // add other chunks afterwards
246  for ($i = 1, $iMax = count($text); $i < $iMax; $i++) {
247  if ($ok) {
248  $next_par = new ilPCParagraph($this->getPage());
249  $next_par->createAfter($c_node);
250  $next_par->setLanguage($this->getLanguage());
251  if ($text[$i]["level"] > 0) {
252  $next_par->setCharacteristic("Headline" . $text[$i]["level"]);
253  } else {
254  $next_par->setCharacteristic($orig_characteristic);
255  }
256  $ok = $next_par->setText($text[$i]["text"], false);
257  $c_node = $next_par->node;
258  }
259  }
260 
261  return true;
262  } else {
263  // We want the correct number of \n here to have the real lines numbers
264  $check = array_reduce($text, function ($t, $i) {
265  return $t . $i["text"];
266  });
267  $text = str_replace("<br>", "\n", $check); // replace <br> with \n to get correct line
268  $text = str_replace("<br/>", "\n", $text);
269  $text = str_replace("<br />", "\n", $text);
270  $text = str_replace("</SimpleListItem>", "</SimpleListItem>\n", $text);
271  $text = str_replace("<SimpleBulletList>", "\n<SimpleBulletList>", $text);
272  $text = str_replace("<SimpleNumberedList>", "\n<SimpleNumberedList>", $text);
273  $text = str_replace("<Paragraph>\n", "<Paragraph>", $text);
274  $text = str_replace("</Paragraph>", "</Paragraph>\n", $text);
275  $doc = new ilDomDocument();
276  $text = '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text . '</Paragraph>';
277  //echo htmlentities($text);
278  $doc->loadXML($text);
279  $error = $doc->getErrors();
280  $estr = "";
281  foreach ($error as $e) {
282  $e = str_replace(" in Entity", "", $e);
283  $estr .= $e . "<br />";
284  }
285  if (DEVMODE) {
286  $estr .= "<br />" . $text;
287  }
288 
289  return $estr;
290  }
291  }
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
php4DOMElement $node
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkTextArray(array $text)
Check text array.
$path
Definition: ltiservices.php:32
xpath_new_context($dom_document)
domxml_open_mem($str, $mode=0, &$error=null)
autoSplit(string $a_text)
This function splits a paragraph text that has been already processed with input2xml at each header p...
$check
Definition: buildRTE.php:81
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const DOMXML_LOAD_PARSING
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ updatePage()

ilPCParagraph::updatePage ( ilPageObject  $a_page)

Update page object (it would be better to have this centralized and to change the constructors and pass the page object instead the dom object)

Returns
array|bool
Exceptions
ilDateTimeException

Definition at line 1798 of file class.ilPCParagraph.php.

References ilPageObject\beforePageContentUpdate(), and ilPageObject\update().

1799  {
1800  $a_page->beforePageContentUpdate($this);
1801  return $a_page->update();
1802  }
update(bool $a_validate=true, bool $a_no_history=false)
update complete page content in db (dom xml content is used)
beforePageContentUpdate(ilPageContent $a_page_content)
Before page content update Note: This one is "work in progress", currently only text paragraphs call ...
+ Here is the call graph for this function:

◆ xml2output()

static ilPCParagraph::xml2output ( string  $a_text,
bool  $a_wysiwyg = false,
bool  $a_replace_lists = true,
bool  $unmask = true 
)
static

Converts xml from DB to output in edit textarea.

Parameters
string$a_textxml from db
Returns
string string ready for edit textarea

Definition at line 1155 of file class.ilPCParagraph.php.

References $target_id, $target_type, ilObjUser\_lookupLogin(), ilObject\_lookupType(), and xml2outputReplaceLists().

Referenced by ilPresentationListTableGUI\fillRow(), ilTermListTableGUI\fillRow(), ilPCDataTableGUI\getCellContent(), ilPCTable\getModel(), getModel(), and ilPageObject\getPageContentsHashes().

1160  : string {
1161  // note: the order of the processing steps is crucial
1162  // and should be the same as in input2xml() in REVERSE order!
1163 
1164  // xml to bb code
1165  $any = "[^>]*";
1166  $tframestr = "";
1167 
1168  foreach (self::getBBMap() as $bb => $tag) {
1169  $a_text = preg_replace('~<' . $tag . '[^>]*>~i', "[" . $bb . "]", $a_text);
1170  $a_text = preg_replace('~</' . $tag . '>~i', "[/" . $bb . "]", $a_text);
1171  $a_text = preg_replace('~<' . $tag . '/>~i', "[" . $bb . "][/" . $bb . "]", $a_text);
1172  }
1173 
1174  // replace lists
1175  if ($a_replace_lists) {
1176  //echo "<br>".htmlentities($a_text);
1177  $a_text = ilPCParagraph::xml2outputReplaceLists($a_text);
1178  //echo "<br>".htmlentities($a_text);
1179  }
1180 
1181  // internal links
1182  while (preg_match('~<IntLink(' . $any . ')>~i', $a_text, $found)) {
1183  $attribs = self::attribsToArray($found[1]);
1184  $target = explode("_", $attribs["Target"]);
1185  $target_id = $target[count($target) - 1];
1186  $inst_str = (!is_int(strpos($attribs["Target"], "__")))
1187  ? $inst_str = "inst=\"" . ($target[1] ?? '') . "\" "
1188  : $inst_str = "";
1189  switch ($attribs["Type"]) {
1190  case "PageObject":
1191  $tframestr = (!empty($attribs["TargetFrame"]))
1192  ? " target=\"" . $attribs["TargetFrame"] . "\""
1193  : "";
1194  $ancstr = (!empty($attribs["Anchor"]))
1195  ? ' anchor="' . $attribs["Anchor"] . '"'
1196  : "";
1197  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "page=\"" . $target_id . "\"$tframestr$ancstr]", $a_text);
1198  break;
1199 
1200  case "StructureObject":
1201  $tframestr = (!empty($attribs["TargetFrame"]))
1202  ? " target=\"" . $attribs["TargetFrame"] . "\""
1203  : "";
1204  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "chap=\"" . $target_id . "\"$tframestr]", $a_text);
1205  break;
1206 
1207  case "GlossaryItem":
1208  $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
1209  ? ""
1210  : " target=\"" . $attribs["TargetFrame"] . "\"";
1211  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "term=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1212  break;
1213 
1214  case "WikiPage":
1215  $tframestr = "";
1216  $ancstr = (!empty($attribs["Anchor"]))
1217  ? ' anchor="' . $attribs["Anchor"] . '"'
1218  : "";
1219  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "wpage=\"" . $target_id . "\"" . $tframestr . $ancstr . "]", $a_text);
1220  break;
1221 
1222  case "PortfolioPage":
1223  $tframestr = "";
1224  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "ppage=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1225  break;
1226 
1227  case "MediaObject":
1228  if (empty($attribs["TargetFrame"])) {
1229  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "media=\"" . $target_id . "\"/]", $a_text);
1230  } else {
1231  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln media=\"" . $target_id . "\"" .
1232  " target=\"" . ($attribs["TargetFrame"] ?? "") . "\"]", $a_text);
1233  }
1234  break;
1235 
1236  // Repository Item (using ref id)
1237  case "RepositoryItem":
1238  if ($inst_str == "") {
1240  } else {
1241  $rtype = ($target[count($target) - 2] ?? "");
1242  $target_type = $rtype;
1243  }
1244  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "$target_type=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1245  break;
1246 
1247  // Download File (not in repository, Object ID)
1248  case "File":
1249  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "dfile=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1250  break;
1251 
1252  // User
1253  case "User":
1254  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "user=\"" . ilObjUser::_lookupLogin((int) $target_id) . "\"/]", $a_text);
1255  break;
1256 
1257  default:
1258  $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln]", $a_text);
1259  break;
1260  }
1261  }
1262  $a_text = str_replace("</IntLink>", "[/iln]", $a_text);
1263 
1264  // external links
1265  while (preg_match('~<ExtLink(' . $any . ')>~i', $a_text, $found)) {
1266  $attribs = self::attribsToArray($found[1]);
1267  //$found[1] = str_replace("?", "\?", $found[1]);
1268  $tstr = "";
1269  if (in_array(($attribs["TargetFrame"] ?? ""), array("FAQ", "Glossary", "Media"))) {
1270  $tstr = ' target="' . ($attribs["TargetFrame"] ?? "") . '"';
1271  }
1272  $a_text = str_replace("<ExtLink" . $found[1] . ">", "[xln url=\"" . ($attribs["Href"] ?? "") . "\"$tstr]", $a_text);
1273  }
1274  $a_text = str_replace("</ExtLink>", "[/xln]", $a_text);
1275 
1276  // anchor
1277  while (preg_match('~<Anchor(' . $any . '/)>~i', $a_text, $found)) {
1278  $attribs = self::attribsToArray($found[1]);
1279  $a_text = str_replace("<Anchor" . $found[1] . ">", "[anc name=\"" . ($attribs["Name"] ?? "") . "\"][/anc]", $a_text);
1280  }
1281  while (preg_match('~<Anchor(' . $any . ')>~i', $a_text, $found)) {
1282  $attribs = self::attribsToArray($found[1]);
1283  $a_text = str_replace("<Anchor" . $found[1] . ">", "[anc name=\"" . ($attribs["Name"] ?? "") . "\"]", $a_text);
1284  }
1285  $a_text = str_replace("</Anchor>", "[/anc]", $a_text);
1286 
1287  // marked text
1288  while (preg_match('~<Marked(' . $any . ')>~i', $a_text, $found)) {
1289  $attribs = self::attribsToArray($found[1]);
1290  $a_text = str_replace("<Marked" . $found[1] . ">", "[marked class=\"" . ($attribs["Class"] ?? "") . "\"]", $a_text);
1291  }
1292  $a_text = str_replace("</Marked>", "[/marked]", $a_text);
1293 
1294  // br to linefeed
1295  if (!$a_wysiwyg) {
1296  $a_text = str_replace("<br />", "\n", $a_text);
1297  $a_text = str_replace("<br/>", "\n", $a_text);
1298  }
1299 
1300  if (!$a_wysiwyg) {
1301  // prevent curly brackets from being swallowed up by template engine
1302  $a_text = str_replace("{", "&#123;", $a_text);
1303  $a_text = str_replace("}", "&#125;", $a_text);
1304 
1305  // unmask html
1306  if ($unmask) {
1307  $a_text = str_replace("&lt;", "<", $a_text);
1308  $a_text = str_replace("&gt;", ">", $a_text);
1309  }
1310 
1311  // this is needed to allow html like <tag attribute="value">... in paragraphs
1312  $a_text = str_replace("&quot;", "\"", $a_text);
1313 
1314  // make ampersands in (enabled) html attributes work
1315  // e.g. <a href="foo.php?n=4&t=5">hhh</a>
1316  $a_text = str_replace("&amp;", "&", $a_text);
1317 
1318  // make &gt; and $lt; work to allow (disabled) html descriptions
1319  if ($unmask) {
1320  $a_text = str_replace("&lt;", "&amp;lt;", $a_text);
1321  $a_text = str_replace("&gt;", "&amp;gt;", $a_text);
1322  }
1323  }
1324  return $a_text;
1325  }
$target_type
Definition: goto.php:51
static xml2outputReplaceLists(string $a_text)
Replaces with *.
$target_id
Definition: goto.php:52
static _lookupType(int $id, bool $reference=false)
static _lookupLogin(int $a_user_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xml2outputReplaceLists()

static ilPCParagraph::xml2outputReplaceLists ( string  $a_text)
static

Replaces

with *.

Parameters
string$a_textxml from db
Returns
string string containing * for lists

Definition at line 1040 of file class.ilPCParagraph.php.

References $i, and segmentString().

Referenced by xml2output().

1042  : string {
1043  $list_start = false;
1044  $li = false;
1045 
1046  $segments = ilPCParagraph::segmentString($a_text, array("<SimpleBulletList>", "</SimpleBulletList>",
1047  "</SimpleListItem>", "<SimpleListItem>", "<SimpleListItem/>", "<SimpleNumberedList>", "</SimpleNumberedList>"));
1048 
1049  $current_list = array();
1050  $text = "";
1051  for ($i = 0, $iMax = count($segments); $i < $iMax; $i++) {
1052  if ($segments[$i] == "<SimpleBulletList>") {
1053  if (count($current_list) == 0) {
1054  $list_start = true;
1055  }
1056  $current_list[] = "*";
1057  $li = false;
1058  } elseif ($segments[$i] == "<SimpleNumberedList>") {
1059  if (count($current_list) == 0) {
1060  $list_start = true;
1061  }
1062  $current_list[] = "#";
1063  $li = false;
1064  } elseif ($segments[$i] == "</SimpleBulletList>") {
1065  array_pop($current_list);
1066  $li = false;
1067  } elseif ($segments[$i] == "</SimpleNumberedList>") {
1068  array_pop($current_list);
1069  $li = false;
1070  } elseif ($segments[$i] == "<SimpleListItem>") {
1071  $li = true;
1072  } elseif ($segments[$i] == "</SimpleListItem>") {
1073  $li = false;
1074  } elseif ($segments[$i] == "<SimpleListItem/>") {
1075  if ($list_start) {
1076  $text .= "<br />";
1077  $list_start = false;
1078  }
1079  foreach ($current_list as $list) {
1080  $text .= $list;
1081  }
1082  $text .= "<br />";
1083  $li = false;
1084  } else {
1085  if ($li) {
1086  if ($list_start) {
1087  $text .= "<br />";
1088  $list_start = false;
1089  }
1090  foreach ($current_list as $list) {
1091  $text .= $list;
1092  }
1093  }
1094  $text .= $segments[$i];
1095  if ($li) {
1096  $text .= "<br />";
1097  }
1098  $li = false;
1099  }
1100  }
1101 
1102  // remove trailing <br />, if text ends with list
1103  if ((($segments[count($segments) - 1] ?? "") === "</SimpleBulletList>" ||
1104  ($segments[count($segments) - 1] ?? "") === "</SimpleNumberedList>") &&
1105  substr($text, strlen($text) - 6) === "<br />") {
1106  $text = substr($text, 0, -6);
1107  }
1108 
1109  return $text;
1110  }
static segmentString(string $a_haystack, array $a_needles)
Segments a string into an array at each position of a substring.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $bb_tags

array ilPCParagraph::$bb_tags
staticprotected
Initial value:
= array(
"com" => "Comment",
"emp" => "Emph",
"str" => "Strong",
"fn" => "Footnote",
"code" => "Code",
"acc" => "Accent",
"imp" => "Important",
"kw" => "Keyw",
"sub" => "Sub",
"sup" => "Sup",
"quot" => "Quotation",
)

Definition at line 34 of file class.ilPCParagraph.php.

◆ $inserted_pc_id

string ilPCParagraph::$inserted_pc_id
protected

Definition at line 28 of file class.ilPCParagraph.php.

Referenced by getLastSavedPCId().

◆ $lng

ilLanguage ilPCParagraph::$lng
protected

Definition at line 32 of file class.ilPCParagraph.php.

◆ $par_node

php4DOMElement ilPCParagraph::$par_node = null

Definition at line 30 of file class.ilPCParagraph.php.

◆ $user

ilObjUser ilPCParagraph::$user
protected

Definition at line 29 of file class.ilPCParagraph.php.

Referenced by insert(), and saveJS().


The documentation for this class was generated from the following file: