| @@ -1,0 +1,107 @@ | ||
| 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( 'WpssoStdMediaFacebook' ) ) { | |
| 14 | + | |
| 15 | + class WpssoStdMediaFacebook { | |
| 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 = 60 ); | |
| 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' ], 'facebook.com' ) ) { // Optimize before preg_match(). | |
| 63 | + | |
| 64 | + if ( $this->p->debug->enabled ) { | |
| 65 | + | |
| 66 | + $this->p->debug->log( 'exiting early: "facebook.com" string not found in video URL' ); | |
| 67 | + } | |
| 68 | + | |
| 69 | + return array(); | |
| 70 | + | |
| 71 | + /* | |
| 72 | + * Note that forward-slashes in the 'href' query value are encoded as %2F. | |
| 73 | + * | |
| 74 | + * Example: https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Ffacebook%2Fvideos%2F10153231379946729%2F&width=500&show_text=false&appId=525239184171769&height=281 | |
| 75 | + */ | |
| 76 | + } elseif ( preg_match( '/^.*(facebook\.com)\/plugins\/video.php\?href=([^\/\?\&\#<>]+).*$/', $args[ 'url' ], $match ) ) { | |
| 77 | + | |
| 78 | + if ( $this->p->debug->enabled ) { | |
| 79 | + | |
| 80 | + $this->p->debug->log( 'Facebook video URL found but no video API modules' ); | |
| 81 | + } | |
| 82 | + | |
| 83 | + if ( $this->p->notice->is_admin_pre_notices() ) { | |
| 84 | + | |
| 85 | + $this->p->msgs->pro_feature_video_found_notice( _x( 'Facebook', 'video service name', 'wpsso' ), $mod ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /* | |
| 89 | + * Example: https://www.facebook.com/DrDainHeer/videos/943226206036691/ | |
| 90 | + */ | |
| 91 | + } elseif ( preg_match( '/^(.*facebook\.com\/.*\/videos\/[^\?\#]+).*$/', $args[ 'url' ], $match ) ) { | |
| 92 | + | |
| 93 | + if ( $this->p->debug->enabled ) { | |
| 94 | + | |
| 95 | + $this->p->debug->log( 'Facebook video URL found but no video API modules' ); | |
| 96 | + } | |
| 97 | + | |
| 98 | + if ( $this->p->notice->is_admin_pre_notices() ) { | |
| 99 | + | |
| 100 | + $this->p->msgs->pro_feature_video_found_notice( _x( 'Facebook', 'video service name', 'wpsso' ), $mod ); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + return array(); | |
| 105 | + } | |
| 106 | + } | |
| 107 | +} | |