edit_content.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 
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');  //text | xml | html | latex | texi
00040     $this->addSVar('normalize', 'false');  //normalize space
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     //make sure that the node is not locked by somebody else
00052     if (locked_by_somebody())  return;
00053 
00054     //get variables
00055     $content = $event_args['content'];
00056     $mode = $this->getSVar('mode');
00057 
00058     //replace comments and cdata by tags
00059     $content = strip_comments($content);
00060     if ($mode=='text')  $content = expand_cdata($content);
00061     $content = strip_cdata($content);
00062 
00063     //replace the xml entities
00064     $content = preg_replace('#&(\w+);#', '&amp;$1;', $content);
00065 
00066     //convert it to xml(docbook)
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     //put back the cdata and the comments
00077     $xml_content = putback_cdata($xml_content);
00078     $xml_content = putback_comments($xml_content);
00079 
00080     //validate the xml content
00081     if (! validate_xml($xml_content))
00082       {
00083         $this->error_on_save($content);
00084         return;
00085       }
00086 
00087     //write the new content to the content file
00088     $xml_file = file_content_xml();
00089     write_file($xml_file, $xml_content);
00090 
00091     //update the cache file content.html
00092     update_cache();
00093 
00094     //if the node type is simplesect, then update subnodes.html of the parent
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         //get node path of the parent
00101         $p_node_path = ereg_replace('[^/]+/$', '', $node_path);
00102         //update subnodes.html of the parent
00103         update_subnodes_html($p_node_path, $lng, 'non-recursive');
00104       }
00105 
00106     //add this node in the list of the modified nodes
00107     add_to_modified_nodes();
00108 
00109     //set the status of the node to modified
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     //fill the recordset
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     //set the recordset to the page
00168     global $webPage;
00169     $webPage->addRecordset($rs);
00170   }
00171 }
00172 ?>

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