Exemple #1
0
/**
 * Triggers all upgrade functions
 *
 * @since 2.2
 * @return void
*/
function edd_sl_show_upgrade_notice()
{
    if (!function_exists('EDD')) {
        return;
    }
    $edd_sl_version = get_option('edd_sl_version');
    if (!$edd_sl_version) {
        edd_sl_v22_upgrades();
    }
    if (version_compare($edd_sl_version, '2.4', '<') && !isset($_GET['edd_upgrade'])) {
        printf('<div class="updated"><p>' . __('The License Keys in Easy Digital Downloads needs to be upgraded, click <a href="%s">here</a> to start the upgrade.', 'edd_sl') . '</p></div>', esc_url(add_query_arg(array('edd_action' => 'upgrade_site_urls'), admin_url())));
    }
    if (version_compare($edd_sl_version, '2.5', '<') && !isset($_GET['edd_upgrade'])) {
        printf('<div class="updated"><p>' . __('The License Keys in Easy Digital Downloads needs to be upgraded, click <a href="%s">here</a> to start the upgrade.', 'edd_sl') . '</p></div>', esc_url(add_query_arg(array('edd_action' => 'upgrade_license_price_ids'), admin_url())));
    }
    if (version_compare($edd_sl_version, '3.0', '<') && !isset($_GET['edd_upgrade']) && edd_get_option('edd_sl_send_renewal_reminders')) {
        printf('<div class="updated"><p>' . __('The renewal notices in Easy Digital Downloads needs to be upgraded, click <a href="%s">here</a> to start the upgrade.', 'edd_sl') . '</p></div>', esc_url(add_query_arg(array('edd_action' => 'upgrade_renewal_notices'), admin_url())));
    }
    if (function_exists('edd_has_upgrade_completed') && function_exists('edd_maybe_resume_upgrade')) {
        $resume_upgrade = edd_maybe_resume_upgrade();
        if (empty($resume_upgrade)) {
            if (version_compare($edd_sl_version, '3.2', '<') || !edd_has_upgrade_completed('sl_add_bundle_licenses')) {
                $notice = '<div class="notice notice-info"><p>';
                $notice .= __('Easy Digital Downloads - Software Licensing now supports Bundle Licenses. This is an opt-in upgrade, so please choose one of the following:', 'edd_sl');
                $notice .= '<p>';
                $notice .= sprintf(__('If you want to read more on this new feature, <a href="%s" target="_blank">click here</a>.', 'edd_sl'), 'http://docs.easydigitaldownloads.com/article/698-bundle-licensing');
                $notice .= '</p>';
                $notice .= '<ol>';
                $notice .= sprintf(__('<li>Make <a href="%s">no changes</a></li>', 'edd_sl'), esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=sl_add_bundle_licenses&custom=0')));
                $notice .= __('<li>After you enable licensing for the bundles of your choice, <a href="#" onClick="jQuery(\'#generate-licenses-button-wrapper\').toggle(); return false;">generate licenses for bundles with Licensing enabled</a>.</li>', 'edd_sl');
                $notice .= '</ol>';
                $notice .= '</p></div>';
                $notice .= '<div class="notice notice-info" style="display:none;" id="generate-licenses-button-wrapper">';
                $notice .= '<p>' . __('Before clicking this button, verify that all bundles you want to generate licenses for have Licensing enabled, and their license length is correct.', 'edd_sl') . '</p>';
                $notice .= sprintf(__('<a href="%s" class="button-primary">', 'edd_sl'), esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=sl_add_bundle_licenses&custom=1')));
                $notice .= __('Generate Bundle Licenses', 'edd_sl');
                $notice .= '</a>';
                $notice .= '</p></div>';
                echo $notice;
            }
        }
    }
}
 /**
  * Process Get Stats API Request
  *
  * @author Daniel J Griffiths
  * @since 1.5
  *
  * @global object $wpdb Used to query the database using the WordPress
  *
  * @param array $args Arguments provided by API Request
  *
  * @return array
  */
 public function get_stats($args = array())
 {
     $defaults = array('type' => null, 'product' => null, 'date' => null, 'startdate' => null, 'enddate' => null);
     $args = wp_parse_args($args, $defaults);
     $dates = $this->get_dates($args);
     $stats = array();
     $earnings = array('earnings' => array());
     $sales = array('sales' => array());
     $error = array();
     if (!user_can($this->user_id, 'view_shop_reports') && !$this->override) {
         return $stats;
     }
     if ($args['type'] == 'sales') {
         if ($args['product'] == null) {
             if ($args['date'] == null) {
                 $sales = $this->get_default_sales_stats();
             } elseif ($args['date'] === 'range') {
                 // Return sales for a date range
                 // Ensure the end date is later than the start date
                 if ($args['enddate'] < $args['startdate']) {
                     $error['error'] = __('The end date must be later than the start date!', 'easy-digital-downloads');
                 }
                 // Ensure both the start and end date are specified
                 if (empty($args['startdate']) || empty($args['enddate'])) {
                     $error['error'] = __('Invalid or no date range specified!', 'easy-digital-downloads');
                 }
                 $total = 0;
                 // Loop through the years
                 $y = $dates['year'];
                 while ($y <= $dates['year_end']) {
                     if ($dates['year'] == $dates['year_end']) {
                         $month_start = $dates['m_start'];
                         $month_end = $dates['m_end'];
                     } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) {
                         $month_start = $dates['m_start'];
                         $month_end = 12;
                     } elseif ($y == $dates['year_end']) {
                         $month_start = 1;
                         $month_end = $dates['m_end'];
                     } else {
                         $month_start = 1;
                         $month_end = 12;
                     }
                     $i = $month_start;
                     while ($i <= $month_end) {
                         if ($i == $dates['m_start']) {
                             $d = $dates['day_start'];
                         } else {
                             $d = 1;
                         }
                         if ($i == $dates['m_end']) {
                             $num_of_days = $dates['day_end'];
                         } else {
                             $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
                         }
                         while ($d <= $num_of_days) {
                             $sale_count = edd_get_sales_by_date($d, $i, $y);
                             $date_key = date('Ymd', strtotime($y . '/' . $i . '/' . $d));
                             if (!isset($sales['sales'][$date_key])) {
                                 $sales['sales'][$date_key] = 0;
                             }
                             $sales['sales'][$date_key] += $sale_count;
                             $total += $sale_count;
                             $d++;
                         }
                         $i++;
                     }
                     $y++;
                 }
                 $sales['totals'] = $total;
             } else {
                 if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') {
                     $sales_count = 0;
                     // Loop through the months
                     $month = $dates['m_start'];
                     while ($month <= $dates['m_end']) {
                         $sales_count += edd_get_sales_by_date(null, $month, $dates['year']);
                         $month++;
                     }
                     $sales['sales'][$args['date']] = $sales_count;
                 } else {
                     $sales['sales'][$args['date']] = edd_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']);
                 }
             }
         } elseif ($args['product'] == 'all') {
             $products = get_posts(array('post_type' => 'download', 'nopaging' => true));
             $i = 0;
             foreach ($products as $product_info) {
                 $sales['sales'][$i] = array($product_info->post_name => edd_get_download_sales_stats($product_info->ID));
                 $i++;
             }
         } else {
             if (get_post_type($args['product']) == 'download') {
                 $product_info = get_post($args['product']);
                 $sales['sales'][0] = array($product_info->post_name => edd_get_download_sales_stats($args['product']));
             } else {
                 $error['error'] = sprintf(__('Product %s not found!', 'easy-digital-downloads'), $args['product']);
             }
         }
         if (!empty($error)) {
             return $error;
         }
         return $sales;
     } elseif ($args['type'] == 'earnings') {
         if ($args['product'] == null) {
             if ($args['date'] == null) {
                 $earnings = $this->get_default_earnings_stats();
             } elseif ($args['date'] === 'range') {
                 // Return sales for a date range
                 // Ensure the end date is later than the start date
                 if ($args['enddate'] < $args['startdate']) {
                     $error['error'] = __('The end date must be later than the start date!', 'easy-digital-downloads');
                 }
                 // Ensure both the start and end date are specified
                 if (empty($args['startdate']) || empty($args['enddate'])) {
                     $error['error'] = __('Invalid or no date range specified!', 'easy-digital-downloads');
                 }
                 $total = (double) 0.0;
                 // Loop through the years
                 $y = $dates['year'];
                 if (!isset($earnings['earnings'])) {
                     $earnings['earnings'] = array();
                 }
                 while ($y <= $dates['year_end']) {
                     if ($dates['year'] == $dates['year_end']) {
                         $month_start = $dates['m_start'];
                         $month_end = $dates['m_end'];
                     } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) {
                         $month_start = $dates['m_start'];
                         $month_end = 12;
                     } elseif ($y == $dates['year_end']) {
                         $month_start = 1;
                         $month_end = $dates['m_end'];
                     } else {
                         $month_start = 1;
                         $month_end = 12;
                     }
                     $i = $month_start;
                     while ($i <= $month_end) {
                         if ($i == $dates['m_start']) {
                             $d = $dates['day_start'];
                         } else {
                             $d = 1;
                         }
                         if ($i == $dates['m_end']) {
                             $num_of_days = $dates['day_end'];
                         } else {
                             $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y);
                         }
                         while ($d <= $num_of_days) {
                             $earnings_stat = edd_get_earnings_by_date($d, $i, $y);
                             $date_key = date('Ymd', strtotime($y . '/' . $i . '/' . $d));
                             if (!isset($earnings['earnings'][$date_key])) {
                                 $earnings['earnings'][$date_key] = 0;
                             }
                             $earnings['earnings'][$date_key] += $earnings_stat;
                             $total += $earnings_stat;
                             $d++;
                         }
                         $i++;
                     }
                     $y++;
                 }
                 $earnings['totals'] = $total;
             } else {
                 if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') {
                     $earnings_count = (double) 0.0;
                     // Loop through the months
                     $month = $dates['m_start'];
                     while ($month <= $dates['m_end']) {
                         $earnings_count += edd_get_earnings_by_date(null, $month, $dates['year']);
                         $month++;
                     }
                     $earnings['earnings'][$args['date']] = $earnings_count;
                 } else {
                     $earnings['earnings'][$args['date']] = edd_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']);
                 }
             }
         } elseif ($args['product'] == 'all') {
             $products = get_posts(array('post_type' => 'download', 'nopaging' => true));
             $i = 0;
             foreach ($products as $product_info) {
                 $earnings['earnings'][$i] = array($product_info->post_name => edd_get_download_earnings_stats($product_info->ID));
                 $i++;
             }
         } else {
             if (get_post_type($args['product']) == 'download') {
                 $product_info = get_post($args['product']);
                 $earnings['earnings'][0] = array($product_info->post_name => edd_get_download_earnings_stats($args['product']));
             } else {
                 $error['error'] = sprintf(__('Product %s not found!', 'easy-digital-downloads'), $args['product']);
             }
         }
         if (!empty($error)) {
             return $error;
         }
         return $earnings;
     } elseif ($args['type'] == 'customers') {
         if (version_compare($edd_version, '2.3', '<') || !edd_has_upgrade_completed('upgrade_customer_payments_association')) {
             global $wpdb;
             $stats = array();
             $count = $wpdb->get_col("SELECT COUNT(DISTINCT meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_user_email'");
             $stats['customers']['total_customers'] = $count[0];
             return $stats;
         } else {
             $customers = new EDD_DB_Customers();
             $stats['customers']['total_customers'] = $customers->count();
             return $stats;
         }
     } elseif (empty($args['type'])) {
         $stats = array_merge($stats, $this->get_default_sales_stats());
         $stats = array_merge($stats, $this->get_default_earnings_stats());
         return array('stats' => $stats);
     }
 }
