Changeset 3749021
- Timestamp:
- 10/15/2026 05:25:05 PM (7 weeks ago)
- Location:
- viable-url-media-uploader/trunk
- Files:
-
- 6 edited
-
includes/class-viable-url-media-uploader.php (modified) (8 diffs)
-
includes/class-vumu-upload-handler.php (modified) (4 diffs)
-
includes/class-vumu-url-handler.php (modified) (3 diffs)
-
includes/upload-page.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
viable-url-media-uploader.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
viable-url-media-uploader/trunk/includes/class-viable-url-media-uploader.php
r3717904 r3749021 14 14 15 15 class Viable_URL_Media_Uploader { 16 16 17 17 private static $instance = null; 18 18 19 /** 20 * Load dependencies and start the plugin. 21 * 22 * @return Viable_URL_Media_Uploader 23 */ 24 public static function boot() { 25 self::load_svg_sanitizer_module(); 26 27 return self::get_instance(); 28 } 29 30 /** 31 * Load the SVG sanitizer and define availability for all upload paths. 32 */ 33 private static function load_svg_sanitizer_module() { 34 if (defined('VUMU_SVG_SANITIZER_AVAILABLE')) { 35 return; 36 } 37 38 $available = false; 39 $sanitizer_path = VUMU_PLUGIN_DIR . 'includes/class-vumu-svg-sanitizer.php'; 40 41 if (is_readable($sanitizer_path)) { 42 require_once $sanitizer_path; 43 $available = class_exists(__NAMESPACE__ . '\\VUMU_SVG_Sanitizer'); 44 } 45 46 define('VUMU_SVG_SANITIZER_AVAILABLE', $available); 47 48 if (!$available) { 49 add_action('admin_notices', array(__CLASS__, 'render_svg_sanitizer_missing_notice')); 50 } 51 } 52 53 /** 54 * Admin notice when the SVG sanitizer file is missing from the plugin package. 55 */ 56 public static function render_svg_sanitizer_missing_notice() { 57 if (!current_user_can('activate_plugins')) { 58 return; 59 } 60 61 echo '<div class="notice notice-error"><p>'; 62 echo esc_html__( 63 'Viable URL Media Uploader is missing its SVG security module (class-vumu-svg-sanitizer.php). SVG uploads are disabled until you reinstall a complete copy of the plugin.', 64 'viable-url-media-uploader' 65 ); 66 echo '</p></div>'; 67 } 68 19 69 /** 20 70 * Get plugin instance … … 47 97 add_action('admin_enqueue_scripts', array($this, 'enqueue_styles')); 48 98 add_action('admin_init', array($this, 'init_upload_handler')); 49 add_action('admin_menu', array($this, 'add_upload_page')); 50 99 $this->register_admin_menu(); 100 101 add_action('load-media_page_vumu-upload-from-url', array($this, 'on_upload_admin_page_load')); 102 51 103 // Hide admin notices from other plugins on upload page 52 104 add_action('admin_init', array($this, 'remove_admin_notices'), 999); … … 62 114 */ 63 115 private function init_svg_support() { 64 require_once VUMU_PLUGIN_DIR . 'includes/class-vumu-svg-sanitizer.php'; 116 if (!defined('VUMU_SVG_SANITIZER_AVAILABLE') || !VUMU_SVG_SANITIZER_AVAILABLE) { 117 return; 118 } 119 65 120 require_once VUMU_PLUGIN_DIR . 'includes/class-vumu-svg-support.php'; 66 121 VUMU_SVG_Support::init(); … … 75 130 public function enqueue_styles($hook) { 76 131 $allowed_hooks = array('media_page_vumu-upload-from-url'); 77 78 if (!in_array($hook, $allowed_hooks, true) ) {79 return; 80 } 81 132 133 if (!in_array($hook, $allowed_hooks, true) || $this->should_show_freemius_connect_screen()) { 134 return; 135 } 136 82 137 wp_enqueue_style( 83 138 'vumu-admin-style', … … 98 153 } 99 154 155 /** 156 * Register the Media submenu so Freemius can override it for opt-in on the same URL. 157 */ 158 private function register_admin_menu() { 159 if (function_exists('vumu_fs') && vumu_fs()) { 160 vumu_fs()->add_action('before_admin_menu_init', array($this, 'add_upload_page')); 161 return; 162 } 163 164 add_action('admin_menu', array($this, 'add_upload_page')); 165 } 166 100 167 /** 101 168 * Add upload page to media menu … … 112 179 ); 113 180 } 181 182 /** 183 * Prepare Freemius assets when the opt-in screen should appear on this admin page. 184 */ 185 public function on_upload_admin_page_load() { 186 if (!$this->should_show_freemius_connect_screen()) { 187 return; 188 } 189 190 $fs = vumu_fs(); 191 if ($fs && is_callable(array($fs, '_enqueue_connect_essentials'))) { 192 $fs->_enqueue_connect_essentials(); 193 } 194 } 195 196 /** 197 * Whether the Freemius connect / opt-in UI should replace the upload screen. 198 * 199 * @return bool 200 */ 201 private function should_show_freemius_connect_screen() { 202 if (!function_exists('vumu_fs') || !function_exists('fs_get_template')) { 203 return false; 204 } 205 206 $fs = vumu_fs(); 207 if (!$fs) { 208 return false; 209 } 210 211 if (!$fs->is_activation_mode()) { 212 return false; 213 } 214 215 if ($fs->is_registered() || $fs->is_anonymous() || $fs->is_pending_activation()) { 216 return false; 217 } 218 219 return true; 220 } 221 222 /** 223 * Output the Freemius connect template (same screen as SDK override). 224 * 225 * @return bool True when connect UI was rendered. 226 */ 227 private function render_freemius_connect_screen() { 228 if (!$this->should_show_freemius_connect_screen()) { 229 return false; 230 } 231 232 $fs = vumu_fs(); 233 if (!$fs) { 234 return false; 235 } 236 237 if (is_callable(array($fs, '_enqueue_connect_essentials'))) { 238 $fs->_enqueue_connect_essentials(); 239 } 240 241 $vars = array('id' => $fs->get_id()); 242 $connect_markup = $fs->apply_filters('templates/connect.php', fs_get_template('connect.php', $vars)); 243 244 // Freemius SDK connect screen markup (same output as Freemius::_connect_page_render()). 245 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 246 echo $connect_markup; 247 248 return true; 249 } 114 250 115 251 /** … … 125 261 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug check; no form processing. 126 262 $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; 127 if ('upload.php' === $pagenow && 'vumu-upload-from-url' === $current_page ) {263 if ('upload.php' === $pagenow && 'vumu-upload-from-url' === $current_page && !$this->should_show_freemius_connect_screen()) { 128 264 // Remove all admin notices actions 129 265 remove_all_actions('admin_notices'); … … 141 277 wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'viable-url-media-uploader')); 142 278 } 143 279 280 if ($this->render_freemius_connect_screen()) { 281 return; 282 } 283 144 284 include VUMU_PLUGIN_DIR . 'includes/upload-page.php'; 145 285 } -
viable-url-media-uploader/trunk/includes/class-vumu-upload-handler.php
r3717904 r3749021 15 15 16 16 class VUMU_Upload_Handler { 17 17 18 /** 19 * Transient key for per-user upload error messages. 20 * 21 * @return string 22 */ 23 public static function get_error_transient_key() { 24 return 'vumu_upload_error_' . get_current_user_id(); 25 } 26 27 /** 28 * Whether the current request is our plugin upload form POST. 29 * 30 * @return bool 31 */ 32 private static function is_plugin_upload_request() { 33 global $pagenow; 34 35 if ('upload.php' !== $pagenow) { 36 return false; 37 } 38 39 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug check. 40 $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; 41 if ('vumu-upload-from-url' !== $current_page) { 42 return false; 43 } 44 45 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Method check only. 46 if (!isset($_SERVER['REQUEST_METHOD']) || 'POST' !== $_SERVER['REQUEST_METHOD']) { 47 return false; 48 } 49 50 return true; 51 } 52 18 53 /** 19 54 * Handle form-based upload (non-AJAX) … … 22 57 */ 23 58 public static function handle_upload() { 24 global $pagenow; 25 26 if ('upload.php' !== $pagenow) { 59 if (!self::is_plugin_upload_request()) { 27 60 return; 28 61 } 29 62 30 63 if (!current_user_can('upload_files')) { 31 64 return; 32 65 } 33 66 34 67 if (!isset($_POST['vumu_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['vumu_nonce'])), 'vumu_upload_nonce')) { 35 68 return; … … 43 76 44 77 if (!wp_http_validate_url($url)) { 45 set_transient( 'vumu_upload_error', __('Invalid URL provided.', 'viable-url-media-uploader'), 30);78 set_transient(self::get_error_transient_key(), __('Invalid URL provided.', 'viable-url-media-uploader'), 30); 46 79 return; 47 80 } … … 54 87 55 88 if (is_wp_error($attachment_id)) { 56 set_transient( 'vumu_upload_error', $attachment_id->get_error_message(), 30);89 set_transient(self::get_error_transient_key(), $attachment_id->get_error_message(), 30); 57 90 return; 58 91 } -
viable-url-media-uploader/trunk/includes/class-vumu-url-handler.php
r3717904 r3749021 63 63 } 64 64 65 // Sanitize SVG files before sideloading66 if (!class_exists(__NAMESPACE__ . '\\VUMU_SVG_Sanitizer')) {67 require_once VUMU_PLUGIN_DIR . 'includes/class-vumu-svg-sanitizer.php';68 }69 70 65 $mime_type = isset($file_array['type']) ? $file_array['type'] : ''; 71 if (VUMU_SVG_Sanitizer::is_svg_file($file_array['tmp_name'], $mime_type)) { 66 if (self::is_svg_upload($file_array['tmp_name'], $mime_type)) { 67 if (!defined('VUMU_SVG_SANITIZER_AVAILABLE') || !VUMU_SVG_SANITIZER_AVAILABLE) { 68 wp_delete_file($file_array['tmp_name']); 69 return new \WP_Error( 70 'svg_sanitizer_unavailable', 71 __('SVG uploads are unavailable because the plugin security module is missing. Please reinstall the plugin.', 'viable-url-media-uploader') 72 ); 73 } 74 72 75 if (!VUMU_SVG_Sanitizer::sanitize_file($file_array['tmp_name'])) { 73 76 wp_delete_file($file_array['tmp_name']); … … 163 166 'redirection' => 5, 164 167 'blocking' => true, 165 'sslverify' => false168 'sslverify' => true, 166 169 )); 167 170 … … 316 319 317 320 /** 321 * Determine whether an upload is an SVG file. 322 * 323 * @param string $file_path Temporary file path. 324 * @param string $mime_type MIME type when known. 325 * @return bool 326 */ 327 private static function is_svg_upload($file_path, $mime_type = '') { 328 if (defined('VUMU_SVG_SANITIZER_AVAILABLE') && VUMU_SVG_SANITIZER_AVAILABLE) { 329 return VUMU_SVG_Sanitizer::is_svg_file($file_path, $mime_type); 330 } 331 332 $extension = strtolower(pathinfo($file_path, PATHINFO_EXTENSION)); 333 if (in_array($extension, array('svg', 'svgz'), true)) { 334 return true; 335 } 336 337 return 'image/svg+xml' === $mime_type; 338 } 339 340 /** 318 341 * Get mime type from extension 319 342 * -
viable-url-media-uploader/trunk/includes/upload-page.php
r3717904 r3749021 13 13 $vumu_assets_url = plugin_dir_url( dirname( __FILE__ ) ) . 'assets/image/'; 14 14 15 $error = get_transient( 'vumu_upload_error' ); 15 require_once VUMU_PLUGIN_DIR . 'includes/class-vumu-upload-handler.php'; 16 17 $vumu_error_key = \ahsangadit\viable_url_media_uploader\VUMU_Upload_Handler::get_error_transient_key(); 18 $error = get_transient( $vumu_error_key ); 16 19 17 20 if ( $error ) { 18 delete_transient( 'vumu_upload_error');21 delete_transient( $vumu_error_key ); 19 22 } 20 23 ?> -
viable-url-media-uploader/trunk/readme.txt
r3717904 r3749021 11 11 Tested up to: 7.1 12 12 13 Stable tag: 1.0. 113 Stable tag: 1.0.2 14 14 15 15 Requires PHP: 7.0 … … 107 107 == Changelog == 108 108 109 = 1.0.2 – 2026-10-15 = 110 111 * Ensures `includes/class-vumu-svg-sanitizer.php` is shipped with the plugin (fixes fatal error on activation in 1.0.1) 112 * Loads the SVG sanitizer at plugin bootstrap so all upload paths use the same security module 113 * Disables SVG uploads with an admin notice if the sanitizer file is missing, instead of breaking the whole plugin 114 * Security hardening: TLS verification for remote URL downloads and Freemius API, scoped upload POST handling, per-user error messages, stricter SVG URL sanitization 115 109 116 = 1.0.1 – Security Release = 110 117 … … 135 142 == Upgrade Notice == 136 143 144 = 1.0.2 = 145 146 Fixes plugin activation when the SVG sanitizer file was missing from the 1.0.1 package. Keeps SVG XSS protections from 1.0.1. 147 137 148 = 1.0.1 = 138 149 -
viable-url-media-uploader/trunk/viable-url-media-uploader.php
r3717904 r3749021 7 7 * Text Domain: viable-url-media-uploader 8 8 * Domain Path: /languages 9 * Version: 1.0. 19 * Version: 1.0.2 10 10 * Description: Add media files from URL directly to your WordPress media library with a simple input field and button in the media modal. 11 11 * Requires at least: 5.6.0 … … 13 13 * License: GPL v2 or later 14 14 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 15 * 15 * 16 16 * @package ahsangadit\viable_url_media_uploader 17 17 * @author Ahsan Gadit 18 18 */ 19 20 namespace ahsangadit\viable_url_media_uploader;21 19 22 20 if (!defined('ABSPATH')) { … … 24 22 } 25 23 26 // Define plugin constants 27 define('VUMU_VERSION', '1.0.1'); 24 if (!defined('FS_SDK__SSLVERIFY')) { 25 define('FS_SDK__SSLVERIFY', true); 26 } 27 28 if (!function_exists('vumu_fs')) { 29 /** 30 * Freemius SDK helper. 31 * 32 * @return \Freemius|null 33 */ 34 function vumu_fs() { 35 global $vumu_fs; 36 37 if (!isset($vumu_fs)) { 38 if (!defined('WP_FS__PRODUCT_41632_MULTISITE')) { 39 define('WP_FS__PRODUCT_41632_MULTISITE', true); 40 } 41 42 $freemius_start = dirname(__FILE__) . '/freemius/start.php'; 43 if (!is_readable($freemius_start)) { 44 $freemius_start = dirname(__FILE__) . '/vendor/freemius/start.php'; 45 } 46 47 if (!is_readable($freemius_start)) { 48 return null; 49 } 50 51 require_once $freemius_start; 52 53 $vumu_fs = fs_dynamic_init( 54 array( 55 'id' => '41632', 56 'slug' => 'viable-url-media-uploader', 57 'type' => 'plugin', 58 'public_key' => 'pk_c1973284c19c8858490c8b253ed87', 59 'is_premium' => false, 60 'has_addons' => false, 61 'has_paid_plans' => false, 62 'is_org_compliant' => true, 63 'menu' => array( 64 'slug' => 'vumu-upload-from-url', 65 'first-path' => 'upload.php?page=vumu-upload-from-url', 66 'account' => false, 67 'contact' => false, 68 'support' => false, 69 'parent' => array( 70 'slug' => 'upload.php', 71 ), 72 ), 73 ) 74 ); 75 } 76 77 return $vumu_fs; 78 } 79 80 vumu_fs(); 81 do_action('vumu_fs_loaded'); 82 } 83 84 define('VUMU_VERSION', '1.0.2'); 28 85 define('VUMU_PLUGIN_DIR', plugin_dir_path(__FILE__)); 29 86 define('VUMU_PLUGIN_URL', plugin_dir_url(__FILE__)); 30 87 31 // Include main plugin class32 88 require_once VUMU_PLUGIN_DIR . 'includes/class-viable-url-media-uploader.php'; 33 89 34 /** 35 * Initialize plugin 36 * 37 * @author Ahsan Gadit 38 */ 39 function vumu_init() { 40 return Viable_URL_Media_Uploader::get_instance(); 41 } 42 43 vumu_init(); 90 \ahsangadit\viable_url_media_uploader\Viable_URL_Media_Uploader::boot();
Note:
See TracChangeset
for help on using the changeset viewer.