/**
  * Returns the array of view options for this campaign.
  *
  * @param   array       $views
  * @return  array
  * @access  public
  * @since   1.0.0
  */
 public function view_options($views)
 {
     $current = isset($_GET['post-status']) ? $_GET['post-status'] : '';
     $statuses = charitable_get_valid_donation_statuses();
     $donations = new Charitable_Donations();
     $status_count = $donations->count_by_status();
     $views = array();
     $views['all'] = sprintf('<a href="%s"%s>%s <span class="count">(%s)</span></a>', esc_url(remove_query_arg(array('post_status', 'paged'))), 'all' === $current || '' == $current ? ' class="current"' : '', __('All', 'charitable'), $donations->count_all());
     foreach ($statuses as $status => $label) {
         $views[$status] = sprintf('<a href="%s"%s>%s <span class="count">(%s)</span></a>', esc_url(add_query_arg(array('post_status' => $status, 'paged' => false))), $current === $status ? ' class="current"' : '', $label, isset($status_count[$status]) ? $status_count[$status]->num_donations : 0);
     }
     return $views;
 }
 /**
  * Get the donation counts. 
  *
  * @return  void
  * @access  protected
  * @since   1.0.0     
  */
 protected function prepare_donation_counts()
 {
     $counts = Charitable_Donations::count_by_status();
     foreach ($this->donation_statuses as $status_key => $label) {
         $this->status_counts[$status_key] = isset($counts[$status_key]) ? $counts[$status_key]->num_donations : 0;
     }
     $this->total_count = array_sum($this->status_counts);
 }
 /**
  * Fix the donation dates.
  *
  * This upgrade routine was added in 1.3.0
  *
  * @see 	https://github.com/Charitable/Charitable/issues/58
  *
  * @return  void
  * @access  public
  * @since   1.3.0
  */
 public function fix_donation_dates()
 {
     if (!current_user_can('manage_charitable_settings')) {
         wp_die(__('You do not have permission to do Charitable upgrades', 'charitable'), __('Error', 'charitable'), array('response' => 403));
     }
     ignore_user_abort(true);
     if (!charitable_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
         @set_time_limit(0);
     }
     $step = isset($_GET['step']) ? absint($_GET['step']) : 1;
     $number = 20;
     $total = Charitable_Donations::count_all();
     /**
      * If there are no donations to update, go ahead and wrap it up right now.
      */
     if (!$total) {
         $this->finish_upgrade('fix_donation_dates');
     }
     $donations = get_posts(array('post_type' => Charitable::DONATION_POST_TYPE, 'posts_per_page' => $number, 'paged' => $step, 'post_status' => array_keys(Charitable_Donation::get_valid_donation_statuses())));
     if (count($donations)) {
         /**
          * Prevent donation receipt & admin notifications from getting resent.
          */
         remove_action('save_post_' . Charitable::DONATION_POST_TYPE, array('Charitable_Email_Donation_Receipt', 'send_with_donation_id'));
         remove_action('save_post_' . Charitable::DONATION_POST_TYPE, array('Charitable_Email_New_Donation', 'send_with_donation_id'));
         foreach ($donations as $donation) {
             /**
              * Thankfully, we store the timestamp of the donation in the log,
              * so we can use that to correct any incorrect post_date/post_date_gmt
              * values.
              */
             $donation_log = get_post_meta($donation->ID, '_donation_log', true);
             if (empty($donation_log)) {
                 continue;
             }
             $time = $donation_log[0]['time'];
             $date_gmt = gmdate('Y-m-d H:i:s', $time);
             if ($date_gmt == $donation->post_date_gmt) {
                 continue;
             }
             $date = get_date_from_gmt($date_gmt);
             wp_update_post(array('ID' => $donation->ID, 'post_date' => $date, 'post_date_gmt' => $date_gmt));
         }
         $step++;
         $redirect = add_query_arg(array('page' => 'charitable-upgrades', 'charitable-upgrade' => 'fix_donation_dates', 'step' => $step, 'number' => $number, 'total' => $total), admin_url('index.php'));
         wp_redirect($redirect);
         exit;
     }
     $this->upgrade_logs();
     $this->finish_upgrade('fix_donation_dates');
 }
 /**
  * Return the status counts, taking into account any current filters.
  *
  * @return  array
  * @access  protected
  * @since   1.4.0
  */
 protected function get_status_counts()
 {
     if (!isset($this->status_counts)) {
         $args = array();
         if (isset($_GET['s']) && strlen($_GET['s'])) {
             $args['s'] = $_GET['s'];
         }
         if (isset($_GET['start_date']) && strlen($_GET['start_date'])) {
             $args['start_date'] = $this->get_parsed_date($_GET['start_date']);
         }
         if (isset($_GET['end_date']) && strlen($_GET['end_date'])) {
             $args['end_date'] = $this->get_parsed_date($_GET['end_date']);
         }
         $status_counts = Charitable_Donations::count_by_status($args);
         foreach (charitable_get_valid_donation_statuses() as $key => $label) {
             $count = array_key_exists($key, $status_counts) ? $status_counts[$key]->num_donations : 0;
             $this->status_counts[$key] = $count;
         }
     }
     return $this->status_counts;
 }
 /**
  * Get the donation counts. 
  *
  * @return  void
  * @access  protected
  * @since   1.0.0     
  */
 protected function prepare_donation_counts()
 {
     $args = array();
     if (!empty($_GET['start_date'])) {
         $args['start_date'] = $this->get_parsed_date($_GET['start_date']);
     }
     if (!empty($_GET['end_date'])) {
         $args['end_date'] = $this->get_parsed_date($_GET['end_date']);
     }
     if (isset($_GET['s'])) {
         $args['s'] = urldecode($_GET['s']);
     }
     $counts = Charitable_Donations::count_by_status($args);
     foreach ($this->donation_statuses as $status_key => $label) {
         $this->status_counts[$status_key] = isset($counts[$status_key]) ? $counts[$status_key]->num_donations : 0;
     }
     $this->total_count = array_sum($this->status_counts);
 }