PluginProbe
Infinite Uploads – Offload, Optimize & Organize Your Media Library / 3.1.6
Infinite Uploads – Offload, Optimize & Organize Your Media Library v3.1.6
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.1.6, at infinite-uploads.php

206 lines 6.5 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.1.6
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: 6.9.1
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.1.6' );
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 // Install the needed DB table if not already.
82 $installed = get_site_option( 'iup_installed' );
83 if ( INFINITE_UPLOADS_VERSION != $installed ) {
84 infinite_uploads_install();
85 }
86 }
87
88 function infinite_uploads_install() {
89 global $wpdb;
90
91 //prevent race condition during upgrade by setting option before running potentially long query
92 if ( is_multisite() ) {
93 update_site_option( 'iup_installed', INFINITE_UPLOADS_VERSION );
94 } else {
95 update_option( 'iup_installed', INFINITE_UPLOADS_VERSION, true );
96 }
97
98 $charset_collate = $wpdb->get_charset_collate();
99
100 //191 is the maximum innodb default key length on utf8mb4
101 $sql = "CREATE TABLE {$wpdb->base_prefix}infinite_uploads_files (
102 `file` VARCHAR(255) NOT NULL,
103 `size` BIGINT UNSIGNED NOT NULL DEFAULT '0',
104 `modified` INT UNSIGNED NOT NULL,
105 `type` VARCHAR(20) NOT NULL,
106 `transferred` BIGINT UNSIGNED NOT NULL DEFAULT '0',
107 `synced` BOOLEAN NOT NULL DEFAULT '0',
108 `deleted` BOOLEAN NOT NULL DEFAULT '0',
109 `errors` INT UNSIGNED NOT NULL DEFAULT '0',
110 `transfer_status` TEXT NULL DEFAULT NULL,
111 PRIMARY KEY (`file`(191)),
112 KEY `type` (`type`),
113 KEY `synced` (`synced`),
114 KEY `deleted` (`deleted`)
115 ) {$charset_collate};";
116
117 if ( ! function_exists( 'dbDelta' ) ) {
118 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
119 }
120
121 return dbDelta( $sql );
122 }
123
124 /**
125 * Check whether the environment meets the plugin's requirements, like the minimum PHP version.
126 *
127 * @return bool True if the requirements are met, else false.
128 */
129 function infinite_uploads_check_requirements() {
130 global $wp_version;
131 $hook = is_multisite() ? 'network_admin_notices' : 'admin_notices';
132
133 if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) {
134 add_action( $hook, 'infinite_uploads_outdated_php_version_notice' );
135
136 return false;
137 }
138
139 if ( version_compare( $wp_version, '5.3.0', '<' ) ) {
140 add_action( $hook, 'infinite_uploads_outdated_wp_version_notice' );
141
142 return false;
143 }
144
145 return true;
146 }
147
148 /**
149 * Print an admin notice when the PHP version is not high enough.
150 *
151 * This has to be a named function for compatibility with PHP 5.2.
152 */
153 function infinite_uploads_outdated_php_version_notice() {
154 ?>
155 <div class="notice notice-warning is-dismissible"><p>
156 <?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 ); ?>
157 </p></div>
158 <?php
159 }
160
161 /**
162 * Print an admin notice when the WP version is not high enough.
163 *
164 * This has to be a named function for compatibility with PHP 5.2.
165 */
166 function infinite_uploads_outdated_wp_version_notice() {
167 global $wp_version;
168 ?>
169 <div class="notice notice-warning is-dismissible"><p>
170 <?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 ); ?>
171 </p></div>
172 <?php
173 }
174
175 /**
176 * Check if URL rewriting is enabled.
177 *
178 * @return bool
179 */
180 function infinite_uploads_enabled() {
181 return get_site_option( 'iup_enabled' );
182 }
183
184 /**
185 * Autoload callback.
186 *
187 * @param $class_name string Name of the class to load.
188 */
189 function infinite_uploads_autoload( $class_name ) {
190 /*
191 * Load plugin classes:
192 * - Class name: Infinite_Uploads_Image_Editor_Imagick.
193 * - File name: class-infinite-uploads-image-editor-imagick.php.
194 */
195 $class_file = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
196 $class_path = dirname( __FILE__ ) . '/inc/' . $class_file;
197
198 if ( file_exists( $class_path ) ) {
199 require $class_path;
200
201 return;
202 }
203 }
204
205 // spl_autoload_register( 'infinite_uploads_autoload' );
206