add urldecode on read a private file and try/catch on `pre_delete_attachment` logs

This commit is contained in:
vnmedeiros 2020-06-30 14:45:05 -03:00
parent 914ea388ef
commit c3148daa91
3 changed files with 44 additions and 40 deletions

View File

@ -256,7 +256,7 @@ class REST_Collections_Controller extends REST_Controller {
} }
// Clear private metadata from metadata_order // Clear private metadata from metadata_order
if ( is_array( $item_arr['metadata_order'] ) && ! current_user_can( 'tnc_col_' . $item->get_id() . '_read_private_metadata' ) ) { if ( isset($item_arr['metadata_order']) && is_array( $item_arr['metadata_order'] ) && ! current_user_can( 'tnc_col_' . $item->get_id() . '_read_private_metadata' ) ) {
$metadata = $item->get_metadata(); $metadata = $item->get_metadata();
$meta_ids = array_map( $meta_ids = array_map(
@ -275,7 +275,7 @@ class REST_Collections_Controller extends REST_Controller {
} }
// Clear private filters from filters_order // Clear private filters from filters_order
if ( is_array( $item_arr['filters_order'] ) && ! current_user_can( 'tnc_col_' . $item->get_id() . '_read_private_filters' ) ) { if ( isset($item_arr['filters_order']) && is_array( $item_arr['filters_order'] ) && ! current_user_can( 'tnc_col_' . $item->get_id() . '_read_private_filters' ) ) {
$filters = $item->get_filters(); $filters = $item->get_filters();
$filters_ids = array_map( $filters_ids = array_map(

View File

@ -202,7 +202,7 @@ class Private_Files {
$file_path = \str_replace( '/', $this->dir_separator, str_replace($base_upload_url, '', $requested_uri) ); $file_path = \str_replace( '/', $this->dir_separator, str_replace($base_upload_url, '', $requested_uri) );
$file = $upload_dir['basedir'] . $file_path; $file = urldecode($upload_dir['basedir'] . $file_path);
$existing_file = false; $existing_file = false;
@ -262,9 +262,10 @@ class Private_Files {
* private uploads folder prefix from the attachments URLs * private uploads folder prefix from the attachments URLs
*/ */
function image_get_intermediate_size($data, $post_id, $size) { function image_get_intermediate_size($data, $post_id, $size) {
if(isset($data['path']))
$data['path'] = str_replace($this->dir_separator . $this->get_private_folder_prefix(), $this->dir_separator, $data['path']); $data['path'] = str_replace($this->dir_separator . $this->get_private_folder_prefix(), $this->dir_separator, $data['path']);
$data['url'] = str_replace('/' . $this->get_private_folder_prefix(), '/', $data['url']); if(isset($data['url']))
$data['url'] = str_replace('/' . $this->get_private_folder_prefix(), '/', $data['url']);
return $data; return $data;

View File

@ -309,41 +309,44 @@ class Logs extends Repository {
$entity_post = get_post($attachment_post->post_parent); $entity_post = get_post($attachment_post->post_parent);
if ( $entity_post ) { if ( $entity_post ) {
try {
$entity = Repository::get_entity_by_post( $entity_post );
$entity = Repository::get_entity_by_post( $entity_post ); if ( $entity ) {
if ( $entity ) { $collection_id = method_exists($entity, 'get_collection_id') ? $entity->get_collection_id() : 'default';
$collection_id = method_exists($entity, 'get_collection_id') ? $entity->get_collection_id() : 'default'; $log = new Entities\Log();
$log = new Entities\Log(); if ( $entity instanceof Entities\Collection ) {
$collection_id = $entity->get_id();
$log->set_title( sprintf(__( 'File attached to Collection "%s" was removed', 'tainacan'), $entity->get_name() ) );
}
if ( $entity instanceof Entities\Item ) {
$log->set_item_id($entity->get_id());
$log->set_title( sprintf( __( 'File attached to Item "%s" was removed' , 'tainacan'), $entity->get_title() ) );
}
$object_type = get_class($entity);
$object_id = $entity->get_id();
$preapred = [
'id' => $attachment_id,
'title' => $attachment_post->post_title,
'description' => $attachment_post->post_content,
];
$log->set_collection_id($collection_id);
$log->set_object_type($object_type);
$log->set_object_id($object_id);
$log->set_old_value($preapred);
$log->set_action('delete-attachment');
$this->current_attachment_delete_log = $log;
if ( $entity instanceof Entities\Collection ) {
$collection_id = $entity->get_id();
$log->set_title( sprintf(__( 'File attached to Collection "%s" was removed', 'tainacan'), $entity->get_name() ) );
} }
if ( $entity instanceof Entities\Item ) { } catch (\Exception $e) {
$log->set_item_id($entity->get_id()); error_log("[pre_delete_attachment]:" . $e->getMessage());
$log->set_title( sprintf( __( 'File attached to Item "%s" was removed' , 'tainacan'), $entity->get_title() ) );
}
$object_type = get_class($entity);
$object_id = $entity->get_id();
$preapred = [
'id' => $attachment_id,
'title' => $attachment_post->post_title,
'description' => $attachment_post->post_content,
];
$log->set_collection_id($collection_id);
$log->set_object_type($object_type);
$log->set_object_id($object_id);
$log->set_old_value($preapred);
$log->set_action('delete-attachment');
$this->current_attachment_delete_log = $log;
} }
} }