/** * Set the file headers and force the download of a given file * * @return void */ public function download() { if (isset($_GET['download']) && isset($_GET['payment_id'])) { $transaction_id = urldecode($_GET['download']); $payment_id = urldecode($_GET['payment_id']); $product_id = urldecode($_GET['product_id']); // Old download links might not have attachment_id set. // This means they were purchased before we added support // for multiple attachments. So, we just grab the first // attachment_id saved in post meta. $attachment_id = !empty($_GET['attachment_id']) ? urldecode($_GET['attachment_id']) : sell_media_get_attachment_id($product_id); $size_id = !empty($_GET['size_id']) ? urldecode($_GET['size_id']) : null; $verified = apply_filters('sell_media_verify_download', $this->verify($transaction_id, $payment_id), $product_id); if ($verified) { $file = Sell_Media()->products->get_protected_file($product_id, $attachment_id); if (!file_exists($file)) { wp_die(__('The original high resolution file doesn\'t exist here: %1$s', 'sell_media'), $file); exit; } $file_type = wp_check_filetype($file); if (!ini_get('safe_mode')) { set_time_limit(0); } if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); } if (function_exists('apache_setenv')) { @apache_setenv('no-gzip', 1); } @ini_set('zlib.output_compression', 'Off'); nocache_headers(); header("Robots: none"); header("Content-Type: " . $file_type['type'] . ""); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"" . basename($file) . "\""); header("Content-Transfer-Encoding: binary"); // If image, generate the image sizes purchased and create a download if (wp_attachment_is_image($attachment_id)) { $this->download_image($product_id, $attachment_id, $size_id); } else { $this->download_file($file); } do_action('sell_media_after_successful_download', $product_id); exit; } else { do_action('sell_media_before_failed_download', $product_id, $attachment_id); wp_die(__('You do not have permission to download this file', 'sell_media'), __('Purchase Verification Failed', 'sell_media')); } exit; } // Rend purchase receipt? if (isset($_GET['resend_email']) && isset($_GET['payment_id'])) { $payment_id = $_GET['payment_id']; $payment_email = get_meta_key($payment_id, 'email'); Sell_Media()->payments->email_receipt($payment_id, $payment_email); } }
/** * Loop over products in payment meta and format them * * @param $post_id (int) The post_id for a post of post type "sell_media_payment" * * @return html */ public function get_payment_products_formatted($post_id = null, $inline_css = false) { $products = $this->get_products($post_id); $tax = $this->get_meta_key($post_id, $key = 'tax'); $shipping = $this->get_meta_key($post_id, $key = 'shipping'); $discount = $this->get_meta_key($post_id, $key = 'discount'); $total = $this->get_meta_key($post_id, $key = 'total'); $css = $inline_css ? 'border-bottom: 1px solid #ccc; padding: 0.5rem; text-align: left;' : ''; $style = apply_filters('sell_media_products_table_style', $css); if ($products) { $html = null; $html .= '<table class="sell-media-products sell-media-products-payment-' . $post_id . '" border="0" width="100%" style="border-collapse:collapse">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th style="' . $style . ' font-weight: bold;">' . __('Product', 'sell_media') . '</th>'; $html .= '<th style="' . $style . ' font-weight: bold;">' . __('Size', 'sell_media') . '</th>'; $html .= '<th style="' . $style . ' font-weight: bold;">' . __('License', 'sell_media') . '</th>'; $html .= '<th class="text-center" style="' . $style . ' text-align: center; font-weight: bold;">' . __('Qty', 'sell_media') . '</th>'; $html .= '<th class="sell-media-product-subtotal" style="' . $style . ' text-align: right; font-weight: bold;">' . __('Subtotal', 'sell_media') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; foreach ($products as $product) { // Old purchase links didn't have attachment_id set // So we derive the attachment_id from the product's post_meta $product['attachment'] = !empty($product['attachment']) ? $product['attachment'] : sell_media_get_attachment_id($product['id']); // If license description exists, show it. $product['license']['desc'] = term_description($product['license']['id'], 'licenses') ? '<br /><span class="license_desc">' . term_description($product['license']['id'], 'licenses') . '</span>' : ''; if (!empty($product['id'])) { $html .= '<tr class="sell-media-product sell-media-product-' . $product['id'] . '">'; $html .= '<td class="sell-media-product-id" style="' . $style . '">'; if (isset($product['id']) && !is_array($product['id'])) { $html .= '#' . $product['id'] . ', ' . $product['name'] . '<br />'; $html .= '<a href="' . $this->get_download_link($post_id, $product['id'], $product['attachment'], $product['size']['id']) . '">' . sell_media_item_icon($product['attachment'], 'thumbnail', false) . '</a><br />'; if ('download' == $product['type']) { $html .= '<a href="' . $this->get_download_link($post_id, $product['id'], $product['attachment'], $product['size']['id']) . '" class="text-center">' . __('Download', 'sell_media') . '</a>'; } elseif ('print' == $product['type']) { $html .= apply_filters('sell_media_product_delivery_text', 'Your print will be mailed to you shortly.'); } } $html .= '</td>'; $html .= '<td class="sell-media-product-size" style="' . $style . '">'; if (isset($product['size']['name']) && !is_array($product['size']['name'])) { $html .= $product['size']['name']; } $html .= '</td>'; $html .= '<td class="sell-media-product-license" style="' . $style . '">'; if (isset($product['license']['name']) && !is_array($product['license']['name'])) { $html .= $product['license']['name'] . $product['license']['desc']; } $html .= '</td>'; $html .= '<td class="sell-media-product-qty text-center" style="' . $style . ' text-align: center;">'; if (isset($product['qty']) && !is_array($product['qty'])) { $html .= $product['qty']; } $html .= '</td>'; $html .= '<td class="sell-media-product-total" style="' . $style . ' text-align: right;">'; if (isset($product['total']) && !is_array($product['total'])) { $html .= sell_media_get_currency_symbol() . sprintf("%0.2f", $product['total']); } $html .= '</td>'; $html .= '</tr>'; } } $html .= '</tbody>'; $html .= '<tfoot>'; $html .= '<tr>'; $html .= '<td> </td>'; $html .= '<td> </td>'; $html .= '<td> </td>'; $html .= '<td> </td>'; $html .= '<td class="sell-media-products-grandtotal" style="border-bottom: 3px solid #ccc; padding: 0.5rem; text-align: right;">'; if ($discount) { $html .= __('DISCOUNT', 'sell_media') . ': -' . sell_media_get_currency_symbol() . $this->get_discount_total($post_id) . '<br />'; } if ($tax) { $html .= __('TAX', 'sell_media') . ': ' . sell_media_get_currency_symbol() . number_format($tax, 2, '.', ',') . '<br />'; } if ($shipping) { $html .= __('SHIPPING', 'sell_media') . ': ' . sell_media_get_currency_symbol() . number_format($shipping, 2, '.', ',') . '<br />'; } do_action('sell_media_above_products_formatted_table_total', $post_id); $html .= '<strong>' . __('TOTAL', 'sell_media') . ': ' . sell_media_get_currency_symbol() . number_format($this->get_meta_key($post_id, $key = 'total'), 2, '.', ',') . '</strong>'; $html .= '</td>'; $html .= '</tr>'; $html .= '</table>'; do_action('sell_media_below_products_formatted_table', $post_id); return $html; } }
/** * Show additional file info * * @since 1.9.2 * @param int $post_id Item ID * @return void */ function sell_media_show_file_info() { $post = get_post(); $attachment_id = sell_media_get_attachment_id($post->ID); $media_dims = ''; $meta = wp_get_attachment_metadata($attachment_id); $filename = basename(get_attached_file($attachment_id)); $postguid = get_the_guid($attachment_id); echo '<h2 class="widget-title sell-media-item-details-title">' . __('Details', 'sell_media') . '</h2>'; echo '<ul class="sell-media-item-details">'; echo '<li class="filename"><span class="title">' . __('File Name', 'sell_media') . ':</span> ' . $filename . '</li>'; echo '<li class="fileid"><span class="title">' . __('File ID', 'sell_media') . ':</span> ' . $attachment_id . '</li>'; preg_match('/^.*?\\.(\\w+)$/', $filename, $ext); echo '<li class="filetype"><span class="title">' . __('File Type', 'sell_media') . ':</span> ' . esc_html(strtoupper($ext[1])) . ' (' . get_post_mime_type($attachment_id) . ')</li>'; echo '<li class="filesize"><span class="title">' . __('File Size', 'sell_media') . ':</span> ' . sell_media_get_filesize($post->ID, $attachment_id) . '</li>'; if (isset($meta['width'], $meta['height'])) { echo '<li class="filedims"><span class="title">' . __('Dimensions', 'sell_media') . ':</span> ' . $meta['width'] . ' x ' . $meta['height'] . '</li>'; } if (wp_get_post_terms($post->ID, 'collection')) { echo '<li class="collections"><span class="title">' . __('Collections', 'sell_media') . ':</span> ' . sell_media_get_taxonomy_terms('collection') . '</li>'; } if (wp_get_post_terms($post->ID, 'keywords') && !get_query_var('id')) { echo '<li class="keywords"><span class="title">' . __('Keywords', 'sell_media') . ':</span> ' . sell_media_get_taxonomy_terms('keywords') . '</li>'; } if (preg_match('#^(audio|video)/#', get_post_mime_type($attachment_id))) { echo '<li class="length"><span class="title">' . __('Length', 'sell_media') . ':</span> ' . $meta['length_formatted'] . '</li>'; echo '<li class="bitrate"><span class="title">' . __('Bitrate', 'sell_media') . ':</span> ' . round($meta['bitrate'] / 1000) . 'kb/s</li>'; } echo do_action('sell_media_additional_list_items', $post->ID); echo '</ul>'; }
/** * Show additional file info * * @since 1.9.2 * @param int $post_id Item ID * @return void */ function sell_media_show_file_info() { global $post; $attachment_id = sell_media_get_attachment_id($post->ID); echo '<h2 class="widget-title">' . __('Details', 'sell_media') . '</h2>'; echo '<ul>'; echo '<li class="filename"><span class="title">' . __('File ID', 'sell_media') . ':</span> ' . $attachment_id . '</li>'; echo '<li class="filetype"><span class="title">' . __('File Type', 'sell_media') . ':</span> ' . get_post_mime_type($attachment_id) . '</li>'; echo '<li class="filesize"><span class="title">' . __('File Size', 'sell_media') . ':</span> ' . sell_media_get_filesize($post->ID, $attachment_id) . '</li>'; if (wp_get_post_terms($post->ID, 'collection')) { echo '<li class="collections"><span class="title">' . __('Collections', 'sell_media') . ':</span> ' . sell_media_get_taxonomy_terms('collection') . '</li>'; } if (wp_get_post_terms($post->ID, 'keywords') && !get_query_var('id')) { echo '<li class="keywords"><span class="title">' . __('Keywords', 'sell_media') . ':</span> ' . sell_media_get_taxonomy_terms('keywords') . '</li>'; } echo do_action('sell_media_additional_list_items', $post->ID); echo '</ul>'; }
/** * Query lightbox items */ function sell_media_lightbox_query() { $html = ''; // Decode the lightbox array of IDs since they're encoded if (isset($_COOKIE['sell_media_lightbox'])) { $items = json_decode(stripslashes($_COOKIE['sell_media_lightbox']), true); } // Check if items in lightbox if (isset($items)) { $i = 0; // loop over items from 'sell_media_lightbox' cookie foreach ($items as $item) { // Old cookies were stored as simple array of ids // New cookies are stored as a multidimensional array of ids // so that we can support attachments (galleries) $post_id = !empty($item['post_id']) ? $item['post_id'] : $item; $attachment_id = !empty($item['attachment_id']) ? $item['attachment_id'] : sell_media_get_attachment_id($post_id); $permalink = !empty($item['attachment_id']) ? add_query_arg('id', $attachment_id, get_permalink($post_id)) : get_permalink($attachment_id); $i++; $class = $i % 3 == 0 ? ' end' : ''; $html .= '<div id="sell-media-' . $attachment_id . '" class="sell-media-grid' . $class . '">'; $html .= '<div class="item-inner">'; $html .= '<a href="' . esc_url($permalink) . '">' . sell_media_item_icon($attachment_id, apply_filters('sell_media_thumbnail', 'medium'), false) . '</a>'; $html .= '<span class="item-overlay">'; $html .= '<h3><a href="' . esc_url($permalink) . '">' . get_the_title($post_id) . '</a></h3>'; $html .= sell_media_item_buy_button($post_id, $attachment_id, 'text', __('Buy', 'sell_media'), false); $html .= sell_media_lightbox_link($post_id, $attachment_id); $html .= '</span>'; $html .= '</div>'; $html .= '</div>'; } } else { $html .= __('Your lightbox is empty.', 'sell_media'); } return $html; }