builder
4 weeks ago
form-migrator
4 weeks ago
plugin-updates
8 years ago
settings
4 weeks ago
views
4 weeks ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
1 week ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
4 weeks ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
4 weeks ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
4 weeks ago
class-evf-admin-menus.php
4 weeks ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
1 year ago
class-evf-admin-settings.php
4 weeks ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
4 weeks ago
class-evf-admin-form-templates.php
116 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Form Templates |
| 4 | * |
| 5 | * @package EverestForms /Admin/Form Templates |
| 6 | * @version 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; // Exit if accessed directly. |
| 11 | } |
| 12 | /** |
| 13 | * EVF_Admin_Form_Templates class |
| 14 | */ |
| 15 | class EVF_Admin_Form_Templates { |
| 16 | |
| 17 | /** |
| 18 | * Get default template.q |
| 19 | * |
| 20 | * @return array |
| 21 | */ |
| 22 | private static function get_default_template() { |
| 23 | $template = new stdClass(); |
| 24 | $template->title = __( 'Start From Scratch', 'everest-forms' ); |
| 25 | $template->slug = 'blank'; |
| 26 | $template->image = untrailingslashit( plugin_dir_url( EVF_PLUGIN_FILE ) ) . '/assets/images/templates/blank.png'; |
| 27 | $template->plan = array( 'free', 'premium' ); |
| 28 | |
| 29 | return array( $template ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get section content for the template screen. |
| 34 | * |
| 35 | * @return array |
| 36 | */ |
| 37 | public static function get_template_data() { |
| 38 | $template_data = get_transient( 'evf_template_section_list' ); |
| 39 | $template_data = get_transient( 'evf_template_section_list' ); |
| 40 | |
| 41 | $template_url = 'https://assets.wpeverest.com/everestforms/forms/'; |
| 42 | |
| 43 | if ( false === $template_data ) { |
| 44 | |
| 45 | $template_json_url = $template_url . 'templates1.json'; |
| 46 | try { |
| 47 | $content = wp_remote_get( $template_json_url ); |
| 48 | $content_json = wp_remote_retrieve_body( $content ); |
| 49 | |
| 50 | $template_data = json_decode( $content_json ); |
| 51 | } catch ( Exception $e ) { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | // Removing directory so the templates can be reinitialized. |
| 56 | $folder_path = untrailingslashit( plugin_dir_path( EVF_PLUGIN_FILE ) . '/assets/images/templates' ); |
| 57 | if ( isset( $template_data->templates[0]->templates ) ) { |
| 58 | |
| 59 | foreach ( $template_data->templates[0]->templates as $template_tuple ) { |
| 60 | |
| 61 | $image_url = isset( $template_tuple->image ) ? $template_tuple->image : ( $template_url . 'images/' . $template_tuple->slug . '.png' ); |
| 62 | |
| 63 | $template_tuple->image = $image_url; |
| 64 | |
| 65 | $temp_name = explode( '/', $image_url ); |
| 66 | $relative_path = $folder_path . '/' . end( $temp_name ); |
| 67 | $exists = file_exists( $relative_path ); |
| 68 | |
| 69 | // If it exists, utilize this file instead of remote file. |
| 70 | if ( $exists ) { |
| 71 | $template_tuple->image = untrailingslashit( plugin_dir_url( EVF_PLUGIN_FILE ) ) . '/assets/images/templates/' . untrailingslashit( $template_tuple->slug ) . '.png'; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | set_transient( 'evf_template_section_list', $template_data, WEEK_IN_SECONDS ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return isset( $template_data->templates ) ? apply_filters( 'everest_forms_template_section_data', $template_data->templates ) : self::get_default_template(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Load the template view. |
| 84 | * |
| 85 | * @since 1.0.0 |
| 86 | */ |
| 87 | public static function load_template_view() { |
| 88 | $use_react_header = apply_filters( 'everest_forms_use_react_header', true, 'forms' ); |
| 89 | if ( $use_react_header ) { |
| 90 | include __DIR__ . '/views/html-admin-header-skeleton.php'; |
| 91 | } |
| 92 | |
| 93 | $templates_js_path = evf()->plugin_path() . '/dist/templates.min.js'; |
| 94 | $templates_js_ver = file_exists( $templates_js_path ) ? filemtime( $templates_js_path ) : EVF_VERSION; |
| 95 | wp_register_script( 'evf-templates', plugins_url( 'dist/templates.min.js', EVF_PLUGIN_FILE ), array( 'wp-element', 'react', 'react-dom', 'wp-api-fetch', 'wp-i18n', 'wp-blocks' ), $templates_js_ver, true ); |
| 96 | wp_localize_script( |
| 97 | 'evf-templates', |
| 98 | 'evf_templates_script', |
| 99 | array( |
| 100 | 'security' => wp_create_nonce( 'wp_rest' ), |
| 101 | 'restURL' => rest_url(), |
| 102 | // ThemeGrill AI Cloud (Python gateway) — used by the Create with AI flow. |
| 103 | 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 104 | 'aiNonce' => wp_create_nonce( 'evf_ai_nonce' ), |
| 105 | 'aiRegistered' => class_exists( 'EVF_AI_Registration' ) ? EVF_AI_Registration::is_registered() : false, |
| 106 | 'aiTier' => class_exists( 'EVF_AI_Registration' ) ? EVF_AI_Registration::get_tier() : 'free', |
| 107 | // Create with AI is disabled on local / development sites (gateway cannot verify ownership). |
| 108 | 'aiEnabled' => class_exists( 'EVF_AI_Registration' ) && ! EVF_AI_Registration::is_local_site(), |
| 109 | ) |
| 110 | ); |
| 111 | wp_enqueue_script( 'evf-templates' ); |
| 112 | echo '<div id="evf-templates"></div>'; |
| 113 | } |
| 114 | |
| 115 | } |
| 116 |