1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 20:57:26 +02:00

e107::unserialize() will now return the array if the input is an array. Additional form-handler tests added for type: media, file and files. Admin-ui can now manage a change of field type from 'array' to 'json' without additional changes needed.

This commit is contained in:
Cameron
2021-02-08 08:44:44 -08:00
parent 62815a965a
commit c32e5bf1e2
6 changed files with 86 additions and 41 deletions

View File

@@ -541,7 +541,7 @@ class e_array {
if(is_array($ArrayData)) if(is_array($ArrayData))
{ {
return false; return $ArrayData;
} }
// Saftety mechanism for 0.7 -> 0.8 transition. // Saftety mechanism for 0.7 -> 0.8 transition.

View File

@@ -1133,7 +1133,7 @@ class e_form
$class = !empty($extras['class']) ? $extras['class']. ' ' : ''; $class = !empty($extras['class']) ? $extras['class']. ' ' : '';
$title = !empty($extras['title']) ? $extras['title'] : $title; $title = !empty($extras['title']) ? $extras['title'] : $title;
$ret = "<a 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. '</a>'; // using bootstrap. $ret = "<a 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. '</a>'; // using bootstrap.
if(!e107::getRegistry('core/form/mediaurl')) if(!e107::getRegistry('core/form/mediaurl'))
{ {
@@ -1449,9 +1449,9 @@ class e_form
$ret .= $preview; // image, video. audio tag etc. $ret .= $preview; // image, video. audio tag etc.
$ret .= '</div><div class="overlay"> $ret .= "</div><div class='overlay'>
<div class="text">'.$editIcon.$previewIcon.'</div> <div class='text'>".$editIcon.$previewIcon."</div>
</div>'; </div>";
$ret .= "</div>\n"; $ret .= "</div>\n";
$ret .= "<input type='hidden' name='{$name}' id='{$name_id}' value='{$default}' />"; $ret .= "<input type='hidden' name='{$name}' id='{$name_id}' value='{$default}' />";
@@ -1589,7 +1589,7 @@ class e_form
$ret = ''; $ret = '';
if($sc_parameters['data'] === 'array') if(isset($sc_parameters['data']) && $sc_parameters['data'] === 'array')
{ {
// Do not use $this->hidden() method - as it will break 'id' value. // Do not use $this->hidden() method - as it will break 'id' value.
$ret .= "<input type='hidden' name='".$name."[path]' id='".$this->name2id($name. '[path]')."' value='".varset($default['path'])."' />"; $ret .= "<input type='hidden' name='".$name."[path]' id='".$this->name2id($name. '[path]')."' value='".varset($default['path'])."' />";
@@ -5036,6 +5036,10 @@ var_dump($select_options);*/
public function renderValue($field, $value, $attributes, $id = 0) public function renderValue($field, $value, $attributes, $id = 0)
{ {
if(!empty($value) && !empty($attributes['data']) && ($attributes['data'] === 'array' || $attributes['data'] === 'json'))
{
$value = e107::unserialize($value);
}
if(!empty($attributes['multilan']) && is_array($value)) if(!empty($attributes['multilan']) && is_array($value))
{ {
@@ -5638,22 +5642,26 @@ var_dump($select_options);*/
case 'media': case 'media':
case 'images':
if(!empty($value) && $attributes['data'] === 'json') $firstItem = !empty($value[0]['path']) ? $value[0]['path'] : null; // display first item.
{ return e107::getMedia()->previewTag($firstItem, $parms);
$tmp = e107::unserialize($value);
$value = !empty($tmp[0]['path']) ? $tmp[0]['path'] : null; // display first item.
}
return e107::getMedia()->previewTag($value, $parms);
break; break;
case 'files': case 'files':
if(!empty($value) && !is_array($value))
{
return "Type 'files' must have a data type of 'array' or 'json'";
}
$ret = '<ol>'; $ret = '<ol>';
for ($i=0; $i < 5; $i++) for ($i=0; $i < 5; $i++)
{ {
//$k = $key.'['.$i.'][path]';
$ival = $value[$i]['path']; $ival = $value[$i]['path'];
if(empty($ival))
{
continue;
}
$ret .= '<li>'.$ival.'</li>'; $ret .= '<li>'.$ival.'</li>';
} }
$ret .= '</ol>'; $ret .= '</ol>';
@@ -5924,11 +5932,6 @@ var_dump($select_options);*/
$method = varset($attributes['field']); // prevents table alias in method names. ie. u.my_method. $method = varset($attributes['field']); // prevents table alias in method names. ie. u.my_method.
$_value = $value; $_value = $value;
if(!empty($attributes['data']) && $attributes['data'] === 'array') // FIXME @SecretR - please move this to where it should be.
{
$value = e107::unserialize($value); // (saved as array, return it as an array)
}
$meth = (!empty($attributes['method'])) ? $attributes['method'] : $method; $meth = (!empty($attributes['method'])) ? $attributes['method'] : $method;
if(strpos($meth,'::')!==false) if(strpos($meth,'::')!==false)
@@ -6105,6 +6108,12 @@ var_dump($select_options);*/
*/ */
public function renderElement($key, $value, $attributes, $required_data = array(), $id = 0) public function renderElement($key, $value, $attributes, $required_data = array(), $id = 0)
{ {
if(!empty($value) && !empty($attributes['data']) && ($attributes['data'] === 'array' || $attributes['data'] === 'json'))
{
$value = e107::unserialize($value);
}
$tp = e107::getParser(); $tp = e107::getParser();
$ret = ''; $ret = '';
@@ -6356,7 +6365,7 @@ var_dump($select_options);*/
break; break;
case 'images': case 'images':
// return print_a($value, true);
$ret = ''; $ret = '';
$label = varset($parms['label'], 'LAN_EDIT'); $label = varset($parms['label'], 'LAN_EDIT');
$max = varset($parms['max'],5); $max = varset($parms['max'],5);
@@ -6379,11 +6388,6 @@ var_dump($select_options);*/
$max = varset($parms['max'],1); $max = varset($parms['max'],1);
if(!empty($value) && $attributes['data'] === 'json')
{
$value = e107::unserialize($value);
}
$ret = "<div class='mediaselector-multi field-element-media'>"; $ret = "<div class='mediaselector-multi field-element-media'>";
for ($i=0; $i < $max; $i++) for ($i=0; $i < $max; $i++)
{ {
@@ -6399,8 +6403,10 @@ var_dump($select_options);*/
break; break;
case 'files': case 'files':
$label = varset($parms['label'], 'LAN_EDIT'); $label = varset($parms['label'], 'LAN_EDIT');
if($attributes['data'] === 'array') if(!empty($attributes['data']) && ($attributes['data'] === 'array' || $attributes['data'] === 'json'))
{ {
$parms['data'] = 'array'; $parms['data'] = 'array';
} }

View File

@@ -2108,7 +2108,7 @@ class e_front_model extends e_model
{ {
$d = $this->getDataFields(); $d = $this->getDataFields();
if(!empty($d[$key]) && ($d[$key] == 'array')) if(!empty($d[$key]) && ($d[$key] === 'array' || $d[$key] === 'json'))
{ {
return e107::unserialize($this->getData((string) $key, $default, $index)); return e107::unserialize($this->getData((string) $key, $default, $index));
} }

View File

@@ -1787,7 +1787,7 @@ class e_user extends e_user_model
$userlogin = new userlogin(); $userlogin = new userlogin();
if(e_PAGE === 'admin.php') if(defset('e_PAGE') === 'admin.php')
{ {
$userlogin->setSecureImageMode('admin'); // use the admin secure code pref. $userlogin->setSecureImageMode('admin'); // use the admin secure code pref.
} }

File diff suppressed because one or more lines are too long

View File

@@ -205,7 +205,7 @@ ul.checkboxes { display: inline-block; list-style: none; margin: 0; padding: 0;}
.has-feedback-left input { padding-left:30px; } .has-feedback-left input { padding-left:30px; }
.form-control[disabled], .form-control[readonly] { .form-control[disabled], .form-control[readonly] {
background-color: transparent; /*background-color: transparent;*/
box-shadow: none; box-shadow: none;
} }