<?php

/*
  Plugin Name: Drag and Drop Form Builder for Contact Form 7
  Plugin URI: https://wpsuperadmins.com
  Description: Create forms using a live, drag and drop Form builder.
  Version: 1.2.8
  Author: WP Super Admins
  Author Email: josevega@wpsuperadmins.com
  Author URI:  https://wpsuperadmins.com/?utm_source=wp-admin&utm_medium=plugins-list&utm_campaign=cf7-builder
  Plugin URI: https://wpsuperadmins.com/?utm_source=wp-admin&utm_medium=plugins-list&utm_campaign=cf7-builder
    Text Domain: vg_cf7_form_builder
  Domain Path: /lang
  License:
 Copyright 2011 JoseVega (josevega@vegacorp.me)
 This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.
 This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
require_once 'vendor/vg-plugin-sdk/index.php';
require_once 'vendor/freemius/start.php';
require_once 'inc/freemius.php';
/**
 * Load CSS
 */
if ( !class_exists( 'VG_CF7_Form_Builder' ) ) {
    class VG_CF7_Form_Builder {
        private static $instance = false;

        var $textname = 'vg_cf7_form_builder';

        static $dir = __DIR__;

        static $file = __FILE__;

        var $version = '1.2.8';

        var $buy_url = null;

        public $args = array();

        var $vg_plugin_sdk = null;

        private function __construct() {
        }

        function init() {
            $this->buy_url = wpvsfb_freemius()->checkout_url( WP_FS__PERIOD_ANNUALLY, true );
            $this->args = array(
                'main_plugin_file'  => __FILE__,
                'show_welcome_page' => true,
                'welcome_page_file' => VG_CF7_Form_Builder::$dir . '/views/welcome-page-content.php',
                'logo'              => plugins_url( '/assets/imgs/logo.png', __FILE__ ),
                'plugin_name'       => 'CF7 Form Builder',
                'plugin_prefix'     => 'wpvsfb_',
                'plugin_version'    => $this->version,
                'plugin_options'    => get_option( $this->textname, false ),
            );
            $this->vg_plugin_sdk = new VG_Freemium_Plugin_SDK($this->args);
            require 'core/index.php';
            add_action( 'admin_enqueue_scripts', array($this, 'enqueue_assets'), 10 );
            add_action( 'admin_menu', array($this, 'register_menu_page') );
            add_filter( 'vgcf7b_form_builder_settings', array($this, 'modify_form_builder_args') );
            add_filter( 'vgcf7b_metabox_classes', array($this, 'add_metabox_classes') );
            if ( wpvsfb_freemius()->is_not_paying() ) {
                add_filter( 'vgcf7b_allow_to_activate', array($this, 'allow_to_activate_styles') );
                add_filter( 'vgcf7b_after_style_buttons', array($this, 'render_style_upgrade_button') );
                add_filter( 'vgcf7b_after_preview_buttons', array($this, 'render_style_upgrade_button') );
                add_filter( 'vgcf7b_allow_to_activate_preview', '__return_false' );
                add_filter( 'vgcf7b_two_columns_disabled', array($this, 'disable_two_columns_option') );
                add_filter( 'vgcf7b_two_columns_after', array($this, 'after_two_columns_option') );
            }
            add_action( 'vgcf7b_after_header', array($this, 'display_help_buttons_in_metabox') );
            load_plugin_textdomain( $this->textname, false, basename( dirname( __FILE__ ) ) . '/lang/' );
        }

        function display_help_buttons_in_metabox() {
            ?>
			<div class="vgcf7b-intro">
				<?php 
            ?>
					<a target="_blank" href="<?php 
            echo esc_url( $this->buy_url );
            ?>" class="button"><span class="dashicons dashicons-cart"></span> <?php 
            _e( 'Go pro', $this->textname );
            ?></a>
				<?php 
            ?>
				<a target="_blank" href="<?php 
            echo wpvsfb_freemius()->contact_url();
            ?>" class="button"><span class="dashicons dashicons-editor-help"></span> <?php 
            _e( 'Need help? Contact us', $this->textname );
            ?></a>
			</div>
			<style>
				.wpvsfb-metabox-wrapper .metabox-header h2, .wpvsfb-metabox-wrapper .metabox-header  .vgcf7b-intro {
					display: inline-block;
				}
				.wpvsfb-metabox-wrapper .vgcf7b-intro {
					margin-left: 20px;
					float: right;
				}
			</style>
			<?php 
        }

        function after_two_columns_option( $html ) {
            $html .= '<a class="disable" href="' . esc_url( add_query_arg( 'wpcf7-source', 'twoColumns', $this->buy_url ) ) . '" target="_blank">' . __( 'Pro', $this->textname ) . '</a>';
            return $html;
        }

        function disable_two_columns_option( $disabled ) {
            return ' disabled ';
        }

        function add_metabox_classes( $classes ) {
            if ( wpvsfb_freemius()->is_not_paying() ) {
                $classes[] = 'wpcf7-free';
            } else {
                $classes[] = 'wpcf7-pro';
            }
            return $classes;
        }

        function enqueue_assets( $hook ) {
            if ( strpos( $hook, 'wpcf7' ) === false ) {
                return;
            }
            wp_enqueue_style( 'wpcf7b-main-styles', plugins_url( '/assets/styles.css', __FILE__ ) );
        }

        function allow_to_activate_styles( $style ) {
            return $style === 'plain';
        }

        function render_style_upgrade_button( $style = null ) {
            if ( $style === 'plain' ) {
                return;
            }
            ?>
			<a href="<?php 
            echo esc_url( add_query_arg( 'wpcf7-source', 'disabledStyle', $this->buy_url ) );
            ?>" target="_blank" class="wpcf7-upgrade"><?php 
            _e( 'Upgrade to use this design', $this->textname );
            ?></a>
			<?php 
        }

        function modify_form_builder_args( $args ) {
            if ( wpvsfb_freemius()->is_not_paying() ) {
                $args['disableFields'] = array(
                    'autocomplete',
                    'hidden',
                    'date',
                    'file',
                    'paragraph-cf7',
                    'number',
                    'checkbox-group',
                    'header',
                    'shortcode-cf7'
                );
                $args['upgradeLink'] = '<a class="disable" href="' . esc_url( add_query_arg( 'wpcf7-source', 'disabledFieldType', $this->buy_url ) ) . '" target="_blank">Pro</a>';
            }
            return $args;
        }

        function register_menu_page() {
            add_options_page(
                $this->args['plugin_name'],
                $this->args['plugin_name'],
                'manage_options',
                $this->args['plugin_prefix'] . 'welcome_page',
                array($this->vg_plugin_sdk, 'render_welcome_page')
            );
        }

        /**
         * Creates or returns an instance of this class.
         *
         * @return  Foo A single instance of this class.
         */
        static function get_instance() {
            if ( null == VG_CF7_Form_Builder::$instance ) {
                VG_CF7_Form_Builder::$instance = new VG_CF7_Form_Builder();
                VG_CF7_Form_Builder::$instance->init();
            }
            return VG_CF7_Form_Builder::$instance;
        }

        function __set( $name, $value ) {
            $this->{$name} = $value;
        }

        function __get( $name ) {
            return $this->{$name};
        }

        function get_plugin_install_url( $plugin_slug ) {
            $install_plugin_base_url = ( is_multisite() ? network_admin_url() : admin_url() );
            $install_plugin_url = add_query_arg( array(
                's'    => $plugin_slug,
                'tab'  => 'search',
                'type' => 'term',
            ), $install_plugin_base_url . 'plugin-install.php' );
            return $install_plugin_url;
        }

    }

}
if ( !function_exists( 'VG_CF7_Form_Builder_Obj' ) ) {
    function VG_CF7_Form_Builder_Obj() {
        return VG_CF7_Form_Builder::get_instance();
    }

}
VG_CF7_Form_Builder_Obj();