home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / wiki / parse / latex.php < prev    next >
PHP Script  |  2004-03-08  |  9KB  |  287 lines

  1. <?php
  2. // $Id: latex.php,v 1.1 2004/01/12 22:14:05 comsubvie Exp $
  3.  
  4. //
  5. //   2002/03/18  Troy D. Straszheim  <troy@resophonic.com>
  6. //
  7.  
  8. //   These functions take wiki entities like 'bold_begin' or 'ref' and return
  9. //   latex representing these entities.  They are used throught this script
  10. //   to generate appropriate latex.  Together with the template scripts, they
  11. //   constitue the sole generators of latex in this script, and are thus the
  12. //   sole means of customizing appearance.
  13.  
  14. function latex_bold_start()
  15.   { return '\textbf{'; }
  16. function latex_bold_end()
  17.   { return '}'; }
  18. function latex_italic_start()
  19.   { return '\textit{'; }
  20. function latex_italic_end()
  21.   { return '}'; }
  22. function latex_tt_start()
  23.   { return '\texttt{'; }
  24. function latex_tt_end()
  25.   { return '}'; }
  26. function latex_ul_start()
  27.   { return "\\begin{itemize}\n"; }
  28. function latex_ul_end()
  29.   { return "\\end{itemize}\n"; }
  30. function latex_ol_start()
  31.   { return '\begin{enumerate}'; }
  32. function latex_ol_end()
  33.   { return '\end{enumerate}'; }
  34. function latex_li_start()
  35.   { return '\item '; }
  36. function latex_li_end()
  37.   { return "\n\n"; }
  38.  
  39. function latex_dl_start()
  40.   { return '\begin{itemize}'; }
  41. function latex_dl_end()
  42.   { return '\end{itemize}'; }
  43. function latex_dd_start()
  44.   { return '\item '; }
  45. function latex_dd_end()
  46.   { return "\n"; }
  47.  
  48. function latex_hr()
  49.   { return "\vskip0.25cm\hrule\vskip0.25cm"; }
  50. function latex_newline()
  51.   { return "\n"; }
  52. function latex_head_start($level)
  53.   { 
  54.     $lvlmap = array('\chapter', '\section', '\subsection',
  55.           '\subsubsection', '\paragraph', '\subparagraph');
  56.   
  57.     return $lvlmap[$level] . '{'; 
  58.   }
  59.  
  60. function latex_head_end($level)
  61.   { return "}\n\n"; }
  62. function sanitize($text) 
  63.   { 
  64. //    $patterns = array ("/([^\\])%/", "/([^\\])#/", "/([^\\])&/");
  65. //    $replacements = array ("$1\%CLEAN", "$1\#CLEAN", "$1\&CLEAN");
  66. //    return preg_replace($patterns, $replacements, $text);
  67.       return "GIMPY:" . $text;
  68.   }
  69. function latex_nowiki($text)
  70.   { 
  71. //  $newtext = sanitize($text);
  72.     return $text; 
  73.   }
  74. function latex_code($text)
  75.   { return '\begin{verbatim}' . $text . '\end{verbatim}'; }
  76. function latex_raw($text)
  77.   { return $text; }
  78.  
  79. function html_table_start()
  80.   { return '\begin{tabular}{|l|l|l|l|l|l|l|l|l|}'; }
  81. function html_table_end()
  82.   { return '\end{tabular}' . "\n"; }
  83. function html_table_row_start()
  84.   { return ''; }
  85. function html_table_row_end()
  86.   { return '\\'.'\\'."\n"; }
  87. function html_table_cell_start($span = 1)
  88. {
  89. //  if($span == 1)
  90. //    { return '<td>'; }
  91. //  else
  92. //    { return '<td colspan="' . $span . '">'; }
  93.  
  94.   return '&';    
  95. }
  96. function html_table_cell_end()
  97.   { return '&'; }
  98. //function latex_diff_old_start()
  99. //  { return "<table width=\"95%\" bgcolor=\"ffffaf\"><tr><td>\n"; }
  100. //function latex_diff_end()
  101. //  { return '</td></tr></table>'; }
  102. //function latex_diff_new_start()
  103. //  { return "<table width=\"95%\" bgcolor=\"cfffcf\"><tr><td>\n"; }
  104. //function latex_diff_add()
  105. //  { return latex_bold_start() . 'Added:' . latex_bold_end(); }
  106. //function latex_diff_change()
  107. //  { return latex_bold_start() . 'Changed:' . latex_bold_end(); }
  108. //function latex_diff_delete()
  109. //  { return latex_bold_start() . 'Deleted:' . latex_bold_end(); }
  110.  
  111. function latex_time($timestamp)
  112. {
  113.   $time = mktime(substr($timestamp, 8, 2),  substr($timestamp, 10, 2),
  114.                  substr($timestamp, 12, 2), substr($timestamp, 4, 2),
  115.                  substr($timestamp, 6, 2),  substr($timestamp, 0, 4));
  116.   return date('D, d M Y H:i:s', $time);
  117. }
  118.  
  119. function latex_timestamp($timestamp)
  120. {
  121.   return substr($timestamp, 0, 4) . '.' .
  122.          substr($timestamp, 4, 2) . '.' .
  123.          substr($timestamp, 6, 2) . ' ' .
  124.          substr($timestamp, 8, 2) . ':' .
  125.          substr($timestamp, 10, 2);
  126. }
  127.  
  128. function latex_url($url, $text)
  129. {
  130.   if($url == $text
  131.      && preg_match('/(.jpg|.png|.gif)$/', $text))
  132.   {
  133.     return '\textit{(image: '. $url .')}';
  134.   }
  135.   return '$\underline{\textrm{'. $url . '}}$';
  136. }
  137.  
  138. function latex_ref($page, $appearance, $hover = '')
  139. {
  140.   global $db;
  141.  
  142.   if($hover != '')
  143.     { $hover = ' title="' . $hover . '"'; }
  144.  
  145.   $p = new WikiPage($db, $page);
  146.  
  147.   if($p->exists())
  148.   {
  149. //    return '<a href="' . viewURL($page) . '"' . $hover . '>' . $page . '</a>';
  150.     return '\textbf{'. $page . '}';
  151.   }
  152.   else
  153.   {
  154.     return '\textbf{' . $appearance . $hover . "}";
  155.   }
  156. }
  157.  
  158. function latex_interwiki($base, $ref)
  159. {
  160.   global $pagestore;
  161.  
  162.   if(($url = $pagestore->interwiki($base)) != '')
  163.     { return 'INTERWIKI-W-URL: ' . $url . ' ' . $base . ':' . $ref ; }
  164.  
  165.   return 'INTERWIKI-NO-URL: ' . $base . ':' . $ref;
  166. }
  167.  
  168. function latex_twin($base, $ref)
  169. {
  170.   global $pagestore;
  171.  
  172. //  return '<a href="' . $pagestore->interwiki($base) . $ref . '">' .
  173. //         '<font size="-1"><em>[' . $base . ']</em></font></a>';
  174. }
  175. function latex_category($time, $page, $host, $user, $comment)
  176. {
  177.   global $pagestore;
  178.  
  179.   $text = '(' . latex_timestamp($time) . ') (' .
  180.           '<a href="' . historyURL($page) . '"><font size="-1">changes</font></a>) ' .
  181.           latex_ref($page, $page);
  182.  
  183.   if(count($twin = $pagestore->twinpages($page)))
  184.   {
  185.     foreach($twin as $site)
  186.       { $text = $text . ' ' . latex_twin($site[0], $site[1]); }
  187.   }
  188.  
  189.   $text = $text . ' . . . . . <em>' .
  190.           ($user == '' ? $host : latex_ref($user, $user, $host)) . '</em>';
  191.  
  192.   if($comment != '')
  193.   {
  194.     $text = $text . ' ' . latex_bold_start() . '[' .
  195.             str_replace('<', '<', str_replace('&', '&', $comment)) .
  196.             ']' . latex_bold_end();
  197.   }
  198.  
  199.   return $text . latex_newline();
  200. }
  201. function latex_fulllist($page, $count)
  202. {
  203.   return '<strong><a href="' . viewURL($page, '', 1) . '">' .
  204.          PARSE_CompleteListStart . $count . PARSE_CompleteListEnd .
  205.          '</a></strong>';
  206. }
  207. function latex_fullhistory($page, $count)
  208. {
  209.   return '<tr><td colspan="3"><strong><a href="' . historyURL($page, 1) .'">'. 
  210.          PARSE_CompleteListStart . $count . PARSE_CompleteListEnd .
  211.          '</a></strong></td></tr>';
  212. }
  213. function latex_toolbar_top()
  214. {
  215.   global $HomePage, $PrefsScript;
  216.   return latex_ref($HomePage, $HomePage) . ' | ' .
  217.          latex_ref(PARSE_RecentChanges, PARSE_RecentChanges) . ' | ' .
  218.          '<a href="' . $PrefsScript . '">Preferences</a>';
  219. }
  220. function latex_history_entry($page, $version, $time, $host, $user, $c1, $c2,
  221.                              $comment)
  222. {
  223.   return "<tr><td>" .
  224.          "<input type=\"radio\" name=\"ver1\" value=\"$version\"" .
  225.          ($c1 ? ' checked="checked"' : '') . " /></td>\n" .
  226.          "    <td>" .
  227.          "<input type=\"radio\" name=\"ver2\" value=\"$version\"" .
  228.          ($c2 ? ' checked="checked"' : '') . " /></td>\n" .
  229.          "<td><a href=\"" . viewURL($page, $version) . "\">" .
  230.          latex_time($time) . "</a> . . . . " .
  231.          ($user == '' ? $host : latex_ref($user, $user, $host)) .
  232.          ($comment == '' ? '' :
  233.            (' ' . latex_bold_start() . '[' .
  234.             str_replace('<', '<', str_replace('&', '&', $comment)) .
  235.             ']' . latex_bold_end())) .
  236.          "</td></tr>\n";
  237. }
  238. function latex_lock_start()
  239. {
  240.   global $AdminScript;
  241.  
  242.   return '<form method="post" action="' . $AdminScript . "\">\n" .
  243.          '<input type="hidden" name="locking" value="1" />' . "\n" .
  244.          latex_bold_start() . PARSE_Locked . latex_bold_end() . latex_newline();
  245. }
  246. function latex_lock_end($count)
  247. {
  248.   return '<input type="hidden" name="count" value="' . $count . '" />' . "\n" .
  249.          '<input type="submit" name="Save" value="'.PARSE_ButtonSave.'" />' . 
  250.          "\n" . '</form>' . "\n";
  251. }
  252. function latex_lock_page($page, $mutable)
  253. {
  254.   static $count = 0;
  255.   $count++;
  256.   return '<input type="hidden" name="name' . $count .
  257.          '" value="' . urlencode($page) . '" />' . "\n" .
  258.          '<input type="checkbox" name="lock' . $count . '" value="1"' .
  259.          ($mutable ? '' : ' checked="checked"') . ' />' . "\n" .
  260.          "\n" . $page . latex_newline();
  261. }
  262. function latex_rate_start()
  263. {
  264.   return '<br /><strong>' . PARSE_BlockedRange. "</strong>\n<dl>\n";
  265. }
  266. function latex_rate_end()
  267. {
  268.   global $AdminScript;
  269.  
  270.   return "</dl>\n" .
  271.          '<form method="post" action="' . $AdminScript . "\">\n" .
  272.          '<input type="hidden" name="blocking" value="1" />' . "\n" .
  273.          PARSE_EnterIpRange . "<br />\n" .
  274.          '<input type="text" name="address" value="" size="40" /><br />' .
  275.          "\n" .
  276.          '<input type="submit" name="Block" value="'. PARSE_ButtonBlock . 
  277.          '" />' . "\n" .
  278.          '<input type="submit" name="Unblock" value="'. PARSE_ButtonUnblock . 
  279.          '" />' . "\n" .
  280.          '</form>' . "\n";
  281. }
  282. function latex_rate_entry($address)
  283. {
  284.   return '<dd>' . $address . "</dd>\n";
  285. }
  286. ?>
  287.