PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/antonyravel/cape-resorts
PHP | 293 lines | 249 code | 24 blank | 20 comment | 45 complexity | 08885cd1cc515d06cfb00f0bad55d240 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. $post_types = arrConst::get(POSTTYPE);
  60. if( $wp_query->query_vars['post_type'] == EM_POST_TYPE_EVENT || in_array($wp_query->query_vars['post_type'], $post_types) ){
  61. ?>
  62. <select name="scope">
  63. <?php
  64. $scope = (!empty($wp_query->query_vars['scope'])) ? $wp_query->query_vars['scope']:'future';
  65. foreach ( em_get_scopes() as $key => $value ) {
  66. $selected = "";
  67. if ($key == $scope)
  68. $selected = "selected='selected'";
  69. echo "<option value='$key' $selected>$value</option> ";
  70. }
  71. ?>
  72. </select>
  73. <?php
  74. if( get_option('dbem_categories_enabled') ){
  75. //Categories
  76. $selected = !empty($_GET['event-categories']) ? $_GET['event-categories'] : 0;
  77. wp_dropdown_categories(array( 'hide_empty' => 1, 'name' => EM_TAXONOMY_CATEGORY,
  78. 'hierarchical' => true, 'orderby'=>'name', 'id' => EM_TAXONOMY_CATEGORY,
  79. 'taxonomy' => EM_TAXONOMY_CATEGORY, 'selected' => $selected,
  80. 'show_option_all' => __('View all categories')));
  81. }
  82. if( !empty($_REQUEST['author']) ){
  83. ?>
  84. <input type="hidden" name="author" value="<?php echo esc_attr($_REQUEST['author']); ?>" />
  85. <?php
  86. }
  87. }
  88. }
  89. function views($views){
  90. if( !current_user_can('edit_others_events') ){
  91. //alter the views to reflect correct numbering
  92. }
  93. return $views;
  94. }
  95. function columns_add($columns) {
  96. if( array_key_exists('cb', $columns) ){
  97. $cb = $columns['cb'];
  98. unset($columns['cb']);
  99. $id_array = array('cb'=>$cb, 'event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  100. }else{
  101. $id_array = array('event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  102. }
  103. unset($columns['comments']);
  104. unset($columns['date']);
  105. unset($columns['author']);
  106. $columns = array_merge($id_array, $columns, array(
  107. 'location' => __('Location','dbem'),
  108. 'date-time' => __('Date and Time','dbem'),
  109. 'author' => __('Owner','dbem'),
  110. 'extra' => ''
  111. ));
  112. if( !get_option('dbem_locations_enabled') ){
  113. unset($columns['location']);
  114. }
  115. return $columns;
  116. }
  117. function columns_output( $column ) {
  118. global $post, $EM_Event;
  119. $EM_Event = em_get_event($post, 'post_id');
  120. /* @var $post EM_Event */
  121. switch ( $column ) {
  122. case 'event-id':
  123. echo $EM_Event->event_id;
  124. break;
  125. case 'location':
  126. //get meta value to see if post has location, otherwise
  127. $EM_Location = $EM_Event->get_location();
  128. if( !empty($EM_Location->location_id) ){
  129. echo "<strong>" . $EM_Location->location_name . "</strong><br/>" . $EM_Location->location_address . " - " . $EM_Location->location_town;
  130. }else{
  131. echo __('None','dbem');
  132. }
  133. break;
  134. case 'date-time':
  135. //get meta value to see if post has location, otherwise
  136. $localised_start_date = date_i18n(get_option('date_format'), $EM_Event->start);
  137. $localised_end_date = date_i18n(get_option('date_format'), $EM_Event->end);
  138. echo $localised_start_date;
  139. echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'';
  140. echo "<br />";
  141. if(!$EM_Event->event_all_day){
  142. echo date_i18n(get_option('time_format'), $EM_Event->start) . " - " . date_i18n(get_option('time_format'), $EM_Event->end);
  143. }else{
  144. echo get_option('dbem_event_all_day_message');
  145. }
  146. break;
  147. case 'extra':
  148. if( get_option('dbem_rsvp_enabled') == 1 && !empty($EM_Event->event_rsvp) && $EM_Event->can_manage('manage_bookings','manage_others_bookings')){
  149. ?>
  150. <a href="<?php echo $EM_Event->get_bookings_url(); ?>"><?php echo __("Bookings",'dbem'); ?></a> &ndash;
  151. <?php _e("Booked",'dbem'); ?>: <?php echo $EM_Event->get_bookings()->get_booked_spaces()."/".$EM_Event->get_spaces(); ?>
  152. <?php if( get_option('dbem_bookings_approval') == 1 ): ?>
  153. | <?php _e("Pending",'dbem') ?>: <?php echo $EM_Event->get_bookings()->get_pending_spaces(); ?>
  154. <?php endif;
  155. echo ($EM_Event->is_recurrence()) ? '<br />':'';
  156. }
  157. if ( $EM_Event->is_recurrence() && $EM_Event->can_manage('edit_recurring_events','edit_others_recurring_events') ) {
  158. $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');
  159. ?>
  160. <strong>
  161. <?php echo $EM_Event->get_recurrence_description(); ?> <br />
  162. </strong>
  163. <div class="row-actions">
  164. <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>
  165. </div>
  166. <?php
  167. }
  168. break;
  169. }
  170. }
  171. function row_actions($actions, $post){
  172. if($post->post_type == EM_POST_TYPE_EVENT){
  173. global $post, $EM_Event;
  174. $EM_Event = em_get_event($post, 'post_id');
  175. $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>';
  176. }
  177. return $actions;
  178. }
  179. }
  180. add_action('admin_init', array('EM_Event_Posts_Admin','init'));
  181. /*
  182. * Recurring Events
  183. */
  184. class EM_Event_Recurring_Posts_Admin{
  185. function init(){
  186. global $pagenow;
  187. $post_types = arrConst::get(POSTTYPE);
  188. if( $pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && in_array($_REQUEST['post_type'], $post_types) ){
  189. //hide some cols by default:
  190. $screen = 'edit-'.EM_POST_TYPE_EVENT;
  191. $hidden = get_user_option( 'manage' . $screen . 'columnshidden' );
  192. if( !$hidden ){
  193. $hidden = array('event-id');
  194. update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
  195. }
  196. //notices
  197. add_action('admin_notices',array('EM_Event_Recurring_Posts_Admin','admin_notices'));
  198. add_action('admin_head', array('EM_Event_Recurring_Posts_Admin','admin_head'));
  199. //collumns
  200. add_filter('manage_edit-event-recurring_columns' , array('EM_Event_Recurring_Posts_Admin','columns_add'));
  201. add_filter('manage_posts_custom_column' , array('EM_Event_Recurring_Posts_Admin','columns_output'),10,1 );
  202. add_action('restrict_manage_posts', array('EM_Event_Posts_Admin','restrict_manage_posts'));
  203. }
  204. }
  205. function admin_notices(){
  206. $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);
  207. ?><div class="updated"><p><?php echo $warning; ?></p></div><?php
  208. }
  209. function admin_head(){
  210. //quick hacks to make event admin table make more sense for events
  211. ?>
  212. <script type="text/javascript">
  213. jQuery(document).ready( function($){
  214. $('.inline-edit-date').prev().css('display','none').next().css('display','none').next().css('display','none');
  215. if(!EM.recurrences_menu){
  216. $('#menu-posts-'+EM.event_post_type+', #menu-posts-'+EM.event_post_type+' > a').addClass('wp-has-current-submenu');
  217. }
  218. });
  219. </script>
  220. <style>
  221. table.fixed{ table-layout:auto !important; }
  222. .tablenav select[name="m"] { display:none; }
  223. </style>
  224. <?php
  225. }
  226. function columns_add($columns) {
  227. if( array_key_exists('cb', $columns) ){
  228. $cb = $columns['cb'];
  229. unset($columns['cb']);
  230. $id_array = array('cb'=>$cb, 'event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  231. }else{
  232. $id_array = array('event-id' => sprintf(__('%s ID','dbem'),__('Event','dbem')));
  233. }
  234. unset($columns['comments']);
  235. unset($columns['date']);
  236. unset($columns['author']);
  237. return array_merge($id_array, $columns, array(
  238. 'location' => __('Location'),
  239. 'date-time' => __('Date and Time'),
  240. 'author' => __('Owner','dbem'),
  241. ));
  242. }
  243. function columns_output( $column ) {
  244. global $post, $EM_Event;
  245. $post_types = arrConst::get(POSTTYPE);
  246. if( in_array($post->post_type, $post_types) ){
  247. $post = $EM_Event = em_get_event($post);
  248. /* @var $post EM_Event */
  249. switch ( $column ) {
  250. case 'event-id':
  251. echo $EM_Event->event_id;
  252. break;
  253. case 'location':
  254. //get meta value to see if post has location, otherwise
  255. $EM_Location = $EM_Event->get_location();
  256. if( !empty($EM_Location->location_id) ){
  257. echo "<strong>" . $EM_Location->location_name . "</strong><br/>" . $EM_Location->location_address . " - " . $EM_Location->location_town;
  258. }else{
  259. echo __('None','dbem');
  260. }
  261. break;
  262. case 'date-time':
  263. echo $EM_Event->get_recurrence_description();
  264. break;
  265. }
  266. }
  267. }
  268. }
  269. add_action('admin_init', array('EM_Event_Recurring_Posts_Admin','init'));