class.Info.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This  file is part  of WikiConverter.   WikiConverter is  a program
00004    that  converts   text/wiki  into   other  formats  (like   html  or
00005    xml/docbook).
00006 
00007    Copyright (c) 2005 Dashamir Hoxha, dhoxha@inima.al
00008 
00009    WikiConverter  is free  software;  you can  redistribute it  and/or
00010    modify  it under the  terms of  the GNU  General Public  License as
00011    published by the Free Software  Foundation; either version 2 of the
00012    License, or (at your option) any later version.
00013 
00014    WikiConverter is  distributed in the  hope that it will  be useful,
00015    but  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  WikiConverter; 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 Info
00032 {
00033   var $authors;
00034   var $abstract;
00035   var $keywords;
00036   var $copyright;
00037 
00038   function Info()
00039   {
00040     $this->authors = array();
00041     $this->abstract = '';
00042     $this->keywords = array();
00043     $this->copyright = '';
00044   }
00045 
00050   function parse($content)
00051   {
00052     $lines = explode("\n", $content);
00053     $attrib = 'dummy';
00054     $value  = '';
00055 
00056     for ($i=0; $i < sizeof($lines); $i++)
00057       {
00058         $line = $lines[$i];
00059         if (!ereg('^@([^:]+): (.*)$', $line, $regs))
00060           {
00061             $value .= $line;
00062           }
00063         else
00064           {
00065             //process the previous attribute
00066             $func_name = "parse_$attrib";
00067             $this->$func_name($value);
00068 
00069             //initialize the new attribute
00070             $attrib = $regs[1];
00071             $value  = $regs[2];
00072           }
00073       }
00074     //process the last attribute
00075     $func_name = "parse_$attrib";
00076     $this->$func_name($value);
00077   }
00078 
00079   function parse_dummy($str) {}
00080 
00081   function parse_author($str)
00082   {
00083     $arr = explode(',', $str);
00084     $this->authors[] = array(
00085                              'surname' => trim($arr[0]),
00086                              'firstname' => trim($arr[1]),
00087                              'email' => trim($arr[2]),
00088                              'org' => trim($arr[3])
00089                              );
00090   }
00091   
00092   function parse_keywords($str)
00093   {
00094     $arr = explode(',', $str);
00095     for ($i=0; $i < sizeof($arr); $i++)
00096       {
00097         $keyword = trim($arr[$i]);
00098         if ($keyword=='')  continue;
00099         $this->keywords[] = $keyword;
00100       }
00101   }
00102 
00103   function parse_abstract($str)
00104   {
00105     $this->abstract = trim($str);
00106   }
00107 
00108   function parse_copyright($str)
00109   {
00110     $this->copyright = trim($str);
00111   }
00112 
00114   function to_xml()
00115   {
00116     $xml .= $this->render_authors();
00117     $xml .= $this->render_abstract();
00118     $xml .= $this->render_keywords();
00119     $xml .= $this->render_copyright();
00120     return $xml;
00121   }
00122 
00123   function render_authors()
00124   {
00125     if (sizeof($this->authors)==0)  return '';
00126 
00127     for ($i=0; $i < sizeof($this->authors); $i++)
00128       {
00129         extract($this->authors[$i]);
00130 
00131         $xml .= "\n  <author>\n";
00132         $xml .= "    <firstname>$firstname</firstname>\n";
00133         $xml .= "    <surname>$surname</surname>\n";
00134         if ($email!='' or $org!='')
00135           {
00136             $xml .= "    <affiliation>\n";
00137             if ($org!='')
00138               {
00139                 $org = regex_replace($org);
00140                 $xml .= "      <orgname>$org</orgname>\n";
00141               }
00142             if ($email!='')
00143               {
00144                 $xml .= "      <address><email>$email</email></address>\n";
00145               }
00146             $xml .= "    </affiliation>\n";
00147           }
00148         $xml .= "  </author>\n";
00149       }
00150 
00151     return $xml;
00152   }
00153 
00154   function render_abstract()
00155   {
00156     $xml = "\n  <abstract><para>"
00157       . $this->abstract
00158       . "</para></abstract>\n";
00159 
00160     return $xml;
00161   }
00162 
00163   function render_keywords()
00164   {
00165     if (sizeof($this->keywords)==0)  return '';
00166 
00167     $xml = "\n  <keywordset>\n";
00168     for ($i=0; $i < sizeof($this->keywords); $i++)
00169       {
00170         $keyword = $this->keywords[$i];
00171         $xml .= "    <keyword>$keyword</keyword>\n";
00172       }
00173     $xml .= "  </keywordset>\n";
00174 
00175     return $xml;
00176   }
00177 
00178   function render_copyright()
00179   {
00180     if ($this->copyright=='')
00181       {
00182         $this->copyright = "Copyright (C) 2004, 2005 Firstname Lastname. 
00183 Permission is granted to copy, distribute and/or modify this document 
00184 under the terms of the GNU Free Documentation License, Version 1.1 
00185 or any later version published by the Free Software Foundation; 
00186 with no Invariant Sections, with no Front-Cover Texts, and with no 
00187 Back-Cover Texts. A copy of the license is included in the section 
00188 entitled \"GNU Free Documentation License.\"";
00189       }
00190 
00191     $xml = "\n  <legalnotice><para>"
00192       . $this->copyright
00193       . "</para></legalnotice>\n";
00194 
00195     return $xml;
00196   }
00197 }
00198 ?>

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