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']:'')
+ ));
}
}
?>
diff --git a/bl-kernel/admin/views/new-content.php b/bl-kernel/admin/views/new-content.php
index e6d34893..9b3568dd 100644
--- a/bl-kernel/admin/views/new-content.php
+++ b/bl-kernel/admin/views/new-content.php
@@ -79,7 +79,7 @@ echo Bootstrap::formOpen(array(
- customFields()!="{}"): ?>
+ customFields())): ?>
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']:'')
+ ));
}
}
?>
diff --git a/bl-kernel/admin/views/settings.php b/bl-kernel/admin/views/settings.php
index 318522da..1f40b631 100644
--- a/bl-kernel/admin/views/settings.php
+++ b/bl-kernel/admin/views/settings.php
@@ -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'=>'',
diff --git a/bl-kernel/boot/site.php b/bl-kernel/boot/site.php
index 4925da23..3ecf62ba 100644
--- a/bl-kernel/boot/site.php
+++ b/bl-kernel/boot/site.php
@@ -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');
diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php
index e46ba13a..8ad6c240 100644
--- a/bl-kernel/pages.class.php
+++ b/bl-kernel/pages.class.php
@@ -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;
diff --git a/bl-kernel/site.class.php b/bl-kernel/site.class.php
index d1b0e8e2..7cc93e77 100644
--- a/bl-kernel/site.class.php
+++ b/bl-kernel/site.class.php
@@ -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);
}
}
\ No newline at end of file