Skip to content

Commit

Permalink
Merge pull request #40 from mwks-jg/mwks-plugin-management
Browse files Browse the repository at this point in the history
PR for housekeeping / light refactoring / file extension feature
  • Loading branch information
jdashley27 authored Jul 21, 2022
2 parents b2075a1 + 22fda5c commit 97bf13f
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 27 deletions.
Binary file modified dist/img/placeholder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dist/scripts/admin.js

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

22 changes: 19 additions & 3 deletions dist/styles/admin.css

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

12 changes: 6 additions & 6 deletions lib/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public function handle_search_submit(): void {
* $_POST['description']
* $_POST['url']
*/
public function add_image_to_library(): void {
public function add_asset_to_library(): void {
// Kill this process if this method wasn't called from our form.
check_ajax_referer( 'widen_media_ajax_request', 'nonce' );

Expand Down Expand Up @@ -545,9 +545,7 @@ public function add_image_to_library(): void {
$asset_data['fields'] = sanitize_text_field( wp_unslash( $_POST['fields'] ) );
}

$mime_type = mime_content_type( $asset_data['url'] );

// Get asset size & mime type.
// Get image size & mime type.
if ( 'image' === $asset_data['type'] ) {
// Original image sizes.
$image_size = @getimagesize( $asset_data['url'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
Expand All @@ -556,12 +554,13 @@ public function add_image_to_library(): void {
$asset_data['mime_type'] = $image_size['mime'];
}

// Check if pdf file extension and add mime type.
if ( 'pdf' === $asset_data['type'] ) {
$asset_data['mime_type'] = 'application/pdf';
}

// Check if Office file extension and add mime type.
if ( 'office' === $asset_data['type'] ) {
// check office file extension and apply correct mimetype.
if ( 'xls' === $asset_data['ext'] ) {
$asset_data['mime_type'] = 'application/vnd.ms-excel';
}
Expand All @@ -582,8 +581,8 @@ public function add_image_to_library(): void {
}
}

// Check if generic file type (.xml, .csv) and add mime type.
if ( 'generic' === $asset_data['type'] ) {
// check generic file extension and apply correct mimetype.
if ( 'csv' === $asset_data['ext'] ) {
$asset_data['mime_type'] = 'text/csv';
}
Expand All @@ -592,6 +591,7 @@ public function add_image_to_library(): void {
}
}

// Check if video file and add mime type.
if ( 'video' === $asset_data['type'] ) {
if ( 'MPEG4' === $asset_data['format'] ) {
$asset_data['mime_type'] = 'video/mp4';
Expand Down
4 changes: 3 additions & 1 deletion lib/Admin/tiles/generic_binary.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Results tile for an Office file (.doc, .xls, etc).
* Results tile for a generic file (.xml, .csv etc).
*/

declare( strict_types = 1 );
Expand Down Expand Up @@ -33,11 +33,13 @@
$already_added = Util::attachment_exists( $original_url );
$attachment_id = $already_added ? Util::get_attachment_id( $original_url ) : '';

// Get extension of file.
$file_ext = pathinfo( $original_url );
$file_ext = $file_ext['extension'];
?>
<div class="tile file <?php echo esc_attr( $already_added ) ? 'added' : ''; ?>">
<div class="tile__wrapper">
<div class="extension"><?php echo esc_attr( $file_ext ); ?></div>
<div class="tile__header" aria-hidden="true">
<img
class="tile__image blur-up lazyload"
Expand Down
4 changes: 4 additions & 0 deletions lib/Admin/tiles/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
$already_added = Util::attachment_exists( $original_url );
$attachment_id = $already_added ? Util::get_attachment_id( $original_url ) : '';

// Get extension of file.
$file_ext = pathinfo( $original_url );
$file_ext = $file_ext['extension'];
?>
<div class="tile image <?php echo $already_added ? 'added' : ''; ?>">
<div class="tile__wrapper">
<div class="extension"><?php echo esc_attr( $file_ext ); ?></div>
<div class="tile__header" aria-hidden="true">
<img
class="tile__image blur-up lazyload"
Expand Down
1 change: 1 addition & 0 deletions lib/Admin/tiles/office.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
?>
<div class="tile office_file <?php echo $already_added ? 'added' : ''; ?>">
<div class="tile__wrapper">
<div class="extension"><?php echo esc_attr( $office_file_ext ); ?></div>
<div class="tile__header" aria-hidden="true">
<img
class="tile__image blur-up lazyload"
Expand Down
4 changes: 4 additions & 0 deletions lib/Admin/tiles/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
$already_added = Util::attachment_exists( $original_url );
$attachment_id = $already_added ? Util::get_attachment_id( $original_url ) : '';

// Get extension of file.
$file_ext = pathinfo( $original_url );
$file_ext = $file_ext['extension'];
?>
<div class="tile pdf <?php echo $already_added ? 'added' : ''; ?>">
<div class="tile__wrapper">
<div class="extension"><?php echo esc_attr( $file_ext ); ?></div>
<div class="tile__header" aria-hidden="true">
<img
class="tile__image blur-up lazyload"
Expand Down
9 changes: 7 additions & 2 deletions lib/Admin/tiles/video.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Results tile for a pdf
* Results tile for a video file.
*/

declare( strict_types = 1 );
Expand Down Expand Up @@ -34,9 +34,14 @@

// Get tile thumbnail video preview url.
$video_thumbnail = $item['embeds']['video_poster']['url'];

// Get extension of file.
$file_ext = pathinfo( $original_url );
$file_ext = $file_ext['extension'];
?>
<div class="tile mp4 <?php echo $already_added ? 'added' : ''; ?>">
<div class="tile video <?php echo $already_added ? 'added' : ''; ?>">
<div class="tile__wrapper">
<div class="extension"><?php echo esc_attr( $file_ext ); ?></div>
<div class="tile__header" aria-hidden="true">
<img
class="tile__image blur-up lazyload"
Expand Down
7 changes: 1 addition & 6 deletions lib/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ private function define_admin_hooks(): void {
$this->loader->add_action( 'admin_post_handle_search_submit', $plugin_admin, 'handle_search_submit' );

// Register ajax actions for this plugin.
$this->loader->add_action( 'wp_ajax_widen_media_add_image_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_audio_to_library', $plugin_admin, 'add_audio_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_pdf_to_library', $plugin_admin, 'add_pdf_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_office_file_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_generic_file_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_video_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_asset_to_library', $plugin_admin, 'add_asset_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_save_collection', $plugin_admin, 'save_collection' );
$this->loader->add_filter( 'post_row_actions', $plugin_admin, 'remove_collections_quick_edit', 10, 2 );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'remove_collections_submit_box' );
Expand Down
12 changes: 6 additions & 6 deletions src/scripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import '../styles/admin.scss';
switch (type) {
case 'image':
data = {
action: 'widen_media_add_image_to_library',
action: 'widen_media_add_asset_to_library',
nonce: widen_media.ajax_nonce,
type,
id,
Expand All @@ -51,7 +51,7 @@ import '../styles/admin.scss';
break
case 'pdf':
data = {
action: 'widen_media_add_image_to_library',
action: 'widen_media_add_asset_to_library',
nonce: widen_media.ajax_nonce,
type,
id,
Expand All @@ -65,7 +65,7 @@ import '../styles/admin.scss';
break
case 'office':
data = {
action: 'widen_media_add_office_file_to_library',
action: 'widen_media_add_asset_to_library',
nonce: widen_media.ajax_nonce,
type,
ext,
Expand All @@ -80,7 +80,7 @@ import '../styles/admin.scss';
break
case 'generic':
data = {
action: 'widen_media_add_generic_file_to_library',
action: 'widen_media_add_asset_to_library',
nonce: widen_media.ajax_nonce,
type,
ext,
Expand All @@ -95,7 +95,7 @@ import '../styles/admin.scss';
break
case 'video':
data = {
action: 'widen_media_add_video_to_library',
action: 'widen_media_add_asset_to_library',
nonce: widen_media.ajax_nonce,
type,
format,
Expand All @@ -110,7 +110,7 @@ import '../styles/admin.scss';
break
case 'audio':
data = {
action: 'widen_media_add_audio_to_library',
action: 'widen_media_add_asset_to_library',
nonce: widen_media.ajax_nonce,
type,
id,
Expand Down
26 changes: 24 additions & 2 deletions src/styles/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,28 @@ $breakpoint-xs: 500px;
letter-spacing: 0.02em;
backface-visibility: hidden;
}

.extension {
position: absolute;
top: 0;
right: 0;
padding: 0.3em 1em;
background-color: #343639;
color: #fff;
font-weight: 700;
border-bottom-left-radius: 3px;
text-transform: uppercase;
font-size: 0.85em;
z-index: 1;
}
}

&__image {
display: block;
max-width: 100%;
height: auto;
height: 200px;
margin: 0 auto;
object-fit: contain;
}

&__header {
Expand Down Expand Up @@ -226,10 +241,17 @@ $breakpoint-xs: 500px;

.tile__image,
.tile__title,
.button-link {
.button-link,
.extension {
opacity: 0.4;
}
}

&.video {
.tile__image {
object-fit: cover;
}
}
}

.blur-up:not(.lazyloaded) {
Expand Down

0 comments on commit 97bf13f

Please sign in to comment.