class.Tpl.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 
00029 class Tpl
00030 {
00031   var $id;
00032   var $type;    
00033   var $contents; 
00034 
00036   function Tpl($type ='Template')
00037   {
00038     static $default_id = 'Template_001';
00039                 
00040     $this->id = $default_id++;
00041     $this->type = $type;
00042     $this->contents = array();
00043   }
00044 
00050   function get_tpl_id($line)
00051   {
00052     ereg('^&&([[:alnum:]_]+);;$', trim($line), $regs);
00053     return $regs[1];
00054   }
00055 
00060   function get_subtemplates()
00061   {
00062     $arr_tpl_id = array();
00063     for ($i=0; $i < sizeof($this->contents); $i++)
00064       {
00065         $line = $this->contents[$i];
00066         $tpl_id = $this->get_tpl_id($line);
00067         if ($tpl_id!='')  $arr_tpl_id[] = $tpl_id;
00068       }
00069     return $arr_tpl_id;
00070   }
00071 
00072   function to_html($indent ='', $class ='')
00073   {
00074     global $tpl_collection;
00075 
00076     $nr = sizeof($this->contents);
00077     for ($i=0; $i < $nr; $i++)
00078       {
00079         $line = $this->contents[$i];
00080         $tpl_id = $this->get_tpl_id($line);
00081         if ($tpl_id != '')
00082           {
00083             $tpl = $tpl_collection[$tpl_id];
00084             $html .= $tpl->to_html('  '.$indent, $class);
00085           }
00086         else
00087           {
00088             $indent1 = ($i==0 ? '' : $indent);
00089             $line1 = ($i==($nr-1) ? chop($line) : $line); 
00090             $html .= $this->line_to_html($line1, $indent1);
00091           }
00092       }
00093     return $html;
00094   }
00095 
00096   function line_to_html($line, $indent)
00097   {
00098     $line = regex_replace($line);
00099     return trim($line).' ';
00100   }
00101 
00102   function to_xml($indent ='')
00103   {
00104     global $tpl_collection;
00105 
00106     $nr = sizeof($this->contents);
00107     for ($i=0; $i < $nr; $i++)
00108       {
00109         $line = $this->contents[$i];
00110         $tpl_id = $this->get_tpl_id($line);
00111         if ($tpl_id != '')
00112           {
00113             $tpl = $tpl_collection[$tpl_id];
00114             $xml .= $tpl->to_xml('  '.$indent);
00115           }
00116         else
00117           {
00118             $indent1 = ($i==0 ? '' : $indent);
00119             $line1 = ($i==($nr-1) ? chop($line) : $line); 
00120             $xml .= $this->line_to_xml($line1, $indent1);
00121           }
00122       }
00123 
00124     return $xml;
00125   }
00126 
00127   function line_to_xml($line, $indent)
00128   {
00129     $line = regex_replace($line);
00130     return trim($line).' ';
00131   }
00132 
00134   function to_html_table()
00135   {
00136     $html_table = "
00137 <br />
00138 <a name='$this->id' id='$this->id'><span class='h_space'/></a>[<a href='javascript: back()'>Back</a>]
00139 <table class='converter' width='90%' bgcolor='#aaaaaa' border='0' cellspacing='1' cellpadding='2'>
00140   <tr>
00141     <td bgcolor='#eeeeee'>
00142       $this->id, type=$this->type
00143     </td>
00144   </tr>
00145   <tr><td bgcolor='#f9f9ff'>
00146 <pre>";
00147     for ($i=0; $i < sizeof($this->contents); $i++)
00148       {
00149         $line = $this->contents[$i];
00150         $tpl_id = $this->get_tpl_id($line);
00151         if ($tpl_id != '')
00152           {
00153             $html_table .= "<a href='#$tpl_id'>$line</a>";
00154           }
00155         else
00156           {
00157             $html_table .= htmlspecialchars($line);
00158           }
00159       }
00160 
00161     $html_table .= "</pre>
00162   </td></tr>
00163 </table>
00164 ";
00165     return $html_table;
00166   }
00167 }
00168 ?>

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