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

  1. <?php
  2. // $Id: html.php,v 1.1 2004/01/12 22:14:05 comsubvie Exp $
  3.  
  4. // These functions take wiki entities like 'bold_begin' or 'ref' and return
  5. //   HTML representing these entities.  They are used throught this script
  6. //   to generate appropriate HTML.  Together with the template scripts, they
  7. //   constitue the sole generators of HTML in this script, and are thus the
  8. //   sole means of customizing appearance.
  9. function html_bold_start()
  10.   { return '<strong>'; }
  11. function html_bold_end()
  12.   { return '</strong>'; }
  13. function html_italic_start()
  14.   { return '<em>'; }
  15. function html_italic_end()
  16.   { return '</em>'; }
  17. function html_superscript_start()
  18.   { return '<sup>'; }
  19. function html_superscript_end()
  20.   { return '</sup>'; }
  21. function html_subscript_start()
  22.   { return '<sub>'; }
  23. function html_subscript_end()
  24.   { return '</sub>'; }
  25. function html_del_start()
  26.   { return '<del>'; }
  27. function html_del_end()
  28.   { return '</del>'; }
  29. function html_ins_start()
  30.   { return '<ins>'; }
  31. function html_ins_end()
  32.   { return '</ins>'; }
  33. function html_tt_start()
  34.   { return '<tt>'; }
  35. function html_tt_end()
  36.   { return '</tt>'; }
  37. function html_ul_start($attr='')
  38.   { return "<ul $attr>"; }
  39. function html_ul_end()
  40.   { return "</ul>\n"; }
  41. function html_ol_start()
  42.   { return '<ol>'; }
  43. function html_ol_end()
  44.   { return "</ol>\n"; }
  45. function html_li_start()
  46.   { return '<li>'; }
  47. function html_li_end()
  48.   { return "</li>\n"; }
  49. function html_dl_start()
  50.   { return '<dl>'; }
  51. function html_dl_end()
  52.   { return "</dl>\n"; }
  53. function html_dd_start()
  54.   { return '<dd>'; }
  55. function html_dd_end()
  56.   { return "</dd>\n"; }
  57. function html_dt_start()
  58.   { return '<dt>'; }
  59. function html_dt_end()
  60.   { return '</dt>'; }
  61. function html_hr()
  62.   { return "<hr />\n"; }
  63. function html_newline()
  64.   { return "<br />\n"; }
  65. function html_paragraph_start()
  66.   { return "<p>"; }
  67. function html_paragraph_end()
  68.   { return "</p>\n"; }
  69. function html_head_start($level)
  70.   { return "<h$level>"; }
  71. function html_head_end($level)
  72.   { return "</h$level>"; }
  73. function html_nowiki($text)
  74.   { return $text; }
  75. function html_code($text)
  76.   { return '<pre>' . $text . '</pre>'; }
  77. function html_phpcode($text) 
  78.   ob_start();
  79.   highlight_string($text);
  80.   $text = ob_get_contents();
  81.   ob_end_clean();
  82.  
  83.   $text = preg_replace("/^<code>/", "<pre class=\"phpsource\">", $text);
  84.   $text = preg_replace("/<\/code>$/", "</pre>", $text);
  85.   
  86.   // Make it valid xhtml...
  87.   $search[0] = '<font color="'.ini_get('highlight.html').'">';
  88.   $search[1] = '<font color="'.ini_get('highlight.default').'">';
  89.   $search[2] = '<font color="'.ini_get('highlight.keyword').'">';
  90.   $search[3] = '<font color="'.ini_get('highlight.string').'">';
  91.   $search[4] = '<font color="'.ini_get('highlight.comment').'">';
  92.   $search[5] = '</font>';
  93.   $search[6] = '\r';
  94.   $search[7] = '<br />';
  95.   $search[8] = ' ';
  96.   $replace[0] = '<span class="html">';
  97.   $replace[1] = '<span class="default">';
  98.   $replace[2] = '<span class="keyword">';
  99.   $replace[3] = '<span class="string">';
  100.   $replace[4] = '<span class="comment">';
  101.   $replace[5] = '</span>';
  102.   $replace[6] = '';
  103.   $replace[7] = "\n";
  104.   $replace[8] = ' ';
  105.  
  106.   return str_replace($search,$replace,$text);
  107. }
  108. function html_raw($text)
  109.   { return $text; }
  110. function html_anchor($name)
  111.   { return '<a name="' . $name . '"></a>'; }
  112. function html_diff_old_start()
  113.   { return "<table class=\"diff\"><tr><td class=\"diff-removed\">\n"; }
  114. function html_diff_new_start()
  115.   { return "<table class=\"diff\"><tr><td class=\"diff-added\">\n"; }
  116. function html_diff_end()
  117.   { return '</td></tr></table>'; }
  118. function html_diff_add()
  119.   { return html_bold_start() . PARSE_Added . html_bold_end(); }
  120. function html_diff_change()
  121.   { return html_bold_start() . PARSE_Changed . html_bold_end(); }
  122. function html_diff_delete()
  123.   { return html_bold_start() . PARSE_Deleted . html_bold_end(); }
  124. function html_table_start($args)
  125. {
  126.   if ($args != '') {
  127.     $extraStr = '';
  128.  
  129.     // Split and parse CurlyOptions
  130.     $options = split(',', $args);
  131.     foreach ($options as $opt) {
  132.       list($name, $value) = split('=', $opt);
  133.       // Only use the Table-options
  134.       if ($name[0]=='T') {
  135.         if ($name[1]=='c') { // TClass - Class of <table>
  136.           $extraStr .= ' class="'. $value .'"';
  137.         } else if ($name[1]=='s') {  // TStyle - Style of <table>
  138.           $extraStr .= ' style="'. $value .'"';
  139.         } else if ($name[1]=='b') { // TBorder - Use border with given width
  140.           if (is_numeric($value)) {
  141.             $extraStr .= ' border="'. $value .'"';
  142.           } else {
  143.             $extraStr .= ' border="1"';
  144.           }
  145.         }
  146.       }
  147.     }
  148.  
  149.     return "<table$extraStr>";
  150.   } else {
  151.     return '<table border="1">';
  152.   }
  153. }
  154. function html_table_end()
  155.   { return '</table>'; }
  156. function html_table_row_start($args)
  157. {
  158.   if ($args != '') {
  159.     $extraStr = '';
  160.  
  161.     // Split and parse CurlyOptions
  162.     $options = split(',', $args);
  163.     foreach ($options as $opt) {
  164.       list($name, $value) = split('=', $opt);
  165.       // Only use the Row-options
  166.       if ($name[0]=='R') {
  167.         if ($name[1]=='c') { // RClass - Class of <row>
  168.           $extraStr .= ' class="'. $value .'"';
  169.         } else if ($name[1]=='s') {  // RStyle - Style of <row>
  170.           $extraStr .= ' style="'. $value .'"';
  171.         }
  172.       }
  173.     }
  174.  
  175.     return "<tr$extraStr>";
  176.   } else {
  177.     return "<tr>";
  178.   }
  179. }
  180. function html_table_row_end()
  181.   { return '</tr>'; }
  182. function html_table_cell_start($span = 1, $args)
  183. {
  184.  
  185.   if ($args != '') {
  186.     $styleStr = '';
  187.  
  188.     $options = split(',', $args);
  189.  
  190.     // Parse CurlyOptions
  191.     foreach ($options as $opt) {
  192.       list($name, $value) = split('=', $opt);
  193.       if ($name[0]=='T' or $name[0]=='R') {
  194.         continue; //Was either a row or table option
  195.       }
  196.       if ($name[0]=='w') {
  197.         if (is_numeric($value)) {
  198.           $rowspan = $value;
  199.         } else {
  200.           $rowspan=2;
  201.         }
  202.         $extraStr .= ' rowspan="' . $rowspan .'"';
  203.       } else if ($name[0] == 'l') { $styleStr .= ' text-align: left;';
  204.       } else if ($name[0] == 'c') { $styleStr .= ' text-align: center;';
  205.       } else if ($name[0] == 'r') { $styleStr .= ' text-align: right;';
  206.       } else if ($name[0] == 't') { $styleStr .= ' vertical-align: top;';
  207.       } else if ($name[0] == 'b') { $styleStr .= ' vertical-align: bottom;';
  208.       } else if ($name[0] == 'B') { $styleStr .= ' font-weight: bold;';
  209.       } else if ($name[0] == 'I') { $styleStr .= ' font-style: italic;';
  210.       } else if ($name[0] == 's') { $styleStr .= ' '. $value .';';
  211.       } else if ($name[0] == 'C') { $extraStr .= ' class="'. $value .'"';
  212.       }
  213.     }
  214.  
  215.     if ($styleStr != "") {
  216.       $extraStr .= ' style="'. $styleStr .'"';
  217.     }
  218.   }
  219.  
  220.   if($span == 1)
  221.     { return '<td'. $extraStr .'>'; }
  222.   else
  223.     { return '<td colspan="'. $span .'"' .$extraStr. '>'; }
  224. }
  225. function html_table_cell_end()
  226.   { return '</td>'; }
  227. function html_time($timestamp)
  228. {
  229.   global $TimeZoneOff;
  230.   if($timestamp == '') { return PARSE_Never; }
  231.   $time = mktime(substr($timestamp, 8, 2),  substr($timestamp, 10, 2),
  232.                  substr($timestamp, 12, 2), substr($timestamp, 4, 2),
  233.                  substr($timestamp, 6, 2),  substr($timestamp, 0, 4));
  234.   return date('D, d M Y H:i:s', $time + $TimeZoneOff * 60);
  235. }
  236. function html_gmtime($timestamp)
  237. {
  238.   $time = mktime(substr($timestamp, 8, 2),  substr($timestamp, 10, 2),
  239.                  substr($timestamp, 12, 2), substr($timestamp, 4, 2),
  240.                  substr($timestamp, 6, 2),  substr($timestamp, 0, 4));
  241.   return gmdate('Y-m-d', $time) . 'T' . gmdate('H:i:s', $time) . 'Z';
  242. }
  243. function html_timestamp($timestamp)
  244. {
  245.   global $TimeZoneOff;
  246.   $time = mktime(substr($timestamp, 8, 2),  substr($timestamp, 10, 2),
  247.                  substr($timestamp, 12, 2), substr($timestamp, 4, 2),
  248.                  substr($timestamp, 6, 2),  substr($timestamp, 0, 4));
  249.   return date('Y.m.d H:i:s', $time + $TimeZoneOff * 60);
  250. }
  251. function html_url($url, $text)
  252. {
  253.   global $ImgPtn;
  254.   if($url == $text
  255.      && preg_match("/($ImgPtn)$/i", $text))
  256.   {
  257.     return "<img src=\"$url\" alt=\"" . basename($url) . "\" />";
  258.   }
  259.   if (preg_match("/(.*)\?(.*)/", $url, $match)) 
  260.   {
  261.     $match[2] = preg_replace("/&(amp;amp;|!?amp;)/", '&', $match[2]);
  262.     $url = $match[1] . '?'. $match[2];
  263.   }
  264.   return "<a href=\"$url\">$text</a>";
  265. }
  266. function html_ref($page, $appearance, $hover = '', $anchor = '', $anchor_appearance = '')
  267. {
  268.   global $db, $SeparateLinkWords;
  269.  
  270.   if($hover != '')
  271.     { $hover = ' title="' . $hover . '"'; }
  272.  
  273.   $p = new WikiPage($db, $page);
  274.  
  275.   if($p->exists())
  276.   {
  277.     if($SeparateLinkWords && $page == $appearance)
  278.       { $appearance = html_split_name($page); }
  279.     return '<a href="' . viewURL($page) . $anchor . '"' . $hover . '>'
  280.            . $appearance . $anchor_appearance . '</a>';
  281.   }
  282.   else
  283.   {
  284.     if(validate_page($page) == 1        // Normal WikiName
  285.        && $appearance == $page)         // ... and is what it appears
  286.       { return $page . '<a href="' . editURL($page) . '"' . $hover . '>?</a>'; }
  287.     else                                // Free link.
  288.       { return '(' . $appearance . ')<a href="' . editURL($page) . '"' . $hover . '>?</a>'; }
  289.   }
  290. }
  291. function html_interwiki($url, $text)
  292. {
  293.   return '<a href="' . $url . '">' . $text . '</a>';
  294. }
  295. function html_twin($base, $ref)
  296. {
  297.   global $pagestore;
  298.  
  299.   return '<a href="' . $pagestore->interwiki($base) . $ref . '">' .
  300.          '<span class="twin"><em>[' . $base . ']</em></span></a>';
  301. }
  302. function html_category($time, $page, $host, $user, $comment)
  303. {
  304.   global $pagestore;
  305.  
  306.   $text = '(' . html_timestamp($time) . ') (' .
  307.           '<a href="' . historyURL($page) . '">history</a>) ' .
  308.           html_ref($page, $page);
  309.  
  310.   if(count($twin = $pagestore->twinpages($page)))
  311.   {
  312.     foreach($twin as $site)
  313.       { $text = $text . ' ' . html_twin($site[0], $site[1]); }
  314.   }
  315.  
  316.   $text = $text . ' . . . . ' .
  317.           ($user == '' ? $host : html_ref($user, $user, $host));
  318.  
  319.   if($comment != '')
  320.   {
  321.     $text = $text . ' ' . html_bold_start() . '[' .
  322.             str_replace('<', '<', str_replace('&', '&', $comment)) .
  323.             ']' . html_bold_end();
  324.   }
  325.  
  326.   return $text;
  327. }
  328. function html_fulllist($page, $count)
  329. {
  330.   return '<strong><a href="' . viewURL($page, '', 1) . '">' .
  331.          PARSE_CompleteListStart . $count . PARSE_CompleteListEnd .
  332.          '</a></strong>';
  333. }
  334. function html_fullhistory($page, $count)
  335. {
  336.   return '<tr><td colspan="3"><strong><a href="' . historyURL($page, 1) . '">'.
  337.          PARSE_CompleteListStart . $count . PARSE_CompleteListEnd .
  338.          '</a></strong></td></tr>';
  339. }
  340. function html_parents_top($path)
  341. {
  342.   $ret = ''; $topDir='';
  343.   foreach (split('/', $path) as $subDir) {
  344.     $ret .= html_ref($topDir . $subDir, $subDir) . '/ ';
  345.     $topDir .= $subDir . '/';
  346.   };
  347.   return $ret;
  348. }
  349. function html_toolbar_top($path)
  350. {
  351.   global $HomePage, $PrefsScript;
  352.   return html_ref($HomePage, $HomePage) . ' | ' .
  353.          html_ref(PARSE_RecentChanges, PARSE_RecentChanges) . ' | ' .
  354.          (($path!="")? html_parents_top($path) . ' | ' : '') .
  355.          '<a href="' . $PrefsScript . '">Preferences</a>';
  356. }
  357. function html_history_entry($page, $version, $time, $host, $user, $c1, $c2,
  358.                             $comment)
  359. {
  360.   return "<tr><td>" .
  361.          "<input type=\"radio\" name=\"ver1\" value=\"$version\"" .
  362.          ($c1 ? ' checked="checked"' : '') . " /></td>\n" .
  363.          "    <td>" .
  364.          "<input type=\"radio\" name=\"ver2\" value=\"$version\"" .
  365.          ($c2 ? ' checked="checked"' : '') . " /></td>\n" .
  366.          "<td><a href=\"" . viewURL($page, $version) . "\">" .
  367.          html_time($time) . "</a> . . . . " .
  368.          ($user == '' ? $host : html_ref($user, $user, $host)) .
  369.          ($comment == '' ? '' :
  370.            (' ' . html_bold_start() . '[' .
  371.             str_replace('<', '<', str_replace('&', '&', $comment)) .
  372.             ']' . html_bold_end())) .
  373.          "</td></tr>\n";
  374. }
  375. function html_lock_start()
  376. {
  377.   global $AdminScript;
  378.  
  379.   return '<form method="post" action="' . $AdminScript . "\">\n" .
  380.          '<div class="form">' . "\n" .
  381.          '<input type="hidden" name="locking" value="1" />' . "\n" .
  382.          html_bold_start() . PARSE_Locked . html_bold_end() . html_newline();
  383. }
  384. function html_lock_end($count)
  385. {
  386.   return '<input type="hidden" name="count" value="' . $count . '" />' . "\n" .
  387.          '<input type="submit" name="Save" value="'. PARSE_ButtonSave .'" />'.
  388.          "\n" . '</div>' . "\n" .
  389.          '</form>' . "\n";
  390. }
  391. function html_lock_page($page, $mutable)
  392. {
  393.   static $count = 0;
  394.   $count++;
  395.   return '<input type="hidden" name="name' . $count .
  396.          '" value="' . urlencode($page) . '" />' . "\n" .
  397.          '<input type="checkbox" name="lock' . $count . '" value="1"' .
  398.          ($mutable ? '' : ' checked="checked"') . ' />' . "\n" .
  399.          "\n" . $page . html_newline();
  400. }
  401. function html_rate_start()
  402. {
  403.   return '<br /><strong>'. PARSE_BlockedRange. "</strong>\n<dl>\n";
  404. }
  405. function html_rate_end()
  406. {
  407.   global $AdminScript;
  408.  
  409.   return "</dl>\n" .
  410.          '<form method="post" action="' . $AdminScript . "\">\n" .
  411.          '<div class="form">' . "\n" .
  412.          '<input type="hidden" name="blocking" value="1" />' . "\n" .
  413.          PARSE_EnterIpRange . "<br />\n" . 
  414.          '<input type="text" name="address" value="" size="40" /><br />' .
  415.          "\n" .
  416.          '<input type="submit" name="Block" value="'.PARSE_ButtonBlock.'" />'.
  417.          "\n" .
  418.          '<input type="submit" name="Unblock" value="'. PARSE_ButtonUnblock.
  419.          '" />' . "\n" .
  420.          '</div>' . "\n";
  421.          '</form>' . "\n";
  422. }
  423. function html_rate_entry($address)
  424. {
  425.   return '<dd>' . $address . "</dd>\n";
  426. }
  427.  
  428. // This function splits up a traditional WikiName so that individual
  429. // words are separated by spaces.
  430.  
  431. function html_split_name($page)
  432. {
  433.   global $UpperPtn, $LowerPtn;
  434.  
  435.   if(validate_page($page) != 1)
  436.     { return $page; }
  437.   $page = preg_replace("/(?<=$UpperPtn|$LowerPtn)($UpperPtn$LowerPtn)/",
  438.                        ' \\1', $page, -1);
  439.   $page = preg_replace("/($LowerPtn)($UpperPtn)/",
  440.                        '\\1 \\2', $page, -1);
  441.   return $page;
  442. }
  443. function html_reflist() 
  444. {
  445.   global $RefList;
  446.   if (!empty($RefList)) {
  447.     $str = '<hr style="width:30%; margin-bottom: 0px; float:left" />'; 
  448.     $str .= '<ol style="font-size: 80%; clear:left; line-height:1" class="reflist" style="font-size:80%">'; 
  449.     foreach ($RefList as $ref) {
  450.       $str .=  '<li><a href="'. $ref. '">'. $ref .'</a></li>';
  451.     }
  452.     $str .= '</ol>';
  453.     return $str;
  454.   }
  455.   else 
  456.     { return ""; }
  457.  
  458. }
  459. ?>