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 = stripslashes($a_text);
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
00318
00319
00320
00321
00322
00323
00324
00325 $a_text = str_replace(chr(13).chr(10),"<br />",$a_text);
00326 $a_text = str_replace(chr(13),"<br />", $a_text);
00327 $a_text = str_replace(chr(10),"<br />", $a_text);
00328
00329
00330 $a_text = eregi_replace("\[com\]","<Comment Language=\"".$this->getLanguage()."\">",$a_text);
00331 $a_text = eregi_replace("\[\/com\]","</Comment>",$a_text);
00332 $a_text = eregi_replace("\[emp\]","<Emph>",$a_text);
00333 $a_text = eregi_replace("\[\/emp\]","</Emph>",$a_text);
00334 $a_text = eregi_replace("\[str\]","<Strong>",$a_text);
00335 $a_text = eregi_replace("\[\/str\]","</Strong>",$a_text);
00336 $a_text = eregi_replace("\[fn\]","<Footnote>",$a_text);
00337 $a_text = eregi_replace("\[\/fn\]","</Footnote>",$a_text);
00338 $a_text = eregi_replace("\[quot\]","<Quotation Language=\"".$this->getLanguage()."\">",$a_text);
00339 $a_text = eregi_replace("\[\/quot\]","</Quotation>",$a_text);
00340 $a_text = eregi_replace("\[code\]","<Code>",$a_text);
00341 $a_text = eregi_replace("\[\/code\]","</Code>",$a_text);
00342
00343
00344
00345 $ws= "[ \t\r\f\v\n]*";
00346
00347 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
00348 "((page|chap|term|media|lm|dbk|glo|frm|exc|tst|svy|webr)$ws=$ws([\"0-9])*)$ws".
00349 "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws))\]", $a_text, $found))
00350 {
00351 $attribs = ilUtil::attribsToArray($found[2]);
00352 $inst_str = $attribs["inst"];
00353
00354 if (isset($attribs["page"]))
00355 {
00356 if (!empty($found[10]))
00357 {
00358 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00359 }
00360 else
00361 {
00362 $tframestr = "";
00363 }
00364 $a_text = eregi_replace("\[".$found[1]."\]",
00365 "<IntLink Target=\"il_".$inst_str."_pg_".$attribs[page]."\" Type=\"PageObject\"".$tframestr.">", $a_text);
00366 }
00367
00368 else if (isset($attribs["chap"]))
00369 {
00370 if (!empty($found[10]))
00371 {
00372 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00373 }
00374 else
00375 {
00376 $tframestr = "";
00377 }
00378 $a_text = eregi_replace("\[".$found[1]."\]",
00379 "<IntLink Target=\"il_".$inst_str."_st_".$attribs[chap]."\" Type=\"StructureObject\"".$tframestr.">", $a_text);
00380 }
00381
00382 else if (isset($attribs["term"]))
00383 {
00384 switch ($found[10])
00385 {
00386 case "New":
00387 $tframestr = " TargetFrame=\"New\" ";
00388 break;
00389
00390 default:
00391 $tframestr = " TargetFrame=\"Glossary\" ";
00392 break;
00393 }
00394 $a_text = eregi_replace("\[".$found[1]."\]",
00395 "<IntLink Target=\"il_".$inst_str."_git_".$attribs[term]."\" Type=\"GlossaryItem\" $tframestr>", $a_text);
00396 }
00397
00398 else if (isset($attribs["media"]))
00399 {
00400 if (!empty($found[10]))
00401 {
00402 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00403 $a_text = eregi_replace("\[".$found[1]."\]",
00404 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"".$tframestr.">", $a_text);
00405 }
00406 else
00407 {
00408 $a_text = eregi_replace("\[".$found[1]."\]",
00409 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00410 }
00411 }
00412
00413
00414 else if (isset($attribs["lm"]) || isset($attribs["dbk"]) || isset($attribs["glo"])
00415 || isset($attribs["frm"]) || isset($attribs["exc"]) || isset($attribs["tst"])
00416 || isset($attribs["svy"]) || isset($attribs["obj"]) || isset($attribs['webr']))
00417 {
00418 $obj_id = (isset($attribs["lm"])) ? $attribs["lm"] : $obj_id;
00419 $obj_id = (isset($attribs["dbk"])) ? $attribs["dbk"] : $obj_id;
00420 $obj_id = (isset($attribs["glo"])) ? $attribs["glo"] : $obj_id;
00421 $obj_id = (isset($attribs["frm"])) ? $attribs["frm"] : $obj_id;
00422 $obj_id = (isset($attribs["exc"])) ? $attribs["exc"] : $obj_id;
00423 $obj_id = (isset($attribs["tst"])) ? $attribs["tst"] : $obj_id;
00424 $obj_id = (isset($attribs["svy"])) ? $attribs["svy"] : $obj_id;
00425 $obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
00426 $obj_id = (isset($attribs["webr"])) ? $attribs["webr"] : $obj_id;
00427
00428 $a_text = eregi_replace("\[".$found[1]."\]",
00429 "<IntLink Target=\"il_".$inst_str."_obj_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
00430 }
00431 else
00432 {
00433 $a_text = eregi_replace("\[".$found[1]."\]", "[error: iln".$found[1]."]",$a_text);
00434 }
00435 }
00436 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?".$ws."media$ws=$ws([\"0-9])*)$ws)/\]", $a_text, $found))
00437 {
00438 $attribs = ilUtil::attribsToArray($found[2]);
00439 $inst_str = $attribs["inst"];
00440 $a_text = eregi_replace("\[".$found[1]."/\]",
00441 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00442 }
00443 $a_text = eregi_replace("\[\/iln\]","</IntLink>",$a_text);
00444
00445
00446 $ws= "[ \t\r\f\v\n]*";
00447
00448
00449 while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
00450 {
00451
00452 $attribs = ilUtil::attribsToArray($found[2]);
00453
00454
00455 if (isset($attribs["url"]))
00456 {
00457
00458 $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$attribs["url"]."\">", $a_text);
00459 }
00460 else
00461 {
00462 $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
00463 }
00464 }
00465 $a_text = eregi_replace("\[\/xln\]","</ExtLink>",$a_text);
00466
00467
00468
00469
00470
00471 return $a_text;
00472 }
00473
00474 function xml2output($a_text)
00475 {
00476
00477
00478
00479
00480 $any = "[^>]*";
00481 $a_text = eregi_replace("<Comment[^>]*>","[com]",$a_text);
00482 $a_text = eregi_replace("</Comment>","[/com]",$a_text);
00483 $a_text = eregi_replace("<Emph>","[emp]",$a_text);
00484 $a_text = eregi_replace("</Emph>","[/emp]",$a_text);
00485 $a_text = eregi_replace("<Strong>","[str]",$a_text);
00486 $a_text = eregi_replace("</Strong>","[/str]",$a_text);
00487 $a_text = eregi_replace("<Footnote[^>]*>","[fn]",$a_text);
00488 $a_text = eregi_replace("</Footnote>","[/fn]",$a_text);
00489 $a_text = eregi_replace("<Quotation[^>]*>","[quot]",$a_text);
00490 $a_text = eregi_replace("</Quotation>","[/quot]",$a_text);
00491 $a_text = eregi_replace("<Code[^>]*>","[code]",$a_text);
00492 $a_text = eregi_replace("</Code>","[/code]",$a_text);
00493
00494
00495 while (eregi("<IntLink($any)>", $a_text, $found))
00496 {
00497 $found[0];
00498 $attribs = ilUtil::attribsToArray($found[1]);
00499 $target = explode("_", $attribs["Target"]);
00500 $target_id = $target[count($target) - 1];
00501 $inst_str = (!is_int(strpos($attribs["Target"], "__")))
00502 ? $inst_str = "inst=\"".$target[1]."\" "
00503 : $inst_str = "";
00504 switch($attribs["Type"])
00505 {
00506 case "PageObject":
00507 $tframestr = (!empty($attribs["TargetFrame"]))
00508 ? " target=\"".$attribs["TargetFrame"]."\" "
00509 : "";
00510 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."page=\"".$target_id."\"$tframestr]",$a_text);
00511 break;
00512
00513 case "StructureObject":
00514 $tframestr = (!empty($attribs["TargetFrame"]))
00515 ? " target=\"".$attribs["TargetFrame"]."\" "
00516 : "";
00517 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."chap=\"".$target_id."\"$tframestr]",$a_text);
00518 break;
00519
00520 case "GlossaryItem":
00521 $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
00522 ? ""
00523 : " target=\"".$attribs["TargetFrame"]."\" ";
00524 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."term=\"".$target_id."\"".$tframestr."]",$a_text);
00525 break;
00526
00527 case "MediaObject":
00528 if (empty($attribs["TargetFrame"]))
00529 {
00530 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."media=\"".$target_id."\"/]",$a_text);
00531 }
00532 else
00533 {
00534 $a_text = eregi_replace("<IntLink".$found[1].">","[iln media=\"".$target_id."\"".
00535 " target=\"".$attribs["TargetFrame"]."\"]",$a_text);
00536 }
00537 break;
00538
00539 case "RepositoryItem":
00540 if ($inst_str == "")
00541 {
00542 $target_type = ilObject::_lookupType($target_id, true);
00543 }
00544 else
00545 {
00546 $target_type = "obj";
00547 }
00548 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."$target_type=\"".$target_id."\"".$tframestr."]",$a_text);
00549 break;
00550
00551 default:
00552 $a_text = eregi_replace("<IntLink".$found[1].">","[iln]",$a_text);
00553 break;
00554 }
00555 }
00556 $a_text = eregi_replace("</IntLink>","[/iln]",$a_text);
00557
00558
00559 while (eregi("<ExtLink($any)>", $a_text, $found))
00560 {
00561 $found[0];
00562 $attribs = ilUtil::attribsToArray($found[1]);
00563
00564 $a_text = str_replace("<ExtLink".$found[1].">","[xln url=\"".$attribs["Href"]."\"]",$a_text);
00565 }
00566 $a_text = eregi_replace("</ExtLink>","[/xln]",$a_text);
00567
00568
00569
00570 $a_text = str_replace("<br />", "\n", $a_text);
00571 $a_text = str_replace("<br/>", "\n", $a_text);
00572
00573
00574 $a_text = str_replace("{", "{", $a_text);
00575 $a_text = str_replace("}", "}", $a_text);
00576
00577
00578 $a_text = str_replace("<", "<", $a_text);
00579 $a_text = str_replace(">", ">",$a_text);
00580
00581
00582 $a_text = str_replace(""", "\"", $a_text);
00583
00584
00585
00586 $a_text = str_replace("&", "&", $a_text);
00587
00588
00589 $a_text = str_replace("<", "&lt;", $a_text);
00590 $a_text = str_replace(">", "&gt;", $a_text);
00591
00592 return $a_text;
00593
00594 }
00595
00600 function getType()
00601 {
00602 return ($this->getCharacteristic() == "Code")?"src":parent::getType();
00603 }
00604
00605 }
00606 ?>