Version Description
- Fix plugin activation
Download this release
Release Info
Developer | dd32 |
Plugin | Add From Server |
Version | 3.3.1 |
Comparing to | |
See all releases |
Version 3.3.1
- add-from-server.css +9 -0
- add-from-server.php +26 -0
- changelog.txt +95 -0
- class.add-from-server-settings.php +118 -0
- class.add-from-server.php +681 -0
- old-versions.php +36 -0
- readme.txt +48 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
add-from-server.css
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.frmsvr_wrap .widefat tbody tr.doesnt-meet-guidelines,
|
2 |
+
.frmsvr_wrap .widefat tbody tr.unreadable {
|
3 |
+
background-color: #FFE8EE;
|
4 |
+
}
|
5 |
+
|
6 |
+
.frmsvr_wrap fieldset {
|
7 |
+
padding: 5px;
|
8 |
+
margin-top: 0.7em;
|
9 |
+
}
|
add-from-server.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Plugin Name: Add From Server
|
4 |
+
* Version: 3.3.1
|
5 |
+
* Plugin URI: https://dd32.id.au/wordpress-plugins/add-from-server/
|
6 |
+
* Description: Plugin to allow the Media Manager to add files from the webservers filesystem. <strong>Note:</strong> All files are copied to the uploads directory.
|
7 |
+
* Author: Dion Hulse
|
8 |
+
* Author URI: https://dd32.id.au/
|
9 |
+
* Text Domain: add-from-server
|
10 |
+
*/
|
11 |
+
|
12 |
+
if ( !is_admin() ) {
|
13 |
+
return;
|
14 |
+
}
|
15 |
+
|
16 |
+
define( 'ADD_FROM_SERVER_WP_REQUIREMENT', '4.0' );
|
17 |
+
define( 'ADD_FROM_SERVER_PHP_REQUIREMENT', '5.4' );
|
18 |
+
|
19 |
+
// Old versions of WordPress or PHP
|
20 |
+
if ( version_compare( $GLOBALS['wp_version'], ADD_FROM_SERVER_WP_REQUIREMENT, '<' ) || version_compare( phpversion(), ADD_FROM_SERVER_PHP_REQUIREMENT, '<' ) ) {
|
21 |
+
include dirname( __FILE__ ) . '/old-versions.php';
|
22 |
+
} else {
|
23 |
+
include __DIR__ . '/class.add-from-server.php';
|
24 |
+
}
|
25 |
+
|
26 |
+
$add_from_server = new Add_From_Server( plugin_basename( __FILE__ ) );
|
changelog.txt
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
= 3.3.1 =
|
2 |
+
* Fix plugin activation
|
3 |
+
|
4 |
+
= 3.3 =
|
5 |
+
* The plugin now requires WordPress 4.0 and PHP 5.4 as a minumum requirement.
|
6 |
+
* Updated to use WordPress.org translation system, please submit translations through https://translate.wordpress.org/projects/wp-plugins/add-from-server/stable
|
7 |
+
* Updated to WordPress 4.3 styles
|
8 |
+
|
9 |
+
= 3.2.0.4 =
|
10 |
+
* Fix for a PHP Warning shown under certain hosting configurations, "headers already sent by (output started at .../add-from-server/class.add-from-server.php:1357)"
|
11 |
+
* WordPress.org Translation compatibility
|
12 |
+
|
13 |
+
= 3.2.0.3 =
|
14 |
+
* PHP 5.4 compatibility
|
15 |
+
* Special characters in URL fixes
|
16 |
+
* Japanese Translations from Naoko Takano ( http://en.naoko.cc/ )
|
17 |
+
|
18 |
+
= 3.2.0.2 =
|
19 |
+
* Fix: Translations not loaded early enough for menu items.
|
20 |
+
|
21 |
+
= 3.2.0.1 =
|
22 |
+
* Fix: Incorrect GUID on imported items in subdir of uploads folder
|
23 |
+
* Fix: Not all items would correctly trigger the already-imported error
|
24 |
+
|
25 |
+
= 3.2.0 =
|
26 |
+
* For Pre-3.2 changelog, Please see http://plugins.svn.wordpress.org/add-from-server/tags/2.3/readme.txt
|
27 |
+
* Cleanup, Now requires WordPress 3.2+
|
28 |
+
* Now has an options panel to control who is allowed to import files
|
29 |
+
* Now has the option to specify what the base directory is for file imports (ie. allows you to prevent users access to non-public directories)
|
30 |
+
* Versioning changes - This plugin will from now use the earliest version of WordPress it supports. 3.2 requires 3.2, 3.2.0.1 is a point release which requires 3.2. 3.3.4 will require WP 3.3.4 etc. May seem a little weird, but you'll get used to it, bigger numbers are still better :)
|
31 |
+
|
32 |
+
= 2.3 =
|
33 |
+
* Quick 3.0 compatibility release
|
34 |
+
* Removed Deprecated notices, Fixed a few other warnings occasionally
|
35 |
+
* GUID now a valid url when % is included in the filename
|
36 |
+
* Requires WordPress 3.0 now.
|
37 |
+
|
38 |
+
= 2.x =
|
39 |
+
* French update from Denis Rebaud
|
40 |
+
|
41 |
+
= 2.2.1 =
|
42 |
+
* Remove svn:externals, The WordPress .zip packager does NOT like making peoples life easier when you've got multiple plugins.
|
43 |
+
|
44 |
+
= 2.2 =
|
45 |
+
* Slight error warning changes
|
46 |
+
* WARNING: 2.8.5/2.9 compatibility: ALL users who can upload files will now have access to the Add From Server functionality, This is due to security changes in wordpress removing the unfiltered uploads functionality. This has the side effect that you cannot upload ALL types of files too, See the FAQ for some more info.
|
47 |
+
* Re-ordered changelog for 2.8 changelog compatibility.
|
48 |
+
|
49 |
+
= 2.1 =
|
50 |
+
* Introduce QuickJump
|
51 |
+
* Fix bugs related to the Admin navigation disapearing
|
52 |
+
* Fix bugs related to hints showing up linking to the wrong page
|
53 |
+
* Do not show the Inline uploaders tabs in the normal uploader :)
|
54 |
+
* Fix 2.8.1's plugin security mashes..
|
55 |
+
|
56 |
+
= 2.0.1 =
|
57 |
+
* Russian Translation from Lecactus
|
58 |
+
|
59 |
+
= 2.0 =
|
60 |
+
* Requires WordPress 2.7+ (From now on, My Plugins will only be supported for the current stable branch)
|
61 |
+
* WP2.7 SSL Support
|
62 |
+
* WP2.7 checkbox support
|
63 |
+
* WP2.7 upload modifications
|
64 |
+
* WP2.7 Styling
|
65 |
+
* Files/folders are sorted by name
|
66 |
+
* Update Notification changelogs (On the plugins page)
|
67 |
+
* Completely rewritten, Hopefully this'll fix some long-time bugs which have affected some.
|
68 |
+
* Persion translation from sourena
|
69 |
+
* Italian translation from Stafano
|
70 |
+
|
71 |
+
= 1.4 =
|
72 |
+
* German Translation
|
73 |
+
* More stuffing around with the checkbox that doesnt work for anyone, yet works on every test system i've tried
|
74 |
+
* Set the date on imported files to that of their uploads folder
|
75 |
+
|
76 |
+
= 1.3.2 =
|
77 |
+
* French translation changes from Ozh & Olivier
|
78 |
+
* Fixed the checkbox list for certain unknown browsers.
|
79 |
+
|
80 |
+
= 1.3 =
|
81 |
+
* Internationalisation; French translation
|
82 |
+
* Internationalisation; Spanish translation
|
83 |
+
* Checkbox select all
|
84 |
+
* Import into non-post attachment
|
85 |
+
|
86 |
+
= 1.2 =
|
87 |
+
* Fixed filename oddness including old directory names
|
88 |
+
* Added a check to see if the file exists in the Media library allready
|
89 |
+
* Added a check to see if the file is allready in the uploads folder before importing, and if so, simply add it to the database, do not mash the filesystem
|
90 |
+
|
91 |
+
= 1.1 =
|
92 |
+
* Fixed a bug which causes the original import file to be deleted upon removing from the media library, The file in /uploads/2008/03/ remains however. Will now delete the file in the uploads folder instead of the original imported file, However, Be warned, files previously imported WILL remain as they are, and the original import file will be deleted(if you delete from the media library)
|
93 |
+
|
94 |
+
= 1.0 =
|
95 |
+
* Initial Release
|
class.add-from-server-settings.php
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Add_From_Server_Settings {
|
4 |
+
var $main; // main Add From Server instance.
|
5 |
+
|
6 |
+
function __construct($afs) {
|
7 |
+
$this->main = $afs;
|
8 |
+
}
|
9 |
+
|
10 |
+
function render() {
|
11 |
+
echo '<div class="wrap">';
|
12 |
+
screen_icon( 'options-general' );
|
13 |
+
echo '<h1>' . __( 'Add From Server', 'add-from-server' ) . '</h1>';
|
14 |
+
echo '<form method="post" action="options.php">';
|
15 |
+
|
16 |
+
settings_fields( 'add_from_server' );
|
17 |
+
|
18 |
+
$uac = get_option( 'frmsvr_uac', 'allusers' );
|
19 |
+
$root = $this->main->get_root( 'raw' );
|
20 |
+
?>
|
21 |
+
<table class="form-table">
|
22 |
+
<tr valign="top">
|
23 |
+
<th scope="row"><?php _e( 'User Access Control', 'add-from-server' ); ?></th>
|
24 |
+
|
25 |
+
<td>
|
26 |
+
<fieldset>
|
27 |
+
<legend class="screen-reader-text">
|
28 |
+
<span><?php _e( 'User Access Control', 'add-from-server' ); ?></span></legend>
|
29 |
+
<label for="frmsvr_uac-allusers">
|
30 |
+
<input name="frmsvr_uac" type="radio" id="frmsvr_uac-allusers"
|
31 |
+
value="allusers" <?php checked( $uac, 'allusers' ); ?> />
|
32 |
+
<?php _e( 'All users with the ability to upload files', 'add-from-server' ); ?>
|
33 |
+
</label>
|
34 |
+
<br/>
|
35 |
+
<label for="frmsvr_uac-role">
|
36 |
+
<input name="frmsvr_uac" type="radio" id="frmsvr_uac-role"
|
37 |
+
value="role" <?php checked( $uac, 'role' ); ?> />
|
38 |
+
<?php _e( 'Any user with the ability to upload files in the following roles', 'add-from-server' ); ?>
|
39 |
+
</label>
|
40 |
+
<?php
|
41 |
+
$current_roles = (array)get_option( 'frmsvr_uac_role', array() );
|
42 |
+
foreach ( get_editable_roles() as $role => $details ) {
|
43 |
+
if ( !isset($details['capabilities']['upload_files']) || !$details['capabilities']['upload_files'] )
|
44 |
+
continue;
|
45 |
+
?>
|
46 |
+
<label for="frmsvr_uac-role-<?php echo esc_attr( $role ); ?>">
|
47 |
+
<input type="checkbox" name="frmsvr_uac_role[]"
|
48 |
+
id="frmsvr_uac-role-<?php echo esc_attr( $role ); ?>"
|
49 |
+
value="<?php echo esc_attr( $role ); ?>" <?php checked( in_array( $role, $current_roles ) ); ?> />
|
50 |
+
<?php echo translate_user_role( $details['name'] ); ?>
|
51 |
+
</label>
|
52 |
+
<?php
|
53 |
+
}
|
54 |
+
?>
|
55 |
+
<br/>
|
56 |
+
<label for="frmsvr_uac-listusers">
|
57 |
+
<input name="frmsvr_uac" type="radio" id="frmsvr_uac-listusers"
|
58 |
+
value="listusers" <?php checked( $uac, 'listusers' ); ?> />
|
59 |
+
<?php _e( 'Any users with the ability to upload files listed below', 'add-from-server' ); ?>
|
60 |
+
</label>
|
61 |
+
<br/>
|
62 |
+
<textarea rows="5" cols="20" name="frmsvr_uac_users"
|
63 |
+
class="large-text code"><?php echo esc_textarea( get_option( 'frmsvr_uac_users', 'admin' ) ); ?></textarea>
|
64 |
+
<br/>
|
65 |
+
<small><em><?php _e( "List the user login's one per line", 'add-from-server' ); ?></em></small>
|
66 |
+
</fieldset>
|
67 |
+
</td>
|
68 |
+
</tr>
|
69 |
+
<tr valign="top">
|
70 |
+
<th scope="row"><?php _e( 'Root Directory', 'add-from-server' ); ?></th>
|
71 |
+
|
72 |
+
<td>
|
73 |
+
<fieldset>
|
74 |
+
<legend class="screen-reader-text">
|
75 |
+
<span><?php _e( 'Root Directory', 'add-from-server' ); ?></span></legend>
|
76 |
+
<label for="frmsvr_root-default">
|
77 |
+
<?php
|
78 |
+
$default_root = '/';
|
79 |
+
if ( preg_match( '!(\w:)!', __FILE__, $matches ) )
|
80 |
+
$default_root = strtolower( $matches[1] );
|
81 |
+
?>
|
82 |
+
<input name="frmsvr_root" type="radio" id="frmsvr_root-default"
|
83 |
+
value="<?php echo esc_attr( $default_root ); ?>" <?php checked( $root, $default_root ); ?> />
|
84 |
+
<?php _e( 'Do not lock browsing to a specific directory', 'add-from-server' ); ?>
|
85 |
+
</label>
|
86 |
+
<br/>
|
87 |
+
<label for="frmsvr_root-specify">
|
88 |
+
<input name="frmsvr_root" type="radio" id="frmsvr_root-specify"
|
89 |
+
value="specific" <?php checked( $root != $default_root ); ?> />
|
90 |
+
<?php _e( 'Lock browsing to the directory specified below', 'add-from-server' ); ?>
|
91 |
+
</label>
|
92 |
+
<br/>
|
93 |
+
<input type="text" name="frmsvr_root-specified" id="frmsvr_root-specify-specified"
|
94 |
+
class="large-text code"
|
95 |
+
value="<?php echo esc_attr( str_replace( '/', DIRECTORY_SEPARATOR, $root ) . (strlen( $root ) > 1 ? DIRECTORY_SEPARATOR : '') ); ?>"/>
|
96 |
+
<br/>
|
97 |
+
<small><em><?php
|
98 |
+
printf( __( 'You may use placeholders such as %s and %s in the path.', 'add-from-server' ), '%username%', '%role%' );
|
99 |
+
echo ' ';
|
100 |
+
printf( __( 'For reference, Your WordPress Root path is: <code>%s</code>', 'add-from-server' ), ABSPATH );
|
101 |
+
?>
|
102 |
+
</em></small>
|
103 |
+
</fieldset>
|
104 |
+
</td>
|
105 |
+
</tr>
|
106 |
+
</table>
|
107 |
+
<script type="text/javascript">
|
108 |
+
jQuery('#frmsvr_root-specify-specified').change(function () {
|
109 |
+
jQuery('#frmsvr_root-specify').attr('checked', 'checked');
|
110 |
+
});
|
111 |
+
</script>
|
112 |
+
<?php
|
113 |
+
submit_button( __( 'Save Changes', 'add-from-server' ), 'primary', 'submit' );
|
114 |
+
echo '</form>';
|
115 |
+
$this->main->language_notice( ( get_locale() !== 'en_US' ) );
|
116 |
+
echo '</div>';
|
117 |
+
}
|
118 |
+
}
|
class.add-from-server.php
ADDED
@@ -0,0 +1,681 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Add_From_Server {
|
4 |
+
|
5 |
+
var $version = '3.3.1';
|
6 |
+
var $basename = '';
|
7 |
+
|
8 |
+
function __construct( $plugin ) {
|
9 |
+
$this->basename = $plugin;
|
10 |
+
// Register general hooks.
|
11 |
+
add_action( 'init', array( $this, 'load_translations' ) ); // must run before admin_menu
|
12 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
13 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
14 |
+
}
|
15 |
+
|
16 |
+
function load_translations() {
|
17 |
+
// Load any translation files needed:
|
18 |
+
load_plugin_textdomain( 'add-from-server' );
|
19 |
+
}
|
20 |
+
|
21 |
+
function admin_init() {
|
22 |
+
// Register our JS & CSS
|
23 |
+
wp_register_style( 'add-from-server', plugins_url( '/add-from-server.css', __FILE__ ), array(), $this->version );
|
24 |
+
|
25 |
+
// Enqueue JS & CSS
|
26 |
+
add_action( 'load-media_page_add-from-server', array( $this, 'add_styles' ) );
|
27 |
+
add_action( 'media_upload_server', array( $this, 'add_styles' ) );
|
28 |
+
|
29 |
+
add_filter( 'plugin_action_links_' . $this->basename, array( $this, 'add_configure_link' ) );
|
30 |
+
|
31 |
+
if ( $this->user_allowed() ) {
|
32 |
+
// Add actions/filters
|
33 |
+
add_filter( 'media_upload_tabs', array( $this, 'tabs' ) );
|
34 |
+
add_action( 'media_upload_server', array( $this, 'tab_handler' ) );
|
35 |
+
}
|
36 |
+
|
37 |
+
// Register our settings:
|
38 |
+
register_setting( 'add_from_server', 'frmsvr_root', array( $this, 'sanitize_option_root' ) );
|
39 |
+
// register_setting('add-from-server', 'frmsvr_last_folder');
|
40 |
+
register_setting( 'add_from_server', 'frmsvr_uac' );
|
41 |
+
register_setting( 'add_from_server', 'frmsvr_uac_users' );
|
42 |
+
register_setting( 'add_from_server', 'frmsvr_uac_role' );
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
function admin_menu() {
|
47 |
+
if ( $this->user_allowed() ) {
|
48 |
+
add_media_page( __( 'Add From Server', 'add-from-server' ), __( 'Add From Server', 'add-from-server' ), 'read', 'add-from-server', array( $this, 'menu_page' ) );
|
49 |
+
}
|
50 |
+
add_options_page( __( 'Add From Server', 'add-from-server' ), __( 'Add From Server', 'add-from-server' ), 'manage_options', 'add-from-server-settings', array( $this, 'options_page' ) );
|
51 |
+
}
|
52 |
+
|
53 |
+
function add_configure_link( $_links ) {
|
54 |
+
$links = array();
|
55 |
+
if ( $this->user_allowed() ) {
|
56 |
+
$links[] = '<a href="' . admin_url( 'upload.php?page=add-from-server' ) . '">' . __( 'Import Files', 'add-from-server' ) . '</a>';
|
57 |
+
}
|
58 |
+
if ( current_user_can( 'manage_options' ) ) {
|
59 |
+
$links[] = '<a href="' . admin_url( 'options-general.php?page=add-from-server-settings' ) . '">' . __( 'Options', 'add-from-server' ) . '</a>';
|
60 |
+
}
|
61 |
+
|
62 |
+
return array_merge( $links, $_links );
|
63 |
+
}
|
64 |
+
|
65 |
+
// Add a tab to the media uploader:
|
66 |
+
function tabs( $tabs ) {
|
67 |
+
if ( $this->user_allowed() ) {
|
68 |
+
$tabs['server'] = __( 'Add From Server', 'add-from-server' );
|
69 |
+
}
|
70 |
+
return $tabs;
|
71 |
+
}
|
72 |
+
|
73 |
+
function add_styles() {
|
74 |
+
// Enqueue support files.
|
75 |
+
if ( 'media_upload_server' == current_filter() ) {
|
76 |
+
wp_enqueue_style( 'media' );
|
77 |
+
}
|
78 |
+
wp_enqueue_style( 'add-from-server' );
|
79 |
+
}
|
80 |
+
|
81 |
+
// Handle the actual page:
|
82 |
+
function tab_handler() {
|
83 |
+
global $body_id;
|
84 |
+
if ( !$this->user_allowed() ) {
|
85 |
+
return;
|
86 |
+
}
|
87 |
+
|
88 |
+
$body_id = 'media-upload';
|
89 |
+
iframe_header( __( 'Add From Server', 'add-from-server' ) );
|
90 |
+
$this->handle_imports();
|
91 |
+
$this->main_content();
|
92 |
+
iframe_footer();
|
93 |
+
}
|
94 |
+
|
95 |
+
function menu_page() {
|
96 |
+
if ( !$this->user_allowed() ) {
|
97 |
+
return;
|
98 |
+
}
|
99 |
+
|
100 |
+
// Handle any imports:
|
101 |
+
$this->handle_imports();
|
102 |
+
|
103 |
+
echo '<div class="wrap">';
|
104 |
+
echo '<h1>' . __( 'Add From Server', 'add-from-server' ) . '</h1>';
|
105 |
+
$this->main_content();
|
106 |
+
echo '</div>';
|
107 |
+
}
|
108 |
+
|
109 |
+
function options_page() {
|
110 |
+
if ( !current_user_can( 'manage_options' ) ) {
|
111 |
+
return;
|
112 |
+
}
|
113 |
+
|
114 |
+
include __DIR__ . '/class.add-from-server-settings.php';
|
115 |
+
$settings = new Add_From_Server_Settings( $this );
|
116 |
+
$settings->render();
|
117 |
+
}
|
118 |
+
|
119 |
+
function get_root( $context = 'use' ) {
|
120 |
+
static $static_root = null;
|
121 |
+
if ( $static_root )
|
122 |
+
return $static_root;
|
123 |
+
|
124 |
+
$root = get_option( 'frmsvr_root', false );
|
125 |
+
if ( strpos( $root, '%' ) !== false && 'raw' != $context ) {
|
126 |
+
$user = wp_get_current_user();
|
127 |
+
|
128 |
+
$root = str_replace( '%username%', $user->user_login, $root );
|
129 |
+
$root = str_replace( '%role%', $user->roles[0], $root );
|
130 |
+
}
|
131 |
+
if ( ! $root ) {
|
132 |
+
if ( '/' == substr( __FILE__, 0, 1 ) ) {
|
133 |
+
$root = '/';
|
134 |
+
} elseif ( preg_match( '!^[a-zA-Z]:!', __FILE__, $root_win_match ) ) {
|
135 |
+
$root = $root_win_match[1];
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
if ( strlen( $root ) > 1 ) {
|
140 |
+
$root = untrailingslashit( $root );
|
141 |
+
}
|
142 |
+
|
143 |
+
return $root;
|
144 |
+
}
|
145 |
+
|
146 |
+
function user_allowed() {
|
147 |
+
if ( !current_user_can( 'upload_files' ) ) {
|
148 |
+
return false;
|
149 |
+
}
|
150 |
+
|
151 |
+
switch ( get_option( 'frmsvr_uac', 'allusers' ) ) {
|
152 |
+
default:
|
153 |
+
case 'allusers':
|
154 |
+
return true;
|
155 |
+
|
156 |
+
case 'role':
|
157 |
+
$user = wp_get_current_user();
|
158 |
+
$roles = $user->roles;
|
159 |
+
$allowed_roles = get_option( 'frmsvr_uac_role', array() );
|
160 |
+
foreach ( $roles as $r ) {
|
161 |
+
if ( in_array( $r, $allowed_roles ) )
|
162 |
+
return true;
|
163 |
+
}
|
164 |
+
return false;
|
165 |
+
|
166 |
+
case 'listusers':
|
167 |
+
$user = wp_get_current_user();
|
168 |
+
$allowed_users = explode( "\n", get_option( 'frmsvr_uac_users', '' ) );
|
169 |
+
$allowed_users = array_map( 'trim', $allowed_users );
|
170 |
+
$allowed_users = array_filter( $allowed_users );
|
171 |
+
return in_array( $user->user_login, $allowed_users );
|
172 |
+
}
|
173 |
+
return false;
|
174 |
+
}
|
175 |
+
|
176 |
+
function sanitize_option_root($input) {
|
177 |
+
$_input = $input;
|
178 |
+
if ( 'specific' == $input ) {
|
179 |
+
$input = wp_unslash( $_POST['frmsvr_root-specified'] );
|
180 |
+
}
|
181 |
+
|
182 |
+
if ( !$this->validate_option_root( $input ) ) {
|
183 |
+
$input = get_option( 'frmsvr_root' );
|
184 |
+
}
|
185 |
+
|
186 |
+
$input = wp_normalize_path( $input );
|
187 |
+
|
188 |
+
return $input;
|
189 |
+
}
|
190 |
+
|
191 |
+
function validate_option_root($o) {
|
192 |
+
if ( strpos( $o, '%' ) !== false ) {
|
193 |
+
// Ensure only valid placeholders are used:
|
194 |
+
if ( preg_match_all( '!%(.*?)%!', $o, $placeholders ) ) {
|
195 |
+
$valid_ph = array( 'username', 'role' );
|
196 |
+
foreach ( $placeholders[1] as $ph ) {
|
197 |
+
if ( !in_array( $ph, $valid_ph ) ) {
|
198 |
+
add_settings_error( 'general', 'update_failed', sprintf( __( 'The placeholder %s is not valid in the root path.', 'add-from-server' ), '%' . $ph . '%' ), 'error' );
|
199 |
+
return false;
|
200 |
+
}
|
201 |
+
}
|
202 |
+
return true;
|
203 |
+
}
|
204 |
+
}
|
205 |
+
if ( !is_dir( $o ) || !is_readable( $o ) ) {
|
206 |
+
add_settings_error( 'general', 'update_failed', __( 'The root path specified could not be read.', 'add-from-server' ), 'error' );
|
207 |
+
return false;
|
208 |
+
}
|
209 |
+
return true;
|
210 |
+
}
|
211 |
+
|
212 |
+
// Handle the imports
|
213 |
+
function handle_imports() {
|
214 |
+
|
215 |
+
if ( !empty($_POST['files']) && !empty($_POST['cwd']) ) {
|
216 |
+
|
217 |
+
$files = wp_unslash( $_POST['files'] );
|
218 |
+
|
219 |
+
$cwd = trailingslashit( wp_unslash( $_POST['cwd'] ) );
|
220 |
+
$post_id = isset($_REQUEST['post_id']) ? intval( $_REQUEST['post_id'] ) : 0;
|
221 |
+
$import_date = isset($_REQUEST['import-date']) ? $_REQUEST['import-date'] : 'current';
|
222 |
+
|
223 |
+
$import_to_gallery = isset($_POST['gallery']) && 'on' == $_POST['gallery'];
|
224 |
+
if ( !$import_to_gallery && !isset($_REQUEST['cwd']) ) {
|
225 |
+
$import_to_gallery = true; // cwd should always be set, if it's not, and neither is gallery, this must be the first page load.
|
226 |
+
}
|
227 |
+
|
228 |
+
if ( !$import_to_gallery ) {
|
229 |
+
$post_id = 0;
|
230 |
+
}
|
231 |
+
|
232 |
+
flush();
|
233 |
+
wp_ob_end_flush_all();
|
234 |
+
|
235 |
+
foreach ( (array)$files as $file ) {
|
236 |
+
$filename = $cwd . $file;
|
237 |
+
$id = $this->handle_import_file( $filename, $post_id, $import_date );
|
238 |
+
if ( is_wp_error( $id ) ) {
|
239 |
+
echo '<div class="updated error"><p>' . sprintf( __( '<em>%s</em> was <strong>not</strong> imported due to an error: %s', 'add-from-server' ), esc_html( $file ), $id->get_error_message() ) . '</p></div>';
|
240 |
+
} else {
|
241 |
+
echo '<div class="updated"><p>' . sprintf( __( '<em>%s</em> has been added to Media library', 'add-from-server' ), esc_html( $file ) ) . '</p></div>';
|
242 |
+
}
|
243 |
+
flush();
|
244 |
+
wp_ob_end_flush_all();
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
// Handle an individual file import.
|
250 |
+
function handle_import_file( $file, $post_id = 0, $import_date = 'current' ) {
|
251 |
+
set_time_limit( 0 );
|
252 |
+
|
253 |
+
// Initially, Base it on the -current- time.
|
254 |
+
$time = current_time( 'mysql', 1 );
|
255 |
+
// Next, If it's post to base the upload off:
|
256 |
+
if ( 'post' == $import_date && $post_id > 0 ) {
|
257 |
+
$post = get_post( $post_id );
|
258 |
+
if ( $post && substr( $post->post_date_gmt, 0, 4 ) > 0 ) {
|
259 |
+
$time = $post->post_date_gmt;
|
260 |
+
}
|
261 |
+
} elseif ( 'file' == $import_date ) {
|
262 |
+
$time = gmdate( 'Y-m-d H:i:s', @filemtime( $file ) );
|
263 |
+
}
|
264 |
+
|
265 |
+
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
266 |
+
if ( !(($uploads = wp_upload_dir( $time )) && false === $uploads['error']) ) {
|
267 |
+
return new WP_Error( 'upload_error', $uploads['error'] );
|
268 |
+
}
|
269 |
+
|
270 |
+
$wp_filetype = wp_check_filetype( $file, null );
|
271 |
+
|
272 |
+
extract( $wp_filetype );
|
273 |
+
|
274 |
+
if ( (!$type || !$ext) && !current_user_can( 'unfiltered_upload' ) ) {
|
275 |
+
return new WP_Error( 'wrong_file_type', __( 'Sorry, this file type is not permitted for security reasons.', 'add-from-server' ) );
|
276 |
+
}
|
277 |
+
|
278 |
+
// Is the file allready in the uploads folder?
|
279 |
+
if ( preg_match( '|^' . preg_quote( wp_normalize_path( $uploads['basedir'] ), '|' ) . '(.*)$|i', $file, $mat ) ) {
|
280 |
+
|
281 |
+
$filename = basename( $file );
|
282 |
+
$new_file = $file;
|
283 |
+
|
284 |
+
$url = $uploads['baseurl'] . $mat[1];
|
285 |
+
|
286 |
+
$attachment = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attached_file', 'meta_value' => ltrim( $mat[1], '/' ) ) );
|
287 |
+
if ( !empty($attachment) ) {
|
288 |
+
return new WP_Error( 'file_exists', __( 'Sorry, That file already exists in the WordPress media library.', 'add-from-server' ) );
|
289 |
+
}
|
290 |
+
|
291 |
+
// Ok, Its in the uploads folder, But NOT in WordPress's media library.
|
292 |
+
if ( 'file' == $import_date ) {
|
293 |
+
$time = @filemtime( $file );
|
294 |
+
if ( preg_match( "|(\d+)/(\d+)|", $mat[1], $datemat ) ) { // So lets set the date of the import to the date folder its in, IF its in a date folder.
|
295 |
+
$hour = $min = $sec = 0;
|
296 |
+
$day = 1;
|
297 |
+
$year = $datemat[1];
|
298 |
+
$month = $datemat[2];
|
299 |
+
|
300 |
+
// 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.
|
301 |
+
if ( $time && date( 'Y-m', $time ) == "$year-$month" ) {
|
302 |
+
list($hour, $min, $sec, $day) = explode( ';', date( 'H;i;s;j', $time ) );
|
303 |
+
}
|
304 |
+
|
305 |
+
$time = mktime( $hour, $min, $sec, $month, $day, $year );
|
306 |
+
}
|
307 |
+
$time = gmdate( 'Y-m-d H:i:s', $time );
|
308 |
+
|
309 |
+
// A new time has been found! Get the new uploads folder:
|
310 |
+
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
311 |
+
if ( !(($uploads = wp_upload_dir( $time )) && false === $uploads['error']) ) {
|
312 |
+
return new WP_Error( 'upload_error', $uploads['error'] );
|
313 |
+
}
|
314 |
+
$url = $uploads['baseurl'] . $mat[1];
|
315 |
+
}
|
316 |
+
} else {
|
317 |
+
$filename = wp_unique_filename( $uploads['path'], basename( $file ) );
|
318 |
+
|
319 |
+
// copy the file to the uploads dir
|
320 |
+
$new_file = $uploads['path'] . '/' . $filename;
|
321 |
+
if ( false === @copy( $file, $new_file ) )
|
322 |
+
return new WP_Error( 'upload_error', sprintf( __( 'The selected file could not be copied to %s.', 'add-from-server' ), $uploads['path'] ) );
|
323 |
+
|
324 |
+
// Set correct file permissions
|
325 |
+
$stat = stat( dirname( $new_file ) );
|
326 |
+
$perms = $stat['mode'] & 0000666;
|
327 |
+
@ chmod( $new_file, $perms );
|
328 |
+
// Compute the URL
|
329 |
+
$url = $uploads['url'] . '/' . $filename;
|
330 |
+
|
331 |
+
if ( 'file' == $import_date ) {
|
332 |
+
$time = gmdate( 'Y-m-d H:i:s', @filemtime( $file ) );
|
333 |
+
}
|
334 |
+
}
|
335 |
+
|
336 |
+
// Apply upload filters
|
337 |
+
$return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
|
338 |
+
$new_file = $return['file'];
|
339 |
+
$url = $return['url'];
|
340 |
+
$type = $return['type'];
|
341 |
+
|
342 |
+
$title = preg_replace( '!\.[^.]+$!', '', basename( $file ) );
|
343 |
+
$content = '';
|
344 |
+
|
345 |
+
// use image exif/iptc data for title and caption defaults if possible
|
346 |
+
if ( $image_meta = @wp_read_image_metadata( $new_file ) ) {
|
347 |
+
if ( '' != trim( $image_meta['title'] ) ) {
|
348 |
+
$title = trim( $image_meta['title'] );
|
349 |
+
}
|
350 |
+
if ( '' != trim( $image_meta['caption'] ) ) {
|
351 |
+
$content = trim( $image_meta['caption'] );
|
352 |
+
}
|
353 |
+
}
|
354 |
+
|
355 |
+
if ( $time ) {
|
356 |
+
$post_date_gmt = $time;
|
357 |
+
$post_date = $time;
|
358 |
+
} else {
|
359 |
+
$post_date = current_time( 'mysql' );
|
360 |
+
$post_date_gmt = current_time( 'mysql', 1 );
|
361 |
+
}
|
362 |
+
|
363 |
+
// Construct the attachment array
|
364 |
+
$attachment = array(
|
365 |
+
'post_mime_type' => $type,
|
366 |
+
'guid' => $url,
|
367 |
+
'post_parent' => $post_id,
|
368 |
+
'post_title' => $title,
|
369 |
+
'post_name' => $title,
|
370 |
+
'post_content' => $content,
|
371 |
+
'post_date' => $post_date,
|
372 |
+
'post_date_gmt' => $post_date_gmt
|
373 |
+
);
|
374 |
+
|
375 |
+
$attachment = apply_filters( 'afs-import_details', $attachment, $file, $post_id, $import_date );
|
376 |
+
|
377 |
+
$new_file = str_replace( wp_normalize_path( $uploads['basedir'] ), $uploads['basedir'], $new_file );
|
378 |
+
|
379 |
+
// Save the data
|
380 |
+
$id = wp_insert_attachment( $attachment, $new_file, $post_id );
|
381 |
+
if ( !is_wp_error( $id ) ) {
|
382 |
+
$data = wp_generate_attachment_metadata( $id, $new_file );
|
383 |
+
wp_update_attachment_metadata( $id, $data );
|
384 |
+
}
|
385 |
+
// update_post_meta( $id, '_wp_attached_file', $uploads['subdir'] . '/' . $filename );
|
386 |
+
|
387 |
+
return $id;
|
388 |
+
}
|
389 |
+
|
390 |
+
// Create the content for the page
|
391 |
+
function main_content() {
|
392 |
+
global $pagenow;
|
393 |
+
$post_id = isset($_REQUEST['post_id']) ? intval( $_REQUEST['post_id'] ) : 0;
|
394 |
+
$import_to_gallery = isset($_POST['gallery']) && 'on' == $_POST['gallery'];
|
395 |
+
if ( !$import_to_gallery && !isset($_REQUEST['cwd']) ) {
|
396 |
+
$import_to_gallery = true; // cwd should always be set, if it's not, and neither is gallery, this must be the first page load.
|
397 |
+
}
|
398 |
+
$import_date = isset($_REQUEST['import-date']) ? $_REQUEST['import-date'] : 'current';
|
399 |
+
|
400 |
+
if ( 'upload.php' == $pagenow ) {
|
401 |
+
$url = admin_url( 'upload.php?page=add-from-server' );
|
402 |
+
} else {
|
403 |
+
$url = admin_url( 'media-upload.php?tab=server' );
|
404 |
+
}
|
405 |
+
|
406 |
+
if ( $post_id ) {
|
407 |
+
$url = add_query_arg( 'post_id', $post_id, $url );
|
408 |
+
}
|
409 |
+
|
410 |
+
$cwd = trailingslashit( get_option( 'frmsvr_last_folder' ) ?: WP_CONTENT_DIR );
|
411 |
+
|
412 |
+
if ( isset($_REQUEST['directory']) ) {
|
413 |
+
$cwd .= stripslashes( urldecode( $_REQUEST['directory'] ) );
|
414 |
+
}
|
415 |
+
|
416 |
+
if ( isset($_REQUEST['adirectory']) && empty($_REQUEST['adirectory']) ) {
|
417 |
+
$_REQUEST['adirectory'] = '/'; // For good measure.
|
418 |
+
}
|
419 |
+
|
420 |
+
if ( isset($_REQUEST['adirectory']) ) {
|
421 |
+
$cwd = stripslashes( urldecode( $_REQUEST['adirectory'] ) );
|
422 |
+
}
|
423 |
+
|
424 |
+
$cwd = preg_replace( '![^/]*/\.\./!', '', $cwd );
|
425 |
+
$cwd = preg_replace( '!//!', '/', $cwd );
|
426 |
+
|
427 |
+
if ( !is_readable( $cwd ) && is_readable( $this->get_root() . '/' . ltrim( $cwd, '/' ) ) ) {
|
428 |
+
$cwd = $this->get_root() . '/' . ltrim( $cwd, '/' );
|
429 |
+
}
|
430 |
+
|
431 |
+
if ( !is_readable( $cwd ) && get_option( 'frmsvr_last_folder' ) ) {
|
432 |
+
$cwd = get_option( 'frmsvr_last_folder' );
|
433 |
+
}
|
434 |
+
|
435 |
+
if ( !is_readable( $cwd ) ) {
|
436 |
+
$cwd = WP_CONTENT_DIR;
|
437 |
+
}
|
438 |
+
|
439 |
+
if ( strpos( $cwd, $this->get_root() ) === false ) {
|
440 |
+
$cwd = $this->get_root();
|
441 |
+
}
|
442 |
+
|
443 |
+
$cwd = wp_normalize_path( $cwd );
|
444 |
+
|
445 |
+
if ( strlen( $cwd ) > 1 ) {
|
446 |
+
$cwd = untrailingslashit( $cwd );
|
447 |
+
}
|
448 |
+
|
449 |
+
if ( !is_readable( $cwd ) ) {
|
450 |
+
echo '<div class="error"><p>' . __( '<strong>Error:</strong> This users root directory is not readable. Please have your site administrator correct the <em>Add From Server</em> root directory settings.', 'add-from-server' ) . '</p></div>';
|
451 |
+
return;
|
452 |
+
}
|
453 |
+
|
454 |
+
update_option( 'frmsvr_last_folder', $cwd );
|
455 |
+
|
456 |
+
$files = $this->find_files( $cwd );
|
457 |
+
|
458 |
+
$parts = explode( '/', ltrim( str_replace( $this->get_root(), '/', $cwd ), '/' ) );
|
459 |
+
if ( $parts[0] != '' ) {
|
460 |
+
$parts = array_merge( (array)'', $parts );
|
461 |
+
}
|
462 |
+
|
463 |
+
array_walk( $parts, function( &$item, $index ) use( $url, $parts ) {
|
464 |
+
$path = implode( '/', array_slice( $parts, 0, $index ) );
|
465 |
+
$path = ltrim( $path, '/' ) ?: '/';
|
466 |
+
$item_url = add_query_arg( array( 'adirectory' => $path ), $url );
|
467 |
+
|
468 |
+
$item = sprintf( '<a href="%s">%s/</a>', esc_url( $item_url ), esc_html( $item ) );
|
469 |
+
} );
|
470 |
+
$dirparts = implode( '', $parts );
|
471 |
+
|
472 |
+
?>
|
473 |
+
<div class="frmsvr_wrap">
|
474 |
+
<form method="post" action="<?php echo esc_url( $url ); ?>">
|
475 |
+
<p><?php printf( __( '<strong>Current Directory:</strong> <span id="cwd">%s</span>', 'add-from-server' ), $dirparts ) ?></p>
|
476 |
+
<?php $this->display_quick_jumps( $url ); ?>
|
477 |
+
<?php if ( 'media-upload.php' == $GLOBALS['pagenow'] && $post_id > 0 ) : ?>
|
478 |
+
<p><?php _e( 'Once you have Imported your files, head over to <strong>Insert Media</strong> to add them to your post.', 'add-from-server' ); ?></p>
|
479 |
+
<?php endif; ?>
|
480 |
+
<table class="widefat">
|
481 |
+
<thead>
|
482 |
+
<tr>
|
483 |
+
<td class="check-column"><input type='checkbox'/></td>
|
484 |
+
<td><?php _e( 'File', 'add-from-server' ); ?></td>
|
485 |
+
</tr>
|
486 |
+
</thead>
|
487 |
+
<tbody>
|
488 |
+
<?php
|
489 |
+
$parent = dirname( $cwd );
|
490 |
+
if ( $parent != $cwd && (strpos( $parent, $this->get_root() ) === 0) && is_readable( $parent ) ) :
|
491 |
+
$parent = preg_replace( '!^' . preg_quote( $this->get_root(), '!' ) . '!i', '', $parent );
|
492 |
+
?>
|
493 |
+
<tr>
|
494 |
+
<td> </td>
|
495 |
+
<td>
|
496 |
+
<a href="<?php echo esc_url( add_query_arg( array( 'adirectory' => rawurlencode( $parent ) ), $url ) ); ?>"
|
497 |
+
title="<?php echo esc_attr( dirname( $cwd ) ) ?>"><?php _e( 'Parent Folder', 'add-from-server' ); ?></a>
|
498 |
+
</td>
|
499 |
+
</tr>
|
500 |
+
<?php endif; ?>
|
501 |
+
<?php
|
502 |
+
$directories = array();
|
503 |
+
foreach ( (array)$files as $key => $file ) {
|
504 |
+
if ( is_dir( $file ) ) {
|
505 |
+
$directories[] = $file;
|
506 |
+
unset($files[$key]);
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
sort( $directories );
|
511 |
+
sort( $files );
|
512 |
+
|
513 |
+
foreach ( (array)$directories as $file ) :
|
514 |
+
$filename = preg_replace( '!^' . preg_quote( $cwd ) . '!i', '', $file );
|
515 |
+
$filename = ltrim( $filename, '/' );
|
516 |
+
$folder_url = add_query_arg( array( 'directory' => rawurlencode( $filename ), 'import-date' => $import_date, 'gallery' => $import_to_gallery ), $url );
|
517 |
+
?>
|
518 |
+
<tr>
|
519 |
+
<td> </td>
|
520 |
+
<td>
|
521 |
+
<a href="<?php echo esc_url( $folder_url ); ?>"><?php echo esc_html( rtrim( $filename, '/' ) . '/' ); ?></a>
|
522 |
+
</td>
|
523 |
+
</tr>
|
524 |
+
<?php
|
525 |
+
endforeach;
|
526 |
+
$names = $rejected_files = $unreadable_files = array();
|
527 |
+
$unfiltered_upload = current_user_can( 'unfiltered_upload' );
|
528 |
+
foreach ( (array)$files as $key => $file ) {
|
529 |
+
if ( !$unfiltered_upload ) {
|
530 |
+
$wp_filetype = wp_check_filetype( $file );
|
531 |
+
if ( false === $wp_filetype['type'] ) {
|
532 |
+
$rejected_files[] = $file;
|
533 |
+
unset($files[$key]);
|
534 |
+
continue;
|
535 |
+
}
|
536 |
+
}
|
537 |
+
if ( !is_readable( $file ) ) {
|
538 |
+
$unreadable_files[] = $file;
|
539 |
+
unset($files[$key]);
|
540 |
+
continue;
|
541 |
+
}
|
542 |
+
}
|
543 |
+
|
544 |
+
foreach ( array( 'meets_guidelines' => $files, 'unreadable' => $unreadable_files, 'doesnt_meets_guidelines' => $rejected_files ) as $key => $_files ) :
|
545 |
+
$file_meets_guidelines = $unfiltered_upload || ('meets_guidelines' == $key);
|
546 |
+
$unreadable = 'unreadable' == $key;
|
547 |
+
foreach ( $_files as $file_index => $file ) :
|
548 |
+
$classes = array();
|
549 |
+
|
550 |
+
if ( !$file_meets_guidelines ) {
|
551 |
+
$classes[] = 'doesnt-meet-guidelines';
|
552 |
+
}
|
553 |
+
if ( $unreadable ) {
|
554 |
+
$classes[] = 'unreadable';
|
555 |
+
}
|
556 |
+
|
557 |
+
$filename = preg_replace( '!^' . preg_quote( $cwd, '!' ) . '!', '', $file );
|
558 |
+
$filename = ltrim( $filename, '/' );
|
559 |
+
|
560 |
+
?>
|
561 |
+
<tr class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" title="<?php if ( !$file_meets_guidelines ) {
|
562 |
+
esc_attr_e( 'Sorry, this file type is not permitted for security reasons. Please see the FAQ.', 'add-from-server' );
|
563 |
+
} elseif ( $unreadable ) {
|
564 |
+
esc_attr_e( 'Sorry, but this file is unreadable by your Webserver. Perhaps check your File Permissions?', 'add-from-server' );
|
565 |
+
} ?>">
|
566 |
+
<th class='check-column'>
|
567 |
+
<input type='checkbox' id='file-<?php echo (int)$file_index; ?>' name='files[]' value='<?php echo esc_attr( $filename ); ?>' <?php disabled( !$file_meets_guidelines || $unreadable ); ?> />
|
568 |
+
</th>
|
569 |
+
<td>
|
570 |
+
<label for='file-<?php echo (int)$file_index; ?>'><?php echo esc_html( $filename ); ?></label>
|
571 |
+
</td>
|
572 |
+
</tr>
|
573 |
+
<?php endforeach; endforeach; ?>
|
574 |
+
</tbody>
|
575 |
+
<tfoot>
|
576 |
+
<tr>
|
577 |
+
<td class="check-column"><input type='checkbox'/></td>
|
578 |
+
<td><?php _e( 'File', 'add-from-server' ); ?></td>
|
579 |
+
</tr>
|
580 |
+
</tfoot>
|
581 |
+
</table>
|
582 |
+
|
583 |
+
<fieldset>
|
584 |
+
<legend><?php _e( 'Import Options', 'add-from-server' ); ?></legend>
|
585 |
+
|
586 |
+
<?php if ( $post_id ) : ?>
|
587 |
+
<input type="checkbox" name="gallery" id="gallery-import" <?php checked( $import_to_gallery ); ?> /><label for="gallery-import"><?php _e( 'Attach imported files to this post', 'add-from-server' ) ?></label>
|
588 |
+
<br class="clear"/>
|
589 |
+
<?php endif; ?>
|
590 |
+
<?php _e( 'Set the imported date to the', 'add-from-server' ); ?>
|
591 |
+
<input type="radio" name="import-date" id="import-time-currenttime" value="current" <?php checked( 'current', $import_date ); ?> /> <label for="import-time-currenttime"><?php _e( 'Current Time', 'add-from-server' ); ?></label>
|
592 |
+
<input type="radio" name="import-date" id="import-time-filetime" value="file" <?php checked( 'file', $import_date ); ?> /> <label for="import-time-filetime"><?php _e( 'File Time', 'add-from-server' ); ?></label>
|
593 |
+
<?php if ( $post_id ) : ?>
|
594 |
+
<input type="radio" name="import-date" id="import-time-posttime" value="post" <?php checked( 'post', $import_date ); ?> /> <label for="import-time-posttime"><?php _e( 'Post Time', 'add-from-server' ); ?></label>
|
595 |
+
<?php endif; ?>
|
596 |
+
</fieldset>
|
597 |
+
<br class="clear"/>
|
598 |
+
<input type="hidden" name="cwd" value="<?php echo esc_attr( $cwd ); ?>"/>
|
599 |
+
<?php submit_button( __( 'Import', 'add-from-server' ), 'primary', 'import', false ); ?>
|
600 |
+
</form>
|
601 |
+
<?php $this->language_notice(); ?>
|
602 |
+
</div>
|
603 |
+
<?php
|
604 |
+
}
|
605 |
+
|
606 |
+
function display_quick_jumps( $url ) {
|
607 |
+
$quickjumps = array();
|
608 |
+
$quickjumps[] = array(
|
609 |
+
__( 'WordPress Root', 'add-from-server' ),
|
610 |
+
wp_normalize_path( ABSPATH )
|
611 |
+
);
|
612 |
+
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
|
613 |
+
$quickjumps[] = array(
|
614 |
+
__( 'Uploads Folder', 'add-from-server' ),
|
615 |
+
wp_normalize_path( $uploads['path'] )
|
616 |
+
);
|
617 |
+
}
|
618 |
+
$quickjumps[] = array(
|
619 |
+
__( 'Content Folder', 'add-from-server' ),
|
620 |
+
wp_normalize_path( WP_CONTENT_DIR )
|
621 |
+
);
|
622 |
+
|
623 |
+
$quickjumps = apply_filters( 'frmsvr_quickjumps', $quickjumps );
|
624 |
+
|
625 |
+
if ( empty( $quickjumps ) ) {
|
626 |
+
return;
|
627 |
+
}
|
628 |
+
|
629 |
+
$pieces = array();
|
630 |
+
foreach ( $quickjumps as $jump ) {
|
631 |
+
list( $text, $adir ) = $jump;
|
632 |
+
$adir = wp_normalize_path( $adir );
|
633 |
+
|
634 |
+
// Validate it's within the locked directory
|
635 |
+
if ( strpos( $adir, $this->get_root() ) === false )
|
636 |
+
continue;
|
637 |
+
|
638 |
+
$adir = preg_replace( '!^' . preg_quote( $this->get_root(), '!' ) . '!i', '', $adir );
|
639 |
+
if ( strlen( $adir ) > 1 ) {
|
640 |
+
$adir = ltrim( $adir, '/' );
|
641 |
+
}
|
642 |
+
|
643 |
+
$durl = add_query_arg( array( 'adirectory' => rawurlencode( $adir ) ), $url );
|
644 |
+
$pieces[] = sprintf( '<a href="%s">%s</a>', esc_url( $durl ), esc_html( $text ) );
|
645 |
+
}
|
646 |
+
|
647 |
+
if ( !empty( $pieces ) ) {
|
648 |
+
printf( '<p>' . __( '<strong>Quick Jump:</strong> %s', 'add-from-server' ) . '<p>', implode( ' | ', $pieces ) );
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
function find_files( $folder ) {
|
653 |
+
if ( !is_readable( $folder ) ) {
|
654 |
+
return array();
|
655 |
+
}
|
656 |
+
|
657 |
+
return glob( rtrim( $folder, '/' ) . '/*' );
|
658 |
+
}
|
659 |
+
|
660 |
+
function language_notice( $force = false ) {
|
661 |
+
$message_english = 'Hi there!
|
662 |
+
I notice you use WordPress in a Language other than English (US), Did you know you can translate WordPress Plugins into your native language as well?
|
663 |
+
If you\'d like to help out with translating this plugin into %1$s you can head over to <a href="%2$s">translate.WordPress.org page</a> and suggest translations for any languages which you know.
|
664 |
+
Thanks! Dion.';
|
665 |
+
/* translators: %1$s = The Locale (de_DE, en_US, fr_FR, he_IL, etc). %2$s = The translate.wordpress.org link to the plugin overview */
|
666 |
+
$message = __( 'Hi there!
|
667 |
+
I notice you use WordPress in a Language other than English (US), Did you know you can translate WordPress Plugins into your native language as well?
|
668 |
+
If you\'d like to help out with translating this plugin into %1$s you can head over to <a href="%2$s">translate.WordPress.org page</a> and suggest translations for any languages which you know.
|
669 |
+
Thanks! Dion.', 'add-from-server' );
|
670 |
+
|
671 |
+
// Don't display the message for English (US) or what we'll assume to be fully translated localised builds.
|
672 |
+
if ( 'en_US' === get_locale() || ( $message == $message_english && ! $force ) ) {
|
673 |
+
return false;
|
674 |
+
}
|
675 |
+
|
676 |
+
$translate_url = 'https://translate.wordpress.org/projects/wp-plugins/add-from-server/stable';
|
677 |
+
|
678 |
+
echo '<div class="notice notice-info"><p>' . sprintf( nl2br( $message ), get_locale(), $translate_url ) . '</p></div>';
|
679 |
+
}
|
680 |
+
|
681 |
+
}
|
old-versions.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Add_From_Server {
|
4 |
+
function __construct( $plugin_basename ) {
|
5 |
+
|
6 |
+
// Handle activation gracefully with a block screen.
|
7 |
+
if ( isset( $_REQUEST['action'] ) && ( 'activate' == $_REQUEST['action'] || 'error_scrape' == $_REQUEST['action'] ) && isset( $_REQUEST['plugin'] ) && $plugin_basename = $_REQUEST['plugin'] ) {
|
8 |
+
load_plugin_textdomain( 'add-from-server' );
|
9 |
+
die( sprintf(
|
10 |
+
__( 'This plugin requires WordPress %1$s or greater, and PHP %2$s or greater. You are currently running WordPress %3$s and PHP %4$s. Please contact your website host or server administrator for more information. The plugin has been deactivated.', 'add-from-server' ),
|
11 |
+
ADD_FROM_SERVER_WP_REQUIREMENT,
|
12 |
+
ADD_FROM_SERVER_PHP_REQUIREMENT,
|
13 |
+
$GLOBALS['wp_version'],
|
14 |
+
phpversion()
|
15 |
+
) );
|
16 |
+
}
|
17 |
+
|
18 |
+
add_action( 'pre_current_active_plugins', array( $this, 'unsupported_plugins_notice' ) );
|
19 |
+
}
|
20 |
+
|
21 |
+
function unsupported_plugins_notice( $var ) {
|
22 |
+
load_plugin_textdomain( 'add-from-server' );
|
23 |
+
printf(
|
24 |
+
'<div class="error"><p><strong>%s</strong>: %s</p></div>',
|
25 |
+
__( 'Add From Server', 'add-from-server' ),
|
26 |
+
sprintf(
|
27 |
+
__( 'This plugin requires WordPress %1$s or greater, and PHP %2$s or greater. You are currently running WordPress %3$s and PHP %4$s. Please contact your website host or server administrator for more information. The plugin has been deactivated.', 'add-from-server' ),
|
28 |
+
ADD_FROM_SERVER_WP_REQUIREMENT,
|
29 |
+
ADD_FROM_SERVER_PHP_REQUIREMENT,
|
30 |
+
$GLOBALS['wp_version'],
|
31 |
+
phpversion()
|
32 |
+
)
|
33 |
+
);
|
34 |
+
}
|
35 |
+
|
36 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Add From Server ===
|
2 |
+
Contributors: dd32
|
3 |
+
Tags: admin, media, uploads, post, import, files
|
4 |
+
Requires at least: 4.0
|
5 |
+
Stable tag: 3.3.1
|
6 |
+
|
7 |
+
"Add From Server" is a quick plugin which allows you to import media & files into the WordPress uploads manager from the Webservers filesystem
|
8 |
+
|
9 |
+
== Description ==
|
10 |
+
|
11 |
+
The heart of a CMS is the ability to upload and insert content, WordPress does a fantastic job at this, unfortunately, some web hosts have limited servers, or users simply do not have the ability to upload large files through their web browser.
|
12 |
+
Add From Server is designed to help ease this pain, You can upload a bunch of files via FTP (Or your favourite transmission method) and simply import those files from the webserver directly into WordPress.
|
13 |
+
|
14 |
+
== Changelog ==
|
15 |
+
|
16 |
+
= 3.3.1 =
|
17 |
+
* Fix plugin activation
|
18 |
+
|
19 |
+
= 3.3 =
|
20 |
+
* The plugin now requires WordPress 4.0 and PHP 5.4 as a minumum requirement.
|
21 |
+
* Updated to use WordPress.org translation system, please submit translations through https://translate.wordpress.org/projects/wp-plugins/add-from-server/stable
|
22 |
+
* Updated to WordPress 4.3 styles
|
23 |
+
|
24 |
+
== Upgrade Notice ==
|
25 |
+
|
26 |
+
= 3.3.1 =
|
27 |
+
Warning: This plugin now requires WordPress 4.0 & PHP 5.4. Updates to support WordPress 4.3 & WordPress.org Language Pack Translations
|
28 |
+
|
29 |
+
= 3.3 =
|
30 |
+
Warning: This plugin now requires WordPress 4.0 & PHP 5.4. Updates to support WordPress 4.3 & WordPress.org Language Pack Translations
|
31 |
+
|
32 |
+
== FAQ ==
|
33 |
+
Q: What placeholders can I use in the Root path option?
|
34 |
+
You can use %role% and %username% only. In the case of Role, The first role which the user has is used, This can mean that in complex installs, that using %role% is unreliable.
|
35 |
+
|
36 |
+
Q: Why does the file I want to import have a red background?
|
37 |
+
WordPress only allows the importing/uploading of certain file types to improve your security. If you wish to add extra file types, you can use a plugin such as: http://wordpress.org/extend/plugins/pjw-mime-config/ You can also enable "Unfiltered uploads" globally for WordPress if you'd like to override this security function. Please see the WordPress support forum for details.
|
38 |
+
|
39 |
+
Q: Where are the files saved?
|
40 |
+
If you import a file which is outside your standard upload directory (usually wp-content/uploads/) then it will be copied to your current upload directory setting as normal. If you however import a file which -is already within the uploads directory- (for example, wp-content/uploads/2011/02/superplugin.zip) then the file will not be copied, and will be used as-is.
|
41 |
+
|
42 |
+
Q: I have a a bug report
|
43 |
+
Then please email me! wordpress at dd32.id.au is best.
|
44 |
+
|
45 |
+
== Screenshots ==
|
46 |
+
|
47 |
+
1. The import manager, This allows you to select which files to import. Note that files which cannot be imported are Red.
|
48 |
+
2. The Options panel, This allows you to specify what users can access Add From Server, and which folders users can import files from.
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|