aboutsummaryrefslogtreecommitdiff
path: root/scripts/guiedit.php
blob: b8a59c5869ec0eb03be8660c96c0a0018ea0a70c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php if (!defined('PmWiki')) exit();
/*  Copyright 2004-2024 Patrick R. Michaud (pmichaud@pobox.com)
    This file is part of PmWiki; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  See pmwiki.php for full details.

    This script adds a graphical button bar to the edit page form.
    The buttons are placed in the $GUIButtons array; each button
    is specified by an array of five values:
      - the position of the button relative to others (a number)
      - the opening markup sequence
      - the closing markup sequence
      - the default text if none was highlighted
      - the text of the button, either (a) HTML markup or (b) the 
        url of a gif/jpg/png image to be used for the button 
        (along with optional "title" text in quotes).

    The buttons specified in this file are the default buttons
    for the standard markups.  Some buttons (e.g., the attach/upload
    button) are specified in their respective cookbook module.
    
    Script maintained by Petko YOTOV www.pmwiki.org/petko
*/


## Included even if no buttons: has "not saved warning" and others
SDVA($HTMLHeaderFmt, array('guiedit' => "<script type='text/javascript'
  src='\$FarmPubDirUrl/guiedit/guiedit.js'></script>\n"));

SDV($GUIButtonDirUrlFmt,'$FarmPubDirUrl/guiedit');

if(IsEnabled($EnableGUIButtons,0)) {
  SDVA($GUIButtons, array(
    'em'       => array(100, "''", "''", '$[Emphasized]',
                    '$GUIButtonDirUrlFmt/em.gif"$[Emphasized (italic)]"',
                    '$[ak_em]'),
    'strong'   => array(110, "'''", "'''", '$[Strong]',
                    '$GUIButtonDirUrlFmt/strong.gif"$[Strong (bold)]"',
                    '$[ak_strong]'),
    'pagelink' => array(200, '[[', ']]', '$[Page link]',
                    '$GUIButtonDirUrlFmt/pagelink.gif"$[Link to internal page]"'),
    'extlink'  => array(210, '[[', ']]', 'https:// | $[link text]',
                    '$GUIButtonDirUrlFmt/extlink.gif"$[Link to external page]"'),
    'big'      => array(300, "'+", "+'", '$[Big text]',
                    '$GUIButtonDirUrlFmt/big.gif"$[Big text]"'),
    'small'    => array(310, "'-", "-'", '$[Small text]',
                    '$GUIButtonDirUrlFmt/small.gif"$[Small text]"'),
    'sup'      => array(320, "'^", "^'", '$[Superscript]',
                    '$GUIButtonDirUrlFmt/sup.gif"$[Superscript]"'),
    'sub'      => array(330, "'_", "_'", '$[Subscript]',
                    '$GUIButtonDirUrlFmt/sub.gif"$[Subscript]"'),
    'h2'       => array(400, '\\n!! ', '\\n', '$[Heading]',
                    '$GUIButtonDirUrlFmt/h.gif"$[Heading]"'),
    'center'   => array(410, '%center%', '', '',
                    '$GUIButtonDirUrlFmt/center.gif"$[Center]"')));

  if(IsEnabled($EnableGuiEditFixUrl)) {
    $GUIButtons['fixurl'] = array($EnableGuiEditFixUrl, 'FixSelectedURL', '', '',
      '$GUIButtonDirUrlFmt/fixurl.png"$[Encode special characters in URL link addresses]"');
  }

  Markup('e_guibuttons', 'directives',
    '/\\(:e_guibuttons:\\)/', 'GUIButtonCode');
}

function GUIButtonCode() {
  global $GUIButtons;
  extract($GLOBALS["MarkupToHTML"]); # get $pagename
  
  foreach($GUIButtons as $k=>&$a) {
    if (!$a || count($a)<4 ) unset($GUIButtons[$k]);
    else $a[0] = floatval($a[0]);
  }

  usort($GUIButtons, 'cb_gbcompare');
  
  $json = PHSC(json_encode($GUIButtons));
  $out = "<span class='GUIButtons' data-json=\"$json\"></span>";
  return Keep(FmtPageName($out, $pagename));
}
function cb_gbcompare($a, $b) {return $a[0]-$b[0];}