diff --git a/_mediavault.php b/_mediavault.php
index 771ab55..2b425be 100644
--- a/_mediavault.php
+++ b/_mediavault.php
@@ -1,13 +1,13 @@
array(
- 'description' => __( 'Admin users only', 'media-vault' ),
- 'select' => __( 'Admin users', 'media-vault' ),
- 'logged_in' => true,
- 'run_in_admin' => true,
- 'cb' => 'mgjp_mv_check_admin_permission'
+ 'admin' => array(
+ 'description' => __('Admin users only', 'media-vault'),
+ 'select' => __('Admin users', 'media-vault'),
+ 'logged_in' => true,
+ 'run_in_admin' => true,
+ 'cb' => 'mgjp_mv_check_admin_permission',
),
- 'author' => array(
- 'description' => __( 'The file\'s author', 'media-vault' ),
- 'select' => __( 'The file\'s author', 'media-vault' ),
- 'logged_in' => true,
- 'run_in_admin' => true,
- 'cb' => 'mgjp_mv_check_author_permission'
+ 'author' => array(
+ 'description' => __('The file\'s author', 'media-vault'),
+ 'select' => __('The file\'s author', 'media-vault'),
+ 'logged_in' => true,
+ 'run_in_admin' => true,
+ 'cb' => 'mgjp_mv_check_author_permission',
),
- 'logged-in' => array(
- 'description' => __( 'All logged-in users', 'media-vault' ),
- 'select' => __( 'Logged-in users', 'media-vault' ),
- 'logged_in' => true,
- 'run_in_admin' => false,
- 'cb' => false
+ 'logged-in' => array(
+ 'description' => __('All logged-in users', 'media-vault'),
+ 'select' => __('Logged-in users', 'media-vault'),
+ 'logged_in' => true,
+ 'run_in_admin' => false,
+ 'cb' => false,
+ ),
+ 'all' => array(
+ 'description' => __('Anyone', 'media-vault'),
+ 'select' => __('Anyone', 'media-vault'),
+ 'logged_in' => false,
+ 'run_in_admin' => false,
+ 'cb' => false,
),
- 'all' => array(
- 'description' => __( 'Anyone', 'media-vault' ),
- 'select' => __( 'Anyone', 'media-vault' ),
- 'logged_in' => false,
- 'run_in_admin' => false,
- 'cb' => false
- )
);
-
-register_activation_hook( __FILE__, 'mgjp_mv_activate' );
-register_deactivation_hook( __FILE__, 'mgjp_mv_deactivate' );
-
-add_action( 'plugins_loaded', 'mgjp_mv_textdomain' );
-
-add_action( 'init', 'mgjp_mv_check_version' );
-
-add_action( 'load-plugins.php', 'mgjp_mv_on_deactivation_request' );
-
-if ( get_site_option( 'mgjp_mv_enabled' ) ) {
-
- add_action( 'init', 'mgjp_mv_handle_file_request', 0 );
- add_action( 'init', 'mgjp_mv_register_shortcodes' );
-
- add_action( 'wp_enqueue_media', 'mgjp_mv_attachment_edit_fields_styles_and_scripts' );
-
- add_filter( 'mod_rewrite_rules', 'mgjp_mv_add_plugin_rewrite_rules' );
-
- add_filter( 'upload_dir', 'mgjp_mv_change_upload_directory', 999 );
-
- add_filter( 'user_has_cap', 'mgjp_mv_edit_capabilities', 999, 3 );
-
- add_filter( 'image_downsize', 'mgjp_mv_replace_protected_image', 999, 3 );
-
- if ( is_admin() ) {
-
- add_action( 'admin_init', 'mgjp_mv_ajax_actions_include', 0 );
- add_action( 'admin_init', 'mgjp_mv_media_vault_options_include' );
- add_action( 'admin_init', 'mgjp_mv_attachment_metabox_include' );
-
- add_action( 'load-media-new.php', 'mgjp_mv_media_new_options_include' );
- add_action( 'load-upload.php', 'mgjp_mv_media_library_options_include' );
-
- add_filter( 'admin_body_class', 'mgjp_add_mp6_admin_body_class' );
-
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'mgjp_mv_settings_link' );
-
- }
-
-} else {
-
- include( plugin_dir_path( __FILE__ ) . 'mv-extra-activation-steps.php' );
-
+register_activation_hook(__FILE__, 'mgjp_mv_activate');
+register_deactivation_hook(__FILE__, 'mgjp_mv_deactivate');
+
+add_action('plugins_loaded', 'mgjp_mv_textdomain');
+
+add_action('init', 'mgjp_mv_check_version');
+
+add_action('load-plugins.php', 'mgjp_mv_on_deactivation_request');
+
+if (get_site_option('mgjp_mv_enabled'))
+{
+
+ add_action('init', 'mgjp_mv_handle_file_request', 0);
+ add_action('init', 'mgjp_mv_register_shortcodes');
+
+ add_action('wp_enqueue_media', 'mgjp_mv_attachment_edit_fields_styles_and_scripts');
+
+ add_filter('mod_rewrite_rules', 'mgjp_mv_add_plugin_rewrite_rules');
+
+ add_filter('upload_dir', 'mgjp_mv_change_upload_directory', 999);
+
+ add_filter('user_has_cap', 'mgjp_mv_edit_capabilities', 999, 3);
+
+ add_filter('image_downsize', 'mgjp_mv_replace_protected_image', 999, 3);
+
+ if (is_admin())
+ {
+
+ add_action('admin_init', 'mgjp_mv_ajax_actions_include', 0);
+ add_action('admin_init', 'mgjp_mv_media_vault_options_include');
+ add_action('admin_init', 'mgjp_mv_attachment_metabox_include');
+
+ add_action('load-media-new.php', 'mgjp_mv_media_new_options_include');
+ add_action('load-upload.php', 'mgjp_mv_media_library_options_include');
+
+ add_filter('admin_body_class', 'mgjp_add_mp6_admin_body_class');
+
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'mgjp_mv_settings_link');
+
+ }
+
+}
+else
+{
+
+ include(plugin_dir_path(__FILE__) . 'mv-extra-activation-steps.php');
+
}
-if ( get_site_option( 'mgjp_mv_deactivation' ) )
- include( plugin_dir_path( __FILE__ ) . 'mv-extra-deactivation-steps.php' );
-
+if (get_site_option('mgjp_mv_deactivation'))
+{
+ include(plugin_dir_path(__FILE__) . 'mv-extra-deactivation-steps.php');
+}
//-----------------------------------------------------------------------//
// MEDIA VAULT - PERMISSION CHECKING FUNCTIONS
//-----------------------------------------------------------------------//
-
/**
* The 'admin' permission checking callback.
*
* @since 0.4
*/
-function mgjp_mv_check_admin_permission() {
- if ( ! current_user_can( 'manage_options' ) )
- return new WP_Error( 'not_admin', __( 'You do not have sufficient permissions to view this file.', 'media-vault' ) );
-
- return true;
+function mgjp_mv_check_admin_permission()
+{
+ if (!current_user_can('manage_options'))
+ {
+ return new WP_Error('not_admin', __('You do not have sufficient permissions to view this file.', 'media-vault'));
+ }
+
+ return true;
}
/**
@@ -144,27 +147,31 @@ function mgjp_mv_check_admin_permission() {
*
* @since 0.4
*/
-function mgjp_mv_check_author_permission( $attachment_id ) {
-
- if ( current_user_can( 'manage_options' ) )
+function mgjp_mv_check_author_permission($attachment_id)
+{
+
+ if (current_user_can('manage_options'))
+ {
+ return true;
+ }
+
+ if (!isset($attachment_id) || empty($attachment_id))
+ {
+ return new WP_Error('no_id', __('There was an error determining this attachment\'s author. Please contact the website administrator.', 'media-vault'));
+ }
+
+ if (get_current_user_id() != get_post_field('post_author', $attachment_id, 'raw'))
+ {
+ return new WP_Error('not_author', __('You do not have sufficient permissions to view this file.', 'media-vault'));
+ }
+
return true;
-
- if ( ! isset( $attachment_id ) || empty( $attachment_id ) )
- return new WP_Error( 'no_id', __( 'There was an error determining this attachment\'s author. Please contact the website administrator.', 'media-vault' ) );
-
- if ( get_current_user_id() != get_post_field( 'post_author', $attachment_id, 'raw' ) )
- return new WP_Error( 'not_author', __( 'You do not have sufficient permissions to view this file.', 'media-vault' ) );
-
- return true;
}
-
-
//-----------------------------------------------------------------------//
// MEDIA VAULT - MAIN HOOKED FUNCTIONS
//-----------------------------------------------------------------------//
-
/**
* On plugin activation
*
@@ -172,51 +179,56 @@ function mgjp_mv_check_author_permission( $attachment_id ) {
*
* @uses _mgjp_mv_activate_local()
*/
-function mgjp_mv_activate( $network_activating ) {
-
- global $is_apache;
-
- if ( $is_apache
- && ! is_multisite()
- && get_option( 'permalink_structure' )
- && got_mod_rewrite()
- && is_writable( get_home_path() . '.htaccess' ) ) {
-
- // register plugin enabled option
- update_site_option( 'mgjp_mv_enabled', true );
-
- // Flush rewrite rules to add Media Vault rewrite rules to the
- // site's .htaccess file on plugin activation
- add_filter( 'mod_rewrite_rules', 'mgjp_mv_add_plugin_rewrite_rules' );
- flush_rewrite_rules();
- }
-
- // register Media Vault's other network-wide options
- add_site_option( 'mgjp_mv_version', MGJP_MV_VERSION, '', 'yes' );
- delete_site_option( 'mgjp_mv_deactivation' );
-
- if ( ! is_multisite() ) {
-
- // run the activation function for the single site
- _mgjp_mv_activate_local();
-
- } else if ( ! wp_is_large_network() ) {
- global $wpdb;
-
- $blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `$wpdb->blogs`" );
-
- // run the activation function for each site in the network
- foreach ( $blog_ids as $blog_id ) {
-
- switch_to_blog( $blog_id );
- _mgjp_mv_activate_local( $blog_id );
- restore_current_blog();
-
+function mgjp_mv_activate($network_activating)
+{
+
+ global $is_apache;
+
+ if ($is_apache
+ && !is_multisite()
+ && get_option('permalink_structure')
+ && got_mod_rewrite()
+ && is_writable(get_home_path() . '.htaccess'))
+ {
+
+ // register plugin enabled option
+ update_site_option('mgjp_mv_enabled', true);
+
+ // Flush rewrite rules to add Media Vault rewrite rules to the
+ // site's .htaccess file on plugin activation
+ add_filter('mod_rewrite_rules', 'mgjp_mv_add_plugin_rewrite_rules');
+ flush_rewrite_rules();
+ }
+
+ // register Media Vault's other network-wide options
+ add_site_option('mgjp_mv_version', MGJP_MV_VERSION, '', 'yes');
+ delete_site_option('mgjp_mv_deactivation');
+
+ if (!is_multisite())
+ {
+
+ // run the activation function for the single site
+ _mgjp_mv_activate_local();
+
+ }
+ else if (!wp_is_large_network())
+ {
+ global $wpdb;
+
+ $blog_ids = $wpdb->get_col("SELECT `blog_id` FROM `$wpdb->blogs`");
+
+ // run the activation function for each site in the network
+ foreach ($blog_ids as $blog_id)
+ {
+
+ switch_to_blog($blog_id);
+ _mgjp_mv_activate_local($blog_id);
+ restore_current_blog();
+
+ }
}
- }
}
-
/**
* On plugin deactivation
*
@@ -224,50 +236,54 @@ function mgjp_mv_activate( $network_activating ) {
*
* @uses mgjp_mv_check_rewrite_rules()
*/
-function mgjp_mv_deactivate( $network_deactivating ) {
-
- delete_site_option( 'mgjp_mv_deactivation' );
- delete_site_option( 'mgjp_mv_enabled' );
-
- // Flush rewrite rules to remove Media Vault rewrite rules from the
- // site's .htaccess file on plugin deactivation
- remove_filter( 'mod_rewrite_rules', 'mgjp_mv_add_plugin_rewrite_rules' );
- flush_rewrite_rules();
-
- if ( ! is_multisite() ) {
-
- // run the deactivation function for the single site
- _mgjp_mv_deactivate_local();
-
- } else if ( ! wp_is_large_network() ) {
- global $wpdb;
-
- $blog_ids = $wpdb->get_col( "SELECT `blog_id` FROM `$wpdb->blogs`" );
-
- // run the deactivation function for each site in the network
- foreach ( $blog_ids as $blog_id ) {
-
- switch_to_blog( $blog_id );
- _mgjp_mv_deactivate_local( $blog_id );
- restore_current_blog();
-
+function mgjp_mv_deactivate($network_deactivating)
+{
+
+ delete_site_option('mgjp_mv_deactivation');
+ delete_site_option('mgjp_mv_enabled');
+
+ // Flush rewrite rules to remove Media Vault rewrite rules from the
+ // site's .htaccess file on plugin deactivation
+ remove_filter('mod_rewrite_rules', 'mgjp_mv_add_plugin_rewrite_rules');
+ flush_rewrite_rules();
+
+ if (!is_multisite())
+ {
+
+ // run the deactivation function for the single site
+ _mgjp_mv_deactivate_local();
+
+ }
+ else if (!wp_is_large_network())
+ {
+ global $wpdb;
+
+ $blog_ids = $wpdb->get_col("SELECT `blog_id` FROM `$wpdb->blogs`");
+
+ // run the deactivation function for each site in the network
+ foreach ($blog_ids as $blog_id)
+ {
+
+ switch_to_blog($blog_id);
+ _mgjp_mv_deactivate_local($blog_id);
+ restore_current_blog();
+
+ }
}
- }
}
-
/**
* Load the plugin textdomain.
*
* @since 0.1
*/
-function mgjp_mv_textdomain() {
-
- load_plugin_textdomain( 'media-vault', false, plugin_dir_path( __FILE__ ) . 'languages/' );
-
+function mgjp_mv_textdomain()
+{
+
+ load_plugin_textdomain('media-vault', false, plugin_dir_path(__FILE__) . 'languages/');
+
}
-
/**
* Plugin update handling. Checks current version against
* a version number stored in the database and performs any
@@ -277,26 +293,32 @@ function mgjp_mv_textdomain() {
*
* @uses MGJP_MV_Update
*/
-function mgjp_mv_check_version() {
-
- $option_key = 'mgjp_mv_version';
-
- $version_db = get_site_option( $option_key, '0' );
-
- if ( version_compare( $version_db, MGJP_MV_VERSION, 'eq' ) )
- return;
-
- if ( version_compare( $version_db, MGJP_MV_VERSION, 'gt' ) )
- return update_site_option( $option_key, MGJP_MV_VERSION );
-
- include( plugin_dir_path( __FILE__ ) . 'mv-class-update.php' );
-
- if ( class_exists( 'MGJP_MV_Update' ) )
- new MGJP_MV_Update( $version_db, MGJP_MV_VERSION, $option_key );
-
+function mgjp_mv_check_version()
+{
+
+ $option_key = 'mgjp_mv_version';
+
+ $version_db = get_site_option($option_key, '0');
+
+ if (version_compare($version_db, MGJP_MV_VERSION, 'eq'))
+ {
+ return;
+ }
+
+ if (version_compare($version_db, MGJP_MV_VERSION, 'gt'))
+ {
+ return update_site_option($option_key, MGJP_MV_VERSION);
+ }
+
+ include(plugin_dir_path(__FILE__) . 'mv-class-update.php');
+
+ if (class_exists('MGJP_MV_Update'))
+ {
+ new MGJP_MV_Update($version_db, MGJP_MV_VERSION, $option_key);
+ }
+
}
-
/**
* Remove Media Vault from the plugins.php deactivation
* actions if Media Vault needs extra steps in order
@@ -307,52 +329,65 @@ function mgjp_mv_check_version() {
* @uses mgjp_mv_get_dirfile()
* @uses mgjp_mv_is_deactivation_allowed()
*/
-function mgjp_mv_on_deactivation_request() {
-
- if ( in_array( get_site_option( 'mgjp_mv_deactivation' ), array( 'allowed', 'temp' ) ) )
- return;
-
- $action = isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ?
- $_REQUEST['action'] :
- ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ?
- $_REQUEST['action2'] :
- false
- );
-
- if ( ! in_array( $action, array( 'deactivate', 'deactivate-selected' ) ) )
- return;
-
- switch ( $action ) {
- case 'deactivate':
- if ( ! isset( $_REQUEST['plugin'] ) || mgjp_mv_get_dirfile() != $_REQUEST['plugin'] )
- return;
-
- if ( mgjp_mv_is_deactivation_allowed() )
- return;
-
- update_site_option( 'mgjp_mv_deactivation', 'disallowed' );
-
- $location = remove_query_arg( array( 'action', 'plugin', '_wpnonce' ), $_SERVER['REQUEST_URI'] );
- wp_redirect( $location );
- exit;
- break;
- case 'deactivate-selected':
- $plugin_dirfile = mgjp_mv_get_dirfile();
-
- if ( ! isset( $_POST['checked'] ) || ! in_array( $plugin_dirfile, (array) $_POST['checked'] ) )
+function mgjp_mv_on_deactivation_request()
+{
+
+ if (in_array(get_site_option('mgjp_mv_deactivation'), array('allowed', 'temp')))
+ {
return;
-
- if ( mgjp_mv_is_deactivation_allowed() )
+ }
+
+ $action = isset($_REQUEST['action']) && -1 != $_REQUEST['action'] ?
+ $_REQUEST['action'] :
+ (isset($_REQUEST['action2']) && -1 != $_REQUEST['action2'] ?
+ $_REQUEST['action2'] :
+ false
+ );
+
+ if (!in_array($action, array('deactivate', 'deactivate-selected')))
+ {
return;
-
- update_site_option( 'mgjp_mv_deactivation', 'disallowed' );
-
- $_POST['checked'] = array_diff( $_POST['checked'], array( $plugin_dirfile ) );
- break;
- }
+ }
+
+ switch ($action)
+ {
+ case 'deactivate':
+ if (!isset($_REQUEST['plugin']) || mgjp_mv_get_dirfile() != $_REQUEST['plugin'])
+ {
+ return;
+ }
+
+ if (mgjp_mv_is_deactivation_allowed())
+ {
+ return;
+ }
+
+ update_site_option('mgjp_mv_deactivation', 'disallowed');
+
+ $location = remove_query_arg(array('action', 'plugin', '_wpnonce'), $_SERVER['REQUEST_URI']);
+ wp_redirect($location);
+ exit;
+ break;
+ case 'deactivate-selected':
+ $plugin_dirfile = mgjp_mv_get_dirfile();
+
+ if (!isset($_POST['checked']) || !in_array($plugin_dirfile, (array)$_POST['checked']))
+ {
+ return;
+ }
+
+ if (mgjp_mv_is_deactivation_allowed())
+ {
+ return;
+ }
+
+ update_site_option('mgjp_mv_deactivation', 'disallowed');
+
+ $_POST['checked'] = array_diff($_POST['checked'], array($plugin_dirfile));
+ break;
+ }
}
-
/**
* Trigger protected media uploads file handling function
* if 'file' GET parameter is set in URL on wp init
@@ -361,48 +396,54 @@ function mgjp_mv_on_deactivation_request() {
*
* @uses mgjp_mv_get_file()
*/
-function mgjp_mv_handle_file_request() {
-
- if ( isset( $_GET['mgjp_mv_file'] ) && ! empty( $_GET['mgjp_mv_file'] ) ) {
-
- // used by @func mgjp_mv_check_rewrite_rules to verify rewrite rules are
- // set and working as intended
- if ( isset( $_GET['mgjp_mv_rewrite_test'] ) && $_GET['mgjp_mv_rewrite_test'] )
- die( 'pass' );
-
- require( plugin_dir_path( __FILE__ ) . 'mv-file-handler.php' );
-
- // Check if force download flag is set
- $force_download = isset( $_REQUEST['mgjp_mv_download'] ) ?
- $_REQUEST['mgjp_mv_download'] :
- '';
-
- if ( function_exists( 'mgjp_mv_get_file' ) ) {
- mgjp_mv_get_file( $_GET['mgjp_mv_file'], $force_download );
- exit; // This exit is important as all we want to do when a
+function mgjp_mv_handle_file_request()
+{
+
+ if (isset($_GET['mgjp_mv_file']) && !empty($_GET['mgjp_mv_file']))
+ {
+
+ // used by @func mgjp_mv_check_rewrite_rules to verify rewrite rules are
+ // set and working as intended
+ if (isset($_GET['mgjp_mv_rewrite_test']) && $_GET['mgjp_mv_rewrite_test'])
+ {
+ die('pass');
+ }
+
+ require(plugin_dir_path(__FILE__) . 'mv-file-handler.php');
+
+ // Check if force download flag is set
+ $force_download = isset($_REQUEST['mgjp_mv_download']) ?
+ $_REQUEST['mgjp_mv_download'] :
+ '';
+
+ if (function_exists('mgjp_mv_get_file'))
+ {
+ mgjp_mv_get_file($_GET['mgjp_mv_file'], $force_download);
+ exit; // This exit is important as all we want to do when a
// media download is requested is to serve it and exit
// If it is missing WP will continue serving the page
// after the media file, thus breaking it
+ }
}
- }
}
-
/**
* Register Media Vault Shortcodes
*
* @since 0.5
*/
-function mgjp_mv_register_shortcodes() {
-
- include( plugin_dir_path( __FILE__ ) . 'mv-shortcodes.php' );
-
- if ( function_exists( 'mgjp_mv_download_links_list_shortcode_handler' ) )
- add_shortcode( 'mv_dl_links', 'mgjp_mv_download_links_list_shortcode_handler' );
-
+function mgjp_mv_register_shortcodes()
+{
+
+ include(plugin_dir_path(__FILE__) . 'mv-shortcodes.php');
+
+ if (function_exists('mgjp_mv_download_links_list_shortcode_handler'))
+ {
+ add_shortcode('mv_dl_links', 'mgjp_mv_download_links_list_shortcode_handler');
+ }
+
}
-
/**
* Enqueue styles and scripts for Media Vault
* attachment edit fields.
@@ -411,14 +452,21 @@ function mgjp_mv_register_shortcodes() {
*
* @since 0.8.8
*/
-function mgjp_mv_attachment_edit_fields_styles_and_scripts() {
-
- wp_enqueue_style( 'mgjp-mv-att-fields-css', plugins_url( 'css/mv-attachment-fields.css', __FILE__ ), 'all', null );
- wp_enqueue_script( 'mgjp-mv-att-fields-js', plugins_url( 'js/min/mv-attachment-fields.min.js', __FILE__ ), array( 'media-editor' ), null, true );
-
+function mgjp_mv_attachment_edit_fields_styles_and_scripts()
+{
+
+ wp_enqueue_style('mgjp-mv-att-fields-css', plugins_url('css/mv-attachment-fields.css', __FILE__), 'all', null);
+ // wp_enqueue_script( 'mgjp-mv-att-fields-js', plugins_url( 'js/min/mv-attachment-fields.min.js', __FILE__ ), array( 'media-editor' ), null, true );
+
+ wp_enqueue_script('mgjp-mv-att-fields-js', plugins_url('js/min/mv-attachment-fields.min.js', __FILE__), array('media-editor'), null, true);
+ // Localize the script with new data
+ $translation_array = array(
+ 'upl' => wp_upload_dir(),
+ 'protected_dir' => mgjp_mv_upload_dir()
+ );
+ wp_localize_script( 'mgjp-mv-att-fields-js', 'mgjp_mv_att_fields_js', $translation_array );
}
-
/**
* Add the plugin rewrite rules to the WP rewrite
* rules being written in the sitewide .htaccess file
@@ -430,14 +478,14 @@ function mgjp_mv_attachment_edit_fields_styles_and_scripts() {
* @return string String containing all rewrite rules to be written in htaccess
* including Media Vault custom rewrite rules
*/
-function mgjp_mv_add_plugin_rewrite_rules( $rules ) {
-
- $pattern = "RewriteRule ^index\.php$ - [L]\n";
-
- return str_replace( $pattern, "$pattern\n" . implode( "\n", mgjp_mv_get_the_rewrite_rules() ) . "\n\n", $rules );
+function mgjp_mv_add_plugin_rewrite_rules($rules)
+{
+
+ $pattern = "RewriteRule ^index\.php$ - [L]\n";
+
+ return str_replace($pattern, "$pattern\n" . implode("\n", mgjp_mv_get_the_rewrite_rules()) . "\n\n", $rules);
}
-
/**
* Change upload directory for media uploads to a protected
* folder if the 'protected' post/get parameter has been set
@@ -449,18 +497,19 @@ function mgjp_mv_add_plugin_rewrite_rules( $rules ) {
* @param $param array Array of path info for WP Upload Directory
* @return array Array of path info for Media Vault protected directory
*/
-function mgjp_mv_change_upload_directory( $param ) {
-
- if ( isset( $_POST['mgjp_mv_protected'] ) && 'on' == $_POST['mgjp_mv_protected'] ) {
- $param['subdir'] = mgjp_mv_upload_dir( $param['subdir'], true );
- $param['path'] = $param['basedir'] . $param['subdir'];
- $param['url'] = $param['baseurl'] . $param['subdir'];
- }
-
- return $param;
+function mgjp_mv_change_upload_directory($param)
+{
+
+ if (isset($_POST['mgjp_mv_protected']) && 'on' == $_POST['mgjp_mv_protected'])
+ {
+ $param['subdir'] = mgjp_mv_upload_dir($param['subdir'], true);
+ $param['path'] = $param['basedir'] . $param['subdir'];
+ $param['url'] = $param['baseurl'] . $param['subdir'];
+ }
+
+ return $param;
}
-
/**
* Function for the 'user_has_cap' WP Core filter. Checks the permissions set
* on an attachment before making it available to a user to edit/delete/read.
@@ -476,30 +525,36 @@ function mgjp_mv_change_upload_directory( $param ) {
* @return array @param $allcaps unchanged if user permitted to access post
* @return array @param $allcaps with capability @param $cap[0] set to false
*/
-function mgjp_mv_edit_capabilities( $allcaps, $cap, $args ) {
-
- $disallowed_caps = array(
- 'edit_post',
- 'delete_post',
- 'read_post'
- );
-
- if ( ! in_array( $args[0], $disallowed_caps ) )
- return $allcaps;
-
- if ( ! isset( $args[2] ) )
- return $allcaps;
-
- // check if user is permitted to access the post
- if ( mgjp_mv_check_user_permitted( $args[2] ) )
+function mgjp_mv_edit_capabilities($allcaps, $cap, $args)
+{
+
+ $disallowed_caps = array(
+ 'edit_post',
+ 'delete_post',
+ 'read_post',
+ );
+
+ if (!in_array($args[0], $disallowed_caps))
+ {
+ return $allcaps;
+ }
+
+ if (!isset($args[2]))
+ {
+ return $allcaps;
+ }
+
+ // check if user is permitted to access the post
+ if (mgjp_mv_check_user_permitted($args[2]))
+ {
+ return $allcaps;
+ }
+
+ $allcaps[$cap[0]] = false;
+
return $allcaps;
-
- $allcaps[$cap[0]] = false;
-
- return $allcaps;
}
-
/**
* Replace requested image with a Media Vault place-holder
* if the user is not permitted to view them
@@ -515,109 +570,121 @@ function mgjp_mv_edit_capabilities( $allcaps, $cap, $args ) {
* [2] string height of the Media Vault replacement image
* [3] bool whether the url is for a resized image or not
*/
-function mgjp_mv_replace_protected_image( $img, $attachment_id, $size ) {
-
- $ir = get_option( 'mgjp_mv_ir' );
-
- if ( ! isset( $ir['is_on'] ) || ! $ir['is_on'] )
- return $img;
-
- $upload_dir = wp_upload_dir();
-
- if ( isset( $img[0] ) && 0 !== strpos( ltrim( $img[0], $upload_dir['baseurl'] ), mgjp_mv_upload_dir( '/', true ) ) )
- return $img;
-
- if ( mgjp_mv_check_user_permitted( $attachment_id ) )
- return $img;
-
- if ( isset( $ir['id'] ) && ! mgjp_mv_is_protected( $ir['id'] ) ) {
-
- remove_filter( 'image_downsize', 'mgjp_mv_replace_protected_image', 999, 3 );
- $placeholder = wp_get_attachment_image_src( $ir['id'], $size );
- add_filter( 'image_downsize', 'mgjp_mv_replace_protected_image', 999, 3 );
-
- return $placeholder;
-
- } else {
-
- list( $width, $height ) = image_constrain_size_for_editor( 1024, 1024, $size );
-
- return array(
- plugins_url( 'imgs/media-vault-ir.jpg', __FILE__ ),
- $width,
- $height,
- false
- );
-
- }
+function mgjp_mv_replace_protected_image($img, $attachment_id, $size)
+{
+
+ $ir = get_option('mgjp_mv_ir');
+
+ if (!isset($ir['is_on']) || !$ir['is_on'])
+ {
+ return $img;
+ }
+
+ $upload_dir = wp_upload_dir();
+
+ if (isset($img[0]) && 0 !== strpos(ltrim($img[0], $upload_dir['baseurl']), mgjp_mv_upload_dir('/', true)))
+ {
+ return $img;
+ }
+
+ if (mgjp_mv_check_user_permitted($attachment_id))
+ {
+ return $img;
+ }
+
+ if (isset($ir['id']) && !mgjp_mv_is_protected($ir['id']))
+ {
+
+ remove_filter('image_downsize', 'mgjp_mv_replace_protected_image', 999, 3);
+ $placeholder = wp_get_attachment_image_src($ir['id'], $size);
+ add_filter('image_downsize', 'mgjp_mv_replace_protected_image', 999, 3);
+
+ return $placeholder;
+
+ }
+ else
+ {
+
+ list($width, $height) = image_constrain_size_for_editor(1024, 1024, $size);
+
+ return array(
+ plugins_url('imgs/media-vault-ir.jpg', __FILE__),
+ $width,
+ $height,
+ false,
+ );
+
+ }
}
-
/**
* Include the Media Vault custom AJAX actions
*
* @since 0.8
*/
-function mgjp_mv_ajax_actions_include() {
-
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
- include( plugin_dir_path( __FILE__ ) . 'mv-ajax-actions.php' );
-
+function mgjp_mv_ajax_actions_include()
+{
+
+ if (defined('DOING_AJAX') && DOING_AJAX)
+ {
+ include(plugin_dir_path(__FILE__) . 'mv-ajax-actions.php');
+
+ }
+
}
-
/**
* Include the plugin's general settings
*
* @since 0.4
*/
-function mgjp_mv_media_vault_options_include() {
-
- include( plugin_dir_path( __FILE__ ) . 'mv-options-media-vault.php' );
-
+function mgjp_mv_media_vault_options_include()
+{
+
+ include(plugin_dir_path(__FILE__) . 'mv-options-media-vault.php');
+
}
-
/**
* Include the custom attachment metabox functions
*
* @since 0.7.1
*/
-function mgjp_mv_attachment_metabox_include() {
-
- include( plugin_dir_path( __FILE__ ) . 'mv-metaboxes.php' );
-
+function mgjp_mv_attachment_metabox_include()
+{
+
+ include(plugin_dir_path(__FILE__) . 'mv-metaboxes.php');
+
}
-
/**
* Include the options for protected media uploads
* on the 'media-new.php' admin page
*
* @since 0.2
*/
-function mgjp_mv_media_new_options_include() {
-
- include( plugin_dir_path( __FILE__ ) . 'mv-options-media-new.php' );
-
+function mgjp_mv_media_new_options_include()
+{
+
+ include(plugin_dir_path(__FILE__) . 'mv-options-media-new.php');
+
}
-
/**
* Include the options for protected media uploads
* on the 'upload.php' (Media Library) admin page
*
* @since 0.3
*/
-function mgjp_mv_media_library_options_include() {
-
- include( plugin_dir_path( __FILE__ ) . 'mv-options-media-library.php' );
-
+function mgjp_mv_media_library_options_include()
+{
+
+ include(plugin_dir_path(__FILE__) . 'mv-options-media-library.php');
+
}
-
/**
- * Add Media Vault flag to enable
+ * Add Media Vault flag to enable
* Media Vault mp6 styles for WP 3.8+
*
* @since 0.8.7
@@ -625,19 +692,22 @@ function mgjp_mv_media_library_options_include() {
* @param $classes string admin body classes
* @return string admin body classes
*/
-if ( ! function_exists( 'mgjp_add_mp6_admin_body_class' ) ) {
- function mgjp_add_mp6_admin_body_class( $classes ) {
-
- global $wp_version;
-
- if ( version_compare( '3.7.5', $wp_version, '>' ) )
- return $classes;
-
- return $classes . ' mgjp_mp6 ';
- }
+if (!function_exists('mgjp_add_mp6_admin_body_class'))
+{
+ function mgjp_add_mp6_admin_body_class($classes)
+ {
+
+ global $wp_version;
+
+ if (version_compare('3.7.5', $wp_version, '>'))
+ {
+ return $classes;
+ }
+
+ return $classes . ' mgjp_mp6 ';
+ }
}
-
/**
* Add Media Vault settings link on plugins manager page
*
@@ -646,24 +716,22 @@ function mgjp_add_mp6_admin_body_class( $classes ) {
* @param $links array Array of links associated with plugin
* @return array Array of links associated with plugin plus settings link
*/
-function mgjp_mv_settings_link( $links ) {
-
- $settings_link = ''
- . esc_html__( 'Settings', 'media-vault' )
- . '';
-
- array_push( $links, $settings_link );
-
- return $links;
+function mgjp_mv_settings_link($links)
+{
+
+ $settings_link = ''
+ . esc_html__('Settings', 'media-vault')
+ . '';
+
+ array_push($links, $settings_link);
+
+ return $links;
}
-
-
//-----------------------------------------------------------------------//
// MEDIA VAULT - GENERAL FUNCTIONS
//-----------------------------------------------------------------------//
-
/**
* Media Vault internal Activation function for a single
* blog install or for each blog site
@@ -674,20 +742,20 @@ function mgjp_mv_settings_link( $links ) {
* @uses mgjp_mv_default_options()
* @uses mgjp_mv_load_placeholder_image()
*/
-function _mgjp_mv_activate_local( $blog_id = 0 ) {
-
- // register Media Vault options to the local options table
- add_option( 'mgjp_mv_default_permission', 'logged-in', '', 'yes' );
-
- add_option( 'mgjp_mv_options', mgjp_mv_default_options(), '', 'no' );
- add_option( 'mgjp_mv_ir', array( 'is_on' => true ), '', 'no' );
-
- mgjp_mv_load_placeholder_image();
-
- do_action( 'mgjp_mv_activated_local', $blog_id );
+function _mgjp_mv_activate_local($blog_id = 0)
+{
+
+ // register Media Vault options to the local options table
+ add_option('mgjp_mv_default_permission', 'logged-in', '', 'yes');
+
+ add_option('mgjp_mv_options', mgjp_mv_default_options(), '', 'no');
+ add_option('mgjp_mv_ir', array('is_on' => true), '', 'no');
+
+ mgjp_mv_load_placeholder_image();
+
+ do_action('mgjp_mv_activated_local', $blog_id);
}
-
/**
* Checks whether Media Vault requires extra
* deactivation steps before it can be correctly
@@ -698,25 +766,31 @@ function _mgjp_mv_activate_local( $blog_id = 0 ) {
* @return bool true
* false
*/
-function mgjp_mv_is_deactivation_allowed() {
-
- if ( 'temp' === get_site_option( 'mgjp_mv_deactivation' ) )
- return true;
-
- global $is_apache;
- if ( $is_apache
- && ! is_multisite()
- && get_option( 'permalink_structure' )
- && is_writable( get_home_path() . '.htaccess' ) )
- return true;
-
- if ( ! mgjp_mv_check_rewrite_rules( true ) )
- return true;
-
- return false;
+function mgjp_mv_is_deactivation_allowed()
+{
+
+ if ('temp' === get_site_option('mgjp_mv_deactivation'))
+ {
+ return true;
+ }
+
+ global $is_apache;
+ if ($is_apache
+ && !is_multisite()
+ && get_option('permalink_structure')
+ && is_writable(get_home_path() . '.htaccess'))
+ {
+ return true;
+ }
+
+ if (!mgjp_mv_check_rewrite_rules(true))
+ {
+ return true;
+ }
+
+ return false;
}
-
/**
* Media Vault internal Deactivation function for a single
* blog install or for each blog site
@@ -724,17 +798,19 @@ function mgjp_mv_is_deactivation_allowed() {
*
* @since 0.8.5
*/
-function _mgjp_mv_deactivate_local( $blog_id = 0 ) {
-
- // unload default placeholder image if it exists
- $ir = get_option( 'mgjp_mv_ir' );
- if ( isset( $ir['default'] ) && wp_attachment_is_image( $ir['default'] ) )
- wp_delete_attachment( $ir['default'], true );
-
- do_action( 'mgjp_mv_deactivated_local', $blog_id );
+function _mgjp_mv_deactivate_local($blog_id = 0)
+{
+
+ // unload default placeholder image if it exists
+ $ir = get_option('mgjp_mv_ir');
+ if (isset($ir['default']) && wp_attachment_is_image($ir['default']))
+ {
+ wp_delete_attachment($ir['default'], true);
+ }
+
+ do_action('mgjp_mv_deactivated_local', $blog_id);
}
-
/**
* Return the relative "Path to plugin file with plugin data"
*
@@ -742,18 +818,18 @@ function _mgjp_mv_deactivate_local( $blog_id = 0 ) {
*
* @return string
*/
-function mgjp_mv_get_dirfile() {
-
- $plugin_dir = explode( '/', plugin_basename( __FILE__ ) );
- $plugin_dir = $plugin_dir[0];
-
- $plugin_file = array_keys( get_plugins( "/$plugin_dir" ) );
- $plugin_file = $plugin_file[0];
-
- return "$plugin_dir/$plugin_file";
+function mgjp_mv_get_dirfile()
+{
+
+ $plugin_dir = explode('/', plugin_basename(__FILE__));
+ $plugin_dir = $plugin_dir[0];
+
+ $plugin_file = array_keys(get_plugins("/$plugin_dir"));
+ $plugin_file = $plugin_file[0];
+
+ return "$plugin_dir/$plugin_file";
}
-
/**
* Return the Media Vault protected upload folder
*
@@ -763,20 +839,20 @@ function mgjp_mv_get_dirfile() {
* @param $in_url bool set to true if slash before protected folder dirname is desired
* @return string Media Vault protected upload folder relative to WP uploads folder
*/
-function mgjp_mv_upload_dir( $path = '', $in_url = false ) {
-
- $dirpath = $in_url ? '/' : '';
- $dirpath .= '_mediavault';
- $dirpath .= $path;
-
- return $dirpath;
-
+function mgjp_mv_upload_dir($path = '', $in_url = false)
+{
+
+ $dirpath = $in_url ? '/' : '';
+ $dirpath .= '_mediavault';
+ $dirpath .= $path;
+
+ return $dirpath;
+
}
-
/**
* Generate the rewrite rules to reroute requests for
- * media uploads within protected folders and requests
+ * media uploads within protected folders and requests
* for media uploads with the `safeforce` download flag
* set, to the file-handling script. Even supporting
* WP Multisite.
@@ -787,52 +863,62 @@ function mgjp_mv_upload_dir( $path = '', $in_url = false ) {
* @return array Array of strings of each line of the
* plugin's custom rewrite rules.
*/
-function mgjp_mv_get_the_rewrite_rules() {
-
- $upload = wp_upload_dir();
- $uploads_path = str_replace( home_url( '/' ), '', $upload['baseurl'] );
-
- // if is multisite add allowance for '/sites/ID' folders in uploads path
- if ( is_multisite() )
- $uploads_path .= '(?:/sites/[0-9]+)?';
-
- // if multisite is on sub-directory mode add allowance for the site's
- // sub-directory in the rewrite regex
- if ( is_multisite() && ! is_subdomain_install() )
- $uploads_path = '(?:[_0-9a-zA-Z-]+/)?' . $uploads_path;
-
- $old_path_protected = $uploads_path . '(' . mgjp_mv_upload_dir( '/.*\.\w+)$', true );
- $old_path_downloads = $uploads_path . '(/.*\.\w+)$';
-
- $rewrite_rules = array(
- '# Media Vault Rewrite Rules',
- 'RewriteRule ^' . $old_path_protected . ' index.php?mgjp_mv_file=$1 [QSA,L]',
- 'RewriteCond %{QUERY_STRING} ^(?:.*&)?mgjp_mv_download=safeforce(?:&.*)?$',
- 'RewriteRule ^' . $old_path_downloads . ' index.php?mgjp_mv_file=$1 [QSA,L]',
- '# Media Vault Rewrite Rules End'
- );
-
- // if pretty permalinks not enabled then produce the code necessary for the user to manually
- // add the rules to .htaccess
- if ( ! is_multisite() && ! get_option( 'permalink_structure' ) ) {
- $home_root = parse_url( home_url() );
- if ( isset( $home_root['path'] ) )
- $home_root = trailingslashit( $home_root['path'] );
- else
- $home_root = '/';
-
- array_splice( $rewrite_rules, 1, 0, array(
- '
- ←' . esc_html__( 'Return to homepage', 'media-vault' ) .'
'; - - if ( ! isset( $permissions[$permission] ) ) - wp_die( __( 'The permissions set for this file are not recognized.', 'media-vault' ) . $standard_error_txt ); - - if ( ! isset( $permissions[$permission]['logged_in'] ) ) - $errors[] = 'logged_in'; - if ( ! isset( $permissions[$permission]['cb'] ) ) - $errors[] = 'cb'; - if ( isset( $errors ) ) { - $error_txt = __( 'The permissions set for this file have left the following important parameters undefined:', 'media-vault' ) - . '' . $standard_error_txt . '
'; - wp_die( $error_txt ); +function mgjp_mv_get_file($rel_file, $action = '') +{ + + // $rel_file = path to the file to view/download, + // relative to the WP uploads folder + // (eg:'/media-vault/2013/10/media-vault-150x150.jpg') + + $upload_dir = wp_upload_dir(); + + // only files in the WP uploads directory are allowed to be accessed: + $file = rtrim($upload_dir['basedir'], '/') . str_replace('..', '', isset($rel_file) ? $rel_file : ''); + + //---Basic Checks----------------------------------------------------// + + if (!$upload_dir['basedir'] || !is_file($file)) + { + status_header(404); + wp_die('404. File not found. ' . $upload_dir['basedir'] . " " . $file); } - - if ( $permissions[$permission]['logged_in'] ) - is_user_logged_in() || auth_redirect(); // using is_user_logged_in is lighter than using just auth_redirect - - if ( false !== $permissions[$permission]['cb'] ) { - - if ( ! is_callable( $permissions[$permission]['cb'] ) ) - wp_die( __( 'The permission checking function set in this file\'s permissions is not callable.', 'media-vault' ) . $standard_error_txt ); - - $permission_check = call_user_func_array( $permissions[$permission]['cb'], array( $attachment_id, $rel_file, $file ) ); - - if ( is_wp_error( $permission_check ) ) - wp_die( $permission_check->get_error_message() . $standard_error_txt ); - - if ( true !== $permission_check ) - wp_die( __( 'You do not have sufficient permissions to view this file.', 'media-vault' ) . $standard_error_txt ); + + $mime = wp_check_filetype($file); // Check filetype against allowed filetypes + + if (isset($mime['type']) && $mime['type']) + { + $mimetype = $mime['type']; } - - } // end of permission checks - - //-------------------------------------------------------------------// - - //header( 'Content-Type: ' . $mimetype ); // always send this - if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) - header( 'Content-Length: ' . filesize( $file ) ); - if ( 'safeforce' !== $action ) { - //Force PDF Download - if ($mimetype !== "application/pdf"){ - //--OPEN FILE IN BROWSER functions-------------// - header( 'Content-Type: application/octet-stream' ); - $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); - $etag = '"' . md5( $last_modified ) . '"'; - header( "Last-Modified: $last_modified GMT" ); - header( 'ETag: ' . $etag ); - header( 'Cache-Control: no-store, no-cache, must-revalidate' ); // HTTP 1.1. - header( 'Pragma: no-cache' ); // HTTP 1.0. - header( 'Expires: Thu, 01 Dec 1994 16:00:00 GMT' ); // Proxies - header( 'Content-Disposition: attachment; filename="' . $file_info['basename'] . '";' ); - header( 'Content-Transfer-Encoding: binary' ); - - // Support for Conditional GET - $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; - - if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) - $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; - - $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); - // If string is empty, return 0. If not, attempt to parse into a timestamp - $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; - - // Make a timestamp for our most recent modification... - $modified_timestamp = strtotime( $last_modified ); - - if ( ( $client_last_modified && $client_etag ) - ? ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) - : ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) - ) { - status_header( 304 ); - exit; - } - } else { - header( 'Content-Type: application/octet-stream' ); - // required for IE, otherwise Content-disposition is ignored - if( ini_get( 'zlib.output_compression' ) ) - ini_set( 'zlib.output_compression', 'Off' ); - - header( 'Pragma: public' ); // required - header( 'Expires: 0' ); - header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); - header( 'Cache-Control: private', false ); // required for certain browsers - header( 'Content-Disposition: attachment; filename="' . $file_info['basename'] . '";' ); - header( 'Content-Transfer-Encoding: binary' ); - } - - } else { - //--FORCE DOWNLOAD Functions-----------------------// - - // required for IE, otherwise Content-disposition is ignored - if( ini_get( 'zlib.output_compression' ) ) - ini_set( 'zlib.output_compression', 'Off' ); - - header( 'Pragma: public' ); // required - header( 'Expires: 0' ); - header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); - header( 'Cache-Control: private', false ); // required for certain browsers - header( 'Content-Disposition: attachment; filename="' . $file_info['basename'] . '";' ); - header( 'Content-Transfer-Encoding: binary' ); - - } - - // If we made it this far, just serve the file - if ( ob_get_length() ) - ob_clean(); - - flush(); - - readfile( $file ); - exit; -} + else + { + status_header(403); + wp_die(__('403. Forbidden.←' . esc_html__('Return to homepage', 'media-vault') . '
'; + + if (!isset($permissions[$permission])) + { + wp_die(__('The permissions set for this file are not recognized.', 'media-vault') . $standard_error_txt); + } + + if (!isset($permissions[$permission]['logged_in'])) + { + $errors[] = 'logged_in'; + } + if (!isset($permissions[$permission]['cb'])) + { + $errors[] = 'cb'; + } + if (isset($errors)) + { + $error_txt = __('The permissions set for this file have left the following important parameters undefined:', 'media-vault') + . '' . $standard_error_txt . '
'; + wp_die($error_txt); + } + + if ($permissions[$permission]['logged_in']) + { + is_user_logged_in() || auth_redirect(); + } // using is_user_logged_in is lighter than using just auth_redirect + + if (false !== $permissions[$permission]['cb']) + { + + if (!is_callable($permissions[$permission]['cb'])) + { + wp_die(__('The permission checking function set in this file\'s permissions is not callable.', 'media-vault') . $standard_error_txt); + } + + $permission_check = call_user_func_array($permissions[$permission]['cb'], array($attachment_id, $rel_file, $file)); + + if (is_wp_error($permission_check)) + { + wp_die($permission_check->get_error_message() . $standard_error_txt); + } + + if (true !== $permission_check) + { + wp_die(__('You do not have sufficient permissions to view this file.', 'media-vault') . $standard_error_txt); + } + } + + } // end of permission checks + + //-------------------------------------------------------------------// + + //header( 'Content-Type: ' . $mimetype ); // always send this + if (false === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS')) + { + header('Content-Length: ' . filesize($file)); + } + if ('safeforce' !== $action) + { + //Force PDF Download + if ($mimetype !== "application/pdf") + { + //--OPEN FILE IN BROWSER functions-------------// + header('Content-Type: application/octet-stream'); + $last_modified = gmdate('D, d M Y H:i:s', filemtime($file)); + $etag = '"' . md5($last_modified) . '"'; + header("Last-Modified: $last_modified GMT"); + header('ETag: ' . $etag); + header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP 1.1. + header('Pragma: no-cache'); // HTTP 1.0. + header('Expires: Thu, 01 Dec 1994 16:00:00 GMT'); // Proxies + header('Content-Disposition: attachment; filename="' . $file_info['basename'] . '";'); + header('Content-Transfer-Encoding: binary'); + + // Support for Conditional GET + $client_etag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : false; + + if (!isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) + { + $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; + } + + $client_last_modified = trim($_SERVER['HTTP_IF_MODIFIED_SINCE']); + // If string is empty, return 0. If not, attempt to parse into a timestamp + $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; + + // Make a timestamp for our most recent modification... + $modified_timestamp = strtotime($last_modified); + + if (($client_last_modified && $client_etag) + ? (($client_modified_timestamp >= $modified_timestamp) && ($client_etag == $etag)) + : (($client_modified_timestamp >= $modified_timestamp) || ($client_etag == $etag)) + ) + { + status_header(304); + exit; + } + } + else + { + header('Content-Type: application/octet-stream'); + // required for IE, otherwise Content-disposition is ignored + if (ini_get('zlib.output_compression')) + { + ini_set('zlib.output_compression', 'Off'); + } + + header('Pragma: public'); // required + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Cache-Control: private', false); // required for certain browsers + header('Content-Disposition: attachment; filename="' . $file_info['basename'] . '";'); + header('Content-Transfer-Encoding: binary'); + } + + } + else + { + //--FORCE DOWNLOAD Functions-----------------------// + + // required for IE, otherwise Content-disposition is ignored + if (ini_get('zlib.output_compression')) + { + ini_set('zlib.output_compression', 'Off'); + } + + header('Pragma: public'); // required + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Cache-Control: private', false); // required for certain browsers + header('Content-Disposition: attachment; filename="' . $file_info['basename'] . '";'); + header('Content-Transfer-Encoding: binary'); + + } + + // If we made it this far, just serve the file + if (ob_get_length()) + { + ob_clean(); + } + + flush(); + + readfile($file); + exit; +} \ No newline at end of file diff --git a/mv-metaboxes.php b/mv-metaboxes.php index d7a85fe..aa54187 100644 --- a/mv-metaboxes.php +++ b/mv-metaboxes.php @@ -174,5 +174,3 @@ function mgjp_mv_save_attachment_metabox_data( $attachment_id ) { } } add_action( 'edit_attachment', 'mgjp_mv_save_attachment_metabox_data' ); - -?> \ No newline at end of file diff --git a/mv-options-media-new.php b/mv-options-media-new.php index a4bc479..3f9ac0e 100644 --- a/mv-options-media-new.php +++ b/mv-options-media-new.php @@ -134,6 +134,4 @@ function mgjp_mv_render_media_new_options_message_box() { \ No newline at end of file +add_action( 'pre-plupload-upload-ui', 'mgjp_mv_render_media_new_options_message_box' ); \ No newline at end of file diff --git a/mv-options-media-vault.php b/mv-options-media-vault.php index bfe3ed5..985b7c5 100644 --- a/mv-options-media-vault.php +++ b/mv-options-media-vault.php @@ -304,6 +304,4 @@ function mgjp_mv_options_media_enqueue_scripts() { wp_enqueue_script( 'mgjp-image-selector', plugins_url( 'js/min/mv-image-selector.min.js', __FILE__ ), array( 'jquery', 'json2' ), null, true ); } -add_action( 'admin_enqueue_scripts', 'mgjp_mv_options_media_enqueue_scripts' ); - -?> \ No newline at end of file +add_action( 'admin_enqueue_scripts', 'mgjp_mv_options_media_enqueue_scripts' ); \ No newline at end of file diff --git a/mv-shortcodes.php b/mv-shortcodes.php index a2c072c..80e2da5 100644 --- a/mv-shortcodes.php +++ b/mv-shortcodes.php @@ -83,6 +83,4 @@ function mgjp_mv_download_links_list_shortcode_handler( $atts ) { \ No newline at end of file +} \ No newline at end of file diff --git a/readme.txt b/readme.txt index 5236536..74e4965 100644 --- a/readme.txt +++ b/readme.txt @@ -1,12 +1,14 @@ === Media Vault === -Contributors: Max GJP -Donate Link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6KFT65LQXEHFQ -Tags: media, security, protection, attachments, downloads, download links, powerful, shortcode, flexible, simple, uploads, images, multisite, files, links, private, documents -Requires at least: 3.5.0 -Tested up to: 3.8.1 -Stable tag: 0.8.13 +Plugin Name: Media Vault (BB) +Plugin URI: https://github.com/bruno-barros/wordpress-plugin-media-vault +Description: Protect attachment files from direct access using powerful and flexible restrictions. Offer safe download links for any file in your uploads folder. +Network: true +Text Domain: media-vault +Domain Path: /languages +Version: 0.9.0 +Author: Bruno Barros +Author URI: http://maxpanas.com License: GPLv3 or later -License URI: http://www.gnu.org/licenses/gpl-3.0.html Protect attachment files from direct access using powerful and flexible restrictions. Offer safe download links for any file in your uploads folder. @@ -88,6 +90,12 @@ This question was recently asked and answered in [this support thread](https://w == Changelog == += 0.9.0 = +* Fixed $meta array could me string and breaks file name. +* On mgjp_get_attachment_by_post_name() the way it finds the attachment based on the filename is totally unsure if you apply a filter when process upload. Now stores a metadata '_wp_attachment_filename' to match the filename and fallback to the previous behavior. +* Remove closing PHP tag to prevent to send unexpected data to the browser. +* On media popup, when changing the secure rule updates the URL dynamically. + = 0.8.13 = * Fixed vulnerability in `mv-file-handler.php` allowing authenticated users access to other users files.