Custom fields: Boolean type
This commit is contained in:
parent
cc73f609e4
commit
72b6908899
@ -264,7 +264,7 @@ EOF;
|
||||
{
|
||||
$labelForCheckbox = isset($args['labelForCheckbox'])?$args['labelForCheckbox']:'';
|
||||
$placeholder = isset($args['placeholder'])?$args['placeholder']:'';
|
||||
$tip = isset($args['tip'])?$args['tip']:' ';
|
||||
$tip = isset($args['tip'])?'<small class="form-text text-muted">'.$args['tip'].'</small>':'';
|
||||
$value = isset($args['value'])?$args['value']:'';
|
||||
$name = $args['name'];
|
||||
$id = 'js'.$name;
|
||||
@ -273,7 +273,7 @@ EOF;
|
||||
}
|
||||
$disabled = isset($args['disabled'])?'disabled':'';
|
||||
|
||||
$class = 'form-group';
|
||||
$class = 'form-group m-0';
|
||||
if (isset($args['class'])) {
|
||||
$class = $class.' '.$args['class'];
|
||||
}
|
||||
@ -289,14 +289,15 @@ EOF;
|
||||
}
|
||||
|
||||
$checked = $args['checked']?'checked':'';
|
||||
$value = $checked?'1':'0';
|
||||
|
||||
return <<<EOF
|
||||
<div class="$class">
|
||||
$label
|
||||
<div class="form-check">
|
||||
<input name="$name" class="form-check-input" type="checkbox" id="$id" $checked>
|
||||
<input type="hidden" name="$name" value="$value"><input id="$id" type="checkbox" class="form-check-input" onclick="this.previousSibling.value=1-this.previousSibling.value" $checked>
|
||||
<label class="form-check-label" for="$id">$labelForCheckbox</label>
|
||||
<small class="form-text text-muted">$tip</small>
|
||||
$tip
|
||||
</div>
|
||||
</div>
|
||||
EOF;
|
||||
|
@ -89,7 +89,7 @@ echo Bootstrap::formOpen(array(
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
<a class="nav-link active show" id="nav-general-tab" data-toggle="tab" href="#nav-general" role="tab" aria-controls="general"><?php $L->p('General') ?></a>
|
||||
<a class="nav-link" id="nav-advanced-tab" data-toggle="tab" href="#nav-advanced" role="tab" aria-controls="advanced"><?php $L->p('Advanced') ?></a>
|
||||
<?php if ($site->customFields()!="{}"): ?>
|
||||
<?php if (!empty($site->customFields())): ?>
|
||||
<a class="nav-link" id="nav-custom-tab" data-toggle="tab" href="#nav-custom" role="tab" aria-controls="custom"><?php $L->p('Custom') ?></a>
|
||||
<?php endif ?>
|
||||
<a class="nav-link" id="nav-seo-tab" data-toggle="tab" href="#nav-seo" role="tab" aria-controls="seo"><?php $L->p('SEO') ?></a>
|
||||
@ -288,10 +288,10 @@ echo Bootstrap::formOpen(array(
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<?php if ($site->customFields()!="{}"): ?>
|
||||
<?php if (!empty($site->customFields())): ?>
|
||||
<div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab">
|
||||
<?php
|
||||
$customFields = json_decode($site->customFields(), true);
|
||||
$customFields = $site->customFields();
|
||||
foreach($customFields as $field=>$options) {
|
||||
if ($options['type']=="string") {
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
@ -302,6 +302,14 @@ echo Bootstrap::formOpen(array(
|
||||
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
|
||||
'value'=>$page->custom($field)
|
||||
));
|
||||
} elseif ($options['type']=="bool") {
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
'name'=>'custom['.$field.']',
|
||||
'label'=>(isset($options['label'])?$options['label']:''),
|
||||
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
|
||||
'checked'=>$page->custom($field),
|
||||
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'')
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -79,7 +79,7 @@ echo Bootstrap::formOpen(array(
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
<a class="nav-link active show" id="nav-general-tab" data-toggle="tab" href="#nav-general" role="tab" aria-controls="general"><?php $L->p('General') ?></a>
|
||||
<a class="nav-link" id="nav-advanced-tab" data-toggle="tab" href="#nav-advanced" role="tab" aria-controls="advanced"><?php $L->p('Advanced') ?></a>
|
||||
<?php if ($site->customFields()!="{}"): ?>
|
||||
<?php if (!empty($site->customFields())): ?>
|
||||
<a class="nav-link" id="nav-custom-tab" data-toggle="tab" href="#nav-custom" role="tab" aria-controls="custom"><?php $L->p('Custom') ?></a>
|
||||
<?php endif ?>
|
||||
<a class="nav-link" id="nav-seo-tab" data-toggle="tab" href="#nav-seo" role="tab" aria-controls="seo"><?php $L->p('SEO') ?></a>
|
||||
@ -263,19 +263,27 @@ echo Bootstrap::formOpen(array(
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<?php if ($site->customFields()!="{}"): ?>
|
||||
<?php if (!empty($site->customFields())): ?>
|
||||
<div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab">
|
||||
<?php
|
||||
$customFields = json_decode($site->customFields(), true);
|
||||
$customFields = $site->customFields();
|
||||
foreach($customFields as $field=>$options) {
|
||||
if ($options['type']=="string") {
|
||||
echo Bootstrap::formInputTextBlock(array(
|
||||
'name'=>'custom['.$field.']',
|
||||
'label'=>(isset($options['label'])?$options['label']:''),
|
||||
'value'=>(isset($options['default'])?$options['default']:''),
|
||||
'tip'=>(isset($options['tip'])?$options['tip']:''),
|
||||
'label'=>(isset($options['label'])?$options['label']:''),
|
||||
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:'')
|
||||
));
|
||||
} elseif ($options['type']=="bool") {
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
'name'=>'custom['.$field.']',
|
||||
'label'=>(isset($options['label'])?$options['label']:''),
|
||||
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
|
||||
'checked'=>(isset($options['checked'])?true:false),
|
||||
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'')
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -533,7 +533,7 @@
|
||||
echo Bootstrap::formTextarea(array(
|
||||
'name'=>'customFields',
|
||||
'label'=>$L->g('Custom'),
|
||||
'value'=>$site->customFields(),
|
||||
'value'=>json_encode($site->customFields(), JSON_PRETTY_PRINT),
|
||||
'class'=>'',
|
||||
'placeholder'=>'',
|
||||
'tip'=>'',
|
||||
|
@ -28,8 +28,6 @@ if (Sanitize::pathFile(PATH_THEMES, $site->theme().DS.'index.php')) {
|
||||
$L->p('Please check your theme configuration in the admin panel. Check for an active theme.');
|
||||
}
|
||||
|
||||
var_dump($page->custom('field3'));
|
||||
|
||||
// Plugins after site loaded
|
||||
Theme::plugins('afterSiteLoad');
|
||||
|
||||
|
@ -66,8 +66,13 @@ class Pages extends dbJSON {
|
||||
$finalValue = $this->generateTags($tags);
|
||||
} elseif ($field=='custom') {
|
||||
if (isset($args['custom'])) {
|
||||
global $site;
|
||||
$customFields = $site->customFields();
|
||||
foreach ($args['custom'] as $customField=>$customValue) {
|
||||
$row['custom'][$customField]['value'] = Sanitize::html($customValue);
|
||||
$html = Sanitize::html($customValue);
|
||||
// Store the custom field as defined type
|
||||
settype($html, $customFields[$customField]['type']);
|
||||
$row['custom'][$customField]['value'] = $html;
|
||||
}
|
||||
unset($args['custom']);
|
||||
continue;
|
||||
@ -79,6 +84,7 @@ class Pages extends dbJSON {
|
||||
// Default value for the field if not defined
|
||||
$finalValue = $value;
|
||||
}
|
||||
// Store the value as defined type
|
||||
settype($finalValue, gettype($value));
|
||||
$row[$field] = $finalValue;
|
||||
}
|
||||
@ -178,8 +184,13 @@ class Pages extends dbJSON {
|
||||
$finalValue = $this->generateTags($args['tags']);
|
||||
} elseif ($field=='custom') {
|
||||
if (isset($args['custom'])) {
|
||||
global $site;
|
||||
$customFields = $site->customFields();
|
||||
foreach ($args['custom'] as $customField=>$customValue) {
|
||||
$row['custom'][$customField]['value'] = Sanitize::html($customValue);
|
||||
$html = Sanitize::html($customValue);
|
||||
// Store the custom field as defined type
|
||||
settype($html, $customFields[$customField]['type']);
|
||||
$row['custom'][$customField]['value'] = $html;
|
||||
}
|
||||
unset($args['custom']);
|
||||
continue;
|
||||
|
@ -401,10 +401,11 @@ class Site extends dbJSON {
|
||||
return date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
// Returns the custom fields
|
||||
// Returns the custom fields as array
|
||||
public function customFields()
|
||||
{
|
||||
return Sanitize::htmlDecode($this->getField('customFields'));
|
||||
$customFields = Sanitize::htmlDecode($this->getField('customFields'));
|
||||
return json_decode($customFields, true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user