PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/events-manager/classes/em-event-posts-admin.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 280 lines | 246 code | 14 blank | 20 comment | 48 complexity | ce3859ff30b3776b95af6283c00e38d7 MD5 | raw file
  1. <?php
  2. class EM_Event_Posts_Admin{
  3. function init(){
  4. global $pagenow;
  5. if( $pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == EM_POST_TYPE_EVENT ){ //only needed for events list
  6. if( !empty($_REQUEST['category_id']) && is_numeric($_REQUEST['category_id']) ){
  7. $term = get_term_by('id', $_REQUEST['category_id'], EM_TAXONOMY_CATEGORY);
  8. if( !empty($term->slug) ){
  9. $_REQUEST['category_id'] = $term->slug;
  10. }
  11. }
  12. //hide some cols by default:
  13. $screen = 'edit-'.EM_POST_TYPE_EVENT;
  14. $hidden = get_user_option( 'manage' . $screen . 'columnshidden' );
  15. if( !$hidden ){
  16. $hidden = array('event-id');
  17. update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
  18. }
  19. //deal with actions
  20. $row_action_type = is_post_type_hierarchical( EM_POST_TYPE_EVENT ) ? 'page_row_actions' : 'post_row_actions';
  21. add_filter($row_action_type, array('EM_Event_Posts_Admin','row_actions'),10,2);
  22. add_action('admin_head', array('EM_Event_Posts_Admin','admin_head'));
  23. //collumns
  24. add_filter('manage_edit-'.EM_POST_TYPE_EVENT.'_columns' , array('EM_Event_Posts_Admin','columns_add'));
  25. add_filter('manage_'.EM_POST_TYPE_EVENT.'_posts_custom_column' , array('EM_Event_Posts_Admin','columns_output'),10,2 );
  26. //TODO alter views of locations, events and recurrences, specifically find a good way to alter the wp_count_posts method to force user owned posts only
  27. //add_filter('views_edit-'.EM_POST_TYPE_EVENT, array('EM_Event_Posts_Admin','views'),10,1);
  28. }
  29. add_action('restrict_manage_posts', array('EM_Event_Posts_Admin','restrict_manage_posts'));
  30. }
  31. function admin_head(){
  32. //quick hacks to make event admin table make more sense for events
  33. ?>
  34. <script type="text/javascript">
  35. jQuery(document).ready( function($){
  36. $('.inline-edit-date').prev().css('display','none').next().css('display','none').next().css('display','none');
  37. $('.em-detach-link').click(function( event ){
  38. if( !confirm(EM.event_detach_warning) ){
  39. event.preventDefault();
  40. return false;
  41. }
  42. });
  43. $('.em-delete-recurrence-link').click(function( event ){
  44. if( !confirm(EM.delete_recurrence_warning) ){
  45. event.preventDefault();
  46. return false;
  47. }
  48. });
  49. });
  50. </script>
  51. <style>
  52. table.fixed{ table-layout:auto !important; }
  53. .tablenav select[name="m"] { display:none; }
  54. </style>
  55. <?php
  56. }
  57. function restrict_manage_posts(){
  58. global $wp_query;
  59. if( $wp_query->query_vars['post_type'] == EM_POST_TYPE_EVENT || $wp_query->query_vars['post_type'] == 'event-recurring' ){
  60. ?>
  61. <select name="scope">
  62. <?php
  63. $scope = (!empty($wp_query->query_vars['scope'])) ? $wp_query->query_vars['scope']:'future';
  64. foreach ( em_get_scopes() as $key => $value ) {
  65. $selected = "";
  66. if ($key == $scope)
  67. $selected = "selected='selected'";
  68. echo "<option value='$key' $selected>$value</option> ";
  69. }
  70. ?>
  71. </select>
  72. <?php
  73. if( get_option('dbem_categories_enabled') ){
  74. //Categories
  75. $selected = !empty($_GET['event-categories']) ? $_GET['event-categories'] : 0;
  76. wp_dropdown_categories(array( 'hide_empty' => 1, 'name' => 'event-categories',
  77. 'hierarchical' => true, 'orderby'=>'name', 'id' => EM_TAXONOMY_CATEGORY,
  78. 'taxonomy' => EM_TAXONOMY_CATEGORY, 'selected' => $selected,
  79. 'show_option_all' => __('View all categories')));
  80. }
  81. if( !empty($_REQUEST['author']) ){
  82. ?>
  83. <input type="hidden" name="author" value="<?php echo $_REQUEST['author'] ?>" />
  84. <?php
  85. }
  86. }
  87. }
  88. function views($views){
  89. if( !current_user_can('edit_others_events') ){
  90. //alter the views to reflect correct numbering
  91. }
  92. return $views;
  93. }
  94. function columns_add($columns) {
  95. if( array_key_exists('cb', $columns) ){
  96. $cb = $columns['cb'];
  97. unset($columns['cb']);
  98. $id_array = array('cb'=>$cb, 'event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  99. }else{
  100. $id_array = array('event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  101. }
  102. unset($columns['comments']);
  103. unset($columns['date']);
  104. unset($columns['author']);
  105. $columns = array_merge($id_array, $columns, array(
  106. 'location' => __('Location','dbem'),
  107. 'date-time' => __('Date and Time','dbem'),
  108. 'author' => __('Owner','dbem'),
  109. 'extra' => ''
  110. ));
  111. if( !get_option('dbem_locations_enabled') ){
  112. unset($columns['location']);
  113. }
  114. return $columns;
  115. }
  116. function columns_output( $column ) {
  117. global $post, $EM_Event;
  118. $EM_Event = em_get_event($post, 'post_id');
  119. /* @var $post EM_Event */
  120. switch ( $column ) {
  121. case 'event-id':
  122. echo $EM_Event->event_id;
  123. break;
  124. case 'location':
  125. //get meta value to see if post has location, otherwise
  126. $EM_Location = $EM_Event->get_location();
  127. if( !empty($EM_Location->location_id) ){
  128. echo "<strong>" . $EM_Location->location_name . "</strong><br/>" . $EM_Location->location_address . " - " . $EM_Location->location_town;
  129. }else{
  130. echo __('None','dbem');
  131. }
  132. break;
  133. case 'date-time':
  134. //get meta value to see if post has location, otherwise
  135. $localised_start_date = date_i18n(get_option('date_format'), $EM_Event->start);
  136. $localised_end_date = date_i18n(get_option('date_format'), $EM_Event->end);
  137. echo $localised_start_date;
  138. echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'';
  139. echo "<br />";
  140. if(!$EM_Event->event_all_day){
  141. echo date_i18n(get_option('time_format'), $EM_Event->start) . " - " . date_i18n(get_option('time_format'), $EM_Event->end);
  142. }else{
  143. echo get_option('dbem_event_all_day_message');
  144. }
  145. break;
  146. case 'extra':
  147. if( get_option('dbem_rsvp_enabled') == 1 && !empty($EM_Event->event_rsvp) && $EM_Event->can_manage('manage_bookings','manage_others_bookings')){
  148. ?>
  149. <a href="<?php echo $EM_Event->get_bookings_url(); ?>"><?php echo __("Bookings",'dbem'); ?></a> &ndash;
  150. <?php _e("Booked",'dbem'); ?>: <?php echo $EM_Event->get_bookings()->get_booked_spaces()."/".$EM_Event->get_spaces(); ?>
  151. <?php if( get_option('dbem_bookings_approval') == 1 ): ?>
  152. | <?php _e("Pending",'dbem') ?>: <?php echo $EM_Event->get_bookings()->get_pending_spaces(); ?>
  153. <?php endif;
  154. echo ($EM_Event->is_recurrence()) ? '<br />':'';
  155. }
  156. if ( $EM_Event->is_recurrence() && $EM_Event->can_manage('edit_recurring_events','edit_others_recurring_events') ) {
  157. $recurrence_delete_confirm = __('WARNING! You will delete ALL recurrences of this event, including booking history associated with any event in this recurrence. To keep booking information, go to the relevant single event and save it to detach it from this recurrence series.','dbem');
  158. ?>
  159. <strong>
  160. <?php echo $EM_Event->get_recurrence_description(); ?> <br />
  161. </strong>
  162. <div class="row-actions">
  163. <a href="<?php echo admin_url(); ?>post.php?action=edit&amp;post=<?php echo $EM_Event->get_event_recurrence()->post_id ?>"><?php _e ( 'Edit Recurring Events', 'dbem' ); ?></a> | <span class="trash"><a class="em-delete-recurrence-link" href="<?php echo get_delete_post_link($EM_Event->get_event_recurrence()->post_id); ?>"><?php _e('Delete','dbem'); ?></a></span> | <a class="em-detach-link" href="<?php echo $EM_Event->get_detach_url(); ?>"><?php _e('Detach', 'dbem'); ?></a>
  164. </div>
  165. <?php
  166. }
  167. break;
  168. }
  169. }
  170. function row_actions($actions, $post){
  171. if($post->post_type == EM_POST_TYPE_EVENT){
  172. global $post, $EM_Event;
  173. $EM_Event = em_get_event($post, 'post_id');
  174. $actions['duplicate'] = '<a href="'.admin_url().'edit.php?action=event_duplicate&amp;event_id='.$EM_Event->event_id.'&amp;_wpnonce='.wp_create_nonce('event_duplicate_'.$EM_Event->event_id).'" title="'.sprintf(__('Duplicate %s','dbem'), __('Event','dbem')).'">'.__('Duplicate','dbem').'</a>';
  175. }
  176. return $actions;
  177. }
  178. }
  179. add_action('admin_init', array('EM_Event_Posts_Admin','init'));
  180. /*
  181. * Recurring Events
  182. */
  183. class EM_Event_Recurring_Posts_Admin{
  184. function init(){
  185. global $pagenow;
  186. if( $pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'event-recurring' ){
  187. //hide some cols by default:
  188. $screen = 'edit-'.EM_POST_TYPE_EVENT;
  189. $hidden = get_user_option( 'manage' . $screen . 'columnshidden' );
  190. if( !$hidden ){
  191. $hidden = array('event-id');
  192. update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
  193. }
  194. //notices
  195. add_action('admin_notices',array('EM_Event_Recurring_Posts_Admin','admin_notices'));
  196. add_action('admin_head', array('EM_Event_Recurring_Posts_Admin','admin_head'));
  197. //collumns
  198. add_filter('manage_edit-event-recurring_columns' , array('EM_Event_Recurring_Posts_Admin','columns_add'));
  199. add_filter('manage_posts_custom_column' , array('EM_Event_Recurring_Posts_Admin','columns_output'),10,1 );
  200. add_action('restrict_manage_posts', array('EM_Event_Posts_Admin','restrict_manage_posts'));
  201. }
  202. }
  203. function admin_notices(){
  204. $warning = sprintf(__( 'Modifications to these events will cause all recurrences of each event to be deleted and recreated and previous bookings will be deleted! You can edit individual recurrences and detach them from recurring events by visiting the <a href="%s">events page</a>.', 'dbem' ), admin_url().'edit.php?post_type='.EM_POST_TYPE_EVENT);
  205. ?><div class="updated"><p><?php echo $warning; ?></p></div><?php
  206. }
  207. function admin_head(){
  208. //quick hacks to make event admin table make more sense for events
  209. ?>
  210. <script type="text/javascript">
  211. jQuery(document).ready( function($){
  212. $('.inline-edit-date').prev().css('display','none').next().css('display','none').next().css('display','none');
  213. if(!EM.recurrences_menu){
  214. $('#menu-posts-'+EM.event_post_type+', #menu-posts-'+EM.event_post_type+' > a').addClass('wp-has-current-submenu');
  215. }
  216. });
  217. </script>
  218. <style>
  219. table.fixed{ table-layout:auto !important; }
  220. .tablenav select[name="m"] { display:none; }
  221. </style>
  222. <?php
  223. }
  224. function columns_add($columns) {
  225. if( array_key_exists('cb', $columns) ){
  226. $cb = $columns['cb'];
  227. unset($columns['cb']);
  228. $id_array = array('cb'=>$cb, 'event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  229. }else{
  230. $id_array = array('event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  231. }
  232. unset($columns['comments']);
  233. unset($columns['date']);
  234. unset($columns['author']);
  235. return array_merge($id_array, $columns, array(
  236. 'location' => __('Location'),
  237. 'date-time' => __('Date and Time'),
  238. 'author' => __('Owner','dbem'),
  239. ));
  240. }
  241. function columns_output( $column ) {
  242. global $post, $EM_Event;
  243. if( $post->post_type == 'event-recurring' ){
  244. $post = $EM_Event = em_get_event($post);
  245. /* @var $post EM_Event */
  246. switch ( $column ) {
  247. case 'event-id':
  248. echo $EM_Event->event_id;
  249. break;
  250. case 'location':
  251. //get meta value to see if post has location, otherwise
  252. $EM_Location = $EM_Event->get_location();
  253. if( !empty($EM_Location->location_id) ){
  254. echo "<strong>" . $EM_Location->location_name . "</strong><br/>" . $EM_Location->location_address . " - " . $EM_Location->location_town;
  255. }else{
  256. echo __('None','dbem');
  257. }
  258. break;
  259. case 'date-time':
  260. echo $EM_Event->get_recurrence_description();
  261. break;
  262. }
  263. }
  264. }
  265. }
  266. add_action('admin_init', array('EM_Event_Recurring_Posts_Admin','init'));