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("<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
00116 return true;
00117 }
00118 else
00119 {
00120 return $error;
00121 }
00122 }
00123
00127 function getText($a_short_mode = false)
00128 {
00129 if (is_object($this->par_node))
00130 {
00131 $content = "";
00132 $childs = $this->par_node->child_nodes();
00133 for($i=0; $i<count($childs); $i++)
00134 {
00135 $content .= $this->dom->dump_node($childs[$i]);
00136 }
00137
00138 return $content;
00139 }
00140 else
00141 {
00142 return "";
00143 }
00144 }
00145
00149 function setCharacteristic($a_char)
00150 {
00151 if (!empty($a_char))
00152 {
00153 $this->par_node->set_attribute("Characteristic", $a_char);
00154 }
00155 else
00156 {
00157 if ($this->par_node->has_attribute("Characteristic"))
00158 {
00159 $this->par_node->remove_attribute("Characteristic");
00160 }
00161 }
00162 }
00163
00167 function getCharacteristic()
00168 {
00169 return $this->par_node->get_attribute("Characteristic");
00170 }
00171
00172
00177 function setSubCharacteristic($a_char)
00178 {
00179 if (!empty($a_char))
00180 {
00181 $this->par_node->set_attribute("SubCharacteristic", $a_char);
00182 }
00183 else
00184 {
00185 if ($this->par_node->has_attribute("SubCharacteristic"))
00186 {
00187 $this->par_node->remove_attribute("SubCharacteristic");
00188 }
00189 }
00190 }
00191
00195 function getAutoIndent()
00196 {
00197 return $this->par_node->get_attribute("AutoIndent");
00198 }
00199
00200 function setAutoIndent($a_char)
00201 {
00202 if (!empty($a_char))
00203 {
00204 $this->par_node->set_attribute("AutoIndent", $a_char);
00205 }
00206 else
00207 {
00208 if ($this->par_node->has_attribute("AutoIndent"))
00209 {
00210 $this->par_node->remove_attribute("AutoIndent");
00211 }
00212 }
00213 }
00214
00218 function getSubCharacteristic()
00219 {
00220 return $this->par_node->get_attribute("SubCharacteristic");
00221 }
00222
00227 function setDownloadTitle($a_char)
00228 {
00229 if (!empty($a_char))
00230 {
00231 $this->par_node->set_attribute("DownloadTitle", $a_char);
00232 }
00233 else
00234 {
00235 if ($this->par_node->has_attribute("DownloadTitle"))
00236 {
00237 $this->par_node->remove_attribute("DownloadTitle");
00238 }
00239 }
00240 }
00241
00245 function getDownloadTitle()
00246 {
00247 return $this->par_node->get_attribute("DownloadTitle");
00248 }
00249
00254 function setShowLineNumbers($a_char)
00255 {
00256 $a_char = empty($a_char)?"n":$a_char;
00257
00258 $this->par_node->set_attribute("ShowLineNumbers", $a_char);
00259 }
00260
00265 function getShowLineNumbers()
00266 {
00267 return $this->par_node->get_attribute("ShowLineNumbers");
00268 }
00269
00273 function setLanguage($a_lang)
00274 {
00275 $this->par_node->set_attribute("Language", $a_lang);
00276 }
00277
00281 function getLanguage()
00282 {
00283 return $this->par_node->get_attribute("Language");
00284 }
00285
00289 function input2xml($a_text, $a_wysiwyg = 0)
00290 {
00291 $a_text = stripslashes($a_text);
00292
00293
00294
00295 $a_text = trim($a_text);
00296
00297
00298
00299 if ($a_wysiwyg == 1)
00300 {
00301 # $a_text = str_replace("&","&",$a_text);
00302 # $a_text = str_replace("<","<",$a_text);
00303 # $a_text = str_replace(">",">",$a_text);
00304
00305 $wysiwygUtil = new ilWysiwygUtil();
00306 $a_text = $wysiwygUtil->convertFromPost($a_text);
00307 # $a_text = addslashes($a_text);
00308 }
00309
00310
00311
00312
00313 $a_text = str_replace("&","&",$a_text);
00314 $a_text = str_replace("<","<",$a_text);
00315 $a_text = str_replace(">",">",$a_text);
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 $a_text = str_replace(chr(13).chr(10),"<br />",$a_text);
00327 $a_text = str_replace(chr(13),"<br />", $a_text);
00328 $a_text = str_replace(chr(10),"<br />", $a_text);
00329
00330
00331 $a_text = eregi_replace("\[com\]","<Comment Language=\"".$this->getLanguage()."\">",$a_text);
00332 $a_text = eregi_replace("\[\/com\]","</Comment>",$a_text);
00333 $a_text = eregi_replace("\[emp\]","<Emph>",$a_text);
00334 $a_text = eregi_replace("\[\/emp\]","</Emph>",$a_text);
00335 $a_text = eregi_replace("\[str\]","<Strong>",$a_text);
00336 $a_text = eregi_replace("\[\/str\]","</Strong>",$a_text);
00337 $a_text = eregi_replace("\[fn\]","<Footnote>",$a_text);
00338 $a_text = eregi_replace("\[\/fn\]","</Footnote>",$a_text);
00339 $a_text = eregi_replace("\[quot\]","<Quotation Language=\"".$this->getLanguage()."\">",$a_text);
00340 $a_text = eregi_replace("\[\/quot\]","</Quotation>",$a_text);
00341 $a_text = eregi_replace("\[code\]","<Code>",$a_text);
00342 $a_text = eregi_replace("\[\/code\]","</Code>",$a_text);
00343
00344
00345
00346 $ws= "[ \t\r\f\v\n]*";
00347
00348 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
00349 "((page|chap|term|media)$ws=$ws([\"0-9])*)$ws".
00350 "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws))\]", $a_text, $found))
00351 {
00352 $attribs = ilUtil::attribsToArray($found[2]);
00353 $inst_str = $attribs["inst"];
00354
00355 if (isset($attribs["page"]))
00356 {
00357 if (!empty($found[10]))
00358 {
00359 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00360 }
00361 else
00362 {
00363 $tframestr = "";
00364 }
00365 $a_text = eregi_replace("\[".$found[1]."\]",
00366 "<IntLink Target=\"il_".$inst_str."_pg_".$attribs[page]."\" Type=\"PageObject\"".$tframestr.">", $a_text);
00367 }
00368
00369 else if (isset($attribs["chap"]))
00370 {
00371 if (!empty($found[10]))
00372 {
00373 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00374 }
00375 else
00376 {
00377 $tframestr = "";
00378 }
00379 $a_text = eregi_replace("\[".$found[1]."\]",
00380 "<IntLink Target=\"il_".$inst_str."_st_".$attribs[chap]."\" Type=\"StructureObject\"".$tframestr.">", $a_text);
00381 }
00382
00383 else if (isset($attribs["term"]))
00384 {
00385 switch ($found[10])
00386 {
00387 case "New":
00388 $tframestr = " TargetFrame=\"New\" ";
00389 break;
00390
00391 default:
00392 $tframestr = " TargetFrame=\"Glossary\" ";
00393 break;
00394 }
00395 $a_text = eregi_replace("\[".$found[1]."\]",
00396 "<IntLink Target=\"il_".$inst_str."_git_".$attribs[term]."\" Type=\"GlossaryItem\" $tframestr>", $a_text);
00397 }
00398
00399 else if (isset($attribs["media"]))
00400 {
00401 if (!empty($found[10]))
00402 {
00403 $tframestr = " TargetFrame=\"".$found[10]."\" ";
00404 $a_text = eregi_replace("\[".$found[1]."\]",
00405 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"".$tframestr.">", $a_text);
00406 }
00407 else
00408 {
00409 $a_text = eregi_replace("\[".$found[1]."\]",
00410 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00411 }
00412 }
00413 else
00414 {
00415 $a_text = eregi_replace("\[".$found[1]."\]", "[error: iln".$found[1]."]",$a_text);
00416 }
00417 }
00418 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?".$ws."media$ws=$ws([\"0-9])*)$ws)/\]", $a_text, $found))
00419 {
00420 $attribs = ilUtil::attribsToArray($found[2]);
00421 $inst_str = $attribs["inst"];
00422 $a_text = eregi_replace("\[".$found[1]."/\]",
00423 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00424 }
00425 $a_text = eregi_replace("\[\/iln\]","</IntLink>",$a_text);
00426
00427
00428 $ws= "[ \t\r\f\v\n]*";
00429
00430
00431 while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
00432 {
00433
00434 $attribs = ilUtil::attribsToArray($found[2]);
00435
00436
00437 if (isset($attribs["url"]))
00438 {
00439
00440 $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$attribs["url"]."\">", $a_text);
00441 }
00442 else
00443 {
00444 $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
00445 }
00446 }
00447 $a_text = eregi_replace("\[\/xln\]","</ExtLink>",$a_text);
00448
00449
00450
00451
00452
00453 return $a_text;
00454 }
00455
00456 function xml2output($a_text)
00457 {
00458
00459
00460
00461
00462 $any = "[^>]*";
00463 $a_text = eregi_replace("<Comment[^>]*>","[com]",$a_text);
00464 $a_text = eregi_replace("</Comment>","[/com]",$a_text);
00465 $a_text = eregi_replace("<Emph>","[emp]",$a_text);
00466 $a_text = eregi_replace("</Emph>","[/emp]",$a_text);
00467 $a_text = eregi_replace("<Strong>","[str]",$a_text);
00468 $a_text = eregi_replace("</Strong>","[/str]",$a_text);
00469 $a_text = eregi_replace("<Footnote[^>]*>","[fn]",$a_text);
00470 $a_text = eregi_replace("</Footnote>","[/fn]",$a_text);
00471 $a_text = eregi_replace("<Quotation[^>]*>","[quot]",$a_text);
00472 $a_text = eregi_replace("</Quotation>","[/quot]",$a_text);
00473 $a_text = eregi_replace("<Code[^>]*>","[code]",$a_text);
00474 $a_text = eregi_replace("</Code>","[/code]",$a_text);
00475
00476
00477 while (eregi("<IntLink($any)>", $a_text, $found))
00478 {
00479 $found[0];
00480 $attribs = ilUtil::attribsToArray($found[1]);
00481 $target = explode("_", $attribs["Target"]);
00482 $target_id = $target[count($target) - 1];
00483 $inst_str = (!is_int(strpos($attribs["Target"], "__")))
00484 ? $inst_str = "inst=\"".$target[1]."\" "
00485 : $inst_str = "";
00486 switch($attribs["Type"])
00487 {
00488 case "PageObject":
00489 $tframestr = (!empty($attribs["TargetFrame"]))
00490 ? " target=\"".$attribs["TargetFrame"]."\" "
00491 : "";
00492 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."page=\"".$target_id."\"$tframestr]",$a_text);
00493 break;
00494
00495 case "StructureObject":
00496 $tframestr = (!empty($attribs["TargetFrame"]))
00497 ? " target=\"".$attribs["TargetFrame"]."\" "
00498 : "";
00499 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."chap=\"".$target_id."\"$tframestr]",$a_text);
00500 break;
00501
00502 case "GlossaryItem":
00503 $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
00504 ? ""
00505 : " target=\"".$attribs["TargetFrame"]."\" ";
00506 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."term=\"".$target_id."\"".$tframestr."]",$a_text);
00507 break;
00508
00509 case "MediaObject":
00510 if (empty($attribs["TargetFrame"]))
00511 {
00512 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."media=\"".$target_id."\"/]",$a_text);
00513 }
00514 else
00515 {
00516 $a_text = eregi_replace("<IntLink".$found[1].">","[iln media=\"".$target_id."\"".
00517 " target=\"".$attribs["TargetFrame"]."\"]",$a_text);
00518 }
00519 break;
00520
00521 default:
00522 $a_text = eregi_replace("<IntLink".$found[1].">","[iln]",$a_text);
00523 break;
00524 }
00525 }
00526 $a_text = eregi_replace("</IntLink>","[/iln]",$a_text);
00527
00528
00529 while (eregi("<ExtLink($any)>", $a_text, $found))
00530 {
00531 $found[0];
00532 $attribs = ilUtil::attribsToArray($found[1]);
00533
00534 $a_text = str_replace("<ExtLink".$found[1].">","[xln url=\"".$attribs["Href"]."\"]",$a_text);
00535 }
00536 $a_text = eregi_replace("</ExtLink>","[/xln]",$a_text);
00537
00538
00539
00540 $a_text = str_replace("<br />", "\n", $a_text);
00541 $a_text = str_replace("<br/>", "\n", $a_text);
00542
00543
00544 $a_text = str_replace("{", "{", $a_text);
00545 $a_text = str_replace("}", "}", $a_text);
00546
00547
00548 $a_text = str_replace("<", "<", $a_text);
00549 $a_text = str_replace(">", ">",$a_text);
00550
00551
00552 $a_text = str_replace(""", "\"", $a_text);
00553
00554
00555
00556 $a_text = str_replace("&", "&", $a_text);
00557
00558
00559 $a_text = str_replace("<", "&lt;", $a_text);
00560 $a_text = str_replace(">", "&gt;", $a_text);
00561
00562 return $a_text;
00563
00564 }
00565
00570 function getType()
00571 {
00572 return ($this->getCharacteristic() == "Code")?"src":parent::getType();
00573 }
00574
00575 }
00576 ?>