| 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 |
' |
| 96 |
SELECT * FROM ' . |
| 97 |
$wpdb->vimeography_gallery_meta . |
| 98 |
' AS meta |
| 99 |
JOIN ' . |
| 100 |
$wpdb->vimeography_gallery . |
| 101 |
' AS gallery |
| 102 |
ON meta.gallery_id = gallery.id |
| 103 |
WHERE meta.gallery_id = ' . |
| 104 |
$this->_gallery_id . |
| 105 |
' |
| 106 |
LIMIT 1; |
| 107 |
' |
| 108 |
); |
| 109 |
|
| 110 |
if (!$this->_gallery) { |
| 111 |
$this->messages[] = array( |
| 112 |
'type' => 'error', |
| 113 |
'heading' => __('Uh oh.', 'vimeography'), |
| 114 |
'message' => __( |
| 115 |
"That gallery no longer exists. It's gone. Kaput!", |
| 116 |
'vimeography' |
| 117 |
) |
| 118 |
); |
| 119 |
} else { |
| 120 |
if (strtolower($this->_gallery[0]->theme_name) === 'bugsauce') { |
| 121 |
$this->messages[] = array( |
| 122 |
'type' => 'error', |
| 123 |
'heading' => __('Heads up!', 'vimeography'), |
| 124 |
'message' => __( |
| 125 |
"The Bugsauce gallery theme has been discontinued in Vimeography 2. We recommend switching over to the free Harvestone gallery theme.", |
| 126 |
'vimeography' |
| 127 |
) |
| 128 |
); |
| 129 |
} |
| 130 |
|
| 131 |
try { |
| 132 |
$theme = self::_set_active_theme($this->_gallery[0]->theme_name); |
| 133 |
} catch (Exception $e) { |
| 134 |
$this->messages[] = array( |
| 135 |
'type' => 'error', |
| 136 |
'heading' => __('Heads up!', 'vimeography'), |
| 137 |
'message' => $e->getMessage() |
| 138 |
); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
$this->_gallery[0]->featured_video = |
| 143 |
$this->_gallery[0]->featured_video === 0 |
| 144 |
? '' |
| 145 |
: $this->_gallery[0]->featured_video; |
| 146 |
|
| 147 |
// Backwards compatibility |
| 148 |
$this->_gallery = apply_filters( |
| 149 |
'vimeography/deprecated/reload-pro-gallery-settings', |
| 150 |
$this, |
| 151 |
$this->_gallery |
| 152 |
); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* [_set_active_theme description] |
| 157 |
* @since 1.3 |
| 158 |
* @param string $theme_name [description] |
| 159 |
* @return array Theme meta |
| 160 |
*/ |
| 161 |
private static function _set_active_theme($theme_name) |
| 162 |
{ |
| 163 |
$vimeography = Vimeography::get_instance(); |
| 164 |
$vimeography->addons->set_active_theme($theme_name); |
| 165 |
return $vimeography->addons->active_theme; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Removes the cache file associated with the loaded gallery. |
| 170 |
* |
| 171 |
* @return void |
| 172 |
*/ |
| 173 |
public function vimeography_refresh_gallery_cache() |
| 174 |
{ |
| 175 |
if ($this->_cache->exists()) { |
| 176 |
$this->_cache->delete(); |
| 177 |
} |
| 178 |
|
| 179 |
$this->messages[] = array( |
| 180 |
'type' => 'updated', |
| 181 |
'heading' => __('So fresh.', 'vimeography'), |
| 182 |
'message' => __('Your videos have been refreshed.', 'vimeography') |
| 183 |
); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Removes the custom CSS file associated with |
| 188 |
* the current gallery, if it exists. |
| 189 |
* |
| 190 |
* @return void |
| 191 |
*/ |
| 192 |
public function vimeography_refresh_gallery_appearance() |
| 193 |
{ |
| 194 |
if ( |
| 195 |
file_exists( |
| 196 |
VIMEOGRAPHY_CUSTOMIZATIONS_PATH . |
| 197 |
'vimeography-gallery-' . |
| 198 |
$this->_gallery_id . |
| 199 |
'-custom.css' |
| 200 |
) |
| 201 |
) { |
| 202 |
unlink( |
| 203 |
VIMEOGRAPHY_CUSTOMIZATIONS_PATH . |
| 204 |
'vimeography-gallery-' . |
| 205 |
$this->_gallery_id . |
| 206 |
'-custom.css' |
| 207 |
); |
| 208 |
} |
| 209 |
|
| 210 |
$this->messages[] = array( |
| 211 |
'type' => 'updated', |
| 212 |
'heading' => __('Theme settings cleared.', 'vimeography'), |
| 213 |
'message' => __('Your gallery appearance has been reset.', 'vimeography') |
| 214 |
); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Returns the gallery settings to the gallery editor template |
| 219 |
* |
| 220 |
* @since 1.3 |
| 221 |
* @return array |
| 222 |
*/ |
| 223 |
public function gallery() |
| 224 |
{ |
| 225 |
return apply_filters('vimeography/gallery-settings', $this->_gallery); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Switches to the selected gallery theme |
| 230 |
* |
| 231 |
* @param array $input posted values |
| 232 |
* @return void |
| 233 |
*/ |
| 234 |
public function vimeography_set_gallery_theme($input) |
| 235 |
{ |
| 236 |
// if this fails, check_admin_referer() will automatically print a "failed" page and die. |
| 237 |
if ( |
| 238 |
check_admin_referer( |
| 239 |
'vimeography-theme-action', |
| 240 |
'vimeography-theme-verification' |
| 241 |
) |
| 242 |
) { |
| 243 |
try { |
| 244 |
$theme = $input['theme_name']; |
| 245 |
|
| 246 |
global $wpdb; |
| 247 |
|
| 248 |
$result = $wpdb->update( |
| 249 |
$wpdb->vimeography_gallery_meta, |
| 250 |
array('theme_name' => $theme), |
| 251 |
array('gallery_id' => $this->_gallery_id), |
| 252 |
array('%s'), |
| 253 |
array('%d') |
| 254 |
); |
| 255 |
|
| 256 |
if ($result === false) { |
| 257 |
throw new Exception( |
| 258 |
__('Your theme could not be updated.', 'vimeography') |
| 259 |
); |
| 260 |
} |
| 261 |
|
| 262 |
if ( |
| 263 |
file_exists( |
| 264 |
VIMEOGRAPHY_CUSTOMIZATIONS_PATH . |
| 265 |
'vimeography-gallery-' . |
| 266 |
$this->_gallery_id . |
| 267 |
'-custom.css' |
| 268 |
) |
| 269 |
) { |
| 270 |
unlink( |
| 271 |
VIMEOGRAPHY_CUSTOMIZATIONS_PATH . |
| 272 |
'vimeography-gallery-' . |
| 273 |
$this->_gallery_id . |
| 274 |
'-custom.css' |
| 275 |
); |
| 276 |
} |
| 277 |
|
| 278 |
do_action('vimeography/reload-gallery'); |
| 279 |
|
| 280 |
$this->messages[] = array( |
| 281 |
'type' => 'updated', |
| 282 |
'heading' => __('Theme updated.', 'vimeography'), |
| 283 |
'message' => sprintf( |
| 284 |
__('You are now using the "%s" theme.', 'vimeography'), |
| 285 |
$theme |
| 286 |
) |
| 287 |
); |
| 288 |
} catch (Exception $e) { |
| 289 |
$this->messages[] = array( |
| 290 |
'type' => 'error', |
| 291 |
'heading' => __('Ruh roh.', 'vimeography'), |
| 292 |
'message' => $e->getMessage() |
| 293 |
); |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|