Esempio n. 1
0
 /**
  * Convert * and # to lists
  *
  * @param string $a_text text
  * @return string text
  */
 static function convertLists($a_text)
 {
     include_once "./Services/COPage/classes/class.ilPCParagraph.php";
     $a_text = nl2br($a_text);
     $a_text = str_replace(array("\n", "\r"), "", $a_text);
     $a_text = str_replace("<br>", "<br />", $a_text);
     $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
     $a_text = str_replace(array("<SimpleBulletList>", "</SimpleBulletList>", "<SimpleListItem>", "</SimpleListItem>", "<SimpleNumberedList>", "</SimpleNumberedList>"), array("<ul class='ilc_list_u_BulletedList'>", "</ul>", "<li class='ilc_list_item_StandardListItem'>", "</li>", "<ol class='ilc_list_o_NumberedList'>", "</ol>"), $a_text);
     return $a_text;
 }
 /**
  * converts user input to xml
  */
 static function _input2xml($a_text, $a_lang, $a_wysiwyg = 0, $a_handle_lists = true)
 {
     if (!$a_wysiwyg) {
         $a_text = ilUtil::stripSlashes($a_text, false);
     }
     if ($a_wysiwyg) {
         $a_text = str_replace("<br />", chr(10), $a_text);
     }
     // note: the order of the processing steps is crucial
     // and should be the same as in xml2output() in REVERSE order!
     $a_text = trim($a_text);
     //echo "<br>between:".htmlentities($a_text);
     // mask html
     if (!$a_wysiwyg) {
         $a_text = str_replace("&", "&amp;", $a_text);
     }
     $a_text = str_replace("<", "&lt;", $a_text);
     $a_text = str_replace(">", "&gt;", $a_text);
     // Reconvert PageTurn and BibItemIdentifier
     $a_text = preg_replace('/&lt;([\\s\\/]*?PageTurn.*?)&gt;/i', "<\$1>", $a_text);
     $a_text = preg_replace('/&lt;([\\s\\/]*?BibItemIdentifier.*?)&gt;/i', "<\$1>", $a_text);
     //echo "<br>second:".htmlentities($a_text);
     // mask curly brackets
     /*
     echo htmlentities($a_text);
     		$a_text = str_replace("{", "&#123;", $a_text);
     		$a_text = str_replace("}", "&#125;", $a_text);
     echo htmlentities($a_text);*/
     // linefeed to br
     $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
     $a_text = str_replace(chr(13), "<br />", $a_text);
     $a_text = str_replace(chr(10), "<br />", $a_text);
     if ($a_handle_lists) {
         $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
     }
     // remove empty tags
     $atags = array("com", "emp", "str", "fn", "quot", "code", "acc", "imp", "kw");
     foreach ($atags as $at) {
         $a_text = str_replace("[" . $at . "][/" . $at . "]", "", $a_text);
     }
     // bb code to xml
     $a_text = eregi_replace("\\[com\\]", "<Comment Language=\"" . $a_lang . "\">", $a_text);
     $a_text = eregi_replace("\\[\\/com\\]", "</Comment>", $a_text);
     $a_text = eregi_replace("\\[emp\\]", "<Emph>", $a_text);
     $a_text = eregi_replace("\\[\\/emp\\]", "</Emph>", $a_text);
     $a_text = eregi_replace("\\[str\\]", "<Strong>", $a_text);
     $a_text = eregi_replace("\\[\\/str\\]", "</Strong>", $a_text);
     $a_text = eregi_replace("\\[fn\\]", "<Footnote>", $a_text);
     $a_text = eregi_replace("\\[\\/fn\\]", "</Footnote>", $a_text);
     $a_text = eregi_replace("\\[quot\\]", "<Quotation Language=\"" . $a_lang . "\">", $a_text);
     $a_text = eregi_replace("\\[\\/quot\\]", "</Quotation>", $a_text);
     $a_text = eregi_replace("\\[code\\]", "<Code>", $a_text);
     $a_text = eregi_replace("\\[\\/code\\]", "</Code>", $a_text);
     $a_text = eregi_replace("\\[acc\\]", "<Accent>", $a_text);
     $a_text = eregi_replace("\\[\\/acc\\]", "</Accent>", $a_text);
     $a_text = eregi_replace("\\[imp\\]", "<Important>", $a_text);
     $a_text = eregi_replace("\\[\\/imp\\]", "</Important>", $a_text);
     $a_text = eregi_replace("\\[kw\\]", "<Keyw>", $a_text);
     $a_text = eregi_replace("\\[\\/kw\\]", "</Keyw>", $a_text);
     // internal links
     //$any = "[^\]]*";	// this doesn't work :-(
     $ws = "[ \t\r\f\v\n]*";
     $ltypes = "page|chap|term|media|htlm|lm|dbk|glo|frm|exc|tst|svy|webr|chat|cat|crs|grp|file|fold|mep|wiki|sahs|mcst|obj|dfile";
     // empty internal links
     while (eregi("\\[(iln{$ws}((inst{$ws}={$ws}([\"0-9])*)?{$ws}" . "((" . $ltypes . "){$ws}={$ws}([\"0-9])*){$ws}" . "(target{$ws}={$ws}(\"(New|FAQ|Media)\"))?{$ws}(anchor{$ws}={$ws}(\"([^\"])*\"))?{$ws}))\\]\\[\\/iln\\]", $a_text, $found)) {
         $a_text = str_replace($found[0], "", $a_text);
     }
     while (eregi("\\[(iln{$ws}((inst{$ws}={$ws}([\"0-9])*)?{$ws}" . "((" . $ltypes . "){$ws}={$ws}([\"0-9])*){$ws}" . "(target{$ws}={$ws}(\"(New|FAQ|Media)\"))?{$ws}(anchor{$ws}={$ws}(\"([^\"])*\"))?{$ws}))\\]", $a_text, $found)) {
         $attribs = ilUtil::attribsToArray($found[2]);
         $inst_str = $attribs["inst"];
         // pages
         if (isset($attribs["page"])) {
             $tframestr = "";
             if (!empty($found[10])) {
                 $tframestr = " TargetFrame=\"" . $found[10] . "\" ";
             }
             $ancstr = "";
             if ($attribs["anchor"] != "") {
                 $ancstr = ' Anchor="' . $attribs["anchor"] . '" ';
             }
             $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_pg_" . $attribs[page] . "\" Type=\"PageObject\"" . $tframestr . $ancstr . ">", $a_text);
         } else {
             if (isset($attribs["chap"])) {
                 if (!empty($found[10])) {
                     $tframestr = " TargetFrame=\"" . $found[10] . "\" ";
                 } else {
                     $tframestr = "";
                 }
                 $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_st_" . $attribs[chap] . "\" Type=\"StructureObject\"" . $tframestr . ">", $a_text);
             } else {
                 if (isset($attribs["term"])) {
                     switch ($found[10]) {
                         case "New":
                             $tframestr = " TargetFrame=\"New\" ";
                             break;
                         default:
                             $tframestr = " TargetFrame=\"Glossary\" ";
                             break;
                     }
                     $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_git_" . $attribs[term] . "\" Type=\"GlossaryItem\" {$tframestr}>", $a_text);
                 } else {
                     if (isset($attribs["media"])) {
                         if (!empty($found[10])) {
                             $tframestr = " TargetFrame=\"" . $found[10] . "\" ";
                             $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_mob_" . $attribs[media] . "\" Type=\"MediaObject\"" . $tframestr . ">", $a_text);
                         } else {
                             $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_mob_" . $attribs[media] . "\" Type=\"MediaObject\"/>", $a_text);
                         }
                     } else {
                         if (isset($attribs["dfile"])) {
                             $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_dfile_" . $attribs[dfile] . "\" Type=\"File\">", $a_text);
                         } else {
                             if (isset($attribs["lm"]) || isset($attribs["dbk"]) || isset($attribs["glo"]) || isset($attribs["frm"]) || isset($attribs["exc"]) || isset($attribs["tst"]) || isset($attribs["svy"]) || isset($attribs["obj"]) || isset($attribs['webr']) || isset($attribs["htlm"]) || isset($attribs["chat"]) || isset($attribs["grp"]) || isset($attribs["fold"]) || isset($attribs["sahs"]) || isset($attribs["mcst"]) || isset($attribs["mep"]) || isset($attribs["wiki"]) || isset($attribs["cat"]) || isset($attribs["crs"]) || isset($attribs["file"])) {
                                 $obj_id = isset($attribs["lm"]) ? $attribs["lm"] : $obj_id;
                                 $obj_id = isset($attribs["dbk"]) ? $attribs["dbk"] : $obj_id;
                                 $obj_id = isset($attribs["chat"]) ? $attribs["chat"] : $obj_id;
                                 $obj_id = isset($attribs["glo"]) ? $attribs["glo"] : $obj_id;
                                 $obj_id = isset($attribs["frm"]) ? $attribs["frm"] : $obj_id;
                                 $obj_id = isset($attribs["exc"]) ? $attribs["exc"] : $obj_id;
                                 $obj_id = isset($attribs["htlm"]) ? $attribs["htlm"] : $obj_id;
                                 $obj_id = isset($attribs["tst"]) ? $attribs["tst"] : $obj_id;
                                 $obj_id = isset($attribs["svy"]) ? $attribs["svy"] : $obj_id;
                                 $obj_id = isset($attribs["obj"]) ? $attribs["obj"] : $obj_id;
                                 $obj_id = isset($attribs["webr"]) ? $attribs["webr"] : $obj_id;
                                 $obj_id = isset($attribs["fold"]) ? $attribs["fold"] : $obj_id;
                                 $obj_id = isset($attribs["cat"]) ? $attribs["cat"] : $obj_id;
                                 $obj_id = isset($attribs["crs"]) ? $attribs["crs"] : $obj_id;
                                 $obj_id = isset($attribs["grp"]) ? $attribs["grp"] : $obj_id;
                                 $obj_id = isset($attribs["file"]) ? $attribs["file"] : $obj_id;
                                 $obj_id = isset($attribs["sahs"]) ? $attribs["sahs"] : $obj_id;
                                 $obj_id = isset($attribs["mcst"]) ? $attribs["mcst"] : $obj_id;
                                 $obj_id = isset($attribs["mep"]) ? $attribs["mep"] : $obj_id;
                                 $obj_id = isset($attribs["wiki"]) ? $attribs["wiki"] : $obj_id;
                                 //$obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
                                 if ($inst_str == "") {
                                     $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_obj_" . $obj_id . "\" Type=\"RepositoryItem\">", $a_text);
                                 } else {
                                     $a_text = eregi_replace("\\[" . $found[1] . "\\]", "<IntLink Target=\"il_" . $inst_str . "_" . $found[6] . "_" . $obj_id . "\" Type=\"RepositoryItem\">", $a_text);
                                 }
                             } else {
                                 $a_text = eregi_replace("\\[" . $found[1] . "\\]", "[error: iln" . $found[1] . "]", $a_text);
                             }
                         }
                     }
                 }
             }
         }
     }
     while (eregi("\\[(iln{$ws}((inst{$ws}={$ws}([\"0-9])*)?" . $ws . "media{$ws}={$ws}([\"0-9])*){$ws})/\\]", $a_text, $found)) {
         $attribs = ilUtil::attribsToArray($found[2]);
         $inst_str = $attribs["inst"];
         $a_text = eregi_replace("\\[" . $found[1] . "/\\]", "<IntLink Target=\"il_" . $inst_str . "_mob_" . $attribs[media] . "\" Type=\"MediaObject\"/>", $a_text);
     }
     $a_text = eregi_replace("\\[\\/iln\\]", "</IntLink>", $a_text);
     // external link
     $ws = "[ \t\r\f\v\n]*";
     // remove empty external links
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}\"([^\"])*\"){$ws}(target{$ws}={$ws}(\"(Glossary|FAQ|Media)\"))?{$ws})\\]\\[\\/xln\\]", $a_text, $found)) {
         $a_text = str_replace($found[0], "", $a_text);
     }
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}(([^]])*))){$ws}\\]\\[\\/xln\\]", $a_text, $found)) {
         $a_text = str_replace($found[0], "", $a_text);
     }
     // external links
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}\"([^\"])*\"){$ws}(target{$ws}={$ws}(\"(Glossary|FAQ|Media)\"))?{$ws})\\]", $a_text, $found)) {
         $attribs = ilUtil::attribsToArray($found[2]);
         if (isset($attribs["url"])) {
             $a2 = ilUtil::attribsToArray($found[4]);
             $tstr = "";
             if (in_array($a2["target"], array("FAQ", "Glossary", "Media"))) {
                 $tstr = ' TargetFrame="' . $a2["target"] . '"';
             }
             $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $attribs["url"] . "\"{$tstr}>", $a_text);
         } else {
             $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
         }
     }
     // ie/tinymce fix for links without "", see bug #8391
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}(([^]])*))){$ws}\\]", $a_text, $found)) {
         if ($found[3] != "") {
             $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $found[3] . "\">", $a_text);
         } else {
             $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
         }
     }
     $a_text = eregi_replace("\\[\\/xln\\]", "</ExtLink>", $a_text);
     // anchor
     $ws = "[ \t\r\f\v\n]*";
     while (eregi("\\[(anc{$ws}(name{$ws}={$ws}\"([^\"])*\"){$ws})\\]", $a_text, $found)) {
         $attribs = ilUtil::attribsToArray($found[2]);
         $a_text = str_replace("[" . $found[1] . "]", "<Anchor Name=\"" . $attribs["name"] . "\">", $a_text);
     }
     $a_text = eregi_replace("\\[\\/anc\\]", "</Anchor>", $a_text);
     //echo htmlentities($a_text); exit;
     return $a_text;
 }
