PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 2.2
Vimeography: Vimeo Video Gallery WordPress Plugin v2.2
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 2.2, at lib/renderer.php

218 lines 5.8 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 // Set base data for every single gallery
42 $data = array(
43 'id' => $this->gallery_id,
44 'theme' => $theme_name,
45 'version' => $this->theme['version'],
46 'source' => $this->gallery_settings['source'],
47 'limit' => absint($this->gallery_settings['limit']),
48 'pages' => array(
49 'default' => array(),
50 'filter' => array()
51 ),
52 'settings' => array(
53 'player' => array(
54 'dnt' => apply_filters('vimeography.player.settings.dnt', false),
55 'transparent' => apply_filters(
56 'vimeography.player.settings.transparent',
57 true
58 ),
59 'responsive' => apply_filters(
60 'vimeography.player.settings.responsive',
61 true
62 ),
63 'speed' => apply_filters('vimeography.player.settings.speed', true),
64 'playsinline' => apply_filters(
65 'vimeography.player.settings.playsinline',
66 false
67 )
68 )
69 )
70 );
71
72 // Merge the API response from Vimeo
73 $data = array_merge($data, (array) $result);
74
75 // We won't use Vimeo's paging object, so delete it.
76 unset($data['paging']);
77
78 /**
79 * Strip the video ID from its uri and set it
80 * as the index in the video_set array.
81 *
82 * Let's also save the existing sort order to the
83 * `pages` property in the store. That way, we can
84 * always revert to it if we end up filtering the
85 * videos on the client side and want to go back "home"
86 *
87 * @since 2.0
88 */
89 foreach ($data['video_set'] as $i => $video) {
90 $id = absint(str_replace('/', '', strrchr($video->uri, '/')));
91 $data['video_set'][$id] = $video;
92 unset($data['video_set'][$i]);
93
94 $data['pages']['default'][$data['page']][] = absint($id);
95 }
96
97 // Set remaining JS variables
98 $this->data = apply_filters(
99 'vimeography.pro.localize',
100 $data,
101 $this->gallery_settings
102 );
103
104 return $this;
105 }
106
107 /**
108 * [render description]
109 * @return [type] [description]
110 */
111 public function render()
112 {
113 return $this->hydrate($this->data)->template($this->data);
114 }
115
116 /**
117 * [hydrate description]
118 * @return [type] [description]
119 */
120 protected function hydrate($data)
121 {
122 $local_data = array(
123 'l10n_print_after' => sprintf(
124 'vimeography2.galleries.%1$s["%2$s"] = %3$s',
125 $data['theme'],
126 $data['id'],
127 json_encode($data)
128 )
129 );
130
131 $theme_name = strtolower($this->theme['name']);
132 wp_register_script(
133 "vimeography-{$theme_name}",
134 $this->theme['app_js'],
135 array(),
136 false,
137 true
138 );
139
140 if (isset($this->theme['app_css'])) {
141 wp_register_style("vimeography-{$theme_name}", $this->theme['app_css']);
142 wp_enqueue_style("vimeography-{$theme_name}");
143 }
144
145 wp_localize_script(
146 "vimeography-{$theme_name}",
147 'vimeographyBuildPath',
148 $this->theme['app_path']
149 );
150
151 $router_mode = apply_filters('vimeography.pro.router_mode', 'abstract');
152 wp_localize_script(
153 "vimeography-{$theme_name}",
154 'vimeographyRouterMode',
155 $router_mode
156 );
157
158 wp_localize_script(
159 "vimeography-{$theme_name}",
160 "vimeography2 = window.vimeography2 || {};
161 window.vimeography2.galleries = window.vimeography2.galleries || {};
162 window.vimeography2.galleries.{$theme_name} = window.vimeography2.galleries.{$theme_name} || {};
163 vimeography2.unused",
164 $local_data
165 );
166
167 wp_enqueue_script("vimeography-{$theme_name}");
168
169 return $this;
170 }
171
172 /**
173 * [template description]
174 * @return [type] [description]
175 */
176 public function template($data)
177 {
178 $wrapper_class = 'vimeography-theme-' . esc_attr($data['theme']);
179 $wrapper_class = apply_filters(
180 'vimeography.gallery.wrapper_class',
181 $wrapper_class,
182 $data
183 );
184
185 $styles = wp_get_custom_css('vimeography_gallery_' . $data['id']); // returns css string
186 ob_start();
187 ?>
188 <?php if ($styles): ?>
189 <style type="text/css" id="vimeography-gallery-<?php esc_attr_e(
190 $data['id']
191 ); ?>-custom-css">
192 <?php echo strip_tags($styles); ?>
193 </style>
194 <?php endif; ?>
195 <div id="vimeography-gallery-<?php esc_attr_e(
196 $data['id']
197 ); ?>" class="<?php echo $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">
198 <div id="subbie">
199 <gallery></gallery>
200 </div>
201 </div>
202 <?php return ob_get_clean();
203 }
204
205 /**
206 * Output all data to the current screen.
207 *
208 * @return string
209 */
210 public function debug()
211 {
212 echo '<pre>';
213 print_r($this->data);
214 echo '</pre>';
215 die();
216 }
217 }
218