| 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( 'WpssoStdMediaWistia' ) ) { |
| 14 |
|
| 15 |
class WpssoStdMediaWistia { |
| 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 |
'content_videos' => 2, |
| 43 |
'video_details' => 3, |
| 44 |
), $prio = 30 ); |
| 45 |
} |
| 46 |
|
| 47 |
public function filter_content_videos( $videos, $content ) { |
| 48 |
|
| 49 |
if ( $this->p->debug->enabled ) { |
| 50 |
|
| 51 |
$this->p->debug->mark(); |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* Example: |
| 56 |
* |
| 57 |
* <div id="wistia_wb36s0vwcg" class="wistia_embed" style="width:640px;height:360px;"> </div> |
| 58 |
* |
| 59 |
* <div class="wistia_embed wistia_async_j38ihh83m5" style="height:349px;width:620px"> |
| 60 |
*/ |
| 61 |
if ( preg_match_all( '/<div[^<>]*? (id=[\'"]wistia_([^\'"<>]+)[\'"][^<>]* class=[\'"]wistia_embed[\'"]|' . |
| 62 |
'class=[\'"]wistia_embed wistia_async_([^\'"<>]+)[^\'"]*[\'"])[^<>]*>/i', $content, |
| 63 |
$all_matches, PREG_SET_ORDER ) ) { |
| 64 |
|
| 65 |
if ( $this->p->debug->enabled ) { |
| 66 |
|
| 67 |
$this->p->debug->log( count( $all_matches ) . ' x <div/> wistia_embed video tag(s) found' ); |
| 68 |
} |
| 69 |
|
| 70 |
foreach ( $all_matches as $media ) { |
| 71 |
|
| 72 |
$video_url = 'http://fast.wistia.net/embed/iframe/' . ( empty( $media[ 2 ] ) ? $media[ 3 ] : $media[ 2 ] ); |
| 73 |
|
| 74 |
if ( $this->p->debug->enabled ) { |
| 75 |
|
| 76 |
$this->p->debug->log( 'found video URL: ' . $video_url ); |
| 77 |
} |
| 78 |
|
| 79 |
$videos[] = array( 'url' => $video_url ); |
| 80 |
} |
| 81 |
|
| 82 |
} elseif ( $this->p->debug->enabled ) { |
| 83 |
|
| 84 |
$this->p->debug->log( 'no <div/> wistia_embed video tag(s) found' ); |
| 85 |
} |
| 86 |
|
| 87 |
/* |
| 88 |
* example: <a href="//fast.wistia.net/embed/iframe/wb36s0vwcg?popover=true" class="wistia-popover[height=360,playerColor=7b796a,width=640]"> |
| 89 |
*/ |
| 90 |
if ( preg_match_all( '/<a[^<>]*? href=[\'"]([^\'"]+)[\'"][^<>]* class=[\'"]wistia-popover\[([^\]]+)\][\'"][^<>]*>/i', |
| 91 |
$content, $all_matches, PREG_SET_ORDER ) ) { |
| 92 |
|
| 93 |
if ( $this->p->debug->enabled ) { |
| 94 |
|
| 95 |
$this->p->debug->log( count( $all_matches ) . ' x <a/> wistia-popover video tag(s) found' ); |
| 96 |
} |
| 97 |
|
| 98 |
foreach ( $all_matches as $media ) { |
| 99 |
|
| 100 |
$video_url = $media[ 1 ]; |
| 101 |
|
| 102 |
if ( $this->p->debug->enabled ) { |
| 103 |
|
| 104 |
$this->p->debug->log( 'found video URL: ' . $video_url ); |
| 105 |
} |
| 106 |
|
| 107 |
$videos[] = array( 'url' => $video_url ); |
| 108 |
} |
| 109 |
|
| 110 |
} elseif ( $this->p->debug->enabled ) { |
| 111 |
|
| 112 |
$this->p->debug->log( 'no <a/> wistia-popover video tag(s) found' ); |
| 113 |
} |
| 114 |
|
| 115 |
return $videos; |
| 116 |
} |
| 117 |
|
| 118 |
public function filter_video_details( $mt_single_video, $args, $mod ) { |
| 119 |
|
| 120 |
if ( $this->p->debug->enabled ) { |
| 121 |
|
| 122 |
$this->p->debug->mark(); |
| 123 |
} |
| 124 |
|
| 125 |
if ( ! empty( $args[ 'attach_id' ] ) ) { |
| 126 |
|
| 127 |
if ( $this->p->debug->enabled ) { |
| 128 |
|
| 129 |
$this->p->debug->log( 'exiting early: have attachment ID' ); |
| 130 |
} |
| 131 |
|
| 132 |
return array(); |
| 133 |
|
| 134 |
} elseif ( false === strpos( $args[ 'url' ], 'wistia' ) ) { // Optimize before preg_match(). |
| 135 |
|
| 136 |
if ( false === strpos( $args[ 'url' ], 'wi.st' ) ) { // Optimize before preg_match(). |
| 137 |
|
| 138 |
if ( $this->p->debug->enabled ) { |
| 139 |
|
| 140 |
$this->p->debug->log( 'exiting early: "wistia" or "wi.st" string not found in video URL' ); |
| 141 |
} |
| 142 |
|
| 143 |
return array(); |
| 144 |
} |
| 145 |
|
| 146 |
} elseif ( ! preg_match( '/^.*(wistia\.net|wistia\.com|wi\.st)\/([^\?\&\#<>]+).*$/i', $args[ 'url' ], $match ) ) { |
| 147 |
|
| 148 |
if ( $this->p->debug->enabled ) { |
| 149 |
|
| 150 |
$this->p->debug->log( 'exiting early: wistia video URL pattern not found' ); |
| 151 |
} |
| 152 |
|
| 153 |
return array(); |
| 154 |
} |
| 155 |
|
| 156 |
if ( $this->p->debug->enabled ) { |
| 157 |
|
| 158 |
$this->p->debug->log( 'Wistia video URL found but no video API modules' ); |
| 159 |
} |
| 160 |
|
| 161 |
if ( $this->p->notice->is_admin_pre_notices() ) { |
| 162 |
|
| 163 |
$this->p->msgs->pro_feature_video_found_notice( _x( 'Wistia', 'video service name', 'wpsso' ), $mod ); |
| 164 |
} |
| 165 |
|
| 166 |
return array(); |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|