From bff6b9dab5f7a33b9b0d1799a70c5e3bb05cda0f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Dec 2020 11:22:12 +0200 Subject: [PATCH 01/14] Fixed state of the checkbox if no value is provided --- CHANGELOG.md | 7 ++++++- templates/forms/fields/checkbox/checkbox.html.twig | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc69efa7..1774ed48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v4.3.1 +## mm/dd/2020 + +1. [](#bugfix) + * Fixed state of the checkbox if no value is provided + # v4.3.0 ## 12/14/2020 @@ -8,7 +14,6 @@ 1. [](#bugfix) * Fix admin access check [#463](https://github.com/getgrav/grav-plugin-form/pull/463) - # v4.2.0 ## 12/02/2020 diff --git a/templates/forms/fields/checkbox/checkbox.html.twig b/templates/forms/fields/checkbox/checkbox.html.twig index 53c29db1..18250cbb 100644 --- a/templates/forms/fields/checkbox/checkbox.html.twig +++ b/templates/forms/fields/checkbox/checkbox.html.twig @@ -11,7 +11,7 @@ name="{{ (scope ~ field.name)|fieldName }}" value="{{ field.value ?? '1' }}" type="checkbox" - {% if value == field.value ?? '1' %} checked="checked" {% endif %} + {% if value == (field.value ?? '1') %} checked="checked" {% endif %} {# input attribute structures #} {% block input_attributes %} From 14810f3c98bbf351e9d6b0cd3ec80f71a53f9a74 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Dec 2020 11:28:29 +0200 Subject: [PATCH 02/14] Replace method_exists() call with is_callable() --- classes/Forms.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Forms.php b/classes/Forms.php index 3332efb7..fe11befe 100644 --- a/classes/Forms.php +++ b/classes/Forms.php @@ -52,7 +52,7 @@ public function createPageForm(PageInterface $page, string $name = null, array $ $factory = $this->types[$type] ?? null; if ($factory) { - if (method_exists($factory, 'createFormForPage')) { + if (is_callable([$factory, 'createFormForPage'])) { return $factory->createFormForPage($page, $name, $form); } From b3e80f88b9936e7848f0e2cee914060d09713bc8 Mon Sep 17 00:00:00 2001 From: Nico Date: Mon, 28 Dec 2020 19:12:51 +0100 Subject: [PATCH 03/14] https url (#467) --- blueprints.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints.yaml b/blueprints.yaml index 0be6e058..3df04291 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -8,7 +8,7 @@ icon: check-square author: name: Team Grav email: devs@getgrav.org - url: http://getgrav.org + url: https://getgrav.org keywords: plugin, form homepage: https://github.com/getgrav/grav-plugin-form bugs: https://github.com/getgrav/grav-plugin-form/issues From f61725c9e1f79cf8d414fc2f7a6a62d234cc8715 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 8 Jan 2021 10:34:23 +0200 Subject: [PATCH 04/14] Fixed evaluating default value in `hidden` field (thanks @NicoHood) --- CHANGELOG.md | 1 + templates/forms/fields/hidden/hidden.html.twig | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1774ed48..54bc7e53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#bugfix) * Fixed state of the checkbox if no value is provided + * Fixed evaluating default value in `hidden` field (thanks @NicoHood) # v4.3.0 ## 12/14/2020 diff --git a/templates/forms/fields/hidden/hidden.html.twig b/templates/forms/fields/hidden/hidden.html.twig index 0335fb8d..8506fa59 100644 --- a/templates/forms/fields/hidden/hidden.html.twig +++ b/templates/forms/fields/hidden/hidden.html.twig @@ -2,8 +2,7 @@ {% block field %} -{% set value = value ?: field.value|default(field.default) %} -{% set value = field.evaluate ? evaluate(value) : value %} +{% set value = value ?: (field.value ?? (field.evaluate ? evaluate(field.default) : field.default)) %} {% set input_value = value is iterable ? value|join(',') : value|string %} From 98a8ec0a2ff58b5b30b21ff7bb17cc3b48e64ded Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 8 Jan 2021 11:16:50 +0200 Subject: [PATCH 05/14] Fixed default value to come from the `Form` in overridable field (thanks @NicoHood) --- CHANGELOG.md | 1 + templates/forms/default/field.html.twig | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54bc7e53..91a6f59b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#bugfix) * Fixed state of the checkbox if no value is provided * Fixed evaluating default value in `hidden` field (thanks @NicoHood) + * Fixed default value to come from the `Form` in overridable field (thanks @NicoHood) # v4.3.0 ## 12/14/2020 diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index e47b2c90..faa00949 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -7,18 +7,19 @@ {% set vertical = field.style == 'vertical' %} {% if not blueprints or (blueprints.schema.type(field.type)['input@'] ?? true) is same as(true) %} + {% set default = field.default %} {% set toggleable = field.toggleable ?? false %} {% if toggleable %} {% set originalValue = originalValue is defined ? originalValue : value %} {% set toggleableChecked = originalValue is not null %} {% elseif field.overridable %} {% set toggleable = true %} - {% set default = form.getDefaultValue(field.name) ?? field.default %} + {% set default = form.getDefaultValue(field.name) ?? default %} {% set toggleableChecked = value is not null and value != default %} {% endif %} {% set cookie_name = 'forms-' ~ form.name ~ '-' ~ field.name %} - {% set value = value ?? (get_cookie(cookie_name) is not null ? get_cookie(cookie_name) : field.default) %} + {% set value = value ?? (get_cookie(cookie_name) is not null ? get_cookie(cookie_name) : default) %} {% if (field.yaml or field.validate.type == 'yaml') and value is iterable %} {% set value = value|toYaml %} From 075a4d1b4d46d5ba75226d2801d93924a6f89e85 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 11 Jan 2021 11:28:46 +0200 Subject: [PATCH 06/14] Phpdoc fixes --- classes/Form.php | 192 +++++++++++++++++++++++++++++++--------------- classes/Forms.php | 36 +++++++++ form.php | 115 ++++++++++++++++----------- 3 files changed, 239 insertions(+), 104 deletions(-) diff --git a/classes/Form.php b/classes/Form.php index f2445357..dad2974b 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -1,6 +1,7 @@ page = $page ? $page->route() : '/'; // Add form specific rules. - if (!empty($this->items['rules']) && \is_array($this->items['rules'])) { + if (!empty($this->items['rules']) && is_array($this->items['rules'])) { $this->rules += $this->items['rules']; } // Set form name if not set. - if ($name && !\is_int($name)) { + if ($name && !is_int($name)) { $this->items['name'] = $name; } elseif (empty($this->items['name'])) { $this->items['name'] = $slug; @@ -210,6 +205,10 @@ public function initialize() return $this; } + /** + * @param FormFlash $flash + * @return void + */ protected function setAllFiles(FormFlash $flash) { if (!$flash->exists()) { @@ -252,6 +251,8 @@ protected function setAllFiles(FormFlash $flash) /** * Reset form. + * + * @return void */ public function reset(): void { @@ -272,6 +273,12 @@ public function reset(): void $grav->fireEvent('onFormInitialized', new Event(['form' => $this])); } + /** + * @param string $name + * @param mixed|null $default + * @param string|null $separator + * @return mixed + */ public function get($name, $default = null, $separator = null) { switch (strtolower($name)) { @@ -294,13 +301,16 @@ public function get($name, $default = null, $separator = null) return $this->traitGet($name, $default, $separator); } + /** + * @return string + */ public function getAction(): string { return $this->items['action'] ?? $this->page; } /** - * @param $message + * @param string $message * @param string $type * @todo Type not used */ @@ -309,6 +319,12 @@ public function setMessage($message, $type = 'error') $this->setError($message); } + /** + * @param string $name + * @param mixed $value + * @param string|null $separator + * @return Form + */ public function set($name, $value, $separator = null) { switch (strtolower($name)) { @@ -405,6 +421,7 @@ public function getBlueprint(): Blueprint * Allow overriding of fields. * * @param array $fields + * @return void */ public function setFields(array $fields = []) { @@ -422,7 +439,7 @@ public function setFields(array $fields = []) * Get value of given variable (or all values). * First look in the $data array, fallback to the $values array * - * @param string $name + * @param string|null $name * @param bool $fallback * @return mixed */ @@ -446,7 +463,7 @@ public function value($name = null, $fallback = false) /** * Get value of given variable (or all values). * - * @param string $name + * @param string|null $name * @return mixed */ public function data($name = null) @@ -457,8 +474,9 @@ public function data($name = null) /** * Set value of given variable in the values array * - * @param string $name + * @param string|null $name * @param mixed $value + * @return void */ public function setValue($name = null, $value = '') { @@ -472,9 +490,8 @@ public function setValue($name = null, $value = '') /** * Set value of given variable in the data array * - * @param string $name + * @param string|null $name * @param string $value - * * @return bool */ public function setData($name = null, $value = '') @@ -488,6 +505,10 @@ public function setData($name = null, $value = '') return true; } + /** + * @param array $array + * @return void + */ public function setAllData($array): void { $callable = function () { @@ -668,7 +689,7 @@ public function uploadFiles() if ($task === 'cropupload') { $crop = $post['crop']; - if (\is_string($crop)) { + if (is_string($crop)) { $crop = json_decode($crop, true); } $success = $flash->cropFile($field, $filename, $upload, $crop); @@ -689,7 +710,7 @@ public function uploadFiles() // json_response $json_response = [ 'status' => 'success', - 'session' => \json_encode([ + 'session' => json_encode([ 'sessionField' => base64_encode($url), 'path' => $path, 'field' => $settings->name, @@ -753,6 +774,8 @@ public function getFileUploadError(int $error, Language $language = null): strin /** * Removes a file from the flash object session, before it gets saved. + * + * @return void */ public function filesSessionRemove(): void { @@ -761,7 +784,7 @@ public function filesSessionRemove(): void $filename = $this->values->get('filename'); if (!isset($field, $filename)) { - throw new \RuntimeException('Bad Request: name and/or filename are missing', 400); + throw new RuntimeException('Bad Request: name and/or filename are missing', 400); } $this->removeFlashUpload($filename, $field); @@ -772,8 +795,10 @@ public function filesSessionRemove(): void $this->sendJsonResponse($callable); } - - public function storeState(): void + /** + * @return void + */ + public function storeState() { $callable = function (): array { $this->updateFlashData($this->values->get('data') ?? []); @@ -784,7 +809,9 @@ public function storeState(): void $this->sendJsonResponse($callable); } - + /** + * @return void + */ public function clearState(): void { $callable = function (): array { @@ -798,6 +825,8 @@ public function clearState(): void /** * Handle form processing on POST action. + * + * @return void */ public function post() { @@ -862,7 +891,7 @@ public function post() if ($event->isPropagationStopped()) { return; } - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { $this->status = 'error'; $event = new Event(['form' => $this, 'message' => $e->getMessage(), 'messages' => []]); $grav->fireEvent('onFormValidationError', $event); @@ -879,10 +908,10 @@ public function post() $this->legacyUploads(); } - if (\is_array($process)) { + if (is_array($process)) { foreach ($process as $action => $data) { if (is_numeric($action)) { - $action = \key($data); + $action = key($data); $data = $data[$action]; } @@ -940,6 +969,7 @@ public function page(): PageInterface /** * Backwards compatibility * + * @return void * @deprecated 3.0 Calling $form->filter() is not needed anymore (does nothing) */ public function filter(): void @@ -948,6 +978,8 @@ public function filter(): void /** * Store form uploads to the final location. + * + * @return void */ public function copyFiles() { @@ -969,14 +1001,14 @@ public function copyFiles() if (!is_dir($folder) && !@mkdir($folder, 0777, true) && !is_dir($folder)) { $grav = Grav::instance(); - throw new \RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $upload->getClientFilename() . '"', $destination)); + throw new RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $upload->getClientFilename() . '"', $destination)); } try { $upload->moveTo($destination); - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { $grav = Grav::instance(); - throw new \RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $upload->getClientFilename() . '"', $destination)); + throw new RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $upload->getClientFilename() . '"', $destination)); } } } @@ -984,6 +1016,9 @@ public function copyFiles() $flash->clearFiles(); } + /** + * @return void + */ public function legacyUploads() { // Get flash object in order to save the files. @@ -1020,7 +1055,7 @@ public function legacyUploads() } else { user_error('Event onFormStoreUploads is deprecated.', E_USER_DEPRECATED); - if (\is_array($queue)) { + if (is_array($queue)) { foreach ($queue as $key => $files) { foreach ($files as $destination => $file) { $filesystem = Filesystem::getInstance(); @@ -1028,12 +1063,12 @@ public function legacyUploads() if (!is_dir($folder) && !@mkdir($folder, 0777, true) && !is_dir($folder)) { $grav = Grav::instance(); - throw new \RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $file['tmp_name'] . '"', $destination)); + throw new RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $file['tmp_name'] . '"', $destination)); } if (!rename($file['tmp_name'], $destination)) { $grav = Grav::instance(); - throw new \RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $file['tmp_name'] . '"', $destination)); + throw new RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $file['tmp_name'] . '"', $destination)); } if (file_exists($file['tmp_name'] . '.yaml')) { @@ -1051,6 +1086,10 @@ public function legacyUploads() } } + /** + * @param string $path + * @return string + */ public function getPagePathFromToken($path) { return Utils::getPagePathFromToken($path, $this->getPage()); @@ -1067,8 +1106,8 @@ public function getFileUploadAjaxRoute(): ?Route } /** - * @param $field - * @param $filename + * @param string $field + * @param string $filename * @return Route|null */ public function getFileDeleteAjaxRoute($field, $filename): ?Route @@ -1078,6 +1117,10 @@ public function getFileDeleteAjaxRoute($field, $filename): ?Route return $route; } + /** + * @param int|null $code + * @return int|mixed + */ public function responseCode($code = null) { if ($code) { @@ -1086,6 +1129,9 @@ public function responseCode($code = null) return $this->response_code; } + /** + * @return array + */ public function doSerialize() { return $this->doTraitSerialize() + [ @@ -1099,6 +1145,10 @@ public function doSerialize() ]; } + /** + * @param array $data + * @return void + */ public function doUnserialize(array $data) { $this->items = $data['items']; @@ -1149,6 +1199,10 @@ public static function getMaxFilesize($mbytes = false) return $form_filesize; } + /** + * @param callable $callable + * @return void + */ protected function sendJsonResponse(callable $callable) { $grav = Grav::instance(); @@ -1161,7 +1215,7 @@ protected function sendJsonResponse(callable $callable) $post['data'] = $this->decodeData($post['data'] ?? []); if (empty($post['form-nonce']) || !Utils::verifyNonce($post['form-nonce'], 'form')) { - throw new \RuntimeException('Bad Request: Nonce is missing or invalid', 400); + throw new RuntimeException('Bad Request: Nonce is missing or invalid', 400); } $this->values = new Data($post); @@ -1179,6 +1233,7 @@ protected function sendJsonResponse(callable $callable) * * @param string $filename * @param string|null $field + * @return void */ protected function removeFlashUpload(string $filename, string $field = null) { @@ -1191,6 +1246,7 @@ protected function removeFlashUpload(string $filename, string $field = null) * Store updated data into flash object. * * @param array $data + * @return void */ protected function updateFlashData(array $data) { @@ -1210,11 +1266,20 @@ protected function updateFlashData(array $data) $flash->save(); } + /** + * @param array $data + * @param array $files + * @return void + */ protected function doSubmit(array $data, array $files) { return; } + /** + * @param array $fields + * @return array + */ protected function processFields($fields) { $types = Grav::instance()['plugins']->formFieldTypes; @@ -1237,7 +1302,7 @@ protected function processFields($fields) } // Recursively process children - if (isset($value['fields']) && \is_array($value['fields'])) { + if (isset($value['fields']) && is_array($value['fields'])) { $value['fields'] = $this->processFields($value['fields']); } @@ -1247,6 +1312,11 @@ protected function processFields($fields) return $return; } + /** + * @param string $key + * @param array $files + * @return void + */ protected function setImageField($key, $files) { $field = $this->data->blueprints()->schema()->get($key); @@ -1264,7 +1334,7 @@ protected function setImageField($key, $files) */ protected function decodeData($data) { - if (!\is_array($data)) { + if (!is_array($data)) { return []; } @@ -1289,10 +1359,10 @@ protected function cleanDataKeys($source = []) { $out = []; - if (\is_array($source)) { + if (is_array($source)) { foreach ($source as $key => $value) { $key = str_replace(['%5B', '%5D'], ['[', ']'], $key); - if (\is_array($value)) { + if (is_array($value)) { $out[$key] = $this->cleanDataKeys($value); } else { $out[$key] = $value; @@ -1312,9 +1382,9 @@ protected function cleanDataKeys($source = []) */ protected function normalizeFiles($data, $key = '') { - $files = new \stdClass(); + $files = new stdClass(); $files->field = $key; - $files->file = new \stdClass(); + $files->file = new stdClass(); foreach ($data as $fieldName => $fieldValue) { // Since Files Upload are always happening via Ajax diff --git a/classes/Forms.php b/classes/Forms.php index fe11befe..66abb489 100644 --- a/classes/Forms.php +++ b/classes/Forms.php @@ -13,31 +13,54 @@ class Forms /** @var FormInterface|null */ private $form; + /** + * Forms constructor. + */ public function __construct() { $this->registerType('form', new FormFactory()); } + /** + * @param string $type + * @param FormFactoryInterface $factory + */ public function registerType(string $type, FormFactoryInterface $factory): void { $this->types[$type] = $factory; } + /** + * @param string $type + */ public function unregisterType($type): void { unset($this->types[$type]); } + /** + * @param string $type + * @return bool + */ public function hasType(string $type): bool { return isset($this->types[$type]); } + /** + * @return array + */ public function getTypes(): array { return array_keys($this->types); } + /** + * @param PageInterface $page + * @param string|null $name + * @param array|null $form + * @return FormInterface|null + */ public function createPageForm(PageInterface $page, string $name = null, array $form = null): ?FormInterface { if (null === $form) { @@ -57,6 +80,7 @@ public function createPageForm(PageInterface $page, string $name = null, array $ } if ($page instanceof Page) { + // @phpstan-ignore-next-line return $factory->createPageForm($page, $name, $form); } } @@ -64,16 +88,28 @@ public function createPageForm(PageInterface $page, string $name = null, array $ return null; } + /** + * @return FormInterface|null + */ public function getActiveForm(): ?FormInterface { return $this->form; } + /** + * @param FormInterface $form + * @return void + */ public function setActiveForm(FormInterface $form): void { $this->form = $form; } + /** + * @param PageInterface $page + * @param string|null $name + * @return array + */ protected function getPageParameters(PageInterface $page, ?string $name): array { $forms = $page->forms(); diff --git a/form.php b/form.php index 29f073f8..49e4c5f8 100644 --- a/form.php +++ b/form.php @@ -3,6 +3,8 @@ namespace Grav\Plugin; use Composer\Autoload\ClassLoader; +use DateTime; +use Exception; use Grav\Common\Data\ValidationException; use Grav\Common\Debugger; use Grav\Common\Filesystem\Folder; @@ -21,10 +23,18 @@ use Grav\Plugin\Form\Forms; use ReCaptcha\ReCaptcha; use ReCaptcha\RequestMethod\CurlPost; +use RecursiveArrayIterator; +use RecursiveIteratorIterator; use RocketTheme\Toolbox\File\JsonFile; use RocketTheme\Toolbox\File\YamlFile; use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\Event\Event; +use RuntimeException; +use function count; +use function function_exists; +use function is_array; +use function is_string; +use function sprintf; /** * Class FormPlugin @@ -39,19 +49,14 @@ class FormPlugin extends Plugin /** @var Form */ protected $form; - /** @var array */ protected $forms = []; - /** @var array */ protected $flat_forms = []; - /** @var array */ protected $active_forms = []; - /** @var array */ protected $json_response = []; - /** @var bool */ protected $recache_forms = false; @@ -93,8 +98,10 @@ public function autoload() /** * Initialize forms from cache if possible + * + * @return void */ - public function onPluginsInitialized() + public function onPluginsInitialized(): void { // Backwards compatibility for plugins that use forms. class_alias(Form::class, 'Grav\Plugin\Form'); @@ -134,7 +141,11 @@ class_alias(Form::class, 'Grav\Plugin\Form'); ]); } - public function onGetPageTemplates(Event $event) + /** + * @param Event $event + * @return void + */ + public function onGetPageTemplates(Event $event): void { /** @var Types $types */ $types = $event->types; @@ -145,8 +156,9 @@ public function onGetPageTemplates(Event $event) * Process forms after page header processing, but before caching * * @param Event $e + * @return void */ - public function onPageProcessed(Event $e) + public function onPageProcessed(Event $e): void { /** @var PageInterface $page */ $page = $e['page']; @@ -188,16 +200,20 @@ public function onPageProcessed(Event $e) /** * Initialize all the forms + * + * @return void */ - public function onPagesInitialized() + public function onPagesInitialized(): void { $this->loadCachedForms(); } /** * Catches form processing if user posts the form. + * + * @return void */ - public function onPageInitialized() + public function onPageInitialized(): void { $submitted = false; $this->json_response = []; @@ -278,7 +294,7 @@ public function onPageInitialized() // Discard any previously uploaded files session. // and if there were any uploaded file, remove them from the filesystem if ($flash = $this->grav['session']->getFlashObject('files-upload')) { - $flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash)); + $flash = new RecursiveIteratorIterator(new RecursiveArrayIterator($flash)); foreach ($flash as $key => $value) { if ($key !== 'tmp_name') { continue; @@ -326,8 +342,10 @@ public function onPageInitialized() /** * Add simple `forms()` Twig function + * + * @return void */ - public function onTwigInitialized() + public function onTwigInitialized(): void { $this->grav['twig']->twig()->addFunction( new \Twig_SimpleFunction('forms', [$this, 'getForm']) @@ -342,8 +360,10 @@ public function onTwigInitialized() /** * Add current directory to twig lookup paths. + * + * @return void */ - public function onTwigTemplatePaths() + public function onTwigTemplatePaths(): void { $this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; } @@ -352,8 +372,9 @@ public function onTwigTemplatePaths() * Make form accessible from twig. * * @param Event $event + * @return void */ - public function onTwigVariables(Event $event = null) + public function onTwigVariables(Event $event = null): void { if ($event && isset($event['page'])) { $page = $event['page']; @@ -378,9 +399,10 @@ public function onTwigVariables(Event $event = null) * Handle form processing instructions. * * @param Event $event - * @throws \Exception + * @return void + * @throws Exception */ - public function onFormProcessed(Event $event) + public function onFormProcessed(Event $event): void { /** @var Form $form */ $form = $event['form']; @@ -456,7 +478,7 @@ public function onFormProcessed(Event $event) $format = $params['format'] ?? 'Y-m-d H:i:s'; $blueprint = $form->value()->blueprints(); $blueprint->set('form/fields/timestamp', ['name' => 'timestamp', 'label' => $label, 'type' => 'hidden']); - $now = new \DateTime('now'); + $now = new DateTime('now'); $date_string = $now->format($format); $form->setFields($blueprint->fields()); $form->setData('timestamp', $date_string); @@ -522,7 +544,7 @@ public function onFormProcessed(Event $event) $page = $pages->dispatch($route, true); if (!$page) { - throw new \RuntimeException('Display page not found. Please check the page exists.', 400); + throw new RuntimeException('Display page not found. Please check the page exists.', 400); } unset($this->grav['page']); @@ -551,7 +573,7 @@ public function onFormProcessed(Event $event) if (!$filename) { if ($operation === 'add') { - throw new \RuntimeException('Form save: \'operation: add\' is only supported with a static filename'); + throw new RuntimeException('Form save: \'operation: add\' is only supported with a static filename'); } $filename = $prefix . $this->udate($format, $raw_format) . $postfix . $ext; @@ -574,7 +596,7 @@ public function onFormProcessed(Event $event) if (!empty($params['raw']) || !empty($params['template'])) { // Save data as it comes from the form. if ($operation === 'add') { - throw new \RuntimeException('Form save: \'operation: add\' is not supported for raw files'); + throw new RuntimeException('Form save: \'operation: add\' is not supported for raw files'); } switch ($ext) { case '.yaml': @@ -584,7 +606,7 @@ public function onFormProcessed(Event $event) $file = JsonFile::instance($fullFileName); break; default: - throw new \RuntimeException('Form save: Unsupported RAW file format, please use either yaml or json'); + throw new RuntimeException('Form save: Unsupported RAW file format, please use either yaml or json'); } $content = $form->getData(); @@ -634,7 +656,7 @@ public function onFormProcessed(Event $event) if (file_exists($fullFileName)) { $data = Yaml::parse($file->content()); - if (\count($data) > 0) { + if (count($data) > 0) { array_unshift($data, $vars); } else { $data[] = $vars; @@ -650,11 +672,11 @@ public function onFormProcessed(Event $event) case 'call': $callable = $params; - if (\is_array($callable) && !method_exists($callable[0], $callable[1])) { - throw new \RuntimeException('Form cannot be processed (method does not exist)'); + if (is_array($callable) && !method_exists($callable[0], $callable[1])) { + throw new RuntimeException('Form cannot be processed (method does not exist)'); } - if (\is_string($callable) && !\function_exists($callable)) { - throw new \RuntimeException('Form cannot be processed (function does not exist)'); + if (is_string($callable) && !function_exists($callable)) { + throw new RuntimeException('Form cannot be processed (function does not exist)'); } $callable($form); @@ -666,8 +688,9 @@ public function onFormProcessed(Event $event) * Custom field logic can go in here * * @param Event $event + * @return void */ - public function onFormValidationProcessed(Event $event) + public function onFormValidationProcessed(Event $event): void { // special check for honeypot field foreach ($event['form']->fields() as $field) { @@ -681,9 +704,10 @@ public function onFormValidationProcessed(Event $event) * Handle form validation error * * @param Event $event An event object - * @throws \Exception + * @return void + * @throws Exception */ - public function onFormValidationError(Event $event) + public function onFormValidationError(Event $event): void { $form = $event['form']; if (isset($event['message'])) { @@ -716,6 +740,7 @@ public function onFormValidationError(Event $event) * * @param string|null $page_route * @param FormInterface|null $form + * @return void */ public function addForm(?string $page_route, ?FormInterface $form) { @@ -737,15 +762,14 @@ public function addForm(?string $page_route, ?FormInterface $form) * function to get a specific form * * @param null|array|string $data optional form `name` - * * @return FormInterface|null */ public function getForm($data = null) { - if (\is_array($data)) { + if (is_array($data)) { $form_name = $data['name'] ?? null; $page_route = $data['route'] ?? null; - } elseif (\is_string($data)) { + } elseif (is_string($data)) { $form_name = $data; $page_route = null; } else { @@ -765,12 +789,12 @@ public function getForm($data = null) $forms = $this->forms[$page_route]; $first_form = reset($forms) ?: null; return $first_form; - } else { - //No form on this route. Try looking up in the current page first - /** @var Forms $forms */ - $forms = $this->grav['forms']; - return $forms->createPageForm($this->grav['page']); } + + //No form on this route. Try looking up in the current page first + /** @var Forms $forms */ + $forms = $this->grav['forms']; + return $forms->createPageForm($this->grav['page']); } // return the form you are looking for if available @@ -853,6 +877,7 @@ public function getFormFieldTypes() * - fillWithCurrentDateTime * * @param Form $form + * @return void */ protected function process($form) { @@ -878,7 +903,7 @@ protected function getCurrentPageRoute() /** * Retrieve a form based on the form name * - * @param $form_name + * @param string $form_name * @return mixed */ protected function getFormByName($form_name) @@ -953,6 +978,8 @@ protected function shouldProcessForm() /** * Flatten the forms array into something that can be more easily searched + * + * @return void */ protected function flattenForms() { @@ -1031,13 +1058,15 @@ protected function createForm(PageInterface $page, $name = null, $form = null) /** * Load cached forms and merge with any currently found forms + * + * @return void */ protected function loadCachedForms() { // Get and set the cache of forms if it exists try { [$forms] = $this->grav['cache']->fetch($this->getFormCacheId()); - } catch (\Exception $e) { + } catch (Exception $e) { // Couldn't fetch cached forms. $forms = null; @@ -1046,7 +1075,7 @@ protected function loadCachedForms() $debugger->addMessage(sprintf('Unserializing cached forms failed: %s', $e->getMessage()), 'error'); } - if (!\is_array($forms)) { + if (!is_array($forms)) { return; } @@ -1059,6 +1088,8 @@ protected function loadCachedForms() /** * Save the current state of the forms + * + * @return void */ protected function saveCachedForms() { @@ -1084,7 +1115,6 @@ protected function getFormCacheId() * * @param string $format * @param bool $raw - * * @return string */ protected function udate($format = 'u', $raw = false) @@ -1099,7 +1129,6 @@ protected function udate($format = 'u', $raw = false) $timestamp = floor($utimestamp); $milliseconds = round(($utimestamp - $timestamp) * 1000000); - return date(preg_replace('`(? Date: Mon, 11 Jan 2021 11:30:34 +0200 Subject: [PATCH 07/14] Updated deprecated `Twig_SimpleFunction` code --- CHANGELOG.md | 2 ++ form.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a6f59b..35026c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v4.3.1 ## mm/dd/2020 +1. [](#improved) + * Updated deprecated `Twig_SimpleFunction` code 1. [](#bugfix) * Fixed state of the checkbox if no value is provided * Fixed evaluating default value in `hidden` field (thanks @NicoHood) diff --git a/form.php b/form.php index 49e4c5f8..bae80f94 100644 --- a/form.php +++ b/form.php @@ -30,6 +30,7 @@ use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\Event\Event; use RuntimeException; +use Twig\TwigFunction; use function count; use function function_exists; use function is_array; @@ -348,7 +349,7 @@ public function onPageInitialized(): void public function onTwigInitialized(): void { $this->grav['twig']->twig()->addFunction( - new \Twig_SimpleFunction('forms', [$this, 'getForm']) + new TwigFunction('forms', [$this, 'getForm']) ); $this->grav['twig']->twig()->getExtension('Twig_Extension_Core')->setEscaper('yaml', function ($twig, $string, $charset) { From fdbefb210bad6d863e8bee118c5d926f9539ff9b Mon Sep 17 00:00:00 2001 From: Nico Date: Mon, 11 Jan 2021 22:09:49 +0100 Subject: [PATCH 08/14] Fix translations for select field in data template (#475) --- templates/forms/default/data.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/forms/default/data.html.twig b/templates/forms/default/data.html.twig index 4a186c38..729157f4 100644 --- a/templates/forms/default/data.html.twig +++ b/templates/forms/default/data.html.twig @@ -34,11 +34,11 @@ {% set use_keys = field.use is defined and field.use == 'keys' %} {% for key, val in value %} {% set index = (use_keys ? key : val) %} -
  • {{ field.options[index]|e }}
  • +
  • {{ field.options[index]|t|e }}
  • {% endfor %} {% else %} - {{ field.options[value]|e }} + {{ field.options[value]|t|e }} {% endif %} {% else %} {% set value = form.value(scope ~ field.name) %} From af87ce0695b6eeedd99533edc6e2300d498c1398 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 12 Jan 2021 16:06:14 +0200 Subject: [PATCH 09/14] Fixed evaluating default value in `hidden` field (part 2) --- templates/forms/default/field.html.twig | 6 +++++- templates/forms/fields/hidden/hidden.html.twig | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index faa00949..b2b0f27c 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -19,7 +19,11 @@ {% endif %} {% set cookie_name = 'forms-' ~ form.name ~ '-' ~ field.name %} - {% set value = value ?? (get_cookie(cookie_name) is not null ? get_cookie(cookie_name) : default) %} + {% set value = value ?? get_cookie(cookie_name) %} + {% set has_value = value is not same as(null) %} + {% if not has_value %} + {% set value = default %} + {% endif %} {% if (field.yaml or field.validate.type == 'yaml') and value is iterable %} {% set value = value|toYaml %} diff --git a/templates/forms/fields/hidden/hidden.html.twig b/templates/forms/fields/hidden/hidden.html.twig index 8506fa59..3968c8a6 100644 --- a/templates/forms/fields/hidden/hidden.html.twig +++ b/templates/forms/fields/hidden/hidden.html.twig @@ -2,7 +2,13 @@ {% block field %} -{% set value = value ?: (field.value ?? (field.evaluate ? evaluate(field.default) : field.default)) %} +{# Used if the field is being used directly outside of form #} +{% set value = value ?? field.value ?? (field.evaluate ? evaluate(field.default) : field.default) %} + +{# Evaluate support for the form #} +{% if not has_value and value and field.evaluate %} + {% set value = evaluate(value) %} +{% endif %} {% set input_value = value is iterable ? value|join(',') : value|string %} From 24b6310754764ab7c3fadbb143a37300fc299785 Mon Sep 17 00:00:00 2001 From: Nico Date: Wed, 13 Jan 2021 17:38:19 +0100 Subject: [PATCH 10/14] Use correct default --- templates/forms/default/field.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index b2b0f27c..d8b90b21 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -114,7 +114,7 @@ {% block global_attributes %} data-grav-field="{{ field.type }}" data-grav-disabled="{{ toggleable and toggleableChecked }}" - data-grav-default="{{ field.default|json_encode()|e('html_attr') }}" + data-grav-default="{{ default|json_encode()|e('html_attr') }}" {% endblock %} {% block input_attributes %} From f99e0a893931e6c99e531a1cfb74b869b924a5d4 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 14 Jan 2021 19:16:52 +0100 Subject: [PATCH 11/14] Fix disabling of client_side_validation (#482) If `client_side_validation` is set to `false`, the `default` filter will always use the default of `true`. --- templates/forms/default/form.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/forms/default/form.html.twig b/templates/forms/default/form.html.twig index 2675b6c0..f301fe76 100644 --- a/templates/forms/default/form.html.twig +++ b/templates/forms/default/form.html.twig @@ -9,7 +9,7 @@ {% set multipart = '' %} {% set blueprints = blueprints ?? form.blueprint() %} {% set method = form.method|upper|default('POST') %} -{% set client_side_validation = form.client_side_validation is not null ? form.client_side_validation : config.plugins.form.client_side_validation|default(true) %} +{% set client_side_validation = form.client_side_validation is not null ? form.client_side_validation : config.plugins.form.client_side_validation|defined(true) %} {% set inline_errors = form.inline_errors is not null ? form.inline_errors : config.plugins.form.inline_errors(false) %} {% set data = data ?? form.data %} From 7218d1ed76f0efbb2bb88efda9607afff5c7f3a0 Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Sat, 23 Jan 2021 18:06:33 +0200 Subject: [PATCH 12/14] Add Lithuanian translation Translated from EN --- languages.yaml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/languages.yaml b/languages.yaml index ca2e4b77..3a730130 100644 --- a/languages.yaml +++ b/languages.yaml @@ -821,3 +821,77 @@ da: DESTINATION_NOT_SPECIFIED: "Destination ikke angivet" INVALID_MIME_TYPE: "MIME typen %s for filen %s er ikke accepteret." INVALID_FILE_EXTENSION: "Filendelsen for filen %s er ikke accepteret." +lt: + PLUGIN_FORM: + NOT_VALIDATED: "Forma nepatikrinta. Trūksta vieno ar daugiau privalomų laukų." + NONCE_NOT_VALIDATED: "Oi, įvyko klaida. Prašome patikrinti įvestus duomenis ir pateikti formą iš naujo." + FILES: "Bylų įkėlimas" + FORM_ALREADY_SUBMITTED: "Ši forma jau buvo pateikta." + ALLOW_MULTIPLE: "Leisti daugiau nei vieną bylą" + ALLOW_MULTIPLE_HELP: "Leidžia pasirinkti daugiau nei vieną bylą įkėlimui." + DESTINATION: "Tikslas" + DESTINATION_HELP: "Vieta, kur bylos turėtų būti įkeltos" + ACCEPT: "Leidžiami MIME tipai" + ACCEPT_HELP: "MIME tipų sąrašas, kuriuos galima įkelti" + ERROR_VALIDATING_CAPTCHA: "reCAPTCHA apsauga aptiko problemų pateikiant formą" + DATA_SUMMARY: "Čia yra santrauka to, ką mums parašėte:" + NO_FORM_DATA: "Nėra formos duomenų" + RECAPTCHA: "reCAPTCHA" + RECAPTCHA_VERSION: "Versija" + RECAPTCHA_VERSION_V2_CHECKBOX: "v2 - žymimasis langelis" + RECAPTCHA_VERSION_V2_INVISIBLE: "v2 - nematoma" + RECAPTCHA_VERSION_V3_LATEST: "v3 - naujausia" + RECAPTCHA_THEME: "Tema" + RECAPTCHA_THEME_LIGHT: "Šviesi tema" + RECAPTCHA_THEME_DARK: "Tamsi tema" + RECAPTCHA_SITE_KEY: "Puslapio raktas" + RECAPTCHA_SITE_KEY_HELP: "Daugiau informacijos - https://developers.google.com/recaptcha" + RECAPTCHA_SECRET_KEY: "Slaptas raktas" + RECAPTCHA_SECRET_KEY_HELP: "Daugiau informacijos - https://developers.google.com/recaptcha" + GENERAL: "Bendra" + USE_BUILT_IN_CSS: "Naudoti įdiegtą CSS" + USE_INLINE_CSS: "Naudoti įterptą (inline) CSS" + FILEUPLOAD_PREVENT_SELF: 'Negalima naudoti "%s" už puslapių ribų.' + FILEUPLOAD_UNABLE_TO_UPLOAD: 'Nepavyko įkelti bylos %s: %s' + FILEUPLOAD_UNABLE_TO_MOVE: 'Nepavyko perkelti bylos iš %s į "%s"' + FILEUPLOAD_ERR_OK: 'Klaidos nėra, byla įkelta sėkmingai' + FILEUPLOAD_ERR_INI_SIZE: 'Įkelta byla viršija maksimalų įkėlimo dydį' + FILEUPLOAD_ERR_FORM_SIZE: 'Įkelta byla viršija HTML nurodytą MAX_FILE_SIZE direktyvą' + FILEUPLOAD_ERR_PARTIAL: 'Įkeliama byla buvo įkelta tik dalinai' + FILEUPLOAD_ERR_NO_FILE: 'Nebuvo įkelta jokia byla' + FILEUPLOAD_ERR_NO_TMP_DIR: 'Nerastas laikinasis katalogas' + FILEUPLOAD_ERR_CANT_WRITE: 'Nepavyko įrašyti bylos į diską' + FILEUPLOAD_ERR_EXTENSION: 'PHP plėtinys sustabdė bylos įkėlimą' + FILEUPLOAD_ERR_UNKNOWN: 'Nežinoma bylos įkėlimo klaida' + DROPZONE_CANCEL_UPLOAD: 'Atšaukti įkėlimą' + DROPZONE_CANCEL_UPLOAD_CONFIRMATION: 'Ar tikrai norite atšaukti šį įkėlimą?' + DROPZONE_DEFAULT_MESSAGE: 'Tempkite bylas čia arba paspauskite šioje zonoje' + DROPZONE_FALLBACK_MESSAGE: 'Jūsų naršyklė nepalaiko bylų įtempimo (drag and drop).' + DROPZONE_FALLBACK_TEXT: 'Prašome bylų įkėlimui naudoti žemiau esantį atsarginį variantą, kaip senais laikais.' + DROPZONE_FILE_TOO_BIG: 'Byla per didelė ({{filesize}}MiB). Maks. dydis: {{maxFilesize}}MiB.' + DROPZONE_INVALID_FILE_TYPE: "Negalite įkelti šio tipo bylų." + DROPZONE_MAX_FILES_EXCEEDED: "Nebegalite įkelti daugiau bylų." + DROPZONE_REMOVE_FILE: "Šalinti bylą" + DROPZONE_REMOVE_FILE_CONFIRMATION: 'Ar tikrai norite ištrinti šią bylą?' + DROPZONE_RESPONSE_ERROR: "Serveris atsakė su {{statusCode}} kodu." + YES: "Taip" + NO: "Ne" + REFRESH_PREVENTION: "Atnaujinimo apsauga" + REFRESH_PREVENTION_HELP: "Naudoti formos unikalų ID, kad būtų sustabdytas formos pakartotinis apdorojimas atnaujinus puslapį" + LIMIT: "Riba" + LIMIT_HELP: "Maksimalus viename lauke leidžiamų bylų kiekis (privaloma leisti daugiau nei vieną)" + FILESIZE: "Maks. bylos dydis" + FILESIZE_HELP: "Maksimalus leidžiamas bylos dydis (MB), 0 = naudoti sistemos pagal nutylėjimą" + AVOID_OVERWRITING: "Išvengti perrašymo" + AVOID_OVERWRITING_HELP: "Neleisti perrašyti bylų tuo pačiu pavadinimu. Bus pridėtas datos priešdėlis" + RANDOM_NAME: "Atsitiktinis pavadinimas" + RANDOM_NAME_HELP: "Generuoti atsitiktinį 15-os simbolių ilgio pavadinimą įkeliamoms byloms" + CLIENT_SIDE_VALIDATION: "Tikrinimas kliento pusėje" + CLIENT_SIDE_VALIDATION_HELP: "Pagal nutylėjimą formos naudos HTML5 kliento tikrinimą kaip pirminį" + INLINE_ERRORS: "Įterptos klaidos" + INLINE_ERRORS_HELP: "Pravartu su išjungtu 'tikrinimu kliento pusėje' - parodo kontekstines formos klaidas" + RESOLUTION_MIN: "{{attr}} buvo mažiau nei minimalus {{min}}px
    " + RESOLUTION_MAX: "{{attr}} buvo daugiau nei maksimalus {{max}}px
    " + DESTINATION_NOT_SPECIFIED: "Nenurodytas tikslas" + INVALID_MIME_TYPE: "MIME tipas %s bylai %s nepriimtinas." + INVALID_FILE_EXTENSION: "Bylos išplėtimas bylai %s nepriimtinas." From 80861da9342774f9f888ddca4dd15238f14187af Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2021 18:03:31 -0700 Subject: [PATCH 13/14] composer update --- composer.lock | 18 +- vendor/composer/ClassLoader.php | 10 +- vendor/composer/InstalledVersions.php | 228 ++++++++++++++++++ vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_real.php | 7 +- vendor/composer/autoload_static.php | 1 + vendor/composer/installed.json | 112 +++++---- vendor/composer/installed.php | 33 +++ vendor/composer/platform_check.php | 26 ++ vendor/google/recaptcha/README.md | 4 +- .../recaptcha/src/ReCaptcha/ReCaptcha.php | 2 +- .../ReCaptcha/RequestMethod/SocketPost.php | 4 +- .../RequestMethod/SocketPostTest.php | 6 +- 13 files changed, 381 insertions(+), 71 deletions(-) create mode 100644 vendor/composer/InstalledVersions.php create mode 100644 vendor/composer/installed.php create mode 100644 vendor/composer/platform_check.php diff --git a/composer.lock b/composer.lock index 273dc268..80fbb205 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "google/recaptcha", - "version": "1.2.3", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/google/recaptcha.git", - "reference": "98c4a6573b27e8b0990ea8789c74ea378795134c" + "reference": "614f25a9038be4f3f2da7cbfd778dc5b357d2419" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/google/recaptcha/zipball/98c4a6573b27e8b0990ea8789c74ea378795134c", - "reference": "98c4a6573b27e8b0990ea8789c74ea378795134c", + "url": "https://api.github.com/repos/google/recaptcha/zipball/614f25a9038be4f3f2da7cbfd778dc5b357d2419", + "reference": "614f25a9038be4f3f2da7cbfd778dc5b357d2419", "shasum": "" }, "require": { @@ -51,7 +51,12 @@ "recaptcha", "spam" ], - "time": "2019-08-16T15:48:25+00:00" + "support": { + "forum": "https://groups.google.com/forum/#!forum/recaptcha", + "issues": "https://github.com/google/recaptcha/issues", + "source": "https://github.com/google/recaptcha" + }, + "time": "2020-03-31T17:50:54+00:00" } ], "packages-dev": [], @@ -67,5 +72,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.1.3" - } + }, + "plugin-api-version": "2.0.0" } diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index dc02dfb1..1a58957d 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -37,8 +37,8 @@ * * @author Fabien Potencier * @author Jordi Boggiano - * @see http://www.php-fig.org/psr/psr-0/ - * @see http://www.php-fig.org/psr/psr-4/ + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ */ class ClassLoader { @@ -60,7 +60,7 @@ class ClassLoader public function getPrefixes() { if (!empty($this->prefixesPsr0)) { - return call_user_func_array('array_merge', $this->prefixesPsr0); + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); } return array(); @@ -279,7 +279,7 @@ public function isClassMapAuthoritative() */ public function setApcuPrefix($apcuPrefix) { - $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; } /** @@ -377,7 +377,7 @@ private function findFileWithExtension($class, $ext) $subPath = $class; while (false !== $lastPos = strrpos($subPath, '\\')) { $subPath = substr($subPath, 0, $lastPos); - $search = $subPath.'\\'; + $search = $subPath . '\\'; if (isset($this->prefixDirsPsr4[$search])) { $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); foreach ($this->prefixDirsPsr4[$search] as $dir) { diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php new file mode 100644 index 00000000..c8f1873a --- /dev/null +++ b/vendor/composer/InstalledVersions.php @@ -0,0 +1,228 @@ + + array ( + 'pretty_version' => 'dev-develop', + 'version' => 'dev-develop', + 'aliases' => + array ( + ), + 'reference' => '3eabc541329e2fc0b9fc2f23e5d5c58d5f0dbc15', + 'name' => 'getgrav/grav-plugin-form', + ), + 'versions' => + array ( + 'getgrav/grav-plugin-form' => + array ( + 'pretty_version' => 'dev-develop', + 'version' => 'dev-develop', + 'aliases' => + array ( + ), + 'reference' => '3eabc541329e2fc0b9fc2f23e5d5c58d5f0dbc15', + ), + 'google/recaptcha' => + array ( + 'pretty_version' => '1.2.4', + 'version' => '1.2.4.0', + 'aliases' => + array ( + ), + 'reference' => '614f25a9038be4f3f2da7cbfd778dc5b357d2419', + ), + ), +); + + + + + + + +public static function getInstalledPackages() +{ +return array_keys(self::$installed['versions']); +} + + + + + + + + + +public static function isInstalled($packageName) +{ +return isset(self::$installed['versions'][$packageName]); +} + + + + + + + + + + + + + + +public static function satisfies(VersionParser $parser, $packageName, $constraint) +{ +$constraint = $parser->parseConstraints($constraint); +$provided = $parser->parseConstraints(self::getVersionRanges($packageName)); + +return $provided->matches($constraint); +} + + + + + + + + + + +public static function getVersionRanges($packageName) +{ +if (!isset(self::$installed['versions'][$packageName])) { +throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); +} + +$ranges = array(); +if (isset(self::$installed['versions'][$packageName]['pretty_version'])) { +$ranges[] = self::$installed['versions'][$packageName]['pretty_version']; +} +if (array_key_exists('aliases', self::$installed['versions'][$packageName])) { +$ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']); +} +if (array_key_exists('replaced', self::$installed['versions'][$packageName])) { +$ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']); +} +if (array_key_exists('provided', self::$installed['versions'][$packageName])) { +$ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']); +} + +return implode(' || ', $ranges); +} + + + + + +public static function getVersion($packageName) +{ +if (!isset(self::$installed['versions'][$packageName])) { +throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); +} + +if (!isset(self::$installed['versions'][$packageName]['version'])) { +return null; +} + +return self::$installed['versions'][$packageName]['version']; +} + + + + + +public static function getPrettyVersion($packageName) +{ +if (!isset(self::$installed['versions'][$packageName])) { +throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); +} + +if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) { +return null; +} + +return self::$installed['versions'][$packageName]['pretty_version']; +} + + + + + +public static function getReference($packageName) +{ +if (!isset(self::$installed['versions'][$packageName])) { +throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); +} + +if (!isset(self::$installed['versions'][$packageName]['reference'])) { +return null; +} + +return self::$installed['versions'][$packageName]['reference']; +} + + + + + +public static function getRootPackage() +{ +return self::$installed['root']; +} + + + + + + + +public static function getRawData() +{ +return self::$installed; +} + + + + + + + + + + + + + + + + + + + +public static function reload($data) +{ +self::$installed = $data; +} +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 58c38337..9461b4bd 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -6,5 +6,6 @@ $baseDir = dirname($vendorDir); return array( + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 'Grav\\Plugin\\FormPlugin' => $baseDir . '/form.php', ); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index e9ea4f26..74c27c56 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -13,19 +13,24 @@ public static function loadClassLoader($class) } } + /** + * @return \Composer\Autoload\ClassLoader + */ public static function getLoader() { if (null !== self::$loader) { return self::$loader; } + require __DIR__ . '/platform_check.php'; + spl_autoload_register(array('ComposerAutoloaderInitd9f2f96e3ad6fd86ce688af0527a1d7b', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitd9f2f96e3ad6fd86ce688af0527a1d7b', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { - require_once __DIR__ . '/autoload_static.php'; + require __DIR__ . '/autoload_static.php'; call_user_func(\Composer\Autoload\ComposerStaticInitd9f2f96e3ad6fd86ce688af0527a1d7b::getInitializer($loader)); } else { diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index eda5edc0..9bae4382 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -29,6 +29,7 @@ class ComposerStaticInitd9f2f96e3ad6fd86ce688af0527a1d7b ); public static $classMap = array ( + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 'Grav\\Plugin\\FormPlugin' => __DIR__ . '/../..' . '/form.php', ); diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index faaf4f2b..af9c6a10 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1,51 +1,61 @@ -[ - { - "name": "google/recaptcha", - "version": "1.2.3", - "version_normalized": "1.2.3.0", - "source": { - "type": "git", - "url": "https://github.com/google/recaptcha.git", - "reference": "98c4a6573b27e8b0990ea8789c74ea378795134c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/google/recaptcha/zipball/98c4a6573b27e8b0990ea8789c74ea378795134c", - "reference": "98c4a6573b27e8b0990ea8789c74ea378795134c", - "shasum": "" - }, - "require": { - "php": ">=5.5" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.2.20|^2.15", - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^4.8.36|^5.7.27|^6.59|^7.5.11" - }, - "time": "2019-08-16T15:48:25+00:00", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-4": { - "ReCaptcha\\": "src/ReCaptcha" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Client library for reCAPTCHA, a free service that protects websites from spam and abuse.", - "homepage": "https://www.google.com/recaptcha/", - "keywords": [ - "Abuse", - "captcha", - "recaptcha", - "spam" - ] - } -] +{ + "packages": [ + { + "name": "google/recaptcha", + "version": "1.2.4", + "version_normalized": "1.2.4.0", + "source": { + "type": "git", + "url": "https://github.com/google/recaptcha.git", + "reference": "614f25a9038be4f3f2da7cbfd778dc5b357d2419" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/google/recaptcha/zipball/614f25a9038be4f3f2da7cbfd778dc5b357d2419", + "reference": "614f25a9038be4f3f2da7cbfd778dc5b357d2419", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.2.20|^2.15", + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^4.8.36|^5.7.27|^6.59|^7.5.11" + }, + "time": "2020-03-31T17:50:54+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "ReCaptcha\\": "src/ReCaptcha" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Client library for reCAPTCHA, a free service that protects websites from spam and abuse.", + "homepage": "https://www.google.com/recaptcha/", + "keywords": [ + "Abuse", + "captcha", + "recaptcha", + "spam" + ], + "support": { + "forum": "https://groups.google.com/forum/#!forum/recaptcha", + "issues": "https://github.com/google/recaptcha/issues", + "source": "https://github.com/google/recaptcha" + }, + "install-path": "../google/recaptcha" + } + ], + "dev": true, + "dev-package-names": [] +} diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php new file mode 100644 index 00000000..a465c2d1 --- /dev/null +++ b/vendor/composer/installed.php @@ -0,0 +1,33 @@ + + array ( + 'pretty_version' => 'dev-develop', + 'version' => 'dev-develop', + 'aliases' => + array ( + ), + 'reference' => '3eabc541329e2fc0b9fc2f23e5d5c58d5f0dbc15', + 'name' => 'getgrav/grav-plugin-form', + ), + 'versions' => + array ( + 'getgrav/grav-plugin-form' => + array ( + 'pretty_version' => 'dev-develop', + 'version' => 'dev-develop', + 'aliases' => + array ( + ), + 'reference' => '3eabc541329e2fc0b9fc2f23e5d5c58d5f0dbc15', + ), + 'google/recaptcha' => + array ( + 'pretty_version' => '1.2.4', + 'version' => '1.2.4.0', + 'aliases' => + array ( + ), + 'reference' => '614f25a9038be4f3f2da7cbfd778dc5b357d2419', + ), + ), +); diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php new file mode 100644 index 00000000..cd1bd2c5 --- /dev/null +++ b/vendor/composer/platform_check.php @@ -0,0 +1,26 @@ += 70103)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.1.3". You are running ' . PHP_VERSION . '.'; +} + +if ($issues) { + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); + } elseif (!headers_sent()) { + echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; + } + } + trigger_error( + 'Composer detected issues in your platform: ' . implode(' ', $issues), + E_USER_ERROR + ); +} diff --git a/vendor/google/recaptcha/README.md b/vendor/google/recaptcha/README.md index 4f056eb9..92e8deae 100644 --- a/vendor/google/recaptcha/README.md +++ b/vendor/google/recaptcha/README.md @@ -13,7 +13,7 @@ and v3. - reCAPTCHA: https://www.google.com/recaptcha - This repo: https://github.com/google/recaptcha - Hosted demo: https://recaptcha-demo.appspot.com/ -- Version: 1.2.3 +- Version: 1.2.4 - License: BSD, see [LICENSE](LICENSE) ## Installation @@ -89,7 +89,7 @@ The following methods are available: from an Android app. Again, you must do this if you have disabled "Domain/Package Name Validation" for your credentials. - `setExpectedAction($action)`: ensures the action matches for the v3 API. -- `setScoreThreshold($threshold)`: set a score theshold for responses from the +- `setScoreThreshold($threshold)`: set a score threshold for responses from the v3 API - `setChallengeTimeout($timeoutSeconds)`: set a timeout between the user passing the reCAPTCHA and your server processing it. diff --git a/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php b/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php index 177fa44c..31ec44a0 100644 --- a/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php +++ b/vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php @@ -43,7 +43,7 @@ class ReCaptcha * Version of this client library. * @const string */ - const VERSION = 'php_1.2.3'; + const VERSION = 'php_1.2.4'; /** * URL for reCAPTCHA siteverify API diff --git a/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php index 7edffb86..464bc28d 100644 --- a/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php +++ b/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php @@ -81,7 +81,7 @@ public function submit(RequestParameters $params) $content = $params->toQueryString(); - $request = "POST " . $urlParsed['path'] . " HTTP/1.1\r\n"; + $request = "POST " . $urlParsed['path'] . " HTTP/1.0\r\n"; $request .= "Host: " . $urlParsed['host'] . "\r\n"; $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; $request .= "Content-length: " . strlen($content) . "\r\n"; @@ -97,7 +97,7 @@ public function submit(RequestParameters $params) $this->socket->fclose(); - if (0 !== strpos($response, 'HTTP/1.1 200 OK')) { + if (0 !== strpos($response, 'HTTP/1.0 200 OK')) { return '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_RESPONSE.'"]}'; } diff --git a/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php index 8656be4c..d9e1ede2 100644 --- a/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php +++ b/vendor/google/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php @@ -53,7 +53,7 @@ public function testSubmitSuccess() ->method('fwrite'); $socket->expects($this->once()) ->method('fgets') - ->willReturn("HTTP/1.1 200 OK\n\nRESPONSEBODY"); + ->willReturn("HTTP/1.0 200 OK\n\nRESPONSEBODY"); $socket->expects($this->exactly(2)) ->method('feof') ->will($this->onConsecutiveCalls(false, true)); @@ -81,7 +81,7 @@ public function testOverrideSiteVerifyUrl() ->with($this->matchesRegularExpression('/^POST \/some\/path.*Host: over\.ride/s')); $socket->expects($this->once()) ->method('fgets') - ->willReturn("HTTP/1.1 200 OK\n\nRESPONSEBODY"); + ->willReturn("HTTP/1.0 200 OK\n\nRESPONSEBODY"); $socket->expects($this->exactly(2)) ->method('feof') ->will($this->onConsecutiveCalls(false, true)); @@ -107,7 +107,7 @@ public function testSubmitBadResponse() ->method('fwrite'); $socket->expects($this->once()) ->method('fgets') - ->willReturn("HTTP/1.1 500 NOPEn\\nBOBBINS"); + ->willReturn("HTTP/1.0 500 NOPEn\\nBOBBINS"); $socket->expects($this->exactly(2)) ->method('feof') ->will($this->onConsecutiveCalls(false, true)); From 20d6c8552a62b77302ed0ee5699e97c339135eb6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 31 Jan 2021 18:16:15 -0700 Subject: [PATCH 14/14] prepare for release --- CHANGELOG.md | 6 +++++- blueprints.yaml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35026c33..16878729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ # v4.3.1 -## mm/dd/2020 +## 01/31/2021 1. [](#improved) * Updated deprecated `Twig_SimpleFunction` code + * Added Lithuanian translation [#485](https://github.com/getgrav/grav-plugin-form/pull/485) 1. [](#bugfix) * Fixed state of the checkbox if no value is provided * Fixed evaluating default value in `hidden` field (thanks @NicoHood) * Fixed default value to come from the `Form` in overridable field (thanks @NicoHood) + * Fix for disabling `client_side_validation` [#482](https://github.com/getgrav/grav-plugin-form/pull/482) + * Fix for translations in `select` field in data template [#475](https://github.com/getgrav/grav-plugin-form/pull/475) + * PHPDoc fixes # v4.3.0 ## 12/14/2020 diff --git a/blueprints.yaml b/blueprints.yaml index 3df04291..f85e7cc1 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Form slug: form type: plugin -version: 4.3.0 +version: 4.3.1 testing: false description: Enables the forms handling icon: check-square