Skip to content

Commit

Permalink
Merge pull request #41 from mwks-jg/plugin_feedback-8-5-22
Browse files Browse the repository at this point in the history
PDF view default URL
  • Loading branch information
jdashley27 authored Aug 9, 2022
2 parents 97bf13f + 060c225 commit 0041476
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/Admin/tiles/office.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class="tile__image blur-up lazyload"
class="button add-to-library"
data-type="office"
data-ext="<?php echo esc_attr( $office_file_ext ); ?>"
data-id="<?php echo esc_attr( $pdf_id ); ?>"
data-filename="<?php echo esc_attr( $pdf_filename ); ?>"
data-id="<?php echo esc_attr( $office_file_id ); ?>"
data-filename="<?php echo esc_attr( $office_file_filename ); ?>"
data-description="<?php echo esc_attr( $description ); ?>"
data-url="<?php echo esc_attr( $original_url ); ?>"
data-templated-url="<?php echo esc_attr( Util::sanitize_image_url( $templated_url ) ); ?>"
Expand Down
17 changes: 9 additions & 8 deletions lib/Admin/tiles/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@
$templated_url = $item['embeds']['templated']['url'] ?? '';

$original_url = $item['embeds']['original']['url'] ?? '';
$view_url = $item['embeds']['document_viewer_with_download']['url'] ?? '';
$thumbnail_url = $item['embeds']['document_thumbnail']['url'] ?? '';
$skeleton_url = $item['embeds']['document_thumbnail']['url'] ?? '';

// Change possible TIF url to PNG url.
if ( strpos( $original_url, '.tif' ) !== false ) {
$original_url = $item['embeds']['OriginalPNG']['url'];
}

// Remove query string from url.
$original_url = Util::remove_query_string( $original_url );
$view_url = Util::remove_query_string( $view_url );
$thumbnail_url = Util::remove_query_string( $thumbnail_url );
$skeleton_url = Util::remove_query_string( $skeleton_url );

// Remove spaces and escape url.
$view_url = Util::remove_spaces( $view_url );
$view_url = esc_url( $view_url );

// Check if the pdf has already been added.
$already_added = Util::attachment_exists( $original_url );
$attachment_id = $already_added ? Util::get_attachment_id( $original_url ) : '';
$already_added = Util::attachment_exists( $view_url );
$attachment_id = $already_added ? Util::get_attachment_id( $view_url ) : '';

// Get extension of file.
$file_ext = pathinfo( $original_url );
Expand Down Expand Up @@ -69,7 +70,7 @@ class="button add-to-library"
data-id="<?php echo esc_attr( $pdf_id ); ?>"
data-filename="<?php echo esc_attr( $pdf_filename ); ?>"
data-description="<?php echo esc_attr( $description ); ?>"
data-url="<?php echo esc_attr( $original_url ); ?>"
data-url="<?php echo esc_attr( $view_url ); ?>"
data-templated-url="<?php echo esc_attr( Util::sanitize_image_url( $templated_url ) ); ?>"
data-thumbnail-url="<?php echo esc_attr( Util::sanitize_image_url( $thumbnail_url ) ); ?>"
data-fields="<?php echo esc_attr( $fields ); ?>"
Expand Down
9 changes: 9 additions & 0 deletions lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public static function remove_query_string( $url ): string {
return preg_replace( '/\?.*/', '', $url );
}

/**
* Remove space characters from from a url.
*
* @param string $url The url to clean.
*/
public static function remove_spaces( $url ): string {
return preg_replace( '/%20/', '_', $url );
}

/**
* Sanitize our image URLs:
*
Expand Down
2 changes: 1 addition & 1 deletion widen-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Widen Media
* Description: Search and add Widen digital assets to your WordPress media library.
* Version: 2.6.5
* Version: 2.6.7
* Author: Masonite
* Author URI: https://www.masonite.com/
* License: GPL-2.0+
Expand Down

0 comments on commit 0041476

Please sign in to comment.