Version Description
Download this release
Release Info
| Developer | dd32-githubsync |
| Plugin | |
| Version | 3.4.4 |
| Comparing to | |
| See all releases | |
Code changes from version 3.4.3 to 3.4.4
- add-from-server.php +2 -2
- changelog.txt +3 -0
- class.add-from-server.php +18 -22
- readme.md +4 -1
add-from-server.php
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
namespace dd32\WordPress\AddFromServer;
|
| 3 |
/*
|
| 4 |
* Plugin Name: Add From Server
|
| 5 |
-
* Version: 3.4.
|
| 6 |
* Plugin URI: https://dd32.id.au/wordpress-plugins/add-from-server/
|
| 7 |
* Description: Plugin to allow the Media Manager to add files from the webservers filesystem.
|
| 8 |
* Author: Dion Hulse
|
|
@@ -16,7 +16,7 @@ if ( !is_admin() ) {
|
|
| 16 |
|
| 17 |
const MIN_WP = '5.4';
|
| 18 |
const MIN_PHP = '7.0';
|
| 19 |
-
const VERSION = '3.4.
|
| 20 |
|
| 21 |
// Dynamic constants must be define()'d.
|
| 22 |
define( __NAMESPACE__ . '\PLUGIN', plugin_basename( __FILE__ ) );
|
| 2 |
namespace dd32\WordPress\AddFromServer;
|
| 3 |
/*
|
| 4 |
* Plugin Name: Add From Server
|
| 5 |
+
* Version: 3.4.4
|
| 6 |
* Plugin URI: https://dd32.id.au/wordpress-plugins/add-from-server/
|
| 7 |
* Description: Plugin to allow the Media Manager to add files from the webservers filesystem.
|
| 8 |
* Author: Dion Hulse
|
| 16 |
|
| 17 |
const MIN_WP = '5.4';
|
| 18 |
const MIN_PHP = '7.0';
|
| 19 |
+
const VERSION = '3.4.4';
|
| 20 |
|
| 21 |
// Dynamic constants must be define()'d.
|
| 22 |
define( __NAMESPACE__ . '\PLUGIN', plugin_basename( __FILE__ ) );
|
changelog.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
= 3.4.3 =
|
| 2 |
* Better handling for `/` as the root path
|
| 3 |
* Better compatibility with certain WordPress docker images
|
| 1 |
+
= 3.4.4 =
|
| 2 |
+
* Simplify the date handling
|
| 3 |
+
|
| 4 |
= 3.4.3 =
|
| 5 |
* Better handling for `/` as the root path
|
| 6 |
* Better compatibility with certain WordPress docker images
|
class.add-from-server.php
CHANGED
|
@@ -157,8 +157,10 @@ class Plugin {
|
|
| 157 |
function handle_import_file( $file ) {
|
| 158 |
set_time_limit( 0 );
|
| 159 |
|
|
|
|
|
|
|
| 160 |
// Initially, Base it on the -current- time.
|
| 161 |
-
$time =
|
| 162 |
|
| 163 |
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
| 164 |
if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) {
|
|
@@ -172,7 +174,7 @@ class Plugin {
|
|
| 172 |
return new WP_Error( 'wrong_file_type', __( 'Sorry, this file type is not permitted for security reasons.', 'add-from-server' ) );
|
| 173 |
}
|
| 174 |
|
| 175 |
-
// Is the file
|
| 176 |
if ( preg_match( '|^' . preg_quote( wp_normalize_path( $uploads['basedir'] ), '|' ) . '(.*)$|i', $file, $mat ) ) {
|
| 177 |
|
| 178 |
$filename = basename( $file );
|
|
@@ -185,21 +187,15 @@ class Plugin {
|
|
| 185 |
return new WP_Error( 'file_exists', __( 'Sorry, that file already exists in the WordPress media library.', 'add-from-server' ) );
|
| 186 |
}
|
| 187 |
|
|
|
|
|
|
|
| 188 |
// Ok, Its in the uploads folder, But NOT in WordPress's media library.
|
| 189 |
-
if ( preg_match(
|
| 190 |
-
|
| 191 |
-
$
|
| 192 |
-
|
| 193 |
-
$month = $datemat[2];
|
| 194 |
-
|
| 195 |
-
// If the files datetime is set, and it's in the same region of upload directory, set the minute details to that too, else, override it.
|
| 196 |
-
if ( $time && date( 'Y-m', $time ) == "$year-$month" ) {
|
| 197 |
-
list($hour, $min, $sec, $day) = explode( ';', date( 'H;i;s;j', $time ) );
|
| 198 |
}
|
| 199 |
-
|
| 200 |
-
$time = mktime( $hour, $min, $sec, $month, $day, $year );
|
| 201 |
}
|
| 202 |
-
$time = gmdate( 'Y-m-d H:i:s', $time );
|
| 203 |
|
| 204 |
// A new time has been found! Get the new uploads folder:
|
| 205 |
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
|
@@ -298,14 +294,14 @@ class Plugin {
|
|
| 298 |
// Construct the attachment array
|
| 299 |
$attachment = [
|
| 300 |
'post_mime_type' => $type,
|
| 301 |
-
'guid'
|
| 302 |
-
'post_parent'
|
| 303 |
-
'post_title'
|
| 304 |
-
'post_name'
|
| 305 |
-
'post_content'
|
| 306 |
-
'post_excerpt'
|
| 307 |
-
'post_date'
|
| 308 |
-
'post_date_gmt'
|
| 309 |
];
|
| 310 |
|
| 311 |
$attachment = apply_filters( 'afs-import_details', $attachment, $file, 0, 'current' );
|
| 157 |
function handle_import_file( $file ) {
|
| 158 |
set_time_limit( 0 );
|
| 159 |
|
| 160 |
+
$file = wp_normalize_path( $file );
|
| 161 |
+
|
| 162 |
// Initially, Base it on the -current- time.
|
| 163 |
+
$time = time();
|
| 164 |
|
| 165 |
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
| 166 |
if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) {
|
| 174 |
return new WP_Error( 'wrong_file_type', __( 'Sorry, this file type is not permitted for security reasons.', 'add-from-server' ) );
|
| 175 |
}
|
| 176 |
|
| 177 |
+
// Is the file already in the uploads folder?
|
| 178 |
if ( preg_match( '|^' . preg_quote( wp_normalize_path( $uploads['basedir'] ), '|' ) . '(.*)$|i', $file, $mat ) ) {
|
| 179 |
|
| 180 |
$filename = basename( $file );
|
| 187 |
return new WP_Error( 'file_exists', __( 'Sorry, that file already exists in the WordPress media library.', 'add-from-server' ) );
|
| 188 |
}
|
| 189 |
|
| 190 |
+
$time = filemtime( $file ) ?: time();
|
| 191 |
+
|
| 192 |
// Ok, Its in the uploads folder, But NOT in WordPress's media library.
|
| 193 |
+
if ( preg_match( '|^/?(?P<Ym>(?P<year>\d{4})/(?P<month>\d{2}))|', dirname( $mat[1] ), $datemat ) ) {
|
| 194 |
+
// The file date and the folder it's in are mismatched. Set it to the date of the folder.
|
| 195 |
+
if ( date( 'Y/m', $time ) !== $datemat['Ym'] ) {
|
| 196 |
+
$time = mktime( 0, 0, 0, $datemat['month'], 1, $datemat['year'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
}
|
|
|
|
|
|
|
| 198 |
}
|
|
|
|
| 199 |
|
| 200 |
// A new time has been found! Get the new uploads folder:
|
| 201 |
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
| 294 |
// Construct the attachment array
|
| 295 |
$attachment = [
|
| 296 |
'post_mime_type' => $type,
|
| 297 |
+
'guid' => $url,
|
| 298 |
+
'post_parent' => 0,
|
| 299 |
+
'post_title' => $title,
|
| 300 |
+
'post_name' => $title,
|
| 301 |
+
'post_content' => $content,
|
| 302 |
+
'post_excerpt' => $excerpt,
|
| 303 |
+
'post_date' => gmdate( 'Y-m-d H:i:s', $time ),
|
| 304 |
+
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $time ),
|
| 305 |
];
|
| 306 |
|
| 307 |
$attachment = apply_filters( 'afs-import_details', $attachment, $file, 0, 'current' );
|
readme.md
CHANGED
|
@@ -5,7 +5,7 @@ Add From Server
|
|
| 5 |
* Requires at least: 5.4
|
| 6 |
* Tested up to: 5.5
|
| 7 |
* Requires PHP: 7.0
|
| 8 |
-
* Stable tag: 3.4.
|
| 9 |
|
| 10 |
Add From Server is designed to help ease the pain of bad web hosts, allowing you to upload files via FTP or SSH and later import them into WordPress.
|
| 11 |
|
|
@@ -32,6 +32,9 @@ https://developer.wordpress.org/cli/commands/media/import/
|
|
| 32 |
|
| 33 |
## Changelog
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
### 3.4.3
|
| 36 |
* Better handling for `/` as the root path
|
| 37 |
* Better compatibility with certain WordPress docker images
|
| 5 |
* Requires at least: 5.4
|
| 6 |
* Tested up to: 5.5
|
| 7 |
* Requires PHP: 7.0
|
| 8 |
+
* Stable tag: 3.4.4
|
| 9 |
|
| 10 |
Add From Server is designed to help ease the pain of bad web hosts, allowing you to upload files via FTP or SSH and later import them into WordPress.
|
| 11 |
|
| 32 |
|
| 33 |
## Changelog
|
| 34 |
|
| 35 |
+
### 3.4.4
|
| 36 |
+
* Simplify the date handling
|
| 37 |
+
|
| 38 |
### 3.4.3
|
| 39 |
* Better handling for `/` as the root path
|
| 40 |
* Better compatibility with certain WordPress docker images
|
