diff --git a/bl-kernel/admin/views/edit-content.php b/bl-kernel/admin/views/edit-content.php
index d1e0bf08..20bdfca1 100644
--- a/bl-kernel/admin/views/edit-content.php
+++ b/bl-kernel/admin/views/edit-content.php
@@ -89,6 +89,9 @@ echo Bootstrap::formOpen(array(
@@ -284,6 +287,27 @@ echo Bootstrap::formOpen(array(
});
+
+ customFields()!="{}"): ?>
+
+ customFields(), true);
+ foreach($customFields as $field=>$options) {
+ if ($options['type']=="string") {
+ echo Bootstrap::formInputTextBlock(array(
+ 'name'=>'custom['.$field.']',
+ 'value'=>(isset($options['default'])?$options['default']:''),
+ 'tip'=>(isset($options['tip'])?$options['tip']:''),
+ 'label'=>(isset($options['label'])?$options['label']:''),
+ 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
+ 'value'=>$page->custom($field)
+ ));
+ }
+ }
+ ?>
+
+
+
@@ -260,6 +263,24 @@ echo Bootstrap::formOpen(array(
});
+ customFields()!="{}"): ?>
+
+ customFields(), true);
+ foreach($customFields as $field=>$options) {
+ if ($options['type']=="string") {
+ echo Bootstrap::formInputTextBlock(array(
+ 'name'=>'custom['.$field.']',
+ 'value'=>(isset($options['default'])?$options['default']:''),
+ 'tip'=>(isset($options['tip'])?$options['tip']:''),
+ 'label'=>(isset($options['label'])?$options['label']:''),
+ 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:'')
+ ));
+ }
+ }
+ ?>
+
+
@@ -433,6 +434,15 @@
'placeholder'=>'',
'tip'=>''
));
+
+ echo Bootstrap::formInputText(array(
+ 'name'=>'dribbble',
+ 'label'=>'Dribbble',
+ 'value'=>$site->dribbble(),
+ 'class'=>'',
+ 'placeholder'=>'',
+ 'tip'=>''
+ ));
?>
@@ -515,6 +525,23 @@
?>
+
+
+ $L->g('Custom fields')));
+
+ echo Bootstrap::formTextarea(array(
+ 'name'=>'customFields',
+ 'label'=>$L->g('Custom'),
+ 'value'=>$site->customFields(),
+ 'class'=>'',
+ 'placeholder'=>'',
+ 'tip'=>'',
+ 'rows'=>15
+ ));
+ ?>
+
+
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/functions.php b/bl-kernel/functions.php
index 227142d9..db2e587b 100644
--- a/bl-kernel/functions.php
+++ b/bl-kernel/functions.php
@@ -575,6 +575,15 @@ function editSettings($args) {
$args['extremeFriendly'] = (($args['extremeFriendly']=='true')?true:false);
}
+ if (isset($args['customFields'])) {
+ // Custom fields need to be JSON format valid, also the empty JSON need to be "{}"
+ json_decode($args['customFields']);
+ if (json_last_error() != JSON_ERROR_NONE) {
+ return false;
+ }
+ $pages->setCustomFields($args['customFields']);
+ }
+
if ($site->set($args)) {
// Check current order-by if changed it reorder the content
if ($site->orderBy()!=ORDER_BY) {
diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php
index ace3b77d..e46ba13a 100644
--- a/bl-kernel/pages.class.php
+++ b/bl-kernel/pages.class.php
@@ -64,6 +64,14 @@ class Pages extends dbJSON {
$tags = $args['tags'];
}
$finalValue = $this->generateTags($tags);
+ } elseif ($field=='custom') {
+ if (isset($args['custom'])) {
+ foreach ($args['custom'] as $customField=>$customValue) {
+ $row['custom'][$customField]['value'] = Sanitize::html($customValue);
+ }
+ unset($args['custom']);
+ continue;
+ }
} elseif (isset($args[$field])) {
// Sanitize if will be stored on database
$finalValue = Sanitize::html($args[$field]);
@@ -168,6 +176,14 @@ class Pages extends dbJSON {
foreach ($this->dbFields as $field=>$value) {
if ( ($field=='tags') && isset($args['tags'])) {
$finalValue = $this->generateTags($args['tags']);
+ } elseif ($field=='custom') {
+ if (isset($args['custom'])) {
+ foreach ($args['custom'] as $customField=>$customValue) {
+ $row['custom'][$customField]['value'] = Sanitize::html($customValue);
+ }
+ unset($args['custom']);
+ continue;
+ }
} elseif (isset($args[$field])) {
// Sanitize if will be stored on database
$finalValue = Sanitize::html($args[$field]);
@@ -581,8 +597,6 @@ class Pages extends dbJSON {
return $list;
}
-
-
public function sortBy()
{
if (ORDER_BY=='date') {
@@ -772,4 +786,30 @@ class Pages extends dbJSON {
return $this->save();
}
+ // Insert custom fields to all the pages in the database
+ // The structure for the custom fields need to be a valid JSON format
+ // The custom fields are incremental, this means the custom fields are never deleted
+ // The pages only store the value of the custom field, the structure of the custom fields are in the database site.php
+ public function setCustomFields($fields)
+ {
+ $customFields = json_decode($fields, true);
+ if (json_last_error() != JSON_ERROR_NONE) {
+ return false;
+ }
+ foreach ($this->db as $pageKey=>$pageFields) {
+ foreach ($customFields as $customField=>$customValues) {
+ if (!isset($pageFields['custom'][$customField])) {
+ $defaultValue = '';
+ if (isset($customValues['default'])) {
+ $defaultValue = $customValues['default'];
+ }
+ $this->db[$pageKey]['custom'][$customField]['value'] = $defaultValue;
+ }
+ }
+ }
+
+ return $this->save();
+ }
+
+
}
diff --git a/bl-kernel/pagex.class.php b/bl-kernel/pagex.class.php
index f55066db..60da93c0 100644
--- a/bl-kernel/pagex.class.php
+++ b/bl-kernel/pagex.class.php
@@ -563,4 +563,17 @@ class Page {
return $string ? implode(', ', $string) . ' ago' : 'Just now';
}
+
+ // Returns the value from the field, false if the fields doesn't exists
+ // If you set the $option as TRUE, the function returns an array with all the values of the field
+ public function custom($field, $options=false)
+ {
+ if (isset($this->vars['custom'][$field])) {
+ if ($options) {
+ return $this->vars['custom'][$field];
+ }
+ return $this->vars['custom'][$field]['value'];
+ }
+ return false;
+ }
}
diff --git a/bl-kernel/site.class.php b/bl-kernel/site.class.php
index f5958ecc..d1b0e8e2 100644
--- a/bl-kernel/site.class.php
+++ b/bl-kernel/site.class.php
@@ -31,6 +31,7 @@ class Site extends dbJSON {
'gitlab'=> '',
'linkedin'=> '',
'mastodon'=> '',
+ 'dribbble'=> '',
'orderBy'=> 'date', // date or position
'extremeFriendly'=> true,
'autosaveInterval'=> 2, // minutes
@@ -44,7 +45,8 @@ class Site extends dbJSON {
'thumbnailHeight'=> 400, // px
'thumbnailQuality'=> 100,
'logo'=> '',
- 'markdownParser'=> true
+ 'markdownParser'=> true,
+ 'customFields'=> '{}'
);
function __construct()
@@ -185,6 +187,11 @@ class Site extends dbJSON {
return $this->getField('mastodon');
}
+ public function dribbble()
+ {
+ return $this->getField('dribbble');
+ }
+
public function orderBy()
{
return $this->getField('orderBy');
@@ -394,4 +401,10 @@ class Site extends dbJSON {
return date_default_timezone_set($timezone);
}
-}
+ // Returns the custom fields
+ public function customFields()
+ {
+ return Sanitize::htmlDecode($this->getField('customFields'));
+ }
+
+}
\ No newline at end of file