/** * 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); } }
/** * Sets up test set with criteria to test postMatchesCriteria * Any parameter can be null and no meta will be saved * * @param int $startOffset The offset in days from today * @param int $endOffset The offset in days from today * @param bool $weekScheme Whether the week scheme shall match * @param array $postArgs Custom args for the new post * @return WP_Post The post representing the newly created set */ protected function setUpSetWithCriteria($startOffset = null, $endOffset = null, $weekScheme = null, $postArgs = array()) { $ts = new TestScenario($this->factory); $post = $ts->setUpBasicSet($postArgs); if ($startOffset !== null) { $date = new DateTime('00:00'); $interval = new DateInterval('P' . abs($startOffset) . 'D'); if ($startOffset < 0) { $interval->invert = 1; } $date->add($interval); update_post_meta($post->ID, get_meta_key('date-start', SetPostType::CPT_SLUG), $date->format(Dates::STD_DATE_FORMAT)); } if ($endOffset !== null) { $date = new DateTime('23:59:59'); $interval = new DateInterval('P' . abs($endOffset) . 'D'); if ($endOffset < 0) { $interval->invert = 1; } $date->add($interval); update_post_meta($post->ID, get_meta_key('date-end', SetPostType::CPT_SLUG), $date->format(Dates::STD_DATE_FORMAT)); } if ($weekScheme === null) { $wsm = 'all'; } else { $now = new DateTime('now'); $nowEven = (int) $now->format('W') % 2 === 0; if (!$weekScheme) { $nowEven = !$nowEven; } $wsm = $nowEven ? 'even' : 'odd'; } update_post_meta($post->ID, get_meta_key('week-scheme', SetPostType::CPT_SLUG), $wsm); return $post; }