Skip to content

Commit

Permalink
Merge pull request #28 from threadi/feature/showProxyHintOnlyIfEnabled
Browse files Browse the repository at this point in the history
Feature/show proxy hint only if enabled
  • Loading branch information
threadi authored Apr 14, 2024
2 parents 2d0a202 + d8ca4b6 commit 865b6dc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 61 deletions.
33 changes: 24 additions & 9 deletions admin/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,31 @@ jQuery(document).ready(function($) {
nonce: emlJsVars.availability_nonce
},
success: function (response) {
if( response.length > 0 ) {
let response_json = JSON.parse(response);
let p = $("#eml_url_file_state");
if( response_json.state === 'error' ) {
p.html('<span class="dashicons dashicons-no-alt"></span> ' + response_json.message);
}
else {
p.html('<span class="dashicons dashicons-yes-alt"></span> ' + response_json.message);
}
let p = $("#eml_url_file_state");
let dialog_config = {
detail: {
className: 'eml',
title: emlJsVars.title_availability_refreshed,
texts: [
'<p>' + emlJsVars.text_not_available + '</p>'
],
buttons: [
{
'action': 'closeDialog();',
'variant': 'primary',
'text': emlJsVars.lbl_ok
},
]
}
}
if( response.state === 'error' ) {
p.html('<span class="dashicons dashicons-no-alt"></span> ' + response.message);
}
else {
p.html('<span class="dashicons dashicons-yes-alt"></span> ' + response.message);
dialog_config.detail.texts[0] = '<p>' + emlJsVars.text_is_available + '</p>';
}
eml_create_dialog( dialog_config );
}
});
});
Expand Down
19 changes: 17 additions & 2 deletions admin/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.eml_add_external_files_wrapper {
max-width: 400px;
border: 4px dashed #c3c4c7;
margin: 1em auto 0;
padding: 2em 0;
text-align: center;
}

Expand All @@ -10,7 +11,7 @@ select.eml-field-width {

.eml_settings_link {
display: inline-block;
margin-left: 1em;
margin-top: .5em;
text-decoration: none;
vertical-align: middle;
}
Expand Down Expand Up @@ -67,3 +68,17 @@ body.settings_page_eml_settings .nav-tab-help:before {
list-style: disc;
margin-left: 14px;
}

.misc-pub-external-file span {
vertical-align: middle;
}

#eml_recheck_availability {
padding: 0 1em;
vertical-align: middle;
}

