| @@ -1,13 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace IvyForms\Common\Helpers; |
| 4 | 4 | |
| 5 | -// phpcs:disable PSR1.Files.SideEffects | |
| 6 | -if (!defined('ABSPATH')) { | |
| 7 | - exit; // Exit if accessed directly | |
| 8 | -} | |
| 9 | - | |
| 10 | 5 | use IvyForms\Common\Exceptions\ValidationException; |
| 11 | 6 | use IvyForms\Entity\FieldOptions\FieldOptions; |
| 12 | 7 | use IvyForms\Factory\FieldOptions\FieldOptionsFactory; |
| 13 | 8 | use IvyForms\Repository\FieldOptions\FieldOptionsRepositoryInterface; |
| @@ -105,12 +100,27 @@ | ||
| 105 | 100 | * @return bool |
| 106 | 101 | */ |
| 107 | 102 | public static function fieldTypeHasOptions(string $fieldType): bool |
| 108 | 103 | { |
| 109 | - return in_array($fieldType, ['radio', 'checkbox', 'select', 'multi-select'], true); | |
| 104 | + return in_array($fieldType, ['radio', 'checkbox', 'select', 'multi-select', 'product', 'rating'], true); | |
| 110 | 105 | } |
| 111 | 106 | |
| 112 | 107 | /** |
| 108 | + * Check if a field type is a security/CAPTCHA field. | |
| 109 | + * | |
| 110 | + * Security fields are used for bot/spam protection and should be excluded | |
| 111 | + * from stored entries, integration payloads, placeholder lists, and any | |
| 112 | + * other processing that targets user-submitted data. | |
| 113 | + * | |
| 114 | + * @param string $fieldType | |
| 115 | + * @return bool | |
| 116 | + */ | |
| 117 | + public static function isSecurityField(string $fieldType): bool | |
| 118 | + { | |
| 119 | + return in_array($fieldType, ['recaptcha', 'turnstile', 'hcaptcha'], true); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 113 | 123 | * Duplicate field options from one field to another. |
| 114 | 124 | * |
| 115 | 125 | * @param int $oldFieldId |
| 116 | 126 | * @param int $newFieldId |
| @@ -147,6 +157,25 @@ | ||
| 147 | 157 | 'field' |
| 148 | 158 | ); |
| 149 | 159 | $fieldData['htmlContent'] = $processedContent; |
| 150 | 160 | } |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Upload base64 images in rich text default values before form save. | |
| 165 | + * | |
| 166 | + * @param array<string, mixed> $fieldData Passed by reference; defaultValue modified in place | |
| 167 | + * @param ImageService $imageService | |
| 168 | + * @return void | |
| 169 | + */ | |
| 170 | + public static function processRichTextDefaultValue(array &$fieldData, ImageService $imageService): void | |
| 171 | + { | |
| 172 | + if (($fieldData['type'] ?? '') !== 'rich_text' || empty($fieldData['defaultValue'])) { | |
| 173 | + return; | |
| 174 | + } | |
| 175 | + | |
| 176 | + $fieldData['defaultValue'] = $imageService->processImagesInContent( | |
| 177 | + (string) $fieldData['defaultValue'], | |
| 178 | + 'field' | |
| 179 | + ); | |
| 151 | 180 | } |
| 152 | 181 | } |