PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / trunk
WPSSO Core – Complete Schema Markup and Meta Tags vtrunk
22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / std / media / slideshare.php

slideshare.php in WPSSO Core – Complete Schema Markup and Meta Tags trunk, at lib/std/media/slideshare.php

140 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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( 'WpssoStdMediaSlideshare' ) ) {
14
15 class WpssoStdMediaSlideshare {
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 = 40 );
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 * <object type='application/x-shockwave-flash' wmode='opaque'
58 * data='http://static.slideshare.net/swf/ssplayer2.swf?id=29776875&doc=album-design-part-3-visuals-140107132112-phpapp01'
59 * width='650' height='533'>
60 */
61 if ( preg_match_all( '/<object[^<>]*? data=[\'"]([^\'"<>]+\.slideshare.net\/swf[^\'"]+)[\'"][^<>]*>/i', $content, $all_matches, PREG_SET_ORDER ) ) {
62
63 if ( $this->p->debug->enabled ) {
64
65 $this->p->debug->log( count( $all_matches ) . ' x <object/> slideshare video tag(s) found' );
66 }
67
68 foreach ( $all_matches as $media ) {
69
70 $video_url = $media[ 1 ];
71
72 if ( $this->p->debug->enabled ) {
73
74 $this->p->debug->log( 'found video URL: ' . $video_url );
75 }
76
77 $videos[] = array( 'url' => $video_url );
78 }
79
80 } elseif ( $this->p->debug->enabled ) {
81
82 $this->p->debug->log( 'no <object/> slideshare video tag(s) found' );
83 }
84
85 return $videos;
86 }
87
88 public function filter_video_details( $mt_single_video, $args, $mod ) {
89
90 if ( $this->p->debug->enabled ) {
91
92 $this->p->debug->mark();
93 }
94
95 if ( ! empty( $args[ 'attach_id' ] ) ) {
96
97 if ( $this->p->debug->enabled ) {
98
99 $this->p->debug->log( 'exiting early: have attachment ID' );
100 }
101
102 return array();
103
104 } elseif ( false === strpos( $args[ 'url' ], 'slideshare.net' ) ) { // Optimize before preg_match().
105
106 if ( $this->p->debug->enabled ) {
107
108 $this->p->debug->log( 'exiting early: "slideshare.net" string not found in video URL' );
109 }
110
111 return array();
112
113 /*
114 * This matches both the iframe and object URLs.
115 */
116 } elseif ( ! preg_match( '/^.*(slideshare\.net)\/.*(\/([0-9]+)|\?id=([0-9]+).*)$/i', $args[ 'url' ], $match ) ) {
117
118 if ( $this->p->debug->enabled ) {
119
120 $this->p->debug->log( 'exiting early: slideshare video URL pattern not found' );
121 }
122
123 return array();
124 }
125
126 if ( $this->p->debug->enabled ) {
127
128 $this->p->debug->log( 'SlideShare video URL found but no video API modules' );
129 }
130
131 if ( $this->p->notice->is_admin_pre_notices() ) {
132
133 $this->p->msgs->pro_feature_video_found_notice( _x( 'SlideShare', 'video service name', 'wpsso' ), $mod );
134 }
135
136 return array();
137 }
138 }
139 }
140