GFDirectory

The Gravity Forms Directory & Addons GFDirectory class.

Defined (1)

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

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