-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfinite-uploads.php
195 lines (163 loc) · 6.18 KB
/
infinite-uploads.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/*
* Plugin Name: Infinite Uploads
* Description: Infinitely scalable cloud storage and delivery for your videos and uploads made easy! Upload directly to cloud storage and manage your files right from the WordPress Media Library.
* Version: 2.0.6
* Author: Infinite Uploads
* Author URI: https://infiniteuploads.com/?utm_source=iup_plugin&utm_medium=plugin&utm_campaign=iup_plugin&utm_content=meta
* Text Domain: infinite-uploads
* Requires at least: 5.3
* Requires PHP: 7.0
* License: GPLv2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Network: true
*
* Inspired by AWS PHP SDK stream wrapper code from the S3 Uploads plugin by Human Made https://github.com/humanmade/S3-Uploads.
*
* Copyright 2021-2025 ClikIT, LLC
*/
define( 'INFINITE_UPLOADS_VERSION', '2.0.6' );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once dirname( __FILE__ ) . '/inc/class-infinite-uploads-wp-cli-command.php';
}
//require_once 'inc/class-infinite-uploads-wp-mail.php';
register_activation_hook( __FILE__, 'infinite_uploads_install' );
add_action( 'plugins_loaded', 'infinite_uploads_init' );
function infinite_uploads_init() {
//how much to try uploading/downloading per ajax loop (we want as much as possible without exceeding (php timeout - ajax_timeout) to avoid 504s
if ( ! defined( 'INFINITE_UPLOADS_SYNC_MAX_BYTES' ) ) {
define( 'INFINITE_UPLOADS_SYNC_MAX_BYTES', MB_IN_BYTES * 5 );
}
//This is the maximum to transfer in parallel within the INFINITE_UPLOADS_SYNC_MAX_BYTES size.
if ( ! defined( 'INFINITE_UPLOADS_SYNC_CONCURRENCY' ) ) {
define( 'INFINITE_UPLOADS_SYNC_CONCURRENCY', 15 );
}
if ( ! defined( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY' ) ) {
define( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY', 5 );
}
if ( ! defined( 'INFINITE_UPLOADS_SYNC_PER_LOOP' ) ) {
define( 'INFINITE_UPLOADS_SYNC_PER_LOOP', 1000 );
}
if ( ! defined( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL' ) ) {
define( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL', YEAR_IN_SECONDS );
}
//we cache the last object uploaded to cloud in memory so it can be processed without downloading again.
if ( ! defined( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES' ) ) {
define( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES', MB_IN_BYTES * 32 );
}
// Require Our custom AWS Autoloader file.
require_once dirname( __FILE__ ) . '/vendor/Aws3/aws-autoloader.php';
if ( ! infinite_uploads_check_requirements() ) {
return;
}
infinite_uploads_upgrade();
$instance = Infinite_Uploads::get_instance();
$instance->setup();
}
function infinite_uploads_upgrade() {
// Install the needed DB table if not already.
$installed = get_site_option( 'iup_installed' );
if ( INFINITE_UPLOADS_VERSION != $installed ) {
infinite_uploads_install();
}
}
function infinite_uploads_install() {
global $wpdb;
//prevent race condition during upgrade by setting option before running potentially long query
if ( is_multisite() ) {
update_site_option( 'iup_installed', INFINITE_UPLOADS_VERSION );
} else {
update_option( 'iup_installed', INFINITE_UPLOADS_VERSION, true );
}
$charset_collate = $wpdb->get_charset_collate();
//191 is the maximum innodb default key length on utf8mb4
$sql = "CREATE TABLE {$wpdb->base_prefix}infinite_uploads_files (
`file` VARCHAR(255) NOT NULL,
`size` BIGINT UNSIGNED NOT NULL DEFAULT '0',
`modified` INT UNSIGNED NOT NULL,
`type` VARCHAR(20) NOT NULL,
`transferred` BIGINT UNSIGNED NOT NULL DEFAULT '0',
`synced` BOOLEAN NOT NULL DEFAULT '0',
`deleted` BOOLEAN NOT NULL DEFAULT '0',
`errors` INT UNSIGNED NOT NULL DEFAULT '0',
`transfer_status` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`file`(191)),
KEY `type` (`type`),
KEY `synced` (`synced`),
KEY `deleted` (`deleted`)
) {$charset_collate};";
if ( ! function_exists( 'dbDelta' ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
return dbDelta( $sql );
}
/**
* Check whether the environment meets the plugin's requirements, like the minimum PHP version.
*
* @return bool True if the requirements are met, else false.
*/
function infinite_uploads_check_requirements() {
global $wp_version;
$hook = is_multisite() ? 'network_admin_notices' : 'admin_notices';
if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) {
add_action( $hook, 'infinite_uploads_outdated_php_version_notice' );
return false;
}
if ( version_compare( $wp_version, '5.3.0', '<' ) ) {
add_action( $hook, 'infinite_uploads_outdated_wp_version_notice' );
return false;
}
return true;
}
/**
* Print an admin notice when the PHP version is not high enough.
*
* This has to be a named function for compatibility with PHP 5.2.
*/
function infinite_uploads_outdated_php_version_notice() {
?>
<div class="notice notice-warning is-dismissible"><p>
<?php printf( esc_html__( 'The Infinite Uploads plugin requires PHP version 5.5.0 or higher. Your server is running PHP version %s.', 'infinite-uploads' ), PHP_VERSION ); ?>
</p></div>
<?php
}
/**
* Print an admin notice when the WP version is not high enough.
*
* This has to be a named function for compatibility with PHP 5.2.
*/
function infinite_uploads_outdated_wp_version_notice() {
global $wp_version;
?>
<div class="notice notice-warning is-dismissible"><p>
<?php printf( esc_html__( 'The Infinite Uploads plugin requires WordPress version 5.3 or higher. Your server is running WordPress version %s.', 'infinite-uploads' ), $wp_version ); ?>
</p></div>
<?php
}
/**
* Check if URL rewriting is enabled.
*
* @return bool
*/
function infinite_uploads_enabled() {
return get_site_option( 'iup_enabled' );
}
/**
* Autoload callback.
*
* @param $class_name string Name of the class to load.
*/
function infinite_uploads_autoload( $class_name ) {
/*
* Load plugin classes:
* - Class name: Infinite_Uploads_Image_Editor_Imagick.
* - File name: class-infinite-uploads-image-editor-imagick.php.
*/
$class_file = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
$class_path = dirname( __FILE__ ) . '/inc/' . $class_file;
if ( file_exists( $class_path ) ) {
require $class_path;
return;
}
}
spl_autoload_register( 'infinite_uploads_autoload' );