Esempio n. 3
0
 /**
  * converts user input to xml
  */
 static function _input2xml($a_text, $a_lang, $a_wysiwyg = 0, $a_handle_lists = true)
 {
     if (!$a_wysiwyg) {
         $a_text = ilUtil::stripSlashes($a_text, false);
     }
     if ($a_wysiwyg) {
         $a_text = str_replace("<br />", chr(10), $a_text);
     }
     // note: the order of the processing steps is crucial
     // and should be the same as in xml2output() in REVERSE order!
     $a_text = trim($a_text);
     //echo "<br>between:".htmlentities($a_text);
     // mask html
     if (!$a_wysiwyg) {
         $a_text = str_replace("&", "&amp;", $a_text);
     }
     $a_text = str_replace("<", "&lt;", $a_text);
     $a_text = str_replace(">", "&gt;", $a_text);
     // Reconvert PageTurn and BibItemIdentifier
     $a_text = preg_replace('/&lt;([\\s\\/]*?PageTurn.*?)&gt;/i', "<\$1>", $a_text);
     $a_text = preg_replace('/&lt;([\\s\\/]*?BibItemIdentifier.*?)&gt;/i', "<\$1>", $a_text);
     //echo "<br>second:".htmlentities($a_text);
     // mask curly brackets
     /*
     echo htmlentities($a_text);
     		$a_text = str_replace("{", "&#123;", $a_text);
     		$a_text = str_replace("}", "&#125;", $a_text);
     echo htmlentities($a_text);*/
     // linefeed to br
     $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
     $a_text = str_replace(chr(13), "<br />", $a_text);
     $a_text = str_replace(chr(10), "<br />", $a_text);
     if ($a_handle_lists) {
         $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
     }
     // remove empty tags
     $atags = array("com", "emp", "str", "fn", "quot", "code", "acc", "imp", "kw");
     foreach ($atags as $at) {
         $a_text = str_replace("[" . $at . "][/" . $at . "]", "", $a_text);
     }
     // bb code to xml
     $a_text = eregi_replace("\\[com\\]", "<Comment Language=\"" . $a_lang . "\">", $a_text);
     $a_text = eregi_replace("\\[\\/com\\]", "</Comment>", $a_text);
     $a_text = eregi_replace("\\[emp\\]", "<Emph>", $a_text);
     $a_text = eregi_replace("\\[\\/emp\\]", "</Emph>", $a_text);
     $a_text = eregi_replace("\\[str\\]", "<Strong>", $a_text);
     $a_text = eregi_replace("\\[\\/str\\]", "</Strong>", $a_text);
     $a_text = eregi_replace("\\[fn\\]", "<Footnote>", $a_text);
     $a_text = eregi_replace("\\[\\/fn\\]", "</Footnote>", $a_text);
     $a_text = eregi_replace("\\[quot\\]", "<Quotation Language=\"" . $a_lang . "\">", $a_text);
     $a_text = eregi_replace("\\[\\/quot\\]", "</Quotation>", $a_text);
     $a_text = eregi_replace("\\[code\\]", "<Code>", $a_text);
     $a_text = eregi_replace("\\[\\/code\\]", "</Code>", $a_text);
     $a_text = eregi_replace("\\[acc\\]", "<Accent>", $a_text);
     $a_text = eregi_replace("\\[\\/acc\\]", "</Accent>", $a_text);
     $a_text = eregi_replace("\\[imp\\]", "<Important>", $a_text);
     $a_text = eregi_replace("\\[\\/imp\\]", "</Important>", $a_text);
     $a_text = eregi_replace("\\[kw\\]", "<Keyw>", $a_text);
     $a_text = eregi_replace("\\[\\/kw\\]", "</Keyw>", $a_text);
     $a_text = self::intLinks2xml($a_text);
     // external link
     $ws = "[ \t\r\f\v\n]*";
     // remove empty external links
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}\"([^\"])*\"){$ws}(target{$ws}={$ws}(\"(Glossary|FAQ|Media)\"))?{$ws})\\]\\[\\/xln\\]", $a_text, $found)) {
         $a_text = str_replace($found[0], "", $a_text);
     }
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}(([^]])*))){$ws}\\]\\[\\/xln\\]", $a_text, $found)) {
         $a_text = str_replace($found[0], "", $a_text);
     }
     // external links
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}\"([^\"])*\"){$ws}(target{$ws}={$ws}(\"(Glossary|FAQ|Media)\"))?{$ws})\\]", $a_text, $found)) {
         $attribs = ilUtil::attribsToArray($found[2]);
         if (isset($attribs["url"])) {
             $a2 = ilUtil::attribsToArray($found[4]);
             $tstr = "";
             if (in_array($a2["target"], array("FAQ", "Glossary", "Media"))) {
                 $tstr = ' TargetFrame="' . $a2["target"] . '"';
             }
             $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $attribs["url"] . "\"{$tstr}>", $a_text);
         } else {
             $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
         }
     }
     // ie/tinymce fix for links without "", see bug #8391
     while (eregi("\\[(xln{$ws}(url{$ws}={$ws}(([^]])*))){$ws}\\]", $a_text, $found)) {
         if ($found[3] != "") {
             $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $found[3] . "\">", $a_text);
         } else {
             $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
         }
     }
     $a_text = eregi_replace("\\[\\/xln\\]", "</ExtLink>", $a_text);
     // anchor
     $ws = "[ \t\r\f\v\n]*";
     while (eregi("\\[(anc{$ws}(name{$ws}={$ws}\"([^\"])*\"){$ws})\\]", $a_text, $found)) {
         $attribs = ilUtil::attribsToArray($found[2]);
         $a_text = str_replace("[" . $found[1] . "]", "<Anchor Name=\"" . $attribs["name"] . "\">", $a_text);
     }
     $a_text = eregi_replace("\\[\\/anc\\]", "</Anchor>", $a_text);
     //echo htmlentities($a_text); exit;
     return $a_text;
 }