PageRenderTime 76ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 1ms

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

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