templates/admin/addbook/import_doc/import_doc.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 
00031 class import_doc extends WebObject
00032 {
00034   function on_refresh($event_args)
00035   {
00036     sleep(1);
00037   }
00038 
00040   function on_delete($event_args)
00041   {
00042     $fname = $event_args['fname'];
00043     $xml_file = CONTENT."initial_xml/uploaded/$fname";
00044     $media_file = ereg_replace('\.xml$', '.media.tgz', $xml_file);
00045     shell("rm $xml_file");
00046     shell("rm $media_file");
00047   }
00048 
00049   function on_import($event_args)
00050   {
00051     //running the script may take a long time
00052     set_time_limit(0);
00053 
00054     //get the arguments
00055     $book_id = $event_args['book_id'];
00056     $lng = $event_args['lng'];
00057     if ($lng=='')  $lng = 'en';
00058     $fname = $event_args['fname'];
00059 
00060     //get xml_file and media_files to be imported
00061     $xml_file = "initial_xml/uploaded/$fname";
00062     $media_files = ereg_replace('\.xml$', '.media.tgz', $xml_file);
00063     if (! file_exists(CONTENT.$media_files))  $media_files = '';
00064 
00065     //check for any xml errors
00066     $fpi = '-//OASIS//DTD DocBook XML V4.2//EN';
00067     $xmllint = "xmllint --noout --dtdvalidfpi '$fpi' --nonet --nowarning";
00068     $sed = 'sed -e \$d -e /warning:/d';  
00069     $xml_errors = shell("$xmllint $xml_file 2>&1 | $sed");
00070     if (trim($xml_errors)!='')
00071       {
00072         //display an error message
00073         $msg = T_("The XML file 'v_xml_file' cannot be imported because\n\
00074 there are some validation problems (see the output below).\n\
00075 Fix the problems first and try again.");
00076         $msg = str_replace('v_xml_file', $xml_file, $msg);
00077         WebApp::message($msg);
00078         WebApp::debug_msg("<xmp>$xml_errors</xmp>");
00079         return;
00080       }
00081 
00082     //there are no errors, import
00083     $output = shell(CONTENT."import.sh $xml_file $book_id $lng $media_files");
00084     WebApp::debug_msg("<xmp>$output</xmp>");
00085   }
00086 
00087   function onRender()
00088   {
00089     $this->add_uploaded_files_rs();
00090   }
00091 
00093   function add_uploaded_files_rs()
00094   {
00095     $rs = new EditableRS('uploaded_files');
00096 
00097     $path = CONTENT.'initial_xml/uploaded';
00098     $output = shell("ls $path/*.xml");
00099     $arr_files = explode("\n", $output);
00100     for ($i=0; $i < sizeof($arr_files); $i++)
00101       {
00102         $file = $arr_files[$i];
00103         if ($file=='' or ereg('No such file or directory', $file))  continue;
00104         $xml_file = str_replace("$path/", '', $file);
00105         $files = ereg_replace('\.xml$', '', $xml_file);
00106         $media = ereg_replace('\.xml$', '.media.tgz', $file);
00107         $files .= (file_exists($media) ? '.{xml,media.tgz}' : '.xml');
00108         $rs->addRec(compact('xml_file', 'files'));        
00109       }
00110 
00111     global $webPage;
00112     $webPage->addRecordset($rs);
00113   }
00114 }
00115 ?>

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