<?php /** * VR Viewer Shortcode * converts [vr] shortcode to an iframe viewer hosted on vr.me.sh * * @package automattic/jetpack */ /** * Scrub URL paramaters for VR viewer * * @param array $params { * parameter array which is passed to the jetpack_vr_viewer. * * @type string $url url of 360 media * @type string $guid guid for videopress * @type string $view cinema, 360 - controls if panaroma view, or 360 * @type string $rotation number for rotating media * @type string $preview show preview image or not * } * * @return array|false $url_params Array of URL parameters. */ function jetpack_vr_viewer_get_viewer_url_params( $params ) { $url_params = array(); if ( isset( $params['rotation'] ) ) { $url_params['rotation'] = (int) $params['rotation']; } if ( isset( $params['view'] ) && in_array( $params['view'], array( 'cinema', '360' ), true ) ) { $url_params['view'] = $params['view']; } if ( isset( $params['preview'] ) && $params['preview'] ) { $url_params['preview'] = 1; } if ( isset( $params['url'] ) ) { return array_merge( $url_params, array( 'url' => $params['url'] ) ); } elseif ( isset( $params['guid'] ) ) { return array_merge( $url_params, array( 'guid' => $params['guid'] ) ); } return false; } /** * Get padding for IFRAME depending on view type * * @param string $view string cinema, 360 - default cinema. * * @return string $css padding */ function jetpack_vr_viewer_iframe_padding( $view ) { if ( '360' === $view ) { return '100%'; // 1:1 square aspect for 360 } return '50%'; // 2:1 panorama aspect } /** * Create HTML for VR Viewer IFRAME and wrapper * The viewer code is hosted on vr.me.sh site which is then displayed * within posts via an IFRAME. This function returns the IFRAME html. * * @param array $url_params { * parameter array which is passed to the jetpack_vr_viewer. * * @type string $url url of 360 media * @type string $guid guid for videopress * @type string $view cinema, 360 - controls if panaroma view, or 360 * @type string $rotation number for rotating media * @type string $preview show preview image or not * } * * @return string $rtn an iframe for viewer. */ function jetpack_vr_viewer_get_html( $url_params ) { global $content_width; $iframe = add_query_arg( $url_params, 'https://vr.me.sh/view/' ); // set some defaults. $maxwidth = ( is_numeric( $content_width ) && $content_width > 0 ) ? $content_width : 720; $view = ( isset( $url_params['view'] ) ) ? $url_params['view'] : 'cinema'; // If the shortcode is displayed in a WPCOM notification, display a simple link only. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { require_once WP_CONTENT_DIR . '/lib/display-context.php'; $context = A8C\Display_Context\get_current_context(); if ( A8C\Display_Context\NOTIFICATIONS === $context ) { return sprintf( '<a href="%1$s" target="_blank" rel="noopener noreferrer">%1$s</a>', esc_url( $iframe ) ); } } $rtn = '<div style="position: relative; max-width: ' . $maxwidth . 'px; margin-left: auto; margin-right: auto; overflow: hidden; margin-bottom: 1em;">'; $rtn .= '<div style="padding-top: ' . jetpack_vr_viewer_iframe_padding( $view ) . ';"></div>'; $rtn .= '<iframe style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; height: 100%" allowfullscreen="true" frameborder="0" width="100%" height="300" src="' . esc_url( $iframe ) . '">'; $rtn .= '</iframe>'; $rtn .= '</div>'; return $rtn; } /** * Convert [vr] shortcode to viewer * * Shortcode example: * [vr url="https://en-blog.files.wordpress.com/2016/12/regents_park.jpg" view="360"] * * VR Viewer embed code: * <div style="position: relative; max-width: 720px; margin-left: auto; margin-right: auto; overflow: hidden;"> * <div style="padding-top: 100%;"></div> * <iframe style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; height: 100%" allowfullscreen="true" frameborder="0" width="100%" height="400" src="https://vr.me.sh/view/?view=360&url=https://en-blog.files.wordpress.com/2016/12/regents_park.jpg"> * </iframe> * </div> * * @param array $atts Shortcode attributes. * * @return html - complete vr viewer html */ function jetpack_vr_viewer_shortcode( $atts ) { $params = shortcode_atts( array( 0 => null, 'url' => null, 'src' => null, 'guid' => null, 'rotation' => null, 'view' => null, 'preview' => false, ), $atts ); // We offer a few ways to specify the URL. if ( $params[0] ) { $params['url'] = $params[0]; } elseif ( $params['src'] ) { $params['url'] = $params['src']; } $url_params = jetpack_vr_viewer_get_viewer_url_params( $params ); if ( $url_params ) { return jetpack_vr_viewer_get_html( $url_params ); } // add check for user. if ( current_user_can( 'edit_posts' ) ) { return '[vr] shortcode requires a data source to be given'; } else { return ''; } } add_shortcode( 'vr', 'jetpack_vr_viewer_shortcode' );
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
css | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
img | Folder | 0755 |
|
|
js | Folder | 0755 |
|
|
archiveorg-book.php | File | 3.31 KB | 0644 |
|
archiveorg.php | File | 3.92 KB | 0644 |
|
archives.php | File | 2.38 KB | 0644 |
|
bandcamp.php | File | 7.75 KB | 0644 |
|
brightcove.php | File | 8.77 KB | 0644 |
|
cartodb.php | File | 803 B | 0644 |
|
class.filter-embedded-html-objects.php | File | 13.01 KB | 0644 |
|
codepen.php | File | 265 B | 0644 |
|
crowdsignal.php | File | 21.6 KB | 0644 |
|
dailymotion.php | File | 15.27 KB | 0644 |
|
descript.php | File | 3 KB | 0644 |
|
facebook.php | File | 4.41 KB | 0644 |
|
flatio.php | File | 383 B | 0644 |
|
flickr.php | File | 9.29 KB | 0644 |
|
getty.php | File | 7.54 KB | 0644 |
|
gist.php | File | 8.31 KB | 0644 |
|
googleapps.php | File | 9.84 KB | 0644 |
|
googlemaps.php | File | 7.97 KB | 0644 |
|
googleplus.php | File | 1.03 KB | 0644 |
|
gravatar.php | File | 6.13 KB | 0644 |
|
houzz.php | File | 920 B | 0644 |
|
inline-pdfs.php | File | 1.14 KB | 0644 |
|
instagram.php | File | 14.5 KB | 0644 |
|
kickstarter.php | File | 2.39 KB | 0644 |
|
mailchimp.php | File | 7.03 KB | 0644 |
|
medium.php | File | 3.22 KB | 0644 |
|
mixcloud.php | File | 3.62 KB | 0644 |
|
others.php | File | 2.04 KB | 0644 |
|
pinterest.php | File | 1.79 KB | 0644 |
|
presentations.php | File | 14.53 KB | 0644 |
|
quiz.php | File | 9.16 KB | 0644 |
|
recipe.php | File | 18.95 KB | 0644 |
|
scribd.php | File | 2.45 KB | 0644 |
|
sitemap.php | File | 562 B | 0644 |
|
slideshare.php | File | 3.81 KB | 0644 |
|
slideshow.php | File | 8.93 KB | 0644 |
|
smartframe.php | File | 3.64 KB | 0644 |
|
soundcloud.php | File | 8.68 KB | 0644 |
|
spotify.php | File | 3.21 KB | 0644 |
|
ted.php | File | 3.35 KB | 0644 |
|
tweet.php | File | 5.03 KB | 0644 |
|
twitchtv.php | File | 2.63 KB | 0644 |
|
twitter-timeline.php | File | 1.93 KB | 0644 |
|
unavailable.php | File | 3.24 KB | 0644 |
|
untappd-menu.php | File | 2.41 KB | 0644 |
|
upcoming-events.php | File | 1.68 KB | 0644 |
|
ustream.php | File | 3.13 KB | 0644 |
|
videopress.php | File | 423 B | 0644 |
|
vimeo.php | File | 11.13 KB | 0644 |
|
vine.php | File | 2.61 KB | 0644 |
|
vr.php | File | 4.92 KB | 0644 |
|
wordads.php | File | 1.81 KB | 0644 |
|
wufoo.php | File | 3.38 KB | 0644 |
|
youtube.php | File | 20.54 KB | 0644 |
|