| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\integrations\services\Cloudflare; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\meta\Form; |
| | | use JVBase\base\Site; |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = Cache::for('forms', WEEK_IN_SECONDS); |
| | | $this->cache = Cache::for('forms', null, WEEK_IN_SECONDS); |
| | | |
| | | if (JVB_TESTING) { |
| | | $this->cache->flush(); |
| | | } |
| | | |
| | | // Initialize forms from filter |
| | | $this->forms = $this->registerForms(); |
| | | $this->form_contact = apply_filters('jvb_form_contact', ''); |
| | |
| | | |
| | | // Enqueue Turnstile if needed |
| | | if (Site::hasIntegration('cloudflare')) { |
| | | $cloudflare = JVB()->connect('cloudflare'); |
| | | $cloudflare = Cloudflare::getInstance(); |
| | | if ($cloudflare->isSetUp()) { |
| | | $cloudflare->enqueueTurnstileScripts(); |
| | | } |
| | |
| | | $forms = apply_filters('jvb_register_forms', $default_forms); |
| | | |
| | | // Process forms to ensure they have proper structure |
| | | $processed_forms = []; |
| | | foreach ($forms as $form_key => $form_config) { |
| | | $processed_forms[$form_key] = $this->processFormConfig($form_config); |
| | | } |
| | | $processed_forms = array_map(function ($form_config) { |
| | | return $this->processFormConfig($form_config); |
| | | }, $forms); |
| | | |
| | | return $processed_forms; |
| | | } |
| | |
| | | return '<div class="jvb-form-error">No valid form type selected. Please edit this block and select a form type.</div>'; |
| | | } |
| | | |
| | | $cache_key = $this->cache->generateKey($block); |
| | | return $this->cache->remember( |
| | | $cache_key, |
| | | $block, |
| | | function() use ($form_type, $block) { |
| | | return $this->renderForm($form_type, $block); |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | $cloudflare = JVB()->connect('cloudflare'); |
| | | $cloudflare = Cloudflare::getInstance(); |
| | | if ($cloudflare->isSetUp()) { |
| | | $cloudflare->renderTurnstile(); |
| | | } |