builder
2 years ago
plugin-updates
8 years ago
settings
2 years ago
views
2 years ago
class-evf-admin-addons.php
4 years ago
class-evf-admin-assets.php
2 years ago
class-evf-admin-builder.php
7 years ago
class-evf-admin-deactivation-feedback.php
3 years ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-entries-table-list.php
3 years ago
class-evf-admin-entries.php
4 years ago
class-evf-admin-form-templates.php
3 years ago
class-evf-admin-forms-table-list.php
3 years ago
class-evf-admin-forms.php
3 years ago
class-evf-admin-import-export.php
4 years ago
class-evf-admin-menus.php
2 years ago
class-evf-admin-notices.php
3 years ago
class-evf-admin-settings.php
2 years ago
class-evf-admin-tools.php
4 years ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 years ago
evf-admin-functions.php
3 years ago
class-evf-admin-form-templates.php
109 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. |
| 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 | |
| 40 | $template_url = 'https://d3m99fsxk070py.cloudfront.net/'; |
| 41 | |
| 42 | if ( false === $template_data ) { |
| 43 | |
| 44 | $template_json_url = $template_url . 'templates.json'; |
| 45 | try { |
| 46 | $content = wp_remote_get( $template_json_url ); |
| 47 | $content_json = wp_remote_retrieve_body( $content ); |
| 48 | |
| 49 | $template_data = json_decode( $content_json ); |
| 50 | } catch ( Exception $e ) { |
| 51 | |
| 52 | } |
| 53 | |
| 54 | // Removing directory so the templates can be reinitialized. |
| 55 | $folder_path = untrailingslashit( plugin_dir_path( EVF_PLUGIN_FILE ) . '/assets/images/templates' ); |
| 56 | if ( isset( $template_data->templates ) ) { |
| 57 | |
| 58 | foreach ( $template_data->templates as $template_tuple ) { |
| 59 | |
| 60 | $image_url = isset( $template_tuple->image ) ? $template_tuple->image : ( $template_url . 'images/' . $template_tuple->slug . '.png' ); |
| 61 | |
| 62 | $template_tuple->image = $image_url; |
| 63 | |
| 64 | $temp_name = explode( '/', $image_url ); |
| 65 | $relative_path = $folder_path . '/' . end( $temp_name ); |
| 66 | $exists = file_exists( $relative_path ); |
| 67 | |
| 68 | // If it exists, utilize this file instead of remote file. |
| 69 | if ( $exists ) { |
| 70 | $template_tuple->image = untrailingslashit( plugin_dir_url( EVF_PLUGIN_FILE ) ) . '/assets/images/templates/' . untrailingslashit( $template_tuple->slug ) . '.png'; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | set_transient( 'evf_template_section_list', $template_data, WEEK_IN_SECONDS ); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return isset( $template_data->templates ) ? apply_filters( 'everest_forms_template_section_data', $template_data->templates ) : self::get_default_template(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Load the template view. |
| 83 | * |
| 84 | * @since 1.0.0 |
| 85 | */ |
| 86 | public static function load_template_view() { |
| 87 | |
| 88 | $templates = array(); |
| 89 | $refresh_url = add_query_arg( |
| 90 | array( |
| 91 | 'page' => 'evf-builder&create-form=1', |
| 92 | 'action' => 'evf-template-refresh', |
| 93 | 'evf-template-nonce' => wp_create_nonce( 'refresh' ), |
| 94 | ), |
| 95 | admin_url( 'admin.php' ) |
| 96 | ); |
| 97 | $license_plan = evf_get_license_plan(); |
| 98 | $current_section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '_all'; // phpcs:ignore WordPress.Security.NonceVerification |
| 99 | |
| 100 | if ( '_featured' !== $current_section ) { |
| 101 | $category = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : 'free'; // phpcs:ignore WordPress.Security.NonceVerification |
| 102 | $templates = self::get_template_data( $category ); |
| 103 | } |
| 104 | |
| 105 | // Forms template area. |
| 106 | include_once dirname( __FILE__ ) . '/views/html-admin-page-form-templates.php'; |
| 107 | } |
| 108 | } |
| 109 |