PageRenderTime 69ms CodeModel.GetById 23ms RepoModel.GetById 2ms app.codeStats 0ms

/wp-content/plugins/gravityforms/gravityforms.php

https://bitbucket.org/betaimages/chakalos
PHP | 1801 lines | 1290 code | 361 blank | 150 comment | 236 complexity | 30cb69e672a4f5c6ce8d653f2dde6ac0 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. Plugin Name: Gravity Forms
  4. Plugin URI: http://www.gravityforms.com
  5. Description: Easily create web forms and manage form entries within the WordPress admin.
  6. Version: 1.6.11
  7. Author: rocketgenius
  8. Author URI: http://www.rocketgenius.com
  9. ------------------------------------------------------------------------
  10. Copyright 2009-2011 Rocketgenius Inc.
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. //------------------------------------------------------------------------------------------------------------------
  24. //---------- Gravity Forms License Key -----------------------------------------------------------------------------
  25. //------------------------------------------------------------------------------------------------------------------
  26. //If you hardcode a Gravity Forms License Key here, it will automatically populate on activation.
  27. $gf_license_key = "";
  28. //-- OR ---//
  29. //You can also add the Gravity Forms license key to your wp-config.php file to automatically populate on activation
  30. //Add the code in the comment below to your wp-config.php to do so:
  31. //define('GF_LICENSE_KEY','YOUR_KEY_GOES_HERE');
  32. //------------------------------------------------------------------------------------------------------------------
  33. //------------------------------------------------------------------------------------------------------------------
  34. //---------- reCAPTCHA Keys -----------------------------------------------------------------------------
  35. //------------------------------------------------------------------------------------------------------------------
  36. //If you hardcode your reCAPTCHA Keys here, it will automatically populate on activation.
  37. $gf_recaptcha_private_key = "";
  38. $gf_recaptcha_public_key = "";
  39. //-- OR ---//
  40. //You can also add the reCAPTCHA keys to your wp-config.php file to automatically populate on activation
  41. //Add the two lines of code in the comment below to your wp-config.php to do so:
  42. //define('GF_RECAPTCHA_PRIVATE_KEY','YOUR_PRIVATE_KEY_GOES_HERE');
  43. //define('GF_RECAPTCHA_PUBLIC_KEY','YOUR_PUBLIC_KEY_GOES_HERE');
  44. //------------------------------------------------------------------------------------------------------------------
  45. if(!defined("RG_CURRENT_PAGE"))
  46. define("RG_CURRENT_PAGE", basename($_SERVER['PHP_SELF']));
  47. if(!defined("IS_ADMIN"))
  48. define("IS_ADMIN", is_admin());
  49. define("RG_CURRENT_VIEW", RGForms::get("view"));
  50. define("GF_MIN_WP_VERSION", '3.2');
  51. define("GF_SUPPORTED_WP_VERSION", version_compare(get_bloginfo("version"), GF_MIN_WP_VERSION, '>='));
  52. if(!defined("GRAVITY_MANAGER_URL"))
  53. define("GRAVITY_MANAGER_URL", "http://www.gravityhelp.com/wp-content/plugins/gravitymanager");
  54. require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/common.php");
  55. require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/forms_model.php");
  56. require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/widget.php");
  57. add_action('init', array('RGForms', 'init'));
  58. add_action('wp', array('RGForms', 'maybe_process_form'), 9);
  59. add_action('wp', array('RGForms', 'process_exterior_pages'));
  60. add_filter('user_has_cap', array("RGForms", "user_has_cap"), 10, 3);
  61. //Hooks for no-conflict functionality
  62. if(is_admin() && (RGForms::is_gravity_page() || RGForms::is_gravity_ajax_action())){
  63. add_action("wp_print_scripts", array("RGForms", "no_conflict_mode_script"), 1000);
  64. add_action("admin_print_footer_scripts", array("RGForms", "no_conflict_mode_script"), 9);
  65. add_action("wp_print_styles", array("RGForms", "no_conflict_mode_style"), 1000);
  66. add_action("admin_print_styles", array("RGForms", "no_conflict_mode_style"), 1);
  67. add_action("admin_print_footer_scripts", array("RGForms", "no_conflict_mode_style"), 1);
  68. add_action("admin_footer", array("RGForms", "no_conflict_mode_style"), 1);
  69. }
  70. class RGForms{
  71. public static function has_members_plugin(){
  72. return function_exists( 'members_get_capabilities' );
  73. }
  74. //Plugin starting point. Will load appropriate files
  75. public static function init(){
  76. load_plugin_textdomain( 'gravityforms', false, '/gravityforms/languages' );
  77. add_filter("gform_logging_supported", array("RGForms", "set_logging_supported"));
  78. if(IS_ADMIN){
  79. global $current_user;
  80. //Members plugin integration. Adding Gravity Forms roles to the checkbox list
  81. if (self::has_members_plugin())
  82. add_filter('members_get_capabilities', array("RGForms", "members_get_capabilities"));
  83. //Loading Gravity Forms if user has access to any functionality
  84. if(GFCommon::current_user_can_any(GFCommon::all_caps()))
  85. {
  86. require_once(GFCommon::get_base_path() . "/export.php");
  87. GFExport::maybe_export();
  88. //runs the setup when version changes
  89. self::setup();
  90. //creates the "Forms" left menu
  91. add_action('admin_menu', array('RGForms', 'create_menu'));
  92. if(GF_SUPPORTED_WP_VERSION){
  93. add_action('admin_footer', array('RGForms', 'check_upload_folder'));
  94. add_action('wp_dashboard_setup', array('RGForms', 'dashboard_setup'));
  95. //Adding "embed form" button
  96. add_action('media_buttons', array('RGForms', 'add_form_button'), 20);
  97. //Plugin update actions
  98. add_filter("transient_update_plugins", array('RGForms', 'check_update'));
  99. add_filter("site_transient_update_plugins", array('RGForms', 'check_update'));
  100. if(in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))){
  101. add_action('admin_footer', array('RGForms', 'add_mce_popup'));
  102. }
  103. else if(self::is_gravity_page()){
  104. require_once(GFCommon::get_base_path() . "/tooltips.php");
  105. add_action("admin_print_scripts", array('RGForms', 'print_scripts'));
  106. }
  107. else if(RG_CURRENT_PAGE == 'media-upload.php'){
  108. require_once(GFCommon::get_base_path() . "/entry_list.php");
  109. }
  110. else if(in_array(RG_CURRENT_PAGE, array("admin.php", "admin-ajax.php"))){
  111. add_action('wp_ajax_rg_save_form', array('RGForms', 'save_form'));
  112. add_action('wp_ajax_rg_change_input_type', array('RGForms', 'change_input_type'));
  113. add_action('wp_ajax_rg_add_field', array('RGForms', 'add_field'));
  114. add_action('wp_ajax_rg_duplicate_field', array('RGForms', 'duplicate_field'));
  115. add_action('wp_ajax_rg_delete_field', array('RGForms', 'delete_field'));
  116. add_action('wp_ajax_rg_delete_file', array('RGForms', 'delete_file'));
  117. add_action('wp_ajax_rg_select_export_form', array('RGForms', 'select_export_form'));
  118. add_action('wp_ajax_rg_start_export', array('RGForms', 'start_export'));
  119. add_action('wp_ajax_gf_upgrade_license', array('RGForms', 'upgrade_license'));
  120. add_action('wp_ajax_gf_delete_custom_choice', array('RGForms', 'delete_custom_choice'));
  121. add_action('wp_ajax_gf_save_custom_choice', array('RGForms', 'save_custom_choice'));
  122. add_action('wp_ajax_gf_get_post_categories', array('RGForms', 'get_post_category_values'));
  123. add_action('wp_ajax_gf_get_notification_post_categories', array('RGForms', 'get_notification_post_category_values'));
  124. //entry list ajax operations
  125. add_action('wp_ajax_rg_update_lead_property', array('RGForms', 'update_lead_property'));
  126. add_action('wp_ajax_delete-gf_entry', array('RGForms', 'update_lead_status'));
  127. //form list ajax operations
  128. add_action('wp_ajax_rg_update_form_active', array('RGForms', 'update_form_active'));
  129. //dynamic captcha image
  130. add_action('wp_ajax_rg_captcha_image', array('RGForms', 'captcha_image'));
  131. //dashboard message "dismiss upgrade" link
  132. add_action("wp_ajax_rg_dismiss_upgrade", array('RGForms', 'dashboard_dismiss_upgrade'));
  133. // entry detial: resend notifications
  134. add_action("wp_ajax_gf_resend_notifications", array('RGForms', 'resend_notifications'));
  135. }
  136. add_filter("plugins_api", array("RGForms", "get_addon_info"), 10, 3);
  137. add_action('after_plugin_row_gravityforms/gravityforms.php', array('RGForms', 'plugin_row') );
  138. add_action('install_plugins_pre_plugin-information', array('RGForms', 'display_changelog'));
  139. add_filter('plugin_action_links', array('RGForms', 'plugin_settings_link'),10,2);
  140. }
  141. }
  142. }
  143. else{
  144. add_action('wp_enqueue_scripts', array('RGForms', 'enqueue_scripts'));
  145. add_action('wp', array('RGForms', 'ajax_parse_request'), 10);
  146. // ManageWP premium update filters
  147. add_filter( 'mwp_premium_update_notification', array('RGForms', 'premium_update_push') );
  148. add_filter( 'mwp_premium_perform_update', array('RGForms', 'premium_update') );
  149. }
  150. add_shortcode('gravityform', array('RGForms', 'parse_shortcode'));
  151. add_shortcode('gravityforms', array('RGForms', 'parse_shortcode'));
  152. }
  153. public static function set_logging_supported($plugins)
  154. {
  155. $plugins["gravityforms"] = "Gravity Forms Core";
  156. return $plugins;
  157. }
  158. public static function maybe_process_form(){
  159. $form_id = isset($_POST["gform_submit"]) ? $_POST["gform_submit"] : 0;
  160. if($form_id){
  161. $form_info = RGFormsModel::get_form($form_id);
  162. $is_valid_form = $form_info && $form_info->is_active;
  163. if($is_valid_form){
  164. require_once(GFCommon::get_base_path() . "/form_display.php");
  165. GFFormDisplay::process_form($form_id);
  166. }
  167. }
  168. }
  169. public static function process_exterior_pages(){
  170. if(rgempty("gf_page", $_GET))
  171. return;
  172. //ensure users are logged in
  173. if(!is_user_logged_in())
  174. auth_redirect();
  175. switch(rgget("gf_page")){
  176. case "preview":
  177. require_once(GFCommon::get_base_path() . "/preview.php");
  178. break;
  179. case "print-entry" :
  180. require_once(GFCommon::get_base_path() . "/print-entry.php");
  181. break;
  182. case "select_columns" :
  183. require_once(GFCommon::get_base_path() . "/select_columns.php");
  184. break;
  185. }
  186. exit();
  187. }
  188. public static function check_update($update_plugins_option){
  189. if(!class_exists("GFCommon"))
  190. require_once("common.php");
  191. return GFCommon::check_update($update_plugins_option, true);
  192. }
  193. //Creates or updates database tables. Will only run when version changes
  194. public static function setup($force_setup = false){
  195. global $wpdb;
  196. $version = GFCommon::$version;
  197. if(get_option("rg_form_version") != $version || $force_setup){
  198. $error = "";
  199. if(!self::has_database_permission($error)){
  200. ?>
  201. <div class='error' style="padding:15px;"><?php echo $error?></div>
  202. <?php
  203. }
  204. require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
  205. if ( ! empty($wpdb->charset) )
  206. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  207. if ( ! empty($wpdb->collate) )
  208. $charset_collate .= " COLLATE $wpdb->collate";
  209. //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
  210. add_filter( 'dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
  211. //------ FORM -----------------------------------------------
  212. $form_table_name = RGFormsModel::get_form_table_name();
  213. $sql = "CREATE TABLE " . $form_table_name . " (
  214. id mediumint(8) unsigned not null auto_increment,
  215. title varchar(150) not null,
  216. date_created datetime not null,
  217. is_active tinyint(1) not null default 1,
  218. PRIMARY KEY (id)
  219. ) $charset_collate;";
  220. dbDelta($sql);
  221. //droping table that was created by mistake in version 1.6.3.2
  222. $wpdb->query("DROP TABLE IF EXISTS A" . $form_table_name);
  223. //------ META -----------------------------------------------
  224. $meta_table_name = RGFormsModel::get_meta_table_name();
  225. $sql = "CREATE TABLE " . $meta_table_name . " (
  226. form_id mediumint(8) unsigned not null,
  227. display_meta longtext,
  228. entries_grid_meta longtext,
  229. PRIMARY KEY (form_id)
  230. ) $charset_collate;";
  231. dbDelta($sql);
  232. //droping outdated form_id index (if one exists)
  233. self::drop_index($meta_table_name, 'form_id');
  234. //------ FORM VIEW -----------------------------------------------
  235. $form_view_table_name = RGFormsModel::get_form_view_table_name();
  236. $sql = "CREATE TABLE " . $form_view_table_name . " (
  237. id bigint(20) unsigned not null auto_increment,
  238. form_id mediumint(8) unsigned not null,
  239. date_created datetime not null,
  240. ip char(15),
  241. count mediumint(8) unsigned not null default 1,
  242. PRIMARY KEY (id),
  243. KEY form_id (form_id)
  244. ) $charset_collate;";
  245. dbDelta($sql);
  246. //------ LEAD -----------------------------------------------
  247. $lead_table_name = RGFormsModel::get_lead_table_name();
  248. $sql = "CREATE TABLE " . $lead_table_name . " (
  249. id int(10) unsigned not null auto_increment,
  250. form_id mediumint(8) unsigned not null,
  251. post_id bigint(20) unsigned,
  252. date_created datetime not null,
  253. is_starred tinyint(1) not null default 0,
  254. is_read tinyint(1) not null default 0,
  255. ip varchar(39) not null,
  256. source_url varchar(200) not null default '',
  257. user_agent varchar(250) not null default '',
  258. currency varchar(5),
  259. payment_status varchar(15),
  260. payment_date datetime,
  261. payment_amount decimal(19,2),
  262. transaction_id varchar(50),
  263. is_fulfilled tinyint(1),
  264. created_by bigint(20) unsigned,
  265. transaction_type tinyint(1),
  266. status varchar(20) not null default 'active',
  267. PRIMARY KEY (id),
  268. KEY form_id (form_id),
  269. KEY status (status)
  270. ) $charset_collate;";
  271. dbDelta($sql);
  272. //------ LEAD NOTES ------------------------------------------
  273. $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
  274. $sql = "CREATE TABLE " . $lead_notes_table_name . " (
  275. id int(10) unsigned not null auto_increment,
  276. lead_id int(10) unsigned not null,
  277. user_name varchar(250),
  278. user_id bigint(20),
  279. date_created datetime not null,
  280. value longtext,
  281. PRIMARY KEY (id),
  282. KEY lead_id (lead_id),
  283. KEY lead_user_key (lead_id,user_id)
  284. ) $charset_collate;";
  285. dbDelta($sql);
  286. //------ LEAD DETAIL -----------------------------------------
  287. $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
  288. $sql = "CREATE TABLE " . $lead_detail_table_name . " (
  289. id bigint(20) unsigned not null auto_increment,
  290. lead_id int(10) unsigned not null,
  291. form_id mediumint(8) unsigned not null,
  292. field_number float not null,
  293. value varchar(". GFORMS_MAX_FIELD_LENGTH ."),
  294. PRIMARY KEY (id),
  295. KEY form_id (form_id),
  296. KEY lead_id (lead_id)
  297. ) $charset_collate;";
  298. dbDelta($sql);
  299. //------ LEAD DETAIL LONG -----------------------------------
  300. $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
  301. $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (
  302. lead_detail_id bigint(20) unsigned not null,
  303. value longtext,
  304. PRIMARY KEY (lead_detail_id)
  305. ) $charset_collate;";
  306. dbDelta($sql);
  307. //droping outdated form_id index (if one exists)
  308. self::drop_index($lead_detail_long_table_name, 'lead_detail_key');
  309. //------ LEAD META -----------------------------------
  310. $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
  311. $sql = "CREATE TABLE " . $lead_meta_table_name . " (
  312. id bigint(20) unsigned not null auto_increment,
  313. lead_id bigint(20) unsigned not null,
  314. meta_key varchar(255),
  315. meta_value longtext,
  316. PRIMARY KEY (id),
  317. KEY meta_key (meta_key),
  318. KEY lead_id (lead_id)
  319. ) $charset_collate;";
  320. dbDelta($sql);
  321. remove_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
  322. //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
  323. self::fix_checkbox_value();
  324. //auto-setting license key based on value configured via the GF_LICENSE_KEY constant or the gf_license_key variable
  325. global $gf_license_key;
  326. $license_key = defined("GF_LICENSE_KEY") && empty($gf_license_key) ? GF_LICENSE_KEY : $gf_license_key;
  327. if(!empty($license_key))
  328. update_option("rg_gforms_key", md5($license_key));
  329. //auto-setting recaptcha keys based on value configured via the constant or global variable
  330. global $gf_recaptcha_public_key, $gf_recaptcha_private_key;
  331. $private_key = defined("GF_RECAPTCHA_PRIVATE_KEY") && empty($gf_recaptcha_private_key) ? GF_RECAPTCHA_PRIVATE_KEY : $gf_recaptcha_private_key;
  332. if(!empty($private_key))
  333. update_option("rg_gforms_captcha_private_key", $private_key);
  334. $public_key = defined("GF_RECAPTCHA_PUBLIC_KEY") && empty($gf_recaptcha_public_key) ? GF_RECAPTCHA_PUBLIC_KEY : $gf_recaptcha_public_key;
  335. if(!empty($public_key))
  336. update_option("rg_gforms_captcha_public_key", $public_key);
  337. //Auto-importing forms based on GF_IMPORT_FILE AND GF_THEME_IMPORT_FILE
  338. if(defined("GF_IMPORT_FILE") && !get_option("gf_imported_file")){
  339. GFExport::import_file(GF_IMPORT_FILE);
  340. update_option("gf_imported_file", true);
  341. }
  342. //adds empty index.php files to upload folders. only for v1.5.2 and below
  343. if(version_compare(get_option("rg_form_version"), "1.6", "<")){
  344. self::add_empty_index_files();
  345. }
  346. update_option("rg_form_version", $version);
  347. }
  348. //Import theme specific forms if configured. Will only import forms once per theme.
  349. if(defined("GF_THEME_IMPORT_FILE")){
  350. $themes = get_option("gf_imported_theme_file");
  351. if(!is_array($themes))
  352. $themes = array();
  353. //if current theme has already imported it's forms, don't import again
  354. $theme = get_template();
  355. if(!isset($themes[$theme])){
  356. //importing forms
  357. GFExport::import_file(get_stylesheet_directory() . "/" . GF_THEME_IMPORT_FILE);
  358. //adding current theme to the list of imported themes. So that forms are not imported again for it.
  359. $themes[$theme] = true;
  360. update_option("gf_imported_theme_file", $themes);
  361. }
  362. }
  363. }
  364. public static function dbdelta_fix_case($cqueries){
  365. foreach ($cqueries as $table => $qry) {
  366. $table_name = $table;
  367. if(preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)){
  368. $query_table_name = trim($matches[1], '`' );
  369. //fix table names that are different just by their casing
  370. if(strtolower($query_table_name) == $table){
  371. $table_name = $query_table_name;
  372. }
  373. }
  374. $queries[$table_name] = $qry;
  375. }
  376. return $queries;
  377. }
  378. public static function no_conflict_mode_style(){
  379. if(!get_option("gform_enable_noconflict"))
  380. return;
  381. global $wp_styles;
  382. $wp_required_styles = array("admin-bar", "colors", "ie", "wp-admin");
  383. $gf_required_styles = array(
  384. "common" => array(),
  385. "gf_edit_forms" => array("thickbox"),
  386. "gf_edit_forms_notification" => array("thickbox", "editor-buttons", "wp-jquery-ui-dialog"),
  387. "gf_new_form" => array("thickbox"),
  388. "gf_entries" => array("thickbox"),
  389. "gf_settings" => array(),
  390. "gf_export" => array(),
  391. "gf_help" => array()
  392. );
  393. self::no_conflict_mode($wp_styles, $wp_required_styles, $gf_required_styles, "styles");
  394. }
  395. public static function no_conflict_mode_script(){
  396. if(!get_option("gform_enable_noconflict"))
  397. return;
  398. global $wp_scripts;
  399. $wp_required_scripts = array("admin-bar", "common", "jquery-color", "utils");
  400. $gf_required_scripts = array(
  401. "common" => array("qtip-init", "sack"),
  402. "gf_edit_forms" => array("thickbox", "jquery-ui-core", "jquery-ui-sortable", "jquery-ui-tabs", "rg_currency", "gforms_gravityforms" ),
  403. "gf_edit_forms_notification" => array("editor", "word-count", "quicktags", "wpdialogs-popup", "media-upload", "wplink"),
  404. "gf_new_form" => array("thickbox", "jquery-ui-core", "jquery-ui-sortable", "jquery-ui-tabs", "rg_currency", "gforms_gravityforms" ),
  405. "gf_entries" => array("thickbox", "gforms_gravityforms"),
  406. "gf_settings" => array(),
  407. "gf_export" => array(),
  408. "gf_help" => array(),
  409. );
  410. self::no_conflict_mode($wp_scripts, $wp_required_scripts, $gf_required_scripts, "scripts");
  411. }
  412. private static function no_conflict_mode(&$wp_objects, $wp_required_objects, $gf_required_objects, $type="scripts"){
  413. $current_page = trim(strtolower(rgget("page")));
  414. if(empty($current_page))
  415. $current_page = trim(strtolower(rgget("gf_page")));
  416. if(empty($current_page))
  417. $current_page = RG_CURRENT_PAGE;
  418. $view = rgempty("view", $_GET) ? "default" : rgget("view");
  419. $page_objects = isset($gf_required_objects[$current_page . "_" . $view]) ? $gf_required_objects[$current_page . "_" . $view] : rgar($gf_required_objects, $current_page);
  420. //disable no-conflict if $page_objects is false
  421. if($page_objects === false)
  422. return;
  423. if(!is_array($page_objects))
  424. $page_objects = array();
  425. //merging wp scripts with gravity forms scripts
  426. $required_objects = array_merge($wp_required_objects, $gf_required_objects["common"], $page_objects);
  427. //allowing addons or other products to change the list of no conflict scripts
  428. $required_objects = apply_filters("gform_noconflict_{$type}", $required_objects);
  429. $queue = array();
  430. foreach($wp_objects->queue as $object){
  431. if(in_array($object, $required_objects))
  432. $queue[] = $object;
  433. }
  434. $wp_objects->queue = $queue;
  435. $required_objects = self::add_script_dependencies($wp_objects->registered, $required_objects);
  436. //unregistering scripts
  437. $registered = array();
  438. foreach($wp_objects->registered as $script_name => $script_registration){
  439. if(in_array($script_name, $required_objects)){
  440. $registered[$script_name] = $script_registration;
  441. }
  442. }
  443. $wp_objects->registered = $registered;
  444. }
  445. private static function add_script_dependencies($registered, $scripts){
  446. //gets all dependent scripts linked to the $scripts array passed
  447. do{
  448. $dependents = array();
  449. foreach($scripts as $script){
  450. $deps = isset($registered[$script]) && is_array($registered[$script]->deps) ? $registered[$script]->deps : array();
  451. foreach($deps as $dep){
  452. if(!in_array($dep, $scripts) && !in_array($dep, $dependents)){
  453. $dependents[] = $dep;
  454. }
  455. }
  456. }
  457. $scripts = array_merge($scripts, $dependents);
  458. }while(!empty($dependents));
  459. return $scripts;
  460. }
  461. //Integration with ManageWP
  462. public static function premium_update_push( $premium_update ){
  463. if( !function_exists( 'get_plugin_data' ) )
  464. include_once( ABSPATH.'wp-admin/includes/plugin.php');
  465. $update = GFCommon::get_version_info();
  466. if( $update["is_valid_key"] == true && version_compare(GFCommon::$version, $update["version"], '<') ){
  467. $gforms = get_plugin_data( __FILE__ );
  468. $gforms['type'] = 'plugin';
  469. $gforms['slug'] = 'gravityforms/gravityforms.php';
  470. $gforms['new_version'] = isset($update['version']) ? $update['version'] : false ;
  471. $premium_update[] = $gforms;
  472. }
  473. return $premium_update;
  474. }
  475. //Integration with ManageWP
  476. public static function premium_update( $premium_update ){
  477. if( !function_exists( 'get_plugin_data' ) )
  478. include_once( ABSPATH.'wp-admin/includes/plugin.php');
  479. $update = GFCommon::get_version_info();
  480. if( $update["is_valid_key"] == true && version_compare(GFCommon::$version, $update["version"], '<') ){
  481. $gforms = get_plugin_data( __FILE__ );
  482. $gforms['slug'] = 'gravityforms/gravityforms.php'; // If not set by default, always pass theme template
  483. $gforms['type'] = 'plugin';
  484. $gforms['url'] = isset($update["url"]) ? $update["url"] : false; // OR provide your own callback function for managing the update
  485. array_push($premium_update, $gforms);
  486. }
  487. return $premium_update;
  488. }
  489. private static function drop_index($table, $index){
  490. global $wpdb;
  491. $has_index = $wpdb->get_var("SHOW INDEX FROM {$table} WHERE Key_name='{$index}'");
  492. if($has_index){
  493. $wpdb->query("DROP INDEX {$index} ON {$table}");
  494. }
  495. }
  496. private static function add_empty_index_files(){
  497. $upload_root = RGFormsModel::get_upload_root();
  498. GFCommon::recursive_add_index_file($upload_root);
  499. }
  500. private static function has_database_permission(&$error){
  501. global $wpdb;
  502. $wpdb->hide_errors();
  503. $has_permission = true;
  504. $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}rg_test ( col1 int )";
  505. $wpdb->query($sql);
  506. $error = "Current database user does not have necessary permissions to create tables.";
  507. if(!empty($wpdb->last_error))
  508. $has_permission = false;
  509. $sql = "ALTER TABLE {$wpdb->prefix}rg_test ADD COLUMN a" . uniqid() ." int";
  510. $wpdb->query($sql);
  511. $error = "Current database user does not have necessary permissions to modify (ALTER) tables.";
  512. if(!empty($wpdb->last_error))
  513. $has_permission = false;
  514. $sql = "DROP TABLE {$wpdb->prefix}rg_test";
  515. $wpdb->query($sql);
  516. $wpdb->show_errors();
  517. return $has_permission;
  518. }
  519. //Changes checkbox entry values from "!" to the current choice text. Neededed when upgrading users from 1.0
  520. private static function fix_checkbox_value(){
  521. global $wpdb;
  522. $table_name = RGFormsModel::get_lead_details_table_name();
  523. $sql = "select * from $table_name where value= '!'";
  524. $results = $wpdb->get_results($sql);
  525. foreach($results as $result){
  526. $form = RGFormsModel::get_form_meta($result->form_id);
  527. $field = RGFormsModel::get_field($form, $result->field_number);
  528. if($field["type"] == "checkbox"){
  529. $input = GFCommon::get_input($field, $result->field_number);
  530. $wpdb->update($table_name, array("value" => $input["label"]), array("id" => $result->id));
  531. }
  532. }
  533. }
  534. public static function user_has_cap($all_caps, $cap, $args){
  535. $gf_caps = GFCommon::all_caps();
  536. $capability = rgar($cap, 0);
  537. if($capability != "gform_full_access"){
  538. return $all_caps;
  539. }
  540. if(!self::has_members_plugin()){
  541. //give full access to administrators if the members plugin is not installed
  542. if(current_user_can("administrator") || is_super_admin()){
  543. $all_caps["gform_full_access"] = true;
  544. }
  545. }
  546. else if(current_user_can("administrator")|| is_super_admin()){
  547. //checking if user has any GF permission.
  548. $has_gf_cap = false;
  549. foreach($gf_caps as $gf_cap){
  550. if(rgar($all_caps, $gf_cap))
  551. $has_gf_cap = true;
  552. }
  553. if(!$has_gf_cap){
  554. //give full access to administrators if none of the GF permissions are active by the Members plugin
  555. $all_caps["gform_full_access"] = true;
  556. }
  557. }
  558. return $all_caps;
  559. }
  560. //Target of Member plugin filter. Provides the plugin with Gravity Forms lists of capabilities
  561. public static function members_get_capabilities( $caps ) {
  562. return array_merge($caps, GFCommon::all_caps());
  563. }
  564. //Tests if the upload folder is writable and displays an error message if not
  565. public static function check_upload_folder(){
  566. //check if upload folder is writable
  567. $folder = RGFormsModel::get_upload_root();
  568. if(empty($folder))
  569. echo "<div class='error'>Upload folder is not writable. Export and file upload features will not be functional.</div>";
  570. }
  571. //Prints common admin scripts
  572. public static function print_scripts(){
  573. wp_enqueue_script("sack");
  574. wp_print_scripts();
  575. }
  576. public static function is_gravity_ajax_action(){
  577. //Gravity Forms AJAX requests
  578. $current_action = self::post("action");
  579. $gf_ajax_actions = array('rg_save_form', 'rg_change_input_type', 'rg_add_field', 'rg_duplicate_field',
  580. 'rg_delete_field', 'rg_select_export_form', 'rg_start_export', 'gf_upgrade_license',
  581. 'gf_delete_custom_choice', 'gf_save_custom_choice', 'gf_get_notification_post_categories',
  582. 'rg_update_lead_property', 'delete-gf_entry', 'rg_update_form_active',
  583. 'gf_resend_notifications', 'rg_dismiss_upgrade');
  584. if(defined("DOING_AJAX") && DOING_AJAX && in_array($current_action, $gf_ajax_actions))
  585. return true;
  586. //not a gravity forms ajax request.
  587. return false;
  588. }
  589. //Returns true if the current page is one of Gravity Forms pages. Returns false if not
  590. public static function is_gravity_page(){
  591. //Gravity Forms pages
  592. $current_page = trim(strtolower(self::get("page")));
  593. $gf_pages = array("gf_edit_forms","gf_new_form","gf_entries","gf_settings","gf_export","gf_help");
  594. return in_array($current_page, $gf_pages);
  595. }
  596. public static function do_menu_page(){
  597. $args = array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true );
  598. $count = (int) count(get_post_types( $args ));
  599. return $count > 0;
  600. }
  601. //Creates "Forms" left nav
  602. public static function create_menu(){
  603. $has_full_access = current_user_can("gform_full_access");
  604. $min_cap = GFCommon::current_user_can_which(GFCommon::all_caps());
  605. if(empty($min_cap))
  606. $min_cap = "gform_full_access";
  607. $addon_menus = array();
  608. $addon_menus = apply_filters("gform_addon_navigation", $addon_menus);
  609. $parent_menu = self::get_parent_menu($addon_menus);
  610. // Add a top-level left nav
  611. $update_icon = GFCommon::has_update() ? "<span title='" . esc_attr(__("Update Available", "alien")) . "' class='update-plugins count-1'><span class='update-count'>1</span></span>" : "";
  612. //Getting around a Wordpress bug that prevents menus from displayeing when site has multiple custom post types
  613. if( self::do_menu_page() )
  614. 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', 16.9);
  615. else
  616. add_object_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');
  617. // Adding submenu pages
  618. 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"));
  619. 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"));
  620. 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"));
  621. if(is_array($addon_menus)){
  622. foreach($addon_menus as $addon_menu)
  623. 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"]);
  624. }
  625. 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"));
  626. 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"));
  627. if(current_user_can("install_plugins")){
  628. 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"));
  629. 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"));
  630. }
  631. add_submenu_page($parent_menu["name"], __("Help", "gravityforms"), __("Help", "gravityforms"), $has_full_access ? "gform_full_access" : $min_cap, "gf_help", array("RGForms", "help_page"));
  632. }
  633. //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)
  634. public static function get_parent_menu($addon_menus){
  635. if(GFCommon::current_user_can_any("gravityforms_edit_forms"))
  636. $parent = array("name" => "gf_edit_forms", "callback" => array("RGForms", "forms"));
  637. else if(GFCommon::current_user_can_any("gravityforms_create_form"))
  638. $parent = array("name" => "gf_new_form", "callback" => array("RGForms", "new_form"));
  639. else if(GFCommon::current_user_can_any("gravityforms_view_entries"))
  640. $parent = array("name" => "gf_entries", "callback" => array("RGForms", "all_leads_page"));
  641. else if(is_array($addon_menus) && sizeof($addon_menus) > 0){
  642. foreach($addon_menus as $addon_menu)
  643. if(GFCommon::current_user_can_any($addon_menu["permission"]))
  644. {
  645. $parent = array("name" => $addon_menu["name"], "callback" => $addon_menu["callback"]);
  646. break;
  647. }
  648. }
  649. else if(GFCommon::current_user_can_any("gravityforms_view_settings"))
  650. $parent = array("name" => "gf_settings", "callback" => array("RGForms", "settings_page"));
  651. else if(GFCommon::current_user_can_any("gravityforms_export_entries"))
  652. $parent = array("name" => "gf_export", "callback" => array("RGForms", "export_page"));
  653. else if(GFCommon::current_user_can_any("gravityforms_view_updates"))
  654. $parent = array("name" => "gf_update", "callback" => array("RGForms", "update_page"));
  655. else if(GFCommon::current_user_can_any("gravityforms_view_addons"))
  656. $parent = array("name" => "gf_addons", "callback" => array("RGForms", "addons_page"));
  657. else if(GFCommon::current_user_can_any(GFCommon::all_caps()))
  658. $parent = array("name" => "gf_help", "callback" => array("RGForms", "help_page"));
  659. return $parent;
  660. }
  661. //Parses the [gravityform shortcode and returns the front end form UI
  662. public static function parse_shortcode($attributes, $content = null){
  663. extract(shortcode_atts(array(
  664. 'title' => true,
  665. 'description' => true,
  666. 'id' => 0,
  667. 'name' => '',
  668. 'field_values' => "",
  669. 'ajax' => false,
  670. 'tabindex' => 1,
  671. 'action' => 'form'
  672. ), $attributes));
  673. $shortcode_string = "";
  674. switch($action) {
  675. case 'conditional':
  676. $shortcode_string = GFCommon::conditional_shortcode($attributes, $content);
  677. break;
  678. case 'form' :
  679. //displaying form
  680. $title = strtolower($title) == "false" ? false : true;
  681. $description = strtolower($description) == "false" ? false : true;
  682. $field_values = htmlspecialchars_decode($field_values);
  683. $field_values = str_replace("&#038;", "&", $field_values);
  684. $ajax = strtolower($ajax) == "true" ? true : false;
  685. //using name to lookup form if id is not specified
  686. if(empty($id))
  687. $id = $name;
  688. parse_str($field_values, $field_value_array); //parsing query string like string for field values and placing them into an associative array
  689. $field_value_array = stripslashes_deep($field_value_array);
  690. $shortcode_string = self::get_form($id, $title, $description, false, $field_value_array, $ajax, $tabindex);
  691. break;
  692. }
  693. $shortcode_string = apply_filters("gform_shortcode_{$action}", $shortcode_string, $attributes, $content);
  694. return $shortcode_string;
  695. }
  696. //-------------------------------------------------
  697. //----------- AJAX --------------------------------
  698. public static function ajax_parse_request($wp) {
  699. if (isset($_POST["gform_ajax"])) {
  700. parse_str($_POST["gform_ajax"]);
  701. require_once(GFCommon::get_base_path() . "/form_display.php");
  702. $result = GFFormDisplay::get_form($form_id, $title, $description, false, $_POST["gform_field_values"], true);
  703. die($result);
  704. }
  705. }
  706. //------------------------------------------------------
  707. //------------- PAGE/POST EDIT PAGE ---------------------
  708. //Action target that adds the "Insert Form" button to the post/page edit screen
  709. public static function add_form_button(){
  710. $is_post_edit_page = in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'));
  711. if(!$is_post_edit_page)
  712. return;
  713. // do a version check for the new 3.5 UI
  714. $version = get_bloginfo('version');
  715. if ($version < 3.5) {
  716. // show button for v 3.4 and below
  717. $image_btn = GFCommon::get_base_url() . "/images/form-button.png";
  718. 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", 'gravityform') . '" /></a>';
  719. } else {
  720. // display button matching new UI
  721. echo '<style>.gform_media_icon{
  722. background:url(' . GFCommon::get_base_url() . '/images/gravity-admin-icon.png) no-repeat top left;
  723. display: inline-block;
  724. height: 16px;
  725. margin: 0 2px 0 0;
  726. vertical-align: text-top;
  727. width: 16px;
  728. }
  729. .wp-core-ui a.gform_media_link{
  730. padding-left: 0.4em;
  731. }
  732. </style>
  733. <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>';
  734. }
  735. }
  736. //Action target that displays the popup to insert a form to a post/page
  737. public static function add_mce_popup(){
  738. ?>
  739. <script>
  740. function InsertForm(){
  741. var form_id = jQuery("#add_form_id").val();
  742. if(form_id == ""){
  743. alert("<?php _e("Please select a form", "gravityforms") ?>");
  744. return;
  745. }
  746. var form_name = jQuery("#add_form_id option[value='" + form_id + "']").text().replace(/[\[\]]/g, '');
  747. var display_title = jQuery("#display_title").is(":checked");
  748. var display_description = jQuery("#display_description").is(":checked");
  749. var ajax = jQuery("#gform_ajax").is(":checked");
  750. var title_qs = !display_title ? " title=\"false\"" : "";
  751. var description_qs = !display_description ? " description=\"false\"" : "";
  752. var ajax_qs = ajax ? " ajax=\"true\"" : "";
  753. window.send_to_editor("[gravityform id=\"" + form_id + "\" name=\"" + form_name + "\"" + title_qs + description_qs + ajax_qs + "]");
  754. }
  755. </script>
  756. <div id="select_gravity_form" style="display:none;">
  757. <div class="wrap">
  758. <div>
  759. <div style="padding:15px 15px 0 15px;">
  760. <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>
  761. <span>
  762. <?php _e("Select a form below to add it to your post or page.", "gravityforms"); ?>
  763. </span>
  764. </div>
  765. <div style="padding:15px 15px 0 15px;">
  766. <select id="add_form_id">
  767. <option value=""> <?php _e("Select a Form", "gravityforms"); ?> </option>
  768. <?php
  769. $forms = RGFormsModel::get_forms(1, "title");
  770. foreach($forms as $form){
  771. ?>
  772. <option value="<?php echo absint($form->id) ?>"><?php echo esc_html($form->title) ?></option>
  773. <?php
  774. }
  775. ?>
  776. </select> <br/>
  777. <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>
  778. </div>
  779. <div style="padding:15px 15px 0 15px;">
  780. <input type="checkbox" id="display_title" checked='checked' /> <label for="display_title"><?php _e("Display form title", "gravityforms"); ?></label> &nbsp;&nbsp;&nbsp;
  781. <input type="checkbox" id="display_description" checked='checked' /> <label for="display_description"><?php _e("Display form description", "gravityforms"); ?></label>&nbsp;&nbsp;&nbsp;
  782. <input type="checkbox" id="gform_ajax" /> <label for="gform_ajax"><?php _e("Enable AJAX", "gravityforms"); ?></label>
  783. </div>
  784. <div style="padding:15px;">
  785. <input type="button" class="button-primary" value="Insert Form" onclick="InsertForm();"/>&nbsp;&nbsp;&nbsp;
  786. <a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php _e("Cancel", "gravityforms"); ?></a>
  787. </div>
  788. </div>
  789. </div>
  790. </div>
  791. <?php
  792. }
  793. //------------------------------------------------------
  794. //------------- PLUGINS PAGE ---------------------------
  795. //------------------------------------------------------
  796. public static function plugin_settings_link( $links, $file ) {
  797. if ( $file != plugin_basename( __FILE__ ))
  798. return $links;
  799. array_unshift($links, '<a href="' . admin_url("admin.php") . '?page=gf_settings">' . __( 'Settings', 'gravityforms' ) . '</a>');
  800. return $links;
  801. }
  802. //Displays message on Plugin's page
  803. public static function plugin_row($plugin_name){
  804. $key = GFCommon::get_key();
  805. $version_info = GFCommon::get_version_info();
  806. if(!$version_info["is_valid_key"]){
  807. $plugin_name = "gravityforms/gravityforms.php";
  808. $new_version = version_compare(GFCommon::$version, $version_info["version"], '<') ? __('There is a new version of Gravity Forms available.', 'gravityforms') .' <a class="thickbox" title="Gravity Forms" href="plugin-install.php?tab=plugin-information&plugin=gravityforms&TB_iframe=true&width=640&height=808">'. sprintf(__('View version %s Details', 'gravityforms'), $version_info["version"]) . '</a>. ' : '';
  809. echo '</tr><tr class="plugin-update-tr"><td colspan="3" class="plugin-update"><div class="update-message">' . $new_version . __('<a href="' . admin_url() . 'admin.php?page=gf_settings">Register</a> your copy of Gravity Forms to receive access to automatic upgrades and support. Need a license key? <a href="http://www.gravityforms.com">Purchase one now</a>.', 'gravityforms') . '</div></td>';
  810. }
  811. }
  812. //Displays current version details on Plugin's page
  813. public static function display_changelog(){
  814. if($_REQUEST["plugin"] != "gravityforms")
  815. return;
  816. $page_text = self::get_changelog();
  817. echo $page_text;
  818. exit;
  819. }
  820. public static function get_changelog(){
  821. $key = GFCommon::get_key();
  822. $body = "key=$key";
  823. $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body);
  824. $options['headers'] = array(
  825. 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
  826. 'Content-Length' => strlen($body),
  827. 'User-Agent' => 'WordPress/' . get_bloginfo("version"),
  828. 'Referer' => get_bloginfo("url")
  829. );
  830. $raw_response = wp_remote_request(GRAVITY_MANAGER_URL . "/changelog.php?" . GFCommon::get_remote_request_params(), $options);
  831. if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code']){
  832. $page_text = __("Oops!! Something went wrong.<br/>Please try again or <a href='http://www.gravityforms.com'>contact us</a>.", 'gravityforms');
  833. }
  834. else{
  835. $page_text = $raw_response['body'];
  836. if(substr($page_text, 0, 10) != "<!--GFM-->")
  837. $page_text = "";
  838. }
  839. return stripslashes($page_text);
  840. }
  841. //------------------------------------------------------
  842. //-------------- DASHBOARD PAGE -------------------------
  843. //Registers the dashboard widget
  844. public static function dashboard_setup(){
  845. $dashboard_title = apply_filters("gform_dashboard_title", __("Forms", "gravityforms"));
  846. wp_add_dashboard_widget('rg_forms_dashboard', $dashboard_title, array('RGForms', 'dashboard'));
  847. }
  848. //Displays the dashboard UI
  849. public static function dashboard(){
  850. $forms = RGFormsModel::get_form_summary();
  851. if(sizeof($forms) > 0){
  852. ?>
  853. <table class="widefat" cellspacing="0" style="border:0px;">
  854. <thead>
  855. <tr>
  856. <td style="text-align:left; padding:8px 18px!important; font-weight:bold;"><i><?php _e("Title", "gravityforms") ?></i></td>
  857. <td style="text-align:center; padding:8px 18px!important; font-weight:bold;"><i><?php _e("Unread", "gravityforms") ?></i></td>
  858. <td style="text-align:center; padding:8px 18px!important; font-weight:bold;"><i><?php _e("Total", "gravityforms") ?></i></td>
  859. </tr>
  860. </thead>
  861. <tbody class="list:user user-list">
  862. <?php
  863. foreach($forms as $form){
  864. $date_display = GFCommon::format_date($form["last_lead_date"]);
  865. if(!empty($form["total_leads"])){
  866. ?>
  867. <tr class='author-self status-inherit' valign="top">
  868. <td class="column-title" style="padding:8px 18px;">
  869. <a style="display:inline; <?php echo $form["unread_count"] > 0 ? "font-weight:bold;" : "" ?>" href="admin.php?page=gf_entries&view=entries&id=<?php echo absint($form["id"]) ?>" title="<?php echo esc_html($form["title"]) ?> : <?php _e("View All Entries", "gravityforms") ?>"><?php echo esc_html($form["title"]) ?></a>
  870. </td>
  871. <td class="column-date" style="padding:8px 18px; text-align:center;"><a style="<?php echo $form["unread_count"] > 0 ? "font-weight:bold;" : "" ?>" href="admin.php?page=gf_entries&view=entries&filter=unread&id=<?php echo absint($form["id"]) ?>" title="<?php printf(__("Last Entry: %s", "gravityforms"), $date_display); ?>"><?php echo absint($form["unread_count"]) ?></a></td>
  872. <td class="column-date" style="padding:8px 18px; text-align:center;"><a href="admin.php?page=gf_entries&view=entries&id=<?php echo absint($form["id"]) ?>" title="<?php _e("View All Entries", "gravityforms") ?>"><?php echo absint($form["total_leads"]) ?></a></td>
  873. </tr>
  874. <?php
  875. }
  876. }
  877. ?>
  878. </tbody>
  879. </table>
  880. <p class="textright">
  881. <a class="button" href="admin.php?page=gf_edit_forms"><?php _e("View All Forms", "gravityforms") ?></a>
  882. </p>
  883. <?php
  884. }
  885. else{
  886. ?>
  887. <div>
  888. <?php echo sprintf(__("You don't have any forms. Let's go %s create one %s!", 'gravityforms'), '<a href="admin.php?page=gf_new_form">', '</a>'); ?>
  889. </div>
  890. <?php
  891. }
  892. if(GFCommon::current_user_can_any("gravityforms_view_updates") && (!function_exists("is_multisite") || !is_multisite() || is_super_admin())){
  893. //displaying update message if there is an update and user has permission
  894. self::dashboard_update_message();
  895. }
  896. }
  897. public static function dashboard_update_message(){
  898. $version_info = GFCommon::get_version_info();
  899. //don't display a message if use has dismissed the message for this version
  900. $ary_dismissed = get_option("gf_dismissed_upgrades");
  901. $is_dismissed = !empty($ary_dismissed) && in_array($version_info["version"], $ary_dismissed);
  902. if($is_dismissed)
  903. return;
  904. if(version_compare(GFCommon::$version, $version_info["version"], '<')) {
  905. $auto_upgrade = "";
  906. /*if($version_info["is_valid_key"]){
  907. $plugin_file = "gravityforms/gravityforms.php";
  908. $upgrade_url = wp_nonce_url('update.php?action=upgrade-plugin&amp;plugin=' . urlencode($plugin_file), 'upgrade-plugin_' . $plugin_file);
  909. $auto_upgrade = sprintf(__(" or %sUpgrade Automatically%s", "gravityforms"), "<a href='{$upgrade_url}'>", "</a>");
  910. }*/
  911. $message = sprintf(__("There is an update available for Gravity Forms. %sView Details%s %s", "gravityforms"), "<a href='admin.php?page=gf_update'>", "</a>", $auto_upgrade);
  912. ?>
  913. <div class='updated' style='padding:15px; position:relative;' id='gf_dashboard_message'><?php echo $message ?>
  914. <a href="javascript:void(0);" onclick="AlienDismissUpgrade();" style='float:right;'><?php _e("Dismiss", "gravityforms") ?></a>
  915. </div>
  916. <script type="text/javascript">
  917. function AlienDismissUpgrade(){
  918. jQuery("#gf_dashboard_message").slideUp();
  919. jQuery.post(ajaxurl, {action:"rg_dismiss_upgrade", version:"<?php echo $version_info["version"] ?>"});
  920. }
  921. </script>
  922. <?php
  923. }
  924. }
  925. public static function dashboard_dismiss_upgrade(){
  926. $ary = get_option("gf_dismissed_upgrades");
  927. if(!is_array($ary))
  928. $ary = array();
  929. $ary[] = $_POST["version"];
  930. update_option("gf_dismissed_upgrades", $ary);
  931. }
  932. //------------------------------------------------------
  933. //--------------- ALL OTHER PAGES ---------------------
  934. public static function get_form($form_id, $display_title=true, $display_description=true, $force_display=false, $field_values=null, $ajax=false, $tabindex = 1){
  935. require_once(GFCommon::get_base_path() . "/form_display.php");
  936. return GFFormDisplay::get_form($form_id, $display_title, $display_description, $force_display, $field_values, $ajax, $tabindex);
  937. }
  938. public static function new_form(){
  939. self::forms_page(0);
  940. }
  941. public static function enqueue_scripts(){
  942. require_once(GFCommon::get_base_path() . "/form_display.php");
  943. GFFormDisplay::enqueue_scripts();
  944. }
  945. public static function print_form_scripts($form, $ajax){
  946. require_once(GFCommon::get_base_path() . "/form_display.php");
  947. GFFormDisplay::print_form_scripts($form, $ajax);
  948. }
  949. public static function forms_page($form_id){
  950. require_once(GFCommon::get_base_path() . "/form_detail.php");
  951. GFFormDetail::forms_page($form_id);
  952. }
  953. public static function settings_page(){
  954. require_once(GFCommon::get_base_path() . "/settings.php");
  955. GFSettings::settings_page();
  956. }
  957. public static function add_settings_page($name, $handle, $icon_path=""){
  958. require_once(GFCommon::get_base_path() . "/settings.php");
  959. GFSettings::add_settings_page($name, $handle, $icon_path);
  960. }
  961. public static function help_page(){
  962. require_once(GFCommon::get_base_path() . "/help.php");
  963. GFHelp::help_page();
  964. }
  965. public static function export_page(){
  966. require_once(GFCommon::get_base_path() . "/export.php");
  967. GFExport::export_page();
  968. }
  969. public static function update_page(){
  970. require_once(GFCommon::get_base_path() . "/update.php");
  971. GFUpdate::update_page();
  972. }
  973. public static function addons_page(){
  974. wp_print_scripts("thickbox");
  975. wp_print_styles(array("thickbox"));
  976. $plugins = get_plugins();
  977. $installed_plugins = array();
  978. foreach($plugins as $key => $plugin){
  979. $is_active = is_plugin_active($key);
  980. $installed_plugin = array("plugin" => $key, "name" => $plugin["Name"], "is_active"=>$is_active);
  981. $installed_plugin["activation_url"] = $is_active ? "" : wp_nonce_url("plugins.php?action=activate&plugin={$key}", "activate-plugin_{$key}");
  982. $installed_plugin["deactivation_url"] = !$is_active ? "" : wp_nonce_url("plugins.php?action=deactivate&plugin={$key}", "deactivate-plugin_{$key}");
  983. $installed_plugins[] = $installed_plugin;
  984. }
  985. $nonces = self::get_addon_nonces();
  986. $body = array("plugins" => urlencode(serialize($installed_plugins)), "nonces" => urlencode(serialize($nonces)), "key" => GFCommon::get_key());
  987. $options = array('body' => $body, 'headers' => array('Referer' => get_bloginfo("url")));
  988. $request_url = GRAVITY_MANAGER_URL . "/api.php?op=plugin_browser&{$_SERVER["QUERY_STRING"]}";
  989. $raw_response = wp_remote_post($request_url, $options);
  990. if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200){
  991. echo "<div class='error' style='margin-top:50px; padding:20px;'>" . __("Add-On browser is currently unavailable. Please try again later.", "gravityforms") . "</div>";
  992. }
  993. else{
  994. echo GFCommon::get_remote_message();
  995. echo $raw_response["body"];
  996. }
  997. }
  998. public static function get_addon_info($api, $action, $args){
  999. if($action == "plugin_information" && empty($api) && !rgempty("rg", $_GET)){
  1000. $request_url = GRAVITY_MANAGER_URL . "/api.php?op=get_plugin&slug={$args->slug}";
  1001. $raw_response = wp_remote_post($request_url);
  1002. if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200)
  1003. return false;
  1004. $plugin = unserialize($raw_response["body"]);
  1005. $api = new stdClass();
  1006. $api->name = $plugin["title"];
  1007. $api->version = $plugin["version"];
  1008. $api->download_link = $plugin["download_url"];
  1009. }
  1010. return $api;
  1011. }
  1012. public static function get_addon_nonces(){
  1013. $request_url = GRAVITY_MANAGER_URL . "/api.php?op=get_plugins";
  1014. $raw_response = wp_remote_get($request_url);
  1015. if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200)
  1016. return false;
  1017. $addons = unserialize($raw_response["body"]);
  1018. $nonces = array();
  1019. foreach($addons as $addon){
  1020. $nonces[$addon["key"]] = wp_create_nonce("install-plugin_{$addon["key"]}");
  1021. }
  1022. return $nonces;
  1023. }
  1024. public static function start_export(){
  1025. require_once(GFCommon::get_base_path() . "/export.php");
  1026. GFExport::start_export();
  1027. }
  1028. public static function get_post_category_values(){
  1029. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1030. GFFormDetail::get_post_category_values();
  1031. }
  1032. public static function get_notification_post_category_values(){
  1033. require_once(GFCommon::get_base_path() . "/notification.php");
  1034. GFNotification::get_post_category_values();
  1035. }
  1036. public static function all_leads_page(){
  1037. //displaying lead detail page if lead id is in the query string
  1038. if(rgget('lid') || !rgblank(rgget('pos')))
  1039. {
  1040. require_once(GFCommon::get_base_path() . "/entry_detail.php");
  1041. GFEntryDetail::lead_detail_page();
  1042. }
  1043. else{
  1044. require_once(GFCommon::get_base_path() . "/entry_list.php");
  1045. GFEntryList::all_leads_page();
  1046. }
  1047. }
  1048. public static function form_list_page(){
  1049. require_once(GFCommon::get_base_path() . "/form_list.php");
  1050. GFFormList::form_list_page();
  1051. }
  1052. public static function forms(){
  1053. if(!GFCommon::ensure_wp_version())
  1054. return;
  1055. $id = RGForms::get("id");
  1056. $view = RGForms::get("view");
  1057. if($view == "entries"){
  1058. require_once(GFCommon::get_base_path() . "/entry_list.php");
  1059. GFEntryList::leads_page($id);
  1060. }
  1061. else if($view == "entry"){
  1062. require_once(GFCommon::get_base_path() . "/entry_detail.php");
  1063. GFEntryDetail::lead_detail_page();
  1064. }
  1065. else if($view == "notification"){
  1066. require_once(GFCommon::get_base_path() . "/notification.php");
  1067. GFNotification::notification_page($id);
  1068. }
  1069. else if(is_numeric($id)){
  1070. self::forms_page($id);
  1071. }
  1072. else{
  1073. self::form_list_page();
  1074. }
  1075. }
  1076. public static function get($name, $array=null){
  1077. if(!$array)
  1078. $array = $_GET;
  1079. if(isset($array[$name]))
  1080. return $array[$name];
  1081. return "";
  1082. }
  1083. public static function post($name){
  1084. if(isset($_POST[$name]))
  1085. return $_POST[$name];
  1086. return "";
  1087. }
  1088. // AJAX Function
  1089. public static function resend_notifications(){
  1090. check_admin_referer('gf_resend_notifications', 'gf_resend_notifications');
  1091. $leads = rgpost('leadIds'); // may be a single ID or an array of IDs
  1092. $leads = !is_array($leads) ? array($leads) : $leads;
  1093. $form_id = rgpost('formId');
  1094. $form = apply_filters("gform_before_resend_notifications_{$form_id}", apply_filters('gform_before_resend_notifications', RGFormsModel::get_form_meta($form_id), $leads), $leads);
  1095. if(empty($leads) || empty($form)) {
  1096. _e("There was an error while resending the notifications.", "gravityforms");
  1097. die();
  1098. };
  1099. $send_admin = rgpost('sendAdmin');
  1100. $send_user = rgpost('sendUser');
  1101. $override_options = array();
  1102. $validation_errors = array();
  1103. if(rgpost('sendTo')) {
  1104. if(rgpost('sendTo') && GFCommon::is_invalid_or_empty_email(rgpost('sendTo')))
  1105. $validation_errors[] = __("The <strong>Send To</strong> email address provided is not valid.", "gravityforms");
  1106. if(!empty($validation_errors)) {
  1107. echo count($validation_errors) > 1 ? '<ul><li>' . implode('</li><li>', $validation_errors) . '</li></ul>' : $validation_errors[0];
  1108. die();
  1109. }
  1110. $override_options['to'] = rgpost('sendTo');
  1111. $override_options['bcc'] = ''; // overwrite bcc settings
  1112. }
  1113. foreach($leads as $lead_id){
  1114. $lead = RGFormsModel::get_lead($lead_id);
  1115. if($send_admin)
  1116. GFCommon::send_admin_notification($form, $lead, $override_options);
  1117. if($send_user)
  1118. GFCommon::send_user_notification($form, $lead, $override_options);
  1119. }
  1120. die();
  1121. }
  1122. //-------------------------------------------------
  1123. //----------- AJAX CALLS --------------------------
  1124. //captcha image
  1125. public static function captcha_image(){
  1126. $field = array("simpleCaptchaSize" => $_GET["size"], "simpleCaptchaFontColor"=> $_GET["fg"], "simpleCaptchaBackgroundColor"=>$_GET["bg"]);
  1127. if($_GET["type"] == "math")
  1128. $captcha = GFCommon::get_math_captcha($field, $_GET["pos"]);
  1129. else
  1130. $captcha = GFCommon::get_captcha($field);
  1131. @ini_set('memory_limit', '256M');
  1132. $image = imagecreatefrompng($captcha["path"]);
  1133. include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
  1134. wp_stream_image($image, "image/png", 0);
  1135. imagedestroy($image);
  1136. die();
  1137. }
  1138. //entry list
  1139. public static function update_form_active(){
  1140. check_ajax_referer('rg_update_form_active','rg_update_form_active');
  1141. RGFormsModel::update_form_active($_POST["form_id"], $_POST["is_active"]);
  1142. }
  1143. public static function update_lead_property(){
  1144. check_ajax_referer('rg_update_lead_property','rg_update_lead_property');
  1145. RGFormsModel::update_lead_property($_POST["lead_id"], $_POST["name"], $_POST["value"]);
  1146. }
  1147. public static function update_lead_status(){
  1148. check_ajax_referer('gf_delete_entry');
  1149. $status = rgpost("status");
  1150. $lead_id = rgpost("entry");
  1151. switch($status){
  1152. case "unspam" :
  1153. //TODO: call akismet and set entry as not spam.
  1154. RGFormsModel::update_lead_property($lead_id, "status", "active");
  1155. break;
  1156. case "delete" :
  1157. RGFormsModel::delete_lead($lead_id);
  1158. break;
  1159. default :
  1160. RGFormsModel::update_lead_property($lead_id, "status", $status);
  1161. break;
  1162. }
  1163. header("Content-Type: text/xml");
  1164. echo "<?xml version='1.0' standalone='yes'?><wp_ajax></wp_ajax>";
  1165. exit();
  1166. }
  1167. //settings
  1168. public static function upgrade_license(){
  1169. require_once(GFCommon::get_base_path() . "/settings.php");
  1170. GFSettings::upgrade_license();
  1171. }
  1172. //form detail
  1173. public static function save_form(){
  1174. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1175. GFFormDetail::save_form();
  1176. }
  1177. public static function add_field(){
  1178. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1179. GFFormDetail::add_field();
  1180. }
  1181. public static function duplicate_field(){
  1182. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1183. GFFormDetail::duplicate_field();
  1184. }
  1185. public static function delete_field(){
  1186. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1187. GFFormDetail::delete_field();
  1188. }
  1189. public static function change_input_type(){
  1190. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1191. GFFormDetail::change_input_type();
  1192. }
  1193. public static function delete_custom_choice(){
  1194. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1195. GFFormDetail::delete_custom_choice();
  1196. }
  1197. public static function save_custom_choice(){
  1198. require_once(GFCommon::get_base_path() . "/form_detail.php");
  1199. GFFormDetail::save_custom_choice();
  1200. }
  1201. //entry detail
  1202. public static function delete_file(){
  1203. check_ajax_referer("rg_delete_file", "rg_delete_file");
  1204. $lead_id = intval($_POST["lead_id"]);
  1205. $field_id = intval($_POST["field_id"]);
  1206. RGFormsModel::delete_file($lead_id, $field_id);
  1207. die("EndDeleteFile($field_id);");
  1208. }
  1209. //export
  1210. public static function select_export_form(){
  1211. check_ajax_referer("rg_select_export_form", "rg_select_export_form");
  1212. $form_id = intval($_POST["form_id"]);
  1213. $form = RGFormsModel::get_form_meta($form_id);
  1214. $fields = array();
  1215. $form = GFExport::add_default_export_fields($form);
  1216. if(is_array($form["fields"])){
  1217. foreach($form["fields"] as $field){
  1218. if(is_array(rgar($field,"inputs"))){
  1219. foreach($field["inputs"] as $input)
  1220. $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
  1221. }
  1222. else if(!rgar($field,"displayOnly")){
  1223. $fields[] = array($field["id"], GFCommon::get_label($field));
  1224. }
  1225. }
  1226. }
  1227. $field_json = GFCommon::json_encode($fields);
  1228. die("EndSelectExportForm($field_json);");
  1229. }
  1230. public static function top_toolbar(){
  1231. $forms = RGFormsModel::get_forms(null, "title");
  1232. $id = rgempty("id", $_GET) ? count($forms) > 0 ? $forms[0]->id : "0" : rgget("id");
  1233. ?>
  1234. <script type="text/javascript">
  1235. function GF_ReplaceQuery(key, newValue){
  1236. var new_query = "";
  1237. var query = document.location.search.substring(1);
  1238. var ary = query.split("&");
  1239. var has_key=false;
  1240. for (i=0; i < ary.length; i++) {
  1241. var key_value = ary[i].split("=");
  1242. if (key_value[0] == key){
  1243. new_query += key + "=" + newValue + "&";
  1244. has_key = true;
  1245. }
  1246. else if(key_value[0] != "display_settings"){
  1247. new_query += key_value[0] + "=" + key_value[1] + "&";
  1248. }
  1249. }
  1250. if(new_query.length > 0)
  1251. new_query = new_query.substring(0, new_query.length-1);
  1252. if(!has_key)
  1253. new_query += new_query.length > 0 ? "&" + key + "=" + newValue : "?" + key + "=" + newValue;
  1254. return new_query;
  1255. }
  1256. function GF_RemoveQuery(key, query){
  1257. var new_query = "";
  1258. if (query == "")
  1259. {
  1260. query = document.location.search.substring(1);
  1261. }
  1262. var ary = query.split("&");
  1263. for (i=0; i < ary.length; i++) {
  1264. var key_value = ary[i].split("=");
  1265. if (key_value[0] != key){
  1266. new_query += key_value[0] + "=" + key_value[1] + "&";
  1267. }
  1268. }
  1269. if(new_query.length > 0)
  1270. new_query = new_query.substring(0, new_query.length-1);
  1271. return new_query;
  1272. }
  1273. function GF_SwitchForm(id){
  1274. if(id.length > 0){
  1275. query = GF_ReplaceQuery("id", id);
  1276. //remove paging from querystring when changing forms
  1277. new_query = GF_RemoveQuery("paged", query);
  1278. new_query = new_query.replace("gf_new_form", "gf_edit_forms");
  1279. document.location = "?" + new_query;
  1280. }
  1281. }
  1282. function ToggleFormSettings(){
  1283. FieldClick(jQuery('#gform_heading')[0]);
  1284. }
  1285. jQuery(document).ready(function(){
  1286. if(document.location.search.indexOf("display_settings") > 0)
  1287. ToggleFormSettings()
  1288. jQuery('a.gf_toolbar_disabled').click(function(event){
  1289. event.preventDefault();
  1290. });
  1291. });
  1292. </script>
  1293. <div id="gf_form_toolbar">
  1294. <ul id="gf_form_toolbar_links">
  1295. <?php
  1296. if(GFCommon::current_user_can_any("gravityforms_edit_forms")){
  1297. ?>
  1298. <li class="gf_form_toolbar_editor"><a href="?page=gf_edit_forms&id=<?php echo $id ?>" <?php echo self::toolbar_class("editor"); ?>><?php _e("Form Editor", "gravityforms"); ?></a></li>
  1299. <li class="gf_form_toolbar_settings"><a href="javascript: if(jQuery('#gform_heading.selectable').length > 0){FieldClick(jQuery('#gform_heading')[0]);} else{document.location = '?page=gf_edit_forms&id=<?php echo $id ?>&display_settings';}" <?php echo self::toolbar_class("settings"); ?>><?php _e("Form Settings", "gravityforms"); ?></a></li>
  1300. <li class="gf_form_toolbar_notifications"><a href="?page=gf_edit_forms&view=notification&id=<?php echo $id ?>" <?php echo self::toolbar_class("notifications"); ?>><?php _e("Notifications", "gravityforms"); ?></a></li>
  1301. <?php
  1302. }
  1303. if(GFCommon::current_user_can_any(array('gravityforms_view_entries','gravityforms_edit_entries','gravityforms_delete_entries'))){
  1304. ?>
  1305. <li class="gf_form_toolbar_entries"><a href="?page=gf_entries&id=<?php echo $id ?>" <?php echo self::toolbar_class("entries"); ?>>
  1306. <?php echo RG_CURRENT_VIEW != 'entry' ? __("Entries", "gravityforms") : __("Entries", "gravityforms"); ?>
  1307. </a></li>
  1308. <?php
  1309. }
  1310. if(GFCommon::current_user_can_any(array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms"))){
  1311. ?>
  1312. <li class="gf_form_toolbar_preview"><a href="<?php echo site_url() ?>/?gf_page=preview&id=<?php echo $id ?>" target="_blank" <?php echo self::toolbar_class("preview"); ?>><?php _e("Preview", "gravityforms"); ?></a></li>
  1313. <?php
  1314. }
  1315. ?>
  1316. <li class="gf_form_switcher">
  1317. <label for="export_form"><?php _e("Select A Form", "gravityforms") ?></label>
  1318. <?php
  1319. if(RG_CURRENT_VIEW != 'entry'){ ?>
  1320. <select name="form_switcher" id="form_switcher" onchange="GF_SwitchForm(jQuery(this).val());">
  1321. <option value=""><?php _e("Switch Form", "gravityforms") ?></option>
  1322. <?php
  1323. foreach($forms as $form_info){
  1324. ?>
  1325. <option value="<?php echo $form_info->id ?>"><?php echo $form_info->title ?></option>
  1326. <?php
  1327. }
  1328. ?>
  1329. </select>
  1330. <?php
  1331. } // end view check ?>
  1332. </li>
  1333. </ul>
  1334. </div>
  1335. <?php
  1336. }
  1337. private static function toolbar_class($item){
  1338. switch($item){
  1339. case "editor":
  1340. if(in_array(rgget("page"), array("gf_edit_forms", "gf_new_form")) && rgempty("view", $_GET))
  1341. return "class='gf_toolbar_active'";
  1342. break;
  1343. case "notifications" :
  1344. if(rgget("page") == "gf_new_form")
  1345. return "class='gf_toolbar_disabled'";
  1346. else if(rgget("page") == "gf_edit_forms" && rgget("view") == "notification")
  1347. return "class='gf_toolbar_active'";
  1348. break;
  1349. case "entries" :
  1350. if(rgget("page") == "gf_new_form")
  1351. return "class='gf_toolbar_disabled'";
  1352. else if(rgget("page") == "gf_entries")
  1353. return "class='gf_toolbar_active'";
  1354. break;
  1355. case "preview" :
  1356. if(rgget("page") == "gf_new_form")
  1357. return "class='gf_toolbar_disabled'";
  1358. break;
  1359. }
  1360. return "";
  1361. }
  1362. }
  1363. //Main function call. Should be used to insert a Gravity Form from code.
  1364. function gravity_form($id, $display_title=true, $display_description=true, $display_inactive=false, $field_values=null, $ajax=false, $tabindex = 1){
  1365. echo RGForms::get_form($id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex);
  1366. }
  1367. //Enqueues the appropriate scripts for the specified form
  1368. function gravity_form_enqueue_scripts($form_id, $is_ajax=false){
  1369. if(!is_admin()){
  1370. require_once(GFCommon::get_base_path() . "/form_display.php");
  1371. $form = RGFormsModel::get_form_meta($form_id);
  1372. GFFormDisplay::enqueue_form_scripts($form, $is_ajax);
  1373. }
  1374. }
  1375. if(!function_exists("rgget")){
  1376. function rgget($name, $array=null){
  1377. if(!isset($array))
  1378. $array = $_GET;
  1379. if(isset($array[$name]))
  1380. return $array[$name];
  1381. return "";
  1382. }
  1383. }
  1384. if(!function_exists("rgpost")){
  1385. function rgpost($name, $do_stripslashes=true){
  1386. if(isset($_POST[$name]))
  1387. return $do_stripslashes ? stripslashes_deep($_POST[$name]) : $_POST[$name];
  1388. return "";
  1389. }
  1390. }
  1391. if(!function_exists("rgar")){
  1392. function rgar($array, $name){
  1393. if(isset($array[$name]))
  1394. return $array[$name];
  1395. return '';
  1396. }
  1397. }
  1398. if(!function_exists("rgars")){
  1399. function rgars($array, $name){
  1400. $names = explode("/", $name);
  1401. $val = $array;
  1402. foreach($names as $current_name){
  1403. $val = rgar($val, $current_name);
  1404. }
  1405. return $val;
  1406. }
  1407. }
  1408. if(!function_exists("rgempty")){
  1409. function rgempty($name, $array = null){
  1410. if(!$array)
  1411. $array = $_POST;
  1412. $val = rgget($name, $array);
  1413. return empty($val);
  1414. }
  1415. }
  1416. if(!function_exists("rgblank")){
  1417. function rgblank($text){
  1418. return empty($text) && strval($text) != "0";
  1419. }
  1420. }
  1421. if(!function_exists("rgobj")){
  1422. function rgobj($obj, $name){
  1423. if(isset($obj->$name))
  1424. return $obj->$name;
  1425. return '';
  1426. }
  1427. }
  1428. if(!function_exists("rgexplode")){
  1429. function rgexplode($sep, $string, $count){
  1430. $ary = explode($sep, $string);
  1431. while(count($ary) < $count)
  1432. $ary[] = "";
  1433. return $ary;
  1434. }
  1435. }
  1436. ?>