Plugin Directory

Changeset 3373838


Ignore:
Timestamp:
10/06/2025 04:03:17 PM (6 months ago)
Author:
openvideo
Message:

Fix bug with loading js files

Location:
open-video/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • open-video/trunk/OpenVideoNamespace/Channels.php

    r3366601 r3373838  
    1616    const OPENVIDEOPLUGIN_DEFAULT_CHANNEL_PATH = 'openvideo';
    1717    const OPENVIDEOPLUGIN_CHANNEL_PATH_OPTION = 'openvideoplugin_channel_path';
     18    // Any JS files we need to load from middleton should be added here
     19    const OPENVIDEOPLUGIN_JS_FILES = [
     20        '/beardeddragon/anole.js',
     21        '/beardeddragon/drake.js',
     22        '/beardeddragon/wyrm.js',
     23        '/beardeddragon/wyvern.js',
     24        '/beardeddragon/axolotl.js',
     25        '/beardeddragon/gilamonster.js',
     26        '/beardeddragon/iguana.js',
     27    ];
    1828
    1929    const OPENVIDEOPLUGIN_ALLOWED_COOKIES = array(
     
    6373        // Add early handler specifically for video-sitemap.xml to prevent conflicts with Yoast SEO
    6474        add_action('template_redirect', array(self::class, 'openvideoplugin_early_video_sitemap_handler'), -999);
     75       
     76        // Add early handler for JS files to prevent other plugins from interfering
     77        add_action('template_redirect', array(self::class, 'openvideoplugin_early_js_handler'), -999);
    6578    }
    6679
     
    243256        // Remove the early video sitemap handler
    244257        remove_action('template_redirect', array(self::class, 'openvideoplugin_early_video_sitemap_handler'), -999);
     258       
     259        // Remove the early JS handler
     260        remove_action('template_redirect', array(self::class, 'openvideoplugin_early_js_handler'), -999);
    245261    }
    246262
     
    355371    }
    356372
     373    /**
     374     * Very early handler specifically for JS file requests
     375     * This runs before most other plugins to prevent them from interfering
     376     */
     377    public static function openvideoplugin_early_js_handler()
     378    {
     379        // Get the request URI
     380        $request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field($_SERVER['REQUEST_URI']) : '';
     381       
     382        // Parse to get just the path without query parameters
     383        $parsed = parse_url($request_uri);
     384        $path = isset($parsed['path']) ? trim($parsed['path'], '/') : '';
     385
     386        // Check if this request matches any of our JS files
     387        foreach (self::OPENVIDEOPLUGIN_JS_FILES as $js_file) {
     388            if ($path === $js_file) {
     389                // Directly handle the JS file request
     390                $response = OpenVideoPlugin_RequestUtils::openvideoplugin_get_middleton_request($js_file);
     391               
     392                if (is_wp_error($response)) {
     393                    \error_log("Open Video Plugin Error: Failed to load JS file {$js_file} from middleton: " . $response->get_error_message());
     394                    // Let WordPress handle it normally (will likely 404)
     395                    return;
     396                }
     397
     398                $headers = wp_remote_retrieve_headers($response);
     399                $status_code = wp_remote_retrieve_response_code($response);
     400                $output = wp_remote_retrieve_body($response);
     401
     402                // Set appropriate headers for JavaScript
     403                if (isset($headers['content-type'])) {
     404                    header('Content-Type: ' . $headers['content-type'], true);
     405                } else {
     406                    header('Content-Type: application/javascript; charset=utf-8', true);
     407                }
     408               
     409                // Forward other relevant headers
     410                if ($headers && is_iterable($headers)) {
     411                     $skip_headers = array('set-cookie', 'transfer-encoding', 'connection', 'content-encoding', 'content-length');
     412                   
     413                    foreach ($headers as $header_name => $header_values) {
     414                        $header_name_lower = strtolower($header_name);
     415                       
     416                        if (in_array($header_name_lower, $skip_headers)) {
     417                            continue;
     418                        }
     419                       
     420                        if (is_array($header_values)) {
     421                            foreach ($header_values as $header_value) {
     422                                header("$header_name: $header_value", false);
     423                            }
     424                        } else {
     425                            header("$header_name: $header_values", false);
     426                        }
     427                    }
     428                }
     429
     430                // Set status code
     431                http_response_code($status_code);
     432
     433                // Output the JS content and exit
     434                echo $output;
     435                exit;
     436            }
     437        }
     438    }
     439
    357440}
    358441
  • open-video/trunk/README.txt

    r3366601 r3373838  
    66Tested up to: 6.8
    77Requires PHP: 7.0
    8 Stable tag: 1.2.2
     8Stable tag: 1.2.3
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2727
    2828== Changelog ==
     29= 1.2.3 =
     30* Fix bug with loading js files
     31
    2932= 1.2.2 =
    3033* Fix /video-sitemap.xml path being bypassed
  • open-video/trunk/open-video.php

    r3366601 r3373838  
    1616 *
    1717 * @link              https://open.video/
    18  * @since             1.2.2
     18 * @since             1.2.3
    1919 * @package           Open.Video
    2020 *
     
    2323 * Plugin URI:        https://wordpress.org/plugins/open-video
    2424 * Description:       Open.Video allows you to easily embed videos to your site from the Open.Video Network.
    25  * Version:           1.2.2
     25 * Version:           1.2.3
    2626 * Requires at least: 6.1
    2727 * Requires PHP: 7.0
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define('OPENVIDEOPLUGIN_VERSION', '1.2.2');
     43define('OPENVIDEOPLUGIN_VERSION', '1.2.3');
    4444
    4545global $openvideoplugin_regex;
Note: See TracChangeset for help on using the changeset viewer.