| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class FV_Player_Facebook_Share { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
add_action('wp_head', array($this, 'fb_share_tags')); |
| 16 |
add_action('fv_flowplayer_admin_integration_options_after', array($this, 'setting'), 0); |
| 17 |
} |
| 18 |
|
| 19 |
function fb_share_tags() { |
| 20 |
global $fv_fp, $post, $FV_Player_Pro; |
| 21 |
if (!isset($fv_fp->conf['integrations']) || !isset($fv_fp->conf['integrations']['facebook_sharing']) || $fv_fp->conf['integrations']['facebook_sharing'] !== 'true' || !is_singular()) |
| 22 |
return; |
| 23 |
|
| 24 |
// Shortcodes are normally not supported in bbPress Topics so we skip these, |
| 25 |
// as all the sample shortcodes in our support forums would turn up in OG |
| 26 |
if( 'topic' == $post->post_type ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$content = $post->post_content; |
| 31 |
|
| 32 |
$matches = array(); |
| 33 |
if (!preg_match_all("/\[fvplayer[^]]*/", $content, $aMatches)) |
| 34 |
return; |
| 35 |
|
| 36 |
foreach( $aMatches[0] AS $aMatch ) { |
| 37 |
$aAtts = shortcode_parse_atts($aMatch . ' ]'); |
| 38 |
if( !isset($aAtts['src']) || !$aAtts['src'] ) continue; |
| 39 |
|
| 40 |
$sUrl = $aAtts['src']; |
| 41 |
if (empty($sUrl) || strpos($sUrl, '.mp4') === false || $fv_fp->is_secure_amazon_s3($sUrl) || isset($FV_Player_Pro) && method_exists($FV_Player_Pro, 'is_dynamic_item') && $FV_Player_Pro->is_dynamic_item($sUrl)) |
| 42 |
continue; |
| 43 |
|
| 44 |
$sUrl = preg_replace('/https?:\/\/?/', '', $sUrl); |
| 45 |
$httpUrl = 'http://' . $sUrl; |
| 46 |
$httpsUrl = 'https://' . $sUrl; |
| 47 |
|
| 48 |
$sName = get_bloginfo('name'); |
| 49 |
$sTitle = get_the_title($post); |
| 50 |
$sSplash = isset($aAtts['splash']) ? $aAtts['splash'] : false; |
| 51 |
if( !$sSplash ) { |
| 52 |
$aFeaturedImage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' ); |
| 53 |
if( isset($aFeaturedImage[0]) ) { |
| 54 |
$sSplash = $aFeaturedImage[0]; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
if( !$sSplash ) continue; |
| 59 |
|
| 60 |
$sDescription = htmlspecialchars(wp_strip_all_tags( wp_trim_words(strip_shortcodes(wp_strip_all_tags($post->post_content)), 20, ' …') ) ); |
| 61 |
|
| 62 |
?> |
| 63 |
<meta property="og:site_name" content="<?php echo esc_attr($sName); ?>"> |
| 64 |
<meta property="og:url" content="<?php echo get_permalink($post); ?>" /> |
| 65 |
<meta property="og:title" content="<?php echo esc_attr($sTitle); ?>"> |
| 66 |
<?php if( $sSplash ) : ?> |
| 67 |
<meta property="og:image" content="<?php echo esc_attr($sSplash); ?>"> |
| 68 |
<?php endif; ?> |
| 69 |
<meta property="og:description" content="<?php echo esc_attr($sDescription); ?>"> |
| 70 |
<meta property="og:type" content="video"> |
| 71 |
<meta property="og:video:url" content="<?php echo esc_attr($httpUrl); ?>"> |
| 72 |
<meta property="og:video:secure_url" content="<?php echo esc_attr($httpsUrl); ?>"> |
| 73 |
<meta property="og:video:type" content="video/mp4"> |
| 74 |
<meta property="og:video:width" content="640"> |
| 75 |
<meta property="og:video:height" content="360"> |
| 76 |
<?php |
| 77 |
break; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
function setting() { |
| 82 |
global $fv_fp; |
| 83 |
?> |
| 84 |
<tr> |
| 85 |
<td><label for="facebook_sharing">Facebook Video Sharing:</label></td> |
| 86 |
<td> |
| 87 |
<p class="description"> |
| 88 |
<input type="hidden" name="integrations[facebook_sharing]" value="false" /> |
| 89 |
<input type="checkbox" name="integrations[facebook_sharing]" id="facebook_sharing" value="true" <?php if (isset($fv_fp->conf['integrations']['facebook_sharing']) && $fv_fp->conf['integrations']['facebook_sharing'] == 'true') echo 'checked="checked"'; ?> /> |
| 90 |
<?php esc_html_e( 'When sharing your post to Facebook the first MP4 video will be shared directly rather than the post excerpt.', 'fv-player' ); ?> |
| 91 |
<span class="more"><?php echo wp_kses( __( '<strong>Requirements</strong>: video has to be on https:// and splash screen has to be present. Videos with download protection are automatically excluded.', 'fv-player' ), array( 'strong' => array() ) ); ?></span> <a href="#" class="show-more">(…)</a> |
| 92 |
</p> |
| 93 |
</td> |
| 94 |
</tr> |
| 95 |
<?php |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
$FV_Player_Facebook_Share = new FV_Player_Facebook_Share(); |
| 101 |
|