forms.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2005-2006 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. */
  8. # $InputAttrs are the attributes we allow in output tags
  9. SDV($InputAttrs, array('name', 'value', 'id', 'class', 'rows', 'cols',
  10. 'size', 'maxlength', 'action', 'method', 'accesskey',
  11. 'checked', 'disabled', 'readonly', 'enctype', 'src', 'alt'));
  12. # Set up formatting for text, submit, hidden, radio, etc. types
  13. foreach(array('text', 'submit', 'hidden', 'password', 'radio', 'checkbox',
  14. 'reset', 'file', 'image') as $t)
  15. SDV($InputTags[$t][':html'], "<input type='$t' \$InputFormArgs />");
  16. SDV($InputTags['text']['class'], 'inputbox');
  17. SDV($InputTags['password']['class'], 'inputbox');
  18. SDV($InputTags['submit']['class'], 'inputbutton');
  19. SDV($InputTags['reset']['class'], 'inputbutton');
  20. # (:input form:)
  21. SDVA($InputTags['form'], array(
  22. ':args' => array('action', 'method'),
  23. ':html' => "<form \$InputFormArgs>",
  24. 'method' => 'post'));
  25. # (:input end:)
  26. SDV($InputTags['end'][':html'], '</form>');
  27. # (:input textarea:)
  28. SDVA($InputTags['textarea'], array(
  29. ':html' => "<textarea \$InputFormArgs></textarea>"));
  30. # (:input image:)
  31. SDV($InputTags['image'][':args'], array('name', 'src', 'alt'));
  32. Markup('input', 'directives',
  33. '/\\(:input\\s+(\\w+)(.*?):\\)/ei',
  34. "InputMarkup(\$pagename, '$1', PSS('$2'))");
  35. function InputMarkup($pagename, $type, $args) {
  36. global $InputTags, $InputAttrs, $InputValues, $FmtV;
  37. if (!@$InputTags[$type]) return "(:input $type $args:)";
  38. $opt = array_merge($InputTags[$type], ParseArgs($args));
  39. $args = @$opt[':args'];
  40. if (!$args) $args = array('name', 'value');
  41. while (count(@$opt['']) > 0 && count($args) > 0)
  42. $opt[array_shift($args)] = array_shift($opt['']);
  43. foreach ((array)@$opt[''] as $a)
  44. if (!isset($opt[$a])) $opt[$a] = $a;
  45. if (!isset($opt['value']) && isset($InputValues[@$opt['name']]))
  46. $opt['value'] = $InputValues[$opt['name']];
  47. $attr = array();
  48. foreach ($InputAttrs as $a) {
  49. if (!isset($opt[$a])) continue;
  50. $attr[] = "$a='".str_replace("'", '&#39;', $opt[$a])."'";
  51. }
  52. $FmtV['$InputFormArgs'] = implode(' ', $attr);
  53. $out = FmtPageName($opt[':html'], $pagename);
  54. return Keep($out);
  55. }
  56. ## Form-based authorization prompts (for use with PmWikiAuth)
  57. SDVA($InputTags['auth_form'], array(
  58. ':html' => "<form action='{$_SERVER['REQUEST_URI']}' method='post'
  59. name='authform'>\$PostVars"));
  60. SDV($AuthPromptFmt, array(&$PageStartFmt, 'page:$SiteGroup.AuthForm',
  61. "<script language='javascript' type='text/javascript'><!--
  62. try { document.authform.authid.focus(); }
  63. catch(e) { document.authform.authpw.focus(); } //--></script>",
  64. &$PageEndFmt));
  65. ## The section below handles specialized EditForm pages.
  66. ## We don't bother to load it if we're not editing.
  67. if ($action != 'edit') return;
  68. SDV($PageEditForm, '$SiteGroup.EditForm');
  69. SDV($PageEditFmt, '$EditForm');
  70. if (@$_REQUEST['editform']) {
  71. $PageEditForm=$_REQUEST['editform'];
  72. $PageEditFmt='$EditForm';
  73. }
  74. $Conditions['e_preview'] = '(boolean)$_POST["preview"]';
  75. XLSDV('en', array(
  76. 'ak_save' => 's',
  77. 'ak_saveedit' => 'u',
  78. 'ak_preview' => 'p',
  79. 'ak_textedit' => ',',
  80. 'e_rows' => '23',
  81. 'e_cols' => '60'));
  82. # (:e_preview:) displays the preview of formatted text.
  83. Markup('e_preview', 'directives',
  84. '/^\\(:e_preview:\\)/e',
  85. "Keep(\$GLOBALS['FmtV']['\$PreviewText'])");
  86. # If we didn't load guiedit.php, then set (:e_guibuttons:) to
  87. # simply be empty.
  88. Markup('e_guibuttons', 'directives', '/\\(:e_guibuttons:\\)/', '');
  89. SDVA($InputTags['e_form'], array(
  90. ':html' => "<form action='{\$PageUrl}?action=edit' method='post'><input
  91. type='hidden' name='action' value='edit' /><input
  92. type='hidden' name='n' value='{\$FullName}' /><input
  93. type='hidden' name='basetime' value='\$EditBaseTime' />"));
  94. SDVA($InputTags['e_textarea'], array(
  95. ':html' => "<textarea \$InputFormArgs
  96. onkeydown='if (event.keyCode==27) event.returnValue=false;'
  97. >\$EditText</textarea>",
  98. 'name' => 'text', 'id' => 'text', 'accesskey' => XL('ak_textedit'),
  99. 'rows' => XL('e_rows'), 'cols' => XL('e_cols')));
  100. SDVA($InputTags['e_author'], array(
  101. ':html' => "<input type='text' \$InputFormArgs />",
  102. 'name' => 'author', 'value' => $Author));
  103. SDVA($InputTags['e_changesummary'], array(
  104. ':html' => "<input type='text' \$InputFormArgs />",
  105. 'name' => 'csum', 'size' => '60', 'maxlength' => '100',
  106. 'value' => htmlspecialchars(stripmagic(@$_POST['csum']), ENT_QUOTES)));
  107. SDVA($InputTags['e_minorcheckbox'], array(
  108. ':html' => "<input type='checkbox' \$InputFormArgs />",
  109. 'name' => 'diffclass', 'value' => 'minor'));
  110. if (@$_POST['diffclass']=='minor')
  111. SDV($InputTags['e_minorcheckbox']['checked'], 'checked');
  112. SDVA($InputTags['e_savebutton'], array(
  113. ':html' => "<input type='submit' \$InputFormArgs />",
  114. 'name' => 'post', 'value' => ' '.XL('Save').' ',
  115. 'accesskey' => XL('ak_save')));
  116. SDVA($InputTags['e_saveeditbutton'], array(
  117. ':html' => "<input type='submit' \$InputFormArgs />",
  118. 'name' => 'postedit', 'value' => ' '.XL('Save and edit').' ',
  119. 'accesskey' => XL('ak_saveedit')));
  120. SDVA($InputTags['e_savedraftbutton'], array(':html' => ''));
  121. SDVA($InputTags['e_previewbutton'], array(
  122. ':html' => "<input type='submit' \$InputFormArgs />",
  123. 'name' => 'preview', 'value' => ' '.XL('Preview').' ',
  124. 'accesskey' => XL('ak_preview')));
  125. SDVA($InputTags['e_cancelbutton'], array(
  126. ':html' => "<input type='submit' \$InputFormArgs />",
  127. 'name' => 'cancel', 'value' => ' '.XL('Cancel').' ' ));
  128. SDVA($InputTags['e_resetbutton'], array(
  129. ':html' => "<input type='reset' \$InputFormArgs />",
  130. 'value' => ' '.XL('Reset').' '));