KWSGFAddOn2_2

Extend the GFFeedAddOn with lots of default functionality for KWS GF addons.

Defined (1)

The class is defined in the following location(s).

/inc/kwsaddon.php  
  1. abstract class KWSGFAddOn2_2 extends GFFeedAddOn { 
  2.  
  3. protected $_version = "2.2.1"; 
  4. protected $_min_gravityforms_version = "1.7"; 
  5. protected $_slug = "kwsaddon"; 
  6. protected $_path = "kwsaddon/kwsaddon.php"; 
  7. protected $_full_path = __FILE__; 
  8. protected $_title = "Gravity Forms KWS Add-On"; 
  9. protected $_short_title = "KWS Add-On"; 
  10.  
  11. protected $_support_logging = true; 
  12. protected $_has_form_settings_page = true; 
  13.  
  14.  
  15. protected $_capabilities_uninstall = array('administrator', 'manage_options'); 
  16. protected $_capabilities_plugin_page = array('administrator', 'manage_options'); 
  17. protected $_capabilities_form_settings = array('administrator', 'manage_options'); 
  18. protected $_capabilities_settings_page = array('administrator', 'manage_options'); 
  19.  
  20. /** 
  21. * The name of the service exporting to; eg: Constant Contact 
  22. * @var string 
  23. */ 
  24. protected $_service_name = NULL; 
  25.  
  26. /** 
  27. * HTML `<img>` tag with full path to service icon 
  28. * @var string 
  29. */ 
  30. protected $_service_icon = NULL; 
  31.  
  32. protected $_service_favicon_path = NULL; 
  33.  
  34. protected $_service_api_valid = NULL; 
  35.  
  36. protected $_service_api = NULL; 
  37.  
  38. protected $_custom_field_placeholder = 'Field Name'; 
  39.  
  40.  
  41. function __construct() { 
  42.  
  43. parent::__construct(); 
  44.  
  45. $this->admin_hooks(); 
  46.  
  47. add_filter( 'gform_pre_render', array(&$this, 'add_feed_status_to_form'), 10, 2 ); 
  48.  
  49. /** 
  50. * Modify the form array to add slug feed activity to the form itself. 
  51. * Adds [feed-{$slug}] key to the form 
  52. * @param array $form Form array 
  53. * @param boolean $ajax Is ajax or not 
  54. */ 
  55. function add_feed_status_to_form($form, $ajax) { 
  56.  
  57. if($this->has_feed($form['id'])) { 
  58. $form['feed-'.$this->_slug] = true; 
  59.  
  60. return $form; 
  61.  
  62. /** 
  63. * Prevent creation of form settings page if you don't want them. 
  64. * We override `form_settings_init()` because it's available; `has_form_settings_page()` would 
  65. * be preferred, but it's private. 
  66. * @return void 
  67. */ 
  68. public function form_settings_init() { 
  69. if(empty($this->_has_form_settings_page)) { return; } 
  70. parent::form_settings_init(); 
  71.  
  72. public function admin_hooks() { 
  73. global $pagenow; 
  74.  
  75. switch ($pagenow) { 
  76. case 'plugins.php': 
  77. add_action('admin_notices', array(&$this, 'gf_installation_notice'), 10); 
  78. break; 
  79. case 'admin.php': 
  80. add_action('admin_head', array(&$this, 'show_addon_status')); 
  81. break; 
  82.  
  83.  
  84. /** 
  85. * Add the logo for the plugin settings page 
  86. * @return string IMG HTML tag 
  87. */ 
  88. public function plugin_settings_icon() { 
  89. return $this->get_service_icon(); 
  90.  
  91. /** 
  92. * Add a setting for whether to log logs for this addon 
  93. * @param array $plugins Array of existing plugins that have logging settings 
  94. * @return array Modified plugins array 
  95. */ 
  96. public function set_logging_supported($plugins) { 
  97.  
  98. if(!empty($this->_support_logging)) { 
  99. $plugins[$this->_slug] = $this->get_short_title(); 
  100.  
  101. return $plugins; 
  102.  
  103. /** 
  104. * Show a notice if GF isn't activated. 
  105. * @param boolean $echo True: print; False: return 
  106. * @return string HTML output of notice. 
  107. */ 
  108. public function gf_installation_notice($echo = true) { 
  109. global $pagenow, $page; $message = ''; 
  110.  
  111. $installed = 0; 
  112.  
  113. $name = $this->get_short_title(); 
  114. if(!class_exists('RGForms')) { 
  115. if(file_exists(WP_PLUGIN_DIR.'/gravityforms/gravityforms.php')) { 
  116. $installed = 1; 
  117.  
  118. $message .= __(sprintf('%sGravity Forms is installed but not active. %sActivate Gravity Forms%s to use the %s plugin.%s', '<p>', '<strong><a href="'.wp_nonce_url(admin_url('plugins.php?action=activate&plugin=gravityforms/gravityforms.php'), 'activate-plugin_gravityforms/gravityforms.php').'">', '</a></strong>', $name, '</p>'), 'gravity-forms-salesforce'); 
  119.  
  120. } else { 
  121. $message .= <<<EOD 
  122. <p><a href="http://katz.si/gravityforms?con=banner" title="Gravity Forms Contact Form Plugin for WordPress"><img src="http://gravityforms.s3.amazonaws.com/banners/728x90.gif" alt="Gravity Forms Plugin for WordPress" width="728" height="90" style="border:none;" /></a></p> 
  123. <h3><a href="http://katz.si/gravityforms" target="_blank">Gravity Forms</a> is required for the $name</h3> 
  124. <p>You do not have the Gravity Forms plugin installed. <a href="http://katz.si/gravityforms">Get Gravity Forms</a> today.</p> 
  125. EOD; 
  126.  
  127. if(!empty($message) && $echo) { 
  128. echo '<div id="message" class="updated">'.$message.'</div>'; 
  129. } else { 
  130. return true; 
  131. return $installed; 
  132.  
  133. protected function invalid_api_message() { 
  134. return __("Invalid username and/or API key. Please try another combination.", "gravity-forms-salesforce"); 
  135.  
  136. protected function valid_api_message() { 
  137. return __("Your configuration is working!", "gravity-forms-salesforce"); 
  138.  
  139. protected function get_service_signup_message() { 
  140.  
  141. // The ad is stored locally for 30 days as a transient. See if it exists. 
  142. $cache = function_exists('get_site_transient') ? get_site_transient($this->_slug.'_remote_ad') : get_transient($this->_slug.'_remote_ad'); 
  143.  
  144. // If it exists, use that (so we save some request time), unless ?cache is set. 
  145. if(!empty($cache) && !isset($_REQUEST['cache'])) { return $cache; } 
  146.  
  147. // Get the advertisement remotely. An encrypted site identifier, the language of the site, and the version of the cf7 plugin will be sent to katz.co 
  148. $response = wp_remote_post('http://katz.co/ads/', array('timeout' => 45, 'body' => array('siteid' => sha1(site_url()), 'language' => get_bloginfo('language'), 'plugin' => 'gf_'.$this->_slug, 'version' => $this->_version))); 
  149.  
  150. // If it was a successful request, process it. 
  151. if(!is_wp_error($response) && !empty($response)) { 
  152.  
  153. $body = str_replace('{path}', plugins_url( '', $this->_full_path ), $response['body']); 
  154.  
  155. // Basically, remove <script>, <iframe> and <object> tags for security reasons 
  156. $body = strip_tags(trim(rtrim($body)), '<b><strong><em><i><span><u><ul><li><ol><div><attr><cite><a><style><blockquote><q><p><form><br><meta><option><textarea><input><select><pre><code><s><del><small><table><tbody><tr><th><td><tfoot><thead><u><dl><dd><dt><col><colgroup><fieldset><address><button><aside><article><legend><label><source><kbd><tbody><hr><noscript><link><h1><h2><h3><h4><h5><h6><img>'); 
  157.  
  158. // If the result is empty, cache it for 8 hours. Otherwise, cache it for 30 days. 
  159. $cache_time = empty($response['body']) ? floatval(60*60*8) : floatval(60*60*30); 
  160.  
  161. if(function_exists('set_site_transient')) { 
  162. set_site_transient($this->_slug.'_remote_ad', $body, $cache_time); 
  163. } else { 
  164. set_transient($this->_slug.'_remote_ad', $body, $cache_time); 
  165.  
  166. // Return the results. 
  167. return $body; 
  168.  
  169. public function get_api() { 
  170. return $this->_service_api; 
  171.  
  172. public function get_slug() { 
  173. return $this->_slug; 
  174.  
  175. /** 
  176. * Test the API is working or not by showing if lists are retrivable. 
  177. * @return boolean Working or not 
  178. */ 
  179. public function is_valid_api() { 
  180. if(!is_null($this->_service_api_valid)) { 
  181. return $this->_service_api_valid; 
  182.  
  183. $this->_service_api_valid = $this->get_service_lists(); 
  184.  
  185. return $this->_service_api_valid; 
  186.  
  187. /** 
  188. * Is the addon configured properly? Check the API. 
  189. * @return boolean [description] 
  190. */ 
  191. public function is_invalid_api() { 
  192. return !$this->is_valid_api(); 
  193.  
  194. /** 
  195. * Is the addon not yet configured at all? 
  196. * @return boolean [description] 
  197. */ 
  198. public function is_not_configured() { 
  199. $settings = $this->get_plugin_settings(); 
  200. return $settings === false; 
  201.  
  202. public function get_service_name() { 
  203. return !empty($this->_service_name) ? $this->_service_name : $this->get_short_title(); 
  204.  
  205. /** 
  206. * This is here to fix a bug in GF 1.7 that hard-coded MailChimp as the service. 
  207. * @param array $field Field array 
  208. * @param boolean $echo Echo the output 
  209. * @return string HTML output for feed condition 
  210. */ 
  211. public function settings_feed_condition( $field, $echo = true ) { 
  212.  
  213. // Get the output from the default Feed Add-on 
  214. $html = parent::settings_feed_condition( $field, false ); 
  215.  
  216. // Replace MailChimp 
  217. $html = str_replace('MailChimp', $this->get_service_name(), $html); 
  218.  
  219. if($echo) { 
  220. echo $html; 
  221.  
  222. return $html; 
  223.  
  224.  
  225. public function get_service_icon() { 
  226. return $this->_service_icon; 
  227.  
  228. public function get_service_favicon_path() { 
  229. return $this->_service_favicon_path; 
  230.  
  231. /** 
  232. * Returns a specific setting based on key 
  233. * @param string $key Name of setting to return 
  234. * @return mixed|null Value of setting at key {$key}. If not set, returns null. 
  235. */ 
  236. public function get_plugin_setting($key) { 
  237.  
  238. return $this->get_addon_setting($key, false); 
  239.  
  240. public function feed_settings_fields() { 
  241.  
  242. return array( 
  243. array( 
  244. "title" => sprintf("Map your fields for export to %s.", $this->get_service_name()),  
  245. "fields" => array( 
  246. array( 
  247. 'label' => 'Feed Name',  
  248. 'name' => 'name',  
  249. 'type' => 'text',  
  250. 'value' => '',  
  251. 'placeholder' => __('Feed Name (optional)', 'gravity-forms-salesforce'),  
  252. ),  
  253. array( 
  254. 'type' => 'checkbox',  
  255. 'label' => 'Choose Your Lists',  
  256. 'tooltip' => sprintf("<h6>" . __("%s List", "gravity-forms-salesforce") . "</h6>" . __("Select the %s list you would like to add your contacts to.", "gravity-forms-salesforce"), $this->get_service_name(), $this->get_service_name()),  
  257. 'name' => 'lists',  
  258. 'validation_callback' => array( $this, 'validate_service_lists' ),  
  259. 'choices' => $this->feed_settings_service_lists() 
  260. ),  
  261. array( 
  262. 'type' => 'field_map',  
  263. 'label' => 'Map your fields.',  
  264. 'tooltip' => "<h6>" . __("Map Fields", "gravity-forms-salesforce") . "</h6>" . sprintf(__("Associate your %s merge variables to the appropriate Gravity Form fields by selecting.", "gravity-forms-salesforce"), $this->get_service_name()),  
  265. 'name' => null,  
  266. 'field_map' => $this->map_custom_fields($this->feed_settings_fields_field_map()) 
  267. ),  
  268. array( 
  269. 'type' => 'custom_fields',  
  270. 'label' => __("Custom Fields", 'gravity-forms-salesforce'),  
  271. 'name' => null 
  272. ),  
  273. array( 
  274. 'label' => 'Opt-in Condition',  
  275. 'type' => 'feed_condition',  
  276. 'tooltip' => sprintf("<h6>" . __("Opt-In Condition", "gravity-forms-salesforce") . "</h6>" . __("When the opt-in condition is enabled, form submissions will only be exported to %s when the condition is met. When disabled all form submissions will be exported.", "gravity-forms-salesforce"), $this->get_service_name()),  
  277. ); 
  278.  
  279. public function map_custom_fields($fields) { 
  280.  
  281. // Get all the fields for the Feed 
  282. $all_fields = $this->get_current_settings(); 
  283.  
  284. // Unset fields that we know aren't mapped 
  285. unset($all_fields['name'], $all_fields['type'], $all_fields['feed_condition_conditional_logic'], $all_fields['feed_condition_conditional_logic_object']); 
  286.  
  287. // Unset all mapped fields we know are there 
  288. foreach ($fields as $field) { 
  289. unset($all_fields['_'.$field['name']]); 
  290.  
  291. if(!empty($all_fields)) { 
  292. // All the fields that remain are custom 
  293. foreach ($all_fields as $key => $value) { 
  294. $name = esc_html( ltrim($key, '_') ); 
  295. $fields[] = array( 
  296. 'name' => $name,  
  297. 'label' => sprintf(__('Custom Field: %s', 'gravity-forms-salesforce'), '<span class="custom_field_name">'.$name.'</span>'),  
  298. 'class' => 'custom_field',  
  299. ); 
  300.  
  301. return $fields; 
  302.  
  303. /** 
  304. * Add Custom Field functionality for Feed configuration 
  305. */ 
  306. protected function settings_custom_fields() { 
  307. ?> 
  308.  
  309. <style> 
  310. .delete_custom_field { 
  311. cursor:pointer; 
  312. position: absolute; 
  313. margin-left:-1.5em; 
  314. margin-top:.4em; 
  315. </style> 
  316.  
  317. <script> 
  318.  
  319. jQuery(document).ready(function($) { 
  320.  
  321. function KWSFormAddListItem(element) { 
  322. var table = jQuery('.settings-field-map-table'); 
  323. var $clone = jQuery('tr:has(select):last-child', table).clone(); 
  324. var $html = KWSGetInput(); 
  325.  
  326. $clone 
  327. // Make the drop-down and input values empty 
  328. .find("input[type=text], select") 
  329. .val(null) 
  330. .attr('name', null) 
  331. .attr('id', null) 
  332. .end() // Go back to $clone 
  333. .find('td:first-child') 
  334. .html($html) // Add the name input 
  335. .prepend(KWSGetDeleteImage()) 
  336. .end() // Go back to $clone 
  337. .appendTo(table); // Add $clone to the table 
  338.  
  339. return false; 
  340.  
  341. function KWSGetDeleteImage() { 
  342. return $('<img class="delete_list_item delete_custom_field" src="<?php echo GFCommon::get_base_url() . "/images/remove.png"; ?>" style="cursor:pointer;" />'); 
  343.  
  344. /** 
  345. * Get an input with a value 
  346. * @param {string} value The value of the text box 
  347. */ 
  348. function KWSGetInput(value) { 
  349.  
  350. return $('<input/>', { 
  351. class: 'kws_custom_field widefat code',  
  352. type: 'text',  
  353. style: 'padding:.5em .2em;',  
  354. placeholder: '<?php echo str_replace("'", "\'", esc_js( $this->_custom_field_placeholder )); ?>',  
  355. value: value 
  356. }); 
  357.  
  358.  
  359. /** 
  360. * Convert text values ("Custom Field: Example") back to inputs ("<input value="Example">) on form load. 
  361. */ 
  362. jQuery('.settings-field-map-table tr td:has(span.custom_field_name)').each(function() { 
  363.  
  364. $(this).html(KWSGetInput($(this).find('span.custom_field_name').text())); 
  365. }); 
  366.  
  367. /** 
  368. * When the value of the input is changed, change the name of the select 
  369. * associated with it. 
  370. */ 
  371. jQuery('body').on('blur keyup', 'input.kws_custom_field', function(e) { 
  372. $(this).closest('tr').find('select') 
  373. .attr('name', '_gaddon_setting__'+$(this).val()); 
  374. }); 
  375.  
  376. /** 
  377. * When the button is clicked to add a custom field, add one. 
  378. */ 
  379. jQuery('body').on('click', '#kws_add_custom_field', function(e) { 
  380. e.preventDefault(); 
  381. KWSFormAddListItem(this); 
  382. }); 
  383.  
  384. /** 
  385. * When the delete button is clicked, remove the custom field row 
  386. */ 
  387. jQuery('body').on('click', '.delete_custom_field', function(e) { 
  388. $(this).closest('tr').fadeOut(function() { $(this).remove(); }); 
  389. }); 
  390.  
  391. jQuery('select.custom_field') 
  392. .closest('tr') 
  393. .find('td:first-child') 
  394. .addClass('gfield_list_icons') 
  395. .prepend(KWSGetDeleteImage()); 
  396. }); 
  397.  
  398. </script> 
  399.  
  400.  
  401. <a href="#" class="button submit button-large button-secondary" id="kws_add_custom_field"><?php _e('Add a custom field', 'gravity-forms-salesforce'); ?></a> 
  402.  
  403. <?php 
  404.  
  405. /** 
  406. * Add a little service favicon next to the forms that have active feeds for the service 
  407. * @todo Separate out the CSS/JS into files so no inline code. Yeah, yeah, I know. 
  408. */ 
  409. public function show_addon_status() { 
  410. global $pagenow, $plugin_page; 
  411.  
  412. // Only show this on the plugins page. 
  413. if(!($plugin_page === 'gf_edit_forms' && !isset($_REQUEST['id']))) { return; } 
  414.  
  415. // If the icon's not defined, don't do this 
  416. if(!$favicon = $this->get_service_favicon_path()) { return; } 
  417.  
  418. $activeforms = array(); 
  419.  
  420. // Get all feeds 
  421. $feeds = $this->get_feeds(); 
  422.  
  423. // Get a list of active forms by looping through all forms and checking `is_active` 
  424. foreach($feeds as $feed) { 
  425.  
  426. // Only add the icon if the feed is active 
  427. if($feed['is_active']) { 
  428.  
  429. // If the feed isn't already in the active forms list, add it. 
  430. if(!in_array($feed['form_id'], $activeforms)) { 
  431. $activeforms[] = $feed['form_id']; 
  432.  
  433. // If there are no active forms, get outta here. 
  434. if(empty($activeforms)) { return; } 
  435.  
  436. $class = sanitize_html_class($this->get_slug()); 
  437. ?> 
  438. <style type="text/css"> 
  439. .enabled_<?php echo $class; ?> { 
  440. position: absolute; 
  441. background: url('<?php echo $favicon; ?>') right top no-repeat; 
  442. height: 16px; 
  443. width: 16px; 
  444. margin-left: 10px; 
  445. </style> 
  446. <script type="text/javascript"> 
  447. jQuery(document).ready(function($) { 
  448.  
  449. var <?php echo __CLASS__; ?>ActiveForms = [<?php echo implode(', ', $activeforms); ?>]; 
  450.  
  451. var $span = $('<span />', { 
  452. 'class': 'enabled_<?php echo $class; ?>',  
  453. 'title': "<?php esc_attr_e(sprintf(__("%s integration is enabled for this Form", 'gravity-forms-salesforce'), $this->get_service_name())); ?>" 
  454. // , 'text': 'SF' 
  455. }); 
  456.  
  457. // Loop through the rows of forms 
  458. $('table .user-list tr').each(function() { 
  459. // If the current form ID is in the array of active forms 
  460. if($.inArray(parseInt($(this).attr('data-id')), <?php echo __CLASS__; ?>ActiveForms) > -1) { 
  461. $('.row-title', $(this)).append($span.clone()); // Then add the icon to the title. 
  462. }); 
  463. }); 
  464. </script> 
  465. <?php 
  466.  
  467. /** 
  468. * Make sure there's at least one list selected. 
  469. * @param array $field Field value 
  470. * @param array $field_setting Field setting for the feed 
  471. */ 
  472. function validate_service_lists($field, $field_setting) { 
  473.  
  474. // Remove disabled lists from the settings array. 
  475. // Active lists have 1 as their value; inactive have 0. 
  476. foreach ($field_setting as $key => $value) { 
  477. if(empty($value)) { unset($field_setting[$key]); } 
  478.  
  479. // If there are still active lists, this is valid. 
  480. if(empty($field_setting)) { 
  481. $this->set_field_error( $field, sprintf(__('You must choose at least one %s list to receive contacts.', 'gravity-forms-salesforce'), $this->get_service_name() )); 
  482.  
  483. /** 
  484. * Get the active lists for a GF Form Feed 
  485. * @param array $feed Form Feed array 
  486. * @param boolean $populate Whether to populate with the list name or not. key = ID, value = name 
  487. * @return array Array of list IDs 
  488. */ 
  489. protected function feed_get_active_lists($feed, $populate = false) { 
  490. $feed_meta = $feed['meta']; 
  491.  
  492. $lists = rgar( $feed_meta, "lists" ); 
  493.  
  494. if(empty($lists)) { return array(); } 
  495.  
  496. foreach ($lists as $key => $list) { 
  497. if(empty($list)) { unset($lists[$key]); } 
  498.  
  499. $active_lists = array_keys($lists); 
  500.  
  501. if($populate) { 
  502. // Get all the lists 
  503. $all_lists = $this->get_service_lists(); 
  504.  
  505. // Populate the list names for active lists 
  506. $output_lists = array(); 
  507. foreach($active_lists as $active_list_id) { 
  508. $output_lists[$active_list_id] = esc_html( $all_lists[$active_list_id]['name'] ); 
  509. } else { 
  510. $output_lists = $active_lists; 
  511.  
  512. return $output_lists; 
  513.  
  514. /** 
  515. * Generate the list of lists to choose from. 
  516. * @return [type] [description] 
  517. */ 
  518. protected function feed_settings_service_lists() { 
  519. return $this->get_service_lists(); 
  520.  
  521. /** 
  522. * Return an array of all available lists for the service. 
  523. * @return array 
  524. */ 
  525. protected function get_service_lists() { 
  526. return array(); 
  527.  
  528. /** 
  529. * Modify the columns shown in the Form Feeds view 
  530. * Form Feeds view in Forms > Form > Form Settings > {Addon Name} 
  531. * @return [type] [description] 
  532. */ 
  533. function feed_list_columns() { 
  534. return array( 
  535. 'feed_name' => __('Feed Name', 'gravity-forms-salesforce'),  
  536. 'lists' => __('Connected Lists', 'gravity-forms-salesforce'), // if you want to show the lists that the form is connected to. 
  537. ); 
  538.  
  539. /** 
  540. * Generate the feed name for the Form Feeds view 
  541. * Under Forms > Form > Form Settings > {Addon Name} 
  542. * @param array $item Feed data 
  543. * @return string HTML output of name of form with link to edit the feed. 
  544. */ 
  545. function get_column_value_feed_name($item) { 
  546. $name = rgar($item['meta'], "name"); 
  547. $feed_id = rgar($item, "id"); 
  548. $name = !empty($name) ? $name : sprintf(__("Untitled Feed (#%s)", "gravityforms"), $feed_id); 
  549. $edit_url = add_query_arg(array("fid" => $feed_id)); 
  550. return sprintf('<a href="%s" title="Edit the configuration for the feed “%s”">%s</a>', $edit_url, esc_html( $name ), $name); 
  551.  
  552. /** 
  553. * Generate the feed lists for the Form Feeds view 
  554. * Under Forms > Form > Form Settings > {Addon Name} 
  555. * @param array $item Feed data 
  556. * @return string HTML output of name of form with link to edit the feed. 
  557. */ 
  558. function get_column_value_lists($item) { 
  559.  
  560. // Get an array of active list IDs for the current form 
  561. $active_lists = $this->feed_get_active_lists($item, true); 
  562.  
  563. if(empty($active_lists)) { 
  564. return __('No Lists Connected.'); 
  565.  
  566. return '<ul class="ul-square"><li style="list-style:square;">'.implode('</li><li style="list-style:square;">', $active_lists).'</li></ul>'; 
  567.  
  568. public function feed_list_title() { 
  569. $title = parent::feed_list_title(); 
  570. return $this->get_service_icon().$title; 
  571.  
  572. protected function settings_password($field, $echo = true) { 
  573.  
  574. // Once Rocketgenius implements this, this wont be necessary. 
  575. if(method_exists('GFAddOn', 'settings_password') && is_callable(array('GFAddOn', 'settings_password'))) { 
  576. $output = parent::settings_password($field, false); 
  577. } else { 
  578. $output = parent::settings_text($field, false); 
  579.  
  580. $output = str_replace('type="text"', 'type="password" autocomplete="off"', $output); 
  581.  
  582. if($echo) { echo $output; } 
  583.  
  584. return $output; 
  585.  
  586. protected function single_setting_row_html($field) { 
  587.  
  588. if(empty($field['value'])) { return; } 
  589.  
  590. echo '<tr><td colspan="2">'.$field['value'].'</td></tr>'; 
  591.  
  592. /** 
  593. * If you want a menu item under "Forms", uncomment below. 
  594. */ 
  595. /**public function plugin_page() { 
  596. require_once(GFCommon::get_base_path() . "/tooltips.php"); 
  597. parent::plugin_settings_page(); 
  598. }*/ 
  599.  
  600. /** 
  601. * Generate array of fields to be mapped. 
  602. * @return array Array of fields to be mapped. 
  603. */ 
  604. protected function feed_settings_fields_field_map() { 
  605. return array( 
  606. array( 
  607. "label" => "First Name",  
  608. "type" => "text",  
  609. "name" => "first_name",  
  610. ),  
  611. array( 
  612. "label" => "Last Name",  
  613. "type" => "text",  
  614. "name" => "last_name",  
  615. ); 
  616.  
  617. /** 
  618. * Generate the plugin settings. 
  619. * @return [type] [description] 
  620. */ 
  621. public function plugin_settings_fields() { 
  622. return array( 
  623. array( 
  624. "title" => sprintf(__("%s Add-On Settings", 'gravity-forms-salesforce'), $this->get_service_name()),  
  625. array( 
  626. 'type' => 'html',  
  627. 'value' => 'Welcome! If you have any questions, please',  
  628. 'dependency' => array(&$this, 'is_not_configured'),  
  629. ),  
  630. "fields" => array( 
  631. array( 
  632. "name" => "textbox",  
  633. "tooltip" => "This is the tooltip",  
  634. "label" => "This is the label",  
  635. "type" => "text",  
  636. "class" => "small",  
  637. 'dependency' => array(&$this, 'is_configured'),  
  638. ),  
  639. array( 
  640. "name" => "textbox",  
  641. "tooltip" => "This is the tooltip",  
  642. "label" => "This is the label",  
  643. "type" => "text",  
  644. "class" => "small",  
  645. 'dependency' => array(&$this, 'is_not_configured'),  
  646. ); 
  647.  
  648. /** 
  649. * Export the entry on submit. 
  650. * @param array $feed Feed array 
  651. * @param array $entry Entry array 
  652. * @param array $form Form array 
  653. */ 
  654. public function process_feed( $feed, $entry, $form ) { 
  655.  
  656. // The settings are only normally available on the admin page. 
  657. // We want it available everywhere. 
  658. $this->set_settings( $feed['meta'] ); 
  659.  
  660. return; 
  661.  
  662. protected function get_merge_vars_from_entry($feed, $entry, $form) { 
  663.  
  664. $this->log_debug( 'All Feed Meta: '.print_r( $feed["meta"], true ) ); 
  665.  
  666. $merge_vars = array(); 
  667. foreach($feed["meta"] as $var_tag => $field_id) { 
  668.  
  669. if(empty($field_id) || strpos($var_tag, 'feed_condition') !== false) { 
  670. $this->log_debug( '[get_merge_vars_from_entry]: Feed field not defined for field ID '.$var_tag ); 
  671. continue; 
  672.  
  673. $var_tag = str_replace('field_map__', '', $var_tag); 
  674.  
  675. if( !is_numeric( $field_id ) ) { 
  676.  
  677. $value = GFCommon::replace_variables( '{'.$field_id.'}' , $form, $entry, false, false, false ); 
  678.  
  679. } else { 
  680.  
  681. $field = RGFormsModel::get_field($form, $field_id); 
  682.  
  683. $value = RGFormsModel::get_lead_field_value($entry, $field); 
  684.  
  685.  
  686. // If the value is multi-part, like a name or address, there will be an array 
  687. // returned. In that case, we check the array for the key of the field id. 
  688. if(is_array($value)) { 
  689.  
  690. if(array_key_exists($field_id, $value)) { 
  691. $merge_vars[$var_tag] = $value[$field_id]; 
  692.  
  693. // The key wasn't mapped. Keep going. 
  694. continue; 
  695.  
  696. } else { 
  697.  
  698. // The value can be an array, serialized. 
  699. $value = maybe_unserialize( $value ); 
  700.  
  701. $merge_vars[$var_tag] = $value; 
  702.  
  703.  
  704.  
  705. return $merge_vars; 
  706.  
  707. /** 
  708. * Gravity Forms would only check if the `gform-settings-save` field has been saved. 
  709. * We need to be more vigilant than that, so we check if the current `subview` parameter matches the short title. 
  710. */ 
  711. public function is_save_postback() { 
  712. return !rgempty("gform-settings-save") && ( rgget("subview") === $this->get_short_title() || rgget("subview") === $this->get_slug() ); 
  713.  
  714. /** 
  715. * Get a setting from the addon settings 
  716. * @see GFAddon::maybe_save_plugin_settings() 
  717. * @param string $key Name of the key to retrieve from the settings array 
  718. * @return mixed|NULL If set, return the setting. Otherwise, NULL. 
  719. */ 
  720. public function get_addon_setting($key = '', $use_postback = true) { 
  721.  
  722. if( $use_postback && $this->is_save_postback() ) { 
  723.  
  724. // This is taken from GFAddon::maybe_save_plugin_settings() 
  725. // and is used to fetch settings from saved configuration before 
  726. // they're saved in the GFAddon flow. 
  727. $posted_settings = $this->get_posted_settings(); 
  728. $sections = $this->plugin_settings_fields(); 
  729. $is_valid = $this->validate_settings( $sections, $posted_settings ); 
  730.  
  731. // If the saved settings are valid, use them as the value. 
  732. if($is_valid) { $settings = $posted_settings; } 
  733.  
  734. } else { 
  735. $settings = $this->get_plugin_settings(); 
  736.  
  737. return isset($settings[$key]) ? $settings[$key] : NULL; 
  738.  
  739. /** 
  740. * @todo - use this for GF Directory. It has great filtering capabilities. 
  741. */ 
  742. public function _get_results_page_config() { 
  743. return array( 
  744. "title" => "Directory Listings",  
  745. "capabilities" => array("gravityforms_quiz_results"),  
  746. "callbacks" => array( 
  747. "fields" => array($this, "results_fields"),  
  748. "calculation" => array($this, "results_calculation"),  
  749. "markup" => array($this, "results_markup"),  
  750. ); 
  751.  
  752. /** 
  753. * print_r() alternative. 
  754. * @param mixed $content Item to print 
  755. * @param boolean $die Die after output? 
  756. * @param string $title Print a heading for the data below. 
  757. * @return [type] [description] 
  758. */ 
  759. public static function r($content, $die = false, $title = NULL) { 
  760. if(!empty($title)) { 
  761. echo '<h3>'.esc_attr($title).'</h3>'; 
  762. echo '<pre>'; 
  763. print_r($content); 
  764. echo '</pre>'; 
  765. if($die) { exit(); } 
  766. return; 
  767.