Esempio n. 1
0
 function Download()
 {
     global $wpdb, $current_user, $user_ID;
     @error_reporting(0);
     wpfb_loadclass('Category', 'Download');
     $downloader_ip = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
     get_currentuserinfo();
     $logged_in = !empty($user_ID);
     $user_role = $logged_in ? reset($current_user->roles) : null;
     // get user's highest role (like in user-eidt.php)
     $is_admin = current_user_can('manage_options');
     // check user level
     if (!$this->CurUserCanAccess()) {
         $this->DownloadDenied('inaccessible_msg');
     }
     // check offline
     if ($this->file_offline && !$is_admin) {
         wp_die(WPFB_Core::$settings->file_offline_msg);
     }
     // check referrer
     if ($this->file_direct_linking != 1) {
         // if referer check failed, redirect to the file post
         if (!WPFB_Download::RefererCheck()) {
             $url = WPFB_Core::GetPostUrl($this->file_post_id);
             if (empty($url)) {
                 $url = home_url();
             }
             wp_redirect($url);
             exit;
         }
     }
     // check traffic
     if ($this->IsLocal() && !WPFB_Download::CheckTraffic($this->file_size)) {
         header('HTTP/1.x 503 Service Unavailable');
         wp_die(WPFB_Core::$settings->traffic_exceeded_msg);
     }
     // check daily user limit
     if (!$is_admin && WPFB_Core::$settings->daily_user_limits) {
         if (!$logged_in) {
             $this->DownloadDenied('inaccessible_msg');
         }
         $today = intval(date('z'));
         $usr_dls_today = intval(get_user_option(WPFB_OPT_NAME . '_dls_today'));
         $usr_last_dl_day = intval(date('z', intval(get_user_option(WPFB_OPT_NAME . '_last_dl'))));
         if ($today != $usr_last_dl_day) {
             $usr_dls_today = 0;
         }
         // check for limit
         $dl_limit = intval(WPFB_Core::GetOpt('daily_limit_' . $user_role));
         if ($dl_limit > 0 && $usr_dls_today >= $dl_limit) {
             $this->DownloadDenied(sprintf(WPFB_Core::$settings->daily_limit_exceeded_msg, $dl_limit));
         }
         $usr_dls_today++;
         update_user_option($user_ID, WPFB_OPT_NAME . '_dls_today', $usr_dls_today);
         update_user_option($user_ID, WPFB_OPT_NAME . '_last_dl', time());
     }
     // count download
     if (!$is_admin || !WPFB_Core::$settings->ignore_admin_dls) {
         $last_dl_time = mysql2date('U', $this->file_last_dl_time, false);
         if (empty($this->file_last_dl_ip) || $this->file_last_dl_ip != $downloader_ip || time() - $last_dl_time > 86400) {
             $wpdb->query("UPDATE " . $wpdb->wpfilebase_files . " SET file_hits = file_hits + 1, file_last_dl_ip = '" . $downloader_ip . "', file_last_dl_time = '" . current_time('mysql') . "' WHERE file_id = " . (int) $this->file_id);
         }
     }
     // external hooks
     do_action('wpfilebase_file_downloaded', $this->file_id);
     $url = $this->GetRemoteUri();
     $is_local_remote = !empty($url) && parse_url($url, PHP_URL_SCHEME) === 'file' && is_readable($url);
     // download or redirect
     if ($this->IsLocal() || $is_local_remote) {
         $bw = 'bitrate_' . ($logged_in ? 'registered' : 'unregistered');
         WPFB_Download::SendFile($is_local_remote ? $url : $this->GetLocalPath(), array('bandwidth' => WPFB_Core::$settings->{$bw}, 'etag' => $this->file_hash, 'md5_hash' => WPFB_Core::$settings->fake_md5 ? null : $this->file_hash, 'force_download' => WPFB_Core::$settings->force_download || $this->file_force_download, 'cache_max_age' => 10, 'filename' => empty($this->file_name_original) ? $this->file_name : $this->file_name_original));
     } else {
         //header('HTTP/1.1 301 Moved Permanently');
         header('Cache-Control: no-store, no-cache, must-revalidate');
         header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');
         header('Location: ' . $url);
     }
     exit;
 }
Esempio n. 2
0
<?php

define('FASTLOAD', true);
require_once 'wpfb-load.php';
wpfb_loadclass('Core', 'File', 'Category', 'Download');
$item = null;
if (isset($_GET['fid'])) {
    $fid = intval($_GET['fid']);
    if ($fid == 0) {
        $img_path = ABSPATH . WPINC . '/images/';
        if (file_exists($img = $img_path . 'crystal/default.png') || file_exists($img = $img_path . 'default.png') || file_exists($img = $img_path . 'blank.gif')) {
            WPFB_Download::SendFile($img, array('cache_max_age' => -1));
        }
        //was 3600 * 12
        exit;
    }
    $item = WPFB_File::GetFile($fid);
} elseif (isset($_GET['cid'])) {
    $item = WPFB_Category::GetCat(intval($_GET['cid']));
}
if ($item == null || !$item->CurUserCanAccess(true)) {
    exit;
}
// if no thumbnail, redirect
if (empty($item->file_thumbnail) && empty($item->cat_icon)) {
    header('Location: ' . $item->GetIconUrl());
    exit;
}
// send thumbnail
WPFB_Download::SendFile($item->GetThumbPath(), array('cache_max_age' => -1));
// was 3600 * 12