PluginProbe
Infinite Uploads – Offload, Optimize & Organize Your Media Library / 3.1.0
Infinite Uploads – Offload, Optimize & Organize Your Media Library v3.1.0
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.0, 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.0
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.0' );
22
23 if ( defined( 'WP_CLI' ) && WP_CLI ) {
24 \WP_CLI::add_command( 'infinite-uploads', '\ClikIT\InfiniteUploads\InfiniteUploadsWPCLICommand' );
25 }
26
27 //require_once 'inc/class-infinite-uploads-wp-mail.php';
28
29 register_activation_hook( __FILE__, 'infinite_uploads_install' );
30
31 // Load action scheduler.
32 require_once dirname( __FILE__ ) . '/libs/action-scheduler/action-scheduler.php';
33
34 add_action( 'plugins_loaded', 'infinite_uploads_init' );
35
36 function infinite_uploads_init() {
37 //how much to try uploading/downloading per ajax loop (we want as much as possible without exceeding (php timeout - ajax_timeout) to avoid 504s
38 if ( ! defined( 'INFINITE_UPLOADS_SYNC_MAX_BYTES' ) ) {
39 define( 'INFINITE_UPLOADS_SYNC_MAX_BYTES', MB_IN_BYTES * 12 );
40 }
41 //This is the maximum to transfer in parallel within the INFINITE_UPLOADS_SYNC_MAX_BYTES size.
42 if ( ! defined( 'INFINITE_UPLOADS_SYNC_CONCURRENCY' ) ) {
43 define( 'INFINITE_UPLOADS_SYNC_CONCURRENCY', 15 );
44 }
45 if ( ! defined( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY' ) ) {
46 define( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY', 5 );
47 }
48 if ( ! defined( 'INFINITE_UPLOADS_SYNC_PER_LOOP' ) ) {
49 define( 'INFINITE_UPLOADS_SYNC_PER_LOOP', 1000 );
50 }
51 if ( ! defined( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL' ) ) {
52 define( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL', YEAR_IN_SECONDS );
53 }
54 //we cache the last object uploaded to cloud in memory so it can be processed without downloading again.
55 if ( ! defined( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES' ) ) {
56 define( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES', MB_IN_BYTES * 32 );
57 }
58
59 // Require Our custom AWS Autoloader file.
60
61 require_once dirname( __FILE__ ) . '/vendor/Aws3/aws-autoloader.php';
62
63 if ( ! infinite_uploads_check_requirements() ) {
64 return;
65 }
66
67 infinite_uploads_upgrade();
68
69 $instance = \ClikIT\InfiniteUploads\InfiniteUploads::get_instance();
70
71 require_once dirname( __FILE__ ) . '/functions.php';
72
73 $instance->setup();
74 }
75
76 function infinite_uploads_upgrade() {
77
78 // Install the needed DB table if not already.
79 $installed = get_site_option( 'iup_installed' );
80 if ( INFINITE_UPLOADS_VERSION != $installed ) {
81 infinite_uploads_install();
82 }
83 }
84
85 function infinite_uploads_install() {
86 global $wpdb;
87
88 //prevent race condition during upgrade by setting option before running potentially long query
89 if ( is_multisite() ) {
90 update_site_option( 'iup_installed', INFINITE_UPLOADS_VERSION );
91 } else {
92 update_option( 'iup_installed', INFINITE_UPLOADS_VERSION, true );
93 }
94
95 $charset_collate = $wpdb->get_charset_collate();
96
97 //191 is the maximum innodb default key length on utf8mb4
98 $sql = "CREATE TABLE {$wpdb->base_prefix}infinite_uploads_files (
99 `file` VARCHAR(255) NOT NULL,
100 `size` BIGINT UNSIGNED NOT NULL DEFAULT '0',
101 `modified` INT UNSIGNED NOT NULL,
102 `type` VARCHAR(20) NOT NULL,
103 `transferred` BIGINT UNSIGNED NOT NULL DEFAULT '0',
104 `synced` BOOLEAN NOT NULL DEFAULT '0',
105 `deleted` BOOLEAN NOT NULL DEFAULT '0',
106 `errors` INT UNSIGNED NOT NULL DEFAULT '0',
107 `transfer_status` TEXT NULL DEFAULT NULL,
108 PRIMARY KEY (`file`(191)),
109 KEY `type` (`type`),
110 KEY `synced` (`synced`),
111 KEY `deleted` (`deleted`)
112 ) {$charset_collate};";
113
114 if ( ! function_exists( 'dbDelta' ) ) {
115 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
116 }
117
118 return dbDelta( $sql );
119 }
120
121 /**
122 * Check whether the environment meets the plugin's requirements, like the minimum PHP version.
123 *
124 * @return bool True if the requirements are met, else false.
125 */
126 function infinite_uploads_check_requirements() {
127 global $wp_version;
128 $hook = is_multisite() ? 'network_admin_notices' : 'admin_notices';
129
130 if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) {
131 add_action( $hook, 'infinite_uploads_outdated_php_version_notice' );
132
133 return false;
134 }
135
136 if ( version_compare( $wp_version, '5.3.0', '<' ) ) {
137 add_action( $hook, 'infinite_uploads_outdated_wp_version_notice' );
138
139 return false;
140 }
141
142 return true;
143 }
144
145 /**
146 * Print an admin notice when the PHP version is not high enough.
147 *
148 * This has to be a named function for compatibility with PHP 5.2.
149 */
150 function infinite_uploads_outdated_php_version_notice() {
151 ?>
152 <div class="notice notice-warning is-dismissible"><p>
153 <?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 ); ?>
154 </p></div>
155 <?php
156 }
157
158 /**
159 * Print an admin notice when the WP version is not high enough.
160 *
161 * This has to be a named function for compatibility with PHP 5.2.
162 */
163 function infinite_uploads_outdated_wp_version_notice() {
164 global $wp_version;
165 ?>
166 <div class="notice notice-warning is-dismissible"><p>
167 <?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 ); ?>
168 </p></div>
169 <?php
170 }
171
172 /**
173 * Check if URL rewriting is enabled.
174 *
175 * @return bool
176 */
177 function infinite_uploads_enabled() {
178 return get_site_option( 'iup_enabled' );
179 }
180
181 if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
182 require_once __DIR__ . '/vendor/autoload.php';
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