/plugins/gravityforms/gravityforms.php
PHP | 2254 lines | 1621 code | 450 blank | 183 comment | 333 complexity | 77872b40552880aeab1b273d1878e4f7 MD5 | raw file
Possible License(s): GPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Plugin Name: Gravity Forms
- Plugin URI: http://www.gravityforms.com
- Description: Easily create web forms and manage form entries within the WordPress admin.
- Version: 1.7.2
- Author: rocketgenius
- Author URI: http://www.rocketgenius.com
-
- ------------------------------------------------------------------------
- Copyright 2009-2013 Rocketgenius Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-
- //------------------------------------------------------------------------------------------------------------------
- //---------- Gravity Forms License Key -----------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------------
- //If you hardcode a Gravity Forms License Key here, it will automatically populate on activation.
- $gf_license_key = "";
-
- //-- OR ---//
-
- //You can also add the Gravity Forms license key to your wp-config.php file to automatically populate on activation
- //Add the code in the comment below to your wp-config.php to do so:
- //define('GF_LICENSE_KEY','YOUR_KEY_GOES_HERE');
- //------------------------------------------------------------------------------------------------------------------
-
- //------------------------------------------------------------------------------------------------------------------
- //---------- reCAPTCHA Keys -----------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------------
- //If you hardcode your reCAPTCHA Keys here, it will automatically populate on activation.
- $gf_recaptcha_private_key = "";
- $gf_recaptcha_public_key = "";
-
- //-- OR ---//
-
- //You can also add the reCAPTCHA keys to your wp-config.php file to automatically populate on activation
- //Add the two lines of code in the comment below to your wp-config.php to do so:
- //define('GF_RECAPTCHA_PRIVATE_KEY','YOUR_PRIVATE_KEY_GOES_HERE');
- //define('GF_RECAPTCHA_PUBLIC_KEY','YOUR_PUBLIC_KEY_GOES_HERE');
- //------------------------------------------------------------------------------------------------------------------
-
- if(!defined("RG_CURRENT_PAGE"))
- define("RG_CURRENT_PAGE", basename($_SERVER['PHP_SELF']));
-
- if(!defined("IS_ADMIN")){
- define("IS_ADMIN", is_admin());
- }
-
- define("RG_CURRENT_VIEW", RGForms::get("view"));
- define("GF_MIN_WP_VERSION", '3.2');
- define("GF_SUPPORTED_WP_VERSION", version_compare(get_bloginfo("version"), GF_MIN_WP_VERSION, '>='));
-
- if(!defined("GRAVITY_MANAGER_URL"))
- define("GRAVITY_MANAGER_URL", "http://www.gravityhelp.com/wp-content/plugins/gravitymanager");
-
- //initializing translations
- load_plugin_textdomain( 'gravityforms', false, '/gravityforms/languages' );
-
- require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/common.php");
- require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/forms_model.php");
- require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/widget.php");
-
- add_action('init', array('RGForms', 'init'));
- add_action('wp', array('RGForms', 'maybe_process_form'), 9);
- add_action('wp', array('RGForms', 'process_exterior_pages'));
-
- add_filter('user_has_cap', array("RGForms", "user_has_cap"), 10, 3);
-
- //Hooks for no-conflict functionality
- if(is_admin() && (RGForms::is_gravity_page() || RGForms::is_gravity_ajax_action())){
- add_action("wp_print_scripts", array("RGForms", "no_conflict_mode_script"), 1000);
- add_action("admin_print_footer_scripts", array("RGForms", "no_conflict_mode_script"), 9);
-
- add_action("wp_print_styles", array("RGForms", "no_conflict_mode_style"), 1000);
- add_action("admin_print_styles", array("RGForms", "no_conflict_mode_style"), 1);
- add_action("admin_print_footer_scripts", array("RGForms", "no_conflict_mode_style"), 1);
- add_action("admin_footer", array("RGForms", "no_conflict_mode_style"), 1);
- }
-
- class GFForms {
-
- public static function has_members_plugin(){
- return function_exists( 'members_get_capabilities' );
- }
-
- //Plugin starting point. Will load appropriate files
- public static function init(){
-
- add_filter("gform_logging_supported", array("RGForms", "set_logging_supported"));
-
- self::register_scripts();
-
- if(IS_ADMIN){
-
- global $current_user;
-
- //Members plugin integration. Adding Gravity Forms roles to the checkbox list
- if (self::has_members_plugin())
- add_filter('members_get_capabilities', array("RGForms", "members_get_capabilities"));
-
- if(is_multisite()) {
- add_filter('wpmu_drop_tables', array('GFFormsModel', 'mu_drop_tables'));
- }
-
- add_action('admin_enqueue_scripts', array('GFForms', 'enqueue_admin_scripts'));
-
- //Loading Gravity Forms if user has access to any functionality
- if(GFCommon::current_user_can_any(GFCommon::all_caps()))
- {
- require_once(GFCommon::get_base_path() . "/export.php");
- GFExport::maybe_export();
-
- //runs the setup when version changes
- self::setup();
-
- //creates the "Forms" left menu
- add_action('admin_menu', array('RGForms', 'create_menu'));
-
- if(GF_SUPPORTED_WP_VERSION){
-
- add_action('admin_footer', array('RGForms', 'check_upload_folder'));
- add_action('wp_dashboard_setup', array('RGForms', 'dashboard_setup'));
-
- //Adding "embed form" button
- add_action('media_buttons', array('RGForms', 'add_form_button'), 20);
-
- // Add "Form" to the "New" menu in WP admin bar
- add_action( 'wp_before_admin_bar_render', array('GFForms', 'admin_bar') );
-
- //Plugin update actions
- add_filter("transient_update_plugins", array('RGForms', 'check_update'));
- add_filter("site_transient_update_plugins", array('RGForms', 'check_update'));
-
- if(in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))){
- add_action('admin_footer', array('RGForms', 'add_mce_popup'));
- }
- else if(self::is_gravity_page()){
- require_once(GFCommon::get_base_path() . "/tooltips.php");
- add_action("admin_print_scripts", array('RGForms', 'print_scripts'));
- }
- else if(RG_CURRENT_PAGE == 'media-upload.php'){
- require_once(GFCommon::get_base_path() . "/entry_list.php");
- }
- else if(in_array(RG_CURRENT_PAGE, array("admin.php", "admin-ajax.php"))){
-
- add_action('wp_ajax_rg_save_form', array('RGForms', 'save_form'));
- add_action('wp_ajax_rg_change_input_type', array('RGForms', 'change_input_type'));
- add_action('wp_ajax_rg_add_field', array('RGForms', 'add_field'));
- add_action('wp_ajax_rg_duplicate_field', array('RGForms', 'duplicate_field'));
- add_action('wp_ajax_rg_delete_field', array('RGForms', 'delete_field'));
- add_action('wp_ajax_rg_delete_file', array('RGForms', 'delete_file'));
- add_action('wp_ajax_rg_select_export_form', array('RGForms', 'select_export_form'));
- add_action('wp_ajax_rg_start_export', array('RGForms', 'start_export'));
- add_action('wp_ajax_gf_upgrade_license', array('RGForms', 'upgrade_license'));
- add_action('wp_ajax_gf_delete_custom_choice', array('RGForms', 'delete_custom_choice'));
- add_action('wp_ajax_gf_save_custom_choice', array('RGForms', 'save_custom_choice'));
- add_action('wp_ajax_gf_get_post_categories', array('RGForms', 'get_post_category_values'));
- add_action('wp_ajax_gf_get_notification_post_categories', array('RGForms', 'get_notification_post_category_values'));
- add_action('wp_ajax_gf_save_confirmation', array('RGForms', 'save_confirmation'));
- add_action('wp_ajax_gf_delete_confirmation', array('RGForms', 'delete_confirmation'));
- add_action('wp_ajax_gf_save_new_form', array('RGForms', 'save_new_form'));
-
- //entry list ajax operations
- add_action('wp_ajax_rg_update_lead_property', array('RGForms', 'update_lead_property'));
- add_action('wp_ajax_delete-gf_entry', array('RGForms', 'update_lead_status'));
-
- //form list ajax operations
- add_action('wp_ajax_rg_update_form_active', array('RGForms', 'update_form_active'));
-
- //dynamic captcha image
- add_action('wp_ajax_rg_captcha_image', array('RGForms', 'captcha_image'));
-
- //dashboard message "dismiss upgrade" link
- add_action("wp_ajax_rg_dismiss_upgrade", array('RGForms', 'dashboard_dismiss_upgrade'));
-
- // entry detail: resend notifications
- add_action("wp_ajax_gf_resend_notifications", array('RGForms', 'resend_notifications'));
-
- }
-
- add_filter("plugins_api", array("RGForms", "get_addon_info"), 10, 3);
- add_action('after_plugin_row_gravityforms/gravityforms.php', array('RGForms', 'plugin_row') );
- add_action('install_plugins_pre_plugin-information', array('RGForms', 'display_changelog'));
- add_filter('plugin_action_links', array('RGForms', 'plugin_settings_link'),10,2);
- }
- }
-
- }
- else{
- add_action('wp_enqueue_scripts', array('RGForms', 'enqueue_scripts'));
- add_action('wp', array('RGForms', 'ajax_parse_request'), 10);
-
- // ManageWP premium update filters
- add_filter( 'mwp_premium_update_notification', array('RGForms', 'premium_update_push') );
- add_filter( 'mwp_premium_perform_update', array('RGForms', 'premium_update') );
- }
-
- add_shortcode('gravityform', array('RGForms', 'parse_shortcode'));
- add_shortcode('gravityforms', array('RGForms', 'parse_shortcode'));
- }
-
- public static function set_logging_supported($plugins)
- {
- $plugins["gravityforms"] = "Gravity Forms Core";
- return $plugins;
- }
-
- public static function maybe_process_form(){
-
- $form_id = isset($_POST["gform_submit"]) ? $_POST["gform_submit"] : 0;
- if($form_id){
- $form_info = RGFormsModel::get_form($form_id);
- $is_valid_form = $form_info && $form_info->is_active;
-
- if($is_valid_form){
- require_once(GFCommon::get_base_path() . "/form_display.php");
- GFFormDisplay::process_form($form_id);
- }
- }
- }
-
- public static function process_exterior_pages(){
- if(rgempty("gf_page", $_GET))
- return;
-
- //ensure users are logged in
- if(!is_user_logged_in())
- auth_redirect();
-
- switch(rgget("gf_page")){
- case "preview":
- require_once(GFCommon::get_base_path() . "/preview.php");
- break;
-
- case "print-entry" :
- require_once(GFCommon::get_base_path() . "/print-entry.php");
- break;
-
- case "select_columns" :
- require_once(GFCommon::get_base_path() . "/select_columns.php");
- break;
- }
- exit();
- }
-
- public static function check_update($update_plugins_option){
- if(!class_exists("GFCommon"))
- require_once("common.php");
-
- return GFCommon::check_update($update_plugins_option, true);
- }
-
- //Creates or updates database tables. Will only run when version changes
- 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";
-
- //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 . " (
- id mediumint(8) unsigned not null auto_increment,
- title varchar(150) not null,
- date_created datetime not null,
- is_active tinyint(1) not null default 1,
- PRIMARY KEY (id)
- ) $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 . " (
- form_id mediumint(8) unsigned not null,
- display_meta longtext,
- entries_grid_meta longtext,
- confirmations longtext,
- notifications longtext,
- PRIMARY KEY (form_id)
- ) $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 . " (
- id bigint(20) unsigned not null auto_increment,
- form_id mediumint(8) unsigned not null,
- date_created datetime not null,
- ip char(15),
- count mediumint(8) unsigned not null default 1,
- PRIMARY KEY (id),
- KEY form_id (form_id)
- ) $charset_collate;";
- dbDelta($sql);
-
- //------ LEAD -----------------------------------------------
- $lead_table_name = RGFormsModel::get_lead_table_name();
- $sql = "CREATE TABLE " . $lead_table_name . " (
- id int(10) unsigned not null auto_increment,
- form_id mediumint(8) unsigned not null,
- post_id bigint(20) unsigned,
- date_created datetime not null,
- is_starred tinyint(1) not null default 0,
- is_read tinyint(1) not null default 0,
- ip varchar(39) not null,
- source_url varchar(200) not null default '',
- user_agent varchar(250) not null default '',
- currency varchar(5),
- payment_status varchar(15),
- payment_date datetime,
- payment_amount decimal(19,2),
- transaction_id varchar(50),
- is_fulfilled tinyint(1),
- created_by bigint(20) unsigned,
- transaction_type tinyint(1),
- status varchar(20) not null default 'active',
- PRIMARY KEY (id),
- KEY form_id (form_id),
- KEY status (status)
- ) $charset_collate;";
- dbDelta($sql);
-
- //------ LEAD NOTES ------------------------------------------
- $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
- $sql = "CREATE TABLE " . $lead_notes_table_name . " (
- id int(10) unsigned not null auto_increment,
- lead_id int(10) unsigned not null,
- user_name varchar(250),
- user_id bigint(20),
- date_created datetime not null,
- value longtext,
- PRIMARY KEY (id),
- KEY lead_id (lead_id),
- KEY lead_user_key (lead_id,user_id)
- ) $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 ."),
- PRIMARY KEY (id),
- KEY form_id (form_id),
- KEY lead_id (lead_id),
- KEY lead_field_number (lead_id,field_number)
- ) $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 . " (
- lead_detail_id bigint(20) unsigned not null,
- value longtext,
- PRIMARY KEY (lead_detail_id)
- ) $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 . " (
- id bigint(20) unsigned not null auto_increment,
- form_id mediumint(8) unsigned not null default 0,
- lead_id bigint(20) unsigned not null,
- meta_key varchar(255),
- meta_value longtext,
- PRIMARY KEY (id),
- KEY meta_key (meta_key),
- KEY lead_id (lead_id),
- KEY form_id_meta_key (form_id,meta_key)
- ) $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", $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);
- }
- }
- }
-
- //Changes form_id values from default value "0" to the correct value. Neededed when upgrading users from 1.6.11
- private static function fix_lead_meta_form_id_values(){
- global $wpdb;
-
- $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
- $lead_table_name = RGFormsModel::get_lead_table_name();
-
- $sql = "UPDATE $lead_meta_table_name lm,$lead_table_name l SET lm.form_id = l.form_id
- WHERE lm.form_id=0 AND lm.lead_id = l.id;
- ";
- $wpdb->get_results($sql);
-
- }
-
- public static function dbdelta_fix_case($cqueries){
- foreach ($cqueries as $table => $qry) {
- $table_name = $table;
- if(preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)){
- $query_table_name = trim($matches[1], '`' );
-
- //fix table names that are different just by their casing
- if(strtolower($query_table_name) == $table){
- $table_name = $query_table_name;
- }
- }
- $queries[$table_name] = $qry;
- }
- return $queries;
- }
-
- public static function no_conflict_mode_style(){
- if(!get_option("gform_enable_noconflict"))
- return;
-
- global $wp_styles;
- $wp_required_styles = array("admin-bar", "colors", "ie", "wp-admin", "editor-style");
- $gf_required_styles = array(
- "common" => array(),
- "gf_edit_forms" => array("thickbox", "editor-buttons", "wp-jquery-ui-dialog", "media-views", "buttons" ),
- "gf_edit_forms_notification" => array("thickbox", "editor-buttons", "wp-jquery-ui-dialog", "media-views", "buttons"),
- "gf_new_form" => array("thickbox"),
- "gf_entries" => array("thickbox"),
- "gf_settings" => array(),
- "gf_export" => array(),
- "gf_help" => array()
- );
-
- self::no_conflict_mode($wp_styles, $wp_required_styles, $gf_required_styles, "styles");
- }
-
-
- public static function no_conflict_mode_script(){
- if(!get_option("gform_enable_noconflict"))
- return;
-
- global $wp_scripts;
-
- $wp_required_scripts = array("admin-bar", "common", "jquery-color", "utils");
- $gf_required_scripts = array(
- "common" => array("qtip-init", "sack"),
- "gf_edit_forms" => array("backbone", "editor", "gform_forms", "gform_form_admin", "gform_form_editor", "gform_gravityforms", "gform_json", "gform_menu", "gform_placeholder", "jquery-ui-autocomplete", "jquery-ui-core", "jquery-ui-datepicker", "jquery-ui-sortable", "jquery-ui-tabs", "json2", "media-editor", "media-models", "media-upload", "media-views", "plupload", "plupload-flash", "plupload-html4", "plupload-html5", "plupload-silverlight", "quicktags", "rg_currency", "thickbox", "word-count", "wp-plupload", "wpdialogs-popup", "wplink"),
- "gf_edit_forms_notification" => array("editor", "word-count", "quicktags", "wpdialogs-popup", "media-upload", "wplink", "backbone", "jquery-ui-sortable", "json2", "media-editor", "media-models", "media-views", "plupload", "plupload-flash", "plupload-html4", "plupload-html5", "plupload-silverlight", "wp-plupload", "gform_placeholder", "gform_json", "jquery-ui-autocomplete"),
- "gf_new_form" => array("thickbox", "jquery-ui-core", "jquery-ui-sortable", "jquery-ui-tabs", "rg_currency", "gforms_gravityforms" ),
- "gf_entries" => array("thickbox", "gforms_gravityforms", "wp-lists", "gform_json"),
- "gf_settings" => array(),
- "gf_export" => array("gform_form_admin","jquery-ui-datepicker"),
- "gf_help" => array(),
- );
-
- self::no_conflict_mode($wp_scripts, $wp_required_scripts, $gf_required_scripts, "scripts");
- }
-
- private static function no_conflict_mode(&$wp_objects, $wp_required_objects, $gf_required_objects, $type="scripts"){
-
- $current_page = trim(strtolower(rgget("page")));
- if(empty($current_page))
- $current_page = trim(strtolower(rgget("gf_page")));
- if(empty($current_page))
- $current_page = RG_CURRENT_PAGE;
-
- $view = rgempty("view", $_GET) ? "default" : rgget("view");
- $page_objects = isset($gf_required_objects[$current_page . "_" . $view]) ? $gf_required_objects[$current_page . "_" . $view] : rgar($gf_required_objects, $current_page);
-
- //disable no-conflict if $page_objects is false
- if($page_objects === false)
- return;
-
- if(!is_array($page_objects))
- $page_objects = array();
-
- //merging wp scripts with gravity forms scripts
- $required_objects = array_merge($wp_required_objects, $gf_required_objects["common"], $page_objects);
-
- //allowing addons or other products to change the list of no conflict scripts
- $required_objects = apply_filters("gform_noconflict_{$type}", $required_objects);
-
- $queue = array();
- foreach($wp_objects->queue as $object){
- if(in_array($object, $required_objects))
- $queue[] = $object;
- }
- $wp_objects->queue = $queue;
-
- $required_objects = self::add_script_dependencies($wp_objects->registered, $required_objects);
-
- //unregistering scripts
- $registered = array();
- foreach($wp_objects->registered as $script_name => $script_registration){
- if(in_array($script_name, $required_objects)){
- $registered[$script_name] = $script_registration;
- }
- }
- $wp_objects->registered = $registered;
- }
-
- private static function add_script_dependencies($registered, $scripts){
-
- //gets all dependent scripts linked to the $scripts array passed
- do{
- $dependents = array();
- foreach($scripts as $script){
- $deps = isset($registered[$script]) && is_array($registered[$script]->deps) ? $registered[$script]->deps : array();
- foreach($deps as $dep){
- if(!in_array($dep, $scripts) && !in_array($dep, $dependents)){
- $dependents[] = $dep;
- }
- }
- }
- $scripts = array_merge($scripts, $dependents);
- }while(!empty($dependents));
-
- return $scripts;
- }
-
- //Integration with ManageWP
- public static function premium_update_push( $premium_update ){
-
- if( !function_exists( 'get_plugin_data' ) )
- include_once( ABSPATH.'wp-admin/includes/plugin.php');
-
- $update = GFCommon::get_version_info();
- if( $update["is_valid_key"] == true && version_compare(GFCommon::$version, $update["version"], '<') ){
- $gforms = get_plugin_data( __FILE__ );
- $gforms['type'] = 'plugin';
- $gforms['slug'] = 'gravityforms/gravityforms.php';
- $gforms['new_version'] = isset($update['version']) ? $update['version'] : false ;
- $premium_update[] = $gforms;
- }
-
- return $premium_update;
- }
-
- //Integration with ManageWP
- public static function premium_update( $premium_update ){
-
- if( !function_exists( 'get_plugin_data' ) )
- include_once( ABSPATH.'wp-admin/includes/plugin.php');
-
- $update = GFCommon::get_version_info();
- if( $update["is_valid_key"] == true && version_compare(GFCommon::$version, $update["version"], '<') ){
- $gforms = get_plugin_data( __FILE__ );
- $gforms['slug'] = 'gravityforms/gravityforms.php'; // If not set by default, always pass theme template
- $gforms['type'] = 'plugin';
- $gforms['url'] = isset($update["url"]) ? $update["url"] : false; // OR provide your own callback function for managing the update
-
- array_push($premium_update, $gforms);
- }
- return $premium_update;
- }
-
- private static function drop_index($table, $index){
- global $wpdb;
- $has_index = $wpdb->get_var("SHOW INDEX FROM {$table} WHERE Key_name='{$index}'");
- if($has_index){
- $wpdb->query("DROP INDEX {$index} ON {$table}");
- }
- }
-
- private static function add_empty_index_files(){
- $upload_root = RGFormsModel::get_upload_root();
- GFCommon::recursive_add_index_file($upload_root);
- }
-
- private static function has_database_permission(&$error){
- global $wpdb;
-
- $wpdb->hide_errors();
-
- $has_permission = true;
-
- $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}rg_test ( col1 int )";
- $wpdb->query($sql);
- $error = "Current database user does not have necessary permissions to create tables.";
- if(!empty($wpdb->last_error))
- $has_permission = false;
-
- if($has_permission){
- $sql = "ALTER TABLE {$wpdb->prefix}rg_test ADD COLUMN a" . uniqid() ." int";
- $wpdb->query($sql);
- $error = "Current database user does not have necessary permissions to modify (ALTER) tables.";
- if(!empty($wpdb->last_error))
- $has_permission = false;
-
- $sql = "DROP TABLE {$wpdb->prefix}rg_test";
- $wpdb->query($sql);
- }
-
- $wpdb->show_errors();
-
- return $has_permission;
- }
-
- //Changes checkbox entry values from "!" to the current choice text. Neededed when upgrading users from 1.0
- private static function fix_checkbox_value(){
- global $wpdb;
-
- $table_name = RGFormsModel::get_lead_details_table_name();
-
- $sql = "select * from $table_name where value= '!'";
- $results = $wpdb->get_results($sql);
- foreach($results as $result){
- $form = RGFormsModel::get_form_meta($result->form_id);
- $field = RGFormsModel::get_field($form, $result->field_number);
- if($field["type"] == "checkbox"){
- $input = GFCommon::get_input($field, $result->field_number);
- $wpdb->update($table_name, array("value" => $input["label"]), array("id" => $result->id));
- }
- }
- }
-
- public static function user_has_cap($all_caps, $cap, $args){
- $gf_caps = GFCommon::all_caps();
- $capability = rgar($cap, 0);
- if($capability != "gform_full_access"){
- return $all_caps;
- }
-
- if(!self::has_members_plugin()){
- //give full access to administrators if the members plugin is not installed
- if(current_user_can("administrator") || is_super_admin()){
- $all_caps["gform_full_access"] = true;
- }
- }
- else if(current_user_can("administrator")|| is_super_admin()){
-
- //checking if user has any GF permission.
- $has_gf_cap = false;
- foreach($gf_caps as $gf_cap){
- if(rgar($all_caps, $gf_cap))
- $has_gf_cap = true;
- }
-
- if(!$has_gf_cap){
- //give full access to administrators if none of the GF permissions are active by the Members plugin
- $all_caps["gform_full_access"] = true;
- }
- }
-
- return $all_caps;
- }
-
- //Target of Member plugin filter. Provides the plugin with Gravity Forms lists of capabilities
- public static function members_get_capabilities( $caps ) {
- return array_merge($caps, GFCommon::all_caps());
- }
-
- //Tests if the upload folder is writable and displays an error message if not
- public static function check_upload_folder(){
- //check if upload folder is writable
- $folder = RGFormsModel::get_upload_root();
- if(empty($folder))
- echo "<div class='error'>Upload folder is not writable. Export and file upload features will not be functional.</div>";
- }
-
- //Prints common admin scripts
- public static function print_scripts(){
- wp_enqueue_script("sack");
- wp_print_scripts();
- }
-
- public static function is_gravity_ajax_action(){
- //Gravity Forms AJAX requests
- $current_action = self::post("action");
- $gf_ajax_actions = array('rg_save_form', 'rg_change_input_type', 'rg_add_field', 'rg_duplicate_field',
- 'rg_delete_field', 'rg_select_export_form', 'rg_start_export', 'gf_upgrade_license',
- 'gf_delete_custom_choice', 'gf_save_custom_choice', 'gf_get_notification_post_categories',
- 'rg_update_lead_property', 'delete-gf_entry', 'rg_update_form_active',
- 'gf_resend_notifications', 'rg_dismiss_upgrade', 'gf_save_confirmation');
-
- if(defined("DOING_AJAX") && DOING_AJAX && in_array($current_action, $gf_ajax_actions))
- return true;
-
- //not a gravity forms ajax request.
- return false;
- }
-
- //Returns true if the current page is one of Gravity Forms pages. Returns false if not
- public static function is_gravity_page(){
-
- //Gravity Forms pages
- $current_page = trim(strtolower(self::get("page")));
- $gf_pages = array("gf_edit_forms", "gf_new_form", "gf_entries", "gf_settings", "gf_export", "gf_help");
-
- return in_array($current_page, $gf_pages);
- }
-
- //Creates "Forms" left nav
- public static function create_menu(){
-
- $has_full_access = current_user_can("gform_full_access");
- $min_cap = GFCommon::current_user_can_which(GFCommon::all_caps());
- if(empty($min_cap))
- $min_cap = "gform_full_access";
-
- $addon_menus = array();
- $addon_menus = apply_filters("gform_addon_navigation", $addon_menus);
-
- $parent_menu = self::get_parent_menu($addon_menus);
-
- // Add a top-level left nav
- $update_icon = GFCommon::has_update() ? "<span title='" . esc_attr(__("Update Available", "gravityforms")) . "' class='update-plugins count-1'><span class='update-count'>1</span></span>" : "";
-
- add_menu_page(__('Forms', "gravityforms"), __("Forms", "gravityforms") . $update_icon , $has_full_access ? "gform_full_access" : $min_cap, $parent_menu["name"] , $parent_menu["callback"], GFCommon::get_base_url() . '/images/gravity-admin-icon.png', apply_filters("gform_menu_position", "16.9"));
-
- // Adding submenu pages
- add_submenu_page($parent_menu["name"], __("Forms", "gravityforms"), __("Forms", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_edit_forms", "gf_edit_forms", array("RGForms", "forms"));
-
- add_submenu_page($parent_menu["name"], __("New Form", "gravityforms"), __("New Form", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_create_form", "gf_new_form", array("RGForms", "new_form"));
-
- add_submenu_page($parent_menu["name"], __("Entries", "gravityforms"), __("Entries", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_view_entries", "gf_entries", array("RGForms", "all_leads_page"));
-
- if(is_array($addon_menus)){
- foreach($addon_menus as $addon_menu)
- add_submenu_page($parent_menu["name"], $addon_menu["label"], $addon_menu["label"], $has_full_access ? "gform_full_access" : $addon_menu["permission"], $addon_menu["name"], $addon_menu["callback"]);
- }
-
- add_submenu_page($parent_menu["name"], __("Settings", "gravityforms"), __("Settings", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_view_settings", "gf_settings", array("RGForms", "settings_page"));
-
- add_submenu_page($parent_menu["name"], __("Import/Export", "gravityforms"), __("Import/Export", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_export_entries", "gf_export", array("RGForms", "export_page"));
-
- if(current_user_can("install_plugins")){
- add_submenu_page($parent_menu["name"], __("Updates", "gravityforms"), __("Updates", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_view_updates", "gf_update", array("RGForms", "update_page"));
- add_submenu_page($parent_menu["name"], __("Add-Ons", "gravityforms"), __("Add-Ons", "gravityforms"), $has_full_access ? "gform_full_access" : "gravityforms_view_addons", "gf_addons", array("RGForms", "addons_page"));
- }
-
- add_submenu_page($parent_menu["name"], __("Help", "gravityforms"), __("Help", "gravityforms"), $has_full_access ? "gform_full_access" : $min_cap, "gf_help", array("RGForms", "help_page"));
-
- }
-
- //Returns the parent menu item. It needs to be the same as the first sub-menu (otherwise WP will duplicate the main menu as a sub-menu)
- public static function get_parent_menu($addon_menus){
-
- if(GFCommon::current_user_can_any("gravityforms_edit_forms"))
- $parent = array("name" => "gf_edit_forms", "callback" => array("RGForms", "forms"));
-
- else if(GFCommon::current_user_can_any("gravityforms_create_form"))
- $parent = array("name" => "gf_new_form", "callback" => array("RGForms", "new_form"));
-
- else if(GFCommon::current_user_can_any("gravityforms_view_entries"))
- $parent = array("name" => "gf_entries", "callback" => array("RGForms", "all_leads_page"));
-
- else if(is_array($addon_menus) && sizeof($addon_menus) > 0){
- foreach($addon_menus as $addon_menu)
- if(GFCommon::current_user_can_any($addon_menu["permission"]))
- {
- $parent = array("name" => $addon_menu["name"], "callback" => $addon_menu["callback"]);
- break;
- }
- }
- else if(GFCommon::current_user_can_any("gravityforms_view_settings"))
- $parent = array("name" => "gf_settings", "callback" => array("RGForms", "settings_page"));
-
- else if(GFCommon::current_user_can_any("gravityforms_export_entries"))
- $parent = array("name" => "gf_export", "callback" => array("RGForms", "export_page"));
-
- else if(GFCommon::current_user_can_any("gravityforms_view_updates"))
- $parent = array("name" => "gf_update", "callback" => array("RGForms", "update_page"));
-
- else if(GFCommon::current_user_can_any("gravityforms_view_addons"))
- $parent = array("name" => "gf_addons", "callback" => array("RGForms", "addons_page"));
-
- else if(GFCommon::current_user_can_any(GFCommon::all_caps()))
- $parent = array("name" => "gf_help", "callback" => array("RGForms", "help_page"));
-
- return $parent;
- }
-
- //Parses the [gravityform shortcode and returns the front end form UI
- public static function parse_shortcode( $attributes, $content = null ) {
-
- extract( shortcode_atts( array(
- 'title' => true,
- 'description' => true,
- 'id' => 0,
- 'name' => '',
- 'field_values' => "",
- 'ajax' => false,
- 'tabindex' => 1,
- 'action' => 'form'
- ), $attributes ) );
-
- $shortcode_string = "";
-
- switch($action) {
- case 'conditional':
- $shortcode_string = GFCommon::conditional_shortcode($attributes, $content);
- break;
-
- case 'form' :
- //displaying form
- $title = strtolower($title) == "false" ? false : true;
- $description = strtolower($description) == "false" ? false : true;
- $field_values = htmlspecialchars_decode($field_values);
- $field_values = str_replace("&", "&", $field_values);
-
- $ajax = strtolower($ajax) == "true" ? true : false;
-
- //using name to lookup form if id is not specified
- if(empty($id))
- $id = $name;
-
- parse_str($field_values, $field_value_array); //parsing query string like string for field values and placing them into an associative array
- $field_value_array = stripslashes_deep($field_value_array);
-
- $shortcode_string = self::get_form($id, $title, $description, false, $field_value_array, $ajax, $tabindex);
-
- break;
- }
-
- $shortcode_string = apply_filters("gform_shortcode_{$action}", $shortcode_string, $attributes, $content);
-
- return $shortcode_string;
- }
-
- //-------------------------------------------------
- //----------- AJAX --------------------------------
-
- public static function ajax_parse_request($wp) {
-
- if (isset($_POST["gform_ajax"])) {
- parse_str($_POST["gform_ajax"]);
-
- require_once(GFCommon::get_base_path() . "/form_display.php");
- $result = GFFormDisplay::get_form($form_id, $title, $description, false, $_POST["gform_field_values"], true);
- die($result);
- }
- }
-
- //------------------------------------------------------
- //------------- PAGE/POST EDIT PAGE ---------------------
-
- //Action target that adds the "Insert Form" button to the post/page edit screen
- public static function add_form_button(){
- $is_post_edit_page = in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'));
- if(!$is_post_edit_page)
- return;
-
- // do a version check for the new 3.5 UI
- $version = get_bloginfo('version');
-
- if ($version < 3.5) {
- // show button for v 3.4 and below
- $image_btn = GFCommon::get_base_url() . "/images/form-button.png";
- echo '<a href="#TB_inline?width=480&inlineId=select_gravity_form" class="thickbox" id="add_gform" title="' . __("Add Gravity Form", 'gravityforms') . '"><img src="'.$image_btn.'" alt="' . __("Add Gravity Form", 'gravityforms') . '" /></a>';
- } else {
- // display button matching new UI
- echo '<style>.gform_media_icon{
- background:url(' . GFCommon::get_base_url() . '/images/gravity-admin-icon.png) no-repeat top left;
- display: inline-block;
- height: 16px;
- margin: 0 2px 0 0;
- vertical-align: text-top;
- width: 16px;
- }
- .wp-core-ui a.gform_media_link{
- padding-left: 0.4em;
- }
- </style>
- <a href="#TB_inline?width=480&inlineId=select_gravity_form" class="thickbox button gform_media_link" id="add_gform" title="' . __("Add Gravity Form", 'gravityforms') . '"><span class="gform_media_icon "></span> ' . __("Add Form", "gravityforms") . '</a>';
- }
- }
-
-
- //Action target that displays the popup to insert a form to a post/page
- public static function add_mce_popup(){
- ?>
- <script>
- function InsertForm(){
- var form_id = jQuery("#add_form_id").val();
- if(form_id == ""){
- alert("<?php _e("Please select a form", "gravityforms") ?>");
- return;
- }
-
- var form_name = jQuery("#add_form_id option[value='" + form_id + "']").text().replace(/[\[\]]/g, '');
- var display_title = jQuery("#display_title").is(":checked");
- var display_description = jQuery("#display_description").is(":checked");
- var ajax = jQuery("#gform_ajax").is(":checked");
- var title_qs = !display_title ? " title=\"false\"" : "";
- var description_qs = !display_description ? " description=\"false\"" : "";
- var ajax_qs = ajax ? " ajax=\"true\"" : "";
-
- window.send_to_editor("[gravityform id=\"" + form_id + "\" name=\"" + form_name + "\"" + title_qs + description_qs + ajax_qs + "]");
- }
- </script>
-
- <div id="select_gravity_form" style="display:none;">
- <div class="wrap">
- <div>
- <div style="padding:15px 15px 0 15px;">
- <h3 style="color:#5A5A5A!important; font-family:Georgia,Times New Roman,Times,serif!important; font-size:1.8em!important; font-weight:normal!important;"><?php _e("Insert A Form", "gravityforms"); ?></h3>
- <span>
- <?php _e("Select a form below to add it to your post or page.", "gravityforms"); ?>
- </span>
- </div>
- <div style="padding:15px 15px 0 15px;">
- <select id="add_form_id">
- <option value=""> <?php _e("Select a Form", "gravityforms"); ?> </option>
- <?php
- $forms = RGFormsModel::get_forms(1, "title");
- foreach($forms as $form){
- ?>
- <option value="<?php echo absint($form->id) ?>"><?php echo esc_html($form->title) ?></option>
- <?php
- }
- ?>
- </select> <br/>
- <div style="padding:8px 0 0 0; font-size:11px; font-style:italic; color:#5A5A5A"><?php _e("Can't find your form? Make sure it is active.", "gravityforms"); ?></div>
- </div>
- <div style="padding:15px 15px 0 15px;">
- <input type="checkbox" id="display_title" checked='checked' /> <label for="display_title"><?php _e("Display form title", "gravityforms"); ?></label>
- <input type="checkbox" id="display_description" checked='checked' /> <label for="display_description"><?php _e("Display form description", "gravityforms"); ?></label>
- <input type="checkbox" id="gform_ajax" /> <label for="gform_ajax"><?php _e("Enable AJAX", "gravityforms"); ?></label>
- </div>
- <div style="padding:15px;">
- <input type="button" class="button-primary" value="Insert Form" onclick="InsertForm();"/>
- <a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php _e("Cancel", "gravityforms"); ?></a>
- </div>
- </div>
- </div>
- </div>
-
- <?php
- }
-
-
- //------------------------------------------------------
- //------------- PLUGINS PAGE ---------------------------
- //------------------------------------------------------
-
- public static function plugin_settings_link( $links, $file ) {
- if ( $file != plugin_basenam…
Large files files are truncated, but you can click here to view the full file