| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/) |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
|
| 10 |
die( 'These aren\'t the droids you\'re looking for.' ); |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! class_exists( 'WpssoStdMediaYoutube' ) ) { |
| 14 |
|
| 15 |
class WpssoStdMediaYoutube { |
| 16 |
|
| 17 |
private $p; // Wpsso class object. |
| 18 |
|
| 19 |
public function __construct( &$plugin ) { |
| 20 |
|
| 21 |
$this->p =& $plugin; |
| 22 |
|
| 23 |
if ( $this->p->debug->enabled ) { |
| 24 |
|
| 25 |
$this->p->debug->mark(); |
| 26 |
} |
| 27 |
|
| 28 |
/* |
| 29 |
* Filter priorities: |
| 30 |
* |
| 31 |
* 10 = Youtube Videos. |
| 32 |
* 20 = Vimeo Videos. |
| 33 |
* 30 = Wistia Videos. |
| 34 |
* 40 = Slideshare Presentations. |
| 35 |
* 60 = Facebook Videos. |
| 36 |
* 80 = Soundcloud Tracks. |
| 37 |
* 100 = WP Media Library Video Blocks. |
| 38 |
* 110 = WP Media Library Video Shortcodes. |
| 39 |
* 1000 = Gravatar Images. |
| 40 |
*/ |
| 41 |
$this->p->util->add_plugin_filters( $this, array( |
| 42 |
'video_details' => 3, |
| 43 |
), $prio = 10 ); |
| 44 |
} |
| 45 |
|
| 46 |
public function filter_video_details( $mt_single_video, $args, $mod ) { |
| 47 |
|
| 48 |
if ( $this->p->debug->enabled ) { |
| 49 |
|
| 50 |
$this->p->debug->mark(); |
| 51 |
} |
| 52 |
|
| 53 |
if ( ! empty( $args[ 'attach_id' ] ) ) { |
| 54 |
|
| 55 |
if ( $this->p->debug->enabled ) { |
| 56 |
|
| 57 |
$this->p->debug->log( 'exiting early: have attachment ID' ); |
| 58 |
} |
| 59 |
|
| 60 |
return array(); |
| 61 |
|
| 62 |
} elseif ( false === strpos( $args[ 'url' ], 'youtu' ) ) { // Optimize before preg_match(). |
| 63 |
|
| 64 |
if ( $this->p->debug->enabled ) { |
| 65 |
|
| 66 |
$this->p->debug->log( 'exiting early: "youtu" string not found in video URL' ); |
| 67 |
} |
| 68 |
|
| 69 |
return array(); |
| 70 |
|
| 71 |
} elseif ( ! preg_match( '/^.*(youtube\.com|youtube-nocookie\.com|youtu\.be)\/(watch\/?\?v=)?([^\?\&\#<>]+)' . |
| 72 |
'(\?(list)=([^\?\&\#<>]+)|.*)$/', $args[ 'url' ], $match ) ) { |
| 73 |
|
| 74 |
if ( $this->p->debug->enabled ) { |
| 75 |
|
| 76 |
$this->p->debug->log( 'exiting early: youtube video URL pattern not found' ); |
| 77 |
} |
| 78 |
|
| 79 |
return array(); |
| 80 |
} |
| 81 |
|
| 82 |
if ( $this->p->debug->enabled ) { |
| 83 |
|
| 84 |
$this->p->debug->log( 'YouTube video URL found but no video API modules' ); |
| 85 |
} |
| 86 |
|
| 87 |
if ( $this->p->notice->is_admin_pre_notices() ) { |
| 88 |
|
| 89 |
$this->p->msgs->pro_feature_video_found_notice( _x( 'YouTube', 'video service name', 'wpsso' ), $mod ); |
| 90 |
} |
| 91 |
|
| 92 |
return array(); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|