convert_from_xml.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This file is part of DocBookWiki.  DocBookWiki is a web application
00004    that displays and edits DocBook documents.
00005 
00006    Copyright (C) 2004, 2005, 2006, 2007
00007    Dashamir Hoxha, dashohoxha@users.sourceforge.net
00008 
00009    DocBookWiki is free software; you can redistribute it and/or modify
00010    it under the  terms of the GNU General  Public License as published
00011    by the Free  Software Foundation; either version 2  of the License,
00012    or (at your option) any later version.
00013 
00014    DocBookWiki is distributed in the  hope that it will be useful, but
00015    WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
00016    MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
00017    General Public License for more details.
00018 
00019    You should have  received a copy of the  GNU General Public License
00020    along  with  DocBookWiki;  if  not,  write  to  the  Free  Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022    USA
00023   */
00024 
00030 function xml_to_html($xml_file)
00031 {
00032   //process it with a transformer
00033   $normalize = WebApp::getSVar('edit_content->normalize');
00034   $norm = ($normalize=='true' ? '_normalize' : '');
00035   $xsl_file = XSLT."edit_content/xml2html${norm}.xsl";
00036   $html_content = shell("xsltproc $xsl_file $xml_file");
00037 
00038   return $html_content;
00039 }
00040 
00041 function xml_to_text($xml_file)
00042 {
00043   $patterns =
00044     array(
00045           /* escape some special chars by adding a slash before them */
00046           "/(_|`|~)/",
00047 
00048           /* escape [...] by adding a slash before it */
00049           "/\[([^\]]+)\]/",
00050 
00051           /* escape !# by adding a slash before it */
00052           "/!#/",
00053 
00054           /* escape bash$ and bash# */
00055           "/^\s*(bash\\\$|bash#)/",
00056           );
00057 
00058   $replacements =
00059     array(
00060           /* escape some special chars by adding a slash before them*/
00061           '\\\\\\1',
00062 
00063           /* escape [...] by adding a slash before it */
00064           '\\[\\1]',
00065 
00066           /* escape !# by adding a slash before it */
00067           '\\!#',
00068 
00069           /* escape bash$ and bash# */
00070           '\\\\\\1',
00071           );
00072 
00073   $arr_lines = file($xml_file);
00074   for ($i=0; $i < sizeof($arr_lines); $i++)
00075     {
00076       $arr_lines[$i] = preg_replace($patterns, $replacements, $arr_lines[$i]);
00077     }
00078   $xml_content = implode('', $arr_lines);
00079   $tmpfile = write_tmp_file($xml_content);
00080 
00081   //process it with a transformer
00082   $xsl_file = XSLT."edit_content/xml2text.xsl";
00083   $text_content = shell("xsltproc $xsl_file $tmpfile 2>&1");
00084   unlink($tmpfile);
00085 
00086   $patterns = array('/&amp;lt;/', '/&amp;gt;/');
00087   $replacements = array('\\<', '\\>');
00088   $text_content = preg_replace($patterns, $replacements, $text_content);
00089 
00090   return $text_content;
00091 }
00092 ?>

Generated on Wed Jan 9 08:27:32 2008 for DokBookWiki by  doxygen 1.5.2