00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("content/classes/Pages/class.ilPageContent.php");
00025 require_once("./content/classes/Pages/class.ilWysiwygUtil.php");
00026
00037 class ilPCParagraph extends ilPageContent
00038 {
00039 var $dom;
00040 var $par_node;
00041
00046 function ilPCParagraph(&$a_dom)
00047 {
00048 parent::ilPageContent();
00049 $this->setType("par");
00050
00051 $this->dom =& $a_dom;
00052 }
00053
00054 function setNode(&$a_node)
00055 {
00056 parent::setNode($a_node);
00057 $this->par_node =& $a_node->first_child();
00058 }
00059
00060
00061 function createAtNode (&$node) {
00062 $this->node =& $this->dom->create_element("PageContent");
00063 $this->par_node =& $this->dom->create_element("Paragraph");
00064 $this->par_node =& $this->node->append_child($this->par_node);
00065 $this->par_node->set_attribute("Language", "");
00066 $node->append_child ($this->node);
00067 }
00068
00069
00070 function create(&$a_pg_obj, $a_hier_id)
00071 {
00072 $this->node =& $this->dom->create_element("PageContent");
00073 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER);
00074 $this->par_node =& $this->dom->create_element("Paragraph");
00075 $this->par_node =& $this->node->append_child($this->par_node);
00076 $this->par_node->set_attribute("Language", "");
00077 }
00078
00079
00083 function setText($a_text)
00084 {
00085
00086 $temp_dom = @domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$a_text.'</Paragraph>',
00087 DOMXML_LOAD_PARSING, $error);
00088
00089
00090
00091 if(empty($error))
00092 {
00093
00094 $children = $this->par_node->child_nodes();
00095 for($i=0; $i<count($children); $i++)
00096 {
00097 $this->par_node->remove_child($children[$i]);
00098 }
00099
00100
00101
00102 $xpc = xpath_new_context($temp_dom);
00103 $path = "//Paragraph";
00104 $res =& xpath_eval($xpc, $path);
00105 if (count($res->nodeset) == 1)
00106 {
00107 $new_par_node =& $res->nodeset[0];
00108 $new_childs = $new_par_node->child_nodes();
00109 for($i=0; $i<count($new_childs); $i++)
00110 {
00111 $cloned_child =& $new_childs[$i]->clone_node(true);
00112 $this->par_node->append_child($cloned_child);
00113 }
00114 }
00115 return true;
00116 }
00117 else
00118 {
00119 return $error;
00120 }
00121 }
00122
00126 function getText($a_short_mode = false)
00127 {
00128 if (is_object($this->par_node))
00129 {
00130 $content = "";
00131 $childs = $this->par_node->child_nodes();
00132 for($i=0; $i<count($childs); $i++)
00133 {
00134 $content .= $this->dom->dump_node($childs[$i]);
00135 }
00136
00137 return $content;
00138 }
00139 else
00140 {
00141 return "";
00142 }
00143 }
00144
00148 function setCharacteristic($a_char)
00149 {
00150 if (!empty($a_char))
00151 {
00152 $this->par_node->set_attribute("Characteristic", $a_char);
00153 }
00154 else
00155 {
00156 if ($this->par_node->has_attribute("Characteristic"))
00157 {
00158 $this->par_node->remove_attribute("Characteristic");
00159 }
00160 }
00161 }
00162
00166 function getCharacteristic()
00167 {
00168 return $this->par_node->get_attribute("Characteristic");
00169 }
00170
00171
00176 function setSubCharacteristic($a_char)
00177 {
00178 if (!empty($a_char))
00179 {
00180 $this->par_node->set_attribute("SubCharacteristic", $a_char);
00181 }
00182 else
00183 {
00184 if ($this->par_node->has_attribute("SubCharacteristic"))
00185 {
00186 $this->par_node->remove_attribute("SubCharacteristic");
00187 }
00188 }
00189 }
00190
00194 function getAutoIndent()
00195 {
00196 return $this->par_node->get_attribute("AutoIndent");
00197 }
00198
00199 function setAutoIndent($a_char)
00200 {
00201 if (!empty($a_char))
00202 {
00203 $this->par_node->set_attribute("AutoIndent", $a_char);
00204 }
00205 else
00206 {
00207 if ($this->par_node->has_attribute("AutoIndent"))
00208 {
00209 $this->par_node->remove_attribute("AutoIndent");
00210 }
00211 }
00212 }
00213
00217 function getSubCharacteristic()
00218 {
00219 return $this->par_node->get_attribute("SubCharacteristic");
00220 }
00221
00226 function setDownloadTitle($a_char)
00227 {
00228 if (!empty($a_char))
00229 {
00230 $this->par_node->set_attribute("DownloadTitle", $a_char);
00231 }
00232 else
00233 {
00234 if ($this->par_node->has_attribute("DownloadTitle"))
00235 {
00236 $this->par_node->remove_attribute("DownloadTitle");
00237 }
00238 }
00239 }
00240
00244 function getDownloadTitle()
00245 {
00246 return $this->par_node->get_attribute("DownloadTitle");
00247 }
00248
00253 function setShowLineNumbers($a_char)
00254 {
00255 $a_char = empty($a_char)?"n":$a_char;
00256
00257 $this->par_node->set_attribute("ShowLineNumbers", $a_char);
00258 }
00259
00264 function getShowLineNumbers()
00265 {
00266 return $this->par_node->get_attribute("ShowLineNumbers");
00267 }
00268
00272 function setLanguage($a_lang)
00273 {
00274 $this->par_node->set_attribute("Language", $a_lang);
00275 }
00276
00280 function getLanguage()
00281 {
00282 return $this->par_node->get_attribute("Language");
00283 }
00284
00288 function input2xml($a_text, $a_wysiwyg = 0)
00289 {
00290 $a_text = ilUtil::stripSlashes($a_text, false);
00291
00292
00293
00294 $a_text = trim($a_text);
00295
00296
00297
00298 if ($a_wysiwyg == 1)
00299 {
00300
00301
00302
00303
00304 $wysiwygUtil = new ilWysiwygUtil();
00305 $a_text = $wysiwygUtil->convertFromPost($a_text);
00306
00307 }
00308
00309
00310
00311
00312 $a_text = str_replace("&","&",$a_text);
00313 $a_text = str_replace("<","<",$a_text);
00314 $a_text = str_replace(">",">",$a_text);
00315
00316
00317 $a_text = preg_replace('/<([\s\/]*?PageTurn.*?)>/i',"<$1>",$a_text);
00318 $a_text = preg_replace('/<([\s\/]*?BibItemIdentifier.*?)>/i',"<$1>",$a_text);
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 $a_text = str_replace(chr(13).chr(10),"<br />",$a_text);
00330 $a_text = str_replace(chr(13),"<br />", $a_text);
00331 $a_text = str_replace(chr(10),"<br />", $a_text);
00332
00333
00334 $a_text = eregi_replace("\[com\]","<Comment Language=\"".$this->getLanguage()."\">",$a_text);
00335 $a_text = eregi_replace("\[\/com\]","</Comment>",$a_text);
00336 $a_text = eregi_replace("\[emp\]","<Emph>",$a_text);
00337 $a_text = eregi_replace("\[\/emp\]","</Emph>",$a_text);
00338 $a_text = eregi_replace("\[str\]","<Strong>",$a_text);
00339 $a_text = eregi_replace("\[\/str\]","</Strong>",$a_text);
00340 $a_text = eregi_replace("\[fn\]","<Footnote>",$a_text);
00341 $a_text = eregi_replace("\[\/fn\]","</Footnote>",$a_text);
00342 $a_text = eregi_replace("\[quot\]","<Quotation Language=\"".$this->getLanguage()."\">",$a_text);
00343 $a_text = eregi_replace("\[\/quot\]","</Quotation>",$a_text);
00344 $a_text = eregi_replace("\[code\]","<Code>",$a_text);
00345 $a_text = eregi_replace("\[\/code\]","</Code>",$a_text);
00346
00347
00348
00349 $ws= "[ \t\r\f\v\n]*";
00350
00351 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
00352 "((page|chap|term|media|htlm|lm|dbk|glo|frm|exc|tst|svy|webr|chat|sahs|cat|crs|grp|file|fold)$ws=$ws([\"0-9])*)$ws".
00353 "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws))\]", $a_text, $found))
00354 {
00355 $attribs = ilUtil::attribsToArray($found[2]);
00356 $inst_str = $attribs["inst"];
00357
00358 if (isset($attribs["page"]))
00359 {
00360 if (!empty($found[10]))
00361 {
00362 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00363 }
00364 else
00365 {
00366 $tframestr = "";
00367 }
00368 $a_text = eregi_replace("\[".$found[1]."\]",
00369 "<IntLink Target=\"il_".$inst_str."_pg_".$attribs[page]."\" Type=\"PageObject\"".$tframestr.">", $a_text);
00370 }
00371
00372 else if (isset($attribs["chap"]))
00373 {
00374 if (!empty($found[10]))
00375 {
00376 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00377 }
00378 else
00379 {
00380 $tframestr = "";
00381 }
00382 $a_text = eregi_replace("\[".$found[1]."\]",
00383 "<IntLink Target=\"il_".$inst_str."_st_".$attribs[chap]."\" Type=\"StructureObject\"".$tframestr.">", $a_text);
00384 }
00385
00386 else if (isset($attribs["term"]))
00387 {
00388 switch ($found[10])
00389 {
00390 case "New":
00391 $tframestr = " TargetFrame=\"New\" ";
00392 break;
00393
00394 default:
00395 $tframestr = " TargetFrame=\"Glossary\" ";
00396 break;
00397 }
00398 $a_text = eregi_replace("\[".$found[1]."\]",
00399 "<IntLink Target=\"il_".$inst_str."_git_".$attribs[term]."\" Type=\"GlossaryItem\" $tframestr>", $a_text);
00400 }
00401
00402 else if (isset($attribs["media"]))
00403 {
00404 if (!empty($found[10]))
00405 {
00406 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00407 $a_text = eregi_replace("\[".$found[1]."\]",
00408 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"".$tframestr.">", $a_text);
00409 }
00410 else
00411 {
00412 $a_text = eregi_replace("\[".$found[1]."\]",
00413 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00414 }
00415 }
00416
00417
00418 else if (isset($attribs["lm"]) || isset($attribs["dbk"]) || isset($attribs["glo"])
00419 || isset($attribs["frm"]) || isset($attribs["exc"]) || isset($attribs["tst"])
00420 || isset($attribs["svy"]) || isset($attribs["obj"]) || isset($attribs['webr'])
00421 || isset($attribs["htlm"]) || isset($attribs["chat"]) || isset($attribs["grp"])
00422 || isset($attribs["fold"]) || isset($attribs["sahs"])
00423 || isset($attribs["cat"]) || isset($attribs["crs"]) || isset($attribs["file"]))
00424 {
00425 $obj_id = (isset($attribs["lm"])) ? $attribs["lm"] : $obj_id;
00426 $obj_id = (isset($attribs["dbk"])) ? $attribs["dbk"] : $obj_id;
00427 $obj_id = (isset($attribs["chat"])) ? $attribs["chat"] : $obj_id;
00428 $obj_id = (isset($attribs["glo"])) ? $attribs["glo"] : $obj_id;
00429 $obj_id = (isset($attribs["frm"])) ? $attribs["frm"] : $obj_id;
00430 $obj_id = (isset($attribs["exc"])) ? $attribs["exc"] : $obj_id;
00431 $obj_id = (isset($attribs["htlm"])) ? $attribs["htlm"] : $obj_id;
00432 $obj_id = (isset($attribs["tst"])) ? $attribs["tst"] : $obj_id;
00433 $obj_id = (isset($attribs["svy"])) ? $attribs["svy"] : $obj_id;
00434 $obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
00435 $obj_id = (isset($attribs["webr"])) ? $attribs["webr"] : $obj_id;
00436 $obj_id = (isset($attribs["fold"])) ? $attribs["fold"] : $obj_id;
00437 $obj_id = (isset($attribs["cat"])) ? $attribs["cat"] : $obj_id;
00438 $obj_id = (isset($attribs["sahs"])) ? $attribs["sahs"] : $obj_id;
00439 $obj_id = (isset($attribs["crs"])) ? $attribs["crs"] : $obj_id;
00440 $obj_id = (isset($attribs["grp"])) ? $attribs["grp"] : $obj_id;
00441 $obj_id = (isset($attribs["file"])) ? $attribs["file"] : $obj_id;
00442
00443 $a_text = eregi_replace("\[".$found[1]."\]",
00444 "<IntLink Target=\"il_".$inst_str."_obj_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
00445 }
00446 else
00447 {
00448 $a_text = eregi_replace("\[".$found[1]."\]", "[error: iln".$found[1]."]",$a_text);
00449 }
00450 }
00451 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?".$ws."media$ws=$ws([\"0-9])*)$ws)/\]", $a_text, $found))
00452 {
00453 $attribs = ilUtil::attribsToArray($found[2]);
00454 $inst_str = $attribs["inst"];
00455 $a_text = eregi_replace("\[".$found[1]."/\]",
00456 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00457 }
00458 $a_text = eregi_replace("\[\/iln\]","</IntLink>",$a_text);
00459
00460
00461 $ws= "[ \t\r\f\v\n]*";
00462
00463
00464 while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
00465 {
00466
00467 $attribs = ilUtil::attribsToArray($found[2]);
00468
00469
00470 if (isset($attribs["url"]))
00471 {
00472
00473 $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$attribs["url"]."\">", $a_text);
00474 }
00475 else
00476 {
00477 $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
00478 }
00479 }
00480 $a_text = eregi_replace("\[\/xln\]","</ExtLink>",$a_text);
00481
00482
00483
00484
00485
00486 return $a_text;
00487 }
00488
00489 function xml2output($a_text)
00490 {
00491
00492
00493
00494
00495 $any = "[^>]*";
00496 $a_text = eregi_replace("<Comment[^>]*>","[com]",$a_text);
00497 $a_text = eregi_replace("</Comment>","[/com]",$a_text);
00498 $a_text = eregi_replace("<Comment/>","[com][/com]",$a_text);
00499 $a_text = eregi_replace("<Emph>","[emp]",$a_text);
00500 $a_text = eregi_replace("</Emph>","[/emp]",$a_text);
00501 $a_text = eregi_replace("<Emph/>","[emp][/emp]",$a_text);
00502 $a_text = eregi_replace("<Strong>","[str]",$a_text);
00503 $a_text = eregi_replace("</Strong>","[/str]",$a_text);
00504 $a_text = eregi_replace("<Strong/>","[str][/str]",$a_text);
00505 $a_text = eregi_replace("<Footnote[^>]*>","[fn]",$a_text);
00506 $a_text = eregi_replace("</Footnote>","[/fn]",$a_text);
00507 $a_text = eregi_replace("<Footnote/>","[fn][/fn]",$a_text);
00508 $a_text = eregi_replace("<Quotation[^>]*>","[quot]",$a_text);
00509 $a_text = eregi_replace("</Quotation>","[/quot]",$a_text);
00510 $a_text = eregi_replace("<Quotation/>","[quot][/quot]",$a_text);
00511 $a_text = eregi_replace("<Code[^>]*>","[code]",$a_text);
00512 $a_text = eregi_replace("</Code>","[/code]",$a_text);
00513 $a_text = eregi_replace("<Code/>","[code][/code]",$a_text);
00514
00515
00516 while (eregi("<IntLink($any)>", $a_text, $found))
00517 {
00518 $found[0];
00519 $attribs = ilUtil::attribsToArray($found[1]);
00520 $target = explode("_", $attribs["Target"]);
00521 $target_id = $target[count($target) - 1];
00522 $inst_str = (!is_int(strpos($attribs["Target"], "__")))
00523 ? $inst_str = "inst=\"".$target[1]."\" "
00524 : $inst_str = "";
00525 switch($attribs["Type"])
00526 {
00527 case "PageObject":
00528 $tframestr = (!empty($attribs["TargetFrame"]))
00529 ? " target=\"".$attribs["TargetFrame"]."\""
00530 : "";
00531 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."page=\"".$target_id."\"$tframestr]",$a_text);
00532 break;
00533
00534 case "StructureObject":
00535 $tframestr = (!empty($attribs["TargetFrame"]))
00536 ? " target=\"".$attribs["TargetFrame"]."\""
00537 : "";
00538 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."chap=\"".$target_id."\"$tframestr]",$a_text);
00539 break;
00540
00541 case "GlossaryItem":
00542 $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
00543 ? ""
00544 : " target=\"".$attribs["TargetFrame"]."\"";
00545 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."term=\"".$target_id."\"".$tframestr."]",$a_text);
00546 break;
00547
00548 case "MediaObject":
00549 if (empty($attribs["TargetFrame"]))
00550 {
00551 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."media=\"".$target_id."\"/]",$a_text);
00552 }
00553 else
00554 {
00555 $a_text = eregi_replace("<IntLink".$found[1].">","[iln media=\"".$target_id."\"".
00556 " target=\"".$attribs["TargetFrame"]."\"]",$a_text);
00557 }
00558 break;
00559
00560 case "RepositoryItem":
00561 if ($inst_str == "")
00562 {
00563 $target_type = ilObject::_lookupType($target_id, true);
00564 }
00565 else
00566 {
00567 $target_type = "obj";
00568 }
00569 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."$target_type=\"".$target_id."\"".$tframestr."]",$a_text);
00570 break;
00571
00572 default:
00573 $a_text = eregi_replace("<IntLink".$found[1].">","[iln]",$a_text);
00574 break;
00575 }
00576 }
00577 $a_text = eregi_replace("</IntLink>","[/iln]",$a_text);
00578
00579
00580 while (eregi("<ExtLink($any)>", $a_text, $found))
00581 {
00582 $found[0];
00583 $attribs = ilUtil::attribsToArray($found[1]);
00584
00585 $a_text = str_replace("<ExtLink".$found[1].">","[xln url=\"".$attribs["Href"]."\"]",$a_text);
00586 }
00587 $a_text = eregi_replace("</ExtLink>","[/xln]",$a_text);
00588
00589
00590
00591 $a_text = str_replace("<br />", "\n", $a_text);
00592 $a_text = str_replace("<br/>", "\n", $a_text);
00593
00594
00595 $a_text = str_replace("{", "{", $a_text);
00596 $a_text = str_replace("}", "}", $a_text);
00597
00598
00599 $a_text = str_replace("<", "<", $a_text);
00600 $a_text = str_replace(">", ">",$a_text);
00601
00602
00603 $a_text = str_replace(""", "\"", $a_text);
00604
00605
00606
00607 $a_text = str_replace("&", "&", $a_text);
00608
00609
00610 $a_text = str_replace("<", "&lt;", $a_text);
00611 $a_text = str_replace(">", "&gt;", $a_text);
00612
00613 return $a_text;
00614
00615 }
00616
00621 function getType()
00622 {
00623 return ($this->getCharacteristic() == "Code")?"src":parent::getType();
00624 }
00625
00626 }
00627 ?>