guiedit.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2004-2005 Patrick R. Michaud (pmichaud@pobox.com)
  3. This file is part of PmWiki; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version. See pmwiki.php for full details.
  7. This script adds a graphical button bar to the edit page form.
  8. The buttons are placed in the $GUIButtons array; each button
  9. is specified by an array of five values:
  10. - the position of the button relative to others (a number)
  11. - the opening markup sequence
  12. - the closing markup sequence
  13. - the default text if none was highlighted
  14. - the text of the button, either (a) HTML markup or (b) the
  15. url of a gif/jpg/png image to be used for the button
  16. (along with optional "title" text in quotes).
  17. The buttons specified in this file are the default buttons
  18. for the standard markups. Some buttons (e.g., the attach/upload
  19. button) are specified in their respective cookbook module.
  20. */
  21. $HTMLHeaderFmt[] = "<script language='javascript' type='text/javascript'
  22. src='\$FarmPubDirUrl/guiedit/guiedit.js'></script>\n";
  23. SDV($GUIButtonDirUrlFmt,'$FarmPubDirUrl/guiedit');
  24. SDVA($GUIButtons, array(
  25. 'em' => array(100, "''", "''", '$[Emphasized]',
  26. '$GUIButtonDirUrlFmt/em.gif"$[Emphasized (italic)]"',
  27. '$[ak_em]'),
  28. 'strong' => array(110, "'''", "'''", '$[Strong]',
  29. '$GUIButtonDirUrlFmt/strong.gif"$[Strong (bold)]"',
  30. '$[ak_strong]'),
  31. 'pagelink' => array(200, '[[', ']]', '$[Page link]',
  32. '$GUIButtonDirUrlFmt/pagelink.gif"$[Link to internal page]"'),
  33. 'extlink' => array(210, '[[', ']]', 'http:// | $[link text]',
  34. '$GUIButtonDirUrlFmt/extlink.gif"$[Link to external page]"'),
  35. 'big' => array(300, "'+", "+'", '$[Big text]',
  36. '$GUIButtonDirUrlFmt/big.gif"$[Big text]"'),
  37. 'small' => array(310, "'-", "-'", '$[Small text]',
  38. '$GUIButtonDirUrlFmt/small.gif"$[Small text]"'),
  39. 'sup' => array(320, "'^", "^'", '$[Superscript]',
  40. '$GUIButtonDirUrlFmt/sup.gif"$[Superscript]"'),
  41. 'sub' => array(330, "'_", "_'", '$[Subscript]',
  42. '$GUIButtonDirUrlFmt/sub.gif"$[Subscript]"'),
  43. 'h2' => array(400, '\\n!! ', '\\n', '$[Heading]',
  44. '$GUIButtonDirUrlFmt/h.gif"$[Heading]"'),
  45. 'center' => array(410, '%25center%25', '', '',
  46. '$GUIButtonDirUrlFmt/center.gif"$[Center]"')));
  47. Markup('e_guibuttons', 'directives',
  48. '/\\(:e_guibuttons:\\)/e',
  49. "Keep(FmtPageName(GUIButtonCode(\$pagename), \$pagename))");
  50. function GUIButtonCode($pagename) {
  51. global $GUIButtons;
  52. $cmpfn = create_function('$a,$b', 'return $a[0]-$b[0];');
  53. usort($GUIButtons, $cmpfn);
  54. $out = "<script language='javascript' type='text/javascript'>\n";
  55. foreach ($GUIButtons as $k => $g) {
  56. if (!$g) continue;
  57. @list($when, $mopen, $mclose, $mtext, $tag, $mkey) = $g;
  58. if ($tag{0} == '<') {
  59. $out .= "document.write(\"$tag\");\n";
  60. continue;
  61. }
  62. if (preg_match('/^(.*\\.(gif|jpg|png))("([^"]+)")?$/', $tag, $m)) {
  63. $title = (@$m[4] > '') ? "title='{$m[4]}'" : '';
  64. $tag = "<img src='{$m[1]}' $title style='border:0px;' />";
  65. }
  66. $mopen = str_replace(array('\\', "'"), array('\\\\', "\\\\'"), $mopen);
  67. $mclose = str_replace(array('\\', "'"), array('\\\\', "\\\\'"), $mclose);
  68. $mtext = str_replace(array('\\', "'"), array('\\\\', "\\\\'"), $mtext);
  69. $out .=
  70. "insButton(\"$mopen\", \"$mclose\", '$mtext', \"$tag\", \"$mkey\");\n";
  71. }
  72. $out .= '</script>';
  73. return $out;
  74. }