Exemplo n.º 1
0
 public static function setup_database()
 {
     global $wpdb;
     require_once ABSPATH . '/wp-admin/includes/upgrade.php';
     if (!empty($wpdb->charset)) {
         $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
     }
     if (!empty($wpdb->collate)) {
         $charset_collate .= " COLLATE {$wpdb->collate}";
     }
     //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
     add_filter('dbdelta_create_queries', array('RGForms', 'dbdelta_fix_case'));
     /*
      * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
      * As of 4.2, however, WP core moved to utf8mb4, which uses 4 bytes per character. This means that an index which
      * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
      */
     $max_index_length = 191;
     //------ FORM -----------------------------------------------
     $form_table_name = RGFormsModel::get_form_table_name();
     $sql = 'CREATE TABLE ' . $form_table_name . " (\n              id mediumint(8) unsigned not null auto_increment,\n              title varchar(150) not null,\n              date_created datetime not null,\n              is_active tinyint(1) not null default 1,\n              is_trash tinyint(1) not null default 0,\n              PRIMARY KEY  (id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping table that was created by mistake in version 1.6.3.2
     $wpdb->query('DROP TABLE IF EXISTS A' . $form_table_name);
     //------ META -----------------------------------------------
     $meta_table_name = RGFormsModel::get_meta_table_name();
     $sql = 'CREATE TABLE ' . $meta_table_name . " (\n              form_id mediumint(8) unsigned not null,\n              display_meta longtext,\n              entries_grid_meta longtext,\n              confirmations longtext,\n              notifications longtext,\n              PRIMARY KEY  (form_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping outdated form_id index (if one exists)
     self::drop_index($meta_table_name, 'form_id');
     //------ FORM VIEW -----------------------------------------------
     $form_view_table_name = RGFormsModel::get_form_view_table_name();
     $sql = 'CREATE TABLE ' . $form_view_table_name . " (\n              id bigint(20) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null,\n              date_created datetime not null,\n              ip char(15),\n              count mediumint(8) unsigned not null default 1,\n              PRIMARY KEY  (id),\n              KEY form_id (form_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD -----------------------------------------------
     $lead_table_name = RGFormsModel::get_lead_table_name();
     $sql = 'CREATE TABLE ' . $lead_table_name . " (\n              id int(10) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null,\n              post_id bigint(20) unsigned,\n              date_created datetime not null,\n              is_starred tinyint(1) not null default 0,\n              is_read tinyint(1) not null default 0,\n              ip varchar(39) not null,\n              source_url varchar(200) not null default '',\n              user_agent varchar(250) not null default '',\n              currency varchar(5),\n              payment_status varchar(15),\n              payment_date datetime,\n              payment_amount decimal(19,2),\n              payment_method varchar(30),\n              transaction_id varchar(50),\n              is_fulfilled tinyint(1),\n              created_by bigint(20) unsigned,\n              transaction_type tinyint(1),\n              status varchar(20) not null default 'active',\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY status (status)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD NOTES ------------------------------------------
     $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
     $sql = 'CREATE TABLE ' . $lead_notes_table_name . " (\n              id int(10) unsigned not null auto_increment,\n              lead_id int(10) unsigned not null,\n              user_name varchar(250),\n              user_id bigint(20),\n              date_created datetime not null,\n              value longtext,\n              note_type varchar(50),\n              PRIMARY KEY  (id),\n              KEY lead_id (lead_id),\n              KEY lead_user_key (lead_id,user_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD DETAIL -----------------------------------------
     $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
     $sql = 'CREATE TABLE ' . $lead_detail_table_name . ' (
           id bigint(20) unsigned not null auto_increment,
           lead_id int(10) unsigned not null,
           form_id mediumint(8) unsigned not null,
           field_number float not null,
           value varchar(' . GFORMS_MAX_FIELD_LENGTH . "),\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY lead_id (lead_id),\n              KEY lead_field_number (lead_id,field_number)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD DETAIL LONG -----------------------------------
     $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
     $sql = 'CREATE TABLE ' . $lead_detail_long_table_name . " (\n              lead_detail_id bigint(20) unsigned not null,\n              value longtext,\n              PRIMARY KEY  (lead_detail_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     // dropping outdated form_id index (if one exists)
     self::drop_index($lead_detail_long_table_name, 'lead_detail_key');
     //------ LEAD META ------------------------------------------
     $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
     // dropping meta_key and form_id_meta_key (if they exist) to prevent duplicate keys error on upgrade
     if (version_compare(get_option('rg_form_version'), '1.9.8.12', '<')) {
         self::drop_index($lead_meta_table_name, 'meta_key');
         self::drop_index($lead_meta_table_name, 'form_id_meta_key');
     }
     $sql = 'CREATE TABLE ' . $lead_meta_table_name . " (\n              id bigint(20) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null default 0,\n              lead_id bigint(20) unsigned not null,\n              meta_key varchar(255),\n              meta_value longtext,\n              PRIMARY KEY  (id),\n              KEY meta_key (meta_key({$max_index_length})),\n              KEY lead_id (lead_id),\n              KEY form_id_meta_key (form_id,meta_key({$max_index_length}))\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ INCOMPLETE SUBMISSIONS -------------------------------
     $incomplete_submissions_table_name = RGFormsModel::get_incomplete_submissions_table_name();
     $sql = 'CREATE TABLE ' . $incomplete_submissions_table_name . " (\n              uuid char(32) not null,\n              email varchar(255),\n              form_id mediumint(8) unsigned not null,\n              date_created datetime not null,\n              ip varchar(39) not null,\n              source_url longtext not null,\n              submission longtext not null,\n              PRIMARY KEY  (uuid),\n              KEY form_id (form_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     remove_filter('dbdelta_create_queries', array('RGForms', 'dbdelta_fix_case'));
     //fix form_id value needed to update from version 1.6.11
     self::fix_lead_meta_form_id_values();
     //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
     self::fix_checkbox_value();
     //fix leading and trailing spaces in Form objects and entry values
     if (version_compare(get_option('rg_form_version'), '1.8.3.1', '<')) {
         self::fix_leading_and_trailing_spaces();
     }
 }
    public static function setup($force_setup = false)
    {
        global $wpdb;
        $version = GFCommon::$version;
        if (get_option("rg_form_version") != $version || $force_setup) {
            $error = "";
            if (!self::has_database_permission($error)) {
                ?>
                <div class='error' style="padding:15px;"><?php 
                echo $error;
                ?>
</div>
                <?php 
            }
            require_once ABSPATH . '/wp-admin/includes/upgrade.php';
            if (!empty($wpdb->charset)) {
                $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
            }
            if (!empty($wpdb->collate)) {
                $charset_collate .= " COLLATE {$wpdb->collate}";
            }
            //------ FORM -----------------------------------------------
            $form_table_name = RGFormsModel::get_form_table_name();
            $sql = "CREATE TABLE " . $form_table_name . " (\r\n                  id mediumint(8) unsigned not null auto_increment,\r\n                  title varchar(150) not null,\r\n                  date_created datetime not null,\r\n                  is_active tinyint(1) not null default 1,\r\n                  PRIMARY KEY  (id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ META -----------------------------------------------
            $meta_table_name = RGFormsModel::get_meta_table_name();
            $sql = "CREATE TABLE " . $meta_table_name . " (\r\n                  form_id mediumint(8) unsigned not null,\r\n                  display_meta longtext,\r\n                  entries_grid_meta longtext,\r\n                  PRIMARY KEY  (form_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //droping outdated form_id index (if one exists)
            self::drop_index($meta_table_name, 'form_id');
            //------ FORM VIEW -----------------------------------------------
            $form_view_table_name = RGFormsModel::get_form_view_table_name();
            $sql = "CREATE TABLE " . $form_view_table_name . " (\r\n                  id bigint(20) unsigned not null auto_increment,\r\n                  form_id mediumint(8) unsigned not null,\r\n                  date_created datetime not null,\r\n                  ip char(15),\r\n                  count mediumint(8) unsigned not null default 1,\r\n                  PRIMARY KEY  (id),\r\n                  KEY form_id (form_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD -----------------------------------------------
            $lead_table_name = RGFormsModel::get_lead_table_name();
            $sql = "CREATE TABLE " . $lead_table_name . " (\r\n                  id int(10) unsigned not null auto_increment,\r\n                  form_id mediumint(8) unsigned not null,\r\n                  post_id bigint(20) unsigned,\r\n                  date_created datetime not null,\r\n                  is_starred tinyint(1) not null default 0,\r\n                  is_read tinyint(1) not null default 0,\r\n                  ip varchar(39) not null,\r\n                  source_url varchar(200) not null default '',\r\n                  user_agent varchar(250) not null default '',\r\n                  currency varchar(5),\r\n                  payment_status varchar(15),\r\n                  payment_date datetime,\r\n                  payment_amount decimal(19,2),\r\n                  transaction_id varchar(50),\r\n                  is_fulfilled tinyint(1),\r\n                  created_by bigint(20) unsigned,\r\n                  transaction_type tinyint(1),\r\n                  status varchar(20) not null default 'active',\r\n                  PRIMARY KEY  (id),\r\n                  KEY form_id (form_id),\r\n                  KEY status (status)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD NOTES ------------------------------------------
            $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
            $sql = "CREATE TABLE " . $lead_notes_table_name . " (\r\n                  id int(10) unsigned not null auto_increment,\r\n                  lead_id int(10) unsigned not null,\r\n                  user_name varchar(250),\r\n                  user_id bigint(20),\r\n                  date_created datetime not null,\r\n                  value longtext,\r\n                  PRIMARY KEY  (id),\r\n                  KEY lead_id (lead_id),\r\n                  KEY lead_user_key (lead_id,user_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD DETAIL -----------------------------------------
            $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
            $sql = "CREATE TABLE " . $lead_detail_table_name . " (\r\n                  id bigint(20) unsigned not null auto_increment,\r\n                  lead_id int(10) unsigned not null,\r\n                  form_id mediumint(8) unsigned not null,\r\n                  field_number float not null,\r\n                  value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\r\n                  PRIMARY KEY  (id),\r\n                  KEY form_id (form_id),\r\n                  KEY lead_id (lead_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD DETAIL LONG -----------------------------------
            $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
            $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (\r\n                  lead_detail_id bigint(20) unsigned not null,\r\n                  value longtext,\r\n                  PRIMARY KEY  (lead_detail_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //droping outdated form_id index (if one exists)
            self::drop_index($lead_detail_long_table_name, 'lead_detail_key');
            //------ LEAD META -----------------------------------
            $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
            $sql = "CREATE TABLE " . $lead_meta_table_name . " (\r\n                  id bigint(20) unsigned not null auto_increment,\r\n                  lead_id bigint(20) unsigned not null,\r\n                  meta_key varchar(255),\r\n                  meta_value longtext,\r\n                  PRIMARY KEY  (id),\r\n                  KEY meta_key (meta_key),\r\n                  KEY lead_id (lead_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
            self::fix_checkbox_value();
            //auto-setting license key based on value configured via the GF_LICENSE_KEY constant or the gf_license_key variable
            global $gf_license_key;
            $license_key = defined("GF_LICENSE_KEY") && empty($gf_license_key) ? GF_LICENSE_KEY : $gf_license_key;
            if (!empty($license_key)) {
                update_option("rg_gforms_key", md5($license_key));
            }
            //auto-setting recaptcha keys based on value configured via the constant or global variable
            global $gf_recaptcha_public_key, $gf_recaptcha_private_key;
            $private_key = defined("GF_RECAPTCHA_PRIVATE_KEY") && empty($gf_recaptcha_private_key) ? GF_RECAPTCHA_PRIVATE_KEY : $gf_recaptcha_private_key;
            if (!empty($private_key)) {
                update_option("rg_gforms_captcha_private_key", $private_key);
            }
            $public_key = defined("GF_RECAPTCHA_PUBLIC_KEY") && empty($gf_recaptcha_public_key) ? GF_RECAPTCHA_PUBLIC_KEY : $gf_recaptcha_public_key;
            if (!empty($public_key)) {
                update_option("rg_gforms_captcha_public_key", $public_key);
            }
            //Auto-importing forms based on GF_IMPORT_FILE AND GF_THEME_IMPORT_FILE
            if (defined("GF_IMPORT_FILE") && !get_option("gf_imported_file")) {
                GFExport::import_file(GF_IMPORT_FILE);
                update_option("gf_imported_file", true);
            }
            //adds empty index.php files to upload folders. only for v1.5.2 and below
            if (version_compare(get_option("rg_form_version"), "1.6", "<")) {
                self::add_empty_index_files();
            }
            update_option("rg_form_version", $version);
        }
        //Import theme specific forms if configured. Will only import forms once per theme.
        if (defined("GF_THEME_IMPORT_FILE")) {
            $themes = get_option("gf_imported_theme_file");
            if (!is_array($themes)) {
                $themes = array();
            }
            //if current theme has already imported it's forms, don't import again
            $theme = get_template();
            if (!isset($themes[$theme])) {
                //importing forms
                GFExport::import_file(get_stylesheet_directory() . "/" . GF_THEME_IMPORT_FILE);
                //adding current theme to the list of imported themes. So that forms are not imported again for it.
                $themes[$theme] = true;
                update_option("gf_imported_theme_file", $themes);
            }
        }
    }
Exemplo n.º 3
0
 public static function setup_database()
 {
     global $wpdb;
     require_once ABSPATH . '/wp-admin/includes/upgrade.php';
     if (!empty($wpdb->charset)) {
         $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
     }
     if (!empty($wpdb->collate)) {
         $charset_collate .= " COLLATE {$wpdb->collate}";
     }
     //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
     add_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
     //------ FORM -----------------------------------------------
     $form_table_name = RGFormsModel::get_form_table_name();
     $sql = "CREATE TABLE " . $form_table_name . " (\n              id mediumint(8) unsigned not null auto_increment,\n              title varchar(150) not null,\n              date_created datetime not null,\n              is_active tinyint(1) not null default 1,\n              is_trash tinyint(1) not null default 0,\n              PRIMARY KEY  (id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping table that was created by mistake in version 1.6.3.2
     $wpdb->query("DROP TABLE IF EXISTS A" . $form_table_name);
     //------ META -----------------------------------------------
     $meta_table_name = RGFormsModel::get_meta_table_name();
     $sql = "CREATE TABLE " . $meta_table_name . " (\n              form_id mediumint(8) unsigned not null,\n              display_meta longtext,\n              entries_grid_meta longtext,\n              confirmations longtext,\n              notifications longtext,\n              PRIMARY KEY  (form_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping outdated form_id index (if one exists)
     self::drop_index($meta_table_name, 'form_id');
     //------ FORM VIEW -----------------------------------------------
     $form_view_table_name = RGFormsModel::get_form_view_table_name();
     $sql = "CREATE TABLE " . $form_view_table_name . " (\n              id bigint(20) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null,\n              date_created datetime not null,\n              ip char(15),\n              count mediumint(8) unsigned not null default 1,\n              PRIMARY KEY  (id),\n              KEY form_id (form_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD -----------------------------------------------
     $lead_table_name = RGFormsModel::get_lead_table_name();
     $sql = "CREATE TABLE " . $lead_table_name . " (\n              id int(10) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null,\n              post_id bigint(20) unsigned,\n              date_created datetime not null,\n              is_starred tinyint(1) not null default 0,\n              is_read tinyint(1) not null default 0,\n              ip varchar(39) not null,\n              source_url varchar(200) not null default '',\n              user_agent varchar(250) not null default '',\n              currency varchar(5),\n              payment_status varchar(15),\n              payment_date datetime,\n              payment_amount decimal(19,2),\n              payment_method varchar(30),\n              transaction_id varchar(50),\n              is_fulfilled tinyint(1),\n              created_by bigint(20) unsigned,\n              transaction_type tinyint(1),\n              status varchar(20) not null default 'active',\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY status (status)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD NOTES ------------------------------------------
     $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
     $sql = "CREATE TABLE " . $lead_notes_table_name . " (\n              id int(10) unsigned not null auto_increment,\n              lead_id int(10) unsigned not null,\n              user_name varchar(250),\n              user_id bigint(20),\n              date_created datetime not null,\n              value longtext,\n              PRIMARY KEY  (id),\n              KEY lead_id (lead_id),\n              KEY lead_user_key (lead_id,user_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD DETAIL -----------------------------------------
     $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
     $sql = "CREATE TABLE " . $lead_detail_table_name . " (\n              id bigint(20) unsigned not null auto_increment,\n              lead_id int(10) unsigned not null,\n              form_id mediumint(8) unsigned not null,\n              field_number float not null,\n              value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY lead_id (lead_id),\n              KEY lead_field_number (lead_id,field_number)\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ LEAD DETAIL LONG -----------------------------------
     $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
     $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (\n              lead_detail_id bigint(20) unsigned not null,\n              value longtext,\n              PRIMARY KEY  (lead_detail_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping outdated form_id index (if one exists)
     self::drop_index($lead_detail_long_table_name, 'lead_detail_key');
     //------ LEAD META -----------------------------------
     $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
     $sql = "CREATE TABLE " . $lead_meta_table_name . " (\n              id bigint(20) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null default 0,\n              lead_id bigint(20) unsigned not null,\n              meta_key varchar(255),\n              meta_value longtext,\n              PRIMARY KEY  (id),\n              KEY meta_key (meta_key),\n              KEY lead_id (lead_id),\n              KEY form_id_meta_key (form_id,meta_key)\n            ) {$charset_collate};";
     dbDelta($sql);
     remove_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
     //fix form_id value needed to update from version 1.6.11
     self::fix_lead_meta_form_id_values();
     //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
     self::fix_checkbox_value();
     //fix leading and trailing spaces in Form objects and entry values from versions prior to 1.8.2
     if (version_compare(get_option("rg_form_version"), "1.8.2", "<=")) {
         //uncomment to test
         //self::fix_leading_and_trailing_spaces();
     }
 }
Exemplo n.º 4
0
    public static function metarecovery_page()
    {
        if (RGForms::post("gf_metarecovery_submit")) {
            global $wpdb;
            $table_name = RGFormsModel::get_meta_table_name();
            $form_id = RGForms::post("gf_metarecovery_form_id");
            $meta = $wpdb->get_var($wpdb->prepare("SELECT display_meta FROM {$table_name} WHERE form_id=%d", $form_id));
            //fixing meta
            $meta = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $meta);
            //if successfull, store new meta
            $obj = unserialize($meta);
            if ($obj) {
                RGFormsModel::update_form_meta($form_id, $obj);
                $is_success = true;
            } else {
                $is_failure = true;
            }
        }
        ?>
        <style>
            .left_header{float:left; width:200px;}
            .margin_vertical_10{margin: 10px 0;}
        </style>
        <div class="wrap">
            <form method="post">

                <h2><?php 
        _e("Meta Recovery Utility", "gravityformsmetarecovery");
        ?>
</h2>

                <?php 
        if ($is_success) {
            ?>
                    <div class="updated fade" style="padding:6px"><?php 
            echo sprintf(__("Meta recovered successfully. %sGo to form editor%s", "gravityformsmetarecovery"), "<a href='?page=gf_edit_forms&id={$form_id}'>", "</a>");
            ?>
</div>
                    <?php 
        }
        if ($is_failure) {
            ?>
                    <div class="error" style="padding:6px"><?php 
            echo __("This form's meta could not be recovered.", "gravityformsmetarecovery");
            ?>
</div>
                    <?php 
        }
        ?>
                <div class="margin_vertical_10">
                    <label for="gf_metarecovery_form_id" class="left_header"><?php 
        _e("Gravity Form", "gravityforms_feed");
        ?>
 </label>
                    <select name="gf_metarecovery_form_id" id="gf_metarecovery_form_id">
                        <option value=""><?php 
        _e("Select a form", "gravityforms_feed");
        ?>
 </option>
                        <?php 
        $forms = RGFormsModel::get_forms();
        foreach ($forms as $form) {
            ?>
                            <option value="<?php 
            echo absint($form->id);
            ?>
"><?php 
            echo esc_html($form->title);
            ?>
</option>
                            <?php 
        }
        ?>
                    </select>
                </div>
                <div class="margin_vertical_10">
                    <input type="submit" class="button-primary" name="gf_metarecovery_submit" value="<?php 
        _e("Submit", "gravityformsmetarecovery");
        ?>
" />
                </div>

            </form>
        </div>
        <?php 
    }
Exemplo n.º 5
0
    public static function setup_site($blog_id = null)
    {
        if (empty($blog_id)) {
            $blog_id = get_current_blog_id();
        }
        //if a blog id is specified, switch to it
        if (MULTISITE && !switch_to_blog($blog_id)) {
            return;
        }
        global $wpdb;
        $error = "";
        if (!self::has_database_permission($error)) {
            ?>

            <div class='error' style="padding:15px;"><?php 
            echo $error;
            ?>
</div>

            <?php 
        }
        require_once ABSPATH . '/wp-admin/includes/upgrade.php';
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
        //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
        add_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
        //------ FORM -----------------------------------------------
        $form_table_name = RGFormsModel::get_form_table_name();
        $sql = "CREATE TABLE " . $form_table_name . " (\n\n              id mediumint(8) unsigned not null auto_increment,\n\n              title varchar(150) not null,\n\n              date_created datetime not null,\n\n              is_active tinyint(1) not null default 1,\n\n              PRIMARY KEY  (id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //droping table that was created by mistake in version 1.6.3.2
        $wpdb->query("DROP TABLE IF EXISTS A" . $form_table_name);
        //------ META -----------------------------------------------
        $meta_table_name = RGFormsModel::get_meta_table_name();
        $sql = "CREATE TABLE " . $meta_table_name . " (\n\n              form_id mediumint(8) unsigned not null,\n\n              display_meta longtext,\n\n              entries_grid_meta longtext,\n\n              confirmations longtext,\n\n              notifications longtext,\n\n              PRIMARY KEY  (form_id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //droping outdated form_id index (if one exists)
        self::drop_index($meta_table_name, 'form_id');
        //------ FORM VIEW -----------------------------------------------
        $form_view_table_name = RGFormsModel::get_form_view_table_name();
        $sql = "CREATE TABLE " . $form_view_table_name . " (\n\n              id bigint(20) unsigned not null auto_increment,\n\n              form_id mediumint(8) unsigned not null,\n\n              date_created datetime not null,\n\n              ip char(15),\n\n              count mediumint(8) unsigned not null default 1,\n\n              PRIMARY KEY  (id),\n\n              KEY form_id (form_id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //------ LEAD -----------------------------------------------
        $lead_table_name = RGFormsModel::get_lead_table_name();
        $sql = "CREATE TABLE " . $lead_table_name . " (\n\n              id int(10) unsigned not null auto_increment,\n\n              form_id mediumint(8) unsigned not null,\n\n              post_id bigint(20) unsigned,\n\n              date_created datetime not null,\n\n              is_starred tinyint(1) not null default 0,\n\n              is_read tinyint(1) not null default 0,\n\n              ip varchar(39) not null,\n\n              source_url varchar(200) not null default '',\n\n              user_agent varchar(250) not null default '',\n\n              currency varchar(5),\n\n              payment_status varchar(15),\n\n              payment_date datetime,\n\n              payment_amount decimal(19,2),\n\n              transaction_id varchar(50),\n\n              is_fulfilled tinyint(1),\n\n              created_by bigint(20) unsigned,\n\n              transaction_type tinyint(1),\n\n              status varchar(20) not null default 'active',\n\n              PRIMARY KEY  (id),\n\n              KEY form_id (form_id),\n\n              KEY status (status)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //------ LEAD NOTES ------------------------------------------
        $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
        $sql = "CREATE TABLE " . $lead_notes_table_name . " (\n\n              id int(10) unsigned not null auto_increment,\n\n              lead_id int(10) unsigned not null,\n\n              user_name varchar(250),\n\n              user_id bigint(20),\n\n              date_created datetime not null,\n\n              value longtext,\n\n              PRIMARY KEY  (id),\n\n              KEY lead_id (lead_id),\n\n              KEY lead_user_key (lead_id,user_id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //------ LEAD DETAIL -----------------------------------------
        $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
        $sql = "CREATE TABLE " . $lead_detail_table_name . " (\n\n              id bigint(20) unsigned not null auto_increment,\n\n              lead_id int(10) unsigned not null,\n\n              form_id mediumint(8) unsigned not null,\n\n              field_number float not null,\n\n              value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\n\n              PRIMARY KEY  (id),\n\n              KEY form_id (form_id),\n\n              KEY lead_id (lead_id),\n\n              KEY lead_field_number (lead_id,field_number)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //------ LEAD DETAIL LONG -----------------------------------
        $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
        $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (\n\n              lead_detail_id bigint(20) unsigned not null,\n\n              value longtext,\n\n              PRIMARY KEY  (lead_detail_id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //droping outdated form_id index (if one exists)
        self::drop_index($lead_detail_long_table_name, 'lead_detail_key');
        //------ LEAD META -----------------------------------
        $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
        $sql = "CREATE TABLE " . $lead_meta_table_name . " (\n\n              id bigint(20) unsigned not null auto_increment,\n\n              form_id mediumint(8) unsigned not null default 0,\n\n              lead_id bigint(20) unsigned not null,\n\n              meta_key varchar(255),\n\n              meta_value longtext,\n\n              PRIMARY KEY  (id),\n\n              KEY meta_key (meta_key),\n\n              KEY lead_id (lead_id),\n\n              KEY form_id_meta_key (form_id,meta_key)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        remove_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
        //fix form_id value needed to update from version 1.6.11
        self::fix_lead_meta_form_id_values();
        //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
        self::fix_checkbox_value();
        //auto-setting license key based on value configured via the GF_LICENSE_KEY constant or the gf_license_key variable
        global $gf_license_key;
        $license_key = defined("GF_LICENSE_KEY") && empty($gf_license_key) ? GF_LICENSE_KEY : $gf_license_key;
        if (!empty($license_key)) {
            update_option("rg_gforms_key", md5($license_key));
        }
        //auto-setting recaptcha keys based on value configured via the constant or global variable
        global $gf_recaptcha_public_key, $gf_recaptcha_private_key;
        $private_key = defined("GF_RECAPTCHA_PRIVATE_KEY") && empty($gf_recaptcha_private_key) ? GF_RECAPTCHA_PRIVATE_KEY : $gf_recaptcha_private_key;
        if (!empty($private_key)) {
            update_option("rg_gforms_captcha_private_key", $private_key);
        }
        $public_key = defined("GF_RECAPTCHA_PUBLIC_KEY") && empty($gf_recaptcha_public_key) ? GF_RECAPTCHA_PUBLIC_KEY : $gf_recaptcha_public_key;
        if (!empty($public_key)) {
            update_option("rg_gforms_captcha_public_key", $public_key);
        }
        //Auto-importing forms based on GF_IMPORT_FILE AND GF_THEME_IMPORT_FILE
        if (defined("GF_IMPORT_FILE") && !get_option("gf_imported_file")) {
            GFExport::import_file(GF_IMPORT_FILE);
            update_option("gf_imported_file", true);
        }
        //adds empty index.php files to upload folders. only for v1.5.2 and below
        if (version_compare(get_option("rg_form_version"), "1.6", "<")) {
            self::add_empty_index_files();
        }
        update_option("rg_form_version", GFCommon::$version);
        //going back to current blog
        if (MULTISITE) {
            restore_current_blog();
        }
    }
Exemplo n.º 6
0
 public static function setup()
 {
     global $wpdb;
     $version = GFCommon::$version;
     if (get_option("rg_form_version") != $version) {
         require_once ABSPATH . '/wp-admin/includes/upgrade.php';
         if (!empty($wpdb->charset)) {
             $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
         }
         if (!empty($wpdb->collate)) {
             $charset_collate .= " COLLATE {$wpdb->collate}";
         }
         //------ FORM -----------------------------------------------
         $form_table_name = RGFormsModel::get_form_table_name();
         $sql = "CREATE TABLE " . $form_table_name . " (\n                  id mediumint(8) unsigned not null auto_increment,\n                  title varchar(150) not null,\n                  date_created datetime not null,\n                  is_active tinyint(1) not null default 1,\n                  PRIMARY KEY  (id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ META -----------------------------------------------
         $meta_table_name = RGFormsModel::get_meta_table_name();
         $sql = "CREATE TABLE " . $meta_table_name . " (\n                  form_id mediumint(8) unsigned not null,\n                  display_meta longtext,\n                  entries_grid_meta longtext,\n                  KEY form_id (form_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ FORM VIEW -----------------------------------------------
         $form_view_table_name = RGFormsModel::get_form_view_table_name();
         $sql = "CREATE TABLE " . $form_view_table_name . " (\n                  id bigint(20) unsigned not null auto_increment,\n                  form_id mediumint(8) unsigned not null,\n                  date_created datetime not null,\n                  ip char(15),\n                  count mediumint(8) unsigned not null default 1,\n                  PRIMARY KEY  (id),\n                  KEY form_id (form_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD -----------------------------------------------
         $lead_table_name = RGFormsModel::get_lead_table_name();
         $sql = "CREATE TABLE " . $lead_table_name . " (\n                  id int(10) unsigned not null auto_increment,\n                  form_id mediumint(8) unsigned not null,\n                  post_id bigint(20) unsigned,\n                  date_created datetime not null,\n                  is_starred tinyint(1) not null default 0,\n                  is_read tinyint(1) not null default 0,\n                  ip char(15) not null,\n                  source_url varchar(200) not null default '',\n                  user_agent varchar(250) not null default '',\n                  PRIMARY KEY  (id),\n                  KEY form_id (form_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD NOTES ------------------------------------------
         $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
         $sql = "CREATE TABLE " . $lead_notes_table_name . " (\n                  id int(10) unsigned not null auto_increment,\n                  lead_id int(10) unsigned not null,\n                  user_name varchar(250),\n                  user_id bigint(20),\n                  date_created datetime not null,\n                  value longtext,\n                  PRIMARY KEY  (id),\n                  KEY lead_id (lead_id),\n                  KEY lead_user_key (lead_id,user_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD DETAIL -----------------------------------------
         $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
         $sql = "CREATE TABLE " . $lead_detail_table_name . " (\n                  id bigint(20) unsigned not null auto_increment,\n                  lead_id int(10) unsigned not null,\n                  form_id mediumint(8) unsigned not null,\n                  field_number float not null,\n                  value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\n                  PRIMARY KEY  (id),\n                  KEY form_id (form_id),\n                  KEY lead_id (lead_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD DETAIL LONG -----------------------------------
         $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
         $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (\n                  lead_detail_id bigint(20) unsigned not null,\n                  value longtext,\n                  KEY lead_detail_key (lead_detail_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
         self::fix_checkbox_value();
     }
     update_option("rg_form_version", $version);
 }