PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / trunk
Vimeography: Vimeo Video Gallery WordPress Plugin vtrunk
2.4.9 2.4.8 trunk 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.6 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.6.8.1 0.6.9 0.6.9.1 0.6.9.2 0.7 0.8 All 103 releases
vimeography / lib / renderer.php

renderer.php in Vimeography: Vimeo Video Gallery WordPress Plugin trunk, at lib/renderer.php

227 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Vimeography;
3
4 /**
5 * The old approach was loading up the theme class, setting variables,
6 * filtering the data, loading dependencies, and rendering
7 * theme HTML server-side
8 *
9 * In 2.0, let's just make the video data
10 * available to the theme by setting it on a global javascript
11 * variable on the window and then triggering a load event on the
12 * active theme's built javascript bundle.
13 *
14 * The theme javascript can then take over from there, performing
15 * all of the tasks that used to be left up to the theme's PHP files and
16 * Mustache implementation.
17 *
18 * @return [type] [description]
19 */
20 class Renderer
21 {
22 public $version = '2.0';
23
24 public function __construct($engine)
25 {
26 $this->gallery_id = $engine->gallery_id;
27 $this->gallery_settings = $engine->gallery_settings;
28 $this->theme = $engine->theme;
29 }
30
31 /**
32 * Build the initial state for the gallery.
33 *
34 * @param array $result Vimeo API response
35 * @return $this
36 */
37 public function prepare($result)
38 {
39 $theme_name = strtolower($this->theme['name']);
40
41 $player_settings = apply_filters('vimeography.player.settings', array(
42 'dnt' => apply_filters('vimeography.player.settings.dnt', false, $this->gallery_id, $this->gallery_settings),
43 'playsinline' => apply_filters('vimeography.player.settings.playsinline', false, $this->gallery_id, $this->gallery_settings),
44 'transparent' => apply_filters('vimeography.player.settings.transparent', true, $this->gallery_id, $this->gallery_settings),
45 'responsive' => apply_filters('vimeography.player.settings.responsive', true, $this->gallery_id, $this->gallery_settings),
46 'speed' => apply_filters('vimeography.player.settings.speed', true, $this->gallery_id, $this->gallery_settings),
47 'autoplay' => apply_filters('vimeography.player.settings.autoplay', false, $this->gallery_id, $this->gallery_settings),
48 'background' => apply_filters('vimeography.player.settings.background', false, $this->gallery_id, $this->gallery_settings),
49 'muted' => apply_filters('vimeography.player.settings.muted', false, $this->gallery_id, $this->gallery_settings),
50 'loop' => apply_filters('vimeography.player.settings.loop', false, $this->gallery_id, $this->gallery_settings),
51 'pip' => apply_filters('vimeography.player.settings.pip', false, $this->gallery_id, $this->gallery_settings),
52 ));
53
54 // Set base data for every single gallery
55 $data = array(
56 'id' => $this->gallery_id,
57 'theme' => $theme_name,
58 'version' => $this->theme['version'],
59 'source' => $this->gallery_settings['source'],
60 'limit' => absint($this->gallery_settings['limit']),
61 'pages' => array(
62 'default' => array(),
63 'filter' => array()
64 ),
65 'settings' => array(
66 'player' => $player_settings
67 )
68 );
69
70 // Merge the API response from Vimeo
71 $data = array_merge($data, (array) $result);
72
73 // We won't use Vimeo's paging object, so delete it.
74 unset($data['paging']);
75
76 /**
77 * Strip the video ID from its uri and set it
78 * as the index in the video_set array.
79 *
80 * Let's also save the existing sort order to the
81 * `pages` property in the store. That way, we can
82 * always revert to it if we end up filtering the
83 * videos on the client side and want to go back "home"
84 *
85 * @since 2.0
86 */
87 foreach ($data['video_set'] as $i => $video) {
88 $id = absint(str_replace('/', '', strrchr($video->uri, '/')));
89 $data['video_set'][$id] = $video;
90 unset($data['video_set'][$i]);
91
92 $data['pages']['default'][$data['page']][] = absint($id);
93 }
94
95 // Set remaining JS variables
96 $this->data = apply_filters(
97 'vimeography.pro.localize',
98 $data,
99 $this->gallery_settings
100 );
101
102 return $this;
103 }
104
105 /**
106 * [render description]
107 * @return [type] [description]
108 */
109 public function render()
110 {
111 return $this->hydrate($this->data)->template($this->data);
112 }
113
114 /**
115 * [hydrate description]
116 * @return [type] [description]
117 */
118 protected function hydrate($data)
119 {
120 $local_data = array(
121 'l10n_print_after' => sprintf(
122 'vimeography2.galleries.%1$s["%2$s"] = %3$s',
123 $data['theme'],
124 $data['id'],
125 json_encode($data)
126 )
127 );
128
129 $theme_name = strtolower($this->theme['name']);
130 wp_register_script(
131 "vimeography-{$theme_name}",
132 $this->theme['app_js'],
133 array(),
134 false,
135 true
136 );
137
138 if (isset($this->theme['app_css'])) {
139 wp_register_style("vimeography-{$theme_name}", $this->theme['app_css']);
140 wp_enqueue_style("vimeography-{$theme_name}");
141 }
142
143 wp_add_inline_script(
144 "vimeography-{$theme_name}",
145 'var vimeographyBuildPath = "' . $this->theme['app_path'] . '";',
146 'before'
147 );
148
149 $router_mode = apply_filters('vimeography.pro.router_mode', 'abstract');
150
151 wp_add_inline_script(
152 "vimeography-{$theme_name}",
153 'var vimeographyRouterMode = "' . $router_mode . '";',
154 'before'
155 );
156
157 wp_add_inline_script(
158 "vimeography-{$theme_name}",
159 '
160 window.vimeography2 = window.vimeography2 || {};
161 window.vimeography2.galleries = window.vimeography2.galleries || {};
162 window.vimeography2.galleries.' .
163 $theme_name .
164 ' = window.vimeography2.galleries.' .
165 $theme_name .
166 ' || {};
167
168 window.vimeography2.galleries.' .
169 $data['theme'] .
170 '["' .
171 $data['id'] .
172 '"] = ' .
173 json_encode($data),
174 'before'
175 );
176
177 wp_enqueue_script("vimeography-{$theme_name}");
178 return $this;
179 }
180
181 /**
182 * [template description]
183 * @return [type] [description]
184 */
185 public function template($data)
186 {
187 $wrapper_class = 'vimeography-theme-' . esc_attr($data['theme']);
188 $wrapper_class = apply_filters(
189 'vimeography.gallery.wrapper_class',
190 $wrapper_class,
191 $data
192 );
193
194 $styles = wp_get_custom_css('vimeography_gallery_' . $data['id']); // returns css string
195 ob_start();
196 ?>
197 <?php if ($styles): ?>
198 <style type="text/css" id="vimeography-gallery-<?php esc_attr_e(
199 $data['id']
200 ); ?>-custom-css">
201 <?php echo strip_tags($styles); ?>
202 </style>
203 <?php endif; ?>
204 <div id="vimeography-gallery-<?php esc_attr_e(
205 $data['id']
206 ); ?>" class="<?php echo wp_kses_post($wrapper_class); ?>" data-version="<?php esc_attr_e($data['version']); ?>" <?php if (!empty($this->gallery_settings['width'])): ?> style="max-width: <?php esc_attr_e($this->gallery_settings['width']); ?>; margin: 0 auto;" <?php endif; ?> itemscope itemtype="http://schema.org/VideoGallery">
207 <div id="subbie">
208 <gallery></gallery>
209 </div>
210 </div>
211 <?php return ob_get_clean();
212 }
213
214 /**
215 * Output all data to the current screen.
216 *
217 * @return string
218 */
219 public function debug()
220 {
221 echo '<pre>';
222 print_r($this->data);
223 echo '</pre>';
224 die();
225 }
226 }
227