PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 2.4.9
Vimeography: Vimeo Video Gallery WordPress Plugin v2.4.9
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 / admin / controllers / gallery / edit.php

edit.php in Vimeography: Vimeo Video Gallery WordPress Plugin 2.4.9, at lib/admin/controllers/gallery/edit.php

321 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Vimeography_Gallery_Edit extends Vimeography_Base
4 {
5 /**
6 * Current loaded gallery
7 *
8 * @var array
9 */
10 protected $_gallery = array();
11
12 /**
13 * Current gallery ID set by GET param
14 *
15 * @var int
16 */
17 protected $_gallery_id;
18
19 /**
20 * Cache class instance.
21 *
22 * @var object
23 */
24 protected $_cache;
25
26 /**
27 * The settings defined in the theme settings file
28 *
29 * @since 1.3
30 * @var array
31 */
32 protected $_theme_settings;
33
34 public function __construct()
35 {
36 // Backwards compatibility
37 if (!isset($this->_gallery[0])) {
38 $this->_gallery[0] = new StdClass();
39 }
40
41 $this->_gallery_id = intval($_GET['id']);
42
43 if (isset($_GET['debug'])) {
44 $logged_contents = get_site_transient(
45 "vimeography_gallery_" . $this->_gallery_id . "_response"
46 );
47
48 echo "<pre>";
49 var_dump($logged_contents);
50 echo "</pre>";
51 die();
52 }
53
54 $this->load_gallery();
55
56 require_once VIMEOGRAPHY_PATH . 'lib/deprecated/cache.php';
57 $this->_cache = new \Vimeography_Cache($this->_gallery_id);
58
59 add_action('vimeography_action_refresh_gallery_cache', array(
60 $this,
61 'vimeography_refresh_gallery_cache'
62 ));
63 add_action('vimeography_action_refresh_gallery_appearance', array(
64 $this,
65 'vimeography_refresh_gallery_appearance'
66 ));
67 add_action('vimeography_action_set_gallery_theme', array(
68 $this,
69 'vimeography_set_gallery_theme'
70 ));
71
72 add_action('vimeography/reload-gallery', array($this, 'load_gallery'));
73
74 if (isset($_GET['created']) && $_GET['created'] == 1) {
75 $this->messages[] = array(
76 'type' => 'updated',
77 'heading' => __('Gallery created.', 'vimeography'),
78 'message' => __('Well, that was easy.', 'vimeography')
79 );
80 }
81 }
82
83 /**
84 * Load gallery on page load - this is also available through
85 * the `vimeography/reload-gallery` action.
86 *
87 * @since 1.3
88 * @return void
89 */
90 public function load_gallery()
91 {
92 global $wpdb;
93
94 $this->_gallery = $wpdb->get_results(
95 $wpdb->prepare(
96 '
97 SELECT *
98 FROM ' . $wpdb->vimeography_gallery_meta . ' AS meta
99 JOIN ' . $wpdb->vimeography_gallery . ' AS gallery
100 ON meta.gallery_id = gallery.id
101 WHERE meta.gallery_id = %d
102 LIMIT 1;
103 ',
104 $this->_gallery_id
105 )
106 );
107
108 if (!$this->_gallery) {
109 $this->messages[] = array(
110 'type' => 'error',
111 'heading' => __('Uh oh.', 'vimeography'),
112 'message' => __(
113 "That gallery no longer exists. It's gone. Kaput!",
114 'vimeography'
115 )
116 );
117 } else {
118 if (strtolower($this->_gallery[0]->theme_name) === 'bugsauce') {
119 $this->messages[] = array(
120 'type' => 'error',
121 'heading' => __('Heads up!', 'vimeography'),
122 'message' => __(
123 "The Bugsauce gallery theme has been discontinued in Vimeography 2. We recommend switching over to the free Harvestone gallery theme.",
124 'vimeography'
125 )
126 );
127 }
128
129 try {
130 $theme = self::_set_active_theme($this->_gallery[0]->theme_name);
131 } catch (Exception $e) {
132 $this->messages[] = array(
133 'type' => 'error',
134 'heading' => __('Heads up!', 'vimeography'),
135 'message' => $e->getMessage()
136 );
137 }
138 }
139
140 $this->_gallery[0]->featured_video =
141 $this->_gallery[0]->featured_video === 0
142 ? ''
143 : $this->_gallery[0]->featured_video;
144
145 // Backwards compatibility
146 $this->_gallery = apply_filters(
147 'vimeography/deprecated/reload-pro-gallery-settings',
148 $this,
149 $this->_gallery
150 );
151 }
152
153 /**
154 * [_set_active_theme description]
155 * @since 1.3
156 * @param string $theme_name [description]
157 * @return array Theme meta
158 */
159 private static function _set_active_theme($theme_name)
160 {
161 $vimeography = Vimeography::get_instance();
162 $vimeography->addons->set_active_theme($theme_name);
163 return $vimeography->addons->active_theme;
164 }
165
166 /**
167 * Removes the cache file associated with the loaded gallery.
168 *
169 * @return void
170 */
171 public function vimeography_refresh_gallery_cache()
172 {
173 $this->nonceSecurityCheck("nonce_refresh_gallery_cache");
174 if ($this->_cache->exists()) {
175 $this->_cache->delete();
176 }
177
178 $this->messages[] = array(
179 'type' => 'updated',
180 'heading' => __('So fresh.', 'vimeography'),
181 'message' => __('Your videos have been refreshed.', 'vimeography')
182 );
183 }
184
185 /**
186 * nonceSecurityCheck
187 * Check nonce value in the session.
188 *
189 * @param mixed $nonceKey
190 * @return void
191 */
192 private function nonceSecurityCheck($nonceKey){
193 // Vérifier que le nonce existe dans la session
194 if (!isset($_SESSION[$nonceKey])) {
195 wp_die(__('Security check failed.', 'vimeography'));
196 }
197
198 // Vérifier le nonce avec wp_verify_nonce pour plus de sécurité
199 if (!wp_verify_nonce($_SESSION[$nonceKey], $nonceKey)) {
200 wp_die(__('Security check failed.', 'vimeography'));
201 }
202
203 unset($_SESSION[$nonceKey]);
204 }
205
206 /**
207 * Removes the custom CSS file associated with
208 * the current gallery, if it exists.
209 *
210 * @return void
211 */
212 public function vimeography_refresh_gallery_appearance()
213 {
214 $this->nonceSecurityCheck("nonce_refresh_gallery_appearance");
215 if (
216 file_exists(
217 VIMEOGRAPHY_CUSTOMIZATIONS_PATH .
218 'vimeography-gallery-' .
219 $this->_gallery_id .
220 '-custom.css'
221 )
222 ) {
223 unlink(
224 VIMEOGRAPHY_CUSTOMIZATIONS_PATH .
225 'vimeography-gallery-' .
226 $this->_gallery_id .
227 '-custom.css'
228 );
229 }
230
231 $this->messages[] = array(
232 'type' => 'updated',
233 'heading' => __('Theme settings cleared.', 'vimeography'),
234 'message' => __('Your gallery appearance has been reset.', 'vimeography')
235 );
236 }
237
238 /**
239 * Returns the gallery settings to the gallery editor template
240 *
241 * @since 1.3
242 * @return array
243 */
244 public function gallery()
245 {
246 return apply_filters('vimeography/gallery-settings', $this->_gallery);
247 }
248
249 /**
250 * Switches to the selected gallery theme
251 *
252 * @param array $input posted values
253 * @return void
254 */
255 public function vimeography_set_gallery_theme($input)
256 {
257 $this->nonceSecurityCheck("nonce_set_gallery_theme");
258 // if this fails, check_admin_referer() will automatically print a "failed" page and die.
259 if (
260 check_admin_referer(
261 'vimeography-theme-action',
262 'vimeography-theme-verification'
263 )
264 ) {
265 try {
266 $theme = $input['theme_name'];
267
268 global $wpdb;
269
270 $result = $wpdb->update(
271 $wpdb->vimeography_gallery_meta,
272 array('theme_name' => $theme),
273 array('gallery_id' => $this->_gallery_id),
274 array('%s'),
275 array('%d')
276 );
277
278 if ($result === false) {
279 throw new Exception(
280 __('Your theme could not be updated.', 'vimeography')
281 );
282 }
283
284 if (
285 file_exists(
286 VIMEOGRAPHY_CUSTOMIZATIONS_PATH .
287 'vimeography-gallery-' .
288 $this->_gallery_id .
289 '-custom.css'
290 )
291 ) {
292 unlink(
293 VIMEOGRAPHY_CUSTOMIZATIONS_PATH .
294 'vimeography-gallery-' .
295 $this->_gallery_id .
296 '-custom.css'
297 );
298 }
299
300 do_action('vimeography/reload-gallery');
301
302 $this->messages[] = array(
303 'type' => 'updated',
304 'heading' => __('Theme updated.', 'vimeography'),
305 'message' => sprintf(
306 /* translators: %s refers to the theme name */
307 __( 'You are now using the "%s" theme.', 'vimeography' ),
308 $theme
309 )
310 );
311 } catch (Exception $e) {
312 $this->messages[] = array(
313 'type' => 'error',
314 'heading' => __('Ruh roh.', 'vimeography'),
315 'message' => $e->getMessage()
316 );
317 }
318 }
319 }
320 }
321