/deprecated/includes/admin/edit-field/li.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. function ninja_forms_edit_field_output_li( $field_id, $new = false ) { 
  4. global $wpdb, $ninja_forms_fields, $nf_rte_editors; 
  5. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  6. $current_tab = ninja_forms_get_current_tab(); 
  7. if ( isset ( $_REQUEST['page'] ) ) { 
  8. $current_page = esc_html( $_REQUEST['page'] ); 
  9. } else { 
  10. $current_page = ''; 
  11.  
  12. $field_type = $field_row['type']; 
  13. $field_data = $field_row['data']; 
  14. $plugin_settings = nf_get_settings(); 
  15.  
  16. if ( isset( $ninja_forms_fields[$field_type]['use_li'] ) && $ninja_forms_fields[$field_type]['use_li'] ) { 
  17.  
  18. if ( isset( $field_row['fav_id'] ) && $field_row['fav_id'] != 0 ) { 
  19. $fav_id = $field_row['fav_id']; 
  20. $fav_row = ninja_forms_get_fav_by_id( $fav_id ); 
  21. if ( empty( $fav_row['name'] ) ) { 
  22. $args = array( 
  23. 'update_array' => array( 
  24. 'fav_id' => '',  
  25. ),  
  26. 'where' => array( 
  27. 'id' => $field_id,  
  28. ),  
  29. ); 
  30.  
  31. ninja_forms_update_field( $args ); 
  32. $fav_id = ''; 
  33. } else { 
  34. $fav_id = ''; 
  35.  
  36. if ( isset( $field_row['def_id'] ) && $field_row['def_id'] != 0 ) { 
  37. $def_id = $field_row['def_id']; 
  38. } else { 
  39. $def_id = ''; 
  40.  
  41. $form_id = $field_row['form_id']; 
  42.  
  43. if ( isset( $ninja_forms_fields[$field_type] ) ) { 
  44. $reg_field = $ninja_forms_fields[$field_type]; 
  45. $type_name = $reg_field['name']; 
  46. $edit_function = $reg_field['edit_function']; 
  47. $edit_options = $reg_field['edit_options']; 
  48. $li_class = $reg_field['li_class']; 
  49.  
  50. if ( $reg_field['nesting'] ) { 
  51. $nesting_class = 'ninja-forms-nest'; 
  52. } else { 
  53. $nesting_class = 'ninja-forms-no-nest'; 
  54. $conditional = $reg_field['conditional']; 
  55.  
  56. $type_class = $field_type.'-li'; 
  57.  
  58. if ( $def_id != 0 && $def_id != '' ) { 
  59. $def_row = ninja_forms_get_def_by_id( $def_id ); 
  60. if ( !empty( $def_row['name'] ) ) { 
  61. $type_name = $def_row['name']; 
  62.  
  63. if ( $fav_id != 0 && $fav_id != '' ) { 
  64. $fav_row = ninja_forms_get_fav_by_id( $fav_id ); 
  65. if ( !empty( $fav_row['name'] ) ) { 
  66. $fav_class = 'ninja-forms-field-remove-fav'; 
  67. $type_name = $fav_row['name']; 
  68. } else { 
  69. $fav_class = 'ninja-forms-field-add-fav'; 
  70.  
  71. if ( isset( $field_data['label'] ) && $field_data['label'] != '' ) { 
  72. $li_label = $field_data['label']; 
  73. } else { 
  74. $li_label = $type_name; 
  75.  
  76. $li_label = apply_filters( 'ninja_forms_edit_field_li_label', $li_label, $field_id ); 
  77.  
  78. $li_label = stripslashes( $li_label ); 
  79. $li_label = ninja_forms_esc_html_deep( $li_label ); 
  80.  
  81. if ( 
  82. isset( $reg_field ) && 
  83. isset( $reg_field['conditional'] ) && 
  84. isset( $reg_field['conditional']['value'] ) && 
  85. isset( $reg_field['conditional']['value']['type'] ) ) { 
  86. $conditional_value_type = $reg_field['conditional']['value']['type']; 
  87. } else { 
  88. $conditional_value_type = ''; 
  89. ?> 
  90. <li id="ninja_forms_field_<?php echo $field_id;?>" class="<?php echo $li_class; ?> <?php echo $nesting_class;?> <?php echo $type_class;?>"> 
  91. <input type="hidden" id="ninja_forms_field_<?php echo $field_id;?>_conditional_value_type" value="<?php echo $conditional_value_type;?>"> 
  92. <input type="hidden" id="ninja_forms_field_<?php echo $field_id;?>_fav_id" name="" class="ninja-forms-field-fav-id" value="<?php echo $fav_id;?>"> 
  93. <dl class="menu-item-bar"> 
  94. <dt class="menu-item-handle" id="ninja_forms_metabox_field_<?php echo $field_id;?>" > 
  95. <span class="item-title ninja-forms-field-title" id="ninja_forms_field_<?php echo $field_id;?>_title"><?php echo $li_label;?></span> 
  96. <span class="item-controls"> 
  97. <span class="item-type"><span class="spinner" style="margin-top:-2px;float:left;"></span><span class="item-type-name"><?php echo $type_name;?></span></span> 
  98. <a class="item-edit nf-edit-field" id="ninja_forms_field_<?php echo $field_id;?>_toggle" title="<?php _e( 'Edit Menu Item', 'ninja-forms' ); ?>" href="#" data-field="<?php echo $field_id; ?>"><?php _e( 'Edit Menu Item' , 'ninja-forms' ); ?></a> 
  99. </span> 
  100. </dt> 
  101. </dl> 
  102. <?php 
  103. if ( $new ) { 
  104. $padding = ''; 
  105. } else { 
  106. $padding = 'no-padding'; 
  107. ?> 
  108. <div class="menu-item-settings type-class inside <?php echo $padding?>" id="ninja_forms_field_<?php echo $field_id;?>_inside" > 
  109. <?php 
  110. if ( $new ) { 
  111. nf_output_registered_field_settings( $field_id ); 
  112. } else { 
  113. if ( isset( $ninja_forms_fields[$field_type] ) ) { 
  114. $reg_field = $ninja_forms_fields[$field_type]; 
  115. $edit_function = $reg_field['edit_function']; 
  116. $arguments = array(); 
  117. $arguments['field_id'] = $field_id; 
  118. $arguments['data'] = $field_data; 
  119.  
  120. if ( $edit_function != '' ) { 
  121. call_user_func_array( $edit_function, $arguments ); 
  122.  
  123. add_action( 'ninja_forms_edit_field_li', 'ninja_forms_edit_field_output_li', 10, 2 ); 
  124.  
  125. function ninja_forms_edit_field_close_li( $field_id ) { 
  126. global $ninja_forms_fields; 
  127. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  128. $field_type = $field_row['type']; 
  129.  
  130. if ( isset( $ninja_forms_fields[$field_type]['use_li'] ) and $ninja_forms_fields[$field_type]['use_li'] ) { 
  131.  
  132. do_action( 'ninja_forms_edit_field_before_closing_li', $field_id ); 
  133. ?> 
  134. </div><!-- .menu-item-settings--> 
  135. </li> 
  136. <?php 
  137. add_action( 'ninja_forms_edit_field_after_li', 'ninja_forms_edit_field_close_li' ); 
  138.  
  139. /** 
  140. * Test fixes for adding dynamic tinyMCE editors 
  141. * 
  142. */ 
  143.  
  144. // used to capture javascript settings generated by the editor 
  145. add_filter( 'tiny_mce_before_init', 'NF_WP_Editor_Ajax::tiny_mce_before_init', 10, 2 ); 
  146. add_filter( 'quicktags_settings', 'NF_WP_Editor_Ajax::quicktags_settings', 10, 2 ); 
  147.  
  148. class NF_WP_Editor_Ajax { 
  149.  
  150. /** 
  151. * AJAX Call Used to Generate the WP Editor 
  152. */ 
  153.  
  154. public static function output_js( $field_id = '', $editors = array() ) { 
  155.  
  156. if ( empty( $field_id ) or empty( $editors ) ) 
  157. return false; 
  158.  
  159. $mce_init = ''; 
  160. $qt_init = ''; 
  161.  
  162. foreach ( $editors as $id ) { 
  163. $mce_init .= self::get_mce_init($id); 
  164. $qt_init .= self::get_qt_init($id); 
  165.  
  166. $mce_init = '{' . trim( $mce_init, ', ' ) . '}'; 
  167. $qt_init = '{' . trim( $qt_init, ', ' ) . '}'; 
  168.  
  169. ?> 
  170. <script type="text/javascript"> 
  171. tinyMCEPreInit.mceInit = jQuery.extend( tinyMCEPreInit.mceInit, <?php echo $mce_init ?>); 
  172. tinyMCEPreInit.qtInit = jQuery.extend( tinyMCEPreInit.qtInit, <?php echo $qt_init ?>); 
  173. nf_ajax_rte_editors = <?php echo json_encode( $editors ); ?>; 
  174. </script> 
  175. <?php 
  176.  
  177. /** 
  178. * Used to retrieve the javascript settings that the editor generates 
  179. */ 
  180.  
  181. private static $mce_settings = array(); 
  182. private static $qt_settings = array(); 
  183.  
  184. public static function quicktags_settings( $qtInit, $editor_id ) { 
  185. self::$qt_settings[ $editor_id ] = $qtInit; 
  186. return $qtInit; 
  187.  
  188. public static function tiny_mce_before_init( $mceInit, $editor_id ) { 
  189. self::$mce_settings[ $editor_id ] = $mceInit; 
  190. return $mceInit; 
  191.  
  192. /** 
  193. * Code copied from _WP_Editors class (modified a little) 
  194. */ 
  195. private static function get_qt_init($editor_id) { 
  196. if ( ! empty( self::$qt_settings[ $editor_id ] ) ) { 
  197. $options = self::_parse_init( self::$qt_settings[ $editor_id ] ); 
  198. $qtInit = "'$editor_id':{$options}, "; 
  199. } else { 
  200. $qtInit = '{}'; 
  201. return $qtInit; 
  202.  
  203. private static function get_mce_init($editor_id) { 
  204. if ( !empty(self::$mce_settings[ $editor_id ]) ) { 
  205. $options = self::_parse_init( self::$mce_settings[ $editor_id ] ); 
  206. $mceInit = "'$editor_id':{$options}, "; 
  207. } else { 
  208. $mceInit = '{}'; 
  209. return $mceInit; 
  210.  
  211. private static function _parse_init($init) { 
  212. $options = ''; 
  213.  
  214. foreach ( $init as $k => $v ) { 
  215. if ( is_bool($v) ) { 
  216. $val = $v ? 'true' : 'false'; 
  217. $options .= $k . ':' . $val . ', '; 
  218. continue; 
  219. } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) { 
  220. $options .= $k . ':' . $v . ', '; 
  221. continue; 
  222. $options .= $k . ':"' . $v . '", '; 
  223.  
  224. return '{' . trim( $options, ' , ' ) . '}'; 
  225.  
  226. function nf_output_registered_field_settings( $field_id, $data = array() ) { 
  227. global $ninja_forms_fields, $nf_rte_editors; 
  228.  
  229. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  230. $field_type = $field_row['type']; 
  231.  
  232. $field_data = empty ( $data ) ? $field_row['data'] : $data; 
  233.  
  234. $current_tab = ninja_forms_get_current_tab(); 
  235. if ( isset ( $_REQUEST['page'] ) ) { 
  236. $current_page = esc_html( $_REQUEST['page'] ); 
  237. } else { 
  238. $current_page = ''; 
  239.  
  240. $reg_field = $ninja_forms_fields[$field_type]; 
  241. $type_name = $reg_field['name']; 
  242. $edit_function = $reg_field['edit_function']; 
  243. $edit_options = $reg_field['edit_options']; 
  244. $edit_settings = $reg_field['edit_settings']; 
  245.  
  246. if ( $reg_field['nesting'] ) { 
  247. $nesting_class = 'ninja-forms-nest'; 
  248. } else { 
  249. $nesting_class = 'ninja-forms-no-nest'; 
  250. $conditional = $reg_field['conditional']; 
  251.  
  252.  
  253. if ( isset( $field_row['fav_id'] ) && $field_row['fav_id'] != 0 ) { 
  254. $fav_id = $field_row['fav_id']; 
  255. $fav_row = ninja_forms_get_fav_by_id( $fav_id ); 
  256. if ( empty( $fav_row['name'] ) ) { 
  257. $args = array( 
  258. 'update_array' => array( 
  259. 'fav_id' => '',  
  260. ),  
  261. 'where' => array( 
  262. 'id' => $field_id,  
  263. ),  
  264. ); 
  265.  
  266. ninja_forms_update_field( $args ); 
  267. $fav_id = ''; 
  268. } else { 
  269. $fav_id = ''; 
  270.  
  271. if ( isset( $field_row['def_id'] ) && $field_row['def_id'] != 0 ) { 
  272. $def_id = $field_row['def_id']; 
  273. } else { 
  274. $def_id = ''; 
  275.  
  276. if ( $fav_id != 0 && $fav_id != '' ) { 
  277. $fav_row = ninja_forms_get_fav_by_id( $fav_id ); 
  278. if ( !empty( $fav_row['name'] ) ) { 
  279. $fav_class = 'ninja-forms-field-remove-fav'; 
  280. $type_name = $fav_row['name']; 
  281. $icon_class = 'filled'; 
  282. } else { 
  283. $fav_class = 'ninja-forms-field-add-fav'; 
  284. $icon_class = 'empty'; 
  285.  
  286. if ( $reg_field['show_field_id'] || $reg_field['show_fav'] ) { 
  287. ?> 
  288. <table id="field-info"> 
  289. <tr> 
  290. <?php 
  291. if ( $reg_field['show_field_id'] ) { 
  292. ?> 
  293. <td width="65%"><?php _e( 'Field ID', 'ninja-forms' ); ?>: <strong><?php echo $field_id;?></strong></td> 
  294. <?php 
  295. ?> 
  296. <!-- <td width="15%"><a href="#" class="ninja-forms-field-add-def" id="ninja_forms_field_<?php echo $field_id;?>_def" class="ninja-forms-field-add-def">Add Defined</a></td><td width="15%"><a href="#" class="ninja-forms-field-remove-def" id="ninja_forms_field_<?php echo $field_id;?>_def">Remove Defined</a></td> --> 
  297. <?php 
  298. if ( $reg_field['show_fav'] ) { 
  299. ?> 
  300. <td width="5%"><a href="#" class="<?php echo $fav_class;?>" id="ninja_forms_field_<?php echo $field_id;?>_fav"><span class="dashicons dashicons-star-<?php echo $icon_class; ?>"></span></a></td> 
  301. <?php 
  302. ?> 
  303. </tr> 
  304. </table> 
  305. <?php 
  306. do_action( 'ninja_forms_edit_field_before_registered', $field_id, $field_data ); 
  307.  
  308. $arguments = array( 'field_id' => $field_id, 'data' => $field_data ); 
  309.  
  310. if ( $edit_function != '' ) { 
  311. call_user_func_array( $edit_function, $arguments ); 
  312.  
  313. /** 
  314. * We need to get a list of all of our RTEs. 
  315. * If we're submitting via ajax, we'll need to use this list. 
  316. */ 
  317. if ( ! isset ( $nf_rte_editors ) ) 
  318. $nf_rte_editors = array(); 
  319.  
  320. $editors = new NF_WP_Editor_Ajax(); 
  321.  
  322. if ( is_array( $edit_options ) and !empty( $edit_options ) ) { 
  323. foreach ( $edit_options as $opt ) { 
  324. $type = $opt['type']; 
  325.  
  326. $label_class = ''; 
  327.  
  328. if ( isset( $opt['label'] ) ) { 
  329. $label = $opt['label']; 
  330. } else { 
  331. $label = ''; 
  332.  
  333. if ( isset( $opt['name'] ) ) { 
  334. $name = $opt['name']; 
  335. } else { 
  336. $name = ''; 
  337.  
  338. if ( isset( $opt['width'] ) ) { 
  339. $width = $opt['width']; 
  340. } else { 
  341. $width = ''; 
  342.  
  343. if ( isset( $opt['options'] ) ) { 
  344. $options = $opt['options']; 
  345. } else { 
  346. $options = ''; 
  347.  
  348. if ( isset( $opt['class'] ) ) { 
  349. $class = $opt['class']; 
  350. } else { 
  351. $class = ''; 
  352.  
  353. if ( isset( $opt['default'] ) ) { 
  354. $default = $opt['default']; 
  355. } else { 
  356. $default = ''; 
  357.  
  358. if ( isset( $opt['desc'] ) ) { 
  359. $desc = $opt['desc']; 
  360. } else { 
  361. $desc = ''; 
  362.  
  363. if ( isset( $field_data[$name] ) ) { 
  364. $value = $field_data[$name]; 
  365. } else { 
  366. $value = $default; 
  367.  
  368. ninja_forms_edit_field_el_output( $field_id, $type, $label, $name, $value, $width, $options, $class, $desc, $label_class ); 
  369.  
  370. add_action( 'nf_edit_field_advanced', 'nf_test', 10, 2 ); 
  371.  
  372. $settings_sections = apply_filters( 'nf_edit_field_settings_sections', array( 
  373. 'restrictions' => __( 'Restriction Settings', 'ninja-forms' ),  
  374. 'calculations' => __( 'Calculation Settings', 'ninja-forms' ),  
  375. 'advanced' => __( 'Advanced Settings', 'ninja-forms' ),  
  376. ) ); 
  377.  
  378. foreach ( $settings_sections as $key => $name ) { 
  379. ?> 
  380. <div class="nf-field-settings description-wide description"> 
  381. <div class="title"> 
  382. <?php echo $name; ?><span class="dashicons dashicons-arrow-down nf-field-sub-section-toggle"></span> 
  383. </div> 
  384. <div class="inside" style="display:none;"> 
  385. <?php 
  386. if ( ! empty ( $edit_settings[ $key ] ) ) { 
  387. foreach ( $edit_settings[ $key ] as $opt ) { 
  388. $type = $opt['type']; 
  389.  
  390. $label_class = ''; 
  391.  
  392. if ( isset( $opt['label'] ) ) { 
  393. $label = $opt['label']; 
  394. } else { 
  395. $label = ''; 
  396.  
  397. if ( isset( $opt['name'] ) ) { 
  398. $name = $opt['name']; 
  399. } else { 
  400. $name = ''; 
  401.  
  402. if ( isset( $opt['width'] ) ) { 
  403. $width = $opt['width']; 
  404. } else { 
  405. $width = ''; 
  406.  
  407. if ( isset( $opt['options'] ) ) { 
  408. $options = $opt['options']; 
  409. } else { 
  410. $options = ''; 
  411.  
  412. if ( isset( $opt['class'] ) ) { 
  413. $class = $opt['class']; 
  414. } else { 
  415. $class = ''; 
  416.  
  417. if ( isset( $opt['default'] ) ) { 
  418. $default = $opt['default']; 
  419. } else { 
  420. $default = ''; 
  421.  
  422. if ( isset( $opt['desc'] ) ) { 
  423. $desc = $opt['desc']; 
  424. } else { 
  425. $desc = ''; 
  426.  
  427. if ( isset( $field_data[$name] ) ) { 
  428. $value = $field_data[$name]; 
  429. } else { 
  430. $value = $default; 
  431.  
  432. ninja_forms_edit_field_el_output( $field_id, $type, $label, $name, $value, $width, $options, $class, $desc, $label_class ); 
  433.  
  434. do_action( 'nf_edit_field_' . $key, $field_id, $field_data ); 
  435. ?> 
  436. </div> 
  437. </div> 
  438. <?php 
  439.  
  440. ?> 
  441. <div class="menu-item-actions description-wide submitbox"> 
  442. <a class="submitdelete deletion nf-remove-field" id="ninja_forms_field_<?php echo $field_id;?>_remove" data-field="<?php echo $field_id; ?>" href="#"><?php _e('Remove', 'ninja-forms'); ?></a> 
  443. </div> 
  444. <?php 
  445.  
  446. if ( ! empty ( $nf_rte_editors ) && isset ( $editors ) && is_object( $editors ) ) { 
  447. $editors->output_js( $field_id, $nf_rte_editors ); 
  448.  
  449.  
  450. function nf_test( $field_id, $field_data ) { 
  451. do_action( 'ninja_forms_edit_field_after_registered', $field_id, $field_data ); 
.