• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/Pages/class.ilPCParagraph.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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;                  // node of Paragraph element
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);               // this is the PageContent node
00057                 $this->par_node =& $a_node->first_child();              //... and this the Paragraph node
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                 // DOMXML_LOAD_PARSING, DOMXML_LOAD_VALIDATING, DOMXML_LOAD_RECOVERING
00086                 $temp_dom = @domxml_open_mem("<Paragraph>".$a_text."</Paragraph>",
00087                         DOMXML_LOAD_PARSING, $error);
00088 
00089                 //$this->text = $a_text;
00090                 // remove all childs
00091                 if(empty($error))
00092                 {
00093                         // delete children of paragraph node
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                         // copy new content children in paragraph node
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 //echo "<br>thedump:".htmlentities($this->dom->dump_node($this->par_node)).":";
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                         //return $this->par_node->get_content();
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                 // note: the order of the processing steps is crucial
00294                 // and should be the same as in xml2output() in REVERSE order!
00295                 $a_text = trim($a_text);
00296 
00297 //echo "<br>first:".htmlentities($a_text);
00298 
00299                 if ($a_wysiwyg == 1)
00300                 {
00301                         //$a_text = str_replace("&","&amp;",$a_text);
00302                         //$a_text = str_replace("<","&lt;",$a_text);
00303                         //$a_text = str_replace(">","&gt;",$a_text);
00304 
00305                         $wysiwygUtil = new ilWysiwygUtil();
00306                         $a_text = $wysiwygUtil->convertFromPost($a_text);
00307                         //$a_text = addslashes($a_text);
00308                 }
00309 
00310 //echo "<br>between:".htmlentities($a_text);
00311 
00312                 // mask html
00313                 $a_text = str_replace("&","&amp;",$a_text);
00314                 $a_text = str_replace("<","&lt;",$a_text);
00315                 $a_text = str_replace(">","&gt;",$a_text);
00316 
00317 //echo "<br>second:".htmlentities($a_text);
00318 
00319                 // mask curly brackets
00320 /*
00321 echo htmlentities($a_text);
00322                 $a_text = str_replace("{", "&#123;", $a_text);
00323                 $a_text = str_replace("}", "&#125;", $a_text);
00324 echo htmlentities($a_text);*/
00325                 // linefeed to br
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                 // bb code to xml
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                 // internal links
00345                 //$any = "[^\]]*";      // this doesn't work :-(
00346                 $ws= "[ \t\r\f\v\n]*";
00347 
00348                 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
00349                         "((page|chap|term|media|lm|dbk|glo|frm|exc|tst|svy|webr)$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                         // pages
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                         // chapters
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                         // glossary terms
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                         // media object
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                         // repository items (id is ref_id (will be used internally but will
00414                         // be replaced by object id for export purposes)
00415                         else if (isset($attribs["lm"]) || isset($attribs["dbk"]) || isset($attribs["glo"])
00416                                          || isset($attribs["frm"]) || isset($attribs["exc"]) || isset($attribs["tst"])
00417                                          || isset($attribs["svy"]) || isset($attribs["obj"]) || isset($attribs['webr']))
00418                         {
00419                                 $obj_id = (isset($attribs["lm"])) ? $attribs["lm"] : $obj_id;
00420                                 $obj_id = (isset($attribs["dbk"])) ? $attribs["dbk"] : $obj_id;
00421                                 $obj_id = (isset($attribs["glo"])) ? $attribs["glo"] : $obj_id;
00422                                 $obj_id = (isset($attribs["frm"])) ? $attribs["frm"] : $obj_id;
00423                                 $obj_id = (isset($attribs["exc"])) ? $attribs["exc"] : $obj_id;
00424                                 $obj_id = (isset($attribs["tst"])) ? $attribs["tst"] : $obj_id;
00425                                 $obj_id = (isset($attribs["svy"])) ? $attribs["svy"] : $obj_id;
00426                                 $obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
00427                                 $obj_id = (isset($attribs["webr"])) ? $attribs["webr"] : $obj_id;
00428 
00429                                 $a_text = eregi_replace("\[".$found[1]."\]",
00430                                         "<IntLink Target=\"il_".$inst_str."_obj_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
00431                         }                       
00432                         else
00433                         {
00434                                 $a_text = eregi_replace("\[".$found[1]."\]", "[error: iln".$found[1]."]",$a_text);
00435                         }
00436                 }
00437                 while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?".$ws."media$ws=$ws([\"0-9])*)$ws)/\]", $a_text, $found))
00438                 {
00439                         $attribs = ilUtil::attribsToArray($found[2]);
00440                         $inst_str = $attribs["inst"];
00441                         $a_text = eregi_replace("\[".$found[1]."/\]",
00442                                 "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
00443                 }
00444                 $a_text = eregi_replace("\[\/iln\]","</IntLink>",$a_text);
00445 
00446                 // external link
00447                 $ws= "[ \t\r\f\v\n]*";
00448 
00449                 //while (eregi("\[(xln$ws(url$ws=$ws([\"0-9])*)$ws)\]", $a_text, $found))
00450                 while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
00451                 {
00452 //echo "found2:".addslashes($found[2])."<br>"; flush();;
00453                         $attribs = ilUtil::attribsToArray($found[2]);
00454 //echo "url:".$attribs["url"]."<br>";
00455                         //$found[1] = str_replace("?", "\?", $found[1]);
00456                         if (isset($attribs["url"]))
00457                         {
00458 //echo "3";
00459                                 $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$attribs["url"]."\">", $a_text);
00460                         }
00461                         else
00462                         {
00463                                 $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
00464                         }
00465                 }
00466                 $a_text = eregi_replace("\[\/xln\]","</ExtLink>",$a_text);
00467                 /*$blob = ereg_replace("<NR><NR>","<P>",$blob);
00468                 $blob = ereg_replace("<NR>"," ",$blob);*/
00469 //echo htmlentities($a_text);
00470                 //$a_text = nl2br($a_text);
00471                 //$a_text = addslashes($a_text);
00472                 return $a_text;
00473         }
00474 
00475         function xml2output($a_text)
00476         {
00477                 // note: the order of the processing steps is crucial
00478                 // and should be the same as in input2xml() in REVERSE order!
00479 
00480                 // xml to bb code
00481                 $any = "[^>]*";
00482                 $a_text = eregi_replace("<Comment[^>]*>","[com]",$a_text);
00483                 $a_text = eregi_replace("</Comment>","[/com]",$a_text);
00484                 $a_text = eregi_replace("<Emph>","[emp]",$a_text);
00485                 $a_text = eregi_replace("</Emph>","[/emp]",$a_text);
00486                 $a_text = eregi_replace("<Strong>","[str]",$a_text);
00487                 $a_text = eregi_replace("</Strong>","[/str]",$a_text);
00488                 $a_text = eregi_replace("<Footnote[^>]*>","[fn]",$a_text);
00489                 $a_text = eregi_replace("</Footnote>","[/fn]",$a_text);
00490                 $a_text = eregi_replace("<Quotation[^>]*>","[quot]",$a_text);
00491                 $a_text = eregi_replace("</Quotation>","[/quot]",$a_text);
00492                 $a_text = eregi_replace("<Code[^>]*>","[code]",$a_text);
00493                 $a_text = eregi_replace("</Code>","[/code]",$a_text);
00494 
00495                 // internal links
00496                 while (eregi("<IntLink($any)>", $a_text, $found))
00497                 {
00498                         $found[0];
00499                         $attribs = ilUtil::attribsToArray($found[1]);
00500                         $target = explode("_", $attribs["Target"]);
00501                         $target_id = $target[count($target) - 1];
00502                         $inst_str = (!is_int(strpos($attribs["Target"], "__")))
00503                                 ? $inst_str = "inst=\"".$target[1]."\" "
00504                                 : $inst_str = "";
00505                         switch($attribs["Type"])
00506                         {
00507                                 case "PageObject":
00508                                         $tframestr = (!empty($attribs["TargetFrame"]))
00509                                                 ? " target=\"".$attribs["TargetFrame"]."\" "
00510                                                 : "";
00511                                         $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."page=\"".$target_id."\"$tframestr]",$a_text);
00512                                         break;
00513 
00514                                 case "StructureObject":
00515                                         $tframestr = (!empty($attribs["TargetFrame"]))
00516                                                 ? " target=\"".$attribs["TargetFrame"]."\" "
00517                                                 : "";
00518                                         $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."chap=\"".$target_id."\"$tframestr]",$a_text);
00519                                         break;
00520 
00521                                 case "GlossaryItem":
00522                                         $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
00523                                                 ? ""
00524                                                 : " target=\"".$attribs["TargetFrame"]."\" ";
00525                                         $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."term=\"".$target_id."\"".$tframestr."]",$a_text);
00526                                         break;
00527 
00528                                 case "MediaObject":
00529                                         if (empty($attribs["TargetFrame"]))
00530                                         {
00531                                                 $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."media=\"".$target_id."\"/]",$a_text);
00532                                         }
00533                                         else
00534                                         {
00535                                                 $a_text = eregi_replace("<IntLink".$found[1].">","[iln media=\"".$target_id."\"".
00536                                                         " target=\"".$attribs["TargetFrame"]."\"]",$a_text);
00537                                         }
00538                                         break;
00539 
00540                                 case "RepositoryItem":
00541                                         if ($inst_str == "")
00542                                         {
00543                                                 $target_type = ilObject::_lookupType($target_id, true);
00544                                         }
00545                                         else
00546                                         {
00547                                                 $target_type = "obj";
00548                                         }
00549                                         $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."$target_type=\"".$target_id."\"".$tframestr."]",$a_text);
00550                                         break;
00551 
00552                                 default:
00553                                         $a_text = eregi_replace("<IntLink".$found[1].">","[iln]",$a_text);
00554                                         break;
00555                         }
00556                 }
00557                 $a_text = eregi_replace("</IntLink>","[/iln]",$a_text);
00558 
00559                 // external links
00560                 while (eregi("<ExtLink($any)>", $a_text, $found))
00561                 {
00562                         $found[0];
00563                         $attribs = ilUtil::attribsToArray($found[1]);
00564                         //$found[1] = str_replace("?", "\?", $found[1]);
00565                         $a_text = str_replace("<ExtLink".$found[1].">","[xln url=\"".$attribs["Href"]."\"]",$a_text);
00566                 }
00567                 $a_text = eregi_replace("</ExtLink>","[/xln]",$a_text);
00568 
00569 
00570                 // br to linefeed
00571                 $a_text = str_replace("<br />", "\n", $a_text);
00572                 $a_text = str_replace("<br/>", "\n", $a_text);
00573 
00574                 // prevent curly brackets from being swallowed up by template engine
00575                 $a_text = str_replace("{", "&#123;", $a_text);
00576                 $a_text = str_replace("}", "&#125;", $a_text);
00577 
00578                 // unmask html
00579                 $a_text = str_replace("&lt;", "<", $a_text);
00580                 $a_text = str_replace("&gt;", ">",$a_text);
00581 
00582                 // this is needed to allow html like <tag attribute="value">... in paragraphs
00583                 $a_text = str_replace("&quot;", "\"", $a_text);
00584 
00585                 // make ampersands in (enabled) html attributes work
00586                 // e.g. <a href="foo.php?n=4&t=5">hhh</a>
00587                 $a_text = str_replace("&amp;", "&", $a_text);
00588 
00589                 // make &gt; and $lt; work to allow (disabled) html descriptions
00590                 $a_text = str_replace("&lt;", "&amp;lt;", $a_text);
00591                 $a_text = str_replace("&gt;", "&amp;gt;", $a_text);
00592 
00593                 return $a_text;
00594                 //return str_replace("<br />", chr(13).chr(10), $a_text);
00595         }
00596 
00601         function getType()
00602         {
00603                 return ($this->getCharacteristic() == "Code")?"src":parent::getType();
00604         }
00605 
00606 }
00607 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1