addbook.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 
00035 class addbook extends WebObject
00036 {
00037   function on_create($event_args)
00038   {
00039     //running the script may take a long time
00040     set_time_limit(0);
00041 
00042     //construct an initial xml document, using the parameters of $event_args
00043     $xml_content = $this->get_initial_xml($event_args);
00044 
00045     //write the xml content to a temporary file
00046     $tmpfile = write_tmp_file($xml_content);
00047 
00048     //import the xml file
00049     $bookid = $event_args['bookid'];
00050     $lng = $event_args['lng'];
00051     $output = shell(CONTENT."import.sh $tmpfile $bookid $lng");
00052 
00053     //remove the temporary file
00054     unlink($tmpfile);
00055 
00056     //display the output as debug messages
00057     WebApp::debug_msg("<xmp>$output</xmp>");
00058   }
00059 
00061   function get_initial_xml($event_args)
00062   {
00063     extract($event_args);
00064     if ($lng=='')  $lng = 'en';
00065 
00066     $xml_author = $this->author_to_xml($author);
00067     $xml_keywords = $this->keywords_to_xml($keywords);
00068     $legalnotice = $this->get_legalnotice($author);
00069     $fname = dirname(__FILE__).'/GNU-FDL.xml';
00070     $GNU_FDL = file_get_contents($fname);
00071 
00072     if ($doctype=='article')
00073       {
00074         $xml_content = "<?xml version='1.0' encoding='utf-8'?>
00075 <!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"
00076                          \"http://docbook.org/xml/4.2/docbookx.dtd\">
00077 <article id='$bookid' lang='$lng'>
00078   <title>$title</title>
00079   <articleinfo id='INFO'>
00080 " . $xml_author . "
00081     <abstract><para>$abstract</para></abstract>
00082 " . $xml_keywords . $legalnotice . "
00083   </articleinfo>
00084 
00085   <section id='sect01'><title>Section</title><para/>
00086     <section id='sect02'><title>Section</title><para/></section>
00087   </section>
00088   <section id='sect03'><title>Section</title><para/></section>
00089   <appendix id='appendix'><title>Appendix</title><para/></appendix>
00090 
00091   $GNU_FDL
00092 
00093 </article>
00094 ";
00095       }
00096     else // $doctype=='book'
00097       {
00098         $xml_content = "<?xml version='1.0' encoding='utf-8'?>
00099 <!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"
00100                       \"http://docbook.org/xml/4.2/docbookx.dtd\">
00101 <book id='$bookid' lang='$lng'>
00102   <title>$title</title>
00103   <bookinfo id='INFO'>
00104 " . $xml_author . "
00105     <abstract><para>$abstract</para></abstract>
00106 " . $xml_keywords . $legalnotice . "
00107   </bookinfo>
00108 
00109   <preface id='preface'><title>Preface</title><para/></preface>
00110   <chapter id='chap01'><title>Chapter</title><para/>
00111     <section id='sect01'><title>Section</title><para/></section>
00112   </chapter>
00113    <chapter id='chap02'><title>Chapter</title><para/></chapter>
00114  <appendix id='appendix'><title>Appendix</title><para/></appendix>
00115 
00116   $GNU_FDL
00117 
00118 </book>
00119 ";
00120       }
00121 
00122     return $xml_content;
00123   }
00124 
00136   function author_to_xml($str)
00137   {
00138     $arr = explode(',', $str);
00139     $surname = $arr[0];
00140     $firstname = $arr[1];
00141     $email = $arr[2];
00142 
00143     if ($email=='')  $affiliation = '';
00144     else
00145       {
00146         $affiliation = "
00147       <affiliation>
00148         <address><email>$email</email></address>
00149       </affiliation>";
00150       }
00151 
00152     $author = "
00153     <author>
00154       <firstname>Firstname</firstname>
00155       <surname>Surname</surname>"
00156       . $affiliation . "
00157     </author>
00158 ";
00159 
00160     return $author;
00161   }
00162 
00172   function keywords_to_xml($str)
00173   {
00174     $arr = explode(',', $str);
00175     $keywordset = "    <keywordset>\n";
00176     for ($i=0; $i < sizeof($arr); $i++)
00177       {
00178         $keyword = trim($arr[$i]);
00179         if ($keyword=='') continue;
00180         $keywordset .= "      <keyword>$keyword</keyword>\n";
00181       }
00182     $keywordset .= "    </keywordset>\n";
00183 
00184     return $keywordset;
00185   }
00186 
00187   function get_legalnotice($author)
00188   {
00189     $arr = explode(',', $author);
00190     $lastname = $arr[0];
00191     $firstname = $arr[1];
00192     $year = date('Y');
00193 
00194     $legalnotice = "
00195       <legalnotice><para>Copyright (C) $year $firstname $lastname.
00196       Permission is granted to copy, distribute and/or modify this document
00197       under the terms of the GNU Free Documentation License, Version 1.1
00198       or any later version published by the Free Software Foundation;
00199       with no Invariant Sections, with no Front-Cover Texts, and with no
00200       Back-Cover Texts. A copy of the license is included in the section
00201       entitled \"GNU Free Documentation License.\"</para></legalnotice>
00202 ";
00203 
00204     return $legalnotice;
00205   }
00206 }
00207 ?>

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