-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWVRFWP.php
171 lines (146 loc) · 4.26 KB
/
WVRFWP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* WVRFWP: WebVR for WordPress
*
* @package WVRFWP
* @author Eugenio Petullà <support@codeat.co>
* @license GPL-2.0+
* @link https://codeat.co/WVRFWP
* @copyright 2016 Eugenio Petullà - Codeat
*
* @wordpress-plugin
* Plugin Name: WVRFWP
* Plugin URI: http://codeat.co/WVRFWP
* Description: Add support for 360 photos and videos in your WordPress content and give to your users the possibility to explore them using cardboards or headsets.
* Version: 1.0.0
* Author: iGenius, codeat
* Author URI: https://codeat.co/WVRFWP
* Text Domain: WVRFWP
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( !defined( 'WPINC' ) ) {
die;
}
class WVRFWP {
protected static $instance = null;
/**
* Return the style of the aframe.
*
* @since 1.0.0
*
* @return string CSS inline style.
*/
public function wvrfwp_style_params( $width, $height, $margin, $align, $border, $border_width, $border_color ){
$style = '<style>
a-scene {
width: ' . $width . 'px;
height: ' . $height . 'px;
margin: ' . $margin . 'px;
max-width: 100%;
max-height: 1080px;';
if($align === 'left'){
$style .= 'float:left;';
}
if($align === 'right'){
$style .= 'float:right;';
}
if($align === 'center'){
$style .= 'float:none;
margin: 0 auto;';
}
if($align === 'none'){
$style .= 'float:none;';
}
$style .= '}';
if($border === 'solid' || $border === 'dashed' || $border === 'dotted'){
$style .= 'a-scene canvas {
outline: ' . $border_width . 'px ' . $border . ' ' . $border_color . ';
}';
}
$style .= '</style>';
return $style;
}
/**
* Return HTML for image VR rendering via a-frame.
*
* @since 1.0.0
*
* @return string HTML Structure for a-frame.
*/
public function wvrfwp_image_embed_shortcode( $atts ) {
$atts = extract( shortcode_atts( array(
'width' => '300',
'height' => '300',
'margin' => '10',
'align' => 'left',
'border' => '',
'border_width' => '4',
'border_color' => '333333',
'url' => '',
), $atts ) );
if (!empty($url) && is_singular()){
$html = $this->wvrfwp_style_params($width, $height, $margin, $align, $border, $border_width, $border_color);
$html .= '<a-scene embedded><a-sky src="' . $url . '" rotation="0 -130 0"></a-sky></a-scene>';
}
return $html;
}
/**
* Return HTML for video VR rendering via a-frame.
*
* @since 1.0.0
*
* @return string HTML Structure for a-frame.
*/
public function wvrfwp_video_embed_shortcode( $atts ) {
$atts = extract( shortcode_atts( array(
'width' => '300',
'height' => '300',
'margin' => '10',
'align' => 'left',
'border' => '',
'border_width' => '4',
'border_color' => '333333',
'url' => '',
), $atts ) );
if (!empty($url) && is_singular()){
$html = $this->wvrfwp_style_params($width, $height, $margin, $align, $border, $border_width, $border_color);
$html .= '<a-scene embedded>
<a-assets>
<video id="video" src="' . $url . '" autoplay loop crossorigin></video>
</a-assets>
<a-videosphere src="#video" rotation="0 180 0"></a-videosphere>
</a-scene>';
}
return $html;
}
/**
* Initialize the plugin and enqueue scripts.
*
* @since 1.0.0
*/
private function __construct() {
//add_action( 'wp_footer', array( $this, 'wvrfwp_aframe_js' ), 9999 );
wp_register_script( 'aframe', 'https://aframe.io/releases/0.3.0/aframe.min.js', array(), '0.3.0', true );
wp_enqueue_script( 'aframe' );
add_shortcode( 'vr-image', array( $this, 'wvrfwp_image_embed_shortcode' ) );
add_shortcode( 'vr-video', array( $this, 'wvrfwp_video_embed_shortcode' ) );
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
add_action( 'plugins_loaded', array( 'WVRFWP', 'get_instance' ), 9999 );