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
00035 class addbook extends WebObject
00036 {
00037 function on_create($event_args)
00038 {
00039
00040 set_time_limit(0);
00041
00042
00043 $xml_content = $this->get_initial_xml($event_args);
00044
00045
00046 $tmpfile = write_tmp_file($xml_content);
00047
00048
00049 $bookid = $event_args['bookid'];
00050 $lng = $event_args['lng'];
00051 $output = shell(CONTENT."import.sh $tmpfile $bookid $lng");
00052
00053
00054 unlink($tmpfile);
00055
00056
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
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 ?>