PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/ninja-forms/deprecated/includes/admin/output-tab-metabox.php

https://gitlab.com/lamovible/grand-regis
PHP | 434 lines | 402 code | 31 blank | 1 comment | 80 complexity | a1bab809e9303dd8880e0e1d22bf559a MD5 | raw file
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. function ninja_forms_output_tab_metabox($form_id = '', $slug, $metabox){
  3. $plugin_settings = nf_get_settings();
  4. if($form_id != ''){
  5. $current_settings = Ninja_Forms()->form($form_id)->get_all_settings();
  6. }else{
  7. $form_id = '';
  8. $current_settings = nf_get_settings();
  9. }
  10. $page = $metabox['page'];
  11. $tab = $metabox['tab'];
  12. $title = $metabox['title'];
  13. if(isset($metabox['settings'])){
  14. $settings = $metabox['settings'];
  15. }else{
  16. $settings = '';
  17. }
  18. if(isset($metabox['display_function'])){
  19. $display_function = $metabox['display_function'];
  20. }else{
  21. $display_function = '';
  22. }
  23. if($metabox['state'] == 'closed'){
  24. $state = 'display:none;';
  25. }else{
  26. $state = '';
  27. }
  28. if( isset( $plugin_settings['metabox_state'][$page][$tab][$slug] ) ){
  29. $state = $plugin_settings['metabox_state'][$page][$tab][$slug];
  30. }
  31. if( isset( $metabox['display_container'] ) ){
  32. $display_container = $metabox['display_container'];
  33. }else{
  34. $display_container = true;
  35. }
  36. if( $display_container ){
  37. ?>
  38. <div id="ninja_forms_metabox_<?php echo $slug;?>" class="postbox ">
  39. <span class="item-controls">
  40. <a class="item-edit metabox-item-edit" id="edit_id" title="<?php _e( 'Edit Menu Item', 'ninja-forms' ); ?>" href="#"><?php _e( 'Edit Menu Item', 'ninja-forms' ); ?></a>
  41. </span>
  42. <h3 class="hndle"><span><?php _e($title, 'ninja-forms');?></span></h3>
  43. <div class="inside" style="<?php echo $state;?>">
  44. <table class="form-table">
  45. <tbody>
  46. <?php
  47. }
  48. if( is_array( $settings ) AND !empty( $settings ) ){
  49. foreach( $settings as $s ){
  50. $value = '';
  51. if(isset($s['name'])){
  52. $name = $s['name'];
  53. }else{
  54. $name = '';
  55. }
  56. $name_array = '';
  57. if( strpos( $name, '[') !== false ){
  58. $name_array = str_replace( ']', '', $name );
  59. $name_array = explode( '[', $name_array );
  60. }
  61. if(isset($s['type'])){
  62. $type = $s['type'];
  63. }else{
  64. $type = '';
  65. }
  66. if(isset($s['desc'])){
  67. $desc = $s['desc'];
  68. }else{
  69. $desc = '';
  70. }
  71. if(isset($s['help_text'])){
  72. $help_text = $s['help_text'];
  73. }else{
  74. $help_text = '';
  75. }
  76. if(isset($s['label'])){
  77. $label = $s['label'];
  78. }else{
  79. $label = '';
  80. }
  81. if(isset($s['value'])){
  82. $button_text = $s['value'];
  83. }else{
  84. $button_text = $label;
  85. }
  86. if(isset($s['class'])){
  87. $class = $s['class'];
  88. }else{
  89. $class = 'widefat';
  90. }
  91. if(isset($s['tr_class'])){
  92. $tr_class = $s['tr_class'];
  93. }else{
  94. $tr_class = '';
  95. }
  96. if(isset($s['max_file_size'])){
  97. $max_file_size = $s['max_file_size'];
  98. }else{
  99. $max_file_size = '';
  100. }
  101. if(isset($s['select_all'])){
  102. $select_all = $s['select_all'];
  103. }else{
  104. $select_all = false;
  105. }
  106. if(isset($s['default_value'])){
  107. $default_value = $s['default_value'];
  108. }else{
  109. $default_value = '';
  110. }
  111. if( isset( $s['style'] ) ){
  112. $style = $s['style'];
  113. }else{
  114. $style = '';
  115. }
  116. if(isset($s['size'])){
  117. $size = $s['size'];
  118. }else{
  119. $size = '';
  120. }
  121. if(isset($s['min'])){
  122. $min = $s['min'];
  123. }else{
  124. $min = 0;
  125. }
  126. if(isset($s['max'])){
  127. $max = $s['max'];
  128. }else{
  129. $max = '';
  130. }
  131. if( is_array( $name_array ) ){
  132. $tmp = '';
  133. foreach( $name_array as $n ){
  134. if( $tmp == '' ){
  135. if( isset( $current_settings[$n] ) ){
  136. $tmp = $current_settings[$n];
  137. }
  138. }else{
  139. if( isset( $tmp[$n] ) ){
  140. $tmp = $tmp[$n];
  141. }
  142. }
  143. }
  144. $value = (!is_array ($tmp) && !is_object ($tmp)) ? $tmp : '';
  145. }else{
  146. if(isset($current_settings[$name])){
  147. if(is_array($current_settings[$name])){
  148. $value = ninja_forms_stripslashes_deep($current_settings[$name]);
  149. }else{
  150. $value = stripslashes($current_settings[$name]);
  151. }
  152. }else{
  153. $value = '';
  154. }
  155. }
  156. if( $value == '' ){
  157. $value = $default_value;
  158. }
  159. ?>
  160. <tr id="row_<?php echo $name;?>" <?php if( $tr_class != '' ){ ?>class="<?php echo $tr_class;?>"<?php } ?> <?php if( $style != '' ){ ?> style="<?php echo $style;?>"<?php }?>>
  161. <?php if ( $s['type'] == 'desc' AND ! $label ) { ?>
  162. <td colspan="2">
  163. <?php } else { ?>
  164. <th scope="row">
  165. <label for="<?php echo $name;?>"><?php echo $label;?></label>
  166. </th>
  167. <td>
  168. <?php } ?>
  169. <?php
  170. switch( $s['type'] ){
  171. case 'text':
  172. $value = ninja_forms_esc_html_deep( $value );
  173. ?>
  174. <input type="text" class="code <?php echo $class;?>" name="<?php echo $name;?>" id="<?php echo $name;?>" value="<?php echo $value;?>" />
  175. <?php if( $help_text != ''){ ?>
  176. <a href="#" class="tooltip">
  177. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  178. <span>
  179. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>/images/callout.gif" />
  180. <?php echo $help_text;?>
  181. </span>
  182. </a>
  183. <?php }
  184. break;
  185. case 'number':
  186. $value = ninja_forms_esc_html_deep( $value );
  187. ?>
  188. <input type="number" class="code <?php echo $class;?>" name="<?php echo $name;?>" id="<?php echo $name;?>" value="<?php echo $value;?>" min="<?php echo $min; ?>" max="<?php echo $max; ?>" />
  189. <?php if( $help_text != ''){ ?>
  190. <a href="#" class="tooltip">
  191. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  192. <span>
  193. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>/images/callout.gif" />
  194. <?php echo $help_text;?>
  195. </span>
  196. </a>
  197. <?php }
  198. break;
  199. case 'select':
  200. ?>
  201. <select name="<?php echo $name;?>" id="<?php echo $name;?>" class="<?php echo $class;?>">
  202. <?php
  203. if( is_array( $s['options']) AND !empty( $s['options'] ) ){
  204. foreach( $s['options'] as $option ){
  205. ?>
  206. <option value="<?php echo $option['value'];?>" <?php selected($value, $option['value']); ?>><?php echo $option['name'];?></option>
  207. <?php
  208. }
  209. } ?>
  210. </select>
  211. <?php if( $help_text != ''){ ?>
  212. <a href="#" class="tooltip">
  213. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  214. <span>
  215. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>images/callout.gif" />
  216. <?php echo $help_text;?>
  217. </span>
  218. </a>
  219. <?php }
  220. break;
  221. case 'multi_select':
  222. if( $value == '' ){
  223. $value = array();
  224. }
  225. ?>
  226. <input type="hidden" name="<?php echo $name;?>" value="">
  227. <select name="<?php echo $name;?>[]" id="<?php echo $name;?>" class="<?php echo $class;?>" multiple="multiple" size="<?php echo $size;?>">
  228. <?php
  229. if( is_array( $s['options']) AND !empty( $s['options'] ) ){
  230. foreach( $s['options'] as $option ){
  231. ?>
  232. <option value="<?php echo $option['value'];?>" <?php selected( in_array( $option['value'], $value ) ); ?>><?php echo $option['name'];?></option>
  233. <?php
  234. }
  235. } ?>
  236. </select>
  237. <?php if( $help_text != ''){ ?>
  238. <a href="#" class="tooltip">
  239. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  240. <span>
  241. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>/images/callout.gif" />
  242. <?php echo $help_text;?>
  243. </span>
  244. </a>
  245. <?php }
  246. break;
  247. case 'checkbox':
  248. ?>
  249. <input type="hidden" name="<?php echo $name;?>" value="0">
  250. <input type="checkbox" name="<?php echo $name;?>" value="1" <?php checked($value, 1);?> id="<?php echo $name;?>" class="<?php echo $class;?>">
  251. <?php if( $help_text != ''){ ?>
  252. <a href="#" class="tooltip">
  253. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  254. <span>
  255. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>images/callout.gif" />
  256. <?php echo $help_text;?>
  257. </span>
  258. </a>
  259. <?php }
  260. break;
  261. case 'checkbox_list':
  262. if( $value == '' ){
  263. $value = array();
  264. }
  265. ?>
  266. <input type="hidden" name="<?php echo $name;?>" value="">
  267. <?php
  268. if( $select_all ){
  269. ?>
  270. <label>
  271. <input type="checkbox" name="" value="" id="<?php echo $name;?>_select_all" class="ninja-forms-select-all" title="ninja-forms-<?php echo $name;?>">
  272. - <?php _e( 'Select All', 'ninja-forms' );?>
  273. </label>
  274. <?php
  275. }else{
  276. if( is_array( $s['options'] ) AND isset( $s['options'][0] ) ){
  277. $option_name = $s['options'][0]['name'];
  278. $option_value = $s['options'][0]['value'];
  279. ?>
  280. <label>
  281. <input type="checkbox" class="ninja-forms-<?php echo $name;?> <?php echo $class;?>" name="<?php echo $name;?>[]" value="<?php echo $option_value;?>" <?php checked( in_array( $option_value, $value ) );?> id="<?php echo $option_name;?>">
  282. <?php echo $option_name;?>
  283. </label>
  284. <?php
  285. }
  286. }
  287. ?>
  288. <?php
  289. if( is_array( $s['options'] ) AND !empty( $s['options'] ) ){
  290. $x = 0;
  291. foreach( $s['options'] as $option ){
  292. if( ( !$select_all AND $x > 0 ) OR $select_all ){
  293. $option_name = $option['name'];
  294. $option_value = $option['value'];
  295. ?>
  296. <label>
  297. <input type="checkbox" class="ninja-forms-<?php echo $name;?> <?php echo $class;?>" name="<?php echo $name;?>[]" value="<?php echo $option_value;?>" <?php checked( in_array( $option_value, $value ) );?> id="<?php echo $option_name;?>">
  298. <?php echo $option_name;?>
  299. </label>
  300. <?php
  301. }
  302. $x++;
  303. }
  304. }
  305. break;
  306. case 'radio':
  307. if( is_array( $s['options'] ) AND !empty( $s['options'] ) ){
  308. $x = 0; ?>
  309. <?php foreach($s['options'] as $option){ ?>
  310. <input type="radio" name="<?php echo $name;?>" value="<?php echo $option['value'];?>" id="<?php echo $name."_".$x;?>" <?php checked($value, $option['value']);?> class="<?php echo $class;?>"> <label for="<?php echo $name."_".$x;?>"><?php echo $option['name'];?></label>
  311. <?php
  312. $radio_help_text = isset($option['help_text']) ? $option['help_text'] : $help_text;
  313. if( $radio_help_text != ''){ ?>
  314. <a href="#" class="tooltip">
  315. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  316. <span>
  317. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>images/callout.gif" />
  318. <?php echo $radio_help_text;?>
  319. </span>
  320. </a>
  321. <?php } ?>
  322. <br />
  323. <?php
  324. $x++;
  325. }
  326. }
  327. break;
  328. case 'textarea':
  329. $value = ninja_forms_esc_html_deep( $value );
  330. ?>
  331. <textarea name="<?php echo $name;?>" id="<?php echo $name;?>" class="<?php echo $class;?>"><?php echo $value;?></textarea>
  332. <?php
  333. break;
  334. case 'rte':
  335. $args = apply_filters( 'ninja_forms_admin_metabox_rte', array() );
  336. wp_editor( $value, $name, $args );
  337. break;
  338. case 'file':
  339. ?>
  340. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size;?>" />
  341. <input type="file" name="<?php echo $name;?>" id="<?php echo $name;?>" class="<?php echo $class;?>">
  342. <?php
  343. break;
  344. case 'desc':
  345. echo $desc;
  346. break;
  347. case 'hidden':
  348. ?>
  349. <input type="hidden" name="<?php echo $name;?>" id="<?php echo $name;?>" value="<?php echo $value;?>">
  350. <?php
  351. break;
  352. case 'submit':
  353. ?>
  354. <input type="submit" name="<?php echo $name;?>" class="<?php echo $class; ?>" value="<?php echo $button_text;?>">
  355. <?php
  356. break;
  357. case 'button':
  358. // set a default value for $class to maintain the standard WordPress UI
  359. if( isset( $class ) && empty( $class ) ) {
  360. $class = "button-secondary";
  361. }
  362. ?>
  363. <input type="button" name="<?php echo $name;?>" id="<?php echo $name;?>" class="<?php echo $class; ?>" value="<?php echo $button_text;?>">
  364. <?php
  365. break;
  366. default:
  367. if( isset( $s['display_function'] ) ){
  368. $s_display_function = $s['display_function'];
  369. if( $s_display_function != '' ){
  370. $arguments['form_id'] = $form_id;
  371. $arguments['data'] = $current_settings;
  372. $arguments['field'] = $s;
  373. call_user_func_array( $s_display_function, $arguments );
  374. }
  375. }
  376. break;
  377. }
  378. if( $desc != '' AND $s['type'] != 'desc' ){
  379. ?>
  380. <p class="description">
  381. <?php echo $desc;?>
  382. </p>
  383. <?php
  384. }
  385. echo '</td></tr>';
  386. }
  387. }
  388. if( $display_function != '' ){
  389. if( $form_id != '' ){
  390. $arguments['form_id'] = $form_id;
  391. }
  392. $arguments['metabox'] = $metabox;
  393. call_user_func_array( $display_function, $arguments );
  394. }
  395. if( $display_container ){
  396. ?>
  397. </tbody>
  398. </table>
  399. </div>
  400. </div>
  401. <?php
  402. }
  403. }