#eml_recheck_availability:before {
position: relative;
left: -6px;
}
103 changes: 54 additions & 49 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,24 @@ function eml_admin_add_styles_and_js_admin(): void {
'eml-admin',
'emlJsVars',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'urls_nonce' => wp_create_nonce( 'eml-urls-upload-nonce' ),
'availability_nonce' => wp_create_nonce( 'eml-availability-check-nonce' ),
'dismiss_nonce' => wp_create_nonce( 'eml-dismiss-nonce' ),
'get_import_info_nonce' => wp_create_nonce( 'eml-url-upload-info-nonce' ),
'title_rate_us' => __( 'Rate this plugin', 'external-files-in-media-library' ),
'title_import_progress' => __( 'Import of URLs running', 'external-files-in-media-library' ),
'title_import_ended' => __( 'Import has been run', 'external-files-in-media-library' ),
'text_import_ended' => __( 'The import of given URLs has been run.', 'external-files-in-media-library' ),
'lbl_ok' => __( 'OK', 'external-files-in-media-library' ),
'lbl_cancel' => __( 'Cancel', 'external-files-in-media-library' ),
'text_urls_imported' => __( 'The following URLs has been imported successfully', 'external-files-in-media-library' ),
'text_urls_errors' => __( 'Following errors occurred', 'external-files-in-media-library' ),
'title_no_urls' => __( 'No URLs given', 'external-files-in-media-library' ),
'text_no_urls' => __( 'Please enter one or more URLs to import in the field.', 'external-files-in-media-library' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'urls_nonce' => wp_create_nonce( 'eml-urls-upload-nonce' ),
'availability_nonce' => wp_create_nonce( 'eml-availability-check-nonce' ),
'dismiss_nonce' => wp_create_nonce( 'eml-dismiss-nonce' ),
'get_import_info_nonce' => wp_create_nonce( 'eml-url-upload-info-nonce' ),
'title_rate_us' => __( 'Rate this plugin', 'external-files-in-media-library' ),
'title_import_progress' => __( 'Import of URLs running', 'external-files-in-media-library' ),
'title_import_ended' => __( 'Import has been run', 'external-files-in-media-library' ),
'text_import_ended' => __( 'The import of given URLs has been run.', 'external-files-in-media-library' ),
'lbl_ok' => __( 'OK', 'external-files-in-media-library' ),
'lbl_cancel' => __( 'Cancel', 'external-files-in-media-library' ),
'text_urls_imported' => __( 'The following URLs has been imported successfully', 'external-files-in-media-library' ),
'text_urls_errors' => __( 'Following errors occurred', 'external-files-in-media-library' ),
'title_no_urls' => __( 'No URLs given', 'external-files-in-media-library' ),
'text_no_urls' => __( 'Please enter one or more URLs to import in the field.', 'external-files-in-media-library' ),
'title_availability_refreshed' => __( 'Availability refreshed', 'external-files-in-media-library' ),
'text_not_available' => __( 'The file is NOT available.', 'external-files-in-media-library' ),
'text_is_available' => __( 'The file is available.', 'external-files-in-media-library' ),
)
);
}
Expand Down Expand Up @@ -368,7 +371,7 @@ function eml_admin_add_multi_form(): void {
// add link to settings for admin.
if ( current_user_can( 'manage_options' ) ) {
?>
<a href="<?php echo esc_url( helper::get_config_url() ); ?>" class="eml_settings_link"><span class="dashicons dashicons-admin-generic"></span></a>
<br><a href="<?php echo esc_url( helper::get_config_url() ); ?>" class="eml_settings_link" title="<?php echo esc_html__( 'Settings', 'external-files-in-media-library' ); ?>"><span class="dashicons dashicons-admin-generic"></span></a>
<?php
}
?>
Expand Down Expand Up @@ -706,45 +709,50 @@ function eml_admin_media_box(): void {
<p>
<?php echo esc_html__( 'File-URL:', 'external-files-in-media-library' ); ?><br><a href="<?php echo esc_url( $url ); ?>" title="<?php echo esc_attr( $url ); ?>"><?php echo esc_html( $url_to_show ); ?></a>
</p>
<?php
if ( $external_file_obj->get_availability() ) {
?>
<p id="eml_url_file_state"><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html__( 'File-URL is available.', 'external-files-in-media-library' ); ?></p>
<p>
<?php
} else {
$log_url = helper::get_log_url();
?>
<p id="eml_url_file_state"><span class="dashicons dashicons-no-alt"></span>
if ( $external_file_obj->get_availability() ) {
?>
<span id="eml_url_file_state"><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html__( 'File-URL is available.', 'external-files-in-media-library' ); ?></span>
<?php
} else {
$log_url = helper::get_log_url();
?>
<span id="eml_url_file_state"><span class="dashicons dashicons-no-alt"></span>
<?php
/* translators: %1$s will be replaced by the URL for the logs */
printf( esc_html__( 'File-URL is NOT available! Check <a href="%1$s">the log</a> for details.', 'external-files-in-media-library' ), esc_url( $log_url ) );
?>
</p>
<?php
}
?>
<a class="button" href="#" id="eml_recheck_availability"><?php echo esc_html__( 'Recheck availability', 'external-files-in-media-library' ); ?></a>
<p>
</span>
<?php
if ( false !== $external_file_obj->is_locally_saved() ) {
echo esc_html__( 'This file is local hostet.', 'external-files-in-media-library' );
} else {
echo esc_html__( 'This file is extern hostet.', 'external-files-in-media-library' );
}
?>
</p>
<p>
}
?>
<a class="button dashicons dashicons-image-rotate" href="#" id="eml_recheck_availability" title="<?php echo esc_html__( 'Recheck availability', 'external-files-in-media-library' ); ?>"></a>
</p>
<p><span class="dashicons dashicons-yes-alt"></span>
<?php
// TODO nur anzeigen wenn proxy aktiviert ist.
if ( false !== $external_file_obj->is_cached() ) {
echo esc_html__( 'This file is delivered through proxied cache.', 'external-files-in-media-library' );
if ( false !== $external_file_obj->is_locally_saved() ) {
echo esc_html__( 'File is local hostet.', 'external-files-in-media-library' );
} else {
echo esc_html__( 'This file is not cached in proxy.', 'external-files-in-media-library' );
echo esc_html__( 'File is extern hostet.', 'external-files-in-media-library' );
}
?>
</p>
</div>
<?php
<?php
if ( get_option( 'eml_proxy' ) ) {
?>
<p>
<?php
if ( false !== $external_file_obj->is_cached() ) {
echo '<span class="dashicons dashicons-yes-alt"></span> ' . esc_html__( 'File is delivered through proxied cache.', 'external-files-in-media-library' );
} else {
echo '<span class="dashicons dashicons-no-alt"></span> ' . esc_html__( 'File is not cached in proxy.', 'external-files-in-media-library' );
}
?>
</p>
</div>
<?php
}
} else {
?>
<div class="notice notice-error notice-alt inline">
Expand All @@ -762,7 +770,6 @@ function eml_admin_media_box(): void {
* Check file availability.
*
* @return void
* @noinspection PhpNoReturnAttributeCanBeAddedInspection
*/
function eml_admin_check_file_availability(): void {
// check nonce.
Expand Down Expand Up @@ -805,8 +812,7 @@ function eml_admin_check_file_availability(): void {
}

// send response as JSON.
echo wp_json_encode( $result );
wp_die();
wp_send_json( $result );
}
add_action( 'wp_ajax_eml_check_availability', 'eml_admin_check_file_availability', 10, 0 );

Expand Down Expand Up @@ -878,8 +884,7 @@ function eml_admin_settings_tab_general(): void {
}

?>
<!--suppress HtmlUnknownTarget -->
<form method="POST" action="options.php">
<form method="POST" action="<?php echo esc_url( get_admin_url() ); ?>options.php">
<?php
settings_fields( 'eml_settings_group' );
do_settings_sections( 'eml_settings_page' );
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Stable tag: 1.2.0

Add external files to your media library to link or embed them in your website. They will be integrated as if they were locally available.

== Description ==

Add external files to your media database to link or embed them in your website. The plugin integrates them into your WordPress as if they were locally available. So you can use the files in all places where the media library is used like all other files.
Add one or more files under Media > "Add new media file". You can use the files in all places where the media library is used.

The plugin checks for you automatically on a regular basis whether the external files you have stored are still available.

Expand Down Expand Up @@ -77,4 +79,7 @@ No, only public files can be used.

= 1.2.0 =
* New import dialog with progress and extended info about the import
* Show proxy hint on file only if proxy is enabled
* Optimized style for box with infos about external files
* Updated compatibility-flag for WordPress 6.5.2
* Updated dependencies

0 comments on commit 865b6dc

Please sign in to comment.