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 include_once dirname(__FILE__).'/convert_from_xml.php';
00026 include_once dirname(__FILE__).'/convert_to_xml.php';
00027 include_once dirname(__FILE__).'/validate.php';
00028 include_once dirname(__FILE__).'/func.popup_window.php';
00029 include_once dirname(__FILE__).'/process_content.php';
00030
00035 class edit_content extends WebObject
00036 {
00037 function init()
00038 {
00039 $this->addSVar('mode', 'text');
00040 $this->addSVar('normalize', 'false');
00041 }
00042
00043 function on_set_mode($event_args)
00044 {
00045 $mode = $event_args['mode'];
00046 $this->setSVar('mode', $mode);
00047 }
00048
00049 function on_save($event_args)
00050 {
00051
00052 if (locked_by_somebody()) return;
00053
00054
00055 $content = $event_args['content'];
00056 $mode = $this->getSVar('mode');
00057
00058
00059 $content = strip_comments($content);
00060 if ($mode=='text') $content = expand_cdata($content);
00061 $content = strip_cdata($content);
00062
00063
00064 $content = preg_replace('#&(\w+);#', '&$1;', $content);
00065
00066
00067 $converter = $mode.'_to_xml';
00068 $xml_content = $converter($content);
00069
00070 if ($xml_content=='ERROR')
00071 {
00072 $this->error_on_save($content);
00073 return;
00074 }
00075
00076
00077 $xml_content = putback_cdata($xml_content);
00078 $xml_content = putback_comments($xml_content);
00079
00080
00081 if (! validate_xml($xml_content))
00082 {
00083 $this->error_on_save($content);
00084 return;
00085 }
00086
00087
00088 $xml_file = file_content_xml();
00089 write_file($xml_file, $xml_content);
00090
00091
00092 update_cache();
00093
00094
00095 $node_type = WebApp::getVar('node_type');
00096 if ($node_type=='simplesect')
00097 {
00098 $lng = WebApp::getSVar('docbook->lng');
00099 $node_path = WebApp::getSVar('docbook->node_path');
00100
00101 $p_node_path = ereg_replace('[^/]+/$', '', $node_path);
00102
00103 update_subnodes_html($p_node_path, $lng, 'non-recursive');
00104 }
00105
00106
00107 add_to_modified_nodes();
00108
00109
00110 set_node_status('modified');
00111 }
00112
00113 function error_on_save($content)
00114 {
00115 $this->error = true;
00116
00117 $content = putback_cdata($content, 'html');
00118
00119 $mode = $this->getSVar('mode');
00120 if ($mode=='text') $content = compact_cdata($content);
00121
00122 $content = putback_comments($content);
00123
00124 WebApp::addGlobalVar('node_content', $content);
00125 WebApp::message(T_("There was an error, failed to save!"));
00126 }
00127
00128 function onRender()
00129 {
00130 $this->add_tab_items();
00131 $mode = $this->getSVar('mode');
00132 if (!$this->error)
00133 {
00134 $node_content = get_node_content(file_content_xml(), $mode);
00135 WebApp::addVar("node_content", $node_content);
00136 }
00137 }
00138
00142 function add_tab_items()
00143 {
00144 $items = array(
00145 'text' => 'Text',
00146 'xml' => 'DocBook',
00147 'html' => 'HTML',
00148 'latex' => 'Latex',
00149 'texi' => 'Texi'
00150 );
00151
00152 $rs = new EditableRS('items');
00153
00154
00155 $mode = $this->getSVar('mode');
00156 while ( list($item, $label) = each($items) )
00157 {
00158 $css_class = ($item==$mode ? 'item-selected' : 'item');
00159 $rec = array(
00160 'item' => $item,
00161 'label' => $label,
00162 'class' => $css_class
00163 );
00164 $rs->addRec($rec);
00165 }
00166
00167
00168 global $webPage;
00169 $webPage->addRecordset($rs);
00170 }
00171 }
00172 ?>