PluginProbe
Infinite Uploads – Offload, Optimize & Organize Your Media Library / 3.2.3
Infinite Uploads – Offload, Optimize & Organize Your Media Library v3.2.3
3.3.4 3.3.3 3.3.2 3.3.1 3.3.0 3.2.6 3.2.5 3.2.4 3.2.3 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 2.0 2.0.1 2.0.10 2.0.2 2.0.4 All 48 releases
infinite-uploads / infinite-uploads.php

infinite-uploads.php in Infinite Uploads – Offload, Optimize & Organize Your Media Library 3.2.3, at infinite-uploads.php

267 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Infinite Uploads
4 * 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.
5 * Version: 3.2.3
6 * Author: Infinite Uploads
7 * Author URI: https://infiniteuploads.com/?utm_source=iup_plugin&utm_medium=plugin&utm_campaign=iup_plugin&utm_content=meta
8 * Text Domain: infinite-uploads
9 * Requires at least: 6.0
10 * Tested up to: 7.0
11 * Requires PHP: 8.0
12 * License: GPLv2
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Network: true
15 *
16 * Inspired by AWS PHP SDK stream wrapper code from the S3 Uploads plugin by Human Made https://github.com/humanmade/S3-Uploads.
17 *
18 * Copyright 2021-2025 ClikIT, LLC
19 */
20
21 define( 'INFINITE_UPLOADS_VERSION', '3.2.3' );
22
23 if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
24 require_once __DIR__ . '/vendor/autoload.php';
25 }
26
27 // Load action scheduler.
28 require_once dirname( __FILE__ ) . '/libs/action-scheduler/action-scheduler.php';
29
30 if ( defined( 'WP_CLI' ) && WP_CLI ) {
31 \WP_CLI::add_command( 'infinite-uploads', '\ClikIT\InfiniteUploads\InfiniteUploadsWPCLICommand' );
32 }
33
34 //require_once 'inc/class-infinite-uploads-wp-mail.php';
35 register_activation_hook( __FILE__, 'infinite_uploads_install' );
36
37 add_action( 'plugins_loaded', 'infinite_uploads_init' );
38
39 function infinite_uploads_init() {
40 //how much to try uploading/downloading per ajax loop (we want as much as possible without exceeding (php timeout - ajax_timeout) to avoid 504s
41 if ( ! defined( 'INFINITE_UPLOADS_SYNC_MAX_BYTES' ) ) {
42 define( 'INFINITE_UPLOADS_SYNC_MAX_BYTES', MB_IN_BYTES * 12 );
43 }
44 //This is the maximum to transfer in parallel within the INFINITE_UPLOADS_SYNC_MAX_BYTES size.
45 if ( ! defined( 'INFINITE_UPLOADS_SYNC_CONCURRENCY' ) ) {
46 define( 'INFINITE_UPLOADS_SYNC_CONCURRENCY', 15 );
47 }
48 if ( ! defined( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY' ) ) {
49 define( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY', 5 );
50 }
51 if ( ! defined( 'INFINITE_UPLOADS_SYNC_PER_LOOP' ) ) {
52 define( 'INFINITE_UPLOADS_SYNC_PER_LOOP', 1000 );
53 }
54 if ( ! defined( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL' ) ) {
55 define( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL', YEAR_IN_SECONDS );
56 }
57 //we cache the last object uploaded to cloud in memory so it can be processed without downloading again.
58 if ( ! defined( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES' ) ) {
59 define( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES', MB_IN_BYTES * 32 );
60 }
61
62 // Require Our custom AWS Autoloader file.
63
64 require_once dirname( __FILE__ ) . '/vendor/Aws3/aws-autoloader.php';
65
66 if ( ! infinite_uploads_check_requirements() ) {
67 return;
68 }
69
70 infinite_uploads_upgrade();
71
72 $instance = \ClikIT\InfiniteUploads\InfiniteUploads::get_instance();
73
74 require_once dirname( __FILE__ ) . '/functions.php';
75
76 $instance->setup();
77 }
78
79 function infinite_uploads_upgrade() {
80
81 // Network-wide table (infinite_uploads_files) — one option gates the whole network.
82 $installed = get_site_option( 'iup_installed' );
83 if ( INFINITE_UPLOADS_VERSION != $installed ) {
84 infinite_uploads_install();
85 }
86
87 // Per-site folder tables — each subsite tracks its own version independently.
88 $folders_installed = get_option( 'iup_folders_installed' );
89 if ( INFINITE_UPLOADS_VERSION != $folders_installed ) {
90 infinite_uploads_install_folders();
91 }
92 }
93
94 function infinite_uploads_install() {
95 global $wpdb;
96
97 //prevent race condition during upgrade by setting option before running potentially long query
98 if ( is_multisite() ) {
99 update_site_option( 'iup_installed', INFINITE_UPLOADS_VERSION );
100 } else {
101 update_option( 'iup_installed', INFINITE_UPLOADS_VERSION, true );
102 }
103
104 $charset_collate = $wpdb->get_charset_collate();
105
106 //191 is the maximum innodb default key length on utf8mb4
107 $sql = "CREATE TABLE {$wpdb->base_prefix}infinite_uploads_files (
108 `file` VARCHAR(255) NOT NULL,
109 `size` BIGINT UNSIGNED NOT NULL DEFAULT '0',
110 `modified` INT UNSIGNED NOT NULL,
111 `type` VARCHAR(20) NOT NULL,
112 `transferred` BIGINT UNSIGNED NOT NULL DEFAULT '0',
113 `synced` BOOLEAN NOT NULL DEFAULT '0',
114 `deleted` BOOLEAN NOT NULL DEFAULT '0',
115 `errors` INT UNSIGNED NOT NULL DEFAULT '0',
116 `transfer_status` TEXT NULL DEFAULT NULL,
117 PRIMARY KEY (`file`(191)),
118 KEY `type` (`type`),
119 KEY `synced` (`synced`),
120 KEY `deleted` (`deleted`)
121 ) {$charset_collate};";
122
123 if ( ! function_exists( 'dbDelta' ) ) {
124 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
125 }
126
127 dbDelta( $sql );
128
129 // Create per-site folder tables for the current site.
130 infinite_uploads_install_folders();
131 }
132
133 /**
134 * Create (or upgrade) the per-site media-folder tables for the current subsite.
135 *
136 * Uses $wpdb->prefix so each subsite gets its own tables, keeping folder
137 * assignments isolated to the site that owns the attachment posts.
138 * Gated by a per-site option so it runs independently on every subsite.
139 */
140 function infinite_uploads_install_folders() {
141 global $wpdb;
142
143 // Prevent race conditions by marking done before the potentially slow dbDelta.
144 update_option( 'iup_folders_installed', INFINITE_UPLOADS_VERSION, true );
145
146 $charset_collate = $wpdb->get_charset_collate();
147
148 // Media folders table.
149 $sql = "CREATE TABLE {$wpdb->prefix}infinite_uploads_media_folders (
150 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
151 name VARCHAR(255) NOT NULL,
152 parent_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
153 sort_order INT UNSIGNED NOT NULL DEFAULT 0,
154 created_by BIGINT UNSIGNED NOT NULL DEFAULT 0,
155 created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
156 updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
157 color VARCHAR(20) NOT NULL DEFAULT '',
158 PRIMARY KEY (id),
159 KEY parent_id (parent_id),
160 KEY sort_order (sort_order)
161 ) {$charset_collate};";
162
163 // Media-to-folder relationship table.
164 $sql .= "\nCREATE TABLE {$wpdb->prefix}infinite_uploads_media_folder_relationships (
165 folder_id BIGINT UNSIGNED NOT NULL,
166 attachment_id BIGINT UNSIGNED NOT NULL,
167 PRIMARY KEY (folder_id, attachment_id),
168 KEY attachment_id (attachment_id)
169 ) {$charset_collate};";
170
171 if ( ! function_exists( 'dbDelta' ) ) {
172 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
173 }
174
175 dbDelta( $sql );
176 }
177
178 // Create folder tables for each new subsite when it is provisioned.
179 add_action( 'wp_initialize_site', function ( $new_site ) {
180 switch_to_blog( $new_site->blog_id );
181 infinite_uploads_install_folders();
182 restore_current_blog();
183 } );
184
185 /**
186 * Check whether the environment meets the plugin's requirements, like the minimum PHP version.
187 *
188 * @return bool True if the requirements are met, else false.
189 */
190 function infinite_uploads_check_requirements() {
191 global $wp_version;
192 $hook = is_multisite() ? 'network_admin_notices' : 'admin_notices';
193
194 if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) {
195 add_action( $hook, 'infinite_uploads_outdated_php_version_notice' );
196
197 return false;
198 }
199
200 if ( version_compare( $wp_version, '5.3.0', '<' ) ) {
201 add_action( $hook, 'infinite_uploads_outdated_wp_version_notice' );
202
203 return false;
204 }
205
206 return true;
207 }
208
209 /**
210 * Print an admin notice when the PHP version is not high enough.
211 *
212 * This has to be a named function for compatibility with PHP 5.2.
213 */
214 function infinite_uploads_outdated_php_version_notice() {
215 ?>
216 <div class="notice notice-warning is-dismissible"><p>
217 <?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 ); ?>
218 </p></div>
219 <?php
220 }
221
222 /**
223 * Print an admin notice when the WP version is not high enough.
224 *
225 * This has to be a named function for compatibility with PHP 5.2.
226 */
227 function infinite_uploads_outdated_wp_version_notice() {
228 global $wp_version;
229 ?>
230 <div class="notice notice-warning is-dismissible"><p>
231 <?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 ); ?>
232 </p></div>
233 <?php
234 }
235
236 /**
237 * Check if URL rewriting is enabled.
238 *
239 * @return bool
240 */
241 function infinite_uploads_enabled() {
242 return get_site_option( 'iup_enabled' );
243 }
244
245 /**
246 * Autoload callback.
247 *
248 * @param $class_name string Name of the class to load.
249 */
250 function infinite_uploads_autoload( $class_name ) {
251 /*
252 * Load plugin classes:
253 * - Class name: Infinite_Uploads_Image_Editor_Imagick.
254 * - File name: class-infinite-uploads-image-editor-imagick.php.
255 */
256 $class_file = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
257 $class_path = dirname( __FILE__ ) . '/inc/' . $class_file;
258
259 if ( file_exists( $class_path ) ) {
260 require $class_path;
261
262 return;
263 }
264 }
265
266 // spl_autoload_register( 'infinite_uploads_autoload' );
267