From 59f5d84c47a0e1291b350f2ade3b164f383e2a1c Mon Sep 17 00:00:00 2001 From: Prestasafe Date: Tue, 25 Jun 2024 16:56:03 +0200 Subject: [PATCH] secure field type date --- classes/prettyblocks/core/FieldCore.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/classes/prettyblocks/core/FieldCore.php b/classes/prettyblocks/core/FieldCore.php index a39c7f5b..010ea86b 100644 --- a/classes/prettyblocks/core/FieldCore.php +++ b/classes/prettyblocks/core/FieldCore.php @@ -39,6 +39,7 @@ class FieldCore public $allow_html = false; public $id_lang = 0; public $id_shop = 0; + public $options = []; /** * __construct @@ -144,6 +145,9 @@ public function compile() if ($this->force_default_value) { $data['force_default_value'] = $this->force_default_value; } + if($this->options) { + $data['options'] = $this->options; + } $data['value'] = $this->format(); @@ -196,7 +200,6 @@ public function getFormattedValue() public function format() { $method = 'formatField' . ucwords(str_replace('_', '', $this->type)); - if (method_exists($this, $method)) { return $this->{$method}(); } @@ -234,17 +237,23 @@ public function formatForFront() */ public function formatFieldDatepicker() { + $format = 'Y-m-d'; + // if(isset($this->options['dateFormat'])) { + // $format = $this->options['dateFormat']; + // } // if value exists in DB and new_value is empty if (!is_null($this->value) && is_null($this->new_value)) { - return \DateTime::createFromFormat('Y-m-d', $this->value)->format('Y-m-d'); + $date = \DateTime::createFromFormat($format, $this->value); + return $date ? $date->format($format) : date($format); } // if value doesn't exists in DB and new value is set if ($this->force_default_value && is_null($this->new_value)) { - return \DateTime::createFromFormat('Y-m-d', $this->default)->format('Y-m-d'); + $date = \DateTime::createFromFormat($format, $this->default); + return $date ? $date->format($format) : date($format); } - - // dump($this->new_value); - return \DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $this->new_value)->format('Y-m-d'); + // default format from vuedatepicker + $date = \DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $this->new_value); + return $date ? $date->format($format) : date($format); } /**