/**
 * Display Upgrade Notices
 *
 * @since 1.3.1
 * @return void
*/
function edd_show_upgrade_notices()
{
    if (isset($_GET['page']) && $_GET['page'] == 'edd-upgrades') {
        return;
    }
    // Don't show notices on the upgrades page
    $edd_version = get_option('edd_version');
    if (!$edd_version) {
        // 1.3 is the first version to use this option so we must add it
        $edd_version = '1.3';
    }
    $edd_version = preg_replace('/[^0-9.].*/', '', $edd_version);
    if (!get_option('edd_payment_totals_upgraded') && !get_option('edd_version')) {
        if (wp_count_posts('edd_payment')->publish < 1) {
            return;
        }
        // No payment exist yet
        // The payment history needs updated for version 1.2
        $url = add_query_arg('edd-action', 'upgrade_payments');
        $upgrade_notice = sprintf(__('The Payment History needs to be updated. %s', 'edd'), '<a href="' . wp_nonce_url($url, 'edd_upgrade_payments_nonce') . '">' . __('Click to Upgrade', 'edd') . '</a>');
        add_settings_error('edd-notices', 'edd-payments-upgrade', $upgrade_notice, 'error');
    }
    if (version_compare($edd_version, '1.3.2', '<') && !get_option('edd_logs_upgraded')) {
        printf('<div class="updated"><p>' . esc_html__('The Purchase and File Download History in Easy Digital Downloads needs to be upgraded, click %shere%s to start the upgrade.', 'edd') . '</p></div>', '<a href="' . esc_url(admin_url('options.php?page=edd-upgrades')) . '">', '</a>');
    }
    if (version_compare($edd_version, '1.3.4', '<') || version_compare($edd_version, '1.4', '<')) {
        printf('<div class="updated"><p>' . esc_html__('Easy Digital Downloads needs to upgrade the plugin pages, click %shere%s to start the upgrade.', 'edd') . '</p></div>', '<a href="' . esc_url(admin_url('options.php?page=edd-upgrades')) . '">', '</a>');
    }
    if (version_compare($edd_version, '1.5', '<')) {
        printf('<div class="updated"><p>' . esc_html__('Easy Digital Downloads needs to upgrade the database, click %shere%s to start the upgrade.', 'edd') . '</p></div>', '<a href="' . esc_url(admin_url('options.php?page=edd-upgrades')) . '">', '</a>');
    }
    if (version_compare($edd_version, '2.0', '<')) {
        printf('<div class="updated"><p>' . esc_html__('Easy Digital Downloads needs to upgrade the database, click %shere%s to start the upgrade.', 'edd') . '</p></div>', '<a href="' . esc_url(admin_url('options.php?page=edd-upgrades')) . '">', '</a>');
    }
    // Sequential Orders was the first stepped upgrade, so check if we have a stalled upgrade
    $resume_upgrade = edd_maybe_resume_upgrade();
    if (!empty($resume_upgrade)) {
        $resume_url = add_query_arg($resume_upgrade, admin_url('index.php'));
        printf('<div class="error"><p>' . __('Easy Digital Downloads needs to complete a database upgrade that was previously started, click <a href="%s">here</a> to resume the upgrade.', 'edd') . '</p></div>', esc_url($resume_url));
    } else {
        // Include all 'Stepped' upgrade process notices in this else statement,
        // to avoid having a pending, and new upgrade suggested at the same time
        if (EDD()->session->get('upgrade_sequential') && edd_get_payments()) {
            printf('<div class="updated"><p>' . __('Easy Digital Downloads needs to upgrade past order numbers to make them sequential, click <a href="%s">here</a> to start the upgrade.', 'edd') . '</p></div>', admin_url('index.php?page=edd-upgrades&edd-upgrade=upgrade_sequential_payment_numbers'));
        }
        if (version_compare($edd_version, '2.1', '<')) {
            printf('<div class="updated"><p>' . esc_html__('Easy Digital Downloads needs to upgrade the customer database, click %shere%s to start the upgrade.', 'edd') . '</p></div>', '<a href="' . esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=upgrade_customers_db')) . '">', '</a>');
        }
        if (version_compare($edd_version, '2.2.6', '<')) {
            printf('<div class="updated"><p>' . __('Easy Digital Downloads needs to upgrade the payment database, click <a href="%s">here</a> to start the upgrade.', 'edd') . '</p></div>', esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=upgrade_payments_price_logs_db')));
        }
        if (version_compare($edd_version, '2.3', '<') || !edd_has_upgrade_completed('upgrade_customer_payments_association')) {
            printf('<div class="updated"><p>' . __('Easy Digital Downloads needs to upgrade the customer database, click <a href="%s">here</a> to start the upgrade.', 'edd') . '</p></div>', esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=upgrade_customer_payments_association')));
        }
        if (version_compare($edd_version, '2.3', '<') || !edd_has_upgrade_completed('upgrade_payment_taxes')) {
            printf('<div class="updated"><p>' . __('Easy Digital Downloads needs to upgrade the payment database, click <a href="%s">here</a> to start the upgrade.', 'edd') . '</p></div>', esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=upgrade_payment_taxes')));
        }
        if (version_compare($edd_version, '2.4', '<') || !edd_has_upgrade_completed('upgrade_user_api_keys')) {
            printf('<div class="updated"><p>' . __('Easy Digital Downloads needs to upgrade the API Key database, click <a href="%s">here</a> to start the upgrade.', 'edd') . '</p></div>', esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=upgrade_user_api_keys')));
        }
        if (version_compare($edd_version, '2.4.3', '<') || !edd_has_upgrade_completed('remove_refunded_sale_logs')) {
            printf('<div class="updated"><p>' . __('Easy Digital Downloads needs to upgrade the payments database, click <a href="%s">here</a> to start the upgrade.', 'edd') . '</p></div>', esc_url(admin_url('index.php?page=edd-upgrades&edd-upgrade=remove_refunded_sale_logs')));
        }
        /*
         *  NOTICE:
         *
         *  When adding new upgrade notices, please be sure to put the action into the upgrades array during install:
         *  /includes/install.php @ Appox Line 156
         *
         */
        // End 'Stepped' upgrade process notices
    }
}