コード例 #1
0
ファイル: ajax.functions.php プロジェクト: hornet9/Morato
function wpsc_download_file()
{
    global $wpdb;
    if (isset($_GET['downloadid'])) {
        // strip out anything that isnt 'a' to 'z' or '0' to '9'
        ini_set('max_execution_time', 10800);
        $downloadid = preg_replace("/[^a-z0-9]+/i", '', strtolower($_GET['downloadid']));
        $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `uniqueid` = '" . $downloadid . "' AND `downloads` > '0' AND `active`='1' LIMIT 1", ARRAY_A);
        if ($download_data == null && is_numeric($downloadid)) {
            $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `id` = '" . $downloadid . "' AND `downloads` > '0' AND `active`='1' AND `uniqueid` IS NULL LIMIT 1", ARRAY_A);
        }
        if (get_option('wpsc_ip_lock_downloads') == 1 && $_SERVER['REMOTE_ADDR'] != null) {
            $ip_number = $_SERVER['REMOTE_ADDR'];
            if ($download_data['ip_number'] == '') {
                // if the IP number is not set, set it
                $wpdb->update(WPSC_TABLE_DOWNLOAD_STATUS, array('ip_number' => $ip_number), array('id' => $download_data['id']));
            } else {
                if ($ip_number != $download_data['ip_number']) {
                    // if the IP number is set but does not match, fail here.
                    exit(_e('This download is no longer valid, Please contact the site administrator for more information.', 'wpsc'));
                }
            }
        }
        $file_id = $download_data['fileid'];
        $file_data = wpsc_get_downloadable_file($file_id);
        if ($file_data == null) {
            exit(_e('This download is no longer valid, Please contact the site administrator for more information.', 'wpsc'));
        }
        if ($download_data != null) {
            if ((int) $download_data['downloads'] >= 1) {
                $download_count = (int) $download_data['downloads'] - 1;
            } else {
                $download_count = 0;
            }
            $wpdb->update(WPSC_TABLE_DOWNLOAD_STATUS, array('downloads' => $download_count), array('id' => $download_data['id']));
            $cart_contents = $wpdb->get_results("SELECT `" . WPSC_TABLE_CART_CONTENTS . "`.*, {$wpdb->posts}.`guid` FROM `" . WPSC_TABLE_CART_CONTENTS . "` LEFT JOIN {$wpdb->posts} ON `" . WPSC_TABLE_CART_CONTENTS . "`.`prodid`= {$wpdb->posts}.`post_parent` WHERE {$wpdb->posts}.`post_type` = 'wpsc-product-file' AND `purchaseid` =" . $download_data['purchid'], ARRAY_A);
            $dl = 0;
            foreach ($cart_contents as $cart_content) {
                if ($cart_content['guid'] == 1) {
                    $dl++;
                }
            }
            if (count($cart_contents) == $dl) {
                $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('processed' => '4'), array('id' => $download_data['purchid']));
            }
            do_action('wpsc_alter_download_action', $file_id);
            $file_path = WPSC_FILE_DIR . basename($file_data->post_title);
            $file_name = basename($file_data->post_title);
            if (is_file($file_path)) {
                if (!ini_get('safe_mode')) {
                    set_time_limit(0);
                }
                header('Content-Type: ' . $file_data->post_mime_type);
                header('Content-Length: ' . filesize($file_path));
                header('Content-Transfer-Encoding: binary');
                header('Content-Disposition: attachment; filename="' . stripslashes($file_name) . '"');
                if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != '') {
                    /*
                     There is a bug in how IE handles downloads from servers using HTTPS, this is part of the fix, you may also need:
                     session_cache_limiter('public');
                     session_cache_expire(30);
                     At the start of your index.php file or before the session is started
                    */
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header("Cache-Control: public");
                } else {
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                }
                header("Pragma: public");
                header("Expires: 0");
                // destroy the session to allow the file to be downloaded on some buggy browsers and webservers
                session_destroy();
                wpsc_readfile_chunked($file_path);
                exit;
            } else {
                wp_die(__('Sorry something has gone wrong with your download!', 'wpsc'));
            }
        } else {
            exit(_e('This download is no longer valid, Please contact the site administrator for more information.', 'wpsc'));
        }
    }
}
コード例 #2
0
ファイル: ajax.functions.php プロジェクト: alx/SBek-Arak
function nzshpcrt_download_file()
{
    global $wpdb, $user_level, $wp_rewrite;
    get_currentuserinfo();
    if (isset($_GET['downloadid'])) {
        // strip out anything that isnt 'a' to 'z' or '0' to '9'
        //ini_set('max_execution_time',10800);
        $downloadid = preg_replace("/[^a-z0-9]+/i", '', strtolower($_GET['downloadid']));
        $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `uniqueid` = '" . $downloadid . "' AND `downloads` > '0' AND `active`='1' LIMIT 1", ARRAY_A);
        if ($download_data == null && is_numeric($downloadid)) {
            $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `id` = '" . $downloadid . "' AND `downloads` > '0' AND `active`='1' AND `uniqueid` IS NULL LIMIT 1", ARRAY_A);
        }
        if (get_option('wpsc_ip_lock_downloads') == 1 && $_SERVER['REMOTE_ADDR'] != null) {
            $ip_number = $_SERVER['REMOTE_ADDR'];
            if ($download_data['ip_number'] == '') {
                // if the IP number is not set, set it
                $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `ip_number` = '{$ip_number}' WHERE `id` = '{$download_data['id']}' LIMIT 1");
            } else {
                if ($ip_number != $download_data['ip_number']) {
                    // if the IP number is set but does not match, fail here.
                    exit(_e('This download is no longer valid, Please contact the site administrator for more information.', 'wpsc'));
                }
            }
        }
        if ($download_data != null) {
            if ($download_data['fileid'] > 0) {
                $file_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $download_data['fileid'] . "' LIMIT 1", ARRAY_A);
            } else {
                $old_file_data = $wpdb->get_row("SELECT `product_id` FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $download_data['fileid'] . "' LIMIT 1", ARRAY_A);
                $file_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $download_data['fileid'] . "' LIMIT 1", ARRAY_A);
            }
            if ((int) $download_data['downloads'] >= 1) {
                $download_count = (int) $download_data['downloads'] - 1;
            } else {
                $download_count = 0;
            }
            $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `downloads` = '{$download_count}' WHERE `id` = '{$download_data['id']}' LIMIT 1");
            $cart_contents = $wpdb->get_results('SELECT `' . WPSC_TABLE_CART_CONTENTS . '`.*,`' . WPSC_TABLE_PRODUCT_LIST . '`.`file` FROM `' . WPSC_TABLE_CART_CONTENTS . '` LEFT JOIN `' . WPSC_TABLE_PRODUCT_LIST . '` ON `' . WPSC_TABLE_CART_CONTENTS . '`.`prodid`= `' . WPSC_TABLE_PRODUCT_LIST . '`.`id` WHERE `purchaseid` =' . $download_data['purchid'], ARRAY_A);
            $dl = 0;
            foreach ($cart_contents as $cart_content) {
                if ($cart_content['file'] == 1) {
                    $dl++;
                }
            }
            if (count($cart_contents) == $dl) {
                //  	exit('called');
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '4' WHERE `id` = '" . $download_data['purchid'] . "' LIMIT 1");
            }
            //exit('<pre>'.print_r($cart_contents,true).'</pre>');
            if (is_file(WPSC_FILE_DIR . $file_data['idhash'])) {
                header('Content-Type: ' . $file_data['mimetype']);
                header('Content-Length: ' . filesize(WPSC_FILE_DIR . $file_data['idhash']));
                header('Content-Transfer-Encoding: binary');
                header('Content-Disposition: attachment; filename="' . stripslashes($file_data['filename']) . '"');
                if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != '') {
                    /*
                    There is a bug in how IE handles downloads from servers using HTTPS, this is part of the fix, you may also need:
                      session_cache_limiter('public');
                      session_cache_expire(30);
                    At the start of your index.php file or before the session is started
                    */
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header("Cache-Control: public");
                } else {
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                }
                $filename = WPSC_FILE_DIR . $file_data['idhash'];
                // destroy the session to allow the file to be downloaded on some buggy browsers and webservers
                session_destroy();
                wpsc_readfile_chunked($filename);
                exit;
            }
        } else {
            exit(_e('This download is no longer valid, Please contact the site administrator for more information.', 'wpsc'));
        }
    } else {
        if ($_GET['admin_preview'] == "true" && is_numeric($_GET['product_id']) && current_user_can('edit_plugins')) {
            $product_id = $_GET['product_id'];
            $product_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A);
            if (is_numeric($product_data[0]['file']) && $product_data[0]['file'] > 0) {
                $file_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $product_data[0]['file'] . "' LIMIT 1", ARRAY_A);
                $file_data = $file_data[0];
                if (is_file(WPSC_FILE_DIR . $file_data['idhash'])) {
                    header('Content-Type: ' . $file_data['mimetype']);
                    header('Content-Length: ' . filesize(WPSC_FILE_DIR . $file_data['idhash']));
                    header('Content-Transfer-Encoding: binary');
                    if ($_GET['preview_track'] != 'true') {
                        header('Content-Disposition: attachment; filename="' . $file_data['filename'] . '"');
                    } else {
                        header('Content-Disposition: inline; filename="' . $file_data['filename'] . '"');
                    }
                    if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != '') {
                        header("Pragma: public");
                        header("Expires: 0");
                        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                        header("Cache-Control: public");
                    } else {
                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    }
                    $filename = WPSC_FILE_DIR . $file_data['idhash'];
                    session_destroy();
                    wpsc_readfile_chunked($filename);
                    exit;
                }
            }
        }
    }
}
コード例 #3
0
function _wpsc_force_download_file($file_id)
{
    do_action('wpsc_alter_download_action', $file_id);
    $file_data = get_post($file_id);
    if (!$file_data) {
        wp_die(__('Invalid file ID.', 'wpsc'));
    }
    $file_name = basename($file_data->post_title);
    $file_path = WPSC_FILE_DIR . $file_name;
    if (is_file($file_path)) {
        if (!ini_get('safe_mode')) {
            set_time_limit(0);
        }
        header('Content-Type: ' . $file_data->post_mime_type);
        header('Content-Length: ' . filesize($file_path));
        header('Content-Transfer-Encoding: binary');
        header('Content-Disposition: attachment; filename="' . stripslashes($file_name) . '"');
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != '') {
            /*
             There is a bug in how IE handles downloads from servers using HTTPS, this is part of the fix, you may also need:
             session_cache_limiter('public');
             session_cache_expire(30);
             At the start of your index.php file or before the session is started
            */
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: public");
        } else {
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        }
        header("Pragma: public");
        header("Expires: 0");
        // destroy the session to allow the file to be downloaded on some buggy browsers and webservers
        session_destroy();
        wpsc_readfile_chunked($file_path);
        exit;
    } else {
        wp_die(__('Sorry something has gone wrong with your download!', 'wpsc'));
    }
}