function ck_edd_user_download_button($purchase_form, $args) { global $edd_options; if (!is_user_logged_in()) { return $purchase_form; } $download_id = (string) $args['download_id']; $current_user_id = get_current_user_id(); // If the user has purchased this item, itterate through their purchases to get the specific // purchase data and pull out the key and email associated with it. This is necessary for the // generation of the download link if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) { $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete'); foreach ($user_purchases as $purchase) { $cart_items = edd_get_payment_meta_cart_details($purchase->ID); $item_ids = wp_list_pluck($cart_items, 'id'); if (in_array($download_id, $item_ids)) { $email = edd_get_payment_user_email($purchase->ID); $payment_key = edd_get_payment_key($purchase->ID); } } $download_ids = array(); if (edd_is_bundled_product($download_id)) { $download_ids = edd_get_bundled_products($download_id); } else { $download_ids[] = $download_id; } // Setup the style and colors associated with the settings $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button'; $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue'; $new_purchase_form = ''; foreach ($download_ids as $item) { // Attempt to get the file data associated with this download $download_data = edd_get_download_files($item, null); if ($download_data) { foreach ($download_data as $filekey => $file) { // Generate the file URL and then make a link to it $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $item, null); $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a> '; } } // As long as we ended up with links to show, use them. if (!empty($new_purchase_form)) { $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form; } } } return $purchase_form; }
/** * Email Template Tags * * @access private * @since 1.0 * @return string */ function edd_email_templage_tags($message, $payment_data, $payment_id) { $user_info = maybe_unserialize($payment_data['user_info']); if (isset($user_info['id']) && $user_info['id'] > 0) { $user_data = get_userdata($user_info['id']); $name = $user_data->display_name; } elseif (isset($user_info['first_name'])) { $name = $user_info['first_name']; } else { $name = $user_info['email']; } $download_list = '<ul>'; $downloads = maybe_unserialize($payment_data['downloads']); if ($downloads) { foreach (maybe_unserialize($payment_data['downloads']) as $download) { $id = isset($payment_data['cart_details']) ? $download['id'] : $download; $download_list .= '<li>' . get_the_title($id) . '<br/>'; $download_list .= '<ul>'; $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null; $files = edd_get_download_files($id, $price_id); if ($files) { foreach ($files as $filekey => $file) { $download_list .= '<li>'; $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $id); $download_list .= '<a href="' . $file_url . '">' . $file['name'] . '</a>'; $download_list .= '</li>'; } } $download_list .= '</ul></li>'; } } $download_list .= '</ul>'; $price = edd_currency_filter($payment_data['amount']); $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true)); $receipt_id = $payment_data['key']; $message = str_replace('{name}', $name, $message); $message = str_replace('{download_list}', $download_list, $message); $message = str_replace('{date}', date(get_option('date_format'), strtotime($payment_data['date'])), $message); $message = str_replace('{sitename}', get_bloginfo('name'), $message); $message = str_replace('{price}', $price, $message); $message = str_replace('{payment_method}', $gateway, $message); $message = str_replace('{receipt_id}', $receipt_id, $message); $message = apply_filters('edd_email_template_tags', $message, $payment_data); return $message; }
/** * Blocks access to Download attachments * * Only blocks files that are listed as downloadable files for the product * * @since 1.2.2 * @return void */ function edd_block_attachments() { if (!is_attachment()) { return; } $parent = get_post_field('post_parent', get_the_ID()); $uri = wp_get_attachment_url(get_the_ID()); $edd_file = strpos($uri, '/edd/'); if (!$parent && false === $edd_file) { return; } if ('download' != get_post_type($parent) && false === $edd_file) { return; } $files = edd_get_download_files($parent); $restricted = wp_list_pluck($files, 'file'); if (!in_array($uri, $restricted)) { return; } wp_die(__('You do not have permission to view this file.', 'edd'), __('Error', 'edd'), array('response' => 403)); }
/** * Output filelist in ul li list format */ function vp_edd_fd_filelist($atts, $content = null) { extract(shortcode_atts(array(), $atts)); $did = isset($_GET['did']) ? $_GET['did'] : ''; $files = array(); if ($did !== '') { $files = edd_get_download_files($did); } // begin output ?> <ul> <?php foreach ($files as $file_key => $file) { ?> <li><a href="<?php echo vp_edd_fd_build_download_gateway_url($did, $file_key); ?> "><?php echo $file['name']; ?> </a></li> <?php } ?> </ul> <?php // end of output }
/** * Get the Export Data * * @access public * @since 2.4 * @global object $edd_logs EDD Logs Object * @return array $data The data for the CSV file */ public function get_data() { global $edd_logs; $data = array(); $args = array('log_type' => 'file_download', 'posts_per_page' => 30, 'paged' => $this->step); if (!empty($this->start) || !empty($this->end)) { $args['date_query'] = array(array('after' => date('Y-n-d H:i:s', strtotime($this->start)), 'before' => date('Y-n-d H:i:s', strtotime($this->end)), 'inclusive' => true)); } $logs = $edd_logs->get_connected_logs($args); if ($logs) { foreach ($logs as $log) { $user_info = get_post_meta($log->ID, '_edd_log_user_info', true); $files = edd_get_download_files($log->post_parent); $file_id = (int) get_post_meta($log->ID, '_edd_log_file_id', true); $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null; $user = get_userdata($user_info['id']); $user = $user ? $user->user_login : $user_info['email']; $data[] = array('date' => $log->post_date, 'user' => $user, 'ip' => get_post_meta($log->ID, '_edd_log_ip', true), 'download' => get_the_title($log->post_parent), 'file' => $file_name); } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; } return false; }
function edd_ck_show_file_sizes($post_id) { $files = edd_get_download_files($post_id, null); $decimals = 2; $sz = 'BKMGTP'; $header = _n('File Size', 'File Sizes', count($files), 'edd'); echo '<h5>' . $header . '</h5>'; echo '<ul>'; foreach ($files as $file) { $bytes = filesize(get_attached_file($file['attachment_id'])); $factor = floor((strlen($bytes) - 1) / 3); echo '<li>' . $file['name'] . ' - ' . sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor] . '</li>'; } echo '</ul>'; }
/** * Get the Export Data * * @access public * @since 1.4.4 * @global object $edd_logs EDD Logs Object * @return array $data The data for the CSV file */ public function get_data() { global $edd_logs; $data = array(); $args = array('nopaging' => true, 'log_type' => 'file_download', 'monthnum' => isset($_POST['month']) ? absint($_POST['month']) : date('n'), 'year' => isset($_POST['year']) ? absint($_POST['year']) : date('Y')); $logs = $edd_logs->get_connected_logs($args); if ($logs) { foreach ($logs as $log) { $user_info = get_post_meta($log->ID, '_edd_log_user_info', true); $files = edd_get_download_files($log->post_parent); $file_id = (int) get_post_meta($log->ID, '_edd_log_file_id', true); $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null; $user = get_userdata($user_info['id']); $user = $user ? $user->user_login : $user_info['email']; $data[] = array('date' => $log->post_date, 'user' => $user, 'ip' => get_post_meta($log->ID, '_edd_log_ip', true), 'download' => get_the_title($log->post_parent), 'file' => $file_name); } } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; }
/** * File Downloads section. * * Outputs a table of all current files. Extensions can add column heads to the table * via the `edd_download_file_table_head` hook, and actual columns via * `edd_download_file_table_row` * * @since 1.0 * @see edd_render_file_row() * @param int $post_id Download (Post) ID * @return void */ function edd_render_files_field($post_id = 0) { $type = edd_get_download_type($post_id); $files = edd_get_download_files($post_id); $variable_pricing = edd_has_variable_prices($post_id); $display = $type == 'bundle' ? ' style="display:none;"' : ''; $variable_display = $variable_pricing ? '' : 'display:none;'; ?> <div id="edd_download_files"<?php echo $display; ?> > <p> <strong><?php _e('File Downloads:', 'edd'); ?> </strong> </p> <input type="hidden" id="edd_download_files" class="edd_repeatable_upload_name_field" value=""/> <div id="edd_file_fields" class="edd_meta_table_wrap"> <table class="widefat edd_repeatable_table" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <!--drag handle column. Disabled until we can work out a way to solve the issues raised here: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/issues/1066 <th style="width: 20px"></th> --> <th style="width: 20%"><?php _e('File Name', 'edd'); ?> </th> <th><?php _e('File URL', 'edd'); ?> </th> <th class="pricing" style="width: 20%; <?php echo $variable_display; ?> "><?php _e('Price Assignment', 'edd'); ?> </th> <?php do_action('edd_download_file_table_head', $post_id); ?> <th style="width: 2%"></th> </tr> </thead> <tbody> <?php if (!empty($files) && is_array($files)) { foreach ($files as $key => $value) { $name = isset($value['name']) ? $value['name'] : ''; $file = isset($value['file']) ? $value['file'] : ''; $condition = isset($value['condition']) ? $value['condition'] : false; $attachment_id = isset($value['attachment_id']) ? absint($value['attachment_id']) : false; $args = apply_filters('edd_file_row_args', compact('name', 'file', 'condition', 'attachment_id'), $value); ?> <tr class="edd_repeatable_upload_wrapper edd_repeatable_row" data-key="<?php echo esc_attr($key); ?> "> <?php do_action('edd_render_file_row', $key, $args, $post_id); ?> </tr> <?php } } else { ?> <tr class="edd_repeatable_upload_wrapper edd_repeatable_row"> <?php do_action('edd_render_file_row', 0, array(), $post_id); ?> </tr> <?php } ?> <tr> <td class="submit" colspan="4" style="float: none; clear:both; background: #fff;"> <a class="button-secondary edd_add_repeatable" style="margin: 6px 0 10px;"><?php _e('Add New File', 'edd'); ?> </a> </td> </tr> </tbody> </table> </div> </div> <?php }
/** * @param $item * @return bool */ protected function is_print_ticket_item($item) { static $download_files = array(); if (empty($download_files)) { $download_files = edd_get_download_files($item['download_id']); } foreach ($download_files as $index => $download) { if ($item['file'] != $index) { continue; } if (self::TICKET_DOWNLOAD === $download['file']) { return true; } if (self::LEGACY_TICKET_DOWNLOAD === $download['file']) { return true; } } return false; }
/** * Gets the download links for each item purchased * * @since 1.1.5 * @param int $payment_id The ID of the payment to retrieve download links for * @return string */ function edd_get_purchase_download_links($payment_id = 0) { $downloads = edd_get_payment_meta_cart_details($payment_id, true); $payment_key = edd_get_payment_key($payment_id); $email = edd_get_payment_user_email($payment_id); $links = '<ul class="edd_download_links">'; foreach ($downloads as $download) { $links .= '<li>'; $links .= '<h3 class="edd_download_link_title">' . esc_html(get_the_title($download['id'])) . '</h3>'; $price_id = isset($download['options']) && isset($download['options']['price_id']) ? $download['options']['price_id'] : null; $files = edd_get_download_files($download['id'], $price_id); if (is_array($files)) { foreach ($files as $filekey => $file) { $links .= '<div class="edd_download_link_file">'; $links .= '<a href="' . esc_url(edd_get_download_file_url($payment_key, $email, $filekey, $download['id'], $price_id)) . '">'; if (isset($file['name'])) { $links .= esc_html($file['name']); } else { $links .= esc_html($file['file']); } $links .= '</a>'; $links .= '</div>'; } } $links .= '</li>'; } $links .= '</ul>'; return $links; }
/** * Retrieves a new download link for a purchased file * * @since 2.0 * @return string */ function edd_ajax_generate_file_download_link() { if (!current_user_can('view_shop_reports')) { die('-1'); } $payment_id = absint($_POST['payment_id']); $download_id = absint($_POST['download_id']); $price_id = absint($_POST['price_id']); if (empty($payment_id)) { die('-2'); } if (empty($download_id)) { die('-3'); } $payment_key = edd_get_payment_key($payment_id); $email = edd_get_payment_user_email($payment_id); $limit = edd_get_file_download_limit($download_id); if (!empty($limit)) { // Increase the file download limit when generating new links edd_set_file_download_limit_override($download_id, $payment_id); } $files = edd_get_download_files($download_id, $price_id); if (!$files) { die('-4'); } $file_urls = ''; foreach ($files as $file_key => $file) { $file_urls .= edd_get_download_file_url($payment_key, $email, $file_key, $download_id, $price_id); $file_urls .= "\n\n"; } die($file_urls); }
/** * Gets the Price ID that can download a file * * @since 1.0.9 * @param int $download_id Download ID * @param string $file_key File Key * @return string - the price ID if restricted, "all" otherwise */ function edd_get_file_price_condition($download_id, $file_key) { $files = edd_get_download_files($download_id); if (!$files) { return false; } $condition = isset($files[$file_key]['condition']) ? $files[$file_key]['condition'] : 'all'; return $condition; }
/** * Retrieve the price option that has access to the specified file * * @since 2.2 * @return int|string */ public function get_file_price_condition($file_key = 0) { $files = edd_get_download_files($this->ID); $condition = isset($files[$file_key]['condition']) ? $files[$file_key]['condition'] : 'all'; return apply_filters('edd_get_file_price_condition', $condition, $this->ID, $files); }
foreach ($purchases as $payment) { $downloads = edd_get_payment_meta_cart_details($payment->ID, true); $purchase_data = edd_get_payment_meta($payment->ID); $email = edd_get_payment_user_email($payment->ID); if ($downloads) { foreach ($downloads as $download) { // Skip over Bundles. Products included with a bundle will be displayed individually if (edd_is_bundled_product($download['id'])) { continue; } ?> <tr class="edd_download_history_row"> <?php $price_id = edd_get_cart_item_price_id($download); $download_files = edd_get_download_files($download['id'], $price_id); $name = get_the_title($download['id']); // Retrieve and append the price option name if (!empty($price_id)) { $name .= ' - ' . edd_get_price_option_name($download['id'], $price_id, $payment->ID); } do_action('edd_download_history_row_start', $payment->ID, $download['id']); ?> <td class="edd_download_download_name"><?php echo esc_html($name); ?> </td> <?php if (!edd_no_redownload()) { ?>
/** * Get the Export Data * * @access public * @since 2.5 * @return array $data The data for the CSV file */ public function get_data() { $data = array(); $meta = array('edd_price', '_edd_files', '_edd_download_limit', '_thumbnail_id', 'edd_sku', 'edd_product_notes', '_edd_download_sales', '_edd_download_earnings'); $args = array('post_type' => 'download', 'posts_per_page' => 30, 'paged' => $this->step); $downloads = new WP_Query($args); if ($downloads->posts) { foreach ($downloads->posts as $download) { $row = array(); foreach ($this->csv_cols() as $key => $value) { // Setup default value $row[$key] = ''; if (in_array($key, $meta)) { switch ($key) { case '_thumbnail_id': $image_id = get_post_thumbnail_id($download->ID); $row[$key] = wp_get_attachment_url($image_id); break; case 'edd_price': if (edd_has_variable_prices($download->ID)) { $prices = array(); foreach (edd_get_variable_prices($download->ID) as $price) { $prices[] = $price['name'] . ': ' . $price['amount']; } $row[$key] = implode(' | ', $prices); } else { $row[$key] = edd_get_download_price($download->ID); } break; case '_edd_files': $files = array(); foreach (edd_get_download_files($download->ID) as $file) { $f = $file['file']; if (edd_has_variable_prices($download->ID)) { $condition = isset($file['condition']) ? $file['condition'] : 'all'; $f .= ';' . $condition; } $files[] = $f; unset($file); } $row[$key] = implode(' | ', $files); break; default: $row[$key] = get_post_meta($download->ID, $key, true); break; } } elseif (isset($download->{$key})) { switch ($key) { case 'post_author': $row[$key] = get_the_author_meta('user_login', $download->post_author); break; default: $row[$key] = $download->{$key}; break; } } elseif ('tags' == $key) { $terms = get_the_terms($download->ID, 'download_tag'); if ($terms) { $terms = wp_list_pluck($terms, 'name'); $row[$key] = implode(' | ', $terms); } } elseif ('categories' == $key) { $terms = get_the_terms($download->ID, 'download_category'); if ($terms) { $terms = wp_list_pluck($terms, 'name'); $row[$key] = implode(' | ', $terms); } } } $data[] = $row; } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; } return false; }
/** * Email Template Tags * * @since 1.0 * * @param string $message Message with the template tags * @param array $payment_data Payment Data * @param int $payment_id Payment ID * * @return string $message Fully formatted message */ function edd_email_template_tags($message, $payment_data, $payment_id) { global $edd_options; $has_tags = strpos($message, '{') !== false; if (!$has_tags) { return $message; } $user_info = maybe_unserialize($payment_data['user_info']); $fullname = ''; if (isset($user_info['id']) && $user_info['id'] > 0 && isset($user_info['first_name'])) { $user_data = get_userdata($user_info['id']); $name = $user_info['first_name']; $fullname = $user_info['first_name'] . ' ' . $user_info['last_name']; $username = $user_data->user_login; } elseif (isset($user_info['first_name'])) { $name = $user_info['first_name']; $fullname = $user_info['first_name'] . ' ' . $user_info['last_name']; $username = $user_info['first_name']; } else { $name = $user_info['email']; $username = $user_info['email']; } $file_urls = ''; $download_list = '<ul>'; $cart_items = edd_get_payment_meta_cart_details($payment_id); if ($cart_items) { $show_names = apply_filters('edd_email_show_names', true); foreach ($cart_items as $item) { if (edd_use_skus()) { $sku = edd_get_download_sku($item['id']); } $price_id = edd_get_cart_item_price_id($item); if ($show_names) { $title = get_the_title($item['id']); if (!empty($sku)) { $title .= " – " . __('SKU', 'edd') . ': ' . $sku; } if ($price_id !== false) { $title .= " – " . edd_get_price_option_name($item['id'], $price_id); } $download_list .= '<li>' . apply_filters('edd_email_receipt_download_title', $title, $item['id'], $price_id) . '<br/>'; $download_list .= '<ul>'; } $files = edd_get_download_files($item['id'], $price_id); if ($files) { foreach ($files as $filekey => $file) { $download_list .= '<li>'; $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $item['id'], $price_id); $download_list .= '<a href="' . esc_url($file_url) . '">' . $file['name'] . '</a>'; $download_list .= '</li>'; $file_urls .= esc_html($file_url) . '<br/>'; } } if ($show_names) { $download_list .= '</ul>'; } if ('' != edd_get_product_notes($item['id'])) { $download_list .= ' — <small>' . edd_get_product_notes($item['id']) . '</small>'; } if ($show_names) { $download_list .= '</li>'; } } } $download_list .= '</ul>'; $subtotal = isset($payment_data['subtotal']) ? $payment_data['subtotal'] : $payment_data['amount']; $subtotal = edd_currency_filter(edd_format_amount($subtotal)); $tax = isset($payment_data['tax']) ? $payment_data['tax'] : 0; $tax = edd_currency_filter(edd_format_amount($tax)); $price = edd_currency_filter(edd_format_amount($payment_data['amount'])); $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true)); $receipt_id = $payment_data['key']; $message = str_replace('{name}', $name, $message); $message = str_replace('{fullname}', $fullname, $message); $message = str_replace('{username}', $username, $message); $message = str_replace('{download_list}', $download_list, $message); $message = str_replace('{file_urls}', $file_urls, $message); $message = str_replace('{date}', date_i18n(get_option('date_format'), strtotime($payment_data['date'])), $message); $message = str_replace('{sitename}', get_bloginfo('name'), $message); $message = str_replace('{subtotal}', $subtotal, $message); $message = str_replace('{tax}', $tax, $message); $message = str_replace('{price}', $price, $message); $message = str_replace('{payment_method}', $gateway, $message); $message = str_replace('{receipt_id}', $receipt_id, $message); $message = str_replace('{payment_id}', $payment_id, $message); $message = str_replace('{receipt_link}', sprintf(__('%1$sView it in your browser.%2$s', 'edd'), '<a href="' . add_query_arg(array('purchase_key' => $receipt_id, 'edd_action' => 'view_receipt'), home_url()) . '">', '</a>'), $message); $message = apply_filters('edd_email_template_tags', $message, $payment_data, $payment_id); return $message; }
/** * Process Get Products API Request * * @access public * @author Daniel J Griffiths * @since 1.5 * @param int $product Product (Download) ID * @return array $customers Multidimensional array of the products */ public function get_products($product = null) { $products = array(); if ($product == null) { $products['products'] = array(); $product_list = get_posts(array('post_type' => 'download', 'posts_per_page' => $this->per_page(), 'paged' => $this->get_paged())); if ($product_list) { $i = 0; foreach ($product_list as $product_info) { $products['products'][$i]['info']['id'] = $product_info->ID; $products['products'][$i]['info']['slug'] = $product_info->post_name; $products['products'][$i]['info']['title'] = $product_info->post_title; $products['products'][$i]['info']['create_date'] = $product_info->post_date; $products['products'][$i]['info']['modified_date'] = $product_info->post_modified; $products['products'][$i]['info']['status'] = $product_info->post_status; $products['products'][$i]['info']['link'] = html_entity_decode($product_info->guid); $products['products'][$i]['info']['content'] = $product_info->post_content; $products['products'][$i]['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID)); $products['products'][$i]['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID); $products['products'][$i]['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID); $products['products'][$i]['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID); $products['products'][$i]['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID); if (edd_has_variable_prices($product_info->ID)) { foreach (edd_get_variable_prices($product_info->ID) as $price) { $products['products'][$i]['pricing'][sanitize_key($price['name'])] = $price['amount']; } } else { $products['products'][$i]['pricing']['amount'] = edd_get_download_price($product_info->ID); } foreach (edd_get_download_files($product_info->ID) as $file) { $products['products'][$i]['files'][] = $file; } $products['products'][$i]['notes'] = edd_get_product_notes($product_info->ID); $i++; } } } else { if (get_post_type($product) == 'download') { $product_info = get_post($product); $products['products'][0]['info']['id'] = $product_info->ID; $products['products'][0]['info']['slug'] = $product_info->post_name; $products['products'][0]['info']['title'] = $product_info->post_title; $products['products'][0]['info']['create_date'] = $product_info->post_date; $products['products'][0]['info']['modified_date'] = $product_info->post_modified; $products['products'][0]['info']['status'] = $product_info->post_status; $products['products'][0]['info']['link'] = html_entity_decode($product_info->guid); $products['products'][0]['info']['content'] = $product_info->post_content; $products['products'][0]['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID)); $products['products'][0]['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID); $products['products'][0]['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID); $products['products'][0]['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID); $products['products'][0]['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID); if (edd_has_variable_prices($product_info->ID)) { foreach (edd_get_variable_prices($product_info->ID) as $price) { $products['products'][0]['pricing'][sanitize_key($price['name'])] = $price['amount']; } } else { $products['products'][0]['pricing']['amount'] = edd_get_download_price($product_info->ID); } foreach (edd_get_download_files($product_info->ID) as $file) { $products['products'][0]['files'][] = $file; } $products['products'][0]['notes'] = edd_get_product_notes($product_info->ID); } else { $error['error'] = sprintf(__('Product %s not found!', 'edd'), $product); return $error; } } return $products; }
<?php get_header(); ?> <div id="single_product_page"> <?php if (have_posts()) { while (have_posts()) { the_post(); ?> <?php $files = edd_get_download_files($post->ID); $exclude = wp_list_pluck($files, 'attachment_id'); // exclude the actual download files $args = array('post_type' => 'attachment', 'numberposts' => null, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'post_parent' => $post->ID, 'posts_per_page' => '99', 'post__not_in' => $exclude); $attachments = get_posts($args); ?> <div <?php post_class(); ?> > <div id="single_item_wrap" class="clearfix"> <div class="posts-wrap"> <div id="product_images"> <?php if (get_post_meta($post->ID, '_dc_embed_link', true) != '') { // if there is a video
/** * Given a download post object, generate the data for the API output * * @since 2.3.9 * @param object $product_info The Download Post Object * @return array Array of post data to return back in the API */ private function get_product_data( $product_info ) { $product = array(); $product['info']['id'] = $product_info->ID; $product['info']['slug'] = $product_info->post_name; $product['info']['title'] = $product_info->post_title; $product['info']['create_date'] = $product_info->post_date; $product['info']['modified_date'] = $product_info->post_modified; $product['info']['status'] = $product_info->post_status; $product['info']['link'] = html_entity_decode( $product_info->guid ); $product['info']['content'] = $product_info->post_content; $product['info']['excerpt'] = $product_info->post_excerpt; $product['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $product_info->ID ) ); $product['info']['category'] = get_the_terms( $product_info, 'download_category' ); $product['info']['tags'] = get_the_terms( $product_info, 'download_tag' ); if( user_can( $this->user_id, 'view_shop_reports' ) || $this->override ) { $product['stats']['total']['sales'] = edd_get_download_sales_stats( $product_info->ID ); $product['stats']['total']['earnings'] = edd_get_download_earnings_stats( $product_info->ID ); $product['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales( $product_info->ID ); $product['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings( $product_info->ID ); } if ( edd_has_variable_prices( $product_info->ID ) ) { foreach ( edd_get_variable_prices( $product_info->ID ) as $price ) { $product['pricing'][ sanitize_key( $price['name'] ) ] = $price['amount']; } } else { $product['pricing']['amount'] = edd_get_download_price( $product_info->ID ); } if( user_can( $this->user_id, 'view_shop_sensitive_data' ) || $this->override ) { foreach ( edd_get_download_files( $product_info->ID ) as $file ) { $product['files'][] = $file; } $product['notes'] = edd_get_product_notes( $product_info->ID ); } return apply_filters( 'edd_api_products_product', $product ); }
/** * The free download process. * * Modified from: * /includes/process-download.php -> edd_process_download() * Modifed parts: * Stripping the purchase validation process. * * @return void */ function vp_edd_fd_process_download() { global $edd_options; $valid = true; $payment = -1; $download = isset($_GET['did']) ? (int) $_GET['did'] : ''; $expire = isset($_GET['expire']) ? base64_decode(rawurldecode($_GET['expire'])) : ''; $file_key = isset($_GET['file']) ? (int) $_GET['file'] : ''; // if( $download === '' || $email === '' || $file_key === '' ) if ($download === '' || $file_key === '') { return false; } // make sure user logged in $must_logged_in = isset($edd_options['vp_edd_fd_must_logged_in']) ? $edd_options['vp_edd_fd_must_logged_in'] : false; if ($must_logged_in) { if (!is_user_logged_in()) { $valid = false; } } // Make sure the link hasn't expired if (current_time('timestamp') > $expire) { wp_die(apply_filters('edd_download_link_expired_text', __('Sorry but your download link has expired.', 'edd')), __('Error', 'edd')); } // Check to see if the file download limit has been reached if (edd_is_file_at_download_limit($download, -1, $file_key)) { wp_die(apply_filters('edd_download_limit_reached_text', __('Sorry but you have hit your download limit for this file.', 'edd')), __('Error', 'edd')); } if ($valid) { // setup the download $download_files = edd_get_download_files($download); $requested_file = apply_filters('edd_requested_file', $download_files[$file_key]['file'], $download_files, $file_key); // gather user data $user_info = array(); if ($must_logged_in) { global $user_ID; $user_data = get_userdata($user_ID); $user_info['email'] = $user_data->user_email; $user_info['id'] = $user_ID; $user_info['name'] = $user_data->display_name; } else { $user_info['email'] = 'anonymous'; $user_info['id'] = 'anonymous'; } edd_record_download_in_log($download, $file_key, $user_info, edd_get_ip(), $payment); $file_extension = edd_get_file_extension($requested_file); $ctype = edd_get_file_ctype($file_extension); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { set_time_limit(0); } if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); } @session_write_close(); if (function_exists('apache_setenv')) { @apache_setenv('no-gzip', 1); } @ini_set('zlib.output_compression', 'Off'); nocache_headers(); header("Robots: none"); header("Content-Type: " . $ctype . ""); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"" . apply_filters('edd_requested_file_name', basename($requested_file)) . "\";"); header("Content-Transfer-Encoding: binary"); $file_path = realpath($requested_file); if (strpos($requested_file, 'http://') === false && strpos($requested_file, 'https://') === false && strpos($requested_file, 'ftp://') === false && file_exists($file_path)) { /** This is an absolute path */ edd_deliver_download($file_path); } else { if (strpos($requested_file, WP_CONTENT_URL) !== false) { /** This is a local file given by URL */ $upload_dir = wp_upload_dir(); $file_path = str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $requested_file); $file_path = realpath($file_path); if (file_exists($file_path)) { edd_deliver_download($file_path); } else { // Absolute path couldn't be discovered so send straight to the file URL header("Location: " . $requested_file); } } else { // This is a remote file header("Location: " . $requested_file); } } exit; } else { wp_die(apply_filters('edd_deny_download_message', __('You do not have permission to download this file.', 'vp_edd_fd')), __('Error', 'edd')); } exit; }
private function is_s3_download($download_id = 0, $file_id = 0) { $ret = false; $files = edd_get_download_files($download_id); if (isset($files[$file_id])) { $file_name = $files[$file_id]['file']; // Check whether thsi is an Amazon S3 file or not if ('/' !== $file_name[0] && strpos($file_name, 'http://') === false && strpos($file_name, 'https://') === false && strpos($file_name, 'ftp://') === false || false !== strpos($file_name, 'AWSAccessKeyId')) { $ret = true; } } return $ret; }
/** @see WP_Widget::widget */ function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); global $user_ID, $edd_options; if (is_user_logged_in()) { $purchases = edd_get_users_purchases($user_ID); if ($purchases) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } foreach ($purchases as $purchase) { $purchase_data = edd_get_payment_meta($purchase->ID); $downloads = edd_get_payment_meta_downloads($purchase->ID); if ($downloads) { foreach ($downloads as $download) { $id = isset($purchase_data['cart_details']) ? $download['id'] : $download; $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null; $download_files = edd_get_download_files($id, $price_id); echo '<div class="edd-purchased-widget-purchase edd-purchased-widget-purchase-' . $purchase->ID . '" id="edd-purchased-widget-purchase-' . $id . '">'; echo '<div class="edd-purchased-widget-purchase-name">' . get_the_title($id) . '</div>'; echo '<ul class="edd-purchased-widget-file-list">'; if (!edd_no_redownload()) { if ($download_files) { foreach ($download_files as $filekey => $file) { $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $id, $price_id); echo '<li class="edd-purchased-widget-file"><a href="' . $download_url . '" class="edd-purchased-widget-file-link">' . $file['name'] . '</a></li>'; } } else { echo '<li class="edd-purchased-widget-no-file">' . __('No downloadable files found.', 'edd'); } } echo '</ul>'; echo '</div>'; } } } } echo $after_widget; } }
<?php do_action('edd_download_history_header_end'); ?> </tr> </thead> <?php foreach ($purchases as $post) { setup_postdata($post); $downloads = edd_get_payment_meta_downloads($post->ID); $purchase_data = edd_get_payment_meta($post->ID); if ($downloads) { foreach ($downloads as $download) { echo '<tr class="edd_download_history_row">'; $id = isset($purchase_data['cart_details']) ? $download['id'] : $download; $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null; $download_files = edd_get_download_files($id, $price_id); do_action('edd_download_history_row_start', $post->ID, $id); echo '<td class="edd_download_download_name">' . get_the_title($id) . '</td>'; if (!edd_no_redownload()) { echo '<td class="edd_download_download_files">'; if ($download_files) { foreach ($download_files as $filekey => $file) { $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $id); echo '<div class="edd_download_file"><a href="' . esc_url($download_url) . '" class="edd_download_file_link">' . esc_html($file['name']) . '</a></div>'; do_action('edd_download_history_files', $filekey, $file, $id, $post->ID, $purchase_data); } } else { _e('No downloadable files found.', 'edd'); } echo '</td>'; }
/** * * @param unknown $payment * @param string $edd_receipt_args */ public function edd_osgi_action_payment_receipt_after_table($payment, $edd_receipt_args = null) { if ($this->osgipub_osgi_debug) { echo "<p>debug: this is the action after table</p>\n"; } if (isset($payment) && edd_is_payment_complete($payment->ID)) { $meta = get_post_meta($payment->ID); if ($this->osgipub_osgi_debug) { echo "<p>debug: Payment vardump="; var_dump($payment); echo "</p>\n"; echo "<p>debug: Payment metadata vardump="; var_dump($meta); echo "</p>\n"; } // same $cart = edd_get_payment_meta_cart_details( $payment->ID, true ); $downloads = edd_get_payment_meta_cart_details($payment->ID, true); $edd_payment_post_id = $payment->ID; $edd_payment_user_id = (string) $meta['_edd_payment_user_id'][0]; $edd_payment_customer_id = (string) $meta['_edd_payment_customer_id'][0]; //TODO REMOVED BECAUSE NOT BEING GENERATED $edd_payment_number = ( string ) $meta ['_edd_payment_number'] [0]; $edd_payment_number = $edd_payment_post_id; $edd_payment_purchase_key = (string) $meta['_edd_payment_purchase_key'][0]; // see easy-digital-downloads/templates/history-downloads.php // add_query_arg( 'payment_key', edd_get_payment_key( $post->ID ), edd_get_success_page_uri() ) if ($downloads) { $display_licence_table = false; // check if any downloads are osgi licenced foreach ($downloads as $download) { if ($this->is_osgi_licenced($download['id'])) { $display_licence_table = true; } } if ($display_licence_table) { echo "<div id=\"osgi_licence_list_table\" class=\"osgi_licence_list\">\n"; echo "<h3>OSGi Licences</h3>\n"; echo "<p>One of more of your purchased downloads have associated OSGi Licences.<BR>To generate your licences select the links below.</p>\n"; echo "<table>\n"; } // used to set change licence name for multiple downloads $download_no = 0; foreach ($downloads as $download) { // Skip over Bundles. Products included with a bundle will be displayed individually if (edd_is_bundled_product($download['id'])) { continue; } // if not osgi licenced bundle skip if (!$this->is_osgi_licenced($download['id'])) { continue; } $download_no++; $price_id = edd_get_cart_item_price_id($download); $download_files = edd_get_download_files($download['id'], $price_id); $name = get_the_title($download['id']); // quantity used to handle multiple licences per download for ($quantity = 1; $quantity <= $download['quantity']; $quantity++) { if (isset($edd_payment_number)) { // start of table row echo " <tr>\n"; echo " <td>\n"; // product id string from download // contains maven unique id of product to which this licence applies $edd_osgiProductIdStr = get_post_meta($download['id'], '_edd_osgiProductIdStr', true); // try loading modified LicenceMetadataSpecStr from this product efinition and apply to licence post $edd_modified_osgiLicenceMetadataSpecStr = get_post_meta($download['id'], '_edd_modified_osgiLicenceMetadataSpecStr', true); // Retrieve and append the price option name if (!empty($price_id)) { $name .= ' - ' . edd_get_price_option_name($download['id'], $price_id, $payment->ID); } // product name - payment number - download number $licence_post_title = $name . ' - ' . $edd_payment_number . '-' . $download_no . '-' . $quantity; // remove whitepsace $licence_post_name = preg_replace('/\\s+/', '', $licence_post_title); if ($this->osgipub_osgi_debug) { echo "<p>debug: download [id]=" . $download['id'] . '</p>\\n'; if (!isset($edd_osgiProductIdStr)) { echo "<p>debug: from download edd_osgiProductIdStr not set for download [id]=" . $download['id'] . '</p>\\n'; } else { echo "<p>debug: from download edd_osgiProductIdStr="; echo $edd_osgiProductIdStr; echo "</p>\n"; } echo "<p>debug: payment name="; echo $name; echo "</p>\n"; echo "<p>debug: licence_post_title="; echo $licence_post_title; echo "</p>\n"; echo "<p>debug: licence_post_name="; echo $licence_post_name; echo "</p>\n"; echo "<p>debug: edd_payment_number="; echo $edd_payment_number; echo "</p>\n"; } $found_post = null; if ($posts = get_posts(array('name' => $licence_post_name, 'post_type' => 'osgi_licence_post', 'post_status' => 'publish', 'posts_per_page' => 1))) { $found_post = $posts[0]; } // Now, we can do something with $found_post if (!is_null($found_post)) { if ($this->osgipub_osgi_debug) { echo "<p>debug: we found the licence post="; echo $found_post->ID; echo "</p>\n"; } echo '<a href="' . get_post_permalink($found_post->ID) . '" >Link to Licence: ' . $licence_post_title . '</a>'; echo "\n"; } else { // get post with payment number metadata OR create post with metadata $post = array('post_content' => '<p>DO NOT EDIT: You can only view or change this licence post by using View Post.</p>', 'post_name' => $licence_post_name, 'post_title' => $licence_post_title, 'post_status' => 'publish', 'post_type' => 'osgi_licence_post', 'ping_status' => 'closed', 'comment_status' => 'closed'); // Default is the option 'default_comment_status', or 'closed'. // 'post_category' => [ array(<category id>, ...) ] // Default empty. // 'tags_input' => [ '<tag>, <tag>, ...' | array ] // Default empty. // 'tax_input' => [ array( <taxonomy> => <array | string> ) ] // For custom taxonomies. Default empty. // 'page_template' => '../edd-downloads-as-osgi.php' // Requires name of template file, eg template.php. Default empty. $newpost_id = wp_insert_post($post); // setting product id for licence // update_post_meta ( $newpost_id, 'edd_osgiProductIdStr', 'org.opennms.co.uk/org.opennms.co.uk.newfeature/0.0.1-SNAPSHOT' ); update_post_meta($newpost_id, 'edd_osgiProductIdStr', $edd_osgiProductIdStr); // apply modified metadata to this licence post update_post_meta($newpost_id, '_edd_modified_osgiLicenceMetadataSpecStr', $edd_modified_osgiLicenceMetadataSpecStr); // setting customer metadata - not yet used in the template update_post_meta($newpost_id, 'edd_payment_customer_id', $edd_payment_customer_id); update_post_meta($newpost_id, 'edd_payment_user_id', $edd_payment_user_id); // setting edd_osgiLicencee information $f_name = (string) get_user_meta($edd_payment_user_id, 'first_name', true); $first_name = isset($f_name) ? $f_name : ""; $l_name = (string) get_user_meta($edd_payment_user_id, 'last_name', true); $last_name = isset($l_name) ? $l_name : ""; $address = ""; $addr = edd_get_customer_address($edd_payment_user_id); if (isset($addr)) { $address = implode(", ", $addr); } $edd_osgiLicencee = $first_name . ", " . $last_name . ", " . $address; update_post_meta($newpost_id, 'edd_osgiLicencee', $edd_osgiLicencee); // for reverse lookup of post id of the associated payment update_post_meta($newpost_id, 'edd_payment_post_id', $edd_payment_post_id); if ($this->osgipub_osgi_debug) { echo "<p>debug: we created a new licence post="; echo $newpost_id; echo "</p>\n"; } echo '<a href="' . get_post_permalink($newpost_id) . '" >Link to Licence: ' . $licence_post_title . '</a>'; echo "\n"; } echo " </td>\n"; echo " </tr>\n"; } } } if ($display_licence_table) { echo "</table>\n"; echo "</div> <!-- div id=osgi_licence_list_table -->"; } } } else { echo '<p>payment not set</p>\\n'; } if ($this->osgipub_osgi_debug) { if (isset($edd_receipt_args)) { echo "<p>debug: edd_receipt_args vardump="; var_dump($edd_receipt_args); echo "</p>\n"; } else { echo '<p>debug: edd_receipt_args not set</p>\\n'; } } }
/** * Process Get Downloads API Request to retrieve download logs * * @access public * @since 2.5 * @author Daniel J Griffiths * * @param int $customer_id The customer ID you wish to retrieve download logs for * @return array Multidimensional array of the download logs */ public function get_download_logs($customer_id = 0) { global $edd_logs; $downloads = array(); $errors = array(); $paged = $this->get_paged(); $per_page = $this->per_page(); $offset = $per_page * ($paged - 1); $meta_query = array(); if (!empty($customer_id)) { $customer = new EDD_Customer($customer_id); $invalid_customer = false; if ($customer->id > 0) { $meta_query['relation'] = 'OR'; if ($customer->id > 0) { // Based on customer->user_id $meta_query[] = array('key' => '_edd_log_user_id', 'value' => $customer->user_id); } // Based on customer->email $meta_query[] = array('key' => '_edd_log_user_info', 'value' => $customer->email, 'compare' => 'LIKE'); } else { $invalid_customer = true; } } $query = array('log_type' => 'file_download', 'paged' => $paged, 'meta_query' => $meta_query, 'posts_per_page' => $per_page, 'update_post_meta_cache' => false, 'update_post_term_cache' => false); $logs = array(); if (!$invalid_customer) { $logs = $edd_logs->get_connected_logs($query); } if (empty($logs)) { $error['error'] = __('No download logs found!', 'easy-digital-downloads'); return $error; } foreach ($logs as $log) { $item = array(); $log_meta = get_post_custom($log->ID); $user_info = isset($log_meta['_edd_log_user_info']) ? maybe_unserialize($log_meta['_edd_log_user_info'][0]) : array(); $payment_id = isset($log_meta['_edd_log_payment_id']) ? $log_meta['_edd_log_payment_id'][0] : false; $payment_customer_id = edd_get_payment_customer_id($payment_id); $payment_customer = new EDD_Customer($payment_customer_id); $user_id = $payment_customer->user_id > 0 ? $payment_customer->user_id : false; $ip = $log_meta['_edd_log_ip'][0]; $files = edd_get_payment_meta_downloads($payment_id); $files = edd_get_download_files($files[0]['id']); $file_id = (int) $log_meta['_edd_log_file_id'][0]; $file_id = $file_id !== false ? $file_id : 0; $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null; $item = array('ID' => $log->ID, 'user_id' => $user_id, 'product_id' => $log->post_parent, 'product_name' => get_the_title($log->post_parent), 'customer_id' => $payment_customer_id, 'payment_id' => $payment_id, 'file' => $file_name, 'ip' => $ip, 'date' => $log->post_date); $item = apply_filters('edd_api_download_log_item', $item, $log, $log_meta); $downloads['download_logs'][] = $item; } return $downloads; }
/** * Gets the log entries for the current view * * @access private * @since 1.4 * @return array */ function get_logs() { global $edd_logs; $logs_data = array(); $paged = $this->get_paged(); $download = empty($_GET['s']) ? $this->get_filtered_download() : null; $log_query = array('post_parent' => $download, 'log_type' => 'file_download', 'paged' => $paged, 'meta_query' => $this->get_meta_query()); $logs = $edd_logs->get_connected_logs($log_query); if ($logs) { foreach ($logs as $log) { $user_info = get_post_meta($log->ID, '_edd_log_user_info', true); $payment_id = get_post_meta($log->ID, '_edd_log_payment_id', true); $ip = get_post_meta($log->ID, '_edd_log_ip', true); $user_id = isset($user_info['id']) ? $user_info['id'] : 0; $user_data = get_userdata($user_id); $files = edd_get_download_files($log->post_parent); $file_id = (int) get_post_meta($log->ID, '_edd_log_file_id', true); $file_id = $file_id !== false ? $file_id : 0; $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null; if ($this->file_search && strpos(strtolower($file_name), strtolower($this->get_search())) !== false || !$this->file_search) { $logs_data[] = array('ID' => $log->ID, 'download' => $log->post_parent, 'payment_id' => $payment_id, 'user_id' => $user_data ? $user_data->ID : $user_info['email'], 'user_name' => $user_data ? $user_data->display_name : $user_info['email'], 'file' => $file_name, 'ip' => $ip, 'date' => $log->post_date); } } } return $logs_data; }
<?php } ?> <span class="price-text"><?php echo edd_currency_filter(edd_format_amount($price), $currency_code); ?> </span> </li> <li class="actions"> <input type="hidden" class="edd-payment-details-download-has-log" name="edd-payment-details-downloads[<?php echo $key; ?> ][has_log]" value="1" /> <?php if (edd_get_download_files($item_id, $price_id) && edd_is_payment_complete($payment_id)) { ?> <a href="" class="edd-copy-download-link" data-download-id="<?php echo esc_attr($item_id); ?> " data-price-id="<?php echo esc_attr($price_id); ?> "><?php _e('Copy Download Link(s)', 'edd'); ?> </a> | <?php } ?> <a href="" class="edd-order-remove-download edd-delete" data-key="<?php
/** * Email template tag: file_urls * A plain-text list of download URLs for each download purchased * * @param int $payment_id * * @return string $file_urls */ function edd_email_tag_file_urls($payment_id) { $payment_data = edd_get_payment_meta($payment_id); $file_urls = ''; $cart_items = edd_get_payment_meta_cart_details($payment_id); $email = edd_get_payment_user_email($payment_id); foreach ($cart_items as $item) { $price_id = edd_get_cart_item_price_id($item); $files = edd_get_download_files($item['id'], $price_id); if ($files) { foreach ($files as $filekey => $file) { $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $item['id'], $price_id); $file_urls .= esc_html($file_url) . '<br/>'; } } elseif (edd_is_bundled_product($item['id'])) { $bundled_products = apply_filters('edd_email_tag_bundled_products', edd_get_bundled_products($item['id']), $item, $payment_id, 'file_urls'); foreach ($bundled_products as $bundle_item) { $files = edd_get_download_files($bundle_item); foreach ($files as $filekey => $file) { $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $bundle_item, $price_id); $file_urls .= esc_html($file_url) . '<br/>'; } } } } return $file_urls; }
</li> <?php do_action('edd_receipt_files', $filekey, $file, $item['id'], $payment->ID, $meta); } } elseif (edd_is_bundled_product($item['id'])) { $bundled_products = edd_get_bundled_products($item['id']); foreach ($bundled_products as $bundle_item) { ?> <li class="edd_bundled_product"> <span class="edd_bundled_product_name"><?php echo get_the_title($bundle_item); ?> </span> <ul class="edd_bundled_product_files"> <?php $download_files = edd_get_download_files($bundle_item); if ($download_files && is_array($download_files)) { foreach ($download_files as $filekey => $file) { $download_url = edd_get_download_file_url($meta['key'], $email, $filekey, $bundle_item, $price_id); ?> <li class="edd_download_file"> <a href="<?php echo esc_url($download_url); ?> " class="edd_download_file_link"><?php echo esc_html($file['name']); ?> </a> </li> <?php do_action('edd_receipt_bundle_files', $filekey, $file, $item['id'], $bundle_item, $payment->ID, $meta);
/** * Process Download * * Handles the file download process. * * @access private * @since 1.0 * @return void */ function edd_process_download() { if (!isset($_GET['download_id']) && isset($_GET['download'])) { $_GET['download_id'] = $_GET['download']; } $args = apply_filters('edd_process_download_args', array('download' => isset($_GET['download_id']) ? (int) $_GET['download_id'] : '', 'email' => isset($_GET['email']) ? rawurldecode($_GET['email']) : '', 'expire' => isset($_GET['expire']) ? rawurldecode($_GET['expire']) : '', 'file_key' => isset($_GET['file']) ? (int) $_GET['file'] : '', 'price_id' => isset($_GET['price_id']) ? (int) $_GET['price_id'] : false, 'key' => isset($_GET['download_key']) ? $_GET['download_key'] : '', 'eddfile' => isset($_GET['eddfile']) ? $_GET['eddfile'] : '', 'ttl' => isset($_GET['ttl']) ? $_GET['ttl'] : '', 'token' => isset($_GET['token']) ? $_GET['token'] : '')); if (!empty($args['eddfile']) && !empty($args['ttl']) && !empty($args['token'])) { // Validate a signed URL that edd_process_signed_download_urlcontains a token $args = edd_process_signed_download_url($args); // Backfill some legacy super globals for backwards compatibility $_GET['download_id'] = $args['download']; $_GET['email'] = $args['email']; $_GET['expire'] = $args['expire']; $_GET['download_key'] = $args['key']; $_GET['price_id'] = $args['price_id']; } elseif (!empty($args['download']) && !empty($args['key']) && !empty($args['email']) && !empty($args['expire']) && isset($args['file_key'])) { // Validate a legacy URL without a token $args = edd_process_legacy_download_url($args); } else { return; } $args['has_access'] = apply_filters('edd_file_download_has_access', $args['has_access'], $args['payment'], $args); //$args['has_access'] = ( edd_logged_in_only() && is_user_logged_in() ) || !edd_logged_in_only() ? true : false; if ($args['payment'] && $args['has_access']) { do_action('edd_process_verified_download', $args['download'], $args['email'], $args['payment'], $args); // Determine the download method set in settings $method = edd_get_file_download_method(); // Payment has been verified, setup the download $download_files = edd_get_download_files($args['download']); $attachment_id = !empty($download_files[$args['file_key']]['attachment_id']) ? absint($download_files[$args['file_key']]['attachment_id']) : false; /* * If we have an attachment ID stored, use get_attached_file() to retrieve absolute URL * If this fails or returns a relative path, we fail back to our own absolute URL detection */ if ($attachment_id && 'attachment' == get_post_type($attachment_id)) { if ('redirect' == $method) { $attached_file = wp_get_attachment_url($attachment_id); } else { $attached_file = get_attached_file($attachment_id, false); // Confirm the file exists if (!file_exists($attached_file)) { $attached_file = false; } } if ($attached_file) { $requested_file = $attached_file; } } // If we didn't find a file from the attachment, grab the given URL if (!isset($requested_file)) { $requested_file = isset($download_files[$args['file_key']]['file']) ? $download_files[$args['file_key']]['file'] : ''; } // Allow the file to be altered before any headers are sent $requested_file = apply_filters('edd_requested_file', $requested_file, $download_files, $args['file_key']); if ('x_sendfile' == $method && (!function_exists('apache_get_modules') || !in_array('mod_xsendfile', apache_get_modules()))) { // If X-Sendfile is selected but is not supported, fallback to Direct $method = 'direct'; } $file_details = parse_url($requested_file); $schemes = array('http', 'https'); // Direct URL schemes if ((!isset($file_details['scheme']) || !in_array($file_details['scheme'], $schemes)) && isset($file_details['path']) && file_exists($requested_file)) { /** * Download method is seto to Redirect in settings but an absolute path was provided * We need to switch to a direct download in order for the file to download properly */ $method = 'direct'; } /** * Allow extensions to run actions prior to recording the file download log entry * * @since 2.6.14 */ do_action('edd_process_download_pre_record_log', $requested_file, $args, $method); // Record this file download in the log $user_info = array(); $user_info['email'] = $args['email']; if (is_user_logged_in()) { $user_data = get_userdata(get_current_user_id()); $user_info['id'] = get_current_user_id(); $user_info['name'] = $user_data->display_name; } edd_record_download_in_log($args['download'], $args['file_key'], $user_info, edd_get_ip(), $args['payment'], $args['price_id']); $file_extension = edd_get_file_extension($requested_file); $ctype = edd_get_file_ctype($file_extension); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { @set_time_limit(0); } if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime() && version_compare(phpversion(), '5.4', '<')) { set_magic_quotes_runtime(0); } @session_write_close(); if (function_exists('apache_setenv')) { @apache_setenv('no-gzip', 1); } @ini_set('zlib.output_compression', 'Off'); do_action('edd_process_download_headers', $requested_file, $args['download'], $args['email'], $args['payment']); nocache_headers(); header("Robots: none"); header("Content-Type: " . $ctype . ""); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"" . apply_filters('edd_requested_file_name', basename($requested_file)) . "\""); header("Content-Transfer-Encoding: binary"); // If the file isn't locally hosted, process the redirect if (filter_var($requested_file, FILTER_VALIDATE_URL) && !edd_is_local_file($requested_file)) { edd_deliver_download($requested_file, true); exit; } switch ($method) { case 'redirect': // Redirect straight to the file edd_deliver_download($requested_file, true); break; case 'direct': default: $direct = false; $file_path = $requested_file; if ((!isset($file_details['scheme']) || !in_array($file_details['scheme'], $schemes)) && isset($file_details['path']) && file_exists($requested_file)) { /** This is an absolute path */ $direct = true; $file_path = $requested_file; } else { if (defined('UPLOADS') && strpos($requested_file, UPLOADS) !== false) { /** * This is a local file given by URL so we need to figure out the path * UPLOADS is always relative to ABSPATH * site_url() is the URL to where WordPress is installed */ $file_path = str_replace(site_url(), '', $requested_file); $file_path = realpath(ABSPATH . $file_path); $direct = true; } else { if (strpos($requested_file, content_url()) !== false) { /** This is a local file given by URL so we need to figure out the path */ $file_path = str_replace(content_url(), WP_CONTENT_DIR, $requested_file); $file_path = realpath($file_path); $direct = true; } else { if (strpos($requested_file, set_url_scheme(content_url(), 'https')) !== false) { /** This is a local file given by an HTTPS URL so we need to figure out the path */ $file_path = str_replace(set_url_scheme(content_url(), 'https'), WP_CONTENT_DIR, $requested_file); $file_path = realpath($file_path); $direct = true; } } } } // Set the file size header header("Content-Length: " . @filesize($file_path)); // Now deliver the file based on the kind of software the server is running / has enabled if (stristr(getenv('SERVER_SOFTWARE'), 'lighttpd')) { header("X-LIGHTTPD-send-file: {$file_path}"); } elseif ($direct && (stristr(getenv('SERVER_SOFTWARE'), 'nginx') || stristr(getenv('SERVER_SOFTWARE'), 'cherokee'))) { // We need a path relative to the domain $file_path = str_ireplace(realpath($_SERVER['DOCUMENT_ROOT']), '', $file_path); header("X-Accel-Redirect: /{$file_path}"); } if ($direct) { edd_deliver_download($file_path); } else { // The file supplied does not have a discoverable absolute path edd_deliver_download($requested_file, true); } break; } edd_die(); } else { $error_message = __('You do not have permission to download this file', 'easy-digital-downloads'); wp_die(apply_filters('edd_deny_download_message', $error_message, __('Purchase Verification Failed', 'easy-digital-downloads')), __('Error', 'easy-digital-downloads'), array('response' => 403)); } exit; }