sidebar.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. function ninja_forms_sidebar_sorter($array, $sequence){
  3. $tmp = array();
  4. foreach($sequence as $s){
  5. foreach($array as $key => $a){
  6. $s = str_replace( 'ninja_forms_metabox_', '', $s );
  7. if($key == $s){
  8. $tmp[$key] = $a;
  9. unset( $array[$key] );
  10. break;
  11. }
  12. }
  13. }
  14. if( is_array( $array ) AND !empty( $array ) ){
  15. foreach( $array as $key => $a ){
  16. $tmp[$key] = $a;
  17. }
  18. }
  19. return $tmp;
  20. }
  21. function ninja_forms_display_sidebars($data){
  22. global $ninja_forms_sidebars;
  23. $current_tab = ninja_forms_get_current_tab();
  24. $current_page = esc_html( $_REQUEST['page'] );
  25. $opt = nf_get_settings();
  26. if( isset( $opt['sidebars'][$current_page][$current_tab] ) ){
  27. $order = $opt['sidebars'][$current_page][$current_tab];
  28. if ( !is_array ( $order ) ) {
  29. $order = array();
  30. }
  31. $ninja_forms_sidebars[$current_page][$current_tab] = ninja_forms_sidebar_sorter( $ninja_forms_sidebars[$current_page][$current_tab], $order );
  32. }
  33. $plugin_settings = nf_get_settings();
  34. ?>
  35. <div id="menu-settings-column" class="metabox-holder">
  36. <div id="side-sortables" class="meta-box-sortables ui-sortable">
  37. <?php
  38. if(isset($ninja_forms_sidebars[$current_page][$current_tab]) AND is_array($ninja_forms_sidebars[$current_page][$current_tab])){
  39. foreach($ninja_forms_sidebars[$current_page][$current_tab] as $slug => $sidebar){
  40. if((isset($opt['screen_options']['tab'][$current_tab]['sidebars'][$slug]['visible']) AND $opt['screen_options']['tab'][$current_tab]['sidebars'][$slug]['visible'] == 1) OR !isset($opt['screen_options']['tab'][$current_tab]['sidebars'][$slug]['visible'])){
  41. if ( isset ( $plugin_settings['metabox_state'][$current_page][$current_tab][$slug] ) ) {
  42. $state = $plugin_settings['metabox_state'][$current_page][$current_tab][$slug];
  43. } else {
  44. $state = '';
  45. }
  46. ?>
  47. <div id="ninja_forms_metabox_<?php echo $slug;?>" class="postbox">
  48. <h3 class="hndl">
  49. <span><?php _e($sidebar['name'], 'ninja-forms');?></span>
  50. </h3>
  51. <span class="item-controls">
  52. <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>
  53. </span>
  54. <div class="inside" id="ninja_forms_sidebar_<?php echo $slug;?>" style="<?php echo $state;?>">
  55. <?php
  56. if(isset($sidebar['display_function']) AND !empty($sidebar['display_function'])){
  57. $sidebar_callback = $sidebar['display_function'];
  58. $arguments = func_get_args();
  59. array_shift($arguments); // We need to remove the first arg ($function_name)
  60. $arguments['slug'] = $slug;
  61. $arguments['data'] = $data;
  62. call_user_func_array($sidebar_callback, $arguments);
  63. }
  64. if(isset($sidebar['settings']) AND !empty($sidebar['settings'])){
  65. foreach($sidebar['settings'] as $option){
  66. if( isset( $option['p_class'] ) ){
  67. $p_class = $option['p_class'];
  68. }else{
  69. $p_class = '';
  70. }
  71. ?>
  72. <p class="field-controls <?php echo $p_class;?>">
  73. <?php
  74. if(isset($option['display_function']) AND !empty($option['display_function'])){
  75. call_user_func_array($option['display_function'], $arguments);
  76. }else{
  77. $name = $option['name'];
  78. if( isset( $option['default_value'] ) ){
  79. $value = $option['default_value'];
  80. }else{
  81. $value = '';
  82. }
  83. if( isset( $data[$name] ) ){
  84. $value = $data[$name];
  85. }
  86. if( isset( $option['class'] ) ){
  87. $class = $option['class'];
  88. }else{
  89. $class = '';
  90. }
  91. switch($option['type']){
  92. case 'checkbox':
  93. ?>
  94. <input type="hidden" name="<?php echo $name;?>" value="0">
  95. <input type="checkbox" name="<?php echo $name;?>" id="<?php echo $name;?>" value="1" <?php checked(1, $value);?>>
  96. <label for="<?php echo $name;?>"><?php _e($option['label'], 'ninja-forms');?></label>
  97. <?php
  98. break;
  99. case 'radio':
  100. ?>
  101. <label for="<?php echo $name;?>"><?php _e($option['label'], 'ninja-forms');?></label>
  102. <?php
  103. if(isset($option['options'])){
  104. $x = 0;
  105. foreach($option['options'] as $option){
  106. ?>
  107. <input type="radio" id="<?php echo $name.'_'.$x;?>" value="<?php echo $option['value'];?>" <?php checked($option['value'], $value);?> name="<?php echo $name;?>">
  108. <label for="<?php echo $name.'_'.$x;?>"><?php echo $option['name'];?></label>
  109. <?php
  110. $x++;
  111. }
  112. }
  113. break;
  114. case 'select':
  115. ?>
  116. <label for="<?php echo $name;?>"><?php _e($option['label'], 'ninja-forms');?></label>
  117. <select name="<?php echo $name;?>" id="<?php echo $name;?>">
  118. <?php
  119. if(isset($option['options'])){
  120. foreach($option['options'] as $option){
  121. ?>
  122. <option value="<?php echo $option['value'];?>" <?php selected($option['value'], $value);?>><?php echo $option['name'];?></option>
  123. <?php
  124. }
  125. }
  126. ?>
  127. </select>
  128. <?php
  129. break;
  130. case 'text':
  131. ?>
  132. <label for="<?php echo $name;?>"><?php _e($option['label'], 'ninja-forms');?></label>
  133. <input type="text" name="<?php echo $name;?>" id="<?php echo $name;?>" value="<?php echo $value;?>">
  134. <?php
  135. break;
  136. case 'textarea':
  137. ?>
  138. <label for="<?php echo $name;?>"><?php _e($option['label'], 'ninja-forms');?></label>
  139. <textarea name="<?php echo $name;?>" id="<?php echo $name;?>"><?php echo $value;?></textarea>
  140. <?php
  141. break;
  142. case 'submit':
  143. ?>
  144. <input type="submit" name="submit" id="" class="<?php echo $class;?>" value="<?php _e( 'View Submissions', 'ninja-forms' );?>">
  145. <?php
  146. break;
  147. }
  148. if(isset($option['help']) AND !empty($option['help'])){
  149. ?>
  150. <a href="#" class="tooltip">
  151. <img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>images/question-ico.gif" title="">
  152. <span>
  153. <img class="callout" src="<?php echo NINJA_FORMS_URL;?>/images/callout.gif" />
  154. <?php _e($option['help'], 'ninja-forms');?>
  155. </span>
  156. </a>
  157. <?php
  158. }
  159. if(isset($option['desc']) AND !empty($option['desc'])){
  160. ?>
  161. <span class="howto"><?php echo $option['desc'];?></span>
  162. <?php
  163. }
  164. }
  165. ?>
  166. </p>
  167. <?php
  168. }
  169. }
  170. ?>
  171. </div>
  172. </div>
  173. <?php
  174. }
  175. }
  176. }
  177. ?>
  178. </div>
  179. <?php
  180. }
  181. ?>