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

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