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

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