SimpleCalendarFeedsAdminGrouped_Calendars_Admin

Grouped calendars feed admin.

Defined (1)

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

/includes/feeds/admin/grouped-calendars-admin.php  
  1. class Grouped_Calendars_Admin { 
  2.  
  3. /** 
  4. * Grouped Calendars feed object. 
  5. * @access private 
  6. * @var Grouped_Calendars 
  7. */ 
  8. private $feed = null; 
  9.  
  10. /** 
  11. * Hook in tabs. 
  12. * @since 3.0.0 
  13. * @param Grouped_Calendars $feed 
  14. */ 
  15. public function __construct( Grouped_Calendars $feed ) { 
  16.  
  17. $this->feed = $feed; 
  18.  
  19. if ( 'calendar' == simcal_is_admin_screen() ) { 
  20. add_filter( 'simcal_settings_meta_tabs_li', array( $this, 'add_settings_meta_tab_li' ), 10, 1 ); 
  21. add_action( 'simcal_settings_meta_panels', array( $this, 'add_settings_meta_panel' ), 10, 1 ); 
  22. add_action( 'simcal_process_settings_meta', array( $this, 'process_meta' ), 10, 1 ); 
  23.  
  24. /** 
  25. * Add a tab to the settings meta box. 
  26. * @since 3.0.0 
  27. * @param array $tabs 
  28. * @return array 
  29. */ 
  30. public function add_settings_meta_tab_li( $tabs ) { 
  31. return array_merge( $tabs, array( 
  32. 'grouped-calendars' => array( 
  33. 'label' => $this->feed->name,  
  34. 'target' => 'grouped-calendars-settings-panel',  
  35. 'class' => array( 
  36. 'simcal-feed-type',  
  37. 'simcal-feed-type-grouped-calendars',  
  38. ),  
  39. 'icon' => 'simcal-icon-docs',  
  40. ),  
  41. )); 
  42.  
  43. /** 
  44. * Add a panel to the settings meta box. 
  45. * @since 3.0.0 
  46. * @param int $post_id 
  47. */ 
  48. public function add_settings_meta_panel( $post_id ) { 
  49.  
  50. ?> 
  51. <div id="grouped-calendars-settings-panel" class="simcal-panel"> 
  52. <table> 
  53. <thead> 
  54. <tr><th colspan="2"><?php _e( 'Grouped Calendar Settings', 'google-calendar-events' ); ?></th></tr> 
  55. </thead> 
  56. <tbody class="simcal-panel-section"> 
  57. <tr class="simcal-panel-field"> 
  58. <th><label for="_grouped_calendars_source"><?php _e( 'Get Calendars From', 'google-calendar-events' ); ?></label></th> 
  59. <td> 
  60. <?php 
  61.  
  62. $source = esc_attr( get_post_meta( $post_id, '_grouped_calendars_source', true ) ); 
  63. $source = empty( $source ) ? 'ids' : $source; 
  64.  
  65. ?> 
  66. <select name="_grouped_calendars_source" 
  67. id="_grouped_calendars_source" 
  68. class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" 
  69. data-show-field-on-choice="true"> 
  70. <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected( 'ids', $source, true ); ?>><?php _e( 'Manual selection', 'google-calendar-events' ); ?></option> 
  71. <option value="category" data-show-field="_grouped_calendars_category" <?php selected( 'category', $source, true ); ?>><?php _e( 'Category', 'google-calendar-events' ); ?></option> 
  72. </select> 
  73. <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events' ); ?>"></i> 
  74. <br><br> 
  75. <?php 
  76.  
  77. $cals = simcal_get_calendars( $post_id ); 
  78. $meta = get_post_meta( $post_id, '_grouped_calendars_ids', true ); 
  79. $ids = $meta && is_array( $meta ) ? implode( ', ', array_map( 'absint', $meta ) ) : absint( $meta ); 
  80.  
  81. simcal_print_field( array( 
  82. 'type' => 'select',  
  83. 'multiselect' => 'multiselect',  
  84. 'name' => '_grouped_calendars_ids',  
  85. 'id' => '_grouped_calendars_ids',  
  86. 'value' => $ids !== 0 ? $ids : '',  
  87. 'options' => $cals,  
  88. 'enhanced' => 'enhanced',  
  89. 'style' => 'ids' == $source ? '' : array( 'display' => 'none' ),  
  90. 'attributes' => array( 
  91. 'data-noresults' => __( 'No results found.', 'google-calendar-events' ),  
  92. ),  
  93. )); 
  94.  
  95. $meta = get_post_meta( $post_id, '_grouped_calendars_category', true ); 
  96. $category = $meta && is_array( $meta ) ? implode( ', ', array_map( 'absint', $meta ) ): ''; 
  97.  
  98. $terms = get_terms( 'calendar_category' ); 
  99.  
  100. if ( ! empty( $terms ) ) { 
  101.  
  102. $categories = array(); 
  103. foreach ( $terms as $term ) { 
  104. $categories[ $term->term_id ] = $term->name; 
  105.  
  106. simcal_print_field( array( 
  107. 'type' => 'select',  
  108. 'multiselect' => 'multiselect',  
  109. 'name' => '_grouped_calendars_category',  
  110. 'id' => '_grouped_calendars_category',  
  111. 'value' => $category,  
  112. 'options' => $categories,  
  113. 'enhanced' => 'enhanced',  
  114. 'style' => 'category' == $source ? '' : array( 'display' => 'none' ),  
  115. 'attributes' => array( 
  116. 'data-noresults' => __( 'No results found.', 'google-calendar-events' ),  
  117. ),  
  118. ) ); 
  119.  
  120. } else { 
  121.  
  122. $style = 'category' == $source ? '' : 'display: none;'; 
  123. $style .= ' width: 100%; max-width: 500px'; 
  124. echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="' . $style . '" placeholder="' . __( 'There are no calendar categories yet.', 'google-calendar-events' ) . '" />'; 
  125.  
  126.  
  127. ?> 
  128. </td> 
  129. </tr> 
  130. </tbody> 
  131. </table> 
  132. </div> 
  133. <?php 
  134.  
  135.  
  136. /** 
  137. * Process meta fields. 
  138. * @since 3.0.0 
  139. * @param int $post_id 
  140. */ 
  141. public function process_meta( $post_id ) { 
  142.  
  143. $source = isset( $_POST['_grouped_calendars_source'] ) ? sanitize_key( $_POST['_grouped_calendars_source'] ) : 'ids'; 
  144. update_post_meta( $post_id, '_grouped_calendars_source', $source ); 
  145.  
  146. $ids = isset( $_POST['_grouped_calendars_ids'] ) ? array_map( 'absint', $_POST['_grouped_calendars_ids'] ) : ''; 
  147. update_post_meta( $post_id, '_grouped_calendars_ids', $ids ); 
  148.  
  149. $category = isset( $_POST['_grouped_calendars_category'] ) ? array_map( 'absint', $_POST['_grouped_calendars_category'] ) : ''; 
  150. update_post_meta( $post_id, '_grouped_calendars_category', $category ); 
  151.  
  152.