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
00025
00032 function get_id_title()
00033 {
00034 $node_path = WebApp::getSVar('docbook->node_path');
00035 $navig = get_arr_navigation($node_path);
00036 $title = $navig['this_title'];
00037 if ($node_path=='./')
00038 {
00039 $id = WebApp::getSVar('docbook->book_id');
00040 }
00041 else
00042 {
00043 ereg('([^/]+)/$', $node_path, $regs);
00044 $id = $regs[1];
00045 }
00046
00047 return array($id,$title);
00048 }
00049
00050 function xml_to_xml($content)
00051 {
00052
00053 list($id, $title) = get_id_title();
00054 $node_types = process_index_node('get_node_type');
00055 list($node_type, $subnode_type) = explode(':', $node_types);
00056
00057 $content = str_replace("\r\n", "\n", $content);
00058 $content = chop($content)."\n";
00059 $content = "<?xml version='1.0' encoding='utf-8'?>
00060 <$node_type id='$id'>
00061 <title>$title</title>$content</$node_type>
00062 ";
00063
00064 return (is_wellformed($content) ? $content : 'ERROR');
00065 }
00066
00071 function is_wellformed($xml_content)
00072 {
00073
00074 $tmpfile = write_tmp_file($xml_content);
00075
00076
00077
00078 $xsl_file = XSLT."edit_content/xml2xml1.xsl";
00079 $output = shell("xsltproc $xsl_file $tmpfile");
00080
00081 unlink($tmpfile);
00082
00083
00084 if (ereg("^$tmpfile:", $output))
00085 {
00086
00087 popup_window('Transformation Error', "<xmp>$output</xmp>");
00088 return false;
00089 }
00090 else
00091 return true;
00092 }
00093
00094 function html_to_xml($content)
00095 {
00096
00097 list($id, $title) = get_id_title();
00098 $node_types = process_index_node('get_node_type');
00099 list($node_type, $subnode_type) = explode(':', $node_types);
00100
00101 $content = "<?xml version='1.0' encoding='utf-8'?>
00102 <$node_type id='$id'>
00103 <title>$title</title>
00104
00105 $content
00106 </$node_type>
00107 ";
00108
00109
00110 $tmpfile = write_tmp_file($content);
00111
00112
00113 $normalize = WebApp::getSVar('edit_content->normalize');
00114 $norm = ($normalize=='true' ? '_normalize' : '');
00115 $xsl_file = XSLT."edit_content/html2xml${norm}.xsl";
00116 $xml_content = shell("xsltproc $xsl_file $tmpfile");
00117
00118
00119 if (ereg("^$tmpfile:", $xml_content))
00120 {
00121
00122 popup_window('Transformation Error', "<xmp>$xml_content</xmp>");
00123 return 'ERROR';
00124 }
00125
00126 unlink($tmpfile);
00127
00128 return $xml_content;
00129 }
00130
00131 function text_to_xml($content)
00132 {
00133
00134 include_once dirname(__FILE__)."/text_to_xml/package.WikiConverter.php";
00135
00136
00137 list($id, $title) = get_id_title();
00138 $node_types = process_index_node('get_node_type');
00139 list($node_type, $subnode_type) = explode(':', $node_types);
00140
00141
00142 if ($node_type=='bookinfo' or $node_type=='articleinfo')
00143 {
00144 $info = new Info();
00145 $info->parse($content);
00146 $xml_content = $info->to_xml();
00147 }
00148 else
00149 {
00150 $parser = new WikiParser;
00151 $tpl = $parser->parse_string($content);
00152 $xml_content = $tpl->to_xml();
00153 if (trim($xml_content)=='') $xml_content = '<para/>';
00154 }
00155
00156
00157 if ($node_type=='book' or $node_type=='article')
00158 {
00159 $xml_content = "<?xml version='1.0' encoding='utf-8' standalone='no'?>
00160 <$node_type id='$id'><title>$title</title></$node_type>";
00161 }
00162 else if ($node_type=='bookinfo' or $node_type=='articleinfo')
00163 {
00164 $xml_content = "<?xml version='1.0' encoding='utf-8' standalone='no'?>
00165 <$node_type id='$id'>$xml_content</$node_type>";
00166 }
00167 else
00168 {
00169 $xml_content = "<?xml version='1.0' encoding='utf-8' standalone='no'?>
00170 <$node_type id='$id'><title>$title</title>$xml_content</$node_type>";
00171 }
00172
00173 return (is_wellformed($xml_content) ? $xml_content : 'ERROR');
00174 }
00175
00176 function latex_to_xml($content)
00177 {
00178 $msg = "Converting from LATEX to XML is not implemented yet,\n"
00179 . "so, any modifications are not saved.\n";
00180 WebApp::message($msg);
00181
00182 $xml_content = 'ERROR';
00183 return $xml_content;
00184 }
00185
00186 function texi_to_xml($content)
00187 {
00188 $msg = "Converting from TEXI to XML is not implemented yet,\n"
00189 . "so, any modifications are not saved.\n";
00190 WebApp::message($msg);
00191
00192 $xml_content = 'ERROR';
00193 return $xml_content;
00194 }
00195 ?>