/deprecated/includes/admin/ajax.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. add_action( 'wp_ajax_ninja_forms_save_metabox_state', 'ninja_forms_save_metabox_state' ); 
  4. function ninja_forms_save_metabox_state() { 
  5. // Bail if we aren't in the admin 
  6. if ( ! is_admin() ) 
  7. return false; 
  8.  
  9. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  10.  
  11. $plugin_settings = nf_get_settings(); 
  12. $page = esc_html( $_REQUEST['page'] ); 
  13. $tab = esc_html( $_REQUEST['tab'] ); 
  14. $slug = esc_html( $_REQUEST['slug'] ); 
  15. $metabox_state = esc_html( $_REQUEST['metabox_state'] ); 
  16. $plugin_settings['metabox_state'][$page][$tab][$slug] = $metabox_state; 
  17. update_option( 'ninja_forms_settings', $plugin_settings ); 
  18.  
  19. die(); 
  20.  
  21. /** 
  22. * When a field settings metabox is expanded, return a JSON element containing the field settings HTML 
  23. *  
  24. * @since 2.9 
  25. * @return false; 
  26. */ 
  27.  
  28. function nf_output_field_settings_html() { 
  29. global $nf_rte_editors; 
  30.  
  31. // Bail if we aren't in the admin 
  32. if ( ! is_admin() ) 
  33. return false; 
  34.  
  35. // Bail if we don't have proper permissions 
  36. if ( ! current_user_can( apply_filters( 'nf_new_field_capabilities', 'manage_options' ) ) ) 
  37. return false; 
  38.  
  39. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  40.  
  41. $field_id = esc_html( $_REQUEST['field_id'] ); 
  42. $data = isset ( $_REQUEST['data'] ) ? json_decode( stripslashes( $_REQUEST['data'] ), true ) : array(); 
  43.  
  44. $field = ninja_forms_get_field_by_id( $field_id ); 
  45. $field_data = $field['data']; 
  46. $data = wp_parse_args( $data, $field_data ); 
  47.  
  48. nf_output_registered_field_settings( $field_id, $data ); 
  49.  
  50. die(); 
  51.  
  52. add_action( 'wp_ajax_nf_output_field_settings_html', 'nf_output_field_settings_html' ); 
  53.  
  54. /** 
  55. * Save our admin fields page. 
  56. *  
  57. * @since 2.9 
  58. * @return false; 
  59. */ 
  60.  
  61. function nf_admin_save_builder() { 
  62. global $ninja_forms_fields, $wpdb; 
  63.  
  64. // Bail if we aren't in the admin 
  65. if ( ! is_admin() ) 
  66. return false; 
  67.  
  68. // Bail if we don't have proper permissions 
  69. if ( ! current_user_can( apply_filters( 'nf_new_field_capabilities', 'manage_options' ) ) ) 
  70. return false; 
  71.  
  72. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  73.  
  74. $field_data = json_decode( stripslashes( $_REQUEST['field_data'] ), true ); 
  75. $form_id = esc_html( $_REQUEST['form_id'] ); 
  76. $form_title = stripslashes( $_REQUEST['form_title'] ); 
  77. $field_order = json_decode( strip_tags( stripslashes( $_REQUEST['field_order'] ) ), true ); 
  78.  
  79. if ( is_array ( $field_order ) ) { 
  80. $order_array = array(); 
  81. $x = 0; 
  82. foreach ( $field_order as $id ) { 
  83. $id = str_replace( 'ninja_forms_field_', '', $id ); 
  84. $order_array[ $id ] = $x; 
  85. $x++; 
  86.  
  87. $tmp_array = array(); 
  88. foreach ( $field_data as $field ) { 
  89. $field_id = $field['id']; 
  90. unset( $field['id'] ); 
  91. unset( $field['metabox_state'] ); 
  92. $tmp_array[ $field_id ] = $field; 
  93.  
  94. $field_data = $tmp_array; 
  95.  
  96. if ( isset ( $ninja_forms_fields ) && is_array( $ninja_forms_fields ) ) { 
  97. foreach ( $ninja_forms_fields as $slug => $field ) { 
  98. if ( $field['save_function'] != '') { 
  99. $save_function = $field['save_function']; 
  100. $arguments['form_id'] = $form_id; 
  101. $arguments['data'] = $field_data; 
  102. $field_data = call_user_func_array( $save_function, $arguments ); 
  103.  
  104. if( $form_id != '' && $form_id != 0 && $form_id != 'new' ) { 
  105. foreach ( $field_data as $field_id => $vals ) { 
  106. $field_order = isset( $order_array[$field_id] ) ? $order_array[$field_id] : ''; 
  107. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  108. $data = $field_row['data']; 
  109. foreach( $vals as $k => $v ) { 
  110. $data[$k] = $v; 
  111. $data_array = array('data' => serialize( $data ), 'order' => $field_order); 
  112. $wpdb->update( NINJA_FORMS_FIELDS_TABLE_NAME, $data_array, array( 'id' => $field_id )); 
  113.  
  114. $date_updated = date( 'Y-m-d H:i:s', strtotime ( 'now' ) ); 
  115. Ninja_Forms()->form( $form_id )->update_setting( 'form_title', $form_title ); 
  116. Ninja_Forms()->form( $form_id )->update_setting( 'date_updated', $date_updated ); 
  117. Ninja_Forms()->form( $form_id )->update_setting( 'status', '' ); 
  118.  
  119. // Dump our current form transient. 
  120. delete_transient( 'nf_form_' . $form_id ); 
  121.  
  122. die(); 
  123.  
  124. add_action( 'wp_ajax_nf_admin_save_builder', 'nf_admin_save_builder' ); 
  125.  
  126.  
  127. add_action('wp_ajax_ninja_forms_new_field', 'ninja_forms_new_field'); 
  128. function ninja_forms_new_field() { 
  129. global $wpdb, $ninja_forms_fields; 
  130.  
  131. // Bail if we aren't in the admin 
  132. if ( ! is_admin() ) 
  133. return false; 
  134.  
  135. // Bail if we don't have proper permissions 
  136. if ( ! current_user_can( apply_filters( 'nf_new_field_capabilities', 'manage_options' ) ) ) 
  137. return false; 
  138.  
  139. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  140.  
  141. $type = esc_html( $_REQUEST['type'] ); 
  142. $form_id = absint( $_REQUEST['form_id'] ); 
  143.  
  144. if( isset( $ninja_forms_fields[$type]['name'] ) ) { 
  145. $type_name = $ninja_forms_fields[$type]['name']; 
  146. }else{ 
  147. $type_name = ''; 
  148.  
  149. if( isset( $ninja_forms_fields[$type]['default_label'] ) ) { 
  150. $default_label = $ninja_forms_fields[$type]['default_label']; 
  151. }else{ 
  152. $default_label = ''; 
  153.  
  154. if( isset( $ninja_forms_fields[$type]['edit_options'] ) ) { 
  155. $edit_options = $ninja_forms_fields[$type]['edit_options']; 
  156. }else{ 
  157. $edit_options = ''; 
  158.  
  159. if ( $default_label != '' ) { 
  160. $label = $default_label; 
  161. } else { 
  162. $label = $type_name; 
  163.  
  164. $input_limit_msg = __( 'character(s) left', 'ninja-forms' ); 
  165.  
  166. $data = serialize( array( 'label' => $label, 'input_limit_msg' => $input_limit_msg ) ); 
  167.  
  168. $order = 999; 
  169.  
  170. if($form_id != 0 && $form_id != '') { 
  171. $args = array( 
  172. 'type' => $type,  
  173. 'data' => $data,  
  174. ); 
  175.  
  176. $new_id = ninja_forms_insert_field( $form_id, $args ); 
  177. $new_html = ninja_forms_return_echo('ninja_forms_edit_field', $new_id, true ); 
  178. header("Content-type: application/json"); 
  179. $array = array ('new_id' => $new_id, 'new_type' => $type_name, 'new_html' => $new_html, 'edit_options' => $edit_options, 'new_type_slug' => $type ); 
  180. echo json_encode($array); 
  181. die(); 
  182.  
  183. add_action('wp_ajax_ninja_forms_remove_field', 'ninja_forms_remove_field'); 
  184. function ninja_forms_remove_field() { 
  185. global $wpdb; 
  186.  
  187. // Bail if we aren't in the admin 
  188. if ( ! is_admin() ) 
  189. return false; 
  190.  
  191. // Bail if we don't have proper permissions 
  192. if ( ! current_user_can( apply_filters( 'nf_delete_field_capabilities', 'manage_options' ) ) ) 
  193. return false; 
  194.  
  195. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  196.  
  197. $field_id = absint( $_REQUEST['field_id'] ); 
  198. $form_id = absint( $_REQUEST['form_id'] ); 
  199. $wpdb->query($wpdb->prepare("DELETE FROM ".NINJA_FORMS_FIELDS_TABLE_NAME." WHERE id = %d", $field_id)); 
  200. Ninja_Forms()->form( $form_id )->dump_cache(); 
  201. die(); 
  202.  
  203. add_action('wp_ajax_ninja_forms_add_list_option', 'ninja_forms_add_list_options'); 
  204. function ninja_forms_add_list_options() { 
  205. global $wpdb; 
  206.  
  207. // Bail if we aren't in the admin 
  208. if ( ! is_admin() ) 
  209. return false; 
  210.  
  211. // Bail if we don't have proper permissions 
  212. if ( ! current_user_can( apply_filters( 'nf_new_field_capabilities', 'manage_options' ) ) ) 
  213. return false; 
  214.  
  215. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  216.  
  217. $field_id = absint( $_REQUEST['field_id'] ); 
  218. $x = absint( $_REQUEST['x'] ); 
  219. $hidden_value = esc_html( $_REQUEST['hidden_value'] ); 
  220. ninja_forms_field_list_option_output($field_id, $x, '', $hidden_value); 
  221. die(); 
  222.  
  223. function ninja_forms_insert_fav() { 
  224. global $wpdb, $ninja_forms_fields; 
  225. // Bail if we aren't in the admin 
  226. if ( ! is_admin() ) 
  227. return false; 
  228.  
  229. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  230.  
  231. $fav_id = absint( $_REQUEST['field_id'] ); 
  232. $form_id = absint( $_REQUEST['form_id'] ); 
  233.  
  234. $fav_row = ninja_forms_get_fav_by_id($fav_id); 
  235.  
  236. $data = serialize($fav_row['data']); 
  237. $type = $fav_row['type']; 
  238. $type_name = $ninja_forms_fields[$type]['name']; 
  239.  
  240. if($form_id != 0 && $form_id != '') { 
  241. $args = array( 
  242. 'type' => $type,  
  243. 'data' => $data,  
  244. 'fav_id' => $fav_id,  
  245. ); 
  246. $new_id = ninja_forms_insert_field( $form_id, $args ); 
  247. $new_html = ninja_forms_return_echo('ninja_forms_edit_field', $new_id, true ); 
  248. header("Content-type: application/json"); 
  249. $array = array ('new_id' => $new_id, 'new_type' => $type_name, 'new_html' => $new_html); 
  250. echo json_encode($array); 
  251. die(); 
  252.  
  253.  
  254. add_action('wp_ajax_ninja_forms_insert_fav', 'ninja_forms_insert_fav'); 
  255.  
  256. function ninja_forms_insert_def() { 
  257. global $wpdb, $ninja_forms_fields; 
  258.  
  259. // Bail if we aren't in the admin 
  260. if ( ! is_admin() ) 
  261. return false; 
  262.  
  263. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  264.  
  265. $def_id = absint( $_REQUEST['field_id'] ); 
  266. $form_id = absint( $_REQUEST['form_id'] ); 
  267.  
  268. $def_row = ninja_forms_get_def_by_id($def_id); 
  269.  
  270. $data = serialize($def_row['data']); 
  271. $type = $def_row['type']; 
  272. $type_name = $ninja_forms_fields[$type]['name']; 
  273.  
  274. if($form_id != 0 && $form_id != '') { 
  275. $args = array( 
  276. 'type' => $type,  
  277. 'data' => $data,  
  278. 'def_id' => $def_id,  
  279. ); 
  280. $new_id = ninja_forms_insert_field( $form_id, $args ); 
  281. $new_html = ninja_forms_return_echo('ninja_forms_edit_field', $new_id, true ); 
  282. header("Content-type: application/json"); 
  283. $array = array ('new_id' => $new_id, 'new_type' => $type_name, 'new_html' => $new_html); 
  284. echo json_encode($array); 
  285. die(); 
  286.  
  287. add_action('wp_ajax_ninja_forms_insert_def', 'ninja_forms_insert_def'); 
  288.  
  289. add_action('wp_ajax_ninja_forms_add_fav', 'ninja_forms_add_fav'); 
  290. function ninja_forms_add_fav() { 
  291. global $wpdb; 
  292.  
  293. // Bail if we aren't in the admin 
  294. if ( ! is_admin() ) 
  295. return false; 
  296.  
  297. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  298.  
  299. $field_data = $_REQUEST['field_data']; 
  300. $field_id = absint( $_REQUEST['field_id'] ); 
  301.  
  302. $field_row = ninja_forms_get_field_by_id($field_id); 
  303.  
  304. $field_type = $field_row['type']; 
  305. $form_id = 1; 
  306.  
  307. $data = array(); 
  308.  
  309. foreach($field_data as $key => $val) { 
  310. $key = stripslashes( $key ); 
  311. $key = str_replace('"', '', $key); 
  312. if(strpos($key, '[')) { 
  313. $key = str_replace(']', '', $key); 
  314. $key = explode('[', $key); 
  315. $multi = array(); 
  316. $temp =& $multi; 
  317. $x = 0; 
  318. $count = count($key) - 1; 
  319. foreach ($key as $item) { 
  320. $temp[$item] = array(); 
  321. if($x < $count) { 
  322. $temp =& $temp[$item]; 
  323. }else{ 
  324. $temp[$item] = $val; 
  325. $x++; 
  326. $data = ninja_forms_array_merge_recursive($data, $multi); 
  327. }else{ 
  328. $data[$key] = $val; 
  329.  
  330. $name = stripslashes( esc_html( $_REQUEST['fav_name'] ) ); 
  331. if ( !isset ( $data['label'] ) or empty ( $data['label'] ) ) { 
  332. $data['label'] = $name;  
  333.  
  334. $data = ninja_forms_stripslashes_deep( $data ); 
  335.  
  336. $data = serialize($data); 
  337. $wpdb->insert(NINJA_FORMS_FAV_FIELDS_TABLE_NAME, array('row_type' => 1, 'type' => $field_type, 'order' => 0, 'data' => $data, 'name' => $name)); 
  338. $fav_id = $wpdb->insert_id; 
  339. $update_array = array('fav_id' => $fav_id); 
  340. $wpdb->update( NINJA_FORMS_FIELDS_TABLE_NAME, $update_array, array( 'id' => $field_id )); 
  341.  
  342. $new_html = '<p class="button-controls" id="ninja_forms_insert_fav_field_'.$fav_id.'_p"> 
  343. <a class="button add-new-h2 ninja-forms-insert-fav-field" id="ninja_forms_insert_fav_field_'.$fav_id.'" data-field="' . $fav_id . '" data-type="fav" href="#">'.__($name, 'ninja-forms').'</a> 
  344. </p>'; 
  345.  
  346. header("Content-type: application/json"); 
  347. $array = array ('fav_id' => $fav_id, 'fav_name' => $name, 'link_html' => $new_html); 
  348. echo json_encode($array); 
  349.  
  350. die(); 
  351.  
  352. add_action('wp_ajax_ninja_forms_add_def', 'ninja_forms_add_def'); 
  353. function ninja_forms_add_def() { 
  354. global $wpdb; 
  355.  
  356. // Bail if we aren't in the admin 
  357. if ( ! is_admin() ) 
  358. return false; 
  359.  
  360. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  361.  
  362. $field_data = $_REQUEST['field_data']; 
  363. $field_id = absint( $_REQUEST['field_id'] ); 
  364.  
  365. $field_row = ninja_forms_get_field_by_id($field_id); 
  366.  
  367. $field_type = $field_row['type']; 
  368. $row_type = 0; 
  369.  
  370. $data = array(); 
  371.  
  372. foreach($field_data as $key => $val) { 
  373. $key = str_replace('"', '', $key); 
  374. if(strpos($key, '[')) { 
  375. $key = str_replace(']', '', $key); 
  376. $key = explode('[', $key); 
  377. $multi = array(); 
  378. $temp =& $multi; 
  379. $x = 0; 
  380. $count = count($key) - 1; 
  381. foreach ($key as $item) { 
  382. $temp[$item] = array(); 
  383. if($x < $count) { 
  384. $temp =& $temp[$item]; 
  385. }else{ 
  386. $temp[$item] = $val; 
  387. $x++; 
  388. $data = ninja_forms_array_merge_recursive($data, $multi); 
  389. }else{ 
  390. $data[$key] = $val; 
  391.  
  392. $name = stripslashes( esc_html( $_REQUEST['def_name'] ) ); 
  393. $data['label'] = $name; 
  394. $data = serialize($data); 
  395. $wpdb->insert(NINJA_FORMS_FAV_FIELDS_TABLE_NAME, array('row_type' => $row_type, 'type' => $field_type, 'data' => $data, 'name' => $name)); 
  396. $def_id = $wpdb->insert_id; 
  397. $update_array = array('def_id' => $def_id); 
  398. $wpdb->update( NINJA_FORMS_FIELDS_TABLE_NAME, $update_array, array( 'id' => $field_id )); 
  399.  
  400. $new_html = '<p class="button-controls" id="ninja_forms_insert_def_field_'.$def_id.'_p"> 
  401. <a class="button add-new-h2 ninja-forms-insert-def-field" id="ninja_forms_insert_def_field_'.$def_id.'" name="" href="#">'.__($name, 'ninja-forms').'</a> 
  402. </p>'; 
  403. header("Content-type: application/json"); 
  404. $array = array ('def_id' => $def_id, 'def_name' => $name, 'link_html' => $new_html); 
  405. echo json_encode($array); 
  406.  
  407. die(); 
  408.  
  409. add_action('wp_ajax_ninja_forms_remove_fav', 'ninja_forms_remove_fav'); 
  410. function ninja_forms_remove_fav() { 
  411. global $wpdb, $ninja_forms_fields; 
  412.  
  413. // Bail if we aren't in the admin 
  414. if ( ! is_admin() ) 
  415. return false; 
  416.  
  417. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  418.  
  419. $field_id = absint( $_REQUEST['field_id'] ); 
  420. $field_row = ninja_forms_get_field_by_id($field_id); 
  421. $field_type = $field_row['type']; 
  422. $fav_id = $field_row['fav_id']; 
  423. $wpdb->query($wpdb->prepare("DELETE FROM ".NINJA_FORMS_FAV_FIELDS_TABLE_NAME." WHERE id = %d", $fav_id)); 
  424. $wpdb->update(NINJA_FORMS_FIELDS_TABLE_NAME, array('fav_id' => '' ), array('fav_id' => $fav_id)); 
  425. $type_name = $ninja_forms_fields[$field_type]['name']; 
  426. header("Content-type: application/json"); 
  427. $array = array ('fav_id' => $fav_id, 'type_name' => $type_name); 
  428. echo json_encode($array); 
  429.  
  430. die(); 
  431.  
  432. add_action('wp_ajax_ninja_forms_remove_def', 'ninja_forms_remove_def'); 
  433. function ninja_forms_remove_def() { 
  434. global $wpdb, $ninja_forms_fields; 
  435.  
  436. // Bail if we aren't in the admin 
  437. if ( ! is_admin() ) 
  438. return false; 
  439.  
  440. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  441.  
  442. $field_id = absint( $_REQUEST['field_id'] ); 
  443. $field_row = ninja_forms_get_field_by_id($field_id); 
  444. $field_type = $field_row['type']; 
  445. $def_id = $field_row['def_id']; 
  446. $wpdb->query($wpdb->prepare("DELETE FROM ".NINJA_FORMS_FAV_FIELDS_TABLE_NAME." WHERE id = %d", $def_id)); 
  447. $wpdb->update(NINJA_FORMS_FIELDS_TABLE_NAME, array('def_id' => '' ), array('def_id' => $def_id)); 
  448. $type_name = $ninja_forms_fields[$field_type]['name']; 
  449. header("Content-type: application/json"); 
  450. $array = array ('def_id' => $def_id, 'type_name' => $type_name); 
  451. echo json_encode($array); 
  452.  
  453. die(); 
  454.  
  455. add_action( 'wp_ajax_ninja_forms_side_sortable', 'ninja_forms_side_sortable' ); 
  456. function ninja_forms_side_sortable() { 
  457.  
  458. // Bail if we aren't in the admin 
  459. if ( ! is_admin() ) 
  460. return false; 
  461.  
  462. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  463.  
  464. $plugin_settings = nf_get_settings(); 
  465. $page = esc_html( $_REQUEST['page'] ); 
  466. $tab = esc_html( $_REQUEST['tab'] ); 
  467. $order = ninja_forms_esc_html_deep( $_REQUEST['order'] ); 
  468.  
  469. $plugin_settings['sidebars'][$page][$tab] = $order; 
  470. update_option( 'ninja_forms_settings', $plugin_settings ); 
  471.  
  472. die(); 
  473.  
  474. add_action('wp_ajax_ninja_forms_delete_sub', 'ninja_forms_delete_sub'); 
  475. function ninja_forms_delete_sub($sub_id = '') { 
  476. global $wpdb; 
  477.  
  478. // Bail if we aren't in the admin 
  479. if ( ! is_admin() ) 
  480. return false; 
  481.  
  482. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  483.  
  484. if($sub_id == '') { 
  485. $ajax = true; 
  486. $sub_id = absint( $_REQUEST['sub_id'] ); 
  487. }else{ 
  488. $ajax = false; 
  489.  
  490. $wpdb->query($wpdb->prepare("DELETE FROM ".NINJA_FORMS_SUBS_TABLE_NAME." WHERE id = %d", $sub_id)); 
  491. if( $ajax ) { 
  492. die(); 
  493.  
  494. function ninja_forms_array_merge_recursive() { 
  495. $arrays = func_get_args(); 
  496. $base = array_shift($arrays); 
  497.  
  498. foreach ($arrays as $array) { 
  499. reset($base); //important 
  500. while (list($key, $value) = @each($array)) { 
  501. if (is_array($value) && @is_array($base[$key])) { 
  502. $base[$key] = ninja_forms_array_merge_recursive($base[$key], $value); 
  503. } else { 
  504. $base[$key] = $value; 
  505.  
  506. return $base; 
  507.  
  508. function ninja_forms_import_list_options() { 
  509. // Bail if we aren't in the admin 
  510. if ( ! is_admin() ) 
  511. return false; 
  512.  
  513. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  514.  
  515. $options = $_REQUEST['options']; 
  516. $field_id = absint( $_REQUEST['field_id'] ); 
  517. $options = str_replace('\, ', '-comma-replace-placeholder-', $options ); 
  518. $options = ninja_forms_csv_explode( $options ); 
  519.  
  520. if( is_array( $options ) ) { 
  521. $tmp_array = array(); 
  522. $x = 0; 
  523. foreach( $options as $option ) { 
  524. $label = stripslashes( $option[0] ); 
  525. $value = stripslashes( $option[1] ); 
  526. $calc = stripslashes( $option[2] ); 
  527. $label = str_replace( "''", "", $label ); 
  528. $label = str_replace( "-comma-replace-placeholder-", ", ", $label ); 
  529. $value = str_replace( "''", "", $value ); 
  530. $value = str_replace( "-comma-replace-placeholder-", ", ", $value ); 
  531. $calc = str_replace( "''", "", $calc ); 
  532. $calc = str_replace( "-comma-replace-placeholder-", ", ", $calc ); 
  533. $tmp_array[$x]['label'] = $label; 
  534. $tmp_array[$x]['value'] = $value; 
  535. $tmp_array[$x]['calc'] = $calc; 
  536. $x++; 
  537. $x = 0; 
  538. foreach( $tmp_array as $option ) { 
  539. $hidden = 0; 
  540. ninja_forms_field_list_option_output($field_id, $x, $option, $hidden); 
  541. $x++; 
  542.  
  543. die(); 
  544.  
  545. add_action( 'wp_ajax_ninja_forms_import_list_options', 'ninja_forms_import_list_options' ); 
  546.  
  547. /** 
  548. * 
  549. * Function that outputs a list of terms so that the user can exclude terms from a list selector. 
  550. * 
  551. * @since 2.2.51 
  552. * @return void 
  553. */ 
  554.  
  555. function ninja_forms_list_terms_checkboxes( $field_id = '', $tax_name = '' ) { 
  556.  
  557. // Bail if we aren't in the admin 
  558. if ( ! is_admin() ) 
  559. return false; 
  560.  
  561. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  562.  
  563. if ( $field_id == '' && isset ( $_POST['field_id'] ) ) { 
  564. $field_id = absint( $_POST['field_id'] ); 
  565. }  
  566.  
  567. if ( $tax_name == '' && isset ( $_POST['tax_name'] ) ) { 
  568. $tax_name = esc_html( $_POST['tax_name'] ); 
  569.  
  570. if ( $field_id != '' && $tax_name != '' ) { 
  571. $field = ninja_forms_get_field_by_id( $field_id ); 
  572. if ( isset ( $field['data']['exclude_terms'] ) ) { 
  573. $exclude_terms = $field['data']['exclude_terms']; 
  574. } else { 
  575. $exclude_terms = ''; 
  576.  
  577. $terms = get_terms( $tax_name, array( 'hide_empty' => false ) ); 
  578. if ( is_array ( $terms ) && !empty ( $terms ) ) { 
  579. ?> 
  580. <h4><?php _e( 'Do not show these terms', 'ninja-forms' );?>:</h4> 
  581. <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms]" value=""> 
  582. <?php 
  583. foreach ( $terms as $term ) { 
  584. ?> 
  585. <div> 
  586. <label> 
  587. <input type="checkbox" <?php checked( in_array ( $term->term_id, $exclude_terms ), true );?> name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms][]" value="<?php echo $term->term_id;?>"> 
  588. <?php echo $term->name;?> 
  589. </label> 
  590. </div> 
  591. <?php 
  592.  
  593. if ( isset ( $_POST['from_ajax'] ) && absint( $_POST['from_ajax'] ) == 1 ) { 
  594. die(); 
  595.  
  596. add_action( 'wp_ajax_ninja_forms_list_terms_checkboxes', 'ninja_forms_list_terms_checkboxes' ); 
  597.  
  598. /** 
  599. * 
  600. * Function that outputs a calculation row 
  601. * 
  602. * @since 2.2.28 
  603. * @returns void 
  604. */ 
  605.  
  606. function ninja_forms_add_calc_row() { 
  607. // Bail if we aren't in the admin 
  608. if ( ! is_admin() ) 
  609. return false; 
  610.  
  611. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  612.  
  613. $field_id = absint( $_REQUEST['field_id'] ); 
  614. $c = array( 'calc' => '', 'operator' => 'add', 'value' => '', 'when' => '' ); 
  615. $x = absint( $_REQUEST['x'] ); 
  616.  
  617. ninja_forms_output_field_calc_row( $field_id, $c, $x ); 
  618. die(); 
  619.  
  620. add_action( 'wp_ajax_ninja_forms_add_calc_row', 'ninja_forms_add_calc_row' ); 
  621.  
  622. /** 
  623. *  
  624. * Covert a multi-line CSV string into a 2d array. Follows RFC 4180, allows 
  625. * "cells with ""escaped delimiters""" && multi-line enclosed cells 
  626. * It assumes the CSV file is properly formatted, and doesn't check for errors 
  627. * in CSV format. 
  628. * @param string $str The CSV string 
  629. * @param string $d The delimiter between values 
  630. * @param string $e The enclosing character 
  631. * @param bool $crlf Set to true if your CSV file should return carriage return 
  632. * and line feed (CRLF should be returned according to RFC 4180 
  633. * @return array  
  634. */ 
  635. function ninja_forms_csv_explode( $str, $d=', ', $e='"', $crlf=TRUE ) { 
  636. // Convert CRLF to LF, easier to work with in regex 
  637. if( $crlf ) $str = str_replace("\r\n", "\n", $str); 
  638. // Get rid of trailing linebreaks that RFC4180 allows 
  639. $str = trim($str); 
  640. // Do the dirty work 
  641. if ( preg_match_all( 
  642. '/(?: 
  643. '.$e.'((?:[^'.$e.']|'.$e.$e.')*+)'.$e.'(?:'.$d.'|\n|$) 
  644. # match enclose, then match either non-enclose or double-enclose 
  645. # zero to infinity times (possesive), then match another enclose,  
  646. # followed by a comma, linebreak, or string end 
  647. | ####### OR ####### 
  648. ([^'.$d.'\n]*+)(?:['.$d.'\n]|$) 
  649. # match anything thats not a comma or linebreak zero to infinity 
  650. # times (possesive), then match either a comma or a linebreak or 
  651. # string end 
  652. )/x',  
  653. $str, $ms, PREG_SET_ORDER 
  654. ) === FALSE ) return FALSE; 
  655. // Initialize vars, $r will hold our return data, $i will track which line we're on 
  656. $r = array(); $i = 0; 
  657. // Loop through results 
  658. foreach( $ms as $m ) { 
  659. // If the first group of matches is empty, the cell has no quotes 
  660. if( empty($m[1]) ) 
  661. // Put the CRLF back in if needed 
  662. $r[$i][] = ($crlf == TRUE) ? str_replace("\n", "\r\n", $m[2]) : $m[2]; 
  663. else { 
  664. // The cell was quoted, so we want to convert any "" back to " and 
  665. // any LF back to CRLF, if needed 
  666. $r[$i][] = ($crlf == TRUE) ? 
  667. str_replace( 
  668. array("\n", $e.$e),  
  669. array("\r\n", $e),  
  670. $m[1]) : 
  671. str_replace($e.$e, $e, $m[1]); 
  672. // If the raw match doesn't have a delimiter, it must be the last in the 
  673. // row, so we increment our line count. 
  674. if( substr($m[0], -1) != $d ) 
  675. $i++; 
  676. // An empty array will exist due to $ being a zero-length match, so remove it 
  677. array_pop( $r ); 
  678. return $r; 
  679.  
.