summaryrefslogtreecommitdiff
path: root/inc/form.php
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2009-10-22 14:02:17 +0200
committerAdrian Lang <lang@cosmocode.de>2009-10-22 14:02:17 +0200
commit804e2f2f6882dcf7b125406acfc1e7e53a520934 (patch)
tree23e02329aeedef9ac4b8ca667953519d2fbb22cf /inc/form.php
parente351c80d455c51c1c334588fc5e9ff63ad63c09e (diff)
downloadrpg-804e2f2f6882dcf7b125406acfc1e7e53a520934.tar.gz
rpg-804e2f2f6882dcf7b125406acfc1e7e53a520934.tar.bz2
Change inc/form.php to four space indentation
darcs-hash:20091022120217-e4919-5409e48225e5ff0d8ec3fa5da02b106017c1a1dd.gz
Diffstat (limited to 'inc/form.php')
-rw-r--r--inc/form.php895
1 files changed, 447 insertions, 448 deletions
diff --git a/inc/form.php b/inc/form.php
index e638af4bc..650ebfa0a 100644
--- a/inc/form.php
+++ b/inc/form.php
@@ -7,7 +7,6 @@
*/
if(!defined('DOKU_INC')) die('meh.');
-if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/html.php');
/**
@@ -29,242 +28,243 @@ require_once(DOKU_INC.'inc/html.php');
*/
class Doku_Form {
- // Form id attribute
- var $params = array();
-
- // Draw a border around form fields.
- // Adds <fieldset></fieldset> around the elements
- var $_infieldset = false;
-
- // Hidden form fields.
- var $_hidden = array();
-
- // Array of pseudo-tags
- var $_content = array();
-
- /**
- * Constructor
- *
- * Sets parameters and autoadds a security token. The old calling convention
- * with up to four parameters is deprecated, instead the first parameter
- * should be an array with parameters.
- *
- * @param mixed $params Parameters for the HTML form element; Using the
- * deprecated calling convention this is the ID
- * attribute of the form
- * @param string $action (optional, deprecated) submit URL, defaults to
- * current page
- * @param string $method (optional, deprecated) 'POST' or 'GET', default
- * is POST
- * @param string $enctype (optional, deprecated) Encoding type of the
- * data
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function Doku_Form($params, $action=false, $method=false, $enctype=false) {
- if(!is_array($params)) {
- $this->params = array('id' => $params);
- if ($action !== false) $this->params['action'] = $action;
- if ($method !== false) $this->params['method'] = $method;
- if ($enctype !== false) $this->params['enctype'] = $enctype;
- } else {
- $this->params = $params;
+ // Form id attribute
+ var $params = array();
+
+ // Draw a border around form fields.
+ // Adds <fieldset></fieldset> around the elements
+ var $_infieldset = false;
+
+ // Hidden form fields.
+ var $_hidden = array();
+
+ // Array of pseudo-tags
+ var $_content = array();
+
+ /**
+ * Constructor
+ *
+ * Sets parameters and autoadds a security token. The old calling convention
+ * with up to four parameters is deprecated, instead the first parameter
+ * should be an array with parameters.
+ *
+ * @param mixed $params Parameters for the HTML form element; Using the
+ * deprecated calling convention this is the ID
+ * attribute of the form
+ * @param string $action (optional, deprecated) submit URL, defaults to
+ * current page
+ * @param string $method (optional, deprecated) 'POST' or 'GET', default
+ * is POST
+ * @param string $enctype (optional, deprecated) Encoding type of the
+ * data
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function Doku_Form($params, $action=false, $method=false, $enctype=false) {
+ if(!is_array($params)) {
+ $this->params = array('id' => $params);
+ if ($action !== false) $this->params['action'] = $action;
+ if ($method !== false) $this->params['method'] = $method;
+ if ($enctype !== false) $this->params['enctype'] = $enctype;
+ } else {
+ $this->params = $params;
+ }
+
+ if (!isset($this->params['method'])) {
+ $this->params['method'] = 'POST';
+ }
+
+ $this->addHidden('sectok', getSecurityToken());
}
- if (!isset($this->params['method'])) {
- $this->params['method'] = 'POST';
+
+ /**
+ * startFieldset
+ *
+ * Add <fieldset></fieldset> tags around fields.
+ * Usually results in a border drawn around the form.
+ *
+ * @param string $legend Label that will be printed with the border.
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function startFieldset($legend) {
+ if ($this->_infieldset) {
+ $this->addElement(array('_elem'=>'closefieldset'));
+ }
+ $this->addElement(array('_elem'=>'openfieldset', '_legend'=>$legend));
+ $this->_infieldset = true;
}
- $this->addHidden('sectok', getSecurityToken());
- }
-
- /**
- * startFieldset
- *
- * Add <fieldset></fieldset> tags around fields.
- * Usually results in a border drawn around the form.
- *
- * @param string $legend Label that will be printed with the border.
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function startFieldset($legend) {
- if ($this->_infieldset) {
- $this->addElement(array('_elem'=>'closefieldset'));
+ /**
+ * endFieldset
+ *
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function endFieldset() {
+ if ($this->_infieldset) {
+ $this->addElement(array('_elem'=>'closefieldset'));
+ }
+ $this->_infieldset = false;
}
- $this->addElement(array('_elem'=>'openfieldset', '_legend'=>$legend));
- $this->_infieldset = true;
- }
-
- /**
- * endFieldset
- *
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function endFieldset() {
- if ($this->_infieldset) {
- $this->addElement(array('_elem'=>'closefieldset'));
+
+ /**
+ * addHidden
+ *
+ * Adds a name/value pair as a hidden field.
+ * The value of the field (but not the name) will be passed to
+ * formText() before printing.
+ *
+ * @param string $name Field name.
+ * @param string $value Field value. If null, remove a previously added field.
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function addHidden($name, $value) {
+ if (is_null($value))
+ unset($this->_hidden[$name]);
+ else
+ $this->_hidden[$name] = $value;
}
- $this->_infieldset = false;
- }
-
- /**
- * addHidden
- *
- * Adds a name/value pair as a hidden field.
- * The value of the field (but not the name) will be passed to
- * formText() before printing.
- *
- * @param string $name Field name.
- * @param string $value Field value. If null, remove a previously added field.
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function addHidden($name, $value) {
- if (is_null($value))
- unset($this->_hidden[$name]);
- else
- $this->_hidden[$name] = $value;
- }
-
- /**
- * addElement
- *
- * Appends a content element to the form.
- * The element can be either a pseudo-tag or string.
- * If string, it is printed without escaping special chars. *
- *
- * @param string $elem Pseudo-tag or string to add to the form.
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function addElement($elem) {
- $this->_content[] = $elem;
- }
-
- /**
- * insertElement
- *
- * Inserts a content element at a position.
- *
- * @param string $pos 0-based index where the element will be inserted.
- * @param string $elem Pseudo-tag or string to add to the form.
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function insertElement($pos, $elem) {
- array_splice($this->_content, $pos, 0, array($elem));
- }
-
- /**
- * replaceElement
- *
- * Replace with NULL to remove an element.
- *
- * @param int $pos 0-based index the element will be placed at.
- * @param string $elem Pseudo-tag or string to add to the form.
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function replaceElement($pos, $elem) {
- $rep = array();
- if (!is_null($elem)) $rep[] = $elem;
- array_splice($this->_content, $pos, 1, $rep);
- }
-
- /**
- * findElementByType
- *
- * Gets the position of the first of a type of element.
- *
- * @param string $type Element type to look for.
- * @return array pseudo-element if found, false otherwise
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function findElementByType($type) {
- foreach ($this->_content as $pos=>$elem) {
- if (is_array($elem) && $elem['_elem'] == $type)
- return $pos;
+
+ /**
+ * addElement
+ *
+ * Appends a content element to the form.
+ * The element can be either a pseudo-tag or string.
+ * If string, it is printed without escaping special chars. *
+ *
+ * @param string $elem Pseudo-tag or string to add to the form.
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function addElement($elem) {
+ $this->_content[] = $elem;
}
- return false;
- }
-
- /**
- * findElementById
- *
- * Gets the position of the element with an ID attribute.
- *
- * @param string $id ID of the element to find.
- * @return array pseudo-element if found, false otherwise
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function findElementById($id) {
- foreach ($this->_content as $pos=>$elem) {
- if (is_array($elem) && isset($elem['id']) && $elem['id'] == $id)
- return $pos;
+
+ /**
+ * insertElement
+ *
+ * Inserts a content element at a position.
+ *
+ * @param string $pos 0-based index where the element will be inserted.
+ * @param string $elem Pseudo-tag or string to add to the form.
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function insertElement($pos, $elem) {
+ array_splice($this->_content, $pos, 0, array($elem));
}
- return false;
- }
-
- /**
- * findElementByAttribute
- *
- * Gets the position of the first element with a matching attribute value.
- *
- * @param string $name Attribute name.
- * @param string $value Attribute value.
- * @return array pseudo-element if found, false otherwise
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function findElementByAttribute($name, $value) {
- foreach ($this->_content as $pos=>$elem) {
- if (is_array($elem) && isset($elem[$name]) && $elem[$name] == $value)
- return $pos;
+
+ /**
+ * replaceElement
+ *
+ * Replace with NULL to remove an element.
+ *
+ * @param int $pos 0-based index the element will be placed at.
+ * @param string $elem Pseudo-tag or string to add to the form.
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function replaceElement($pos, $elem) {
+ $rep = array();
+ if (!is_null($elem)) $rep[] = $elem;
+ array_splice($this->_content, $pos, 1, $rep);
}
- return false;
- }
-
- /**
- * getElementAt
- *
- * Returns a reference to the element at a position.
- * A position out-of-bounds will return either the
- * first (underflow) or last (overflow) element.
- *
- * @param int $pos 0-based index
- * @return arrayreference pseudo-element
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function &getElementAt($pos) {
- if ($pos < 0) $pos = count($this->_content) + $pos;
- if ($pos < 0) $pos = 0;
- if ($pos >= count($this->_content)) $pos = count($this->_content) - 1;
- return $this->_content[$pos];
- }
-
- /**
- * printForm
- *
- * Output the form.
- * Each element in the form will be passed to a function named
- * 'form_$type'. The function should return the HTML to be printed.
- *
- * @author Tom N Harris <tnharris@whoopdedo.org>
- */
- function printForm() {
- global $lang;
- $this->params['accept-charset'] = $lang['encoding'];
- print '<form ' . html_attbuild($this->params) . '><div class="no">' . NL;
- if (!empty($this->_hidden)) {
- foreach ($this->_hidden as $name=>$value)
- print form_hidden(array('name'=>$name, 'value'=>$value));
+
+ /**
+ * findElementByType
+ *
+ * Gets the position of the first of a type of element.
+ *
+ * @param string $type Element type to look for.
+ * @return array pseudo-element if found, false otherwise
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function findElementByType($type) {
+ foreach ($this->_content as $pos=>$elem) {
+ if (is_array($elem) && $elem['_elem'] == $type)
+ return $pos;
+ }
+ return false;
}
- foreach ($this->_content as $element) {
- if (is_array($element)) {
- $elem_type = $element['_elem'];
- if (function_exists('form_'.$elem_type)) {
- print call_user_func('form_'.$elem_type, $element).NL;
+
+ /**
+ * findElementById
+ *
+ * Gets the position of the element with an ID attribute.
+ *
+ * @param string $id ID of the element to find.
+ * @return array pseudo-element if found, false otherwise
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function findElementById($id) {
+ foreach ($this->_content as $pos=>$elem) {
+ if (is_array($elem) && isset($elem['id']) && $elem['id'] == $id)
+ return $pos;
}
- } else {
- print $element;
- }
+ return false;
+ }
+
+ /**
+ * findElementByAttribute
+ *
+ * Gets the position of the first element with a matching attribute value.
+ *
+ * @param string $name Attribute name.
+ * @param string $value Attribute value.
+ * @return array pseudo-element if found, false otherwise
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function findElementByAttribute($name, $value) {
+ foreach ($this->_content as $pos=>$elem) {
+ if (is_array($elem) && isset($elem[$name]) && $elem[$name] == $value)
+ return $pos;
+ }
+ return false;
+ }
+
+ /**
+ * getElementAt
+ *
+ * Returns a reference to the element at a position.
+ * A position out-of-bounds will return either the
+ * first (underflow) or last (overflow) element.
+ *
+ * @param int $pos 0-based index
+ * @return arrayreference pseudo-element
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function &getElementAt($pos) {
+ if ($pos < 0) $pos = count($this->_content) + $pos;
+ if ($pos < 0) $pos = 0;
+ if ($pos >= count($this->_content)) $pos = count($this->_content) - 1;
+ return $this->_content[$pos];
+ }
+
+ /**
+ * printForm
+ *
+ * Output the form.
+ * Each element in the form will be passed to a function named
+ * 'form_$type'. The function should return the HTML to be printed.
+ *
+ * @author Tom N Harris <tnharris@whoopdedo.org>
+ */
+ function printForm() {
+ global $lang;
+ $this->params['accept-charset'] = $lang['encoding'];
+ print '<form ' . html_attbuild($this->params) . '><div class="no">' . DOKU_LF;
+ if (!empty($this->_hidden)) {
+ foreach ($this->_hidden as $name=>$value)
+ print form_hidden(array('name'=>$name, 'value'=>$value));
+ }
+ foreach ($this->_content as $element) {
+ if (is_array($element)) {
+ $elem_type = $element['_elem'];
+ if (function_exists('form_'.$elem_type)) {
+ print call_user_func('form_'.$elem_type, $element).DOKU_LF;
+ }
+ } else {
+ print $element;
+ }
+ }
+ if ($this->_infieldset) print form_closefieldset().DOKU_LF;
+ print '</div></form>'.DOKU_LF;
}
- if ($this->_infieldset) print form_closefieldset().NL;
- print '</div></form>'.NL;
- }
}
@@ -279,8 +279,8 @@ class Doku_Form {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeTag($tag, $attrs=array()) {
- $elem = array('_elem'=>'tag', '_tag'=>$tag);
- return array_merge($elem, $attrs);
+ $elem = array('_elem'=>'tag', '_tag'=>$tag);
+ return array_merge($elem, $attrs);
}
/**
@@ -295,8 +295,8 @@ function form_makeTag($tag, $attrs=array()) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeOpenTag($tag, $attrs=array()) {
- $elem = array('_elem'=>'opentag', '_tag'=>$tag);
- return array_merge($elem, $attrs);
+ $elem = array('_elem'=>'opentag', '_tag'=>$tag);
+ return array_merge($elem, $attrs);
}
/**
@@ -310,7 +310,7 @@ function form_makeOpenTag($tag, $attrs=array()) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeCloseTag($tag) {
- return array('_elem'=>'closetag', '_tag'=>$tag);
+ return array('_elem'=>'closetag', '_tag'=>$tag);
}
/**
@@ -327,9 +327,9 @@ function form_makeCloseTag($tag) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeWikiText($text, $attrs=array()) {
- $elem = array('_elem'=>'wikitext', '_text'=>$text,
- 'class'=>'edit', 'cols'=>'80', 'rows'=>'10');
- return array_merge($elem, $attrs);
+ $elem = array('_elem'=>'wikitext', '_text'=>$text,
+ 'class'=>'edit', 'cols'=>'80', 'rows'=>'10');
+ return array_merge($elem, $attrs);
}
/**
@@ -347,14 +347,13 @@ function form_makeWikiText($text, $attrs=array()) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeButton($type, $act, $value='', $attrs=array()) {
- if ($value == '') $value = $act;
- //$name = (!empty($act)) ? 'do[$act]' : null;
- $elem = array('_elem'=>'button', 'type'=>$type, '_action'=>$act,
- 'value'=>$value, 'class'=>'button');
- if (!empty($attrs['accesskey']) && empty($attrs['title'])) {
- $attrs['title'] = $value . ' ['.strtoupper($attrs['accesskey']).']';
- }
- return array_merge($elem, $attrs);
+ if ($value == '') $value = $act;
+ $elem = array('_elem'=>'button', 'type'=>$type, '_action'=>$act,
+ 'value'=>$value, 'class'=>'button');
+ if (!empty($attrs['accesskey']) && empty($attrs['title'])) {
+ $attrs['title'] = $value . ' ['.strtoupper($attrs['accesskey']).']';
+ }
+ return array_merge($elem, $attrs);
}
/**
@@ -376,10 +375,10 @@ function form_makeButton($type, $act, $value='', $attrs=array()) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeField($type, $name, $value='', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $elem = array('_elem'=>'field', '_text'=>$label, '_class'=>$class,
- 'type'=>$type, 'id'=>$id, 'name'=>$name, 'value'=>$value);
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ $elem = array('_elem'=>'field', '_text'=>$label, '_class'=>$class,
+ 'type'=>$type, 'id'=>$id, 'name'=>$name, 'value'=>$value);
+ return array_merge($elem, $attrs);
}
/**
@@ -392,10 +391,10 @@ function form_makeField($type, $name, $value='', $label=null, $id='', $class='',
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeFieldRight($type, $name, $value='', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $elem = array('_elem'=>'fieldright', '_text'=>$label, '_class'=>$class,
- 'type'=>$type, 'id'=>$id, 'name'=>$name, 'value'=>$value);
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ $elem = array('_elem'=>'fieldright', '_text'=>$label, '_class'=>$class,
+ 'type'=>$type, 'id'=>$id, 'name'=>$name, 'value'=>$value);
+ return array_merge($elem, $attrs);
}
/**
@@ -407,10 +406,10 @@ function form_makeFieldRight($type, $name, $value='', $label=null, $id='', $clas
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeTextField($name, $value='', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $elem = array('_elem'=>'textfield', '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name, 'value'=>$value, 'class'=>'edit');
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ $elem = array('_elem'=>'textfield', '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name, 'value'=>$value, 'class'=>'edit');
+ return array_merge($elem, $attrs);
}
/**
@@ -423,10 +422,10 @@ function form_makeTextField($name, $value='', $label=null, $id='', $class='', $a
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makePasswordField($name, $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $elem = array('_elem'=>'passwordfield', '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name, 'class'=>'edit');
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ $elem = array('_elem'=>'passwordfield', '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name, 'class'=>'edit');
+ return array_merge($elem, $attrs);
}
/**
@@ -438,10 +437,10 @@ function form_makePasswordField($name, $label=null, $id='', $class='', $attrs=ar
* @author Michael Klier <chi@chimeric.de>
*/
function form_makeFileField($name, $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $elem = array('_elem'=>'filefield', '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name, 'class'=>'edit');
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ $elem = array('_elem'=>'filefield', '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name, 'class'=>'edit');
+ return array_merge($elem, $attrs);
}
/**
@@ -453,11 +452,11 @@ function form_makeFileField($name, $label=null, $id='', $class='', $attrs=array(
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeCheckboxField($name, $value='1', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- if (is_null($value) || $value=='') $value='0';
- $elem = array('_elem'=>'checkboxfield', '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name, 'value'=>$value);
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ if (is_null($value) || $value=='') $value='0';
+ $elem = array('_elem'=>'checkboxfield', '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name, 'value'=>$value);
+ return array_merge($elem, $attrs);
}
/**
@@ -469,11 +468,11 @@ function form_makeCheckboxField($name, $value='1', $label=null, $id='', $class='
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeRadioField($name, $value='1', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- if (is_null($value) || $value=='') $value='0';
- $elem = array('_elem'=>'radiofield', '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name, 'value'=>$value);
- return array_merge($elem, $attrs);
+ if (is_null($label)) $label = $name;
+ if (is_null($value) || $value=='') $value='0';
+ $elem = array('_elem'=>'radiofield', '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name, 'value'=>$value);
+ return array_merge($elem, $attrs);
}
/**
@@ -489,27 +488,27 @@ function form_makeRadioField($name, $value='1', $label=null, $id='', $class='',
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeMenuField($name, $values, $selected='', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $options = array();
- reset($values);
- // FIXME: php doesn't know the difference between a string and an integer
- if (is_string(key($values))) {
- foreach ($values as $val=>$text) {
- $options[] = array($val,$text, (!is_null($selected) && $val==$selected));
- }
- } else {
- if (is_integer($selected)) $selected = $values[$selected];
- foreach ($values as $val) {
- if (is_array($val))
- @list($val,$text) = $val;
- else
- $text = null;
- $options[] = array($val,$text,$val===$selected);
+ if (is_null($label)) $label = $name;
+ $options = array();
+ reset($values);
+ // FIXME: php doesn't know the difference between a string and an integer
+ if (is_string(key($values))) {
+ foreach ($values as $val=>$text) {
+ $options[] = array($val,$text, (!is_null($selected) && $val==$selected));
+ }
+ } else {
+ if (is_integer($selected)) $selected = $values[$selected];
+ foreach ($values as $val) {
+ if (is_array($val))
+ @list($val,$text) = $val;
+ else
+ $text = null;
+ $options[] = array($val,$text,$val===$selected);
+ }
}
- }
- $elem = array('_elem'=>'menufield', '_options'=>$options, '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name);
- return array_merge($elem, $attrs);
+ $elem = array('_elem'=>'menufield', '_options'=>$options, '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name);
+ return array_merge($elem, $attrs);
}
/**
@@ -523,30 +522,30 @@ function form_makeMenuField($name, $values, $selected='', $label=null, $id='', $
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_makeListboxField($name, $values, $selected='', $label=null, $id='', $class='', $attrs=array()) {
- if (is_null($label)) $label = $name;
- $options = array();
- reset($values);
- if (is_null($selected) || $selected == '')
- $selected = array();
- elseif (!is_array($selected))
- $selected = array($selected);
- // FIXME: php doesn't know the difference between a string and an integer
- if (is_string(key($values))) {
- foreach ($values as $val=>$text) {
- $options[] = array($val,$text,in_array($val,$selected));
- }
- } else {
- foreach ($values as $val) {
- if (is_array($val))
- @list($val,$text) = $val;
- else
- $text = null;
- $options[] = array($val,$text,in_array($val,$selected));
+ if (is_null($label)) $label = $name;
+ $options = array();
+ reset($values);
+ if (is_null($selected) || $selected == '')
+ $selected = array();
+ elseif (!is_array($selected))
+ $selected = array($selected);
+ // FIXME: php doesn't know the difference between a string and an integer
+ if (is_string(key($values))) {
+ foreach ($values as $val=>$text) {
+ $options[] = array($val,$text,in_array($val,$selected));
+ }
+ } else {
+ foreach ($values as $val) {
+ if (is_array($val))
+ @list($val,$text) = $val;
+ else
+ $text = null;
+ $options[] = array($val,$text,in_array($val,$selected));
+ }
}
- }
- $elem = array('_elem'=>'listboxfield', '_options'=>$options, '_text'=>$label, '_class'=>$class,
- 'id'=>$id, 'name'=>$name);
- return array_merge($elem, $attrs);
+ $elem = array('_elem'=>'listboxfield', '_options'=>$options, '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name);
+ return array_merge($elem, $attrs);
}
/**
@@ -559,7 +558,7 @@ function form_makeListboxField($name, $values, $selected='', $label=null, $id=''
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_tag($attrs) {
- return '<'.$attrs['_tag'].' '.buildAttributes($attrs).'/>';
+ return '<'.$attrs['_tag'].' '.buildAttributes($attrs).'/>';
}
/**
@@ -572,7 +571,7 @@ function form_tag($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_opentag($attrs) {
- return '<'.$attrs['_tag'].' '.buildAttributes($attrs,true).'>';
+ return '<'.$attrs['_tag'].' '.buildAttributes($attrs,true).'>';
}
/**
@@ -585,7 +584,7 @@ function form_opentag($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_closetag($attrs) {
- return '</'.$attrs['_tag'].'>';
+ return '</'.$attrs['_tag'].'>';
}
/**
@@ -598,9 +597,9 @@ function form_closetag($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_openfieldset($attrs) {
- $s = '<fieldset '.buildAttributes($attrs,true).'>';
- if (!is_null($attrs['_legend'])) $s .= '<legend>'.$attrs['_legend'].'</legend>';
- return $s;
+ $s = '<fieldset '.buildAttributes($attrs,true).'>';
+ if (!is_null($attrs['_legend'])) $s .= '<legend>'.$attrs['_legend'].'</legend>';
+ return $s;
}
/**
@@ -612,7 +611,7 @@ function form_openfieldset($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_closefieldset() {
- return '</fieldset>';
+ return '</fieldset>';
}
/**
@@ -625,7 +624,7 @@ function form_closefieldset() {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_hidden($attrs) {
- return '<input type="hidden" name="'.$attrs['name'].'" value="'.formText($attrs['value']).'" />';
+ return '<input type="hidden" name="'.$attrs['name'].'" value="'.formText($attrs['value']).'" />';
}
/**
@@ -638,13 +637,13 @@ function form_hidden($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_wikitext($attrs) {
- // mandatory attributes
- unset($attrs['name']);
- unset($attrs['id']);
- return '<textarea name="wikitext" id="wiki__text" '
- .buildAttributes($attrs,true).'>'.NL
- .formText($attrs['_text'])
- .'</textarea>';
+ // mandatory attributes
+ unset($attrs['name']);
+ unset($attrs['id']);
+ return '<textarea name="wikitext" id="wiki__text" '
+ .buildAttributes($attrs,true).'>'.DOKU_LF
+ .formText($attrs['_text'])
+ .'</textarea>';
}
/**
@@ -657,8 +656,8 @@ function form_wikitext($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_button($attrs) {
- $p = (!empty($attrs['_action'])) ? 'name="do['.$attrs['_action'].']" ' : '';
- return '<input '.$p.buildAttributes($attrs,true).'/>';
+ $p = (!empty($attrs['_action'])) ? 'name="do['.$attrs['_action'].']" ' : '';
+ return '<input '.$p.buildAttributes($attrs,true).'/>';
}
/**
@@ -672,14 +671,14 @@ function form_button($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_field($attrs) {
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><span>'.$attrs['_text'].'</span>';
- $s .= ' <input '.buildAttributes($attrs,true).'/></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span>';
+ $s .= ' <input '.buildAttributes($attrs,true).'/></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -693,14 +692,14 @@ function form_field($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_fieldright($attrs) {
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><input '.buildAttributes($attrs,true).'/>';
- $s .= ' <span>'.$attrs['_text'].'</span></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><input '.buildAttributes($attrs,true).'/>';
+ $s .= ' <span>'.$attrs['_text'].'</span></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -714,16 +713,16 @@ function form_fieldright($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_textfield($attrs) {
- // mandatory attributes
- unset($attrs['type']);
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><span>'.$attrs['_text'].'</span> ';
- $s .= '<input type="text" '.buildAttributes($attrs,true).'/></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ // mandatory attributes
+ unset($attrs['type']);
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span> ';
+ $s .= '<input type="text" '.buildAttributes($attrs,true).'/></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -737,16 +736,16 @@ function form_textfield($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_passwordfield($attrs) {
- // mandatory attributes
- unset($attrs['type']);
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><span>'.$attrs['_text'].'</span> ';
- $s .= '<input type="password" '.buildAttributes($attrs,true).'/></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ // mandatory attributes
+ unset($attrs['type']);
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span> ';
+ $s .= '<input type="password" '.buildAttributes($attrs,true).'/></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -762,17 +761,17 @@ function form_passwordfield($attrs) {
* @author Michael Klier <chi@chimeric.de>
*/
function form_filefield($attrs) {
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><span>'.$attrs['_text'].'</span> ';
- $s .= '<input type="file" '.buildAttributes($attrs,true);
- if (!empty($attrs['_maxlength'])) $s .= ' maxlength="'.$attrs['_maxlength'].'"';
- if (!empty($attrs['_accept'])) $s .= ' accept="'.$attrs['_accept'].'"';
- $s .= '/></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span> ';
+ $s .= '<input type="file" '.buildAttributes($attrs,true);
+ if (!empty($attrs['_maxlength'])) $s .= ' maxlength="'.$attrs['_maxlength'].'"';
+ if (!empty($attrs['_accept'])) $s .= ' accept="'.$attrs['_accept'].'"';
+ $s .= '/></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -786,16 +785,16 @@ function form_filefield($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_checkboxfield($attrs) {
- // mandatory attributes
- unset($attrs['type']);
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><input type="checkbox" '.buildAttributes($attrs,true).'/>';
- $s .= ' <span>'.$attrs['_text'].'</span></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ // mandatory attributes
+ unset($attrs['type']);
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><input type="checkbox" '.buildAttributes($attrs,true).'/>';
+ $s .= ' <span>'.$attrs['_text'].'</span></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -809,16 +808,16 @@ function form_checkboxfield($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_radiofield($attrs) {
- // mandatory attributes
- unset($attrs['type']);
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><input type="radio" '.buildAttributes($attrs,true).'/>';
- $s .= ' <span>'.$attrs['_text'].'</span></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ // mandatory attributes
+ unset($attrs['type']);
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><input type="radio" '.buildAttributes($attrs,true).'/>';
+ $s .= ' <span>'.$attrs['_text'].'</span></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -835,34 +834,34 @@ function form_radiofield($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_menufield($attrs) {
- $attrs['size'] = '1';
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><span>'.$attrs['_text'].'</span>';
- $s .= ' <select '.buildAttributes($attrs,true).'>'.NL;
- if (!empty($attrs['_options'])) {
- $selected = false;
- for($n=0;$n<count($attrs['_options']);$n++){
- @list($value,$text,$select) = $attrs['_options'][$n];
- $p = '';
- if (!is_null($text))
- $p .= ' value="'.formText($value).'"';
- else
- $text = $value;
- if (!empty($select) && !$selected) {
- $p .= ' selected="selected"';
- $selected = true;
- }
- $s .= '<option'.$p.'>'.formText($text).'</option>';
+ $attrs['size'] = '1';
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span>';
+ $s .= ' <select '.buildAttributes($attrs,true).'>'.DOKU_LF;
+ if (!empty($attrs['_options'])) {
+ $selected = false;
+ for($n=0;$n<count($attrs['_options']);$n++){
+ @list($value,$text,$select) = $attrs['_options'][$n];
+ $p = '';
+ if (!is_null($text))
+ $p .= ' value="'.formText($value).'"';
+ else
+ $text = $value;
+ if (!empty($select) && !$selected) {
+ $p .= ' selected="selected"';
+ $selected = true;
+ }
+ $s .= '<option'.$p.'>'.formText($text).'</option>';
+ }
+ } else {
+ $s .= '<option></option>';
}
- } else {
- $s .= '<option></option>';
- }
- $s .= NL.'</select></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ $s .= DOKU_LF.'</select></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}
/**
@@ -878,27 +877,27 @@ function form_menufield($attrs) {
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
function form_listboxfield($attrs) {
- $s = '<label';
- if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
- if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
- $s .= '><span>'.$attrs['_text'].'</span> ';
- $s .= '<select '.buildAttributes($attrs,true).'>'.NL;
- if (!empty($attrs['_options'])) {
- foreach ($attrs['_options'] as $opt) {
- @list($value,$text,$select) = $opt;
- $p = '';
- if (!is_null($text))
- $p .= ' value="'.formText($value).'"';
- else
- $text = $value;
- if (!empty($select)) $p .= ' selected="selected"';
- $s .= '<option'.$p.'>'.formText($text).'</option>';
+ $s = '<label';
+ if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span> ';
+ $s .= '<select '.buildAttributes($attrs,true).'>'.DOKU_LF;
+ if (!empty($attrs['_options'])) {
+ foreach ($attrs['_options'] as $opt) {
+ @list($value,$text,$select) = $opt;
+ $p = '';
+ if (!is_null($text))
+ $p .= ' value="'.formText($value).'"';
+ else
+ $text = $value;
+ if (!empty($select)) $p .= ' selected="selected"';
+ $s .= '<option'.$p.'>'.formText($text).'</option>';
+ }
+ } else {
+ $s .= '<option></option>';
}
- } else {
- $s .= '<option></option>';
- }
- $s .= NL.'</select></label>';
- if (preg_match('/(^| )block($| )/', $attrs['_class']))
- $s .= '<br />';
- return $s;
+ $s .= DOKU_LF.'</select></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
}