Ejemplo n.º 1
0
/**
 * dlm_create_log function.
 *
 * @access public
 *
 * @deprecated 1.6.0
 *
 * @param string $type (default: '')
 * @param string $status (default: '')
 * @param string $message (default: '')
 * @param mixed $download
 * @param mixed $version
 *
 * @return void
 */
function dlm_create_log($type = '', $status = '', $message = '', $download, $version)
{
    // Deprecated notice
    _deprecated_function(__FUNCTION__, '1.6.0', 'DLM_Logging->create_log()');
    // Logging object
    $logging = new DLM_Logging();
    // Check if logging is enabled
    if ($logging->is_logging_enabled()) {
        // Create log
        $logging->create_log($type, $status, $message, $download, $version);
    }
}
 /**
  * trigger function.
  *
  * @access private
  *
  * @param mixed $download
  *
  * @return void
  */
 private function trigger($download)
 {
     $version = $download->get_file_version();
     $file_paths = $version->mirrors;
     // Check if we got files in this version
     if (empty($file_paths)) {
         wp_die(__('No file paths defined.', 'download-monitor') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'download-monitor') . '</a>', __('Download Error', 'download-monitor'));
     }
     // Get a random file (mirror)
     $file_path = $file_paths[array_rand($file_paths)];
     // Check if we actually got a path
     if (!$file_path) {
         wp_die(__('No file paths defined.', 'download-monitor') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'download-monitor') . '</a>', __('Download Error', 'download-monitor'));
     }
     // Check Access
     if (!apply_filters('dlm_can_download', true, $download, $version)) {
         // Check if we need to redirect if visitor don't have access to file
         if ($redirect = apply_filters('dlm_access_denied_redirect', false)) {
             wp_redirect($redirect);
             exit;
         } else {
             // get 'no access' page id
             $no_access_page_id = get_option('dlm_no_access_page', 0);
             // check if a no access page is set
             if ($no_access_page_id > 0) {
                 // get permalink of no access page
                 $no_access_permalink = get_permalink($no_access_page_id);
                 // check if we can find a permalink
                 if (false !== $no_access_permalink) {
                     // append download id to no access URL
                     $no_access_permalink = untrailingslashit($no_access_permalink) . '/download-id/' . $download->id . '/';
                     // redirect to no access page
                     wp_redirect($no_access_permalink);
                     exit;
                     // out
                 }
             }
             // if we get to this point, we have no proper 'no access' page. Fallback to default wp_die
             wp_die(wp_kses_post(get_option('dlm_no_access_error', '')), __('Download Error', 'download-monitor'), array('response' => 200));
         }
         exit;
     }
     // check if user downloaded this version in the past minute
     if (false == DLM_Cookie_Manager::exists($download)) {
         // DLM Logging object
         $logger = new DLM_Logging();
         // bool if we need to increment download count
         $increment_download_count = true;
         // check if unique ips option is enabled and if so, if visitor already downloaded this file version
         if ($logger->is_logging_enabled() && $logger->is_count_unique_ips_only() && true === $logger->has_ip_downloaded_version($version)) {
             $increment_download_count = false;
         }
         // check if we need to increment the download count
         if (true === $increment_download_count) {
             // Increase download count
             $version->increase_download_count();
         }
         // Trigger Download Action
         do_action('dlm_downloading', $download, $version, $file_path);
         // Set cookie to prevent double logging
         DLM_Cookie_Manager::set_cookie($download);
     }
     // Redirect to the file...
     if ($download->redirect_only() || apply_filters('dlm_do_not_force', false, $download, $version)) {
         $this->log('download', 'redirected', __('Redirected to file', 'download-monitor'), $download, $version);
         // Ensure we have a valid URL, not a file path
         $file_path = str_replace(ABSPATH, site_url('/', 'http'), $file_path);
         header('Location: ' . $file_path);
         exit;
     }
     // File Manager
     $file_manager = new DLM_File_Manager();
     // Parse file path
     list($file_path, $remote_file) = $file_manager->parse_file_path($file_path);
     $this->download_headers($file_path, $download, $version);
     if (get_option('dlm_xsendfile_enabled')) {
         if (function_exists('apache_get_modules') && in_array('mod_xsendfile', apache_get_modules())) {
             $this->log('download', 'redirected', __('Redirected to file', 'download-monitor'), $download, $version);
             header("X-Sendfile: {$file_path}");
             exit;
         } elseif (stristr(getenv('SERVER_SOFTWARE'), 'lighttpd')) {
             $this->log('download', 'redirected', __('Redirected to file', 'download-monitor'), $download, $version);
             header("X-LIGHTTPD-send-file: {$file_path}");
             exit;
         } elseif (stristr(getenv('SERVER_SOFTWARE'), 'nginx') || stristr(getenv('SERVER_SOFTWARE'), 'cherokee')) {
             $this->log('download', 'redirected', __('Redirected to file', 'download-monitor'), $download, $version);
             $file_path = str_ireplace($_SERVER['DOCUMENT_ROOT'], '', $file_path);
             header("X-Accel-Redirect: /{$file_path}");
             exit;
         }
     }
     // multipart-download and download resuming support - http://www.phpgang.com/force-to-download-a-file-in-php_112.html
     if (isset($_SERVER['HTTP_RANGE']) && $version->filesize) {
         list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2);
         list($range) = explode(",", $range, 2);
         list($range, $range_end) = explode("-", $range);
         $range = intval($range);
         if (!$range_end) {
             $range_end = $version->filesize - 1;
         } else {
             $range_end = intval($range_end);
         }
         $new_length = $range_end - $range;
         header("HTTP/1.1 206 Partial Content");
         header("Content-Length: {$new_length}");
         header("Content-Range: bytes {$range}-{$range_end}/{$version->filesize}");
     } else {
         $range = false;
     }
     if ($this->readfile_chunked($file_path, $range)) {
         // Complete!
         $this->log('download', 'completed', '', $download, $version);
     } elseif ($remote_file) {
         // Redirect - we can't track if this completes or not
         $this->log('download', 'redirected', __('Redirected to remote file.', 'download-monitor'), $download, $version);
         header('Location: ' . $file_path);
     } else {
         $this->log('download', 'failed', __('File not found.', 'download-monitor'), $download, $version);
         wp_die(__('File not found.', 'download-monitor') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'download-monitor') . '</a>', __('Download Error', 'download-monitor'), array('response' => 404));
     }
     exit;
 }
 /**
  * Create a log if logging is enabled
  *
  * @param string $type
  * @param string $status
  * @param string $message
  * @param DLM_Download $download
  * @param DLM_Download_Version $version
  */
 private function log($type = '', $status = '', $message = '', $download, $version)
 {
     // Logging object
     $logging = new DLM_Logging();
     // Check if logging is enabled and if unique ips is enabled
     if ($logging->is_logging_enabled()) {
         // set create_log to true
         $create_log = true;
         // check if requester downloaded this version before
         if ('1' == get_option('dlm_count_unique_ips', '0') && true === $this->has_ip_downloaded_version($version)) {
             $create_log = false;
         }
         // check if we need to create the log
         if ($create_log) {
             // Create log
             $logging->create_log($type, $status, $message, $download, $version);
         }
     }
 }
 /**
  * admin_menu function.
  *
  * @access public
  * @return void
  */
 public function admin_menu()
 {
     // Logging object
     $logging = new DLM_Logging();
     // Logs page
     if ($logging->is_logging_enabled()) {
         add_submenu_page('edit.php?post_type=dlm_download', __('Logs', 'download-monitor'), __('Logs', 'download-monitor'), 'dlm_manage_logs', 'download-monitor-logs', array($this, 'log_viewer'));
     }
     // Settings page
     add_submenu_page('edit.php?post_type=dlm_download', __('Settings', 'download-monitor'), __('Settings', 'download-monitor'), 'manage_options', 'download-monitor-settings', array($this, 'settings_page'));
 }
 /**
  * Process bulk actions
  */
 public function process_bulk_action()
 {
     if ('delete' === $this->current_action()) {
         // check nonce
         if (empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'bulk-' . $this->_args['plural'])) {
             wp_die('process_bulk_action() nonce check failed');
         }
         // check capability
         if (!current_user_can('dlm_manage_logs')) {
             wp_die("You're not allowed to delete logs!");
         }
         // logging object
         $logging = new DLM_Logging();
         // check
         if (count($_POST['log']) > 0) {
             // delete the posted logs
             foreach ($_POST['log'] as $log_id) {
                 $logging->delete_log(absint($log_id));
             }
             // display delete message
             $this->display_delete_message = true;
         }
     }
 }