/gravity-forms-addons.php

  1. <?php 
  2. /** 
  3. Plugin Name: Gravity Forms Directory & Addons 
  4. Plugin URI: http://katz.co/gravity-forms-addons/ 
  5. Description: Turn <a href="http://katz.si/gravityforms">Gravity Forms</a> into a great WordPress directory...and more! 
  6. Author: Katz Web Services, Inc. 
  7. Version: 3.8.1 
  8. Author URI: https://gravityview.co 
  9. Text Domain: gravity-forms-addons 
  10. License: GPLv2 or later 
  11. License URI: http://www.gnu.org/licenses/gpl-2.0.html 
  12. Domain Path: /languages 
  13.   
  14. Copyright 2015 Katz Web Services, Inc. (email: info@katzwebservices.com) 
  15.   
  16. This program is free software; you can redistribute it and/or modify 
  17. it under the terms of the GNU General Public License as published by 
  18. the Free Software Foundation; either version 3 of the License, or 
  19. (at your option) any later version. 
  20.   
  21. This program is distributed in the hope that it will be useful,  
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  24. GNU General Public License for more details. 
  25.   
  26. You should have received a copy of the GNU General Public License 
  27. along with this program. If not, see <http://www.gnu.org/licenses/>. 
  28.   
  29. */ 
  30.  
  31. register_activation_hook( __FILE__, array( 'GFDirectory', 'activation' ) ); 
  32. add_action( 'plugins_loaded', array( 'GFDirectory', 'plugins_loaded' ) ); 
  33. add_action( 'plugins_loaded', 'kws_gf_load_functions' ); 
  34.  
  35. class GFDirectory { 
  36.  
  37. private static $path = "gravity-forms-addons/gravity-forms-addons.php"; 
  38. private static $slug = "gravity-forms-addons"; 
  39. private static $version = "3.8.1"; 
  40. private static $min_gravityforms_version = "1.5"; 
  41.  
  42. public static function directory_defaults( $args = array() ) { 
  43. $defaults = array( 
  44. 'form' => 1,  
  45. // Gravity Forms form ID 
  46. 'approved' => false,  
  47. // Show only entries that have been Approved (have a field in the form that is an Admin-only checkbox with a value of 'Approved' 
  48. 'smartapproval' => true,  
  49. // Auto-convert form into Approved-only when an Approved field is detected. 
  50. 'directoryview' => 'table',  
  51. // Table, list or DL 
  52. 'entryview' => 'table',  
  53. // Table, list or DL 
  54. 'hovertitle' => true,  
  55. // Show column name as user hovers over cell 
  56. 'tableclass' => 'gf_directory widefat',  
  57. // Class for the <table> 
  58. 'tablestyle' => '',  
  59. // inline CSS for the <table> 
  60. 'rowclass' => '',  
  61. // Class for the <table> 
  62. 'rowstyle' => '',  
  63. // inline CSS for all <tbody><tr>'s 
  64. 'valign' => '',  
  65. 'sort' => 'date_created',  
  66. // Use the input ID ( example: 1.3 or 7 or ip ) 
  67. 'dir' => 'DESC',  
  68.  
  69. 'useredit' => false,  
  70. 'limituser' => false,  
  71. 'adminedit' => false,  
  72.  
  73. 'status' => 'active',  
  74. // Added in 2.0 
  75. 'start_date' => '',  
  76. // Added in 2.0 
  77. 'end_date' => '',  
  78. // Added in 2.0 
  79.  
  80. //'wpautop' => true, // Convert bulk paragraph text to...paragraphs. Deprecated 3.6.3 
  81. 'page_size' => 20,  
  82. // Number of entries to show at once 
  83. 'startpage' => 1,  
  84. // If you want to show page 8 instead of 1 
  85.  
  86. 'lightboxstyle' => 3,  
  87. 'lightboxsettings' => array( 'images' => true, 'entry' => NULL, 'websites' => NULL ),  
  88.  
  89. 'showcount' => true,  
  90. // Do you want to show "Displaying 1-19 of 19"? 
  91. 'pagelinksshowall' => true,  
  92. // Whether to show each page number, or just 7 
  93. 'next_text' => '»',  
  94. 'prev_text' => '«',  
  95. 'pagelinkstype' => 'plain',  
  96. // 'plain' is just a string with the links separated by a newline character. The other possible values are either 'array' or 'list'. 
  97. //'fulltext' => true, // If there's a textarea or post content field, show the full content or a summary? Deprecated 3.6.3 
  98. 'linkemail' => true,  
  99. // Convert email fields to email mailto: links 
  100. 'linkwebsite' => true,  
  101. // Convert URLs to links 
  102. 'linknewwindow' => false,  
  103. // Open links in new window? (uses target="_blank") 
  104. 'nofollowlinks' => false,  
  105. // Add nofollow to all links, including emails 
  106. 'titleshow' => true,  
  107. // Show a form title? By default, the title will be the form title. 
  108. 'titleprefix' => 'Entries for ',  
  109. // Default GF behavior is 'Entries : ' 
  110. 'tablewidth' => '100%',  
  111. // 'width' attribute for the table 
  112. 'searchtabindex' => false,  
  113. // adds tabindex="" to the search field 
  114. 'search' => true,  
  115. // show the search field 
  116. 'tfoot' => true,  
  117. // show the <tfoot> 
  118. 'thead' => true,  
  119. // show the <thead> 
  120. 'showadminonly' => false,  
  121. // Admin only columns aren't shown by default, but can be (added 2.0.1) 
  122. 'datecreatedformat' => get_option( 'date_format' ) . ' \a\t ' . get_option( 'time_format' ),  
  123. // Use standard PHP date formats (http://php.net/manual/en/function.date.php) 
  124. 'credit' => true,  
  125. // Credit link 
  126. 'dateformat' => false,  
  127. // Override the options from Gravity Forms, and use standard PHP date formats (http://php.net/manual/en/function.date.php) 
  128. 'postimage' => 'icon',  
  129. // Whether to show icon, thumbnail, or large image 
  130. 'getimagesize' => false,  
  131. 'entry' => true,  
  132. // If there's an Entry ID column, link to the full entry 
  133. 'entrylink' => 'View entry details',  
  134. 'entryth' => 'More Info',  
  135. 'entryback' => '← Back to directory',  
  136. 'entryonly' => true,  
  137. 'entrytitle' => 'Entry Detail',  
  138. 'entrydetailtitle' => '%%formtitle%% : Entry # %%leadid%%',  
  139. 'entryanchor' => true,  
  140. 'truncatelink' => false,  
  141. 'appendaddress' => false,  
  142. 'hideaddresspieces' => false,  
  143. 'jssearch' => true,  
  144. 'jstable' => false,  
  145. 'lightbox' => NULL,  
  146. // depreciated - Combining with lightboxsettings 
  147. 'entrylightbox' => NULL,  
  148. // depreciated - Combining with lightboxsettings 
  149. ); 
  150.  
  151. $settings = get_option( "gf_addons_settings" ); 
  152. if ( isset( $settings['directory_defaults'] ) ) { 
  153. $defaults = wp_parse_args( $settings['directory_defaults'], $defaults ); 
  154.  
  155. $options = wp_parse_args( $args, $defaults ); 
  156.  
  157. // Backward Compatibility 
  158. if ( ! empty( $args['lightbox'] ) ) { 
  159. $options['lightboxsettings']['images'] = 1; 
  160. if ( ! empty( $args['entrylightbox'] ) ) { 
  161. $options['lightboxsettings']['entry'] = 1; 
  162. unset( $options['lightbox'], $options['entrylightbox'] ); // Depreciated for lightboxsettings 
  163.  
  164. return apply_filters( 'kws_gf_directory_defaults', $options ); 
  165.  
  166. public static function plugins_loaded() { 
  167.  
  168. if ( ! self::is_gravityforms_installed() ) { 
  169. return false; 
  170.  
  171. include_once( plugin_dir_path( __FILE__ ) . '/edit-form.php' ); 
  172. include_once( plugin_dir_path( __FILE__ ) . '/admin.php' ); 
  173. include_once( plugin_dir_path( __FILE__ ) . '/gravity-forms-lead-creator.php' ); 
  174.  
  175. if ( in_array( RG_CURRENT_PAGE, array( "gf_entries", "admin.php", "admin-ajax.php" ) ) ) { 
  176. self::globals_get_approved_column(); 
  177. if ( self::is_gravity_page() ) { 
  178. self::load_functionality(); 
  179.  
  180. add_action( 'init', array( 'GFDirectory', 'init' ) ); 
  181. add_shortcode( 'directory', array( 'GFDirectory', 'make_directory' ) ); 
  182.  
  183.  
  184. //Plugin starting point. Will load appropriate files 
  185. public static function init() { 
  186. global $current_user; 
  187.  
  188. load_plugin_textdomain( 'gravity-forms-addons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  189.  
  190. self::add_rewrite(); 
  191.  
  192. if ( ! self::is_gravityforms_supported() ) { 
  193. return; 
  194.  
  195. if ( ! is_admin() ) { 
  196.  
  197. add_action( 'template_redirect', array( 'GFDirectory', 'enqueue_files' ) ); 
  198. if ( apply_filters( 'kws_gf_directory_canonical_add', true ) ) { 
  199. add_filter( 'post_link', array( 'GFDirectory', 'directory_canonical' ), 1, 3 ); 
  200. add_filter( 'page_link', array( 'GFDirectory', 'directory_canonical' ), 1, 3 ); 
  201. if ( apply_filters( 'kws_gf_directory_shortlink', true ) ) { 
  202. add_filter( 'get_shortlink', array( 'GFDirectory', 'shortlink' ) ); 
  203. add_filter( 'kws_gf_directory_lead_filter', array( 'GFDirectory', 'show_only_user_entries' ), 10, 2 ); 
  204. add_filter( 'kws_gf_directory_anchor_text', array( 'GFDirectory', 'directory_anchor_text' ) ); 
  205.  
  206. //integrating with Members plugin 
  207. if ( function_exists( 'members_get_capabilities' ) ) { 
  208. add_filter( 'members_get_capabilities', array( "GFDirectory", "members_get_capabilities" ) ); 
  209.  
  210. add_filter( 'kws_gf_directory_td_address', array( 
  211. 'GFDirectory',  
  212. 'format_address',  
  213. ), 1, 2 ); // Add this filter so it can be removed or overridden by users 
  214.  
  215. if ( self::is_directory_page() ) { 
  216.  
  217. //enqueueing sack for AJAX requests 
  218. wp_enqueue_script( array( "sack", 'datepicker' ) ); 
  219. wp_enqueue_style( 'gravityforms-admin', GFCommon::get_base_url() . '/css/admin.css' ); 
  220.  
  221. } else if ( self::is_gravity_page( 'gf_entries' ) ) { 
  222. wp_enqueue_script( 'thickbox', array( 'jquery' ) ); 
  223. add_filter( "gform_get_field_value", array( 'GFDirectory', 'add_lead_approved_hidden_input' ), 1, 3 ); 
  224. } else if ( in_array( RG_CURRENT_PAGE, array( "admin-ajax.php" ) ) ) { 
  225. add_action( 'wp_ajax_rg_update_feed_active', array( 'GFDirectory', 'update_feed_active' ) ); 
  226. add_action( 'wp_ajax_gf_select_directory_form', array( 'GFDirectory', 'select_directory_form' ) ); 
  227. add_action( 'wp_ajax_rg_update_approved', array( 'GFDirectory', 'directory_update_approved_hook' ) ); 
  228. add_action( 'wp_ajax_change_directory_columns', array( 'GFDirectory', 'change_directory_columns' ) ); 
  229. } else if ( in_array( RG_CURRENT_PAGE, array( "plugins.php" ) ) ) { 
  230.  
  231. add_filter( 'plugin_action_links', array( 'GFDirectory', 'settings_link' ), 10, 2 ); 
  232.  
  233.  
  234.  
  235. //Target of Member plugin filter. Provides the plugin with Gravity Forms lists of capabilities 
  236. public static function members_get_capabilities( $caps ) { 
  237. return array_merge( $caps, array( "gravityforms_directory", "gravityforms_directory_uninstall" ) ); 
  238.  
  239. static public function activation() { 
  240. self::add_permissions(); 
  241. self::flush_rules(); 
  242.  
  243. public static function is_gravityforms_installed() { 
  244. return class_exists( "RGForms" ); 
  245.  
  246. public static function add_permissions() { 
  247. global $wp_roles; 
  248. $wp_roles->add_cap( "administrator", "gravityforms_directory" ); 
  249. $wp_roles->add_cap( "administrator", "gravityforms_directory_uninstall" ); 
  250.  
  251. static public function flush_rules() { 
  252. global $wp_rewrite; 
  253. self::add_rewrite(); 
  254. $wp_rewrite->flush_rules(); 
  255.  
  256. return; 
  257.  
  258.  
  259. static private function load_functionality() { 
  260.  
  261. register_deactivation_hook( __FILE__, array( 'GFDirectory', 'uninstall' ) ); 
  262.  
  263. $settings = self::get_settings(); 
  264. extract( $settings ); 
  265.  
  266. if ( $referrer ) { 
  267. // Load Joost's referrer tracker 
  268. @include_once( 'gravity-forms-referrer.php' ); 
  269.  
  270.  
  271. static public function shortlink( $link = '' ) { 
  272. global $post; 
  273. if ( empty( $post ) ) { 
  274. return; 
  275. if ( empty( $link ) && isset( $post->guid ) ) { 
  276. $link = $post->guid; 
  277.  
  278. return $link; 
  279.  
  280. $url = add_query_arg( array() ); 
  281. if ( preg_match( '/' . sanitize_title( apply_filters( 'kws_gf_directory_endpoint', 'entry' ) ) . '\/([0-9]+)(?:\/|-)([0-9]+)\/?/ism', $url, $matches ) ) { 
  282. $link = add_query_arg( array( 'form' => (int) $matches[1], 'leadid' => (int) $matches[2] ), $link ); 
  283. } elseif ( isset( $_REQUEST['leadid'] ) && isset( $_REQUEST['form'] ) ) { 
  284. $link = wp_nonce_url( add_query_arg( array( 
  285. 'leadid' => (int) $_REQUEST['leadid'],  
  286. 'form' => (int) $_REQUEST['form'],  
  287. ), $link ), sprintf( 'view-%d-%d', $_REQUEST['leadid'], $_REQUEST['form'] ), 'view' ); 
  288.  
  289. return esc_url_raw( $link ); 
  290.  
  291. static public function directory_canonical( $permalink, $sentPost = '', $leavename = '' ) { 
  292.  
  293. // This was messing up the wp menu links 
  294. if ( did_action( 'wp_head' ) ) { 
  295. return $permalink; 
  296.  
  297. global $post; 
  298.  
  299. if ( is_object( $post ) ) { 
  300. $post->permalink = $permalink; 
  301.  
  302. $url = add_query_arg( array() ); 
  303.  
  304. $sentPostID = is_object( $sentPost ) ? $sentPost->ID : $sentPost; 
  305. // $post->ID === $sentPostID is so that add_query_arg match doesn't apply to prev/next posts; just current 
  306. preg_match( '/(' . sanitize_title( apply_filters( 'kws_gf_directory_endpoint', 'entry' ) ) . '\/([0-9]+)(?:\/|-)([0-9]+)\/?)/ism', $url, $matches ); 
  307. if ( isset( $post->ID ) && $post->ID === $sentPostID && ! empty( $matches ) ) { 
  308. return trailingslashit( $permalink ) . $matches[0]; 
  309. } elseif ( isset( $post->ID ) && $post->ID === $sentPostID && ( isset( $_REQUEST['leadid'] ) && isset( $_REQUEST['form'] ) ) || ! empty( $matches ) ) { 
  310. if ( $matches ) { 
  311. $leadid = $matches[2]; 
  312. $form = $matches[1]; 
  313. } else { 
  314. $leadid = $_REQUEST['leadid']; 
  315. $form = $_REQUEST['form']; 
  316.  
  317. return esc_url_raw( wp_nonce_url( add_query_arg( array( 
  318. 'leadid' => $leadid,  
  319. 'form' => $form,  
  320. ), trailingslashit( $permalink ) ), sprintf( 'view-%d-%d', $leadid, $form ), 'view' ) ); 
  321.  
  322. return $permalink; 
  323.  
  324. static public function enqueue_files() { 
  325. global $post, $kws_gf_styles, $kws_gf_scripts, $kws_gf_directory_options; 
  326.  
  327. $kws_gf_styles = isset( $kws_gf_styles ) ? $kws_gf_styles : array(); 
  328. $kws_gf_scripts = isset( $kws_gf_scripts ) ? $kws_gf_scripts : array(); 
  329.  
  330. if ( ! empty( $post ) && 
  331. ! empty( $post->post_content ) && 
  332. preg_match( '/(.?)\[(directory)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)/', $post->post_content, $matches ) 
  333. ) { 
  334.  
  335. $options = self::directory_defaults( shortcode_parse_atts( $matches[3] ) ); 
  336. if ( ! is_array( $options['lightboxsettings'] ) ) { 
  337. $options['lightboxsettings'] = explode( ', ', $options['lightboxsettings'] ); 
  338.  
  339. $kws_gf_directory_options = $options; 
  340. do_action( 'kws_gf_directory_enqueue', $options, $post ); 
  341.  
  342. extract( $options ); 
  343.  
  344. if ( $jstable ) { 
  345. $theme = apply_filters( 'kws_gf_tablesorter_theme', 'blue', $form ); 
  346. wp_enqueue_style( 'tablesorter-' . $theme, plugins_url( "/bower_components/jquery.tablesorter/css/theme.{$theme}.css", __FILE__ ) ); 
  347. wp_enqueue_script( 'tablesorter-min', plugins_url( "/bower_components/jquery.tablesorter/js/jquery.tablesorter.min.js", __FILE__ ), array( 'jquery' ) ); 
  348. $kws_gf_styles[] = 'tablesorter-' . $theme; 
  349. $kws_gf_scripts[] = 'tablesorter-min'; 
  350.  
  351. if ( ! empty( $lightboxsettings ) ) { 
  352. wp_enqueue_script( 'colorbox', plugins_url( "/bower_components/colorbox/jquery.colorbox-min.js", __FILE__ ), array( 'jquery' ) ); 
  353. wp_enqueue_style( 'colorbox', plugins_url( "/bower_components/colorbox/example{$lightboxstyle}/colorbox.css", __FILE__ ), array() ); 
  354. $kws_gf_scripts[] = $kws_gf_styles[] = 'colorbox'; 
  355. add_action( apply_filters( 'kws_gf_directory_colorbox_action', 'wp_footer' ), array( 
  356. 'GFDirectory',  
  357. 'load_colorbox',  
  358. ), 1000 ); 
  359.  
  360. list( $urlformid, $urlleadid ) = self::get_form_and_lead_ids(); 
  361. if ( isset( $_GET['edit'] ) && ! empty( $urlformid ) && isset( $urlleadid ) ) { 
  362.  
  363. $edit_scripts = array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all' ); 
  364. wp_enqueue_script( 'gform_gravityforms', $edit_scripts ); 
  365.  
  366. $kws_gf_scripts[] = array_merge( $kws_gf_scripts, $edit_scripts ); 
  367.  
  368. static function format_colorbox_settings( $colorboxSettings = array() ) { 
  369. $settings = array(); 
  370. if ( ! empty( $colorboxSettings ) && is_array( $colorboxSettings ) ) { 
  371. foreach ( $colorboxSettings as $key => $value ) { 
  372. if ( $value === NULL ) { 
  373. continue; 
  374. if ( $value === true ) { 
  375. $value = 'true'; 
  376. } elseif ( empty( $value ) && $value !== 0 ) { 
  377. $value = 'false'; 
  378. } else { 
  379. $value = '"' . $value . '"'; 
  380. $settings["{$key}"] = $key . ':' . $value . ''; 
  381.  
  382. return $settings; 
  383.  
  384. static public function load_colorbox() { 
  385. global $kws_gf_directory_options; 
  386. extract( $kws_gf_directory_options ); 
  387.  
  388. $lightboxsettings = apply_filters( 'kws_gf_directory_lightbox_settings', $lightboxsettings ); 
  389. $colorboxSettings = apply_filters( 'kws_gf_directory_colorbox_settings', array( 
  390. 'width' => apply_filters( 'kws_gf_directory_lightbox_width', '70%' ),  
  391. 'height' => apply_filters( 'kws_gf_directory_lightbox_height', '70%' ),  
  392. 'iframe' => true,  
  393. 'maxWidth' => '95%',  
  394. 'maxHeight' => '95%',  
  395. 'current' => '{current} of {total}',  
  396. 'rel' => apply_filters( 'kws_gf_directory_lightbox_settings_rel', NULL ),  
  397. ) ); 
  398.  
  399. ?> 
  400. <script> 
  401. jQuery( document ).ready( function ( $ ) { 
  402. <?php 
  403. $output = ''; 
  404. foreach ( $lightboxsettings as $key => $value ) { 
  405. $settings = $colorboxSettings; 
  406. if ( is_numeric( $key ) ) { 
  407. $key = $value; 
  408. switch ( $key ) { 
  409. case "images": 
  410. $settings['width'] = $settings['height'] = $settings['iframe'] = NULL; 
  411. break; 
  412. case "urls": 
  413. $settings['height'] = '80%'; 
  414. break; 
  415. $output .= "\t\t" . '$(".colorbox[rel~=\'directory_' . $key . '\']").colorbox('; 
  416. if ( ! empty( $settings ) ) { 
  417. $output .= "{\n\t\t\t" . implode( ", \n\t\t\t", self::format_colorbox_settings( apply_filters( "kws_gf_directory_lightbox_{$key}_settings", $settings ) ) ) . "\n\t\t}"; 
  418. $output .= ");\n\n"; 
  419. echo $output; 
  420. do_action( 'kws_gf_directory_jquery', $kws_gf_directory_options ); 
  421. ?> 
  422. } ); 
  423. </script> 
  424. <?php 
  425.  
  426. static public function add_rewrite() { 
  427. global $wp_rewrite, $wp; 
  428.  
  429. if ( ! $wp_rewrite->using_permalinks() ) { 
  430. return; 
  431. $endpoint = sanitize_title( apply_filters( 'kws_gf_directory_endpoint', 'entry' ) ); 
  432.  
  433. # @TODO: Make sure this works in MU 
  434. $wp_rewrite->add_permastruct( "{$endpoint}", $endpoint . '/%' . $endpoint . '%/?', true ); 
  435. $wp_rewrite->add_endpoint( "{$endpoint}", EP_ALL ); 
  436.  
  437. //Returns true if the current page is one of Gravity Forms pages. Returns false if not 
  438. public static function is_gravity_page( $page = array() ) { 
  439. $current_page = trim( strtolower( RGForms::get( "page" ) ) ); 
  440. if ( empty( $page ) ) { 
  441. $gf_pages = array( "gf_edit_forms", "gf_new_form", "gf_entries", "gf_settings", "gf_export", "gf_help" ); 
  442. } else { 
  443. $gf_pages = is_array( $page ) ? $page : array( $page ); 
  444.  
  445. return in_array( $current_page, $gf_pages ); 
  446.  
  447. static function directory_update_approved( $lead_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0 ) { 
  448. global $wpdb, $_gform_directory_approvedcolumn, $current_user; 
  449. $current_user = wp_get_current_user(); 
  450. $user_data = get_userdata( $current_user->ID ); 
  451.  
  452. if ( ! empty( $approvedcolumn ) ) { 
  453. $_gform_directory_approvedcolumn = $approvedcolumn; 
  454.  
  455. if ( empty( $_gform_directory_approvedcolumn ) ) { 
  456. return false; 
  457.  
  458. $lead_detail_table = RGFormsModel::get_lead_details_table_name(); 
  459.  
  460. // This will be faster in the 1.6+ future. 
  461. if ( function_exists( 'gform_update_meta' ) ) { 
  462. gform_update_meta( $lead_id, 'is_approved', $approved ); 
  463.  
  464. if ( empty( $approved ) ) { 
  465. //Deleting details for this field 
  466. $sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id=%d AND field_number BETWEEN %f AND %f ", $lead_id, $_gform_directory_approvedcolumn - 0.001, $_gform_directory_approvedcolumn + 0.001 ); 
  467. $wpdb->query( $sql ); 
  468.  
  469. RGFormsModel::add_note( $lead_id, $current_user->ID, $user_data->display_name, stripslashes( __( 'Disapproved the lead', 'gravity-forms-addons' ) ) ); 
  470.  
  471. } else { 
  472.  
  473. // Get the fields for the lead 
  474. $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $lead_id ) ); 
  475.  
  476. $lead_detail_id = RGFormsModel::get_lead_detail_id( $current_fields, $_gform_directory_approvedcolumn ); 
  477.  
  478. // If there's already a field for the approved column, then we update it. 
  479. if ( $lead_detail_id > 0 ) { 
  480. $update = $wpdb->update( $lead_detail_table, array( "value" => $approved ), array( 
  481. "lead_id" => $lead_id,  
  482. 'form_id' => $form_id,  
  483. 'field_number' => $_gform_directory_approvedcolumn,  
  484. ), array( "%s" ), array( "%d", "%d", "%f" ) ); 
  485. } // Otherwise, we create it. 
  486. else { 
  487. $update = $wpdb->insert( $lead_detail_table, array( 
  488. "lead_id" => $lead_id,  
  489. "form_id" => $form_id,  
  490. "field_number" => $_gform_directory_approvedcolumn,  
  491. "value" => $approved,  
  492. ), array( "%d", "%d", "%f", "%s" ) ); 
  493.  
  494. RGFormsModel::add_note( $lead_id, $current_user->ID, $user_data->display_name, stripslashes( __( 'Approved the lead', 'gravity-forms-addons' ) ) ); 
  495.  
  496. static public function edit_lead_detail( $Form, $lead, $options ) { 
  497. global $current_user, $_gform_directory_approvedcolumn; 
  498. require_once( GFCommon::get_base_path() . "/form_display.php" ); 
  499. if ( empty( $_gform_directory_approvedcolumn ) ) { 
  500. $_gform_directory_approvedcolumn = self::get_approved_column( $Form ); 
  501.  
  502. // We fetch this again, since it may have had some admin-only columns taken out. 
  503. #$lead = RGFormsModel::get_lead($lead["id"]); 
  504.  
  505. // If you want to allow users to edit their own approval (?) add a filter and return true. 
  506. if ( apply_filters( 'kws_gf_directory_allow_user_edit_approved', false ) === false ) { 
  507. $Form['fields'] = self::remove_approved_column( 'form', $Form['fields'], $_gform_directory_approvedcolumn ); 
  508.  
  509. // If this is not the form that should be edited 
  510. list( $urlformid, $urlleadid ) = self::get_form_and_lead_ids(); 
  511. if ( intval( $Form['id'] ) !== intval( $urlformid ) || intval( $lead['id'] ) !== intval( $urlleadid ) ) { 
  512. return; 
  513.  
  514. // If either of these two things are false (creator of lead, or admin) 
  515. if ( ! ( 
  516.  
  517. // Users can edit their own listings, they are logged in, the current user is the creator of the lead 
  518. ( ! empty( $options['useredit'] ) && is_user_logged_in() && intval( $current_user->ID ) === intval( $lead['created_by'] ) ) === true || // OR 
  519.  
  520. // Administrators can edit every listing, and this person has administrator access 
  521. ( ! empty( $options['adminedit'] ) && self::has_access( "gravityforms_directory" ) ) === true ) 
  522. ) { 
  523. // Kick them out. 
  524. printf( esc_html_e( '%sYou do not have permission to edit this form.%s', 'gravity-forms-addons' ), '<div class="error">', '</div>' ); 
  525.  
  526. return; 
  527.  
  528. $validation_message = ''; 
  529.  
  530. // If the form is submitted 
  531. if ( RGForms::post( "action" ) === "update" ) { 
  532. check_admin_referer( 'gforms_save_entry', 'gforms_save_entry' ); 
  533.  
  534. $lead = apply_filters( 'kws_gf_directory_lead_being_updated', $lead, $Form ); 
  535.  
  536. // We don't DO passwords. 
  537. foreach ( $Form['fields'] as $key => $field ) { 
  538. if ( $field['type'] === 'password' ) { 
  539. unset( $Form['fields'][ $key ] ); 
  540.  
  541. $is_valid = GFFormDisplay::validate( $Form, $lead ); 
  542.  
  543. $validation_message = ''; 
  544. foreach ( $Form['fields'] as $field ) { 
  545. if ( ! GFCommon::is_product_field( $field["type"] ) ) { 
  546. $validation_message .= ( rgget( "failed_validation", $field ) && ! empty( $field["validation_message"] ) ) ? sprintf( "<li class='gfield_description validation_message'><strong>%s</strong>: %s</li>", $field["label"], $field["validation_message"] ) : "";; 
  547. if ( ! empty( $validation_message ) ) { 
  548. $validation_message = '<ul>' . $validation_message . '</ul>'; 
  549. echo esc_html( apply_filters( 'kws_gf_directory_lead_error_message', sprintf( __( "%sThere were errors with the edit you made.%s%s", 'gravity-forms-addons' ), "<div class='error' id='message' style='padding:.5em .75em; background-color:#ffffcc; border:1px solid #ccc;'><p>", "</p>", $validation_message . '</div>' ), $lead, $Form ) ); 
  550.  
  551. // So the form submission always throws an error even though there's no problem. 
  552. // Product fields can't be edited, so that doesn't really matter. 
  553. if ( ! empty( $is_valid ) || ( empty( $is_valid ) && empty( $validation_message ) ) ) { 
  554. do_action( 'kws_gf_directory_pre_update_lead', $lead, $Form ); 
  555. // since @3.6.1 to enable conditional fields' updates. 
  556. self::save_lead( $Form, $lead ); 
  557. $lead = RGFormsModel::get_lead( $lead["id"] ); 
  558.  
  559. do_action( 'kws_gf_directory_post_update_lead', $lead, $Form ); 
  560. echo apply_filters( 'kws_gf_directory_lead_updated_message', sprintf( esc_html__( "%sThe entry was successfully updated.%s", 'gravity-forms-addons' ), "<p class='updated' id='message' style='padding:.5em .75em; background-color:#ffffcc; border:1px solid #ccc;'>", "</p>" ), $lead, $Form ); 
  561.  
  562. return $lead; 
  563.  
  564. if ( ( isset( $_GET['edit'] ) && wp_verify_nonce( $_GET['edit'], 'edit' . $lead['id'] . $Form["id"] ) ) || ! empty( $validation_message ) ) { 
  565.  
  566. // The ID of the form needs to be `gform_{form_id}` for the pluploader 
  567. ?> 
  568. <form method="post" id="gform_<?php echo esc_attr( $Form['id'] ); ?>" enctype="multipart/form-data" 
  569. action="<?php echo esc_url( remove_query_arg( array( 
  570. 'gf_search',  
  571. 'sort',  
  572. 'dir',  
  573. 'pagenum',  
  574. 'edit',  
  575. ), add_query_arg( array() ) ) ); ?>"> 
  576. <?php 
  577. wp_nonce_field( 'gforms_save_entry', 'gforms_save_entry' ); 
  578. ?> 
  579. <input type="hidden" name="action" id="action" value="update"/> 
  580. <input type="hidden" name="screen_mode" id="screen_mode" value="edit"/> 
  581. <?php 
  582.  
  583. $form_without_products = $Form; 
  584. $post_message_shown = false; 
  585. $product_fields = array(); 
  586. foreach ( $Form['fields'] as $key => $field ) { 
  587. if ( 
  588. GFCommon::is_product_field( $field["type"] ) || 
  589. is_numeric( $lead["post_id"] ) && GFCommon::is_post_field( $field ) 
  590. ) { 
  591. if ( is_numeric( $lead["post_id"] ) && GFCommon::is_post_field( $field ) && ! $message_shown ) { 
  592. echo apply_filters( 'kws_gf_directory_edit_post_details_text', sprintf( esc_html__( 'You can edit post details from the %1$spost page%2$s.', 'gravity-forms-addons' ), '<a href="' . admin_url( 'post.php?action=edit&post=' . $lead["post_id"] ) . '">', '</a>' ), $field, $lead, $lead['post_id'] ); 
  593. $message_shown = true; 
  594.  
  595. unset( $form_without_products['fields'][ $key ] ); 
  596. $product_fields[] = $field['id']; 
  597. if ( ! empty( $field['inputs'] ) ) { 
  598. foreach ( $field['inputs'] as $input ) { 
  599. $product_fields[] = $input['id']; 
  600.  
  601. $lead_without_products = &$lead; 
  602. foreach ( $product_fields as $product_field ) { 
  603. $value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  604. unset( $lead_without_products[ $product_field ] ); 
  605.  
  606. require_once( GFCommon::get_base_path() . "/entry_detail.php" ); 
  607. GFEntryDetail::lead_detail_edit( apply_filters( 'kws_gf_directory_form_being_edited', $form_without_products, $lead ), apply_filters( 'kws_gf_directory_lead_being_edited', $lead_without_products, $form_without_products ) ); 
  608. echo '<input class="button-primary" type="submit" tabindex="4" value="' . esc_attr( apply_filters( 'kws_gf_directory_update_lead_button_text', __( 'Update Entry', 'gravity-forms-addons' ) ) ) . '" name="save" />'; 
  609. ?> 
  610. </form> 
  611. <?php 
  612. do_action( 'kws_gf_directory_post_after_edit_lead_form', $lead, $Form ); 
  613.  
  614. return false; 
  615. } elseif ( ( isset( $_GET['edit'] ) && ! wp_verify_nonce( $_GET['edit'], 'edit' ) ) ) { 
  616. echo apply_filters( 'kws_gf_directory_edit_access_error_message', sprintf( esc_html__( "%sThe link to edit this entry is not valid; it may have expired.%s", 'gravity-forms-addons' ), "<p class='error' id='message' style='padding:.5em .75em; background-color:#ffffcc; border:1px solid #ccc;'>", "</p>" ), $lead, $Form ); 
  617.  
  618. return $lead; 
  619.  
  620.  
  621. static public function lead_detail( $Form, $lead, $allow_display_empty_fields = false, $inline = true, $options = array() ) { 
  622.  
  623. if ( ! class_exists( 'GFEntryList' ) ) { 
  624. require_once( GFCommon::get_base_path() . "/entry_list.php" ); 
  625.  
  626. global $current_user, $_gform_directory_approvedcolumn; 
  627. get_currentuserinfo(); 
  628.  
  629. $display_empty_fields = ''; 
  630. $allow_display_empty_fields = true; 
  631. if ( $allow_display_empty_fields ) { 
  632. $display_empty_fields = @rgget( "gf_display_empty_fields", $_COOKIE ); 
  633. if ( empty( $options ) ) { 
  634. $options = self::directory_defaults(); 
  635.  
  636. // There is no edit link 
  637. if ( isset( $_GET['edit'] ) || RGForms::post( "action" ) === "update" ) { 
  638. // Process editing leads 
  639. $lead = self::edit_lead_detail( $Form, $lead, $options ); 
  640. if ( RGForms::post( "action" ) !== "update" ) { 
  641. return; 
  642.  
  643. extract( $options ); 
  644.  
  645. ?> 
  646. <table cellspacing="0" class="widefat fixed entry-detail-view"> 
  647. <?php 
  648. $title = str_replace( '%%formtitle%%', $Form["title"], str_replace( '%%leadid%%', $lead['id'], $entrydetailtitle ) ); 
  649. if ( ! empty( $title ) && $inline ) { ?> 
  650. <thead> 
  651. <tr> 
  652. <th id="details" colspan="2" scope="col"> 
  653. <?php 
  654. $title = apply_filters( 'kws_gf_directory_detail_title', apply_filters( 'kws_gf_directory_detail_title_' . (int) $lead['id'], array( 
  655. $title,  
  656. $lead,  
  657. ), true ), true ); 
  658. if ( is_array( $title ) ) { 
  659. echo $title[0]; 
  660. } else { 
  661. echo $title; 
  662. ?> 
  663. </th> 
  664. </tr> 
  665. </thead> 
  666. <?php 
  667. ?> 
  668. <tbody> 
  669. <?php 
  670. $count = 0; 
  671. $has_product_fields = false; 
  672. $field_count = sizeof( $Form["fields"] ); 
  673. $display_value = ''; 
  674. foreach ( $Form["fields"] as $field ) { 
  675.  
  676. // Don't show fields defined as hide in single. 
  677. if ( ! empty( $field['hideInSingle'] ) ) { 
  678. if ( self::has_access( "gravityforms_directory" ) ) { 
  679. echo "\n\t\t\t\t\t\t\t\t\t" . '<!-- ' . sprintf( esc_html__( '(Admin-only notice) Field #%d not shown: "Hide This Field in Single Entry View" was selected.', 'gravity-forms-addons' ), $field['id'] ) . ' -->' . "\n\n"; 
  680. continue; 
  681.  
  682. $count ++; 
  683. $is_last = $count >= $field_count ? true : false; 
  684.  
  685. switch ( RGFormsModel::get_input_type( $field ) ) { 
  686. case "section" : 
  687. if ( ! GFCommon::is_section_empty( $field, $Form, $lead ) || $display_empty_fields ) { 
  688. $count ++; 
  689. $is_last = $count >= $field_count ? true : false; 
  690. ?> 
  691. <tr> 
  692. <td colspan="2" 
  693. class="entry-view-section-break<?php echo $is_last ? " lastrow" : "" ?>"><?php echo esc_html( GFCommon::get_label( $field ) ) ?></td> 
  694. </tr> 
  695. <?php 
  696. break; 
  697.  
  698. case "captcha": 
  699. case "html": 
  700. case "password": 
  701. case "page": 
  702. //ignore captcha, html, password, page field 
  703. break; 
  704.  
  705. case "post_image" : 
  706. $value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  707. $valueArray = explode( "|:|", $value ); 
  708.  
  709. @list( $url, $title, $caption, $description ) = $valueArray; 
  710.  
  711. if ( ! empty( $url ) ) { 
  712. $value = $display_value = self::render_image_link( $url, $lead, $options, $title, $caption, $description ); 
  713. break; 
  714.  
  715. default : 
  716. //ignore product fields as they will be grouped together at the end of the grid 
  717. if ( GFCommon::is_product_field( $field["type"] ) ) { 
  718. $has_product_fields = true; 
  719. continue; 
  720.  
  721. $value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  722. $display_value = GFCommon::get_lead_field_display( $field, $value, $lead["currency"] ); 
  723. break; 
  724.  
  725. } // end switch 
  726.  
  727. $display_value = apply_filters( "gform_entry_field_value", $display_value, $field, $lead, $Form ); 
  728. if ( $display_empty_fields || ! empty( $display_value ) || $display_value === "0" ) { 
  729. $count ++; 
  730. $is_last = $count >= $field_count && ! $has_product_fields ? true : false; 
  731. $last_row = $is_last ? " lastrow" : ""; 
  732.  
  733. $display_value = empty( $display_value ) && $display_value !== "0" ? " " : $display_value; 
  734.  
  735. $content = ' 
  736. <tr> 
  737. <th colspan="2" class="entry-view-field-name">' . esc_html( GFCommon::get_label( $field ) ) . '</th> 
  738. </tr> 
  739. <tr> 
  740. <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> 
  741. </tr>'; 
  742.  
  743. $content = apply_filters( "gform_field_content", $content, $field, $value, $lead["id"], $Form["id"] ); 
  744.  
  745. echo $content; 
  746.  
  747.  
  748. } // End foreach 
  749.  
  750. $products = array(); 
  751. if ( $has_product_fields ) { 
  752. $products = GFCommon::get_product_fields( $Form, $lead ); 
  753. if ( ! empty( $products["products"] ) ) { 
  754. ?> 
  755. <tr> 
  756. <td colspan="2" 
  757. class="entry-view-field-name"><?php echo apply_filters( "gform_order_label_{$Form["id"]}", apply_filters( "gform_order_label", __( "Order", "gravityforms" ), $Form["id"] ), $Form["id"] ) ?></td> 
  758. </tr> 
  759. <tr> 
  760. <td colspan="2" class="entry-view-field-value lastrow"> 
  761. <table class="entry-products" cellspacing="0" width="97%"> 
  762. <colgroup> 
  763. <col class="entry-products-col1"> 
  764. <col class="entry-products-col2"> 
  765. <col class="entry-products-col3"> 
  766. <col class="entry-products-col4"> 
  767. </colgroup> 
  768. <thead> 
  769. <th scope="col"><?php echo apply_filters( "gform_product_{$Form['id']}", apply_filters( "gform_product", __( "Product", "gravityforms" ), $Form['id'] ), $Form['id'] ) ?></th> 
  770. <th scope="col" 
  771. class="textcenter"><?php echo apply_filters( "gform_product_qty_{$Form['id']}", apply_filters( "gform_product_qty", __( "Qty", "gravityforms" ), $Form['id'] ), $Form['id'] ) ?></th> 
  772. <th scope="col"><?php echo apply_filters( "gform_product_unitprice_{$Form['id']}", apply_filters( "gform_product_unitprice", __( "Unit Price", "gravityforms" ), $Form['id'] ), $Form['id'] ) ?></th> 
  773. <th scope="col"><?php echo apply_filters( "gform_product_price_{$Form['id']}", apply_filters( "gform_product_price", __( "Price", "gravityforms" ), $Form['id'] ), $Form['id'] ) ?></th> 
  774. </thead> 
  775. <tbody> 
  776. <?php 
  777.  
  778. $total = 0; 
  779. foreach ( $products["products"] as $product ) { 
  780. ?> 
  781. <tr> 
  782. <td> 
  783. <div class="product_name"><?php echo esc_html( $product["name"] ) ?></div> 
  784. <ul class="product_options"> 
  785. <?php 
  786. $price = GFCommon::to_number( $product["price"] ); 
  787. if ( is_array( rgar( $product, "options" ) ) ) { 
  788. $count = sizeof( $product["options"] ); 
  789. $index = 1; 
  790. foreach ( $product["options"] as $option ) { 
  791. $price += GFCommon::to_number( $option["price"] ); 
  792. $class = $index == $count ? " class='lastitem'" : ""; 
  793. $index ++; 
  794. ?> 
  795. <li<?php echo $class ?>><?php echo $option["option_label"] ?></li> 
  796. <?php 
  797. $subtotal = floatval( $product["quantity"] ) * $price; 
  798. $total += $subtotal; 
  799. ?> 
  800. </ul> 
  801. </td> 
  802. <td class="textcenter"><?php echo $product["quantity"] ?></td> 
  803. <td><?php echo GFCommon::to_money( $price, $lead["currency"] ) ?></td> 
  804. <td><?php echo GFCommon::to_money( $subtotal, $lead["currency"] ) ?></td> 
  805. </tr> 
  806. <?php 
  807. $total += floatval( $products["shipping"]["price"] ); 
  808. ?> 
  809. </tbody> 
  810. <tfoot> 
  811. <?php 
  812. if ( ! empty( $products["shipping"]["name"] ) ) { 
  813. ?> 
  814. <tr> 
  815. <td colspan="2" rowspan="2" class="emptycell"> </td> 
  816. <td class="textright shipping"><?php echo $products["shipping"]["name"] ?></td> 
  817. <td class="shipping_amount"><?php echo GFCommon::to_money( $products["shipping"]["price"], $lead["currency"] ) ?> 
  818.  </td> 
  819. </tr> 
  820. <?php 
  821. ?> 
  822. <tr> 
  823. <?php 
  824. if ( empty( $products["shipping"]["name"] ) ) { 
  825. ?> 
  826. <td colspan="2" class="emptycell"> </td> 
  827. <?php 
  828. ?> 
  829. <td class="textright grandtotal"><?php esc_html_e( "Total", "gravityforms" ) ?></td> 
  830. <td class="grandtotal_amount"><?php echo GFCommon::to_money( $total, $lead["currency"] ) ?></td> 
  831. </tr> 
  832. </tfoot> 
  833. </table> 
  834. </td> 
  835. </tr> 
  836.  
  837. <?php 
  838.  
  839. // Edit link 
  840. if ( 
  841. ! empty( $options['useredit'] ) && is_user_logged_in() && intval( $current_user->ID ) === intval( $lead['created_by'] ) || // Is user who created the entry 
  842. ! empty( $options['adminedit'] ) && self::has_access( "gravityforms_directory" ) // Or is an administrator 
  843. ) { 
  844.  
  845. if ( ! empty( $options['adminedit'] ) && self::has_access( "gravityforms_directory" ) ) { 
  846. $editbuttontext = apply_filters( 'kws_gf_directory_edit_entry_text_admin', __( "Edit Entry", 'gravity-forms-addons' ) ); 
  847. } else { 
  848. $editbuttontext = apply_filters( 'kws_gf_directory_edit_entry_text_user', __( "Edit Your Entry", 'gravity-forms-addons' ) ); 
  849.  
  850. ?> 
  851. <tr> 
  852. <th scope="row" 
  853. class="entry-view-field-name"><?php echo esc_html( apply_filters( 'kws_gf_directory_edit_entry_th', __( "Edit", "gravity-forms-addons" ) ) ); ?></th> 
  854. <td class="entry-view-field-value useredit"><a 
  855. href="<?php echo esc_url( add_query_arg( array( 'edit' => wp_create_nonce( 'edit' . $lead['id'] . $Form["id"] ) ) ) ); ?>"><?php echo $editbuttontext; ?></a> 
  856. </td> 
  857. </tr> 
  858. <?php 
  859.  
  860. ?> 
  861. </tbody> 
  862. </table> 
  863. <?php 
  864.  
  865. static public function get_admin_only( $form, $adminOnly = array() ) { 
  866. if ( ! is_array( $form ) ) { 
  867. return false; 
  868.  
  869. foreach ( $form['fields'] as $key => $col ) { 
  870. // Only the Go to Entry button adds disableMargins. 
  871.  
  872. if ( $col['type'] === 'hidden' && ! empty( $col['useAsEntryLink'] ) && ! empty( $col['disableMargins'] ) ) { 
  873. continue; 
  874. if ( ! empty( $col['adminOnly'] ) ) { 
  875. $adminOnly[] = $col['id']; 
  876. if ( isset( $col['inputs'] ) && is_array( $col['inputs'] ) ) { 
  877. foreach ( $col['inputs'] as $key2 => $input ) { 
  878. if ( ! empty( $col['adminOnly'] ) ) { 
  879. $adminOnly[] = $input['id']; 
  880.  
  881. return $adminOnly; 
  882.  
  883. /** 
  884. * Get the form and lead IDs from the URL or from $_REQUEST 
  885. * @return array|null $formid, $leadid if found. Null if not. 
  886. */ 
  887. static private function get_form_and_lead_ids() { 
  888. global $wp, $wp_rewrite; 
  889.  
  890. $formid = $leadid = NULL; 
  891.  
  892. $url = isset( $wp->request ) ? $wp->request : add_query_arg( array(), home_url() ); 
  893.  
  894. if ( 
  895. // If permalinks is turned on 
  896. $wp_rewrite->using_permalinks() && 
  897. // And 
  898. preg_match( '/\/?' . sanitize_title( apply_filters( 'kws_gf_directory_endpoint', 'entry' ) ) . '\/([0-9]+)(?:\/|-)([0-9]+)/ism', $url, $matches ) 
  899. ) { 
  900. $formid = $matches[1]; 
  901. $leadid = $matches[2]; 
  902. } else { 
  903. $formid = isset( $_REQUEST['form'] ) ? (int) $_REQUEST['form'] : $formid; 
  904. $leadid = isset( $_REQUEST['leadid'] ) ? (int) $_REQUEST['leadid'] : $leadid; 
  905.  
  906. return array( $formid, $leadid ); 
  907.  
  908.  
  909.  
  910. /** 
  911. * get_back_link function. 
  912. * 
  913. * @access public 
  914. * 
  915. * @param string $entryback (default: '') The text of the back-link anchor 
  916. * 
  917. * @return string The HTML link for the backlink 
  918. */ 
  919. static public function get_back_link( $passed_entryback = '' ) { 
  920. global $pagenow, $wp_rewrite; 
  921.  
  922. $options = self::directory_defaults(); 
  923.  
  924. if ( isset( $_GET['edit'] ) ) { 
  925. return '<p class="entryback"><a href="' . esc_url( add_query_arg( array(), remove_query_arg( array( 'edit' ) ) ) ) . '">' . esc_html( __( apply_filters( 'kws_gf_directory_edit_entry_cancel', "← Cancel Editing" ), "gravity-forms-addons" ) ) . '</a></p>'; 
  926.  
  927. list( $formid, $leadid ) = self::get_form_and_lead_ids(); 
  928. extract( $options ); 
  929.  
  930. // Use passed value, if available. Otherwise, use default 
  931. $entryback = ! empty( $passed_entryback ) ? $passed_entryback : $entryback; 
  932.  
  933. if ( $pagenow === 'entry-details.php' ) { 
  934.  
  935. // If possible, link back to the original post. 
  936. if ( isset( $_GET['post'] ) ) { 
  937. $href = get_permalink( (int) $_GET['post'] ); 
  938. } else { 
  939. // Otherwise we rely on Javascript below. 
  940. $href = '#'; 
  941.  
  942. $onclick = ' onclick="parent.jQuery.fn.colorbox.close();"'; 
  943. } else { 
  944. $onclick = ''; 
  945. $href = remove_query_arg( array( 'row', 'leadid', 'form', 'edit' ) ); 
  946. if ( $wp_rewrite->using_permalinks() ) { 
  947. $href = preg_replace( '/(' . sanitize_title( apply_filters( 'kws_gf_directory_endpoint', 'entry' ) ) . '\/(?:[0-9]+)(?:\/|-)(?:[0-9]+)\/?)/ism', '', $href ); 
  948.  
  949. $href = esc_url_raw( $href ); 
  950.  
  951. $url = parse_url( add_query_arg( array(), $href ) ); 
  952. if ( ! empty( $url['query'] ) && ! empty( $permalink ) ) { 
  953. $href .= '?' . $url['query']; 
  954. if ( ! empty( $options['entryanchor'] ) ) { 
  955. $href .= '#lead_row_' . $leadid; 
  956.  
  957. // If there's a back link, format it 
  958. if ( ! empty( $entryback ) && ! empty( $entryonly ) ) { 
  959. $link = apply_filters( 'kws_gf_directory_backlink', '<p class="entryback"><a href="' . $href . '"' . $onclick . '>' . esc_html( $entryback ) . '</a></p>', $href, $entryback ); 
  960. } else { 
  961. $link = ''; 
  962.  
  963. return $link; 
  964.  
  965. static public function process_lead_detail( $inline = true, $entryback = '', $showadminonly = false, $adminonlycolumns = array(), $approvedcolumn = NULL, $options = array(), $entryonly = true ) { 
  966. global $wp, $post, $wp_rewrite, $wpdb; 
  967. $formid = $leadid = false; 
  968.  
  969. list( $formid, $leadid ) = self::get_form_and_lead_ids(); 
  970.  
  971. if ( ! is_null( $leadid ) && ! is_null( $formid ) ) { 
  972.  
  973. $form = apply_filters( 'kws_gf_directory_lead_detail_form', RGFormsModel::get_form_meta( (int) $formid ) ); 
  974. $lead = apply_filters( 'kws_gf_directory_lead_detail', RGFormsModel::get_lead( (int) $leadid ) ); 
  975.  
  976. if ( empty( $approvedcolumn ) ) { 
  977. $approvedcolumn = self::get_approved_column( $form ); 
  978. if ( empty( $adminonlycolumns ) && ! $showadminonly ) { 
  979. $adminonlycolumns = self::get_admin_only( $form ); 
  980.  
  981. //since 3.5 
  982. $lead = self::remove_hidden_fields( array( $lead ), $adminonlycolumns, $approvedcolumn, true, true, $showadminonly, $form ); 
  983. $lead = $lead[0]; 
  984.  
  985. ob_start(); // Using ob_start() allows us to filter output 
  986. self::lead_detail( $form, $lead, false, $inline, $options ); 
  987. $content = ob_get_contents(); // Get the output 
  988. ob_end_clean(); // Clear the buffer 
  989.  
  990. // Get the back link if this is a single entry. 
  991. $link = ! empty( $entryonly ) ? self::get_back_link( $entryback ) : ''; 
  992.  
  993. $content = $link . $content; 
  994. $content = apply_filters( 'kws_gf_directory_detail', apply_filters( 'kws_gf_directory_detail_' . (int) $leadid, $content, (int) $leadid ), (int) $leadid ); 
  995.  
  996.  
  997. if ( isset( $options['entryview'] ) ) { 
  998. $content = self::html_display_type_filter( $content, $options['entryview'], true ); 
  999.  
  1000. return $content; 
  1001. } else { 
  1002. return false; 
  1003.  
  1004. static public function change_directory_columns() { 
  1005. check_ajax_referer( 'gforms_directory_columns', 'gforms_directory_columns' ); 
  1006. $columns = GFCommon::json_decode( stripslashes( $_POST["directory_columns"] ), true ); 
  1007. self::update_grid_column_meta( (int) $_POST['form_id'], $columns ); 
  1008.  
  1009. public static function update_grid_column_meta( $form_id, $columns ) { 
  1010. global $wpdb; 
  1011.  
  1012. $meta = maybe_serialize( stripslashes_deep( $columns ) ); 
  1013.  
  1014. update_option( 'gf_directory_form_' . $form_id . '_grid', $meta ); 
  1015.  
  1016. public static function get_grid_column_meta( $form_id ) { 
  1017. global $wpdb; 
  1018.  
  1019. $grid = get_option( 'gf_directory_form_' . $form_id . '_grid' ); 
  1020. if ( ! $grid ) { 
  1021. $grid = GFFormsModel::get_grid_column_meta( $form_id ); 
  1022. self::update_grid_column_meta( $form_id, $grid ); 
  1023.  
  1024. return maybe_unserialize( $grid ); 
  1025.  
  1026. public static function get_grid_columns( $form_id, $input_label_only = false ) { 
  1027. $form = GFFormsModel::get_form_meta( $form_id ); 
  1028. $field_ids = self::get_grid_column_meta( $form_id ); 
  1029.  
  1030. if ( ! is_array( $field_ids ) ) { 
  1031. $field_ids = array(); 
  1032. for ( $i = 0, $count = sizeof( $form["fields"] ); $i < $count && $i < 5; $i ++ ) { 
  1033. $field = $form["fields"][ $i ]; 
  1034.  
  1035. if ( RGForms::get( "displayOnly", $field ) ) { 
  1036. continue; 
  1037.  
  1038.  
  1039. if ( isset( $field["inputs"] ) && is_array( $field["inputs"] ) ) { 
  1040. $field_ids[] = $field["id"]; 
  1041. if ( $field["type"] == "name" ) { 
  1042. $field_ids[] = $field["id"] . '.3'; //adding first name 
  1043. $field_ids[] = $field["id"] . '.6'; //adding last name 
  1044. } else if ( isset( $field["inputs"][0] ) ) { 
  1045. $field_ids[] = $field["inputs"][0]["id"]; //getting first input 
  1046. } else { 
  1047. $field_ids[] = $field["id"]; 
  1048. //adding default entry meta columns 
  1049. $entry_metas = GFFormsModel::get_entry_meta( $form_id ); 
  1050. foreach ( $entry_metas as $key => $entry_meta ) { 
  1051. if ( rgar( $entry_meta, "is_default_column" ) ) { 
  1052. $field_ids[] = $key; 
  1053.  
  1054. $columns = array(); 
  1055. $entry_meta = GFFormsModel::get_entry_meta( $form_id ); 
  1056. foreach ( $field_ids as $field_id ) { 
  1057.  
  1058. switch ( $field_id ) { 
  1059. case "id" : 
  1060. $columns[ $field_id ] = array( "label" => "Entry Id", "type" => "id" ); 
  1061. break; 
  1062. case "ip" : 
  1063. $columns[ $field_id ] = array( "label" => "User IP", "type" => "ip" ); 
  1064. break; 
  1065. case "date_created" : 
  1066. $columns[ $field_id ] = array( "label" => "Entry Date", "type" => "date_created" ); 
  1067. break; 
  1068. case "source_url" : 
  1069. $columns[ $field_id ] = array( "label" => "Source Url", "type" => "source_url" ); 
  1070. break; 
  1071. case "payment_status" : 
  1072. $columns[ $field_id ] = array( "label" => "Payment Status", "type" => "payment_status" ); 
  1073. break; 
  1074. case "transaction_id" : 
  1075. $columns[ $field_id ] = array( "label" => "Transaction Id", "type" => "transaction_id" ); 
  1076. break; 
  1077. case "payment_date" : 
  1078. $columns[ $field_id ] = array( "label" => "Payment Date", "type" => "payment_date" ); 
  1079. break; 
  1080. case "payment_amount" : 
  1081. $columns[ $field_id ] = array( "label" => "Payment Amount", "type" => "payment_amount" ); 
  1082. break; 
  1083. case "created_by" : 
  1084. $columns[ $field_id ] = array( "label" => "User", "type" => "created_by" ); 
  1085. break; 
  1086. case ( ( is_string( $field_id ) || is_int( $field_id ) ) && array_key_exists( $field_id, $entry_meta ) ) : 
  1087. $columns[ $field_id ] = array( "label" => $entry_meta[ $field_id ]["label"], "type" => $field_id ); 
  1088. break; 
  1089. default : 
  1090. $field = GFFormsModel::get_field( $form, $field_id ); 
  1091. if ( $field ) { 
  1092. $columns[ strval( $field_id ) ] = array( 
  1093. "label" => self::get_label( $field, $field_id, $input_label_only ),  
  1094. "type" => rgget( "type", $field ),  
  1095. "inputType" => rgget( "inputType", $field ),  
  1096. ); 
  1097.  
  1098. return $columns; 
  1099.  
  1100. /** 
  1101. * Get the label for the input field. This is necessary to prevent Admin Labels from being used instead of normal labels. 
  1102. */ 
  1103. public static function get_label( $field, $input_id = 0, $input_only = false ) { 
  1104. $field_label = rgar( $field, "label" ); 
  1105. $input = GFFormsModel::get_input( $field, $input_id ); 
  1106. if ( rgget( "type", $field ) == "checkbox" && $input != NULL ) { 
  1107. return $input["label"]; 
  1108. } else if ( $input != NULL ) { 
  1109. return $input_only ? $input["label"] : $field_label . ' (' . $input["label"] . ')'; 
  1110. } else { 
  1111. return $field_label; 
  1112.  
  1113. public static function make_directory( $atts ) { 
  1114. global $wpdb, $wp_rewrite, $post, $wpdb, $directory_shown, $kws_gf_scripts, $kws_gf_styles; 
  1115.  
  1116. if ( ! class_exists( 'GFEntryDetail' ) ) { 
  1117. @require_once( GFCommon::get_base_path() . "/entry_detail.php" ); 
  1118. if ( ! class_exists( 'GFCommon' ) ) { 
  1119. @require_once( GFCommon::get_base_path() . "/common.php" ); 
  1120. if ( ! class_exists( 'RGFormsModel' ) ) { 
  1121. @require_once( GFCommon::get_base_path() . "/forms_model.php" ); 
  1122. if ( ! class_exists( 'GFEntryList' ) ) { 
  1123. require_once( GFCommon::get_base_path() . "/entry_list.php" ); 
  1124.  
  1125. //quit if version of wp is not supported 
  1126. if ( ! class_exists( 'GFCommon' ) || ! GFCommon::ensure_wp_version() ) { 
  1127. return; 
  1128.  
  1129. // Already showed edit directory form and there are more than one forms on the page. 
  1130. if ( did_action( 'kws_gf_directory_post_after_edit_lead_form' ) ) { 
  1131. return; 
  1132.  
  1133. ob_start(); // Using ob_start() allows us to use echo instead of $output .= 
  1134.  
  1135. foreach ( $atts as $key => $att ) { 
  1136. if ( strtolower( $att ) == 'false' ) { 
  1137. $atts[ $key ] = false; 
  1138. if ( strtolower( $att ) == 'true' ) { 
  1139. $atts[ $key ] = true; 
  1140.  
  1141. $atts['approved'] = isset( $atts['approved'] ) ? $atts['approved'] : - 1; 
  1142.  
  1143. if ( ! empty( $atts['lightboxsettings'] ) && is_string( $atts['lightboxsettings'] ) ) { 
  1144. $atts['lightboxsettings'] = explode( ', ', $atts['lightboxsettings'] ); 
  1145.  
  1146. $options = self::directory_defaults( $atts ); 
  1147.  
  1148. // Make sure everything is on the same page. 
  1149. if ( is_array( $options['lightboxsettings'] ) ) { 
  1150. foreach ( $options['lightboxsettings'] as $key => $value ) { 
  1151. if ( is_numeric( $key ) ) { 
  1152. $options['lightboxsettings']["{$value}"] = $value; 
  1153. unset( $options['lightboxsettings']["{$key}"] ); 
  1154.  
  1155.  
  1156. extract( $options ); 
  1157.  
  1158. $form_id = $form; 
  1159.  
  1160. $form = RGFormsModel::get_form_meta( $form_id ); 
  1161.  
  1162. if ( empty( $form ) ) { 
  1163. return; 
  1164.  
  1165. $sort_field = empty( $_GET["sort"] ) ? $sort : $_GET["sort"]; 
  1166. $sort_direction = empty( $_GET["dir"] ) ? $dir : $_GET["dir"]; 
  1167. $search_query = ! empty( $_GET["gf_search"] ) ? $_GET["gf_search"] : NULL; 
  1168.  
  1169.  
  1170. $start_date = ! empty( $_GET["start_date"] ) ? $_GET["start_date"] : $start_date; 
  1171. $end_date = ! empty( $_GET["end_date"] ) ? $_GET["end_date"] : $end_date; 
  1172.  
  1173. $page_index = empty( $_GET["pagenum"] ) ? $startpage - 1 : intval( $_GET["pagenum"] ) - 1; 
  1174. $star = ( isset( $_GET["star"] ) && is_numeric( $_GET["star"] ) ) ? intval( $_GET["star"] ) : NULL; 
  1175. $read = ( isset( $_GET["read"] ) && is_numeric( $_GET["read"] ) ) ? intval( $_GET["read"] ) : NULL; 
  1176. $first_item_index = $page_index * $page_size; 
  1177. $link_params = array(); 
  1178. if ( ! empty( $page_index ) ) { 
  1179. $link_params['pagenum'] = $page_index; 
  1180. $formaction = esc_url_raw( remove_query_arg( array( 
  1181. 'gf_search',  
  1182. 'sort',  
  1183. 'dir',  
  1184. 'pagenum',  
  1185. 'edit',  
  1186. ), add_query_arg( $link_params ) ) ); 
  1187. $tableclass .= ! empty( $jstable ) ? sprintf( ' tablesorter tablesorter-%s', apply_filters( 'kws_gf_tablesorter_theme', 'blue', $form ) ) : ''; 
  1188. $title = $form["title"]; 
  1189. $sort_field_meta = RGFormsModel::get_field( $form, $sort_field ); 
  1190. $is_numeric = $sort_field_meta["type"] == "number"; 
  1191.  
  1192. $columns = self::get_grid_columns( $form_id, true ); 
  1193.  
  1194. $approvedcolumn = NULL; 
  1195.  
  1196. if ( ( ! $approved && $approved !== - 1 ) || ( ! empty( $smartapproval ) && $approved === - 1 ) ) { 
  1197. $approvedcolumn = self::get_approved_column( $form ); 
  1198.  
  1199. if ( ! empty( $smartapproval ) && $approved === - 1 && ! empty( $approvedcolumn ) ) { 
  1200. $approved = true; // If there is an approved column, turn on approval 
  1201. } else { 
  1202. $approved = false; // Otherwise, show entries as normal. 
  1203.  
  1204. $entrylinkcolumns = self::get_entrylink_column( $form, $entry ); 
  1205. $adminonlycolumns = self::get_admin_only( $form ); 
  1206.  
  1207. // 
  1208. // Show only a single entry 
  1209. // 
  1210. $detail = self::process_lead_detail( true, $entryback, $showadminonly, $adminonlycolumns, $approvedcolumn, $options, $entryonly ); 
  1211.  
  1212. if ( ! empty( $entry ) && ! empty( $detail ) ) { 
  1213.  
  1214. // Once again, checking to make sure this hasn't been shown already with multiple shortcodes on one page. 
  1215. if ( ! did_action( 'kws_gf_after_directory' ) ) { 
  1216. echo $detail; 
  1217.  
  1218. if ( ! empty( $entryonly ) ) { 
  1219. do_action( 'kws_gf_after_directory', do_action( 'kws_gf_after_directory_form_' . $form_id, $form, compact( "approved", "sort_field", "sort_direction", "search_query", "first_item_index", "page_size", "star", "read", "is_numeric", "start_date", "end_date" ) ) ); 
  1220.  
  1221. $content = ob_get_clean(); // Get the output and clear the buffer 
  1222.  
  1223. // If the form is form #2, two filters are applied: `kws_gf_directory_output_2` and `kws_gf_directory_output` 
  1224. $content = apply_filters( 'kws_gf_directory_output', apply_filters( 'kws_gf_directory_output_' . $form_id, self::html_display_type_filter( $content, $directoryview ) ) ); 
  1225.  
  1226. return $content; 
  1227.  
  1228.  
  1229. // since 3.5 - remove columns of the fields not allowed to be shown 
  1230. $columns = self::remove_hidden_fields( $columns, $adminonlycolumns, $approvedcolumn, false, false, $showadminonly, $form ); 
  1231.  
  1232. // hook for external selection of columns 
  1233. $columns = apply_filters( 'kws_gf_directory_filter_columns', $columns ); 
  1234.  
  1235.  
  1236. //since 3.5 search criteria 
  1237. $show_search_filters = self::get_search_filters( $form ); 
  1238. $show_search_filters = apply_filters( 'kws_gf_directory_search_filters', $show_search_filters, $form ); 
  1239. $search_criteria = array(); 
  1240. foreach ( $show_search_filters as $key ) { 
  1241. if ( ! empty( $_GET[ 'filter_' . $key ] ) ) { 
  1242. $search_criteria[ $key ] = $_GET[ 'filter_' . $key ]; 
  1243.  
  1244.  
  1245. // 
  1246. // Or start to generate the directory 
  1247. // 
  1248. $leads = GFDirectory::get_leads( $form_id, $sort_field, $sort_direction, $search_query, $first_item_index, $page_size, $star, $read, $is_numeric, $start_date, $end_date, 'active', $approvedcolumn, $limituser, $search_criteria ); 
  1249.  
  1250.  
  1251. // Allow lightbox to determine whether showadminonly is valid without passing a query string in URL 
  1252. if ( $entry === true && ! empty( $lightboxsettings['entry'] ) ) { 
  1253. if ( get_site_transient( 'gf_form_' . $form_id . '_post_' . $post->ID . '_showadminonly' ) != $showadminonly ) { 
  1254. set_site_transient( 'gf_form_' . $form_id . '_post_' . $post->ID . '_showadminonly', $showadminonly, HOUR_IN_SECONDS ); 
  1255. } else { 
  1256. delete_site_transient( 'gf_form_' . $form_id . '_post_' . $post->ID . '_showadminonly' ); 
  1257.  
  1258.  
  1259. // Get a list of query args for the pagination links 
  1260. if ( ! empty( $search_query ) ) { 
  1261. $args["gf_search"] = urlencode( $search_query ); 
  1262. if ( ! empty( $sort_field ) ) { 
  1263. $args["sort"] = $sort_field; 
  1264. if ( ! empty( $sort_direction ) ) { 
  1265. $args["dir"] = $sort_direction; 
  1266. if ( ! empty( $star ) ) { 
  1267. $args["star"] = $star; 
  1268.  
  1269. if ( $page_size > 0 ) { 
  1270.  
  1271. // $leads contains all the entries according to request, since 3.5, to allow multisort. 
  1272. if ( apply_filters( 'kws_gf_directory_want_multisort', false ) ) { 
  1273. $lead_count = count( $leads ); 
  1274. $leads = array_slice( $leads, $first_item_index, $page_size ); 
  1275. } else { 
  1276. $lead_count = self::get_lead_count( $form_id, $search_query, $star, $read, $approvedcolumn, $approved, $leads, $start_date, $end_date, $limituser, $search_criteria ); 
  1277.  
  1278.  
  1279.  
  1280. $page_links = array( 
  1281. 'base' => esc_url_raw( @add_query_arg( 'pagenum', '%#%' ) ), // get_permalink().'%_%',  
  1282. 'format' => '&pagenum=%#%',  
  1283. 'add_args' => $args,  
  1284. 'prev_text' => $prev_text,  
  1285. 'next_text' => $next_text,  
  1286. 'total' => ceil( $lead_count / $page_size ),  
  1287. 'current' => $page_index + 1,  
  1288. 'show_all' => $pagelinksshowall,  
  1289. ); 
  1290.  
  1291. $page_links = apply_filters( 'kws_gf_results_pagination', $page_links ); 
  1292.  
  1293. $page_links = paginate_links( $page_links ); 
  1294. } else { 
  1295. // Showing all results 
  1296. $page_links = false; 
  1297. $lead_count = sizeof( $leads ); 
  1298.  
  1299.  
  1300. if ( ! isset( $directory_shown ) ) { 
  1301. $directory_shown = true; 
  1302.  
  1303.  
  1304. ?> 
  1305.  
  1306. <script> 
  1307. <?php if(! empty( $lightboxsettings['images'] ) || ! empty( $lightboxsettings['entry'] )) { ?> 
  1308.  
  1309. var tb_pathToImage = "<?php echo site_url( '/wp-includes/js/thickbox/loadingAnimation.gif' ); ?>"; 
  1310. var tb_closeImage = "<?php echo site_url( '/wp-includes/js/thickbox/tb-close.png' ); ?>"; 
  1311. var tb_height = 600; 
  1312. <?php } ?> 
  1313. function not_empty( variable ) { 
  1314. if ( variable == '' || variable == null || variable == 'undefined' || typeof(variable) == 'undefined' ) { 
  1315. return false; 
  1316. } else { 
  1317. return true; 
  1318.  
  1319. <?php if(! empty( $jstable )) { ?> 
  1320. jQuery( document ).ready( function ( $ ) { 
  1321. $( '.tablesorter' ).each( function () { 
  1322. $( this ).tablesorter(<?php echo apply_filters( 'kws_gf_directory_tablesorter_options', '' ) ?>); 
  1323. } ); 
  1324. } ); 
  1325. <?php } else if(isset( $jssearch ) && $jssearch) { ?> 
  1326. function Search( search, sort_field_id, sort_direction, search_criteria ) { 
  1327. if ( not_empty( search ) ) { 
  1328. var search = "&gf_search=" + encodeURIComponent( search ); 
  1329. } else { 
  1330. var search = ''; 
  1331.  
  1332. var search_filters = ''; 
  1333. if ( not_empty( search_criteria ) ) { 
  1334. $.each( search_criteria, function ( index, value ) { 
  1335. search_filters += "&filter_" + index + "=" + encodeURIComponent( value ); 
  1336. } ); 
  1337.  
  1338. if ( not_empty( sort_field_id ) ) { 
  1339. var sort = "&sort=" + sort_field_id; 
  1340. } else { 
  1341. var sort = ''; 
  1342. if ( not_empty( sort_direction ) ) { 
  1343. var dir = "&dir=" + sort_direction; 
  1344. } else { 
  1345. var dir = ''; 
  1346. var page = '<?php if ( $wp_rewrite->using_permalinks() ) { 
  1347. echo '?'; 
  1348. } else { 
  1349. echo '&'; 
  1350. } ?>page=' +<?php echo isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : '"1"'; ?>; 
  1351. var location = "<?php echo get_permalink( $post->ID ); ?>" + page + search + sort + dir + search_filters; 
  1352. document.location = location; 
  1353. <?php } ?> 
  1354. </script> 
  1355. <?php } ?> 
  1356.  
  1357. <div class="wrap"> 
  1358. <?php if ( $titleshow ) : ?> 
  1359. <h2><?php echo $titleprefix . $title; ?></h2> 
  1360. <?php endif; ?> 
  1361.  
  1362. <?php // --- Render Search Box --- 
  1363.  
  1364. if ( $search || ! empty( $show_search_filters ) ) : ?> 
  1365.  
  1366. <form id="lead_form" method="get" action="<?php echo $formaction; ?>"> 
  1367. <?php 
  1368. //New logic for search criterias (since 3.5) 
  1369.  
  1370. if ( ! empty( $show_search_filters ) ) { 
  1371.  
  1372. foreach ( $show_search_filters as $key ) { 
  1373. $properties = self::get_field_properties( $form, $key ); 
  1374. if ( in_array( $properties['type'], array( 
  1375. 'select',  
  1376. 'checkbox',  
  1377. 'radio',  
  1378. 'post_category',  
  1379. ) ) ) { 
  1380. echo self::render_search_dropdown( $properties['label'], 'filter_' . $properties['id'], $properties['choices'] ); //Label, name attr, choices 
  1381. } else { 
  1382. echo self::render_search_input( $properties['label'], 'filter_' . $properties['id'] ); //label, attr name 
  1383.  
  1384.  
  1385.  
  1386. ?> 
  1387. <p class="search-box"> 
  1388. <?php if ( $search ) : ?> 
  1389. <label class="hidden" 
  1390. for="lead_search"><?php esc_html_e( "Search Entries:", "gravity-forms-addons" ); ?></label> 
  1391. <input type="text" name="gf_search" id="lead_search" 
  1392. value="<?php echo $search_query ?>"<?php if ( $searchtabindex ) { 
  1393. echo ' tabindex="' . intval( $searchtabindex ) . '"'; 
  1394. } ?> /> 
  1395. <?php endif; ?> 
  1396. <?php 
  1397. // If not using permalinks, let's make the form work! 
  1398. echo ! empty( $_GET['p'] ) ? '<input name="p" type="hidden" value="' . esc_html( $_GET['p'] ) . '" />' : ''; 
  1399. echo ! empty( $_GET['page_id'] ) ? '<input name="page_id" type="hidden" value="' . esc_html( $_GET['page_id'] ) . '" />' : ''; 
  1400. ?> 
  1401. <input type="submit" class="button" id="lead_search_button" 
  1402. value="<?php esc_attr_e( "Search", "gravity-forms-addons" ) ?>"<?php if ( $searchtabindex ) { 
  1403. echo ' tabindex="' . intval( $searchtabindex ++ ) . '"'; 
  1404. } ?> /> 
  1405. </p> 
  1406. </form> 
  1407.  
  1408. <?php endif; 
  1409.  
  1410.  
  1411. //Displaying paging links if appropriate 
  1412.  
  1413. if ( $lead_count > 0 && $showcount || $page_links ) { 
  1414. if ( $lead_count == 0 ) { 
  1415. $first_item_index --; 
  1416. ?> 
  1417. <div class="tablenav"> 
  1418. <div class="tablenav-pages"> 
  1419. <?php if ( $showcount ) { 
  1420. if ( ( $first_item_index + $page_size ) > $lead_count || $page_size <= 0 ) { 
  1421. $second_part = $lead_count; 
  1422. } else { 
  1423. $second_part = $first_item_index + $page_size; 
  1424. ?> 
  1425. <span 
  1426. class="displaying-num"><?php printf( __( "Displaying %d - %d of %d", "gravity-forms-addons" ), $first_item_index + 1, $second_part, $lead_count ) ?></span> 
  1427. <?php } 
  1428. if ( $page_links ) { 
  1429. echo $page_links; 
  1430. } ?> 
  1431. </div> 
  1432. <div class="clear"></div> 
  1433. </div> 
  1434. <?php 
  1435.  
  1436. do_action( 'kws_gf_before_directory_after_nav', do_action( 'kws_gf_before_directory_after_nav_form_' . $form_id, $form, $leads, compact( "approved", "sort_field", "sort_direction", "search_query", "first_item_index", "page_size", "star", "read", "is_numeric", "start_date", "end_date" ) ) ); 
  1437. ?> 
  1438.  
  1439. <table class="<?php echo $tableclass; ?>" cellspacing="0"<?php if ( ! empty( $tablewidth ) ) { 
  1440. echo ' width="' . $tablewidth . '"'; 
  1441. echo $tablestyle ? ' style="' . $tablestyle . '"' : ''; ?>> 
  1442. <?php if ( $thead ) { ?> 
  1443. <thead> 
  1444. <tr> 
  1445. <?php 
  1446.  
  1447. $addressesExist = false; 
  1448. foreach ( $columns as $field_id => $field_info ) { 
  1449. $dir = $field_id == 0 ? "DESC" : "ASC"; //default every field so ascending sorting except date_created (id=0) 
  1450. if ( $field_id == $sort_field ) { //reverting direction if clicking on the currently sorted field 
  1451. $dir = $sort_direction == "ASC" ? "DESC" : "ASC"; 
  1452. if ( is_array( $adminonlycolumns ) && ! in_array( $field_id, $adminonlycolumns ) || ( is_array( $adminonlycolumns ) && in_array( $field_id, $adminonlycolumns ) && $showadminonly ) || ! $showadminonly ) { 
  1453. if ( $field_info['type'] == 'address' && $appendaddress && $hideaddresspieces ) { 
  1454. $addressesExist = true; 
  1455. continue; 
  1456. ?> 
  1457. <?php 
  1458. $_showlink = false; 
  1459. if ( isset( $jssearch ) && $jssearch && ! isset( $jstable ) ) { ?> 
  1460. <th scope="col" id="gf-col-<?php echo $form_id . '-' . $field_id ?>" class="manage-column" onclick="Search('<?php echo $search_query ?>', '<?php echo $field_id ?>', '<?php echo $dir ?>', '' );" style="cursor:pointer;"><?php 
  1461. } elseif ( isset( $jstable ) && $jstable || $field_info['type'] === 'id' ) { ?> 
  1462. <th scope="col" id="gf-col-<?php echo $form_id . '-' . $field_id ?>" class="manage-column"> 
  1463. <?php } else { 
  1464. $_showlink = true; 
  1465. ?> 
  1466. <th scope="col" id="gf-col-<?php echo $form_id . '-' . $field_id ?>" class="manage-column"> 
  1467. <a href="<?php 
  1468. $searchpage = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1; 
  1469. $new_query_args = array( 
  1470. 'gf_search' => $search_query,  
  1471. 'sort' => $field_id,  
  1472. 'dir' => $dir,  
  1473. 'pagenum' => $searchpage,  
  1474. ); 
  1475. foreach ( $search_criteria as $key => $value ) { 
  1476. $new_query_args[ 'filter_' . $key ] = $value; 
  1477. echo add_query_arg( $new_query_args, get_permalink( $post->ID ) ); 
  1478. ?>"><?php 
  1479. if ( $field_info['type'] == 'id' && $entry ) { 
  1480. $label = $entryth; 
  1481. } else { 
  1482. $label = $field_info["label"]; 
  1483.  
  1484. $label = apply_filters( 'kws_gf_directory_th', apply_filters( 'kws_gf_directory_th_' . $field_id, apply_filters( 'kws_gf_directory_th_' . sanitize_title( $label ), $label ) ) ); 
  1485. echo esc_html( $label ); 
  1486.  
  1487. if ( $_showlink ) { ?></a><?php } ?> 
  1488. </th> 
  1489. <?php 
  1490.  
  1491. if ( $appendaddress && $addressesExist ) { 
  1492. ?> 
  1493. <th scope="col" id="gf-col-<?php echo $form_id . '-' . $field_id ?>" class="manage-column" 
  1494. onclick="Search('<?php echo $search_query ?>', '<?php echo $field_id ?>', '<?php echo $dir ?>');" 
  1495. style="cursor:pointer;"><?php 
  1496. $label = apply_filters( 'kws_gf_directory_th', apply_filters( 'kws_gf_directory_th_address', 'Address' ) ); 
  1497. echo esc_html( $label ) 
  1498.  
  1499. ?></th> 
  1500. <?php 
  1501. ?> 
  1502. </tr> 
  1503. </thead> 
  1504. <?php } ?> 
  1505. <tbody class="list:user user-list"> 
  1506. <?php 
  1507. include( plugin_dir_path( __FILE__ ) . "/template-row.php" ); 
  1508. ?> 
  1509. </tbody> 
  1510. <?php if ( $tfoot ) { 
  1511. if ( isset( $jssearch ) && $jssearch && ! isset( $jstable ) ) { 
  1512. $th = '<th scope="col" id="gf-col-' . $form_id . '-' . $field_id . '" class="manage-column" onclick="Search(\'' . $search_query . '\', \'' . $field_id . '\', \'' . $dir . '\');" style="cursor:pointer;">'; 
  1513. } else { 
  1514. $th = '<th scope="col" id="gf-col-' . $form_id . '-' . $field_id . '" class="manage-column">'; 
  1515. ?> 
  1516. <tfoot> 
  1517. <tr> 
  1518. <?php 
  1519. $addressesExist = false; 
  1520. foreach ( $columns as $field_id => $field_info ) { 
  1521. $dir = $field_id == 0 ? "DESC" : "ASC"; //default every field so ascending sorting except date_created (id=0) 
  1522. if ( $field_id == $sort_field ) { //reverting direction if clicking on the currently sorted field 
  1523. $dir = $sort_direction == "ASC" ? "DESC" : "ASC"; 
  1524. if ( is_array( $adminonlycolumns ) && ! in_array( $field_id, $adminonlycolumns ) || ( is_array( $adminonlycolumns ) && in_array( $field_id, $adminonlycolumns ) && $showadminonly ) || ! $showadminonly ) { 
  1525. if ( $field_info['type'] == 'address' && $appendaddress && $hideaddresspieces ) { 
  1526. $addressesExist = true; 
  1527. continue; 
  1528.  
  1529. echo $th; 
  1530.  
  1531. if ( $field_info['type'] == 'id' && $entry ) { 
  1532. $label = $entryth; 
  1533. } else { 
  1534. $label = $field_info["label"]; 
  1535.  
  1536. $label = apply_filters( 'kws_gf_directory_th', apply_filters( 'kws_gf_directory_th_' . $field_id, apply_filters( 'kws_gf_directory_th_' . sanitize_title( $label ), $label ) ) ); 
  1537. echo esc_html( $label ) 
  1538.  
  1539. ?></th> 
  1540. <?php 
  1541. if ( $appendaddress && $addressesExist ) { 
  1542. ?> 
  1543. <th scope="col" id="gf-col-<?php echo $form_id . '-' . $field_id ?>" class="manage-column" 
  1544. onclick="Search('<?php echo $search_query ?>', '<?php echo $field_id ?>', '<?php echo $dir ?>');" 
  1545. style="cursor:pointer;"><?php 
  1546. $label = apply_filters( 'kws_gf_directory_th', apply_filters( 'kws_gf_directory_th_address', 'Address' ) ); 
  1547. echo esc_html( $label ) 
  1548.  
  1549. ?></th> 
  1550. <?php 
  1551. ?> 
  1552. </tr> 
  1553. <?php if ( ! empty( $credit ) ) { 
  1554. self::get_credit_link( sizeof( $columns ), $options ); 
  1555. } ?> 
  1556. </tfoot> 
  1557. <?php } ?> 
  1558. </table> 
  1559. <?php 
  1560.  
  1561. do_action( 'kws_gf_after_directory_before_nav', do_action( 'kws_gf_after_directory_before_nav_form_' . $form_id, $form, $leads, compact( "approved", "sort_field", "sort_direction", "search_query", "first_item_index", "page_size", "star", "read", "is_numeric", "start_date", "end_date" ) ) ); 
  1562.  
  1563.  
  1564. //Displaying paging links if appropriate 
  1565.  
  1566. if ( $lead_count > 0 && $showcount || $page_links ) { 
  1567. if ( $lead_count == 0 ) { 
  1568. $first_item_index --; 
  1569. ?> 
  1570. <div class="tablenav"> 
  1571. <div class="tablenav-pages"> 
  1572. <?php if ( $showcount ) { 
  1573. if ( ( $first_item_index + $page_size ) > $lead_count || $page_size <= 0 ) { 
  1574. $second_part = $lead_count; 
  1575. } else { 
  1576. $second_part = $first_item_index + $page_size; 
  1577. ?> 
  1578. <span 
  1579. class="displaying-num"><?php printf( __( "Displaying %d - %d of %d", "gravity-forms-addons" ), $first_item_index + 1, $second_part, $lead_count ) ?></span> 
  1580. <?php } 
  1581. if ( $page_links ) { 
  1582. echo $page_links; 
  1583. } ?> 
  1584. </div> 
  1585. <div class="clear"></div> 
  1586. </div> 
  1587. <?php 
  1588.  
  1589. ?> 
  1590. </div> 
  1591. <?php 
  1592. if ( empty( $credit ) ) { 
  1593. echo "\n" . '<!-- Directory generated by Gravity Forms Directory & Addons : http://wordpress.org/extend/plugins/gravity-forms-addons/ -->' . "\n"; 
  1594.  
  1595. do_action( 'kws_gf_after_directory', do_action( 'kws_gf_after_directory_form_' . $form_id, $form, $leads, compact( "approved", "sort_field", "sort_direction", "search_query", "first_item_index", "page_size", "star", "read", "is_numeric", "start_date", "end_date" ) ) ); 
  1596.  
  1597. $content = ob_get_contents(); // Get the output 
  1598. ob_end_clean(); // Clear the cache 
  1599.  
  1600. // If the form is form #2, two filters are applied: `kws_gf_directory_output_2` and `kws_gf_directory_output` 
  1601. $content = apply_filters( 'kws_gf_directory_output', apply_filters( 'kws_gf_directory_output_' . $form_id, self::html_display_type_filter( $content, $directoryview ) ) ); 
  1602.  
  1603. return $content; // Return it! 
  1604.  
  1605. /** 
  1606. * Render image link HTML 
  1607. * 
  1608. * @since 3.7 
  1609. * 
  1610. * @param [type] $url [description] 
  1611. * @param string $title [description] 
  1612. * @param string $caption [description] 
  1613. * @param string $description [description] 
  1614. * 
  1615. * @return [type] [description] 
  1616. */ 
  1617. static private function render_image_link( $url, $lead, $options, $title = '', $caption = '', $description = '' ) { 
  1618.  
  1619. extract( $options ); 
  1620.  
  1621. $target = ( $linknewwindow && empty( $lightboxsettings['images'] ) ) ? ' target="_blank"' : ''; 
  1622.  
  1623. $size = false; 
  1624. if ( ! empty( $options['getimagesize'] ) ) { 
  1625. $size = @getimagesize( $url ); 
  1626.  
  1627. //displaying thumbnail (if file is an image) or an icon based on the extension 
  1628. $icon = GFEntryList::get_icon_url( $url ); 
  1629. if ( ! preg_match( '/icon\_image\.gif/ism', $icon ) ) { 
  1630. $src = $icon; 
  1631. if ( ! empty( $size ) ) { 
  1632. $img = "<img src='$src' {$size[3]}/>"; 
  1633. } else { 
  1634. $img = "<img src='$src' />"; 
  1635. } else { // No thickbox for non-images please 
  1636. switch ( strtolower( trim( $options['postimage'] ) ) ) { 
  1637. case 'image': 
  1638. $src = $url; 
  1639. break; 
  1640. case 'icon': 
  1641. default: 
  1642. $src = $icon; 
  1643. break; 
  1644. $img = array( 
  1645. 'src' => $src,  
  1646. 'size' => $size,  
  1647. 'title' => $title,  
  1648. 'caption' => $caption,  
  1649. 'description' => $description,  
  1650. 'url' => esc_url_raw( $url ),  
  1651. 'code' => isset( $size[3] ) ? "<img src='$src' {$size[3]} />" : "<img src='$src' />",  
  1652. ); 
  1653. $img = apply_filters( 'kws_gf_directory_lead_image', apply_filters( 'kws_gf_directory_lead_image_' . $options['postimage'], apply_filters( 'kws_gf_directory_lead_image_' . $lead['id'], $img ) ) ); 
  1654.  
  1655. $lightboxclass = ''; 
  1656.  
  1657. if ( ! empty( $lightboxsettings['images'] ) && self::is_image_file( $url ) ) { 
  1658. if ( wp_script_is( 'colorbox', 'registered' ) ) { 
  1659. $lightboxclass = ' class="colorbox lightbox"'; 
  1660. } else if ( wp_script_is( 'thickbox', 'registered' ) ) { 
  1661. $lightboxclass = ' class="thickbox lightbox"'; 
  1662.  
  1663. if ( in_array( 'images', $lightboxsettings ) || ! empty( $lightboxsettings['images'] ) ) { 
  1664. $lightboxclass .= ' rel="directory_all directory_images"'; 
  1665.  
  1666. $value = "<a href='{$url}'{$target}{$lightboxclass}>{$img['code']}</a>"; 
  1667.  
  1668. $value = apply_filters( 'kws_gf_directory_render_image_link', $value, $url, $lead, $options, $title, $caption, $description ); 
  1669.  
  1670. return $value; 
  1671.  
  1672. /** 
  1673. * Verify that the src URL matches image patterns. 
  1674. * 
  1675. * 
  1676. * @return boolean True: matches pattern; False: does not match pattern. 
  1677. */ 
  1678. public static function is_image_file( $src ) { 
  1679.  
  1680. $info = pathinfo( $src ); 
  1681.  
  1682. $image_exts = apply_filters( 'kws_gf_directory_image_extensions', array( 
  1683. 'jpg',  
  1684. 'jpeg',  
  1685. 'jpe',  
  1686. 'gif',  
  1687. 'png',  
  1688. 'bmp',  
  1689. 'tif',  
  1690. 'tiff',  
  1691. 'ico',  
  1692. ) ); 
  1693.  
  1694. return isset( $info['extension'] ) && in_array( strtolower( $info['extension'] ), $image_exts ); 
  1695.  
  1696. /** 
  1697. * render_search_dropdown function. 
  1698. * 
  1699. * @since 3.5 
  1700. * @access private 
  1701. * @static 
  1702. * 
  1703. * @param string $label (default: '') search field label 
  1704. * @param string $name (default: '') input name attribute 
  1705. * @param array $choices 
  1706. * 
  1707. * @return field dropdown html 
  1708. */ 
  1709. static private function render_search_dropdown( $label = '', $name = '', $choices ) { 
  1710.  
  1711. if ( empty( $choices ) || ! is_array( $choices ) || empty( $name ) ) { 
  1712. return ''; 
  1713.  
  1714. $current_value = isset( $_GET[ $name ] ) ? $_GET[ $name ] : ''; 
  1715.  
  1716. $output = '<div class="search-box">'; 
  1717. $output .= '<label for=search-box-' . $name . '>' . $label . '</label>'; 
  1718. $output .= '<select name="' . $name . '" id="search-box-' . $name . '">'; 
  1719. $output .= '<option value="" ' . selected( '', $current_value, false ) . '>---</option>'; 
  1720. foreach ( $choices as $choice ) { 
  1721. $output .= '<option value="' . $choice['value'] . '" ' . selected( $choice['value'], $current_value, false ) . '>' . $choice['text'] . '</option>'; 
  1722. $output .= '</select>'; 
  1723. $output .= '</div>'; 
  1724.  
  1725. return $output; 
  1726.  
  1727.  
  1728.  
  1729. /** 
  1730. * render_search_input function. 
  1731. * 
  1732. * @since 3.5 
  1733. * @access private 
  1734. * @static 
  1735. * 
  1736. * @param string $label (default: '') search field label 
  1737. * @param string $name (default: '') input name attribute 
  1738. * 
  1739. * @return field input html 
  1740. */ 
  1741. static private function render_search_input( $label = '', $name = '' ) { 
  1742.  
  1743. if ( empty( $name ) ) { 
  1744. return ''; 
  1745.  
  1746. $current_value = isset( $_GET[ $name ] ) ? $_GET[ $name ] : ''; 
  1747.  
  1748. $output = '<div class="search-box">'; 
  1749. $output .= '<label for=search-box-' . $name . '>' . $label . '</label>'; 
  1750. $output .= '<input type="text" name="' . $name . '" id="search-box-' . $name . '" value="' . $current_value . '">'; 
  1751. $output .= '</div>'; 
  1752.  
  1753. return $output; 
  1754.  
  1755.  
  1756.  
  1757. static public function get_credit_link( $columns = 1, $options = array() ) { 
  1758. global $post;// prevents calling before <HTML> 
  1759. if ( empty( $post ) || is_admin() ) { 
  1760. return; 
  1761.  
  1762. $settings = self::get_settings(); 
  1763.  
  1764. // Only show credit link if the user has saved settings; 
  1765. // this prevents existing directories adding a link without user action. 
  1766. if ( isset( $settings['version'] ) ) { 
  1767. echo "<tr><th colspan='{$columns}'>" . self::attr( $options ) . "</th></tr>"; 
  1768.  
  1769. static public function get_version() { 
  1770. return self::$version; 
  1771.  
  1772. static public function return_7776000() { 
  1773. return 7776000; // extend the cache to 90 days 
  1774.  
  1775. static public function attr( $options, $default = '<span class="kws_gf_credit" style="font-weight:normal; text-align:center; display:block; margin:0 auto;">Powered by <a href="http://katz.co/gravity-forms-addons/">Gravity Forms Directory</a></span>' ) { 
  1776. include_once( ABSPATH . WPINC . '/feed.php' ); 
  1777. add_filter( 'wp_feed_cache_transient_lifetime', array( 'GFDirectory', 'return_7776000' ) ); 
  1778. $rss = fetch_feed( add_query_arg( array( 
  1779. 'site' => htmlentities( substr( get_bloginfo( 'url' ), is_ssl() ? 8 : 7 ) ),  
  1780. 'from' => 'kws_gf_addons',  
  1781. 'version' => self::$version,  
  1782. 'credit' => ! empty( $options['credit'] ),  
  1783. ), 'http://www.katzwebservices.com/development/attribution.php' ) ); 
  1784. remove_filter( 'wp_feed_cache_transient_lifetime', array( 'GFDirectory', 'return_7776000' ) ); 
  1785. if ( $rss && ! is_wp_error( $rss ) ) { 
  1786. // We want to strip all tags except for 'style', 'id', and 'class' so that the return value is always safe for the site. 
  1787. $strip = array( 
  1788. 'bgsound',  
  1789. 'expr',  
  1790. 'onclick',  
  1791. 'onerror',  
  1792. 'onfinish',  
  1793. 'onmouseover',  
  1794. 'onmouseout',  
  1795. 'onfocus',  
  1796. 'onblur',  
  1797. 'lowsrc',  
  1798. 'dynsrc',  
  1799. ); 
  1800. $rss->strip_attributes( $strip ); 
  1801. $rss_items = $rss->get_items( 0, 1 ); 
  1802. foreach ( $rss_items as $item ) { 
  1803. return str_replace( array( "\n", "\r" ), ' ', $item->get_description() ); 
  1804.  
  1805. return $default; 
  1806.  
  1807.  
  1808. static public function add_lead_approved_hidden_input( $value, $lead, $field = '' ) { 
  1809. global $_gform_directory_processed_meta, $_gform_directory_approvedcolumn; 
  1810.  
  1811. if ( ! in_array( $lead['id'], $_gform_directory_processed_meta ) ) { 
  1812. $_gform_directory_processed_meta[] = $lead['id']; 
  1813. if ( empty( $_gform_directory_approvedcolumn ) ) { 
  1814. $forms = RGFormsModel::get_forms( NULL, "title" ); 
  1815. $_gform_directory_approvedcolumn = self::globals_get_approved_column( $forms[0]->id ); 
  1816. if ( self::check_approval( $lead, $_gform_directory_approvedcolumn ) ) { 
  1817. echo '<span style="display:none;"><input type="hidden" class="lead_approved" id="lead_approved_' . $lead['id'] . '" value="true" /></span>'; 
  1818.  
  1819. return $value; 
  1820.  
  1821.  
  1822. static public function globals_get_approved_column( $formID = 0 ) { 
  1823. global $_gform_directory_processed_meta, $_gform_directory_approvedcolumn, $_gform_directory_activeform; 
  1824.  
  1825. $_gform_directory_processed_meta = array(); 
  1826.  
  1827. if ( empty( $formID ) ) { 
  1828. $formID = RGForms::get( "id" ); 
  1829.  
  1830. if ( empty( $formID ) ) { 
  1831. $forms = RGFormsModel::get_forms( NULL, "title" ); 
  1832. $formID = $forms[0]->id; 
  1833.  
  1834. if ( ! empty( $formID ) ) { 
  1835. $_gform_directory_activeform = RGFormsModel::get_form_meta( $formID ); 
  1836. } else if ( isset( $_GET['id'] ) ) { 
  1837. $_gform_directory_activeform = RGFormsModel::get_form_meta( $_GET['id'] ); 
  1838.  
  1839. $_gform_directory_approvedcolumn = self::get_approved_column( $_gform_directory_activeform ); 
  1840.  
  1841. return $_gform_directory_approvedcolumn; 
  1842.  
  1843. static public function get_approved_column( $form ) { 
  1844. if ( ! is_array( $form ) ) { 
  1845. return false; 
  1846.  
  1847. foreach ( @$form['fields'] as $key => $col ) { 
  1848. if ( isset( $col['inputs'] ) && is_array( $col['inputs'] ) ) { 
  1849. foreach ( $col['inputs'] as $key2 => $input ) { 
  1850. if ( strtolower( $input['label'] ) == 'approved' && $col['type'] == 'checkbox' && ! empty( $col['adminOnly'] ) ) { 
  1851. return $input['id']; 
  1852.  
  1853. foreach ( @$form['fields'] as $key => $col ) { 
  1854. if ( isset( $col['label'] ) && strtolower( $col['label'] ) == 'approved' && $col['type'] == 'checkbox' ) { 
  1855. if ( isset( $col['inputs'][0]['id'] ) ) { 
  1856. return $key; 
  1857.  
  1858. return NULL; 
  1859.  
  1860.  
  1861. static public function directory_update_approved_hook() { 
  1862. global $_gform_directory_approvedcolumn; 
  1863. check_ajax_referer( 'rg_update_approved', 'rg_update_approved' ); 
  1864. if ( ! empty( $_POST["lead_id"] ) ) { 
  1865. $_gform_directory_approvedcolumn = empty( $_gform_directory_approvedcolumn ) ? self::globals_get_approved_column( $_POST['form_id'] ) : $_gform_directory_approvedcolumn; 
  1866. self::directory_update_approved( (int) $_POST["lead_id"], $_POST["approved"], (int) $_POST['form_id'], $_gform_directory_approvedcolumn ); 
  1867.  
  1868. static public function settings_link( $links, $file ) { 
  1869. static $this_plugin; 
  1870. if ( ! $this_plugin ) { 
  1871. $this_plugin = plugin_basename( __FILE__ ); 
  1872. if ( $file == $this_plugin ) { 
  1873. $settings_link = '<a href="' . admin_url( 'admin.php?page=gf_settings&addon=Directory+%26+Addons' ) . '">' . __( 'Settings', 'gravity-forms-addons' ) . '</a>'; 
  1874. array_unshift( $links, $settings_link ); // before other links 
  1875.  
  1876. return $links; 
  1877.  
  1878. //Returns true if the current page is an Feed pages. Returns false if not 
  1879. private static function is_directory_page() { 
  1880. if ( empty( $_GET["pagenum"] ) ) { 
  1881. return false; 
  1882. $current_page = trim( strtolower( $_GET["pagenum"] ) ); 
  1883. $directory_pages = array( "gf_directory" ); 
  1884.  
  1885. return in_array( $current_page, $directory_pages ); 
  1886.  
  1887. static public function get_settings() { 
  1888. return get_option( "gf_addons_settings", array( 
  1889. "directory" => true,  
  1890. "directory_defaults" => array(),  
  1891. "referrer" => false,  
  1892. "modify_admin" => array( 
  1893. 'expand' => true,  
  1894. 'toggle' => true,  
  1895. 'edit' => true,  
  1896. 'ids' => true,  
  1897. ),  
  1898. "saved" => false,  
  1899. "version" => self::$version,  
  1900. ); 
  1901.  
  1902. public static function disable_directory() { 
  1903. delete_option( "gf_directory_oid" ); 
  1904.  
  1905. public static function uninstall() { 
  1906.  
  1907. if ( ! GFDirectory::has_access( "gravityforms_directory_uninstall" ) ) { 
  1908. ( __( "You don't have adequate permission to uninstall Directory Add-On.", "gravity-forms-addons" ) ); 
  1909.  
  1910. //removing options 
  1911. delete_option( "gf_addons_settings" ); 
  1912.  
  1913. //Deactivating plugin 
  1914. $plugin = "gravity-forms-addons/gravity-forms-addons.php"; 
  1915. deactivate_plugins( $plugin ); 
  1916. update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 
  1917.  
  1918. private static function is_gravityforms_supported() { 
  1919. if ( class_exists( "GFCommon" ) ) { 
  1920. $is_correct_version = version_compare( GFCommon::$version, self::$min_gravityforms_version, ">=" ); 
  1921.  
  1922. return $is_correct_version; 
  1923. } else { 
  1924. return false; 
  1925.  
  1926. protected static function get_has_access( $required_permission ) { 
  1927. $has_members_plugin = function_exists( 'members_get_capabilities' ); 
  1928. $has_access = $has_members_plugin ? current_user_can( $required_permission ) : current_user_can( "level_7" ); 
  1929. if ( $has_access ) { 
  1930. return $has_members_plugin ? $required_permission : "level_7"; 
  1931. } else { 
  1932. return false; 
  1933.  
  1934. public static function has_access( $required_permission ) { 
  1935. return self::get_has_access( $required_permission ); 
  1936.  
  1937. //Returns the url of the plugin's root folder 
  1938. static public function get_base_url() { 
  1939. return plugins_url( NULL, __FILE__ ); 
  1940.  
  1941.  
  1942. /** 
  1943. * get_search_filters function. 
  1944. * 
  1945. * @since 3.5 
  1946. * @access public 
  1947. * @static 
  1948. * 
  1949. * @param mixed $form 
  1950. * 
  1951. * @return array search fields ids 
  1952. */ 
  1953. public static function get_search_filters( $form ) { 
  1954. if ( empty( $form['fields'] ) ) { 
  1955. return array(); 
  1956.  
  1957. $search_fields = array(); 
  1958.  
  1959. foreach ( $form['fields'] as $field ) { 
  1960. if ( ! empty( $field['isSearchFilter'] ) ) { 
  1961. $search_fields[] = $field['id']; 
  1962.  
  1963. return $search_fields; 
  1964.  
  1965. /** 
  1966. * get_leads function. 
  1967. * 
  1968. * @access public 
  1969. * @static 
  1970. * 
  1971. * @param int $form_id 
  1972. * @param int $sort_field_number (default: 0) 
  1973. * @param string $sort_direction (default: 'DESC') 
  1974. * @param string $search (default: '') 
  1975. * @param int $offset (default: 0) 
  1976. * @param int $page_size (default: 30) 
  1977. * @param mixed $star (default: null) 
  1978. * @param mixed $read (default: null) 
  1979. * @param bool $is_numeric_sort (default: false) 
  1980. * @param mixed $start_date (default: null) 
  1981. * @param mixed $end_date (default: null) 
  1982. * @param string $status (default: 'active') 
  1983. * @param mixed $approvedcolumn (default: null) 
  1984. * @param bool $limituser (default: false) 
  1985. * @param array $search_criterias , since 3.5 
  1986. * 
  1987. * @return array Leads results 
  1988. */ 
  1989. public static function get_leads( $form_id, $sort_field_number = 0, $sort_direction = 'DESC', $search = '', $offset = 0, $page_size = 30, $star = NULL, $read = NULL, $is_numeric_sort = false, $start_date = NULL, $end_date = NULL, $status = 'active', $approvedcolumn = NULL, $limituser = false, $search_criterias ) { 
  1990.  
  1991. global $wpdb; 
  1992.  
  1993. if ( $sort_field_number == 0 ) { 
  1994. $sort_field_number = "date_created"; 
  1995.  
  1996. //since 3.5 
  1997. if ( empty( $search_criterias ) ) { 
  1998. $search_criterias = array(); 
  1999.  
  2000. // Retrieve the leads based on whether it's sorted or not. 
  2001. if ( is_numeric( $sort_field_number ) ) { 
  2002. $sql = self::sort_by_custom_field_query( $form_id, $sort_field_number, $sort_direction, $search, $search_criterias, $offset, $page_size, $star, $read, $is_numeric_sort, $status, $approvedcolumn, $limituser ); 
  2003. } else { 
  2004. $sql = self::sort_by_default_field_query( $form_id, $sort_field_number, $sort_direction, $search, $search_criterias, $offset, $page_size, $star, $read, $is_numeric_sort, $start_date, $end_date, $status, $approvedcolumn, $limituser ); 
  2005.  
  2006. //initializing rownum 
  2007. $wpdb->query( "select @rownum:=0" ); 
  2008.  
  2009. //getting results 
  2010.  
  2011. $results = $wpdb->get_results( $sql ); 
  2012.  
  2013.  
  2014. $return = ''; 
  2015. if ( function_exists( 'gform_get_meta' ) ) { 
  2016. $return = RGFormsModel::build_lead_array( $results ); // This is a private function until 1.6 
  2017.  
  2018. // Used by at least the show_only_user_entries() method 
  2019. $return = apply_filters( 'kws_gf_directory_lead_filter', $return, compact( "approved", "sort_field_number", "sort_direction", "search_query", "search_criterias", "first_item_index", "page_size", "star", "read", "is_numeric", "start_date", "end_date", "status", "approvedcolumn", "limituser" ) ); 
  2020.  
  2021. return $return; 
  2022.  
  2023. static function is_current_user( $lead = array() ) { 
  2024. global $current_user; 
  2025. get_currentuserinfo(); 
  2026.  
  2027. return ( (int) $current_user->ID === (int) $lead["created_by"] ); 
  2028.  
  2029. static function show_only_user_entries( $leads = array(), $settings = array() ) { 
  2030. if ( empty( $settings['limituser'] ) ) { 
  2031. return $leads; 
  2032.  
  2033. return array_filter( $leads, array( 'GFDirectory', 'is_current_user' ) ); 
  2034.  
  2035.  
  2036. /** 
  2037. * sort_by_custom_field_query function. 
  2038. * 
  2039. * A copy of the Gravity Forms method, but adding $approvedcolumns and $limituser args 
  2040. * 
  2041. * @access private 
  2042. * @static 
  2043. * 
  2044. * @param mixed $form_id 
  2045. * @param int $sort_field_number (default: 0) 
  2046. * @param string $sort_direction (default: 'DESC') 
  2047. * @param string $search (default: '') 
  2048. * @param array $search_criterias , since 3.5 
  2049. * @param int $offset (default: 0) 
  2050. * @param int $page_size (default: 30) 
  2051. * @param mixed $star (default: null) 
  2052. * @param mixed $read (default: null) 
  2053. * @param bool $is_numeric_sort (default: false) 
  2054. * @param string $status (default: 'active') 
  2055. * @param mixed $approvedcolumn (default: null) 
  2056. * @param bool $limituser (default: false) 
  2057. * 
  2058. * @return void 
  2059. */ 
  2060. private static function sort_by_custom_field_query( $form_id, $sort_field_number = 0, $sort_direction = 'DESC', $search = '', $search_criterias, $offset = 0, $page_size = 30, $star = NULL, $read = NULL, $is_numeric_sort = false, $status = 'active', $approvedcolumn = NULL, $limituser = false ) { 
  2061. global $wpdb, $current_user; 
  2062. if ( ! is_numeric( $form_id ) || ! is_numeric( $sort_field_number ) || ! is_numeric( $offset ) || ! is_numeric( $page_size ) ) { 
  2063. return ""; 
  2064.  
  2065. $lead_detail_table_name = RGFormsModel::get_lead_details_table_name(); 
  2066. $lead_table_name = RGFormsModel::get_lead_table_name(); 
  2067.  
  2068. $orderby = $is_numeric_sort ? "ORDER BY query, (value+0) $sort_direction" : "ORDER BY query, value $sort_direction"; 
  2069.  
  2070. //$search = empty($search) ? "" : "WHERE d.value LIKE '%$search%' "; 
  2071. $search_term = "%$search%"; 
  2072. $search_filter = empty( $search ) ? "" : $wpdb->prepare( "WHERE d.value LIKE %s", $search_term ); 
  2073.  
  2074. //starred clause 
  2075. $where = empty( $search ) ? "WHERE" : "AND"; 
  2076. $search_filter .= $star !== NULL && $status == 'active' ? $wpdb->prepare( "$where is_starred=%d AND status='active' ", $star ) : ""; 
  2077.  
  2078. //read clause 
  2079. $where = empty( $search ) ? "WHERE" : "AND"; 
  2080. $search_filter .= $read !== NULL && $status == 'active' ? $wpdb->prepare( "$where is_read=%d AND status='active' ", $read ) : ""; 
  2081.  
  2082. //status clause 
  2083. if ( function_exists( 'gform_get_meta' ) ) { 
  2084. $where = empty( $search ) ? "WHERE" : "AND"; 
  2085. $search_filter .= $wpdb->prepare( "$where status=%s ", $status ); 
  2086.  
  2087. // new search criterias since 3.5 
  2088. $in_search_criteria = ''; 
  2089. if ( ! empty( $search_criterias ) ) { 
  2090. foreach ( $search_criterias as $field_id => $value ) { 
  2091. $value = "%$value%"; 
  2092. $in_search_criteria .= $wpdb->prepare( " l.id IN (SELECT lead_id from $lead_detail_table_name WHERE field_number = %s AND value LIKE %s) AND ", $field_id, $value ); 
  2093. $where = empty( $search_filter ) ? "WHERE " : "AND "; 
  2094. $in_search_criteria = ( ! empty( $in_search_criteria ) ) ? $where . substr( $in_search_criteria, 0, - 4 ) : ''; // to add where/and and remove the last AND 
  2095.  
  2096.  
  2097. if ( $limituser ) { 
  2098. get_currentuserinfo(); 
  2099. if ( (int) $current_user->ID !== 0 || ( $current_user->ID === 0 && apply_filters( 'kws_gf_show_entries_if_not_logged_in', apply_filters( 'kws_gf_treat_not_logged_in_as_user', true ) ) ) ) { 
  2100. $where = empty( $search_filter ) ? "WHERE" : "AND"; 
  2101. if ( (int) $current_user->ID === 0 ) { 
  2102. $search_filter .= $wpdb->prepare( "$where (created_by IS NULL OR created_by=%d)", $current_user->ID ); 
  2103. } else { 
  2104. $search_filter .= $wpdb->prepare( "$where l.created_by=%d ", $current_user->ID ); 
  2105. } else { 
  2106. return false; 
  2107.  
  2108. $field_number_min = $sort_field_number - 0.001; 
  2109. $field_number_max = $sort_field_number + 0.001; 
  2110.  
  2111. $in_filter = ""; 
  2112. if ( ! empty( $approvedcolumn ) ) { 
  2113. $in_filter = $wpdb->prepare( "WHERE l.id IN (SELECT lead_id from $lead_detail_table_name WHERE field_number BETWEEN %f AND %f)", $approvedcolumn - 0.001, $approvedcolumn + 0.001 ); 
  2114. // This will work once all the fields are converted to the meta_key after 1.6 
  2115. #$search_filter .= $wpdb->prepare(" AND m.meta_key = 'is_approved' AND m.meta_value = %s", 1); 
  2116.  
  2117. $limit_filter = ''; //paging is done later since 3.5 to allow multisort 
  2118. if ( ! apply_filters( 'kws_gf_directory_want_multisort', false ) ) { 
  2119. if ( $page_size > 0 ) { 
  2120. $limit_filter = "LIMIT $offset, $page_size"; 
  2121.  
  2122. $sql = " 
  2123. SELECT filtered.sort, l.*, d.field_number, d.value 
  2124. FROM $lead_table_name l 
  2125. INNER JOIN $lead_detail_table_name d ON d.lead_id = l.id 
  2126. INNER JOIN ( 
  2127. SELECT distinct sorted.sort, l.id 
  2128. FROM $lead_table_name l 
  2129. INNER JOIN $lead_detail_table_name d ON d.lead_id = l.id 
  2130. INNER JOIN ( 
  2131. SELECT @rownum:=@rownum+1 as sort, id FROM ( 
  2132. SELECT 0 as query, lead_id as id, value 
  2133. FROM $lead_detail_table_name 
  2134. WHERE form_id=$form_id 
  2135. AND field_number between $field_number_min AND $field_number_max 
  2136.  
  2137. UNION ALL 
  2138.  
  2139. SELECT 1 as query, l.id, d.value 
  2140. FROM $lead_table_name l 
  2141. LEFT OUTER JOIN $lead_detail_table_name d ON d.lead_id = l.id AND field_number between $field_number_min AND $field_number_max 
  2142. WHERE l.form_id=$form_id 
  2143. AND d.lead_id IS NULL 
  2144.  
  2145. ) sorted1 
  2146. $orderby 
  2147. ) sorted ON d.lead_id = sorted.id 
  2148. $search_filter 
  2149. $in_search_criteria 
  2150. $limit_filter 
  2151. ) filtered ON filtered.id = l.id 
  2152. $in_filter 
  2153. ORDER BY filtered.sort"; 
  2154.  
  2155. return $sql; 
  2156.  
  2157.  
  2158. /** 
  2159. * sort_by_default_field_query function. 
  2160. * 
  2161. * A copy of the Gravity Forms method, but adding $approvedcolumns and $limituser args 
  2162. * 
  2163. * @access private 
  2164. * @static 
  2165. * 
  2166. * @param mixed $form_id 
  2167. * @param mixed $sort_field 
  2168. * @param string $sort_direction (default: 'DESC') 
  2169. * @param string $search (default: '') 
  2170. * @param array $search_criterias - since 3.5 
  2171. * @param int $offset (default: 0) 
  2172. * @param int $page_size (default: 30) 
  2173. * @param mixed $star (default: null) 
  2174. * @param mixed $read (default: null) 
  2175. * @param bool $is_numeric_sort (default: false) 
  2176. * @param mixed $start_date (default: null) 
  2177. * @param mixed $end_date (default: null) 
  2178. * @param string $status (default: 'active') 
  2179. * @param mixed $approvedcolumn (default: null) 
  2180. * @param bool $limituser (default: false) 
  2181. * 
  2182. * @return void 
  2183. */ 
  2184. private static function sort_by_default_field_query( $form_id, $sort_field, $sort_direction = 'DESC', $search = '', $search_criterias, $offset = 0, $page_size = 30, $star = NULL, $read = NULL, $is_numeric_sort = false, $start_date = NULL, $end_date = NULL, $status = 'active', $approvedcolumn = NULL, $limituser = false ) { 
  2185. global $wpdb, $current_user; 
  2186.  
  2187. if ( ! is_numeric( $form_id ) || ! is_numeric( $offset ) || ! is_numeric( $page_size ) ) { 
  2188. return ""; 
  2189.  
  2190. $lead_detail_table_name = RGFormsModel::get_lead_details_table_name(); 
  2191. $lead_table_name = RGFormsModel::get_lead_table_name(); 
  2192.  
  2193. $search_term = "%$search%"; 
  2194. $search_filter = empty( $search ) ? "" : $wpdb->prepare( " AND value LIKE %s", $search_term ); 
  2195.  
  2196. // new search criterias since 3.5 
  2197. $in_search_criteria = ''; 
  2198. if ( ! empty( $search_criterias ) ) { 
  2199. foreach ( $search_criterias as $field_id => $value ) { 
  2200. $value = "%$value%"; 
  2201. $in_search_criteria .= $wpdb->prepare( " AND l.id IN (SELECT lead_id from $lead_detail_table_name WHERE field_number = %s AND value LIKE %s)", $field_id, $value ); 
  2202.  
  2203. $star_filter = $star !== NULL && $status == 'active' ? $wpdb->prepare( " AND is_starred=%d AND status='active' ", $star ) : ""; 
  2204. $read_filter = $read !== NULL && $status == 'active' ? $wpdb->prepare( " AND is_read=%d AND status='active' ", $read ) : ""; 
  2205. if ( function_exists( 'gform_get_meta' ) ) { 
  2206. $status_filter = $wpdb->prepare( " AND status=%s ", $status ); 
  2207. } else { 
  2208. $status_filter = ''; 
  2209.  
  2210. $start_date_filter = empty( $start_date ) ? "" : " AND datediff(date_created, '$start_date') >=0"; 
  2211. $end_date_filter = empty( $end_date ) ? "" : " AND datediff(date_created, '$end_date') <=0"; 
  2212.  
  2213. $in_filter = ""; 
  2214. if ( ! empty( $approvedcolumn ) ) { 
  2215. $in_filter = $wpdb->prepare( "l.id IN (SELECT lead_id from $lead_detail_table_name WHERE field_number BETWEEN %f AND %f) AND", $approvedcolumn - 0.001, $approvedcolumn + 0.001 ); 
  2216. // This will work once all the fields are converted to the meta_key after 1.6 
  2217. #$search_filter .= $wpdb->prepare(" AND m.meta_key = 'is_approved' AND m.meta_value = %s", 1); 
  2218.  
  2219. $user_filter = ''; 
  2220. if ( $limituser ) { 
  2221. get_currentuserinfo(); 
  2222. if ( (int) $current_user->ID !== 0 || ( $current_user->ID === 0 && apply_filters( 'kws_gf_show_entries_if_not_logged_in', apply_filters( 'kws_gf_treat_not_logged_in_as_user', true ) ) ) ) { 
  2223. if ( (int) $current_user->ID === 0 ) { 
  2224. $user_filter = $wpdb->prepare( " AND (created_by IS NULL OR created_by=%d)", $current_user->ID ); 
  2225. } else { 
  2226. $user_filter = $wpdb->prepare( " AND created_by=%d ", $current_user->ID ); 
  2227. } else { 
  2228. return false; 
  2229.  
  2230. $limit_filter = ''; //paging is done later since 3.5 to allow multisort 
  2231. if ( ! apply_filters( 'kws_gf_directory_want_multisort', false ) ) { 
  2232. if ( $page_size > 0 ) { 
  2233. $limit_filter = "LIMIT $offset, $page_size"; 
  2234.  
  2235. $sql = " 
  2236. SELECT filtered.sort, l.*, d.field_number, d.value 
  2237. FROM $lead_table_name l 
  2238. INNER JOIN $lead_detail_table_name d ON d.lead_id = l.id 
  2239. INNER JOIN 
  2240. SELECT @rownum:=@rownum + 1 as sort, id 
  2241. FROM 
  2242. SELECT distinct l.id 
  2243. FROM $lead_table_name l 
  2244. INNER JOIN $lead_detail_table_name d ON d.lead_id = l.id 
  2245. WHERE $in_filter 
  2246. l.form_id=$form_id 
  2247. $search_filter 
  2248. $in_search_criteria 
  2249. $star_filter 
  2250. $read_filter 
  2251. $user_filter 
  2252. $status_filter 
  2253. $start_date_filter 
  2254. $end_date_filter 
  2255. ORDER BY $sort_field $sort_direction 
  2256. $limit_filter 
  2257. ) page 
  2258. ) filtered ON filtered.id = l.id 
  2259. ORDER BY filtered.sort"; 
  2260.  
  2261. return $sql; 
  2262.  
  2263. static function directory_anchor_text( $value = NULL ) { 
  2264.  
  2265. if ( apply_filters( 'kws_gf_directory_anchor_text_striphttp', true ) ) { 
  2266. $value = str_replace( 'http://', '', $value ); 
  2267. $value = str_replace( 'https://', '', $value ); 
  2268.  
  2269. if ( apply_filters( 'kws_gf_directory_anchor_text_stripwww', true ) ) { 
  2270. $value = str_replace( 'www.', '', $value ); 
  2271. if ( apply_filters( 'kws_gf_directory_anchor_text_rootonly', true ) ) { 
  2272. $value = preg_replace( '/(.*?)\/(.+)/ism', '$1', $value ); 
  2273. if ( apply_filters( 'kws_gf_directory_anchor_text_nosubdomain', true ) ) { 
  2274. $value = preg_replace( '/((.*?)\.)+(.*?)\.(.*?)/ism', '$3.$4', $value ); 
  2275. if ( apply_filters( 'kws_gf_directory_anchor_text_noquerystring', true ) ) { 
  2276. $ary = explode( "?", $value ); 
  2277. $value = $ary[0]; 
  2278.  
  2279. return $value; 
  2280.  
  2281. static public function r( $content, $die = false ) { 
  2282. echo '<pre>' . print_r( $content, true ) . '</pre>'; 
  2283. if ( $die ) { 
  2284. die(); 
  2285.  
  2286. static private function get_entrylink_column( $form, $entry = false ) { 
  2287. if ( ! is_array( $form ) ) { 
  2288. return false; 
  2289.  
  2290. $columns = empty( $entry ) ? array() : array( 'id' => 'id' ); 
  2291. foreach ( @$form['fields'] as $key => $col ) { 
  2292. if ( ! empty( $col['useAsEntryLink'] ) ) { 
  2293. $columns[ $col['id'] ] = $col['useAsEntryLink']; 
  2294.  
  2295. return empty( $columns ) ? false : $columns; 
  2296.  
  2297. static private function prep_address_field( $field ) { 
  2298. return ! empty( $field ) ? GFCommon::trim_all( $field ) : ''; 
  2299.  
  2300. static function format_address( $address = array(), $linknewwindow = false ) { 
  2301. $address_field_id = @self::prep_address_field( $address['id'] ); 
  2302. $street_value = @self::prep_address_field( $address[ $address_field_id . ".1" ] ); 
  2303. $street2_value = @self::prep_address_field( $address[ $address_field_id . ".2" ] ); 
  2304. $city_value = @self::prep_address_field( $address[ $address_field_id . ".3" ] ); 
  2305. $state_value = @self::prep_address_field( $address[ $address_field_id . ".4" ] ); 
  2306. $zip_value = @self::prep_address_field( $address[ $address_field_id . ".5" ] ); 
  2307. $country_value = @self::prep_address_field( $address[ $address_field_id . ".6" ] ); 
  2308.  
  2309. $address = $street_value; 
  2310. $address .= ! empty( $address ) && ! empty( $street2_value ) ? "<br />$street2_value" : $street2_value; 
  2311. $address .= ! empty( $address ) && ( ! empty( $city_value ) || ! empty( $state_value ) ) ? "<br />$city_value" : $city_value; 
  2312. $address .= ! empty( $address ) && ! empty( $city_value ) && ! empty( $state_value ) ? ", $state_value" : $state_value; 
  2313. $address .= ! empty( $address ) && ! empty( $zip_value ) ? " $zip_value" : $zip_value; 
  2314. $address .= ! empty( $address ) && ! empty( $country_value ) ? "<br />$country_value" : $country_value; 
  2315.  
  2316. //adding map link 
  2317. if ( ! empty( $address ) && apply_filters( 'kws_gf_directory_td_address_map', 1 ) ) { 
  2318. $address_qs = str_replace( "<br />", " ", $address ); //replacing <br/> with spaces 
  2319. $address_qs = urlencode( $address_qs ); 
  2320. $target = ''; 
  2321. if ( $linknewwindow ) { 
  2322. $target = ' target="_blank"'; 
  2323. $address .= "<br/>" . apply_filters( 'kws_gf_directory_map_link', "<a href='http://maps.google.com/maps?q=$address_qs'" . $target . " class='map-it-link'>" . __( 'Map It' ) . "</a>" ); 
  2324.  
  2325. return $address; 
  2326.  
  2327. static public function html_display_type_filter( $content = NULL, $type = 'table', $single = false ) { 
  2328. switch ( $type ) { 
  2329. case 'table': 
  2330. return $content; 
  2331. break; 
  2332. case 'ul': 
  2333. $content = self::convert_to_ul( $content, $single ); 
  2334. break; 
  2335. case 'dl': 
  2336. $content = self::convert_to_dl( $content, $single ); 
  2337. break; 
  2338.  
  2339. return $content; 
  2340.  
  2341. static public function convert_to_ul( $content = NULL, $singleUL = false ) { 
  2342.  
  2343. $strongHeader = apply_filters( 'kws_gf_convert_to_ul_strong_header', 1 ); 
  2344.  
  2345. // Directory View 
  2346. if ( ! $singleUL ) { 
  2347. $content = preg_replace( "/<table([^>]*)>/ism", "<ul$1>", $content ); 
  2348. $content = preg_replace( "/<\/table([^>]*)>/ism", "</ul>", $content ); 
  2349. if ( $strongHeader ) { 
  2350. $content = preg_replace( "/<tr([^>]*)>\s+/", "\n\t\t\t\t\t\t\t\t\t\t\t\t<li$1><ul>", $content ); 
  2351. $content = preg_replace( "/<th([^>]*)\>(.*?)\<\/th\>/", "$2</strong>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<ul>", $content ); 
  2352. } else { 
  2353. $content = preg_replace( "/<tr([^>]*)>\s+/", "\n\t\t\t\t\t\t\t\t\t\t\t\t<li$1>", $content ); 
  2354. $content = preg_replace( "/<th([^>]*)\>(.*?)\<\/th\>/", "$2\n\t\t\t\t\t\t\t\t\t\t\t\t\t<ul>", $content ); 
  2355. $content = preg_replace( "/<\/tr[^>]*>/", "\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t\t\t\t</li>", $content ); 
  2356. } // Single listing view 
  2357. else { 
  2358. $content = preg_replace( "/<table([^>]*)>/ism", "<ul$1>", $content ); 
  2359. $content = preg_replace( "/<\/table([^>]*)>/ism", "</ul>", $content ); 
  2360. if ( $strongHeader ) { 
  2361. $content = preg_replace( "/<tr([^>]*)>\s+/", "\n\t\t\t\t\t\t\t\t\t\t\t\t<li$1><strong>", $content ); 
  2362. $content = preg_replace( "/<th([^>]*)\>(.*?)\<\/th\>/", "$2</strong>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<ul>", $content ); 
  2363. } else { 
  2364. $content = preg_replace( "/<tr([^>]*)>\s+/", "\n\t\t\t\t\t\t\t\t\t\t\t\t<li$1>", $content ); 
  2365. $content = preg_replace( "/<th([^>]*)\>(.*?)\<\/th\>/", "$2\n\t\t\t\t\t\t\t\t\t\t\t\t\t<ul>", $content ); 
  2366. $content = preg_replace( "/<\/tr[^>]*>/", "\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t\t\t\t</li>", $content ); 
  2367. # $content = preg_replace("/\<\/p\>\s+\<\/li/ism", "\<\/p\>\<\/li", $content); 
  2368. $content = preg_replace( "/(?:\s+)?(valign\=\"(?:.*?)\"|width\=\"(?:.*?)\"|cellspacing\=\"(?:.*?)\")(?:\s+)?/ism", ' ', $content ); 
  2369. $content = preg_replace( "/<\/?tbody[^>]*>/", "", $content ); 
  2370. $content = preg_replace( "/<thead[^>]*>.*<\/thead>|<tfoot[^>]*>.*<\/tfoot>/is", "", $content ); 
  2371. $content = preg_replace( "/\<td([^>]*)\>(\ |)\<\/td\>/", "", $content ); 
  2372. $content = preg_replace( "/\<td([^>]*)\>/", "\t\t\t\t\t<li$1>", $content ); 
  2373. $content = preg_replace( "/<\/td[^>]*>/", "</li>", $content ); 
  2374. $content = preg_replace( '/\s?colspan\="([^>]*?)"\s?/ism', ' ', $content ); 
  2375.  
  2376. return $content; 
  2377.  
  2378. static public function convert_to_dl( $content, $singleDL = false ) { 
  2379. $back = ''; 
  2380. // Get the back link, if it exists 
  2381. preg_match( "/\<p\sclass=\"entryback\"\>(.*?)\<\/p\>/", $content, $matches ); 
  2382. if ( isset( $matches[0] ) ) { 
  2383. $back = $matches[0]; 
  2384. $content = preg_replace( "/\<p\sclass=\"entryback\"\>(.*?)\<\/p\>/", "", $content ); 
  2385. $content = preg_replace( "/<\/?table[^>]*>|<\/?tbody[^>]*>/", "", $content ); 
  2386. $content = preg_replace( "/<thead[^>]*>.*<\/thead>|<tfoot[^>]*>.*<\/tfoot>/is", "", $content ); 
  2387. if ( ! $singleDL ) { 
  2388. $content = preg_replace( "/<tr([^>]*)>/", "<dl$1>", $content ); 
  2389. $content = preg_replace( "/<\/tr[^>]*>/", "</dl>", $content ); 
  2390. } else { 
  2391. $content = preg_replace( "/<tr([^>]*)>/", "", $content ); 
  2392. $content = preg_replace( "/<\/tr[^>]*>/", "", $content ); 
  2393. $content = preg_replace( "/\<td([^>]*)\>(\ |)\<\/td\>/", "", $content ); 
  2394. $content = preg_replace( "/\<th([^>]*)\>(.*?)<\/th\>/ism", "<dt$1>$2</dt>", $content ); 
  2395. $content = preg_replace( '/<td(.*?)(title="(.*?)")?>(.*?)<\/td[^>]*>/ism', "<dt$1>$3</dt><dd>$4</dd>", $content ); 
  2396. $output = $back; 
  2397. $output .= "\n\t\t\t\t\t\t\t\t" . '<dl>'; 
  2398. $output .= $content; 
  2399. $output .= "\t\t\t\t\t\t" . '</dl>'; 
  2400.  
  2401. return $output; 
  2402.  
  2403. static public function make_entry_link( $options = array(), $link = false, $lead_id = '', $form_id = '', $field_id = '', $field_label = '', $linkClass = '' ) { 
  2404. global $wp_rewrite, $post, $wp; 
  2405. extract( $options ); 
  2406. $entrylink = ( empty( $link ) || $link === ' ' ) ? $field_label : $link; //$entrylink; 
  2407.  
  2408. $entrytitle = apply_filters( 'kws_gf_directory_detail_title', apply_filters( 'kws_gf_directory_detail_title_' . $lead_id, $entrytitle ) ); 
  2409.  
  2410. if ( ! empty( $lightboxsettings['entry'] ) ) { 
  2411. $href = wp_nonce_url( plugins_url( "/entry-details.php?leadid=$lead_id&form={$form_id}&post={$post->ID}", __FILE__ ), sprintf( 'view-%d-%d', $lead_id, $form_id ), 'view' ); 
  2412. if ( wp_script_is( 'colorbox', 'registered' ) ) { 
  2413. $linkClass = ' class="colorbox lightbox" rel="directory_all directory_entry"'; 
  2414. } else if ( wp_script_is( 'thickbox', 'registered' ) ) { 
  2415. $linkClass = ' class="thickbox lightbox" rel="directory_all directory_entry"'; 
  2416. } else { 
  2417. $multisite = ( function_exists( 'is_multisite' ) && is_multisite() && $wpdb->blogid == 1 ); 
  2418. if ( $wp_rewrite->using_permalinks() ) { 
  2419. // example.com/example-directory/entry/4/14/ 
  2420. if ( isset( $post->ID ) ) { 
  2421. $url = get_permalink( $post->ID ); 
  2422. } else { 
  2423. $url = parse_url( add_query_arg( array(), home_url() ) ); 
  2424. $url = $url['path']; 
  2425. $href = trailingslashit( $url ) . sanitize_title( apply_filters( 'kws_gf_directory_endpoint', 'entry' ) ) . '/' . $form_id . apply_filters( 'kws_gf_directory_endpoint_separator', '/' ) . $lead_id . '/'; 
  2426. #if(!empty($url['query'])) { $href .= '?'.$url['query']; } 
  2427. $href = add_query_arg( array( 
  2428. 'gf_search' => ! empty( $_REQUEST['gf_search'] ) ? $_REQUEST['gf_search'] : NULL,  
  2429. 'sort' => isset( $_REQUEST['sort'] ) ? $_REQUEST['sort'] : NULL,  
  2430. 'dir' => isset( $_REQUEST['dir'] ) ? $_REQUEST['dir'] : NULL,  
  2431. 'pagenum' => isset( $_REQUEST['pagenum'] ) ? $_REQUEST['pagenum'] : NULL,  
  2432. 'start_date' => isset( $_REQUEST['start_date'] ) ? $_REQUEST['start_date'] : NULL,  
  2433. 'end_date' => isset( $_REQUEST['start_date'] ) ? $_REQUEST['end_date'] : NULL,  
  2434. ), $href ); 
  2435. } else { 
  2436. // example.com/?page_id=24&leadid=14&form=4 
  2437. $href = wp_nonce_url( add_query_arg( array( 
  2438. 'leadid' => $lead_id,  
  2439. 'form' => $form_id,  
  2440. ) ), sprintf( 'view-%d-%d', $lead_id, $form_id ), 'view' ); 
  2441.  
  2442. // If this is a preview, add preview arguments to the link. 
  2443. // @since 3.5 
  2444. if ( ! empty( $_GET['preview'] ) && ! empty( $_GET['preview_id'] ) && ! empty( $_GET['preview_nonce'] ) ) { 
  2445. if ( current_user_can( 'edit_posts' ) ) { 
  2446. $href = add_query_arg( array( 
  2447. 'preview' => $_GET['preview'],  
  2448. 'preview_id' => $_GET['preview_id'],  
  2449. 'preview_nonce' => $_GET['preview_nonce'],  
  2450. ), $href ); 
  2451.  
  2452. $value = '<a href="' . esc_url( $href ) . '"' . $linkClass . ' title="' . $entrytitle . '">' . $entrylink . '</a>'; 
  2453.  
  2454. return $value; 
  2455.  
  2456. static function get_lead_count( $form_id, $search, $star = NULL, $read = NULL, $column, $approved = false, $leads = array(), $start_date = NULL, $end_date = NULL, $limituser = false, $search_criterias ) { 
  2457. global $wpdb, $current_user; 
  2458.  
  2459. if ( ! is_numeric( $form_id ) ) { 
  2460. return ""; 
  2461.  
  2462. $detail_table_name = RGFormsModel::get_lead_details_table_name(); 
  2463. $lead_table_name = RGFormsModel::get_lead_table_name(); 
  2464.  
  2465. $star_filter = $star !== NULL ? $wpdb->prepare( "AND is_starred=%d ", $star ) : ""; 
  2466. $read_filter = $read !== NULL ? $wpdb->prepare( "AND is_read=%d ", $read ) : ""; 
  2467. if ( function_exists( 'gform_get_meta' ) ) { 
  2468. $status_filter = $wpdb->prepare( " AND status=%s ", 'active' ); 
  2469. } else { 
  2470. $status_filter = ''; 
  2471. $start_date_filter = empty( $start_date ) ? "" : " AND datediff(date_created, '$start_date') >=0"; 
  2472. $end_date_filter = empty( $end_date ) ? "" : " AND datediff(date_created, '$end_date') <=0"; 
  2473.  
  2474. $search_term = "%$search%"; 
  2475. $search_filter = empty( $search ) ? "" : $wpdb->prepare( "AND ld.value LIKE %s", $search_term ); 
  2476.  
  2477. // new search criterias since 3.5 
  2478. $in_search_criteria = ''; 
  2479. if ( ! empty( $search_criterias ) ) { 
  2480. foreach ( $search_criterias as $field_id => $value ) { 
  2481. $value = "%$value%"; 
  2482. $in_search_criteria .= $wpdb->prepare( " AND l.id IN (SELECT lead_id from $detail_table_name WHERE field_number = %s AND value LIKE %s)", $field_id, $value ); 
  2483.  
  2484.  
  2485. $user_filter = ''; 
  2486. if ( $limituser ) { 
  2487. get_currentuserinfo(); 
  2488. if ( (int) $current_user->ID !== 0 || ( $current_user->ID === 0 && apply_filters( 'kws_gf_show_entries_if_not_logged_in', apply_filters( 'kws_gf_treat_not_logged_in_as_user', true ) ) ) ) { 
  2489. if ( ! empty( $current_user->ID ) ) { 
  2490. $user_filter = $wpdb->prepare( " AND l.created_by=%d ", $current_user->ID ); 
  2491. } else { 
  2492. $user_filter = $wpdb->prepare( " AND (created_by IS NULL OR created_by=%d)", $current_user->ID ); 
  2493. } else { 
  2494. return false; 
  2495.  
  2496.  
  2497. $in_filter = ""; 
  2498. if ( $approved ) { 
  2499. $in_filter = $wpdb->prepare( "l.id IN (SELECT lead_id from $detail_table_name WHERE field_number BETWEEN %f AND %f) AND", $column - 0.001, $column + 0.001 ); 
  2500. // This will work once all the fields are converted to the meta_key after 1.6 
  2501. #$search_filter .= $wpdb->prepare(" AND m.meta_key = 'is_approved' AND m.meta_value = %s", 1); 
  2502.  
  2503. $sql = "SELECT count(distinct l.id) FROM $lead_table_name as l,  
  2504. $detail_table_name as ld"; 
  2505. # $sql .= function_exists('gform_get_meta') ? " INNER JOIN wp_rg_lead_meta m ON l.id = m.lead_id " : ""; // After 1.6 
  2506. $sql .= " 
  2507. WHERE $in_filter 
  2508. l.form_id=$form_id 
  2509. AND ld.form_id=$form_id 
  2510. AND l.id = ld.lead_id 
  2511. $star_filter 
  2512. $read_filter 
  2513. $status_filter 
  2514. $user_filter 
  2515. $start_date_filter 
  2516. $end_date_filter 
  2517. $search_filter 
  2518. $in_search_criteria"; 
  2519.  
  2520. return $wpdb->get_var( $sql ); 
  2521.  
  2522. static function check_meta_approval( $lead_id ) { 
  2523. return gform_get_meta( $lead_id, 'is_approved' ); 
  2524.  
  2525. static function check_approval( $lead, $column ) { 
  2526. return self::check_meta_approval( $lead['id'] ); 
  2527.  
  2528. static function hide_in_directory( $form, $field_id ) { 
  2529. return self::check_hide_in( 'hideInDirectory', $form, $field_id ); 
  2530.  
  2531. static function hide_in_single( $form, $field_id ) { 
  2532. return self::check_hide_in( 'hideInSingle', $form, $field_id ); 
  2533.  
  2534. static function check_hide_in( $type, $form, $field_id ) { 
  2535. foreach ( $form['fields'] as $field ) { 
  2536. # echo $field['label'] . ' / ' . floor($field['id']).' / '.floor($field_id).' / <strong>'.$field["{$type}"].'</strong><br />'; 
  2537. if ( floor( $field_id ) === floor( $field['id'] ) && ! empty( $field["{$type}"] ) ) { 
  2538. return true; 
  2539.  
  2540. return false; 
  2541.  
  2542. /** 
  2543. * get field property value, for a specific field_id on a $form 
  2544. * 
  2545. * @since 3.5 
  2546. */ 
  2547. static function get_field_property( $property, $form, $field_id = '' ) { 
  2548. if ( empty( $property ) || empty( $form ) || '' === $field_id ) { 
  2549. return false; 
  2550. foreach ( $form['fields'] as $field ) { 
  2551.  
  2552. if ( floor( $field_id ) === floor( $field['id'] ) && ! empty( $field[ $property ] ) ) { 
  2553. return $field[ $property ]; 
  2554.  
  2555. return false; 
  2556.  
  2557. /** 
  2558. * get field properties, for a specific field_id on a $form 
  2559. * 
  2560. * @since 3.5 
  2561. * 
  2562. * @param array $form GF Form array 
  2563. * @param string $field_id Field ID 
  2564. * 
  2565. * @return boolean|array If the field matches the searched-for field ID, return the field array. Otherwise, return false. 
  2566. */ 
  2567. static function get_field_properties( $form, $field_id = '' ) { 
  2568. if ( empty( $form ) || '' === $field_id ) { 
  2569. return false; 
  2570.  
  2571. foreach ( $form['fields'] as $field ) { 
  2572. if ( floor( $field_id ) === floor( $field['id'] ) ) { 
  2573. return $field; 
  2574.  
  2575. return false; 
  2576.  
  2577. /** 
  2578. * Deprecated. 
  2579. * 
  2580. * @deprecated 3.5 
  2581. */ 
  2582. static function remove_admin_only() { 
  2583.  
  2584. static function remove_approved_column( $type = 'form', $fields, $approvedcolumn ) { 
  2585.  
  2586. foreach ( $fields as $key => $column ) { 
  2587. if ( (int) floor( $column['id'] ) === (int) floor( $approvedcolumn ) ) { 
  2588. unset( $fields["{$key}"] ); 
  2589.  
  2590. return $fields; 
  2591.  
  2592.  
  2593. /** 
  2594. * Filter columns and fields when generating directory or single entry view based on Admin Only fields, or "hide from directory" fields or (since 3.5) only visible if user is logged in. 
  2595. * 
  2596. * This method replaces GFDirectory::remove_admin_only() in 3.5 
  2597. * 
  2598. * @since 3.5 
  2599. * @access public 
  2600. * @static 
  2601. * 
  2602. * @param mixed $leads 
  2603. * @param mixed $admin_only 
  2604. * @param mixed $approved 
  2605. * @param mixed $is_leads 
  2606. * @param bool $is_single (default: false) 
  2607. * @param bool $show_admin_only (default: false) 
  2608. * @param mixed $form 
  2609. * 
  2610. * @return void 
  2611. */ 
  2612. static function remove_hidden_fields( $leads, $admin_only, $approved, $is_leads, $is_single = false, $show_admin_only = false, $form ) { 
  2613.  
  2614. if ( empty( $admin_only ) || ! is_array( $admin_only ) ) { 
  2615. $admin_only = array(); 
  2616.  
  2617. if ( empty( $leads ) || ! is_array( $leads ) ) { 
  2618. return $leads; 
  2619.  
  2620. if ( $is_leads ) { 
  2621.  
  2622. foreach ( $leads as $index => $lead ) { 
  2623. // the field_ids are the numeric array keys of a lead 
  2624. $field_ids = array_filter( array_keys( $lead ), 'is_int' ); 
  2625.  
  2626. foreach ( $field_ids as $id ) { 
  2627. if ( self::check_hide_field_conditions( $id, $admin_only, $approved, $is_single, $show_admin_only, $form ) ) { 
  2628. unset( $leads[ $index ][ $id ] ); 
  2629.  
  2630.  
  2631. return $leads; 
  2632.  
  2633. } else { 
  2634.  
  2635. // the KEY = field_id (to be used to check directory columns) 
  2636. foreach ( $leads as $key => $column ) { 
  2637.  
  2638. if ( self::check_hide_field_conditions( $key, $admin_only, $approved, $is_single, $show_admin_only, $form ) ) { 
  2639. unset( $leads[ $key ] ); 
  2640.  
  2641.  
  2642. return $leads; 
  2643.  
  2644.  
  2645.  
  2646. /** returns true if field should be hidden / returns false if not , since 3.5 */ 
  2647. static function check_hide_field_conditions( $field_id, $admin_only, $approved, $is_single = false, $show_admin_only = false, $form ) { 
  2648.  
  2649.  
  2650. $properties = self::get_field_properties( $form, $field_id ); 
  2651. if ( empty( $properties ) ) { 
  2652. return false; 
  2653.  
  2654. //check if set to be hidden in directory or in single entry view 
  2655. if ( ( $is_single && ! empty( $properties['hideInSingle'] ) ) || ( ! $is_single && ! empty( $properties['hideInDirectory'] ) ) ) { 
  2656. return true; 
  2657.  
  2658. // check if is and admin only field and remove if not authorized to be shown 
  2659. if ( ! $show_admin_only && @in_array( $field_id, $admin_only ) && $field_id != $approved && $field_id != floor( $approved ) ) { 
  2660. return true; 
  2661.  
  2662. //check if field is only visible for logged in users, and in that case, check capabilities level 
  2663. if ( ! empty( $properties['visibleToLoggedIn'] ) && ! current_user_can( $properties['visibleToLoggedInCap'] ) ) { 
  2664. return true; 
  2665.  
  2666. return false; 
  2667.  
  2668.  
  2669. /** 
  2670. * Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead) 
  2671. * 
  2672. * @param array $form Form object. 
  2673. * @param array $lead Lead object 
  2674. * 
  2675. * @return void 
  2676. */ 
  2677. public static function save_lead( $form, &$lead ) { 
  2678. global $wpdb; 
  2679.  
  2680. if ( IS_ADMIN && ! GFCommon::current_user_can_any( "gravityforms_edit_entries" ) ) { 
  2681. die( __( "You don't have adequate permission to edit entries.", "gravityforms" ) ); 
  2682.  
  2683. $lead_detail_table = RGFormsModel::get_lead_details_table_name(); 
  2684.  
  2685. //Inserting lead if null 
  2686. if ( $lead == NULL ) { 
  2687. global $current_user; 
  2688. $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL'; 
  2689.  
  2690. $lead_table = RGFormsModel::get_lead_table_name(); 
  2691. $user_agent = RGFormsModel::truncate( $_SERVER["HTTP_USER_AGENT"], 250 ); 
  2692. $currency = GFCommon::get_currency(); 
  2693. $source_url = RGFormsModel::truncate( RGFormsModel::get_current_page_url(), 200 ); 
  2694.  
  2695. $wpdb->query( $wpdb->prepare( "INSERT INTO $lead_table(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], RGFormsModel::get_ip(), $source_url, $user_agent, $currency ) ); 
  2696.  
  2697.  
  2698. //reading newly created lead id 
  2699. $lead_id = $wpdb->insert_id; 
  2700. $lead = array( "id" => $lead_id ); 
  2701.  
  2702.  
  2703. $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $lead["id"] ) ); 
  2704. $original_post_id = rgget( "post_id", $lead ); 
  2705.  
  2706. $total_fields = array(); 
  2707. $calculation_fields = array(); 
  2708. $recalculate_total = false; 
  2709.  
  2710. foreach ( $form["fields"] as $field ) { 
  2711.  
  2712. //Ignore fields that are marked as display only 
  2713. if ( rgget( "displayOnly", $field ) && $field["type"] != "password" ) { 
  2714. continue; 
  2715.  
  2716. //ignore pricing fields in the entry detail 
  2717. if ( RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field( $field["type"] ) ) { 
  2718. continue; 
  2719.  
  2720.  
  2721. //process total field after all fields have been saved 
  2722. if ( $field["type"] == "total" ) { 
  2723. $total_fields[] = $field; 
  2724. continue; 
  2725.  
  2726. //only save fields that are not hidden (except on entry screen) 
  2727. if ( RG_CURRENT_VIEW == "entry" || ! RGFormsModel::is_field_hidden( $form, $field, array(), $lead ) ) { 
  2728. // process calculation fields after all fields have been saved (moved after the is hidden check) 
  2729. if ( GFCommon::has_field_calculation( $field ) ) { 
  2730. $calculation_fields[] = $field; 
  2731. continue; 
  2732.  
  2733. if ( $field['type'] == 'post_category' ) { 
  2734. $field = GFCommon::add_categories_as_choices( $field, '' ); 
  2735.  
  2736. if ( isset( $field["inputs"] ) && is_array( $field["inputs"] ) ) { 
  2737.  
  2738. foreach ( $field["inputs"] as $input ) { 
  2739. RGFormsModel::save_input( $form, $field, $lead, $current_fields, $input["id"] ); 
  2740. } else { 
  2741. RGFormsModel::save_input( $form, $field, $lead, $current_fields, $field["id"] ); 
  2742.  
  2743. //Refresh lead to support conditionals (not optimal but...) 
  2744. $lead = RGFormsModel::get_lead( $lead['id'] ); 
  2745.  
  2746. if ( ! empty( $calculation_fields ) ) { 
  2747. foreach ( $calculation_fields as $calculation_field ) { 
  2748.  
  2749. if ( isset( $calculation_field["inputs"] ) && is_array( $calculation_field["inputs"] ) ) { 
  2750. foreach ( $calculation_field["inputs"] as $input ) { 
  2751. RGFormsModel::save_input( $form, $calculation_field, $lead, $current_fields, $input["id"] ); 
  2752. RGFormsModel::refresh_lead_field_value( $lead["id"], $input["id"] ); 
  2753. } else { 
  2754. RGFormsModel::save_input( $form, $calculation_field, $lead, $current_fields, $calculation_field["id"] ); 
  2755. RGFormsModel::refresh_lead_field_value( $lead["id"], $calculation_field["id"] ); 
  2756.  
  2757. RGFormsModel::refresh_product_cache( $form, $lead = RGFormsModel::get_lead( $lead['id'] ) ); 
  2758.  
  2759. //saving total field as the last field of the form. 
  2760. if ( ! empty( $total_fields ) ) { 
  2761. foreach ( $total_fields as $total_field ) { 
  2762. GFCommon::log_debug( "Saving total field." ); 
  2763. RGFormsModel::save_input( $form, $total_field, $lead, $current_fields, $total_field["id"] ); 
  2764.  
  2765.  
  2766.  
  2767.  
  2768. function kws_gf_load_functions() { 
  2769.  
  2770. // If Gravity Forms is installed and exists 
  2771. if ( defined( 'RG_CURRENT_PAGE' ) ) { 
  2772.  
  2773. function gf_field_value( $leadid, $fieldid, $form = array() ) { 
  2774. echo get_gf_field_value( $leadid, $fieldid, $form ); 
  2775.  
  2776.  
  2777. // To retrieve textarea inputs from a lead 
  2778. // Example: get_gf_field_value_long(22, '14'); 
  2779. function get_gf_field_value_long( $leadid, $fieldid, $form = array(), $apply_filter = true ) { 
  2780. return RGFormsModel::get_field_value_long( $leadid, $fieldid, $form, $apply_filter ); 
  2781.  
  2782. // To retrieve textarea inputs from a lead 
  2783. // Example: get_gf_field_value_long(22, '14'); 
  2784. function get_gf_field_value( $leadid, $fieldid, $form = array() ) { 
  2785. $lead = RGFormsModel::get_lead( $leadid ); 
  2786. $fieldid = floatval( $fieldid ); 
  2787. if ( is_numeric( $fieldid ) ) { 
  2788. $result = $lead["$fieldid"]; 
  2789.  
  2790. $max_length = GFORMS_MAX_FIELD_LENGTH; 
  2791.  
  2792. if ( strlen( $result ) >= ( $max_length - 50 ) ) { 
  2793. $result = get_gf_field_value_long( $lead["id"], $fieldid, $form ); 
  2794. $result = trim( $result ); 
  2795.  
  2796. if ( ! empty( $result ) ) { 
  2797. return $result; 
  2798.  
  2799. return false; 
  2800.  
  2801. function gf_field_value_long( $leadid, $fieldid, $form = array() ) { 
  2802. echo get_gf_field_value_long( $leadid, $fieldid, $form ); 
  2803.  
  2804.  
  2805. // Gives you the label for a form input (such as First Name). Enter in the form and the field ID to access the label. 
  2806. // Example: echo get_gf_field_label(1, 1.3); 
  2807. // Gives you the label for a form input (such as First Name). Enter in the form and the field ID to access the label. 
  2808. // Example: echo get_gf_field_label(1, 1.3); 
  2809. function get_gf_field_label( $form_id, $field_id ) { 
  2810. $form = RGFormsModel::get_form_meta( $form_id ); 
  2811. foreach ( $form["fields"] as $field ) { 
  2812. if ( $field['id'] == $field_id ) { 
  2813. # $output = RGForms::escape_text($field['label']); // No longer used 
  2814. $output = esc_html( $field['label'] ); // Using esc_html(), a WP function 
  2815. } elseif ( is_array( $field['inputs'] ) ) { 
  2816. foreach ( $field["inputs"] as $input ) { 
  2817. if ( $input['id'] == $field_id ) { 
  2818. if ( class_exists( 'GFCommon' ) ) { 
  2819. $output = esc_html( GFCommon::get_label( $field, $field_id ) ); 
  2820. } else { 
  2821. #$output = RGForms::escape_text(RGForms::get_label($field, $field_id)); // No longer used 
  2822. $output = esc_html( RGForms::get_label( $field, $field_id ) ); // No longer used 
  2823.  
  2824. return $output; 
  2825.  
  2826. function gf_field_label( $form_id, $field_id ) { 
  2827. echo get_gf_field_label( $form_id, $field_id ); 
  2828.  
  2829. // Returns a form using php instead of shortcode 
  2830. function get_gf_form( $id, $display_title = true, $display_description = true, $force_display = false, $field_values = NULL ) { 
  2831. if ( class_exists( 'GFFormDisplay' ) ) { 
  2832. return GFFormDisplay::get_form( $id, $display_title = true, $display_description = true, $force_display = false, $field_values = NULL ); 
  2833. } else { 
  2834. return RGFormsModel::get_form( $id, $display_title, $display_description ); 
  2835.  
  2836. function gf_form( $id, $display_title = true, $display_description = true, $force_display = false, $field_values = NULL ) { 
  2837. echo get_gf_form( $id, $display_title, $display_description, $force_display, $field_values ); 
  2838.  
  2839. // Returns array of leads for a specific form 
  2840. function get_gf_leads( $form_id, $sort_field_number = 0, $sort_direction = 'DESC', $search = '', $offset = 0, $page_size = 3000, $star = NULL, $read = NULL, $is_numeric_sort = false, $start_date = NULL, $end_date = NULL, $status = 'active', $approvedcolumn = false, $limituser = false ) { 
  2841. return GFDirectory::get_leads( $form_id, $sort_field_number, $sort_direction, $search, $offset, $page_size, $star, $read, $is_numeric_sort, $start_date, $end_date, $status, $approvedcolumn, $limituser ); 
  2842.  
  2843. function gf_leads( $form_id, $sort_field_number = 0, $sort_direction = 'DESC', $search = '', $offset = 0, $page_size = 3000, $star = NULL, $read = NULL, $is_numeric_sort = false, $start_date = NULL, $end_date = NULL ) { 
  2844. echo get_gf_leads( $form_id, $sort_field_number, $sort_direction, $search, $offset, $page_size, $star, $read, $is_numeric_sort, $start_date, $end_date ); 
  2845.  
  2846. function kws_gf_directory( $atts ) { 
  2847. GFDirectory::make_directory( $atts ); 
  2848.  
  2849.  
  2850. if ( ! function_exists( 'kws_print_r' ) ) { 
  2851. function kws_print_r( $content, $die = false ) { 
  2852. echo '<pre>' . print_r( $content, true ) . '</pre>'; 
  2853. if ( $die ) { 
  2854. die(); 
  2855.  
  2856. return $content; 
  2857.  
  2858.  
  2859. /** Ending ?> left out intentionally */ 
.