Plugin Directory

Changeset 3749021


Ignore:
Timestamp:
10/15/2026 05:25:05 PM (7 weeks ago)
Author:
ahsangadit
Message:

Update plugin to version 1.0.2

Location:
viable-url-media-uploader/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • viable-url-media-uploader/trunk/includes/class-viable-url-media-uploader.php

    r3717904 r3749021  
    1414
    1515class Viable_URL_Media_Uploader {
    16    
     16
    1717    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
    1969    /**
    2070     * Get plugin instance
    … …  
    4797        add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'));
    4898        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
    51103        // Hide admin notices from other plugins on upload page
    52104        add_action('admin_init', array($this, 'remove_admin_notices'), 999);
    … …  
    62114     */
    63115    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
    65120        require_once VUMU_PLUGIN_DIR . 'includes/class-vumu-svg-support.php';
    66121        VUMU_SVG_Support::init();
    … …  
    75130    public function enqueue_styles($hook) {
    76131        $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
    82137        wp_enqueue_style(
    83138            'vumu-admin-style',
    … …  
    98153    }
    99154   
     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
    100167    /**
    101168     * Add upload page to media menu
    … …  
    112179        );
    113180    }
     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    }
    114250   
    115251    /**
    … …  
    125261        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug check; no form processing.
    126262        $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()) {
    128264            // Remove all admin notices actions
    129265            remove_all_actions('admin_notices');
    … …  
    141277            wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'viable-url-media-uploader'));
    142278        }
    143        
     279
     280        if ($this->render_freemius_connect_screen()) {
     281            return;
     282        }
     283
    144284        include VUMU_PLUGIN_DIR . 'includes/upload-page.php';
    145285    }
  • viable-url-media-uploader/trunk/includes/class-vumu-upload-handler.php

    r3717904 r3749021  
    1515
    1616class 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
    1853    /**
    1954     * Handle form-based upload (non-AJAX)
    … …  
    2257     */
    2358    public static function handle_upload() {
    24         global $pagenow;
    25        
    26         if ('upload.php' !== $pagenow) {
     59        if (!self::is_plugin_upload_request()) {
    2760            return;
    2861        }
    29        
     62
    3063        if (!current_user_can('upload_files')) {
    3164            return;
    3265        }
    33        
     66
    3467        if (!isset($_POST['vumu_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['vumu_nonce'])), 'vumu_upload_nonce')) {
    3568            return;
    … …  
    4376       
    4477        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);
    4679            return;
    4780        }
    … …  
    5487       
    5588        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);
    5790            return;
    5891        }
  • viable-url-media-uploader/trunk/includes/class-vumu-url-handler.php

    r3717904 r3749021  
    6363        }
    6464
    65         // Sanitize SVG files before sideloading
    66         if (!class_exists(__NAMESPACE__ . '\\VUMU_SVG_Sanitizer')) {
    67             require_once VUMU_PLUGIN_DIR . 'includes/class-vumu-svg-sanitizer.php';
    68         }
    69 
    7065        $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
    7275            if (!VUMU_SVG_Sanitizer::sanitize_file($file_array['tmp_name'])) {
    7376                wp_delete_file($file_array['tmp_name']);
    … …  
    163166            'redirection' => 5,
    164167            'blocking' => true,
    165             'sslverify' => false
     168            'sslverify' => true,
    166169        ));
    167170       
    … …  
    316319   
    317320    /**
     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    /**
    318341     * Get mime type from extension
    319342     *
  • viable-url-media-uploader/trunk/includes/upload-page.php

    r3717904 r3749021  
    1313$vumu_assets_url = plugin_dir_url( dirname( __FILE__ ) ) . 'assets/image/';
    1414
    15 $error = get_transient( 'vumu_upload_error' );
     15require_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 );
    1619
    1720if ( $error ) {
    18         delete_transient( 'vumu_upload_error' );
     21        delete_transient( $vumu_error_key );
    1922}
    2023?>
  • viable-url-media-uploader/trunk/readme.txt

    r3717904 r3749021  
    1111Tested up to: 7.1
    1212
    13 Stable tag: 1.0.1
     13Stable tag: 1.0.2
    1414
    1515Requires PHP: 7.0
    … …  
    107107== Changelog ==
    108108
     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
    109116= 1.0.1 – Security Release =
    110117
    … …  
    135142== Upgrade Notice ==
    136143
     144= 1.0.2 =
     145
     146Fixes plugin activation when the SVG sanitizer file was missing from the 1.0.1 package. Keeps SVG XSS protections from 1.0.1.
     147
    137148= 1.0.1 =
    138149
  • viable-url-media-uploader/trunk/viable-url-media-uploader.php

    r3717904 r3749021  
    77 * Text Domain: viable-url-media-uploader
    88 * Domain Path: /languages
    9  * Version: 1.0.1
     9 * Version: 1.0.2
    1010 * Description: Add media files from URL directly to your WordPress media library with a simple input field and button in the media modal.
    1111 * Requires at least: 5.6.0
    … …  
    1313 * License: GPL v2 or later
    1414 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    15  * 
     15 *
    1616 * @package ahsangadit\viable_url_media_uploader
    1717 * @author Ahsan Gadit
    1818 */
    19 
    20 namespace ahsangadit\viable_url_media_uploader;
    2119
    2220if (!defined('ABSPATH')) {
    … …  
    2422}
    2523
    26 // Define plugin constants
    27 define('VUMU_VERSION', '1.0.1');
     24if (!defined('FS_SDK__SSLVERIFY')) {
     25    define('FS_SDK__SSLVERIFY', true);
     26}
     27
     28if (!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
     84define('VUMU_VERSION', '1.0.2');
    2885define('VUMU_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2986define('VUMU_PLUGIN_URL', plugin_dir_url(__FILE__));
    3087
    31 // Include main plugin class
    3288require_once VUMU_PLUGIN_DIR . 'includes/class-viable-url-media-uploader.php';
    3389
    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.