UM_Admin_Builder

The Ultimate Member UM Admin Builder class.

Defined (1)

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

/admin/core/um-admin-builder.php  
  1. class UM_Admin_Builder { 
  2.  
  3. function __construct() { 
  4.  
  5. add_action('wp_ajax_nopriv_update_builder', array(&$this, 'update_builder') ); 
  6. add_action('wp_ajax_update_builder', array(&$this, 'update_builder') ); 
  7.  
  8.  
  9. /*** 
  10. *** @update the builder area 
  11. ***/ 
  12. function update_builder() { 
  13.  
  14. global $ultimatemember; 
  15.  
  16. if ( !is_user_logged_in() || !current_user_can('manage_options') ) die('Please login as administrator'); 
  17.  
  18. extract($_POST); 
  19.  
  20. ob_start(); 
  21.  
  22. $this->form_id = $_POST['form_id']; 
  23.  
  24. $this->show_builder(); 
  25.  
  26. $output = ob_get_contents(); 
  27. ob_end_clean(); 
  28.  
  29. if(is_array($output)) { print_r($output); }else{ echo $output; } die; 
  30.  
  31.  
  32. /*** 
  33. *** @sort array function 
  34. ***/ 
  35. function array_sort_by_column($arr, $col, $dir = SORT_ASC) { 
  36. $sort_col = array(); 
  37. foreach ($arr as $key=> $row) { 
  38. $sort_col[$key] = $row[$col]; 
  39.  
  40. array_multisort($sort_col, $dir, $arr); 
  41. return $arr; 
  42.  
  43. /*** 
  44. *** @get fields in row 
  45. ***/ 
  46. function get_fields_by_row( $row_id ) { 
  47. foreach( $this->global_fields as $key => $array ) { 
  48. if ( !isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) { 
  49. $results[$key] = $array; 
  50. unset( $this->global_fields[$key] ); 
  51. return ( isset ( $results ) ) ? $results : ''; 
  52.  
  53. /*** 
  54. *** @get fields by sub row 
  55. ***/ 
  56. function get_fields_in_subrow( $row_fields, $subrow_id ) { 
  57. if ( !is_array( $row_fields ) ) return ''; 
  58. foreach( $row_fields as $key => $array ) { 
  59. if ( !isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) { 
  60. $results[$key] = $array; 
  61. unset( $this->global_fields[$key] ); 
  62. return ( isset ( $results ) ) ? $results : ''; 
  63.  
  64. /*** 
  65. *** @Display the builder 
  66. ***/ 
  67. function show_builder() { 
  68. global $ultimatemember; 
  69.  
  70. //print_r( get_option('um_form_rowdata_' . $this->form_id ) ); 
  71.  
  72. $fields = $ultimatemember->query->get_attr('custom_fields', $this->form_id ); 
  73.  
  74. if ( !isset( $fields ) || empty( $fields ) ) { ?> 
  75.  
  76. <div class="um-admin-drag-row"> 
  77.  
  78. <!-- Master Row Actions --> 
  79. <div class="um-admin-drag-row-icons"> 
  80. <a href="#" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php _e('Add Row', 'ultimatemember'); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a> 
  81. <a href="#" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php _e('Edit Row', 'ultimatemember'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo $this->form_id; ?>" data-arg3="_um_row_1"><i class="um-faicon-pencil"></i></a> 
  82. <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span> 
  83. </div><div class="um-admin-clear"></div> 
  84.  
  85. <div class="um-admin-drag-rowsubs"> 
  86. <div class="um-admin-drag-rowsub"> 
  87.  
  88. <!-- Column Layout --> 
  89. <div class="um-admin-drag-ctrls columns"> 
  90. <a href="#" class="active" data-cols="1"></a> 
  91. <a href="#" data-cols="2"></a> 
  92. <a href="#" data-cols="3"></a> 
  93. </div> 
  94.  
  95. <!-- Sub Row Actions --> 
  96. <div class="um-admin-drag-rowsub-icons"> 
  97. <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span> 
  98. </div><div class="um-admin-clear"></div> 
  99.  
  100. <!-- Columns --> 
  101. <div class="um-admin-drag-col"> 
  102.  
  103. </div> 
  104.  
  105. <div class="um-admin-drag-col-dynamic"></div> 
  106.  
  107. <div class="um-admin-clear"></div> 
  108.  
  109. </div> 
  110. </div> 
  111.  
  112. </div> 
  113.  
  114. <?php 
  115.  
  116. } else { 
  117.  
  118. $this->global_fields = $fields; 
  119.  
  120. foreach( $this->global_fields as $key => $array ) { 
  121. if ( $array['type'] == 'row' ) { 
  122. $rows[$key] = $array; 
  123. unset( $this->global_fields[ $key ] ); // not needed now 
  124.  
  125.  
  126. if ( !isset( $rows ) ) { 
  127. $rows = array( '_um_row_1' => array( 
  128. 'type' => 'row',  
  129. 'id' => '_um_row_1',  
  130. 'sub_rows' => 1,  
  131. 'cols' => 1 
  132. ); 
  133.  
  134. foreach ( $rows as $row_id => $array ) { 
  135.  
  136. ?> 
  137.  
  138. <div class="um-admin-drag-row" data-original="<?php echo $row_id; ?>"> 
  139.  
  140. <!-- Master Row Actions --> 
  141. <div class="um-admin-drag-row-icons"> 
  142. <a href="#" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php _e('Add Row', 'ultimatemember'); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a> 
  143. <a href="#" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php _e('Edit Row', 'ultimatemember'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo $this->form_id; ?>" data-arg3="<?php echo $row_id; ?>"><i class="um-faicon-pencil"></i></a> 
  144. <span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span> 
  145. <?php if ( $row_id != '_um_row_1' ) {?> 
  146. <a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row', 'ultimatemember'); ?>" data-remove_element="um-admin-drag-row"><i class="um-faicon-trash-o"></i></a> 
  147. <?php } ?> 
  148. </div><div class="um-admin-clear"></div> 
  149.  
  150. <div class="um-admin-drag-rowsubs"> 
  151.  
  152. <?php 
  153.  
  154. $row_fields = $this->get_fields_by_row( $row_id ); 
  155.  
  156. $sub_rows = ( isset( $array['sub_rows'] ) ) ? $array['sub_rows'] : 1; 
  157. for( $c = 0; $c < $sub_rows; $c++ ) { 
  158.  
  159. $subrow_fields = $this->get_fields_in_subrow( $row_fields, $c ); 
  160.  
  161. ?> 
  162.  
  163. <div class="um-admin-drag-rowsub"> 
  164.  
  165. <!-- Column Layout --> 
  166. <div class="um-admin-drag-ctrls columns"> 
  167.  
  168. <?php 
  169.  
  170. if ( !isset( $array['cols'] ) ) { 
  171. $col_num = 1; 
  172. } else { 
  173.  
  174. $col_split = explode(':', $array['cols'] ); 
  175. $col_num = $col_split[$c]; 
  176.  
  177.  
  178. for ( $i = 1; $i <= 3; $i++ ) { 
  179. echo '<a href="#" data-cols="'.$i.'" '; 
  180. if ( $col_num == $i ) echo 'class="active"'; 
  181. echo '></a>'; 
  182.  
  183. ?> 
  184.  
  185. </div> 
  186.  
  187. <!-- Sub Row Actions --> 
  188. <div class="um-admin-drag-rowsub-icons"> 
  189. <span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span> 
  190. <?php if ( $c > 0 ) { ?><a href="#" class="um-admin-tipsy-n" title="Delete Row" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a><?php } ?> 
  191. </div><div class="um-admin-clear"></div> 
  192.  
  193. <!-- Columns --> 
  194. <div class="um-admin-drag-col"> 
  195.  
  196. <?php  
  197.  
  198. if ( is_array( $subrow_fields ) ) { 
  199.  
  200. $subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position'); 
  201.  
  202. foreach( $subrow_fields as $key => $keyarray ) { 
  203. extract( $keyarray ); 
  204.  
  205. ?> 
  206.  
  207. <div class="um-admin-drag-fld um-admin-delete-area um-field-type-<?php echo $type; ?> <?php echo $key; ?>" data-group="<?php echo (isset($keyarray['in_group'])) ? $keyarray['in_group'] : ''; ?>" data-key="<?php echo $key; ?>" data-column="<?php echo ( isset($keyarray['in_column']) ) ? $keyarray['in_column'] : 1; ?>"> 
  208.  
  209. <div class="um-admin-drag-fld-title um-field-type-<?php echo $type; ?>"> 
  210. <?php if ( $type == 'group' ) { ?> 
  211. <i class="um-icon-plus"></i> 
  212. <?php } else if ( isset($keyarray['icon']) && !empty( $keyarray['icon'] ) ) { ?> 
  213. <i class="<?php echo $keyarray['icon']; ?>"></i> 
  214. <?php } ?><?php echo $title; ?></div> 
  215. <?php $field_name = isset( $ultimatemember->builtin->core_fields[$type]['name'] )?$ultimatemember->builtin->core_fields[$type]['name']:''; ?> 
  216. <div class="um-admin-drag-fld-type um-field-type-<?php echo $type; ?>"><?php echo $field_name; ?></div> 
  217. <div class="um-admin-drag-fld-icons um-field-type-<?php echo $type; ?>"> 
  218.  
  219. <a href="#" class="um-admin-tipsy-n" title="Edit" data-modal="UM_edit_field" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="<?php echo $type; ?>" data-arg2="<?php echo $this->form_id; ?>" data-arg3="<?php echo $key; ?>"><i class="um-faicon-pencil"></i></a> 
  220.  
  221. <a href="#" class="um-admin-tipsy-n um_admin_duplicate_field" title="Duplicate" data-silent_action="um_admin_duplicate_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-files-o"></i></a> 
  222.  
  223. <?php if ( $type == 'group' ) { ?> 
  224.  
  225. <a href="#" class="um-admin-tipsy-n" title="Delete Group" data-remove_element="um-admin-drag-fld.um-field-type-group" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a> 
  226. <?php } else { ?> 
  227.  
  228. <a href="#" class="um-admin-tipsy-n" title="Delete" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a> 
  229.  
  230. <?php } ?> 
  231.  
  232. </div><div class="um-admin-clear"></div> 
  233.  
  234. <?php if ( $type == 'group' ) { ?> 
  235. <div class="um-admin-drag-group"> 
  236.  
  237. </div> 
  238. <?php } ?> 
  239.  
  240. </div> 
  241.  
  242. <?php  
  243.  
  244. } // end foreach 
  245.  
  246. } // end if 
  247.  
  248. ?> 
  249.  
  250. </div> 
  251.  
  252. <div class="um-admin-drag-col-dynamic"></div> 
  253.  
  254. <div class="um-admin-clear"></div> 
  255.  
  256. </div> 
  257.  
  258. <?php } ?> 
  259.  
  260. </div> 
  261.  
  262. </div> 
  263.  
  264. <?php 
  265.  
  266. } // rows loop 
  267.  
  268. } // if fields exist 
  269.  
  270.