attributes([
+ 'id' => $name,
+ 'class' => 'carousel slide',
+ 'data-ride' => 'carousel',
+ 'data-bs-ride' => 'carousel',
+ 'data-interval' => isset($options['interval']) ? $options['interval'] : null,
+ 'data-wrap' => isset($options['wrap']) ? $options['wrap'] : null,
+ 'data-pause' => isset($options['pause']) ? $options['pause'] : null,
+ ]) . '>';
if($indicate && (count($array) > 1))
{
@@ -759,21 +760,27 @@ class e_form
*/
public function text($name, $value = '', $maxlength = 80, $options= null)
{
- if(is_string($options))
+ if (is_string($options))
{
- parse_str($options,$options);
+ parse_str($options, $options);
}
- if(!vartrue($options['class']))
+ $attributes = [
+ 'type' => varset($options['type']) === 'email' ? 'email' : 'text',
+ 'name' => $name,
+ 'value' => $value,
+ ];
+
+ if (!vartrue($options['class']))
{
$options['class'] = 'tbox';
}
- if(deftrue('BOOTSTRAP'))
+ if (deftrue('BOOTSTRAP'))
{
$options['class'] .= ' form-control';
}
-
+
/*
if(!vartrue($options['class']))
{
@@ -828,27 +835,25 @@ class e_form
}
// TODO: remove typeahead.
- if(!empty($options['typeahead']) && vartrue($options['typeahead']) === 'users')
+ if (!empty($options['typeahead']) && vartrue($options['typeahead']) === 'users')
{
- $options['data-source'] = e_BASE. 'user.php';
+ $options['data-source'] = e_BASE . 'user.php';
$options['class'] .= ' e-typeahead';
}
-
- if(!empty($options['size']) && !is_numeric($options['size']))
+
+ if (!empty($options['size']) && !is_numeric($options['size']))
{
- $options['class'] .= ' input-' .$options['size'];
+ $options['class'] .= ' input-' . $options['size'];
unset($options['size']); // don't include in html 'size='.
}
-
- $mlength = !empty($maxlength) ? 'maxlength=' .$maxlength : '';
-
- $type = varset($options['type']) === 'email' ? 'email' : 'text'; // used by $this->email();
-
+
+ $attributes['maxlength'] = !empty($maxlength) ? $maxlength : null;
+
$options = $this->format_options('text', $name, $options);
-
-
+
+
//never allow id in format name-value for text fields
- return "
get_attributes($options, $name). ' />';
+ return "
attributes($attributes) . " " . $this->get_attributes($options, $name) . ' />';
}
@@ -870,44 +875,50 @@ class e_form
*/
public function number($name, $value=0, $maxlength = 200, $options = null)
{
- if(is_string($options))
+ $attributes = [
+ 'type' => 'number',
+ 'name' => $name,
+ 'value' => $value,
+ ];
+
+ if (is_string($options))
{
parse_str($options, $options);
}
- if(!empty($options['maxlength']))
+ if (!empty($options['maxlength']))
{
- $maxlength = $options['maxlength'];
+ $maxlength = $options['maxlength'];
}
unset($options['maxlength']);
- if(empty($options['size']))
+ if (empty($options['size']))
{
- $options['size'] = 15;
+ $options['size'] = 15;
}
- if(empty($options['class']))
+ if (empty($options['class']))
{
- $options['class'] = 'tbox number e-spinner input-small ';
+ $options['class'] = 'tbox number e-spinner input-small ';
}
-
- if(!empty($options['size']))
+
+ if (!empty($options['size']))
{
- $options['class'] .= ' input-'.$options['size'];
+ $options['class'] .= ' input-' . $options['size'];
unset($options['size']);
}
$options['class'] .= ' form-control';
- $options['type'] ='number';
-
+ $options['type'] = 'number';
+
// Not used anymore
//$mlength = vartrue($maxlength) ? "maxlength=".$maxlength : "";
// Always define the min. parameter
// defaults to 0
// setting the min option to a negative value allows negative inputs
- $min = " min='".vartrue($options['min'], '0')."'";
- $max = isset($options['max']) ? " max='".$options['max']."'" : '';
+ $attributes['min'] = vartrue($options['min'], '0');
+ $attributes['max'] = isset($options['max']) ? $options['max'] : null;
if (empty($options['pattern']))
@@ -934,11 +945,11 @@ class e_form
// 0 = 1 > allows only integers, no float values
if ((int) $options['decimals'] <= 0)
{
- $step = "step='1'";
+ $attributes['step'] = "1";
}
else
{
- $step = "step='0." . str_pad(1, (int) $options['decimals'], 0, STR_PAD_LEFT) . "'";
+ $attributes['step'] = "0." . str_pad(1, (int) $options['decimals'], 0, STR_PAD_LEFT);
}
}
else
@@ -946,7 +957,7 @@ class e_form
// decimal option not defined
// check for step option (1, 0.1, 0.01, and so on)
// or set default step 1 (integers only)
- $step = "step='" . vartrue($options['step'], '1') . "'";
+ $attributes['step'] = vartrue($options['step'], '1');
}
}
@@ -954,13 +965,12 @@ class e_form
$options = $this->format_options('text', $name, $options);
//never allow id in format name-value for text fields
- if(THEME_LEGACY === false)
+ if (THEME_LEGACY === false)
{
- // return "
get_attributes($options, $name)." />";
- return "
get_attributes($options, $name). ' />';
+ return "
attributes($attributes) . " " . $this->get_attributes($options, $name) . ' />';
}
-
- return $this->text($name, $value, $maxlength, $options);
+
+ return $this->text($name, $value, $maxlength, $options);
}
@@ -1028,96 +1038,103 @@ class e_form
*/
public function mediaUrl($category = '', $label = '', $tagid='', $extras=null)
{
- if(is_string($extras))
+ if (is_string($extras))
{
- parse_str($extras,$extras);
+ parse_str($extras, $extras);
}
$category = str_replace('+', '^', $category); // Bc Fix.
- $cat = ($category) ? '&for='.urlencode($category) : '';
- $mode = vartrue($extras['mode'],'main');
- $action = vartrue($extras['action'],'dialog');
+ $cat = ($category) ? '&for=' . urlencode($category) : '';
+ $mode = vartrue($extras['mode'], 'main');
+ $action = vartrue($extras['action'], 'dialog');
-
- if(empty($label))
+ if (empty($label))
{
- $label = ' Upload an image or file';
+ $label = ' Upload an image or file';
}
// TODO - option to choose which tabs to display by default.
- $url = e_ADMIN_ABS."image.php?mode={$mode}&action={$action}".$cat;
+ $url = e_ADMIN_ABS . "image.php?mode={$mode}&action={$action}" . $cat;
if(!empty($tagid))
{
- $url .= '&tagid='.$tagid;
+ $url .= '&tagid=' . $tagid;
}
if(!empty($extras['bbcode']))
{
- $url .= '&bbcode='.$extras['bbcode'];
+ $url .= '&bbcode=' . $extras['bbcode'];
}
- $url .= '&iframe=1';
+ $url .= '&iframe=1';
if(!empty($extras['w']))
{
- $url .= '&w=' .$extras['w'];
+ $url .= '&w=' . $extras['w'];
}
if(!empty($extras['image']))
{
- $url .= '&image=1';
+ $url .= '&image=1';
}
if(!empty($extras['glyphs']) || !empty($extras['glyph']))
{
- $url .= '&glyph=1';
+ $url .= '&glyph=1';
}
if(!empty($extras['icons']) || !empty($extras['icon']))
{
- $url .= '&icon=1';
+ $url .= '&icon=1';
}
if(!empty($extras['youtube']))
{
- $url .= '&youtube=1';
+ $url .= '&youtube=1';
}
if(!empty($extras['video']))
{
- $url .= ($extras['video'] == 2) ? '&video=2' : '&video=1';
+ $url .= ($extras['video'] == 2) ? '&video=2' : '&video=1';
}
if(!empty($extras['audio']))
{
- $url .= '&audio=1';
+ $url .= '&audio=1';
}
if(!empty($extras['path']) && $extras['path'] === 'plugin')
{
- $url .= '&path=' .deftrue('e_CURRENT_PLUGIN');
+ $url .= '&path=' . deftrue('e_CURRENT_PLUGIN');
}
if(E107_DBG_BASIC)
{
- $title = 'Media Manager : ' .$category;
+ $title = 'Media Manager : ' . $category;
}
else
{
$title = LAN_EDIT;
}
- $class = !empty($extras['class']) ? $extras['class']. ' ' : '';
+ $class = !empty($extras['class']) ? $extras['class'] . ' ' : '';
$title = !empty($extras['title']) ? $extras['title'] : $title;
- $ret = "
".$label. ' '; // using bootstrap.
+ $ret = "
attributes([
+ 'title' => $title,
+ 'class' => "{$class}e-modal",
+ 'data-modal-submit' => 'true',
+ 'data-modal-caption' => LAN_EFORM_007,
+ 'data-cache' => 'false',
+ 'data-target' => '#uiModal',
+ 'href' => $url,
+ ]) . ">" . $label . ' '; // using bootstrap.
- if(!e107::getRegistry('core/form/mediaurl'))
+ if (!e107::getRegistry('core/form/mediaurl'))
{
e107::setRegistry('core/form/mediaurl', true);
}
@@ -1427,24 +1444,32 @@ class e_form
$editIcon = $this->mediaUrl($cat, '
', $name_id,$parms);
}
- $ret .= "
\n";
- $ret .= "
";
- $ret .= "
";
+ $ret .= "
attributes([
+ 'type' => 'hidden',
+ 'name' => $name,
+ 'id' => $name_id,
+ 'value' => $default]) . " />";
+ $ret .= "
attributes([
+ 'type' => 'hidden',
+ 'name' => "mediameta_$name",
+ 'id' => $meta_id,
+ ]) . " />";
- if(empty($dropzone))
+ if (empty($dropzone))
{
return $ret;
}
- if(!isset($parms['label']))
+ if (!isset($parms['label']))
{
$parms['label'] = defset('LAN_UI_DROPZONE_DROP_FILES', 'Drop files here to upload');
}
@@ -1573,11 +1598,17 @@ class e_form
if(isset($sc_parameters['data']) && $sc_parameters['data'] === 'array')
{
- // Do not use $this->hidden() method - as it will break 'id' value.
- $ret .= "
";
- $ret .= "
";
- $ret .= "
";
-
+ // Do not use $this->hidden() method - as it will break 'id' value.
+ foreach (['path', 'name', 'id'] as $key)
+ {
+ $ret .= "
attributes([
+ 'type' => 'hidden',
+ 'name' => "{$name}[{$key}]",
+ 'id' => $this->name2id("{$name}[{$key}]"),
+ 'value' => varset($default[$key]),
+ ]) . " />";
+ }
+
$default = $default['path'];
}
else
@@ -2023,17 +2054,19 @@ class e_form
*/
public function file($name, $options = array())
{
- if(deftrue('e_ADMIN_AREA') && empty($options['class']))
+ if (deftrue('e_ADMIN_AREA') && empty($options['class']))
{
- $options = array('class'=>'tbox well file');
+ $options = array('class' => 'tbox well file');
}
$options = $this->format_options('file', $name, $options);
-
//never allow id in format name-value for text fields
- return "
get_attributes($options, $name). ' />';
+ return "
attributes([
+ 'type' => 'file',
+ 'name' => $name,
+ ]) . $this->get_attributes($options, $name) . ' />';
}
/**
@@ -2104,24 +2137,29 @@ class e_form
if(!empty($options['size']) && !is_numeric($options['size']))
{
- $options['class'] .= ' input-' .$options['size'];
+ $options['class'] .= ' input-' . $options['size'];
unset($options['size']); // don't include in html 'size='.
}
-
+
$type = empty($options['nomask']) ? 'password' : 'text';
-
+
$options = $this->format_options('text', $name, $options);
-
- //never allow id in format name-value for text fields
- $text = "
get_attributes($options, $name). ' />';
- if(empty($gen) && empty($addon))
+ //never allow id in format name-value for text fields
+ $text = "
attributes([
+ 'type' => $type,
+ 'name' => $name,
+ 'value' => $value,
+ 'maxlength' => $maxlength,
+ ]) . $this->get_attributes($options, $name) . ' />';
+
+ if (empty($gen) && empty($addon))
{
- return $text;
+ return $text;
}
- return "
".$text.$gen. ' ' .vartrue($addon);
+ return "
" . $text . $gen . ' ' . vartrue($addon);
}
@@ -2145,12 +2183,15 @@ class e_form
if(defined('BOOTSTRAP') && BOOTSTRAP === 4)
{
- return '';
+ return '
attributes([
+ 'class' => 'pager-button btn btn-primary',
+ 'href' => $url,
+ ]) . '>' . $total . ' ';
}
if(!is_numeric($total))
{
- return '';
+ return '';
}
@@ -2283,16 +2324,21 @@ class e_form
$options['class'] .= ' form-control input-' .$options['size'];
unset($options['size']); // don't include in html 'size='.
}
- elseif(empty($options['noresize']))
+ elseif (empty($options['noresize']))
{
- $options['class'] = (isset($options['class']) && $options['class']) ? $options['class'].' e-autoheight' : 'tbox col-md-7 span7 e-autoheight form-control';
+ $options['class'] = (isset($options['class']) && $options['class']) ? $options['class'] . ' e-autoheight' : 'tbox col-md-7 span7 e-autoheight form-control';
}
$options = $this->format_options('textarea', $name, $options);
-
+
// print_a($options);
//never allow id in format name-value for text fields
- return "
".($counter !== false ? $this->hidden('__'.$name.'autoheight_opt', $counter) : '');
+ return "
" .
+ ($counter !== false ? $this->hidden('__' . $name . 'autoheight_opt', $counter) : '');
}
/**
@@ -2569,23 +2615,27 @@ class e_form
if(!isset($options['class']))
{
- $options['class'] = '';
+ $options['class'] = '';
}
- $options['class'] .= ' form-check-input';
+ $options['class'] .= ' form-check-input';
- if($snippet = $this->getSnippet('checkbox'))
+ if ($snippet = $this->getSnippet('checkbox'))
{
return $this->renderSnippet($snippet, $options, $name, $value);
}
- $pre = (!empty($options['label'])) ? "
" : ''; // Bootstrap compatible markup
- $post = (!empty($options['label'])) ? '' .$options['label']. ' ' : '';
+ $pre = (!empty($options['label'])) ? "
" : ''; // Bootstrap compatible markup
+ $post = (!empty($options['label'])) ? '' . $options['label'] . ' ' : '';
unset($options['label']); // not to be used as attribute;
-
- return $pre. "
get_attributes($options, $name, $value). ' />' .$post;
-
+
+ return $pre . "
attributes([
+ 'type' => 'checkbox',
+ 'name' => $name,
+ 'value' => $value,
+ ]) . $this->get_attributes($options, $name, $value) . ' />' . $post;
+
}
@@ -2764,37 +2814,43 @@ class e_form
unset($options['id']);
}
- if($snippet = $this->getSnippet('radio'))
+ if ($snippet = $this->getSnippet('radio'))
{
$options['label'] = $labelFound;
+
return $this->renderSnippet($snippet, $options, $name, $value);
}
// $options['class'] = 'inline';
$text = '';
- // return print_a($options,true);
- if($labelFound) // Bootstrap compatible markup
+ // return print_a($options,true);
+ if ($labelFound) // Bootstrap compatible markup
{
$defaultClass = (deftrue('BOOTSTRAP')) ? 'radio-inline form-check-inline' : 'radio inline';
$dis = (!empty($options['disabled'])) ? ' disabled' : '';
$text .= "
";
-
+
}
-
-
- $text .= " get_attributes($options, $name, $value). ' />';
-
- if(!empty($options['help']))
+
+
+ $text .= " attributes([
+ 'class' => 'form-check-input',
+ 'type' => 'radio',
+ 'name' => $name,
+ 'value' => $value,
+ ]) . $this->get_attributes($options, $name, $value) . ' />';
+
+ if (!empty($options['help']))
{
- $text .= "".$options['help']. '
';
+ $text .= "" . $options['help'] . '
';
}
-
- if($labelFound)
+
+ if ($labelFound)
{
- $text .= ' ' .$labelFound. ' ';
+ $text .= '
' . $labelFound . ' ';
}
-
+
return $text;
}
@@ -3375,7 +3431,7 @@ var_dump($select_options);*/
parse_str($options, $options);
}
- if($value === false)
+ if ($value === false)
{
$value = '';
}
@@ -3384,8 +3440,9 @@ var_dump($select_options);*/
$options['selected'] = $selected; //comes as separate argument just for convenience
-
- return "
get_attributes($options). '>' .defset($option_title, $option_title). ' ';
+ return "
attributes(['value' => $value]) . $this->get_attributes($options) . '>'
+ . defset($option_title, $option_title) .
+ ' ';
}
@@ -3499,7 +3556,11 @@ var_dump($select_options);*/
{
$options = $this->format_options('hidden', $name, $options);
- return "
get_attributes($options, $name, $value). ' />';
+ return "
attributes([
+ 'type' => 'hidden',
+ 'name' => $name,
+ 'value' => $value,
+ ]) . $this->get_attributes($options, $name, $value) . ' />';
}
/**
@@ -3508,13 +3569,22 @@ var_dump($select_options);*/
*/
public function token()
{
- return "
";
+ return "
attributes([
+ 'type' => 'hidden',
+ 'name' => 'e-token',
+ 'value' => defset('e_TOKEN'),
+ ]) . " />";
}
public function submit($name, $value, $options = array())
{
$options = $this->format_options('submit', $name, $options);
- return "
get_attributes($options, $name, $value). ' />';
+
+ return "
attributes([
+ 'type' => 'submit',
+ 'name' => $name,
+ 'value' => $value,
+ ]) . $this->get_attributes($options, $name, $value) . ' />';
}
public function submit_image($name, $value, $image, $title='', $options = array())
@@ -3549,19 +3619,24 @@ var_dump($select_options);*/
case 'view':
$icon = $tp->toIcon('e-view-32');
$options['class'] = $options['class'] === 'action' ? 'btn btn-default btn-secondary action view' : $options['class'];
- break;
+ break;
}
$options['title'] = $title;//shorthand
- if(!empty($customIcon))
+ if (!empty($customIcon))
{
$icon = $customIcon;
}
-
- return "
get_attributes($options, $name, $value). ' >' .$icon. ' ';
-
+ return "
attributes([
+ 'type' => 'submit',
+ 'name' => $name,
+ 'data-placement' => 'left',
+ 'value' => $value,
+ ]) . $this->get_attributes($options, $name, $value) . ' >' . $icon . ' ';
+
+
}
/**
@@ -3691,7 +3766,11 @@ var_dump($select_options);*/
{
if(deftrue('BOOTSTRAP') && getperms($perms))
{
- return "
".e107::getParser()->toGlyph('fa-edit'). ' ';
+ return "
attributes([
+ 'target' => '_blank',
+ 'title' => LAN_EDIT,
+ 'href' => $url,
+ ]) . ">" . e107::getParser()->toGlyph('fa-edit') . ' ';
}
return '';
@@ -3714,19 +3793,24 @@ var_dump($select_options);*/
{
$action = (string) $action;
$btype = 'submit';
- if(strpos($action, 'action') === 0 || $action === 'button')
+ if (strpos($action, 'action') === 0 || $action === 'button')
{
$btype = 'button';
}
- if(isset($options['loading']) && ($options['loading'] == false))
+ $attributes = [
+ 'type' => $btype,
+ 'name' => $name,
+ 'value' => $value,
+ ];
+
+ if (isset($options['loading']) && ($options['loading'] == false))
{
unset($options['loading']);
- $include = '';
}
else
{
- $include = ($this->_fontawesome) ? "data-loading-icon='fa-spinner'" : ''; // data-disable breaks db.php charset Fix.
+ $attributes = ['data-loading-icon' => $this->_fontawesome ? 'fa-spinner' : null] + $attributes; // data-disable breaks db.php charset Fix.
}
$confirmation = LAN_JSCONFIRM;
@@ -3782,7 +3866,7 @@ var_dump($select_options);*/
break;
}
- return '
get_attributes($options, $name) . ">{$label} ";
+ return '
attributes($attributes) . $this->get_attributes($options, $name) . ">{$label} ";
}
/**
@@ -3901,6 +3985,30 @@ var_dump($select_options);*/
$this->_tabindex_counter = $reset;
}
+ /**
+ * Build a series of HTML attributes from the provided array
+ *
+ * @param array $attributes Key-value pairs of HTML attributes. The value must not be HTML-encoded. If the value is
+ * boolean true, the value will be set to the key (e.g. `['required' => true]` becomes
+ * "required='required'").
+ * @return string The HTML attributes to concatenate inside an HTML tag
+ */
+ private function attributes($attributes)
+ {
+ $stringifiedAttributes = [];
+
+ foreach ($attributes as $key => $value)
+ {
+ if ($value === true) $value = $key;
+ if (!empty($value) || is_numeric($value))
+ {
+ $stringifiedAttributes[] = $key . "='" . htmlspecialchars($value, ENT_QUOTES) . "'";
+ }
+ }
+
+ return count($stringifiedAttributes) > 0 ? " ".implode(" ", $stringifiedAttributes) : "";
+ }
+
public function get_attributes($options, $name = '', $value = '')
{
$ret = '';
@@ -3909,7 +4017,7 @@ var_dump($select_options);*/
{
if ($option !== 'other')
{
- $optval = htmlspecialchars(trim((string) $optval), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
+ $optval = html_entity_decode(trim((string) $optval));
}
switch ($option)
{
@@ -3919,30 +4027,30 @@ var_dump($select_options);*/
break;
case 'class':
- if(!empty($optval))
- {
- $ret .= " class='{$optval}'";
- }
- break;
-
case 'size':
- if($optval)
- {
- $ret .= " size='{$optval}'";
- }
- break;
-
case 'title':
- if($optval)
- {
- $ret .= " title='{$optval}'";
- }
+ case 'label':
+ case 'maxlength':
+ case 'wrap':
+ case 'autocomplete':
+ case 'pattern':
+ $ret .= $this->attributes([$option => $optval]);
break;
- case 'label':
- if($optval)
- {
- $ret .= " label='{$optval}'";
+ case 'readonly':
+ case 'multiple':
+ case 'selected':
+ case 'checked':
+ case 'disabled':
+ case 'required':
+ case 'autofocus':
+ $ret .= $this->attributes([$option => (bool) $optval]);
+ break;
+
+ case 'placeholder':
+ if($optval) {
+ $optval = deftrue($optval, $optval);
+ $ret .= $this->attributes([$option => $optval]);
}
break;
@@ -3958,91 +4066,7 @@ var_dump($select_options);*/
else
{
++$this->_tabindex_counter;
- $ret .= " tabindex='".$this->_tabindex_counter."'";
- }
- break;
-
- case 'readonly':
- if($optval)
- {
- $ret .= " readonly='readonly'";
- }
- break;
-
- case 'multiple':
- if($optval)
- {
- $ret .= " multiple='multiple'";
- }
- break;
-
- case 'selected':
- if($optval)
- {
- $ret .= " selected='selected'";
- }
- break;
-
- case 'maxlength':
- if($optval)
- {
- $ret .= " maxlength='{$optval}'";
- }
- break;
-
- case 'checked':
- if($optval)
- {
- $ret .= " checked='checked'";
- }
- break;
-
- case 'disabled':
- if($optval)
- {
- $ret .= " disabled='disabled'";
- }
- break;
-
- case 'required':
- if($optval)
- {
- $ret .= " required='required'";
- }
- break;
-
- case 'autofocus':
- if($optval)
- {
- $ret .= " autofocus='autofocus'";
- }
- break;
-
- case 'placeholder':
- if($optval) {
- $optval = deftrue($optval, $optval);
- $ret .= " placeholder='{$optval}'";
- }
- break;
-
- case 'wrap':
- if($optval)
- {
- $ret .= " wrap='{$optval}'";
- }
- break;
-
- case 'autocomplete':
- if($optval)
- {
- $ret .= " autocomplete='{$optval}'";
- }
- break;
-
- case 'pattern':
- if($optval)
- {
- $ret .= " pattern='{$optval}'";
+ $ret .= $this->attributes([$option => $this->_tabindex_counter]);
}
break;
@@ -4056,7 +4080,7 @@ var_dump($select_options);*/
default:
if(strpos($option,'data-') === 0)
{
- $ret .= ' ' .$option."='{$optval}'";
+ $ret .= $this->attributes([$option => $optval]);
}
break;
}
@@ -4119,21 +4143,20 @@ var_dump($select_options);*/
return $ret;
}
-
if (empty($id_value))
{
- $ret = " {$return_attribute}='{$name}" . ($value ? "-{$value}" : '') . "'";
+ $ret = "{$name}" . ($value ? "-{$value}" : '');
}
elseif (is_numeric($id_value) && $name) // also useful when name is e.g. name='my_name[some_id]'
{
- $ret = " {$return_attribute}='{$name}-{$id_value}'";
+ $ret = "{$name}-{$id_value}";
}
else // also useful when name is e.g. name='my_name[]'
{
- $ret = " {$return_attribute}='{$id_value}'";
+ $ret = "{$id_value}";
}
- return $ret;
+ return " $return_attribute='" . htmlentities($ret, ENT_QUOTES) . "'";
}
public function name2id($name)
@@ -4440,30 +4463,33 @@ var_dump($select_options);*/
{
$cl = (vartrue($val['thclass'])) ? " class='".$val['thclass']."'" : '';
- $aClass = ($key === $field) ? "class='sorted-".$sorted."'" : '';
+ $aClass = ($key === $field) ? "sorted-" . $sorted : null;
$text .= "
";
- if($querypattern!= '' && $key !== 'options' && $key !== 'checkboxes' && !vartrue($val['nosort']))
+ if ($querypattern != '' && $key !== 'options' && $key !== 'checkboxes' && !vartrue($val['nosort']))
{
$from = ($key == $field) ? $fromval : 0;
$srch = array('[FIELD]', '[ASC]', '[FROM]');
- $repl = array($key,$ascdesc,$from);
- $val['url'] = e_SELF. '?' .str_replace($srch,$repl,$querypattern);
+ $repl = array($key, $ascdesc, $from);
+ $val['url'] = e_SELF . '?' . str_replace($srch, $repl, $querypattern);
}
-
- $text .= (vartrue($val['url'])) ? '" : ''; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js.
- $text .= !empty($val['title']) ? defset($val['title'], $val['title']) : '';
+ $text .= (vartrue($val['url'])) ? ' attributes([
+ 'class' => $aClass,
+ 'title' => LAN_SORT,
+ 'href' => str_replace('&', '&', $val['url']),
+ ]) . ">" : ''; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js.
+ $text .= !empty($val['title']) ? defset($val['title'], $val['title']) : '';
$text .= ($val['url']) ? ' ' : '';
- $text .= ($key === 'options' && !vartrue($val['noselector'])) ? $this->columnSelector($fieldarray, $columnPref) : '';
+ $text .= ($key === 'options' && !vartrue($val['noselector'])) ? $this->columnSelector($fieldarray, $columnPref) : '';
$text .= ($key === 'checkboxes') ? $this->checkbox_toggle('e-column-toggle', vartrue($val['toggle'], 'multiselect')) : '';
-
- $text .= '
+
+ $text .= '
';
}
@@ -4471,7 +4497,7 @@ var_dump($select_options);*/
return '
- ' .$text. '
+ ' . $text . '
';
@@ -4706,14 +4732,8 @@ var_dump($select_options);*/
$value = $this->renderValue($field, varset($fieldvalues[$field]), $data, varset($fieldvalues[$pid]));
-
- if($tdclass)
- {
- $tdclass = ' class="'.$tdclass.'"';
- }
-
$text .= '
-
+ attributes(['class' => $tdclass]) . '>
'.$value.'
';
@@ -4747,12 +4767,10 @@ var_dump($select_options);*/
return '';
}
- $trclass = '';
- // $trclass = vartrue($fieldvalues['__trclass']) ? ' class="'.$trclass.'"' : '';
unset($fieldValues['__trclass']);
return '
-
+
'.$ret.'
';
@@ -4799,39 +4817,39 @@ var_dump($select_options);*/
if(!isset($options['url']))
{
- $options['url'] = e_SELF."?mode={$mode}&action=inline&id={$pid}&ajax_used=1";
+ $options['url'] = e_SELF . "?mode={$mode}&action=inline&id={$pid}&ajax_used=1";
}
- if(!empty($pid))
+ if (!empty($pid))
{
$options['pk'] = $pid;
}
- $title = varset($options['title'] , (LAN_EDIT. ' ' .$fieldName));
+ $title = varset($options['title'], (LAN_EDIT . ' ' . $fieldName));
$class = varset($options['class']);
- unset( $options['title']);
-
- $text = "
"e-tip e-editable editable-click $class",
+ 'data-name' => $dbField,
+ 'data-source' => is_array($array) ? $source : null,
+ 'title' => $title,
+ 'data-type' => $type,
+ 'data-inputclass' => 'x-editable-' . $this->name2id($dbField) . ' ' . $class,
+ 'data-value' => $curVal,
+ 'href' => '#',
+ ];
$options['token'] = $this->inlineToken();
-
- if(!empty($options))
+ if (!empty($options))
{
- foreach($options as $k=>$opt)
+ foreach ($options as $k => $opt)
{
- if(!empty($opt))
- {
- $text .= ' data-' .$k."='".$opt."'";
- }
+ $attributes += ['data-' . $k => $opt];
}
}
- $text .= '>' .$linkText. ' ';
-
- return $text;
+ return "
attributes($attributes) . ">$linkText ";
}
/**
@@ -4855,38 +4873,43 @@ var_dump($select_options);*/
}
/** @var e_admin_model $model */
- if(!$model = e107::getRegistry('core/adminUI/currentListModel')) // Try list model
+ if (!$model = e107::getRegistry('core/adminUI/currentListModel')) // Try list model
{
$model = e107::getRegistry('core/adminUI/currentModel'); // try create/edit model.
}
- $dialog = vartrue($parms['target']) === 'dialog' ? ' e-modal' : ''; // iframe
- $ext = vartrue($parms['target']) === 'blank' ? " rel='external' " : ''; // new window
- $modal = vartrue($parms['target']) === 'modal' ? " data-toggle='modal' data-bs-toggle='modal' data-cache='false' data-target='#uiModal' " : '';
+ $dialog = vartrue($parms['target']) === 'dialog' ? ' e-modal' : ''; // iframe
+ $ext = vartrue($parms['target']) === 'blank' ? "external" : null; // new window
+ $modal = vartrue($parms['target']) === 'modal' ? [
+ "data-toggle" => 'modal',
+ "data-bs-toggle" => 'modal',
+ "data-cache" => 'false',
+ "data-target" => '#uiModal'
+ ] : [];
$link = null;
- if(!empty($parms['url']) && !empty($model)) // ie. use e_url.php
+ if (!empty($parms['url']) && !empty($model)) // ie. use e_url.php
{
//$plugin = $this->getController()->getPluginName();
- if($plugin = e107::getRegistry('core/adminUI/currentPlugin'))
+ if ($plugin = e107::getRegistry('core/adminUI/currentPlugin'))
{
$data = $model->getData();
- $link = e107::url($plugin,$parms['url'],$data);
+ $link = e107::url($plugin, $parms['url'], $data);
}
}
- elseif(!empty($model)) // old way.
+ elseif (!empty($model)) // old way.
{
$tp = e107::getParser();
$data = $model->getData();
- $link = str_replace('[id]',$id,$parms['link']);
- $link = $tp->replaceConstants($link); // SEF URL is not important since we're in admin.
+ $link = str_replace('[id]', $id, $parms['link']);
+ $link = $tp->replaceConstants($link); // SEF URL is not important since we're in admin.
- if($parms['link'] === 'sef' )
+ if ($parms['link'] === 'sef')
{
- if(!$model->getUrl())
+ if (!$model->getUrl())
{
/** @var e_admin_controller_ui $controller */
$controller = $this->getController();
@@ -4909,7 +4932,14 @@ var_dump($select_options);*/
// in case something goes wrong...
if($link)
{
- return "
".$value. ' ';
+ $attributes = [
+ 'class' => "e-tip{$dialog}",
+ 'rel' => $ext,
+ 'href' => $link,
+ 'title' => varset($parms['title'], LAN_EFORM_010),
+ ] + $modal;
+
+ return "
attributes($attributes) . ">" . $value . ' ';
}
return $value;
@@ -4945,7 +4975,12 @@ var_dump($select_options);*/
{
$mode = preg_replace('/[\W]/', '', vartrue($_GET['mode']));
$from = (int) vartrue($_GET['from'], 0);
- $text .= "
".ADMIN_SORT_ICON. ' ';
+ $text .= "
attributes([
+ 'class' => 'e-sort sort-trigger btn btn-default',
+ 'style' => 'cursor:move',
+ 'data-target' => e_SELF . "?mode=$mode&action=sort&ajax_used=1&from=$from",
+ 'title' => LAN_RE_ORDER,
+ ]) . ">" . ADMIN_SORT_ICON . ' ';
}
@@ -4966,23 +5001,31 @@ var_dump($select_options);*/
if(!empty($parms['target']) && $parms['target'] === 'modal')
{
$eModal = ' e-modal ';
- $eModalCap = !empty($parms['modalCaption']) ? "data-modal-caption='".$parms['modalCaption']."'" : "data-modal-caption='#".$id."'";
+ $eModalCap = !empty($parms['modalCaption']) ? $parms['modalCaption'] : "#" . $id;
$query['iframe'] = 1;
}
else
{
$eModal = '';
- $eModalCap = '';
+ $eModalCap = null;
}
- if(!empty($parms['modalSubmit']))
+ if (!empty($parms['modalSubmit']))
{
$eModalCap .= " data-modal-submit='true'";
}
- $query = http_build_query($query, '', '&');
- $text .= "
- ".$editIconDefault. ' ';
+ $query = http_build_query($query);
+ $text .= "
attributes([
+ 'href' => e_SELF . "?$query",
+ 'class' => "btn btn-default btn-secondary$eModal",
+ 'data-modal-caption' => $eModalCap,
+ 'title' => LAN_EDIT,
+ 'data-toggle' => 'tooltip',
+ 'data-bs-toggle' => 'tooltip',
+ 'data-placement' => 'left',
+ ]) . ">
+ " . $editIconDefault . ' ';
}
$delcls = !empty($attributes['noConfirm']) ? ' no-confirm' : '';
@@ -5345,7 +5388,7 @@ var_dump($select_options);*/
if(empty($value))
{
$value = '-';
- $setValue = "data-value=''";
+ $setValue = null;
}
else
{
@@ -5353,7 +5396,7 @@ var_dump($select_options);*/
if($attributes['type'] === 'tags' && !empty($value))
{
- $setValue = "data-value='" . $value . "'";
+ $setValue = $value;
$value = str_replace(',', ', ', $value); // add spaces so it wraps, but don't change the actual values.
}
}
@@ -5371,7 +5414,20 @@ var_dump($select_options);*/
$tpl = $this->text($field, $value, 80, $options);
$mode = preg_replace('/[\W]/', '', vartrue($_GET['mode']));
- $value = "
" . $value . ' ';
+ $value = "
attributes([
+ 'id' => "{$field}_{$id}",
+ 'class' => 'e-tip e-editable editable-click editable-tags',
+ 'data-emptytext' => '-',
+ 'data-tpl' => $tpl,
+ 'data-name' => $field,
+ 'data-token' => $this->inlineToken(),
+ 'title' => LAN_EDIT . ' ' . $attributes['title'],
+ 'data-type' => 'text',
+ 'data-pk' => $id,
+ 'data-value' => $setValue,
+ 'data-url' => e_SELF . "?mode=$mode&action=inline&id=$id&ajax_used=1",
+ 'href' => '#',
+ ]) . ">" . $value . ' ';
}
$value = vartrue($parms['pre']) . $value . vartrue($parms['post']);
@@ -5408,15 +5464,11 @@ var_dump($select_options);*/
if(empty($value))
{
$value = '-';
- $setValue = "data-value=''";
}
else
{
- $setValue = '';
-
if($attributes['type'] === 'tags' && !empty($value))
{
- $setValue = "data-value='".$value."'";
$value = str_replace(',', ', ', $value); // add spaces so it wraps, but don't change the actual values.
}
}
@@ -5605,24 +5657,36 @@ var_dump($select_options);*/
$thparms['alt'] = $alt;
$thparms['class'] = 'thumbnail e-thumb';
- // e107::getDebug()->log($value);
+ // e107::getDebug()->log($value);
$ttl = $tp->toImage($value, $thparms);
- if($createLink === false)
+ if ($createLink === false)
{
return $ttl;
}
- $value = '
'.$ttl.' ';
+ $value = '
attributes([
+ 'href' => $src,
+ 'data-modal-caption' => $alt,
+ 'data-target' => '#uiModal',
+ 'class' => "e-modal e-image-preview",
+ 'title' => $alt,
+ 'rel' => 'external',
+ ]) . '>' . $ttl . ' ';
}
else
{
- $src = $tp->replaceConstants(vartrue($parms['pre']).$value, 'abs');
+ $src = $tp->replaceConstants(vartrue($parms['pre']) . $value, 'abs');
$alt = $src; //basename($value);
$ttl = vartrue($parms['title'], 'LAN_PREVIEW');
- $value = '
'.defset($ttl, $ttl).' ';
+ $value = '
attributes([
+ 'href' => $src,
+ 'class' => "e-image-preview",
+ 'title' => $alt,
+ 'rel' => 'external',
+ ]) . '>' . defset($ttl, $ttl) . ' ';
}
}
elseif(!empty($parms['fallback']))
@@ -5726,14 +5790,26 @@ var_dump($select_options);*/
if(!vartrue($attributes['noedit']) && vartrue($parms['editable']) && !vartrue($parms['link'])) // avoid bad markup, better solution coming up
{
$uc_options = vartrue($parms['classlist'], 'public,guest, nobody,member,admin,main,classes'); // defaults to 'public,guest,nobody,member,classes' (userclass handler)
- $array = e107::getUserClass()->uc_required_class_list($uc_options); //XXX Ugly looking (non-standard) function naming - TODO discuss name change.
+ $array = e107::getUserClass()->uc_required_class_list($uc_options); //XXX Ugly looking (non-standard) function naming - TODO discuss name change.
//$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
- $mode = $tp->filter(vartrue($_GET['mode']),'w');
- $source = str_replace('"',"'",json_encode($array, JSON_FORCE_OBJECT));
+ $mode = $tp->filter(vartrue($_GET['mode']), 'w');
+ $source = str_replace('"', "'", json_encode($array, JSON_FORCE_OBJECT));
//NOTE Leading ',' required on $value; so it picks up existing value.
- $value = "
".$dispvalue. ' ';
+ $value = "
attributes([
+ 'class' => "e-tip e-editable editable-click",
+ 'data-placement' => 'bottom',
+ 'data-value' => ",$value",
+ 'data-name' => $field,
+ 'data-source' => $source,
+ 'title' => LAN_EDIT . ' ' . $attributes['title'],
+ 'data-type' => 'checklist',
+ 'data-pk' => $id,
+ 'data-token' => $this->inlineToken(),
+ 'data-url' => e_SELF . "?mode=$mode&action=inline&id=$id&ajax_used=1",
+ 'href' => '#',
+ ]) . ">" . $dispvalue . ' ';
}
else
{
@@ -5800,9 +5876,14 @@ var_dump($select_options);*/
if(!empty($parms['link']) && $id && $ttl && is_numeric($id))
{
// Stay in admin area.
- $link = e_ADMIN. 'users.php?mode=main&action=edit&id=' .$id. '&readonly=1&iframe=1'; // e107::getUrl()->create('user/profile/view', array('id' => $id, 'name' => $ttl))
+ $link = e_ADMIN . 'users.php?mode=main&action=edit&id=' . $id . '&readonly=1&iframe=1'; // e107::getUrl()->create('user/profile/view', array('id' => $id, 'name' => $ttl))
- $value = '
'.$ttl.' ';
+ $value = '
attributes([
+ 'class' => "e-modal",
+ 'data-modal-caption' => "User #$id : $ttl",
+ 'href' => $link,
+ 'title' => LAN_EFORM_011
+ ]) . '>' . $ttl . ' ';
}
else
{
@@ -5816,11 +5897,24 @@ var_dump($select_options);*/
$fieldID = $this->name2id($field . '_' . microtime(true));
// Unique ID for each rows.
$eEditableID = $this->name2id($fieldID . '_' . $row_id);
- // $tpl = $this->userpicker($field, '', $ttl, $id, array('id' => $fieldID, 'selectize' => array('e_editable' => $eEditableID)));
+ // $tpl = $this->userpicker($field, '', $ttl, $id, array('id' => $fieldID, 'selectize' => array('e_editable' => $eEditableID)));
- $tpl = $this->userpicker($fieldID, array('user_id'=>$id, 'user_name'=>$ttl), array('id' => $fieldID, 'inline' => $eEditableID));
+ $tpl = $this->userpicker($fieldID, array('user_id' => $id, 'user_name' => $ttl), array('id' => $fieldID, 'inline' => $eEditableID));
$mode = preg_replace('/[\W]/', '', vartrue($_GET['mode']));
- $value = "
" . $ttl . ' ';
+ $value = "
attributes([
+ 'id' => $eEditableID,
+ 'class' => 'e-tip e-editable editable-click editable-userpicker',
+ 'data-clear' => 'false',
+ 'data-token' => $this->inlineToken(),
+ 'data-tpl' => $tpl,
+ 'data-name' => $field,
+ 'title' => LAN_EDIT . ' ' . $attributes['title'],
+ 'data-type' => 'text',
+ 'data-pk' => $row_id,
+ 'data-value' => $id,
+ 'data-url' => e_SELF . "?mode=$mode&action=inline&id=$row_id&ajax_used=1",
+ 'href' => '#'
+ ]) . ">" . $ttl . ' ';
}
break;
@@ -5896,37 +5990,47 @@ var_dump($select_options);*/
break;
}
$ttl = $value;
- if(!empty($parms['href']))
+ if (!empty($parms['href']))
{
- return $tp->replaceConstants(vartrue($parms['pre']).$value, varset($parms['replace_mod'],'abs'));
+ return $tp->replaceConstants(vartrue($parms['pre']) . $value, varset($parms['replace_mod'], 'abs'));
}
- if(!empty($parms['truncate']))
+ if (!empty($parms['truncate']))
{
$ttl = $tp->text_truncate($value, $parms['truncate'], '...');
}
- $target = (!empty($parms['target'])) ? " target='".$parms['target']."' " : '';
- $class = (!empty($parms['class'])) ? " class='".$parms['class']."' " : '';
+ $target = (!empty($parms['target'])) ? $parms['target'] : null;
+ $class = (!empty($parms['class'])) ? $parms['class'] : null;
- $value = '
replaceConstants(vartrue($parms['pre']).$value, 'abs')."' title='{$value}'>".$ttl. ' ';
- break;
+ $value = '
attributes([
+ 'target' => $target,
+ 'class' => $class,
+ 'href' => $tp->replaceConstants(vartrue($parms['pre']) . $value, 'abs'),
+ 'title' => $value,
+ ]) . ">" . $ttl . ' ';
+ break;
case 'email':
- if(!$value)
+ if (!$value)
{
break;
}
$ttl = $value;
- if(!empty($parms['truncate']))
+ if (!empty($parms['truncate']))
{
$ttl = $tp->text_truncate($value, $parms['truncate'], '...');
}
- $target = (!empty($parms['target'])) ? " target='".$parms['target']."' " : '';
- $class = (!empty($parms['class'])) ? " class='".$parms['class']."' " : '';
+ $target = (!empty($parms['target'])) ? $parms['target'] : null;
+ $class = (!empty($parms['class'])) ? $parms['class'] : null;
- $value = '
".$ttl. ' ';
- break;
+ $value = '
attributes([
+ 'target' => $target,
+ 'class' => $class,
+ 'href' => "mailto:$value",
+ 'title' => $value,
+ ]) . ">" . $ttl . ' ';
+ break;
case 'method': // Custom Function
$method = varset($attributes['field']); // prevents table alias in method names. ie. u.my_method.
@@ -6108,11 +6212,20 @@ var_dump($select_options);*/
*/
public function renderElement($key, $value, $attributes, $required_data = array(), $id = 0)
{
+ // Workaround for accepting poorly normalized values from the database where the data would have been stored
+ // with HTML entities escaped.
+ $key = html_entity_decode($key, ENT_QUOTES);
- if(!empty($value) && !empty($attributes['data']) && ($attributes['data'] === 'array' || $attributes['data'] === 'json'))
+ if (!empty($value) && !empty($attributes['data']) && ($attributes['data'] === 'array' || $attributes['data'] === 'json'))
{
$value = e107::unserialize($value);
}
+ elseif (is_string($value))
+ {
+ // Workaround for accepting poorly normalized values from the database where the data would have been stored
+ // with HTML entities escaped.
+ $value = html_entity_decode($value, ENT_QUOTES);
+ }
$tp = e107::getParser();
$ret = '';
@@ -6276,7 +6389,7 @@ var_dump($select_options);*/
{
$sefSource = $this->name2id($parms['sef']);
$sefTarget = $this->name2id($key);
- if(!empty($parms['tdClassRight']))
+ if (!empty($parms['tdClassRight']))
{
$parms['tdClassRight'] .= 'input-group';
}
@@ -6285,7 +6398,12 @@ var_dump($select_options);*/
$parms['tdClassRight'] = 'input-group';
}
- $parms['post'] = "
' .LAN_GENERATE. ' ';
+ $parms['post'] = "
attributes([
+ 'class' => 'e-sef-generate btn btn-default',
+ 'data-src' => $sefSource,
+ 'data-target' => $sefTarget,
+ 'data-sef-generate-confirm' => LAN_WILL_OVERWRITE_SEF . ' ' . LAN_JSCONFIRM,
+ ]) . '>' . LAN_GENERATE . ' ';
}
if(!empty($parms['password'])) // password mechanism without the md5 storage.
@@ -6332,8 +6450,12 @@ var_dump($select_options);*/
if(!empty($parms['maxlength']) && empty($parms['post']))
{
- $charMsg = e107::getParser()->lanVars(defset('LAN_X_CHARS_REMAINING', '[x] chars remaining'),"
".$parms['maxlength']." ");
- $parms['post'] = "
".$charMsg." ";
+ $charMsg = e107::getParser()->lanVars(defset('LAN_X_CHARS_REMAINING', '[x] chars remaining'), "
" . $parms['maxlength'] . " ");
+ $parms['post'] = "
attributes([
+ 'id' => $this->name2id($key) . "-char-count",
+ 'class' => 'text-muted',
+ 'style' => 'display:none',
+ ]) . ">" . $charMsg . " ";
}
$text .= vartrue($parms['pre']).$this->textarea($key, $value, vartrue($parms['rows'], 5), vartrue($parms['cols'], 40), vartrue($parms['__options'],$parms), varset($parms['counter'], false)).vartrue($parms['post']);
@@ -6844,17 +6966,25 @@ var_dump($select_options);*/
foreach($parms['optArray'] as $key=>$val)
{
- $thumbnail = e107::getParser()->toImage($val['thumbnail'],$parms);
- $selected = ($key === $value) ? " checked='checked'" : '';
+ $thumbnail = e107::getParser()->toImage($val['thumbnail'], $parms);
$active = ($key === $value) ? ' active' : '';
- $text .= "
-
- ".$thumbnail. "
+ $text .= "
+
attributes([
+ 'class' => "theme-selection$active",
+ 'title' => varset($val['title']),
+ ]) . "> attributes([
+ 'type' => 'radio',
+ 'name' => $name,
+ 'value' => $key,
+ 'required' => true,
+ 'checked' => $key === $value,
+ ]) . " />
+ " . $thumbnail . "
";
- $text .= isset($val['label']) ? "
".$val['label']."
" : '';
- $text .= "
+ $text .= isset($val['label']) ? "
" . $val['label'] . "
" : '';
+ $text .= "
";
}
@@ -6878,10 +7008,18 @@ var_dump($select_options);*/
{
$thumbnail = e107::getParser()->toImage($val,$parms);
- $selected = ($val == $value) ? ' checked' : '';
- $text .= "
+ $text .= "
-
+ attributes([
+ 'class' => 'theme-selection',
+ 'title' => varset($parms['titles'][$key], $key),
+ ]) . "> attributes([
+ 'type' => 'radio',
+ 'name' => $name,
+ 'value' => $val,
+ 'required' => true,
+ 'checked' => ($val === $value),
+ ]) . " />
".$thumbnail. "
";
@@ -6928,6 +7066,7 @@ var_dump($select_options);*/
* $tree_models['myplugin'] = new e_admin_tree_model($data);
*
* TODO - move fieldset & table generation in separate methods, needed for ajax calls
+ * @todo {@see htmlspecialchars()} at the template, not in the client code
* @param array $form_options
* @param e_admin_tree_model $tree_model
* @param boolean $nocontainer don't enclose form in div container
@@ -7873,7 +8012,9 @@ var_dump($select_options);*/
}
}
-// DEPRECATED - use above methods instead ($frm)
+/**
+ * @deprecated 2.0-beta1 Use {@see e_form} instead.
+ */
class form
{
public function form_open($form_method, $form_action, $form_name = '', $form_target = '', $form_enctype = '', $form_js = '')
diff --git a/e107_tests/tests/unit/e_formTest.php b/e107_tests/tests/unit/e_formTest.php
index e7031f612..90cdd9469 100644
--- a/e107_tests/tests/unit/e_formTest.php
+++ b/e107_tests/tests/unit/e_formTest.php
@@ -314,12 +314,29 @@ class e_formTest extends \Codeception\Test\Unit
{
}
+ */
- public function testText()
- {
+ public function testText()
+ {
+ $result = $this->_frm->renderElement('crazy"key', "crazy'value", ['type' => 'text']);
+ $this->assertEquals(
+ " ",
+ $result
+ );
+ }
- }
+ public function testTextBadNormalizationSource()
+ {
+ $result = $this->_frm->renderElement('crazy"key', "crazy'value", ['type' => 'text']);
+ $this->assertEquals(
+ " ",
+ $result
+ );
+ }
+ /*
public function testNumber()
{
@@ -591,7 +608,7 @@ class e_formTest extends \Codeception\Test\Unit
$actual = $this->_frm->select('name', $opt_array, $selected,null,true);
$actual = str_replace("\n", "", $actual);
- $expected = " Option 1 Option 2 Option 3 ";
+ $expected = " Option 1 Option 2 Option 3 ";
$this->assertSame($expected,$actual);
@@ -799,7 +816,7 @@ class e_formTest extends \Codeception\Test\Unit
1 => "1 ",
2 => "go ",
3 => "Check All ",
- 4 => "My Label ",
+ 4 => "My Label ",
);
// $ret = [];
@@ -966,8 +983,8 @@ class e_formTest extends \Codeception\Test\Unit
'layout_001' => 'default',
'layout_002' => 'default',
- 'image_001' => " ",
- 'image_002' => " ",
+ 'image_001' => " ",
+ 'image_002' => " ",
'checkboxes_001' => 'Check Opt 2, Check Opt 3',
@@ -1063,10 +1080,10 @@ class e_formTest extends \Codeception\Test\Unit
date_default_timezone_set('America/Phoenix');
$expected = array(
- 'text_001' => " ",
+ 'text_001' => " ",
- 'number_001' => " ",
- 'number_002' => " ",
+ 'number_001' => " ",
+ 'number_002' => " ",
'bool_001' => " On Off ",
'bool_002' => " On Off ",
@@ -1081,35 +1098,35 @@ class e_formTest extends \Codeception\Test\Unit
'layout_001' => "Default Videos (experimental) Nav ",
'layout_002' => "Default Videos (experimental) Nav ",
- 'image_001' => " ",
- 'image_002' => " ",
+ 'image_001' => " ",
+ 'image_002' => " ",
'checkboxes_001' => "",
- 'country_001' => " Afghanistan Albania Algeria American Samoa Andorra Angola Anguilla Antarctica Antigua and Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia Bosnia-Herzegovina Botswana Bouvet Island Brazil British Indian Ocean Territory Brunei Darussalam Bulgaria Burkina Faso Burundi Cambodia Cameroon Canada Cape Verde Cayman Islands Central African Republic Chad Chile China Christmas Island Cocos (Keeling) Islands Colombia Comoros Congo Congo (Dem.Rep) Cook Islands Costa Rica Croatia Cuba Cyprus Czech Republic Denmark Djibouti Dominica Dominican Republic East Timor Ecuador Egypt El Salvador Equatorial Guinea Eritrea Estonia Ethiopia Falkland Islands Faroe Islands Fiji Finland France French Guyana French Southern Territories Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe (French) Guam (USA) Guatemala Guinea Guinea Bissau Guyana Haiti Heard and McDonald Islands Honduras Hong Kong Hungary Iceland India Indonesia Iran Iraq Ireland Israel Italy Ivory Coast (Cote D'Ivoire) Jamaica Japan Jordan Kazakhstan Kenya Kiribati Korea (North) Korea (South) Kuwait Kyrgyzstan Laos Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Macau Macedonia Madagascar Malawi Malaysia Maldives Mali Malta Marshall Islands Martinique (French) Mauritania Mauritius Mayotte Mexico Micronesia Moldavia Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands Netherlands Antilles New Caledonia (French) New Zealand Nicaragua Niger Nigeria Niue Norfolk Island Northern Mariana Islands Norway Oman Pakistan Palau Panama Papua New Guinea Paraguay Peru Philippines Pitcairn Island Poland Polynesia (French) Portugal Puerto Rico Palestine Qatar Reunion (French) Romania Russia Rwanda S. Georgia & S. Sandwich Isls. Saint Helena Saint Kitts & Nevis Saint Lucia Saint Pierre and Miquelon Saint Tome (Sao Tome) and Principe Saint Vincent & Grenadines Samoa San Marino Saudi Arabia Senegal Serbia Seychelles Sierra Leone Singapore Slovak Republic Slovenia Solomon Islands Somalia South Africa Spain Sri Lanka Sudan Suriname Svalbard and Jan Mayen Islands Swaziland Sweden Switzerland Syria Tadjikistan Taiwan Tanzania Thailand Tibet Togo Tokelau Tonga Trinidad and Tobago Tunisia Turkey Turkmenistan Turks and Caicos Islands Tuvalu Uganda Ukraine United Arab Emirates United Kingdom United States Uruguay US Minor Outlying Islands Uzbekistan Vanuatu Vatican City State Venezuela Vietnam Virgin Islands (British) Virgin Islands (USA) Wallis and Futuna Islands Western Sahara Yemen Zambia Zimbabwe ",
- 'ip_001' => " ",
+ 'country_001' => " Afghanistan Albania Algeria American Samoa Andorra Angola Anguilla Antarctica Antigua and Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia Bosnia-Herzegovina Botswana Bouvet Island Brazil British Indian Ocean Territory Brunei Darussalam Bulgaria Burkina Faso Burundi Cambodia Cameroon Canada Cape Verde Cayman Islands Central African Republic Chad Chile China Christmas Island Cocos (Keeling) Islands Colombia Comoros Congo Congo (Dem.Rep) Cook Islands Costa Rica Croatia Cuba Cyprus Czech Republic Denmark Djibouti Dominica Dominican Republic East Timor Ecuador Egypt El Salvador Equatorial Guinea Eritrea Estonia Ethiopia Falkland Islands Faroe Islands Fiji Finland France French Guyana French Southern Territories Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe (French) Guam (USA) Guatemala Guinea Guinea Bissau Guyana Haiti Heard and McDonald Islands Honduras Hong Kong Hungary Iceland India Indonesia Iran Iraq Ireland Israel Italy Ivory Coast (Cote D'Ivoire) Jamaica Japan Jordan Kazakhstan Kenya Kiribati Korea (North) Korea (South) Kuwait Kyrgyzstan Laos Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Macau Macedonia Madagascar Malawi Malaysia Maldives Mali Malta Marshall Islands Martinique (French) Mauritania Mauritius Mayotte Mexico Micronesia Moldavia Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands Netherlands Antilles New Caledonia (French) New Zealand Nicaragua Niger Nigeria Niue Norfolk Island Northern Mariana Islands Norway Oman Pakistan Palau Panama Papua New Guinea Paraguay Peru Philippines Pitcairn Island Poland Polynesia (French) Portugal Puerto Rico Palestine Qatar Reunion (French) Romania Russia Rwanda S. Georgia & S. Sandwich Isls. Saint Helena Saint Kitts & Nevis Saint Lucia Saint Pierre and Miquelon Saint Tome (Sao Tome) and Principe Saint Vincent & Grenadines Samoa San Marino Saudi Arabia Senegal Serbia Seychelles Sierra Leone Singapore Slovak Republic Slovenia Solomon Islands Somalia South Africa Spain Sri Lanka Sudan Suriname Svalbard and Jan Mayen Islands Swaziland Sweden Switzerland Syria Tadjikistan Taiwan Tanzania Thailand Tibet Togo Tokelau Tonga Trinidad and Tobago Tunisia Turkey Turkmenistan Turks and Caicos Islands Tuvalu Uganda Ukraine United Arab Emirates United Kingdom United States Uruguay US Minor Outlying Islands Uzbekistan Vanuatu Vatican City State Venezuela Vietnam Virgin Islands (British) Virgin Islands (USA) Wallis and Futuna Islands Western Sahara Yemen Zambia Zimbabwe ",
+ 'ip_001' => " ",
'templates_001' => "Bbcode Forum Icons Forum Poll Forum Post Forum Posted Forum Preview Forum Forum Viewforum Forum Viewtopic Newforumposts Menu ",
'radio_001' => " Radio Opt 1 Radio Opt 2 Radio Opt 3 ",
//todo check tags_001 is correct.
- 'tags_001' => " ",
+ 'tags_001' => " ",
// 'bbarea_001' => 'bold ',
// 'icon_001' => " ",
'file_001' => "{e_MEDIA_FILE}test.zip ",
- 'files_001' => "{e_MEDIA_FILE}test.zip Choose a file Choose a file Choose a file Choose a file ",
+ 'files_001' => "{e_MEDIA_FILE}test.zip Choose a file Choose a file Choose a file Choose a file ",
'datestamp_001' => " ",
'date_001' => " ",
'userclass_001' => "Everyone (public) Admin Admins and Mods CONTACT PEOPLE Forum Moderators Guests Main Admin Members PRIVATEMENU No One (inactive) NEWSLETTER Not Admin Not Admins and Mods Not CONTACT PEOPLE Not Forum Moderators Not Guests Not Main Admin Not Members Not PRIVATEMENU Not NEWSLETTER ",
'userclasses_001' => "Everyone (public) Admin Admins and Mods CONTACT PEOPLE Forum Moderators Guests Main Admin Members PRIVATEMENU No One (inactive) NEWSLETTER Not Admin Not Admins and Mods Not CONTACT PEOPLE Not Forum Moderators Not Guests Not Main Admin Not Members Not PRIVATEMENU Not NEWSLETTER ",
//todo check user_001 is correct
- 'user_001' => " ",
- 'url_001' => " ",
- 'email_001' => " ",
+ 'user_001' => " ",
+ 'url_001' => " ",
+ 'email_001' => " ",
'hidden_001' => " ",
// 'method_001' => 'custom-value',
'language_001' => "Afar Abkhazian Afrikaans Amharic Arabic Assamese Avestan Aymara Azerbaijani Bashkir Belarusian Bengali Bihari Bislama Tibetan Bosnian Brazilian Bulgarian Burmese Catalan Czech Chamorro Chechen ChineseSimp ChineseTrad Chuvash Cornish Corsican Danish Dutch Dzongkha German English Esperanto Estonian Basque Faroese Persian Fijian Finnish French Frisian Gaelic Greek Irish Gallegan Guarani Gujarati Hausa Hebrew Herero Hindi Hiri Motu Croatian Hungarian Armenian Inuktitut Interlingue Indonesian Inupiaq Icelandic Italian Javanese Japanese Kalaallisut Kannada Kashmiri Georgian Kazakh Khmer Kikuyu Kinyarwanda Kirghiz Komi Korean Kurdish Lao Latin Latvian Lingala Lithuanian Letzeburgesch Marshall Malayalam Marathi Macedonian Malagasy Maltese Moldavian Mongolian Maori Malay Manx Nauru Navajo Ndonga Nepali Norwegian Chichewa Oriya Oromo Panjabi Pali Polish Portuguese Pushto Quechua Romanian Rundi Russian Sango Sanskrit Sinhala Slovak Slovenian Samoan Shona Sindhi Somali Spanish Albanian Sardinian Serbian Swati Sundanese Swahili Swedish Tahitian Tamil Tatar Telugu Tajik Tagalog Thai Tigrinya Tswana Tsonga Turkmen Turkish Uighur Ukrainian Urdu Uzbek Vietnamese Welsh Wolof Xhosa Yiddish Yoruba Zhuang Zulu ",
- 'media_001' => "",
+ 'media_001' => "",
// 'lanlist_001' => 'German', // only works with multiple languages installed.
);
@@ -1207,22 +1224,22 @@ class e_formTest extends \Codeception\Test\Unit
0 => array(
'value' => 'Some text',
'parms' => array('link'=>'myurl.php', 'target'=>'blank'),
- 'expected' => "Some text "
+ 'expected' => "Some text "
),
1 => array(
'value' => 'Some text',
'parms' => array('link'=>'myurl.php?id=[id]', 'target'=>'modal'),
- 'expected' => "Some text "
+ 'expected' => "Some text "
),
2 => array(
'value' => 'Some text',
'parms' => array('link'=>'url_001', 'target'=>'blank'),
- 'expected' => "Some text "
+ 'expected' => "Some text "
),
3 => array(
'value' => 'Some text',
'parms' => array('link'=>'myurl.php?country=[country_001]', 'target'=>'dialog'),
- 'expected' => "Some text "
+ 'expected' => "Some text "
),
/* 4 => array(
'value' => 'Some text',
diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php
index 18aedb6ec..76f5b9e68 100644
--- a/e107_tests/tests/unit/e_parseTest.php
+++ b/e107_tests/tests/unit/e_parseTest.php
@@ -2589,7 +2589,22 @@ Your browser does not support the audio tag.
}
+ /**
+ * e107 v0.6.0 requires strings to be passed around with quotation marks escaped for HTML as a way to prevent
+ * both SQL injection and cross-site scripting. Although {@see e_parse::toDB()} is supposed to do that, some
+ * usages, specifically {@see e_front_model::sanitizeValue()} call {@see e_parse::filter()} instead.
+ *
+ * @version 2.3.1
+ */
+ public function testFilterStr()
+ {
+ $input = "\"e107's\" ";
+ $expected = ""e107's"";
+ $actual = $this->tp->filter($input, 'str');
+
+ $this->assertEquals($expected, $actual);
+ }
public function testCleanHtml()
{