PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/wkp_Tables.php

https://github.com/pastak/jichikai_web
PHP | 66 lines | 41 code | 13 blank | 12 comment | 4 complexity | 12e22682d86bede95d8d162e83949e7e MD5 | raw file
  1. <?php
  2. /*
  3. * Tables - plugin providing flexible and powerful syntax for tables
  4. *
  5. * Programmed by TigerWiki and WiKiss programmers, thanks to them.
  6. * (the only piece of LionWiki practically unmodified from WiKiss)
  7. */
  8. class Tables {
  9. var $desc = array(
  10. array("Tables", "provides flexible and powerful syntax. Help how to use it is located <a href=\"http://lionwiki.0o.cz/index.php?page=UserGuide%3A+Tables+plugin\">here</a>.")
  11. );
  12. function table_style($s)
  13. {
  14. $r = '';
  15. $st = '';
  16. if(strpos($s, 'h') !== FALSE)
  17. $r .= ' class="em"';
  18. if(strpos($s, 'l') !== FALSE)
  19. $st .= 'text-align: left; ';
  20. elseif(strpos($s, 'r') !== FALSE)
  21. $st .= 'text-align: right; ';
  22. if(strpos($s, 't') !== FALSE)
  23. $st .= 'vertical-align: top; ';
  24. elseif(strpos($s, 'b') !== FALSE)
  25. $st .= 'vertical-align: bottom; ';
  26. return $r . ($st ? ' style="' . $st . '"' : '');
  27. }
  28. function make_table($s)
  29. {
  30. global $matches_links;
  31. // Suppression des espaces en debut et fin de ligne
  32. //~ $s = trim($s);
  33. // on enleve les liens contenants |
  34. $regex = "/\[([^]]+\|.+)\]/Ums";
  35. $nblinks = preg_match_all($regex, $s, $matches_links);
  36. $s = preg_replace($regex, "[LINK]", $s);
  37. // Double |
  38. $s = str_replace('|', '||', $s);
  39. // Create rows first
  40. $s = preg_replace('/^\s*\|(.*)\|\s*$/m', '<tr>$1</tr>', $s);
  41. $s = str_replace("\n", "", $s);
  42. // Creation des <td></td> en se servant des |
  43. $s = preg_replace('/\|(([hlrtb]* ){0,1})\s*(\d*)\s*,{0,1}(\d*)\s*(.*?)\|/e', '"<td".("$3"?" colspan=\"$3\"":" ").("$4"?" rowspan=\"$4\"":" ").$this->table_style("$1").">$5</td>"', $s);
  44. if($nblinks > 0)
  45. $s = preg_replace_callback(array_fill(0, $nblinks, "/\[LINK\]/"), create_function('$m', 'global $matches_links;static $idxlink=0;return "[".$matches_links[1][$idxlink++]."]";'), $s);
  46. return stripslashes($s);
  47. }
  48. function formatBegin()
  49. {
  50. global $CON;
  51. $CON = preg_replace("/((^ *\|[^\n]*\| *$\n)+)/me", '"<table class=\"wikitable\">".stripslashes($this->make_table("$1"))."</table>\n"', $CON);
  52. }
  53. }