Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,688 changes: 924 additions & 764 deletions _mediavault.php

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions includes/mgjp-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function mgjp_wp_relative_upload_path( $path ) {
* @param $new_reldir string the new path to the attachment relative to the WP uploads directory
* @return object | bool Returns WP_Error on failure and True on success
*/

if ( ! function_exists( 'mgjp_move_attachment_files' ) ) {
function mgjp_move_attachment_files( $attachment_id, $new_reldir ) {

Expand Down Expand Up @@ -108,9 +109,9 @@ function mgjp_move_attachment_files( $attachment_id, $new_reldir ) {
) );


// Get all filenames for all attached files
// If image! Get all filenames for all attached files
$intermediate_sizes = array();
if ( is_array( $meta['sizes'] ) ) {
if (isset($meta['sizes']) && is_array( $meta['sizes'] ) ) {
foreach ( $meta['sizes'] as $size ) {
$intermediate_sizes[] = $size['file'];
}
Expand Down Expand Up @@ -144,7 +145,7 @@ function mgjp_move_attachment_files( $attachment_id, $new_reldir ) {

// prep for filename conflict script
$orig_filename = pathinfo( $orig_basename );
$orig_filename = $orig_filename['filename'];
$orig_filename = $orig_filename['filename'];// filename without extension
$conflict = true;
$number = 1;
$separator = '#';
Expand Down Expand Up @@ -206,11 +207,17 @@ function mgjp_move_attachment_files( $attachment_id, $new_reldir ) {


// Update all attachment filepaths in database to point to the new location

// $new_basenames[0] should always be the basename of the file
// from '_wp_attached_media' with the new conflict free filename
if(!is_array($meta)){
$meta = array();
}

$meta['file'] = path_join( $new_reldir, $new_basenames[0] );
update_post_meta( $attachment_id, '_wp_attached_file', $meta['file'] );

if(strlen($meta['file']) > 4){
update_post_meta( $attachment_id, '_wp_attached_file', $meta['file'] );
}

// if $new_basenames != $old_basenames we must update the
// original basename used in the guid as well as the metadata
Expand Down Expand Up @@ -248,11 +255,20 @@ function mgjp_move_attachment_files( $attachment_id, $new_reldir ) {
}

update_post_meta( $attachment_id, '_wp_attachment_metadata', $meta );

// Save to find later instead of post_name
update_post_meta( $attachment_id, '_wp_attachment_filename', $orig_filename );

$guid = path_join( $new_fulldir, $orig_basename ); // should I be updating the GUID? the Codex says I should
// should I be updating the GUID? the Codex says I should
$guid = path_join( $new_fulldir, $orig_basename );
// dd(array( 'ID' => $attachment_id, 'guid' => $guid, 'post_name' => $orig_filename ));
// just in case someone wants to disable updating the guid: // for attachments.
if ( apply_filters( 'mgjp_update_guid_on_attachment_files_move', true ) )
wp_update_post( array( 'ID' => $attachment_id, 'guid' => $guid ) );
if ( apply_filters( 'mgjp_update_guid_on_attachment_files_move', true ) ){
wp_update_post( array(
'ID' => $attachment_id,
'guid' => $guid,
) );
}


// NOT IMPLEMENTED YET: If $rewrite_whole_db flag is set, sanely search through database for instances of
Expand Down Expand Up @@ -287,6 +303,4 @@ function wpst_mv_restrict_only_for_subscribers() {
return true;

return false;
}

?>
}
2 changes: 1 addition & 1 deletion js/min/mv-attachment-fields.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 55 additions & 41 deletions js/mv-attachment-fields.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
(function ($) {

var vals = {},
postId, permissionsField;

$('body')

.on('mgjpMvLoaded', '#mgjp_mv_attachment_fields', function (event, id) {
postId = id;
permissionsField = $('#mgjp_mv_attachment_permissions_field');

if (vals.hasOwnProperty(postId)) {
$(this).find('.mgjp_mv_protection_toggle, .mgjp_mv_permission_select').each(function () {
if (!vals[postId].hasOwnProperty(this.name))
return;

if ('checkbox' === this.type)
this.checked = vals[postId][this.name];
else
this.value = vals[postId][this.name];
var d = mgjp_mv_att_fields_js,
vals = {},
postId, permissionsField;


$('body')

.on('mgjpMvLoaded', '#mgjp_mv_attachment_fields', function (event, id) {
postId = id;
permissionsField = $('#mgjp_mv_attachment_permissions_field');

if (vals.hasOwnProperty(postId)) {
$(this).find('.mgjp_mv_protection_toggle, .mgjp_mv_permission_select').each(function () {
if (!vals[postId].hasOwnProperty(this.name))
return;

if ('checkbox' === this.type)
this.checked = vals[postId][this.name];
else
this.value = vals[postId][this.name];
});
}

$(this).find('.mgjp_mv_protection_toggle').trigger('change', 'mvJustLoaded');
})

.on('change', '.mgjp_mv_protection_toggle', function (event, justLoaded) {
duration = 'mvJustLoaded' !== justLoaded ? 400 : 0;

var $url = $('label[data-setting=url] input');

if (this.checked){
permissionsField.slideDown(duration);
if($url.val().indexOf(d.protected_dir) === -1){
var end = $url.val().replace(d.upl.baseurl+'/', '');
var final = d.upl.baseurl+'/'+d.protected_dir+'/'+end;
$url.val(final)
}
}
else {
permissionsField.slideUp(duration);
if($url.val().indexOf(d.protected_dir) > -1){
$url.val($url.val().replace(d.protected_dir+'/', ''))
}
}
})

.on('change', '.mgjp_mv_protection_toggle, .mgjp_mv_permission_select', function (event, justLoaded) {
if ('mvJustLoaded' === justLoaded)
return;

if (!vals.hasOwnProperty(postId))
vals[postId] = {};

vals[postId][this.name] = 'checkbox' === this.type ? this.checked : this.value;
});
}

$(this).find('.mgjp_mv_protection_toggle').trigger('change', 'mvJustLoaded');
})

.on('change', '.mgjp_mv_protection_toggle', function (event, justLoaded) {
duration = 'mvJustLoaded' !== justLoaded ? 400 : 0;

if (this.checked)
permissionsField.slideDown(duration);
else
permissionsField.slideUp(duration);
})

.on('change', '.mgjp_mv_protection_toggle, .mgjp_mv_permission_select', function (event, justLoaded) {
if ('mvJustLoaded' === justLoaded)
return;

if (!vals.hasOwnProperty(postId))
vals[postId] = {};

vals[postId][this.name] = 'checkbox' === this.type ? this.checked : this.value;
});

}(jQuery));
Loading