• 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)$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                         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                 // external link
00428                 $ws= "[ \t\r\f\v\n]*";
00429 
00430                 //while (eregi("\[(xln$ws(url$ws=$ws([\"0-9])*)$ws)\]", $a_text, $found))
00431                 while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
00432                 {
00433 //echo "found2:".addslashes($found[2])."<br>"; flush();;
00434                         $attribs = ilUtil::attribsToArray($found[2]);
00435 //echo "url:".$attribs["url"]."<br>";
00436                         //$found[1] = str_replace("?", "\?", $found[1]);
00437                         if (isset($attribs["url"]))
00438                         {
00439 //echo "3";
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                 /*$blob = ereg_replace("<NR><NR>","<P>",$blob);
00449                 $blob = ereg_replace("<NR>"," ",$blob);*/
00450 
00451                 //$a_text = nl2br($a_text);
00452                 //$a_text = addslashes($a_text);
00453                 return $a_text;
00454         }
00455 
00456         function xml2output($a_text)
00457         {
00458                 // note: the order of the processing steps is crucial
00459                 // and should be the same as in input2xml() in REVERSE order!
00460 
00461                 // xml to bb code
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                 // internal links
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                 // external links
00529                 while (eregi("<ExtLink($any)>", $a_text, $found))
00530                 {
00531                         $found[0];
00532                         $attribs = ilUtil::attribsToArray($found[1]);
00533                         //$found[1] = str_replace("?", "\?", $found[1]);
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                 // br to linefeed
00540                 $a_text = str_replace("<br />", "\n", $a_text);
00541                 $a_text = str_replace("<br/>", "\n", $a_text);
00542 
00543                 // prevent curly brackets from being swallowed up by template engine
00544                 $a_text = str_replace("{", "&#123;", $a_text);
00545                 $a_text = str_replace("}", "&#125;", $a_text);
00546 
00547                 // unmask html
00548                 $a_text = str_replace("&lt;", "<", $a_text);
00549                 $a_text = str_replace("&gt;", ">",$a_text);
00550 
00551                 // this is needed to allow html like <tag attribute="value">... in paragraphs
00552                 $a_text = str_replace("&quot;", "\"", $a_text);
00553 
00554                 // make ampersands in (enabled) html attributes work
00555                 // e.g. <a href="foo.php?n=4&t=5">hhh</a>
00556                 $a_text = str_replace("&amp;", "&", $a_text);
00557 
00558                 // make &gt; and $lt; work to allow (disabled) html descriptions
00559                 $a_text = str_replace("&lt;", "&amp;lt;", $a_text);
00560                 $a_text = str_replace("&gt;", "&amp;gt;", $a_text);
00561 
00562                 return $a_text;
00563                 //return str_replace("<br />", chr(13).chr(10), $a_text);
00564         }
00565 
00570         function getType()
00571         {
00572                 return ($this->getCharacteristic() == "Code")?"src":parent::getType();
00573         }
00574 
00575 }
00576 ?>

Generated on Fri Dec 13 2013 08:00:16 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1