Advertisement
jazbek

Fix admin memory problem Events Manager

Oct 21st, 2011
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.92 KB | None | 0 0
  1. <?php
  2.  
  3. // remove old function to display events list
  4. add_action('admin_menu', 'my_override_em_admin_list', 100);
  5. function my_override_em_admin_list()
  6. {
  7.     remove_action('toplevel_page_events-manager', 'em_admin_events_page');
  8. }
  9.  
  10. // add new function to display events list in the admin
  11. add_action('toplevel_page_events-manager', 'my_limit_events_list');
  12. function my_limit_events_list()
  13. {
  14.     //TODO Simplify panel for events, use form flags to detect certain actions (e.g. submitted, etc)
  15.     global $wpdb, $EM_Notices, $EM_Event;
  16.  
  17.     $action = ( !empty($_REQUEST ['action']) ) ? $_REQUEST ['action']:'';
  18.     $order = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'ASC';
  19.     $limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit
  20.     $page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1;
  21.     $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
  22.     $search = ( !empty($_REQUEST['em_search']) ) ? $_REQUEST['em_search']:'';
  23.     $scope_names = em_get_scopes();
  24.     $scope = ( !empty($_REQUEST ['scope']) && array_key_exists($_REQUEST ['scope'], $scope_names) ) ? $_REQUEST ['scope']:'future';
  25.     $selectedEvents = ( !empty($_REQUEST ['events']) ) ? $_REQUEST ['events']:'';
  26.    
  27.     $args = array('scope'=>$scope, 'limit'=>$limit, 'offset' => $offset, 'order'=>$order, 'search'=>$search );
  28.    
  29.     if( !current_user_can('edit_others_events') ){
  30.         $args['owner'] = get_current_user_id();
  31.     }
  32.     //Figure out what status to search for
  33.     $args['status'] = ( isset($_REQUEST['status']) && is_numeric($_REQUEST['status']) ) ? $_REQUEST['status'] : false;
  34.    
  35.     $events = EM_Events::get( $args );
  36.     unset($args['offset']);
  37.     $args['limit'] = 0;
  38.     $events_count = EM_Events::count ( $args );
  39.     $pending_count = EM_Events::count( array('status'=>0, 'scope'=>$scope) );
  40.     $approved_count = EM_Events::count( array('status'=> 1, 'scope'=>$scope) );
  41.     $total_count = EM_Events::count( array('status'=> false, 'scope'=>$scope) );
  42.    
  43.     $use_events_end = get_option('dbem_use_event_end');
  44.     echo $EM_Notices;
  45.     ?>
  46.     <div class="wrap">
  47.         <div id="icon-events" class="icon32"><br />
  48.         </div>
  49.         <h2>   
  50.             <?php echo $scope_names[$scope]; ?>
  51.             <a href="admin.php?page=events-manager-event" class="button add-new-h2"><?php _e('Add New','dbem'); ?></a>
  52.         </h2>
  53.         <?php  
  54.             $link = array ();
  55.             $link ['past'] = "<a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=past&amp;order=desc'>" . __ ( 'Past events', 'dbem' ) . "</a>";
  56.             $link ['all'] = " <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=all&amp;order=desc'>" . __ ( 'All events', 'dbem' ) . "</a>";
  57.             $link ['future'] = "  <a href='" . get_bloginfo ( 'wpurl' ) . "/wp-admin/admin.php?page=events-manager&amp;scope=future'>" . __ ( 'Future events', 'dbem' ) . "</a>";
  58.         ?>
  59.         <?php if ( !empty($_REQUEST['error']) ) : ?>
  60.         <div id='message' class='error'>
  61.             <p><?php echo $_REQUEST['error']; ?></p>
  62.         </div>
  63.         <?php endif; ?>
  64.         <?php if ( !empty($_REQUEST['message']) ) : ?>
  65.         <div id='message' class='updated fade'>
  66.             <p><?php echo $_REQUEST['message']; ?></p>
  67.         </div>
  68.         <?php endif; ?>
  69.         <form id="posts-filter" action="" method="get"><input type='hidden' name='page' value='events-manager' />
  70.             <ul class="subsubsub">
  71.                 <li><a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;scope=<?php echo $scope; ?>' <?php echo ( !isset($_REQUEST['status']) ) ? 'class="current"':''; ?>><?php _e ( 'Total', 'dbem' ); ?> <span class="count">(<?php echo $total_count; ?>)</span></a></li>
  72.                 <?php if( current_user_can('publish_events') ): ?>
  73.                 <li>| <a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;scope=<?php echo $scope; ?>&amp;status=1' <?php echo ( isset($_REQUEST['status']) && $_REQUEST['status']=='1' ) ? 'class="current"':''; ?>><?php _e ( 'Approved', 'dbem' ); ?> <span class="count">(<?php echo $approved_count; ?>)</span></a></li>
  74.                 <li>| <a href='<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;scope=<?php echo $scope; ?>&amp;status=0' <?php echo ( isset($_REQUEST['status']) && $_REQUEST['status']=='0' ) ? 'class="current"':''; ?>><?php _e ( 'Pending', 'dbem' ); ?> <span class="count">(<?php echo $pending_count; ?>)</span></a></li>
  75.                 <?php endif; ?>
  76.             </ul>
  77.             <p class="search-box">
  78.                 <label class="screen-reader-text" for="post-search-input"><?php _e('Search Events','dbem'); ?>:</label>
  79.                 <input type="text" id="post-search-input" name="em_search" value="<?php echo (!empty($_REQUEST['em_search'])) ? $_REQUEST['em_search']:''; ?>" />
  80.                 <input type="submit" value="<?php _e('Search Events','dbem'); ?>" class="button" />
  81.             </p>           
  82.             <div class="tablenav">
  83.            
  84.                 <div class="alignleft actions">
  85.                     <select name="action">
  86.                         <option value="-1" selected="selected"><?php _e ( 'Bulk Actions' ); ?></option>
  87.                         <option value="event_delete"><?php _e ( 'Delete selected','dbem' ); ?></option>
  88.                     </select>
  89.                     <input type="submit" value="<?php _e ( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
  90.                     <select name="scope">
  91.                         <?php
  92.                         foreach ( $scope_names as $key => $value ) {
  93.                             $selected = "";
  94.                             if ($key == $scope)
  95.                                 $selected = "selected='selected'";
  96.                             echo "<option value='$key' $selected>$value</option>  ";
  97.                         }
  98.                         ?>
  99.                     </select>
  100.                     <input id="post-query-submit" class="button-secondary" type="submit" value="<?php _e ( 'Filter' )?>" />
  101.                 </div>
  102.                 <!--
  103.                 <div class="view-switch">
  104.                     <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a>
  105.                 </div>
  106.                 -->
  107.                 <?php
  108.                 if ( $events_count >= $limit ) {
  109.                     $events_nav = em_admin_paginate( $events_count, $limit, $page);
  110.                     echo $events_nav;
  111.                 }
  112.                 ?>
  113.                 <br class="clear" />
  114.             </div>
  115.                
  116.             <?php
  117.             if (empty ( $events )) {
  118.                 // TODO localize
  119.                 _e ( 'no events','dbem' );
  120.             } else {
  121.             ?>
  122.                    
  123.             <table class="widefat events-table">
  124.                 <thead>
  125.                     <tr>
  126.                         <th class='manage-column column-cb check-column' scope='col'>
  127.                             <input class='select-all' type="checkbox" value='1' />
  128.                         </th>
  129.                         <th><?php _e ( 'Name', 'dbem' ); ?></th>
  130.                         <th>&nbsp;</th>
  131.                         <th><?php _e ( 'Location', 'dbem' ); ?></th>
  132.                         <th colspan="2"><?php _e ( 'Date and time', 'dbem' ); ?></th>
  133.                     </tr>
  134.                 </thead>
  135.                 <tbody>
  136.                     <?php
  137.                     $rowno = 0;
  138.                     $event_count = 0;
  139.                     foreach ( $events as $event ) {
  140.                         /* @var $event EM_Event */
  141. /*                          if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) { */
  142.                             $rowno++;
  143.                             $class = ($rowno % 2) ? 'alternate' : '';
  144.                             // FIXME set to american
  145.                             $localised_start_date = date_i18n('D d M Y', $event->start);
  146.                             $localised_end_date = date_i18n('D d M Y', $event->end);
  147.                             $style = "";
  148.                             $today = date ( "Y-m-d" );
  149.                             $location_summary = "<b>" . $event->location->name . "</b><br/>" . $event->location->address . " - " . $event->location->town;
  150.                            
  151.                             if ($event->start_date < $today && $event->end_date < $today){
  152.                                 $class .= " past";
  153.                             }
  154.                             //Check pending approval events
  155.                             if ( !$event->status ){
  156.                                 $class .= " pending";
  157.                             }                  
  158.                             ?>
  159.                             <tr class="event <?php echo trim($class); ?>" <?php echo $style; ?> id="event_<?php echo $event->id ?>">
  160.                                 <td>
  161.                                     <input type='checkbox' class='row-selector' value='<?php echo $event->id; ?>' name='events[]' />
  162.                                 </td>
  163.                                 <td>
  164.                                     <strong>
  165.                                         <a class="row-title" href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>"><?php echo ($event->name); ?></a>
  166.                                     </strong>
  167.                                     <?php
  168.                                     if( get_option('dbem_rsvp_enabled') == 1 && $event->rsvp == 1 ){
  169.                                         ?>
  170.                                         <br/>
  171.                                         <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-bookings&amp;event_id=<?php echo $event->id ?>"><?php echo __("Bookings",'dbem'); ?></a> &ndash;
  172.                                         <?php _e("Booked",'dbem'); ?>: <?php echo $event->get_bookings()->get_booked_spaces()."/".$event->get_spaces(); ?>
  173.                                         <?php if( get_option('dbem_bookings_approval') == 1 ): ?>
  174.                                             | <?php _e("Pending",'dbem') ?>: <?php echo $event->get_bookings()->get_pending_spaces(); ?>
  175.                                         <?php endif;
  176.                                     }
  177.                                     ?>
  178.                                     <div class="row-actions">
  179.                                         <span class="trash"><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;action=event_delete&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" class="em-event-delete"><?php _e('Delete','dbem'); ?></a></span>
  180.                                         <?php if( !$event->status && current_user_can('publish_events') ): ?>
  181.                                         | <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;action=event_approve&amp;event_id=<?php echo $event->id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" class="em-event-approve" style="color:green"><?php _e('Approve','dbem'); ?></a>
  182.                                         <?php endif; ?>
  183.                                     </div>
  184.                                 </td>
  185.                                 <td>
  186.                                     <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;action=event_duplicate&amp;event_id=<?php echo $event->id; ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" title="<?php _e ( 'Duplicate this event', 'dbem' ); ?>">
  187.                                         <strong>+</strong>
  188.                                     </a>
  189.                                 </td>
  190.                                 <td>
  191.                                     <?php echo $location_summary; ?>
  192.                                 </td>
  193.                        
  194.                                 <td>
  195.                                     <?php echo $localised_start_date; ?>
  196.                                     <?php echo ($localised_end_date != $localised_start_date) ? " - $localised_end_date":'' ?>
  197.                                     <br />
  198.                                     <?php
  199.                                         //TODO Should 00:00 - 00:00 be treated as an all day event?
  200.                                         echo substr ( $event->start_time, 0, 5 ) . " - " . substr ( $event->end_time, 0, 5 );
  201.                                     ?>
  202.                                 </td>
  203.                                 <td>
  204.                                     <?php
  205.                                     if ( $event->is_recurrence() ) {
  206.                                         $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');
  207.                                         ?>
  208.                                         <strong>
  209.                                         <?php echo $event->get_recurrence_description(); ?> <br />
  210.                                         <a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php echo $event->recurrence_id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>"><?php _e ( 'Reschedule', 'dbem' ); ?></a> |
  211.                                         <span class="trash"><a href="<?php bloginfo ( 'wpurl' )?>/wp-admin/admin.php?page=events-manager&amp;action=event_delete&amp;event_id=<?php echo $event->recurrence_id ?>&amp;scope=<?php echo $scope ?>&amp;pno=<?php echo $page ?>" class="em-event-rec-delete" onclick ="if( !confirm('<?php echo $recurrence_delete_confirm; ?>') ){ return false; }"><?php _e('Delete','dbem'); ?></a></span>
  212.                                         </strong>
  213.                                         <?php
  214.                                     }
  215.                                     ?>
  216.                                 </td>
  217.                             </tr>
  218.                             <?php
  219. /*                          } */
  220.                         $event_count++;
  221.                     }
  222.                     ?>
  223.                 </tbody>
  224.             </table>  
  225.             <?php
  226.             } // end of table
  227.             ?>
  228.             <div class='tablenav'>
  229.                 <div class="alignleft actions">
  230.                 <br class='clear' />
  231.                 </div>
  232.                 <?php if ( $events_count >= $limit ) : ?>
  233.                 <div class="tablenav-pages">
  234.                     <?php
  235.                     echo $events_nav;
  236.                     ?>
  237.                 </div>
  238.                 <?php endif; ?>
  239.                 <br class='clear' />
  240.             </div>
  241.         </form>
  242.     </div>
  243.     <?php
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement