PluginProbe
Document Gallery / 2.2.6
Document Gallery v2.2.6
trunk 0.8 0.8.5 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 2.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 94 releases
← All changes | admin/class-admin.php +727 -162 2.02.2.6 View file →
@@ -1,30 +1,71 @@
1 1 <?php
2 2 defined('WPINC') OR exit;
3 3
4 +DG_Admin::init();
5 +
4 6 class DG_Admin {
5 -
6 7 /**
8 + * @var string The hook for the Document Gallery settings page.
9 + */
10 + private static $hook;
11 +
12 + /**
13 + * @var string The current tab being rendered.
14 + */
15 + private static $current;
16 +
17 + /**
18 + * @var multitype:string Associative array containing all tab names, keyed by tab slug.
19 + */
20 + private static $tabs;
21 +
22 + /**
23 + * Initializes static values for this class.
24 + */
25 + public static function init() {
26 + if (empty(self::$tabs)) {
27 + self::$tabs = array(
28 + 'General' => __('General', 'document-gallery'),
29 + 'Thumbnail' => __('Thumbnail Management', 'document-gallery'),
30 + 'Logging' => __('Logging', 'document-gallery'),
31 + 'Advanced' => __('Advanced', 'document-gallery'));
32 + }
33 + }
34 +
35 + /**
7 36 * Renders Document Gallery options page.
8 37 */
9 38 public static function renderOptions() { ?>
10 39 <div class="wrap">
11 -<h2>Document Gallery Settings</h2>
40 + <h2>Document Gallery Settings</h2>
12 41
13 -<form method="post" action="options.php">
14 - <?php settings_fields(DG_OPTION_NAME); ?>
15 - <?php do_settings_sections('document_gallery'); ?>
16 - <?php submit_button(); ?>
42 + <h2 class="nav-tab-wrapper">
43 +<?php foreach (self::$tabs as $tab => $name) {
44 + $class = ($tab == self::$current) ? ' nav-tab-active' : '';
45 + echo '<a class="nav-tab '.$tab.'-tab'.$class.'" href="?page=' . DG_OPTION_NAME . '&tab='.$tab.'">'.$name.'</a>';
46 +} ?>
47 +</h2>
48 +
49 + <form method="post" action="options.php" id="tab-<?php echo self::$current?>">
50 + <input type="hidden" name="<?php echo DG_OPTION_NAME; ?>[tab]" value="<?php echo self::$current; ?>" />
51 +<?php
52 + settings_fields(DG_OPTION_NAME);
53 + do_settings_sections(DG_OPTION_NAME);
54 + if (self::$current != 'Thumbnail' && self::$current != 'Logging') {
55 + submit_button();
56 + }
57 +?>
17 58 </form>
18 59
19 60 </div>
20 - <?php }
61 +<?php }
21 62
22 63 /**
23 64 * Adds settings link to main plugin view.
24 65 */
25 66 public static function addSettingsLink($links) {
26 - $settings = '<a href="options-general.php?page=document_gallery">' .
67 + $settings = '<a href="options-general.php?page=' . DG_OPTION_NAME . '">' .
27 68 __('Settings', 'document-gallery') . '</a>';
28 69 array_unshift($links, $settings);
29 70 return $links;
30 71 }
@@ -32,21 +73,23 @@
32 73 /**
33 74 * Adds Document Gallery settings page to admin navigation.
34 75 */
35 76 public static function addAdminPage() {
36 - $page = add_options_page(
77 + DG_Admin::$hook = add_options_page(
37 78 __('Document Gallery Settings', 'document-gallery'),
38 79 __('Document Gallery', 'document-gallery'),
39 - 'manage_options', 'document_gallery', array(__CLASS__, 'renderOptions'));
40 -
41 - add_action('admin_print_styles-' . $page, array(__CLASS__, 'enqueueAdminStyle'));
80 + 'manage_options', DG_OPTION_NAME, array(__CLASS__, 'renderOptions'));
81 + add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueueScriptsAndStyles'));
42 82 }
43 -
83 +
44 84 /**
45 - * Registers stylesheet for admin options page.
85 + * Enqueues styles and scripts for the admin settings page.
46 86 */
47 - public static function registerAdminStyle() {
48 - wp_register_style('dg-admin', DG_URL . 'admin/css/style.css', null, DocumentGallery::version());
87 + public static function enqueueScriptsAndStyles($hook) {
88 + if ($hook !== DG_Admin::$hook) return;
89 +
90 + wp_enqueue_style('document-gallery-admin', DG_URL . 'assets/css/admin.css', null, DG_VERSION);
91 + wp_enqueue_script('document-gallery-admin', DG_URL . 'assets/js/admin.js', array('jquery'), DG_VERSION, true);
49 92 }
50 93
51 94 /**
52 95 * Registers settings for the Document Gallery options page.
@@ -51,39 +94,49 @@
51 94 /**
52 95 * Registers settings for the Document Gallery options page.
53 96 */
54 97 public static function registerSettings() {
98 + if (empty($_REQUEST['tab']) || !array_key_exists($_REQUEST['tab'], self::$tabs)) {
99 + reset(self::$tabs);
100 + self::$current = key(self::$tabs);
101 + } else {
102 + self::$current = $_REQUEST['tab'];
103 + }
104 +
105 + register_setting(DG_OPTION_NAME, DG_OPTION_NAME, array(__CLASS__, 'validateSettings'));
106 +
107 + $funct = 'register' . self::$current . 'Settings';
108 + DG_Admin::$funct();
109 + }
110 +
111 + /**
112 + * Registers settings for the general tab.
113 + */
114 + private static function registerGeneralSettings() {
55 115 global $dg_options;
56 116
57 117 include_once DG_PATH . 'inc/class-gallery.php';
58 118 include_once DG_PATH . 'inc/class-thumber.php';
59 119
60 - $defaults = $dg_options['gallery']['defaults'];
61 - $thumber_active = $dg_options['thumber']['active'];
62 - $thumber_gs = $dg_options['thumber']['gs'];
120 + $defaults = $dg_options['gallery'];
121 + $active = $dg_options['thumber']['active'];
63 122
64 - register_setting(DG_OPTION_NAME, DG_OPTION_NAME, array(__CLASS__, 'validateSettings'));
65 -
66 123 add_settings_section(
67 124 'gallery_defaults', __('Default Settings', 'document-gallery'),
68 - array(__CLASS__, 'renderDefaultSettingsSection'), 'document_gallery');
125 + array(__CLASS__, 'renderDefaultSettingsSection'), DG_OPTION_NAME);
69 126
70 127 add_settings_section(
71 - 'thumber_active', __('Thumbnail Generation', 'document-gallery'),
72 - array(__CLASS__, 'renderThumberSection'), 'document_gallery');
128 + 'thumbnail_generation', __('Thumbnail Generation', 'document-gallery'),
129 + array(__CLASS__, 'renderThumberSection'), DG_OPTION_NAME);
73 130
74 131 add_settings_section(
75 - 'css', __('Custon CSS', 'document-gallery'),
76 - array(__CLASS__, 'renderCssSection'), 'document_gallery');
132 + 'css', __('Custom CSS', 'document-gallery'),
133 + array(__CLASS__, 'renderCssSection'), DG_OPTION_NAME);
77 134
78 - add_settings_section(
79 - 'thumber_advanced', __('Advanced Thumbnail Generation', 'document-gallery'),
80 - array(__CLASS__, 'renderThumberAdvancedSection'), 'document_gallery');
81 -
82 135 add_settings_field(
83 136 'gallery_defaults_attachment_pg', 'attachment_pg',
84 137 array(__CLASS__, 'renderCheckboxField'),
85 - 'document_gallery', 'gallery_defaults',
138 + DG_OPTION_NAME, 'gallery_defaults',
86 139 array (
87 140 'label_for' => 'label_gallery_defaults_attachment_pg',
88 141 'name' => 'gallery_defaults][attachment_pg',
89 142 'value' => esc_attr($defaults['attachment_pg']),
@@ -93,9 +146,9 @@
93 146
94 147 add_settings_field(
95 148 'gallery_defaults_descriptions', 'descriptions',
96 149 array(__CLASS__, 'renderCheckboxField'),
97 - 'document_gallery', 'gallery_defaults',
150 + DG_OPTION_NAME, 'gallery_defaults',
98 151 array (
99 152 'label_for' => 'label_gallery_defaults_descriptions',
100 153 'name' => 'gallery_defaults][descriptions',
101 154 'value' => esc_attr($defaults['descriptions']),
@@ -105,9 +158,9 @@
105 158
106 159 add_settings_field(
107 160 'gallery_defaults_fancy', 'fancy',
108 161 array(__CLASS__, 'renderCheckboxField'),
109 - 'document_gallery', 'gallery_defaults',
162 + DG_OPTION_NAME, 'gallery_defaults',
110 163 array (
111 164 'label_for' => 'label_gallery_defaults_fancy',
112 165 'name' => 'gallery_defaults][fancy',
113 166 'value' => esc_attr($defaults['fancy']),
@@ -117,9 +170,9 @@
117 170
118 171 add_settings_field(
119 172 'gallery_defaults_images', 'images',
120 173 array(__CLASS__, 'renderCheckboxField'),
121 - 'document_gallery', 'gallery_defaults',
174 + DG_OPTION_NAME, 'gallery_defaults',
122 175 array (
123 176 'label_for' => 'label_gallery_defaults_images',
124 177 'name' => 'gallery_defaults][images',
125 178 'value' => esc_attr($defaults['images']),
@@ -129,9 +182,9 @@
129 182
130 183 add_settings_field(
131 184 'gallery_defaults_localpost', 'localpost',
132 185 array(__CLASS__, 'renderCheckboxField'),
133 - 'document_gallery', 'gallery_defaults',
186 + DG_OPTION_NAME, 'gallery_defaults',
134 187 array (
135 188 'label_for' => 'label_gallery_defaults_localpost',
136 189 'name' => 'gallery_defaults][localpost',
137 190 'value' => esc_attr($defaults['localpost']),
@@ -141,9 +194,9 @@
141 194
142 195 add_settings_field(
143 196 'gallery_defaults_order', 'order',
144 197 array(__CLASS__, 'renderSelectField'),
145 - 'document_gallery', 'gallery_defaults',
198 + DG_OPTION_NAME, 'gallery_defaults',
146 199 array (
147 200 'label_for' => 'label_gallery_defaults_order',
148 201 'name' => 'gallery_defaults][order',
149 202 'value' => esc_attr($defaults['order']),
@@ -148,15 +201,15 @@
148 201 'name' => 'gallery_defaults][order',
149 202 'value' => esc_attr($defaults['order']),
150 203 'options' => DG_Gallery::getOrderOptions(),
151 204 'option_name' => DG_OPTION_NAME,
152 - 'description' => __('Ascending or decending sorting of documents', 'document-gallery')
205 + 'description' => __('Ascending or descending sorting of documents', 'document-gallery')
153 206 ));
154 207
155 208 add_settings_field(
156 209 'gallery_defaults_orderby', 'orderby',
157 210 array(__CLASS__, 'renderSelectField'),
158 - 'document_gallery', 'gallery_defaults',
211 + DG_OPTION_NAME, 'gallery_defaults',
159 212 array (
160 213 'label_for' => 'label_gallery_defaults_orderby',
161 214 'name' => 'gallery_defaults][orderby',
162 215 'value' => esc_attr($defaults['orderby']),
@@ -167,9 +220,9 @@
167 220
168 221 add_settings_field(
169 222 'gallery_defaults_relation', 'relation',
170 223 array(__CLASS__, 'renderSelectField'),
171 - 'document_gallery', 'gallery_defaults',
224 + DG_OPTION_NAME, 'gallery_defaults',
172 225 array (
173 226 'label_for' => 'label_gallery_defaults_relation',
174 227 'name' => 'gallery_defaults][relation',
175 228 'value' => esc_attr($defaults['relation']),
@@ -176,44 +229,44 @@
176 229 'options' => DG_Gallery::getRelationOptions(),
177 230 'option_name' => DG_OPTION_NAME,
178 231 'description' => __('Whether matched documents must have all taxa_names (AND) or at least one (OR)', 'document-gallery')
179 232 ));
180 -
233 +
181 234 add_settings_field(
182 - 'thumber_active_av', 'Audio/Video',
235 + 'thumbnail_generation_av', 'Audio/Video',
183 236 array(__CLASS__, 'renderCheckboxField'),
184 - 'document_gallery', 'thumber_active',
237 + DG_OPTION_NAME, 'thumbnail_generation',
185 238 array (
186 - 'label_for' => 'label_thumber_active_av',
187 - 'name' => 'thumber_active][av',
188 - 'value' => esc_attr($thumber_active['av']),
239 + 'label_for' => 'label_thumbnail_generation_av',
240 + 'name' => 'thumbnail_generation][av',
241 + 'value' => esc_attr($active['av']),
189 242 'option_name' => DG_OPTION_NAME,
190 243 'description' => esc_html__('Locally generate thumbnails for audio & video files.', 'document-gallery')
191 244 ));
192 245
193 246 add_settings_field(
194 - 'thumber_active_gs', 'Ghostscript',
247 + 'thumbnail_generation_gs', 'Ghostscript',
195 248 array(__CLASS__, 'renderCheckboxField'),
196 - 'document_gallery', 'thumber_active',
249 + DG_OPTION_NAME, 'thumbnail_generation',
197 250 array (
198 - 'label_for' => 'label_thumber_active_gs',
199 - 'name' => 'thumber_active][gs',
200 - 'value' => esc_attr($thumber_active['gs']),
251 + 'label_for' => 'label_thumbnail_generation_gs',
252 + 'name' => 'thumbnail_generation][gs',
253 + 'value' => esc_attr($active['gs']),
201 254 'option_name' => DG_OPTION_NAME,
202 - 'description' => DG_Thumber::getGhostscriptExecutable()
255 + 'description' => DG_Thumber::isGhostscriptAvailable()
203 256 ? __('Use <a href="http://www.ghostscript.com/" target="_blank">Ghostscript</a> for faster local PDF processing (compared to Imagick).', 'document-gallery')
204 257 : __('Your server is not configured to run <a href="http://www.ghostscript.com/" target="_blank">Ghostscript</a>.', 'document-gallery'),
205 - 'disabled' => !DG_Thumber::getGhostscriptExecutable()
258 + 'disabled' => !DG_Thumber::isGhostscriptAvailable()
206 259 ));
207 260
208 261 add_settings_field(
209 - 'thumber_active_imagick', 'Imagick',
262 + 'thumbnail_generation_imagick', 'Imagick',
210 263 array(__CLASS__, 'renderCheckboxField'),
211 - 'document_gallery', 'thumber_active',
264 + DG_OPTION_NAME, 'thumbnail_generation',
212 265 array (
213 - 'label_for' => 'label_thumber_active_imagick',
214 - 'name' => 'thumber_active][imagick',
215 - 'value' => esc_attr($thumber_active['imagick']),
266 + 'label_for' => 'label_thumbnail_generation_imagick',
267 + 'name' => 'thumbnail_generation][imagick',
268 + 'value' => esc_attr($active['imagick']),
216 269 'option_name' => DG_OPTION_NAME,
217 270 'description' => DG_Thumber::isImagickAvailable()
218 271 ? __('Use <a href="http://www.php.net/manual/en/book.imagick.php" target="_blank">Imagick</a> to handle lots of filetypes locally.', 'document-gallery')
219 272 : __('Your server is not configured to run <a href="http://www.php.net/manual/en/book.imagick.php" target="_blank">Imagick</a>.', 'document-gallery'),
@@ -220,15 +273,15 @@
220 273 'disabled' => !DG_Thumber::isImagickAvailable()
221 274 ));
222 275
223 276 add_settings_field(
224 - 'thumber_active_google', 'Google Drive Viewer',
277 + 'thumbnail_generation_google', 'Google Drive Viewer',
225 278 array(__CLASS__, 'renderCheckboxField'),
226 - 'document_gallery', 'thumber_active',
279 + DG_OPTION_NAME, 'thumbnail_generation',
227 280 array (
228 - 'label_for' => 'label_thumber_active_google',
229 - 'name' => 'thumber_active][google',
230 - 'value' => esc_attr($thumber_active['google']),
281 + 'label_for' => 'label_thumbnail_generation_google',
282 + 'name' => 'thumbnail_generation][google',
283 + 'value' => esc_attr($active['google']),
231 284 'option_name' => DG_OPTION_NAME,
232 285 'description' => DG_Thumber::isGoogleDriveAvailable()
233 286 ? __('Use <a href="https://drive.google.com/viewer" target="_blank">Google Drive Viewer</a> to generate thumbnails for MS Office files and many other file types remotely.', 'document-gallery')
234 287 : __('Your server does not allow remote HTTP access.', 'document-gallery'),
@@ -235,70 +288,634 @@
235 288 'disabled' => !DG_Thumber::isGoogleDriveAvailable()
236 289 ));
237 290
238 291 add_settings_field(
239 - 'thumber_advanced_gs', 'Ghostscript Absolute Path',
292 + 'thumbnail_generation_width', 'Max Thumbnail Dimensions',
293 + array(__CLASS__, 'renderMultiTextField'),
294 + DG_OPTION_NAME, 'thumbnail_generation',
295 + array (
296 + array (
297 + 'label_for' => 'label_advanced_width',
298 + 'name' => 'thumbnail_generation][width',
299 + 'value' => esc_attr($dg_options['thumber']['width']),
300 + 'type' => 'number" min="1" step="1',
301 + 'option_name' => DG_OPTION_NAME,
302 + 'description' => ' x '),
303 + array (
304 + 'label_for' => 'label_advanced_height',
305 + 'name' => 'thumbnail_generation][height',
306 + 'value' => esc_attr($dg_options['thumber']['height']),
307 + 'type' => 'number" min="1" step="1',
308 + 'option_name' => DG_OPTION_NAME,
309 + 'description' => __('The max width and height (in pixels) that thumbnails will be generated.', 'document-gallery'))
310 + ));
311 + }
312 +
313 + /**
314 + * Registers settings for the thumbnail management tab.
315 + */
316 + private static function registerThumbnailSettings() {
317 + add_settings_section(
318 + 'thumbnail_table', '',
319 + array(__CLASS__, 'renderThumbnailSection'), DG_OPTION_NAME);
320 + }
321 +
322 + /**
323 + * Registers settings for the logging tab.
324 + */
325 + private static function registerLoggingSettings() {
326 + add_settings_section(
327 + 'logging_table', '',
328 + array(__CLASS__, 'renderLoggingSection'), DG_OPTION_NAME);
329 + }
330 +
331 + /**
332 + * Registers settings for the advanced tab.
333 + */
334 + private static function registerAdvancedSettings() {
335 + global $dg_options;
336 +
337 + add_settings_section(
338 + 'advanced', __('Advanced Thumbnail Generation', 'document-gallery'),
339 + array(__CLASS__, 'renderAdvancedSection'), DG_OPTION_NAME);
340 +
341 + add_settings_field(
342 + 'advanced_logging', 'Logging',
343 + array(__CLASS__, 'renderCheckboxField'),
344 + DG_OPTION_NAME, 'advanced',
345 + array (
346 + 'label_for' => 'label_advanced_logging',
347 + 'name' => 'logging',
348 + 'value' => esc_attr($dg_options['logging']),
349 + 'option_name' => DG_OPTION_NAME,
350 + 'description' => __('Whether to log debug and error information related to Document Gallery.', 'document-gallery')
351 + ));
352 +
353 + add_settings_field(
354 + 'advanced_validation', 'Option Validation',
355 + array(__CLASS__, 'renderCheckboxField'),
356 + DG_OPTION_NAME, 'advanced',
357 + array (
358 + 'label_for' => 'label_advanced_validation',
359 + 'name' => 'validation',
360 + 'value' => esc_attr($dg_options['validation']),
361 + 'option_name' => DG_OPTION_NAME,
362 + 'description' => __('Whether option structure should be validated before save. This is not generally necessary.', 'document-gallery')
363 + ));
364 +
365 + add_settings_field(
366 + 'advanced_thumb_timeout', 'Thumbnail Generation Timeout',
367 + array(__CLASS__, 'renderTextField'),
368 + DG_OPTION_NAME, 'advanced',
369 + array (
370 + 'label_for' => 'label_advanced_thumb_timeout',
371 + 'name' => 'timeout',
372 + 'value' => esc_attr($dg_options['thumber']['timeout']),
373 + 'type' => 'number" min="1" step="1',
374 + 'option_name' => DG_OPTION_NAME,
375 + 'description' => __('Max number of seconds to wait for thumbnail generation before defaulting to filetype icons.', 'document-gallery') .
376 + ' <em>' . __('Note that generation will continue where timeout happened next time the gallery is loaded.', 'document-gallery') . '</em>'));
377 +
378 + add_settings_field(
379 + 'advanced_gs', 'Ghostscript Absolute Path',
240 380 array(__CLASS__, 'renderTextField'),
241 - 'document_gallery', 'thumber_advanced',
381 + DG_OPTION_NAME, 'advanced',
242 382 array (
243 - 'label_for' => 'label_thumber_advanced_gs',
244 - 'name' => 'thumber_advanced][gs',
245 - 'value' => esc_attr($thumber_gs),
383 + 'label_for' => 'label_advanced_gs',
384 + 'name' => 'gs',
385 + 'value' => esc_attr($dg_options['thumber']['gs']),
246 386 'option_name' => DG_OPTION_NAME,
247 - 'description' => $thumber_gs
387 + 'description' => $dg_options['thumber']['gs']
248 388 ? __('Successfully auto-detected the location of Ghostscript.', 'document-gallery')
249 389 : __('Failed to auto-detect the location of Ghostscript.', 'document-gallery')
250 390 ));
391 +
392 + add_settings_section(
393 + 'advanced_options_dump', __('Options Array Dump', 'document-gallery'),
394 + array(__CLASS__, 'renderOptionsDumpSection'), DG_OPTION_NAME);
251 395 }
396 +
397 + /**
398 + * Validates submitted options, sanitizing any invalid options.
399 + * @param array $values User-submitted new options.
400 + * @return array Sanitized new options.
401 + */
402 + public static function validateSettings($values) {
403 + if (empty($values['tab']) || !array_key_exists($values['tab'], self::$tabs)) {
404 + reset(self::$tabs);
405 + $values['tab'] = key(self::$tabs);
406 + }
407 + $funct = 'validate'.$values['tab'].'Settings';
408 + unset($values['tab']);
409 + return DG_Admin::$funct($values);
410 + }
252 411
253 412 /**
413 + * Validates general settings, sanitizing any invalid options.
414 + * @param array $values User-submitted new options.
415 + * @return array Sanitized new options.
416 + */
417 + private static function validateGeneralSettings($values) {
418 + global $dg_options;
419 + $ret = $dg_options;
420 +
421 + include_once DG_PATH . 'inc/class-gallery.php';
422 +
423 + $thumbs_cleared = false;
424 +
425 + // handle gallery shortcode defaults
426 + $errs = array();
427 + $ret['gallery'] = DG_Gallery::sanitizeDefaults($values['gallery_defaults'], $errs);
428 +
429 + foreach ($errs as $k => $v) {
430 + add_settings_error(DG_OPTION_NAME, str_replace('_', '-', $k), $v);
431 + }
432 +
433 + // handle setting width
434 + if (isset($values['thumbnail_generation']['width'])) {
435 + $width = (int)$values['thumbnail_generation']['width'];
436 + if ($width > 0) {
437 + $ret['thumber']['width'] = $width;
438 + } else {
439 + add_settings_error(DG_OPTION_NAME, 'thumber-width',
440 + __('Invalid width given: ', 'document-gallery') . $values['thumbnail_generation']['width']);
441 + }
442 +
443 + unset($values['thumbnail_generation']['width']);
444 + }
445 +
446 + // handle setting height
447 + if (isset($values['thumbnail_generation']['height'])) {
448 + $height = (int)$values['thumbnail_generation']['height'];
449 + if ($height > 0) {
450 + $ret['thumber']['height'] = $height;
451 + } else {
452 + add_settings_error(DG_OPTION_NAME, 'thumber-height',
453 + __('Invalid height given: ', 'document-gallery') . $values['thumbnail_generation']['height']);
454 + }
455 +
456 + unset($values['thumbnail_generation']['width']);
457 + }
458 +
459 + // delete thumb cache to force regeneration if max dimensions changed
460 + if ($ret['thumber']['width'] !== $dg_options['thumber']['width'] ||
461 + $ret['thumber']['height'] !== $dg_options['thumber']['height']) {
462 + foreach ($ret['thumber']['thumbs'] as $v) {
463 + if (isset($v['thumber'])) {
464 + @unlink($v['thumb_path']);
465 + }
466 + }
467 +
468 + $ret['thumber']['thumbs'] = array();
469 + $thumbs_cleared = true;
470 + }
471 +
472 + // handle setting the active thumbers
473 + foreach (array_keys($ret['thumber']['active']) as $k) {
474 + $ret['thumber']['active'][$k] = isset($values['thumbnail_generation'][$k]);
475 + }
476 +
477 + // if new thumbers available, clear failed thumbnails for retry
478 + if (!$thumbs_cleared) {
479 + foreach ($dg_options['thumber']['active'] as $k => $v) {
480 + if (!$v && $ret['thumber']['active'][$k]) {
481 + foreach ($dg_options['thumber']['thumbs'] as $k => $v) {
482 + if (empty($v['thumber'])) {
483 + unset($ret['thumber']['thumbs'][$k]);
484 + }
485 + }
486 + break;
487 + }
488 + }
489 + }
490 +
491 + // handle modified CSS
492 + if (trim($ret['css']['text']) !== trim($values['css'])) {
493 + $ret['css']['text'] = trim($values['css']);
494 + $ret['css']['version']++;
495 + $ret['css']['last-modified'] = gmdate('D, d M Y H:i:s');
496 + $ret['css']['etag'] = md5($ret['css']['last-modified']);
497 +
498 + if (empty($ret['css']['text'])) {
499 + unset($ret['css']['minified']);
500 + } else {
501 + $ret['css']['minified'] = DocumentGallery::compileCustomCss($ret['css']['text']);
502 + }
503 + }
504 +
505 + return $ret;
506 + }
507 +
508 + /**
509 + * Validates thumbnail management settings, sanitizing any invalid options.
510 + * @param array $values User-submitted new options.
511 + * @return array Sanitized new options.
512 + */
513 + private static function validateThumbnailSettings($values) {
514 + global $dg_options;
515 + $ret = $dg_options;
516 +
517 + if (isset($values['ids'])) {
518 + $deleted = array_values(array_intersect(array_keys($dg_options['thumber']['thumbs']), $values['ids']));
519 +
520 + foreach ($deleted as $k) {
521 + if (isset($ret['thumber']['thumbs'][$k]['thumber'])) {
522 + @unlink($ret['thumber']['thumbs'][$k]['thumb_path']);
523 + }
524 +
525 + unset($ret['thumber']['thumbs'][$k]);
526 + }
527 +
528 + if (isset($values['ajax'])) {
529 + echo '[' . implode(',', $deleted) . ']';
530 + add_filter('wp_redirect', array(__CLASS__, '_exit'), 1, 0);
531 + }
532 + }
533 +
534 + return $ret;
535 + }
536 +
537 + /**
538 + * Validates logging settings, sanitizing any invalid options.
539 + * @param array $values User-submitted new options.
540 + * @return array Sanitized new options.
541 + */
542 + private static function validateLoggingSettings($values) {
543 + global $dg_options;
544 + if (isset($values['clearLog'])) {
545 + DG_Logger::clearLog();
546 + }
547 + return $dg_options;
548 + }
549 +
550 + /**
551 + * Validates advanced settings, sanitizing any invalid options.
552 + * @param array $values User-submitted new options.
553 + * @return array Sanitized new options.
554 + */
555 + private static function validateAdvancedSettings($values) {
556 + global $dg_options;
557 + $ret = $dg_options;
558 +
559 + // handle setting the Ghostscript path
560 + if (isset($values['gs']) &&
561 + 0 != strcmp($values['gs'], $ret['thumber']['gs'])) {
562 + if (false === strpos($values['gs'], ';')) {
563 + $ret['thumber']['gs'] = $values['gs'];
564 + } else {
565 + add_settings_error(DG_OPTION_NAME, 'thumber-gs',
566 + __('Invalid Ghostscript path given: ', 'document-gallery') . $values['gs']);
567 + }
568 + }
569 +
570 + // handle setting timeout
571 + if (isset($values['timeout'])) {
572 + $timeout = (int)$values['timeout'];
573 + if ($timeout > 0) {
574 + $ret['thumber']['timeout'] = $timeout;
575 + } else {
576 + add_settings_error(DG_OPTION_NAME, 'thumber-timeout',
577 + __('Invalid timeout given: ', 'document-gallery') . $values['timeout']);
578 + }
579 + }
580 +
581 + // validation checkbox
582 + $ret['validation'] = isset($values['validation']);
583 +
584 + // logging checkbox
585 + $ret['logging'] = isset($values['logging']);
586 +
587 + return $ret;
588 + }
589 +
590 + /**
591 + * @return bool Whether to register settings.
592 + */
593 + public static function doRegisterSettings() {
594 + if (!is_multisite()) {
595 + $script = !empty($GLOBALS['pagenow']) ? $GLOBALS['pagenow'] : null;
596 + } else {
597 + $script = parse_url($_SERVER['REQUEST_URI']);
598 + $script = basename($script['path']);
599 + }
600 +
601 + return !empty($script) && ('options-general.php' === $script || 'options.php' === $script);
602 + }
603 +
604 + /**
254 605 * Render the Default Settings section.
255 606 */
256 607 public static function renderDefaultSettingsSection() { ?>
257 - <p><?php _e('The following values will be used by default in the shortcode. You can still manually set each of these values in each individual shortcode.', 'document-gallery'); ?></p>
258 - <?php }
608 +<p><?php _e('The following values will be used by default in the shortcode. You can still manually set each of these values in each individual shortcode.', 'document-gallery'); ?></p>
609 +<?php }
259 610
260 611 /**
261 612 * Render the Thumber section.
262 613 */
263 614 public static function renderThumberSection() { ?>
264 - <p><?php _e('Select which tools to use when generating thumbnails.', 'document-gallery'); ?></p>
265 - <?php }
615 +<p><?php _e('Select which tools to use when generating thumbnails.', 'document-gallery'); ?></p>
616 +<?php }
266 617
618 + /**
619 + * Renders a text field for use when modifying the CSS to be printed in addition to the default CSS.
620 + */
267 621 public static function renderCssSection() {
268 622 global $dg_options; ?>
269 - <p><?php printf(
623 +<p><?php printf(
270 624 __('Enter custom CSS styling for use with document galleries. To see which ids and classes you can style, take a look at <a href="%s" target="_blank">style.css</a>.'),
271 625 DG_URL . 'assets/css/style.css'); ?></p>
272 - <table class="form-table">
273 - <tbody>
274 - <tr valign="top">
275 - <td>
276 - <textarea name="document_gallery[css]" rows="10" cols="50" class="large-text code"><?php echo $dg_options['css']['text']; ?></textarea>
277 - </td>
278 - </tr>
279 - </tbody>
280 - </table>
281 - <?php }
626 +<table class="form-table">
627 + <tbody>
628 + <tr valign="top">
629 + <td>
630 + <textarea name="<?php echo DG_OPTION_NAME; ?>[css]" rows="10" cols="50" class="large-text code"><?php echo $dg_options['css']['text']; ?></textarea>
631 + </td>
632 + </tr>
633 + </tbody>
634 +</table>
635 +<?php }
282 636
283 637 /**
284 638 * Render the Thumber Advanced section.
285 639 */
286 - public static function renderThumberAdvancedSection() {
640 + public static function renderAdvancedSection() {
287 641 include_once DG_PATH . 'inc/class-thumber.php';?>
288 - <p><?php _e('Unless you <em>really</em> know what you\'re doing, you should not touch these values.', 'document-gallery'); ?></p>
289 - <?php if (!DG_Thumber::isExecAvailable()) : ?>
290 - <p><em><?php _e('NOTE: <code>exec()</code> is not accessible. Ghostscript will not function.', 'document-gallery'); ?></em></p>
291 - <?php endif; ?>
642 +<p><?php _e('Unless you <em>really</em> know what you\'re doing, you should not touch these values.', 'document-gallery'); ?></p>
643 +<?php if (!DG_Thumber::isExecAvailable()) : ?>
644 +<p>
645 + <em><?php _e('NOTE: <code>exec()</code> is not accessible. Ghostscript will not function.', 'document-gallery'); ?></em>
646 +</p>
647 +<?php endif; ?>
292 648 <?php }
649 +
650 + /**
651 + * Renders a readonly textfield containing a dump of current DG options.
652 + */
653 + public static function renderOptionsDumpSection() {
654 + global $dg_options; ?>
655 + <p><?php
656 + _e('The following <em>readonly text</em> should be provided when <a href="http://wordpress.org/support/plugin/document-gallery" target="_blank">reporting a bug</a>:', 'documet-gallery');
657 + ?></p>
658 + <table class="form-table">
659 + <tbody>
660 + <tr valign="top">
661 + <td>
662 + <textarea readonly="true" rows="10" cols="50" id="options-dump" class="large-text code"><?php var_dump($dg_options); ?></textarea>
663 + </td>
664 + </tr>
665 + </tbody>
666 + </table>
667 + <?php }
293 668
294 669 /**
670 + * Render the Thumbnail table.
671 + */
672 + public static function renderThumbnailSection() {
673 + include_once DG_PATH . 'inc/class-thumber.php';
674 + $options = DG_Thumber::getOptions();
675 +
676 + $URL_params = array('page' => DG_OPTION_NAME, 'tab' => 'Thumbnail');
677 + $att_ids = array();
678 +
679 + if (isset($_REQUEST['orderby']) && in_array(strtolower($_REQUEST['orderby']), array('title', 'date'))) {
680 + $orderby = strtolower($_REQUEST['orderby']);
681 + $URL_params['orderby'] = $orderby;
682 +
683 + switch ($orderby)
684 + {
685 + case 'date':
686 + foreach ($options['thumbs'] as $key => $node) {
687 + $keyArray[$key] = $node['timestamp'];
688 + $options['thumbs'][$key]['thumb_id'] = $att_ids[] = $key;
689 + }
690 + break;
691 +
692 + case 'title':
693 + foreach ($options['thumbs'] as $key => $node) {
694 + $keyArray[$key] = basename($node['thumb_path']);
695 + $options['thumbs'][$key]['thumb_id'] = $att_ids[] = $key;
696 + }
697 + break;
698 + }
699 +
700 + $order = strtolower($_REQUEST['order']);
701 + if (!isset($_REQUEST['order']) || !in_array($order, array('asc', 'desc'))) {
702 + $order = 'asc';
703 + }
704 + $URL_params['order'] = $order;
705 +
706 + if ($order == 'asc') {
707 + array_multisort($keyArray, SORT_ASC, $options['thumbs']);
708 + } else {
709 + array_multisort($keyArray, SORT_DESC, $options['thumbs']);
710 + }
711 + } else {
712 + $orderby = '';
713 + foreach ($options['thumbs'] as $key => $node) {
714 + $options['thumbs'][$key]['thumb_id'] = $att_ids[] = $key;
715 + }
716 + }
717 +
718 + static $limit_options = array(10, 25, 75);
719 + if (!isset($_REQUEST['limit']) || !in_array(intval($_REQUEST['limit']), $limit_options)) {
720 + $limit = $limit_options[0];
721 + } else {
722 + $limit = intval($_REQUEST['limit']);
723 + }
724 +
725 + $URL_params['limit'] = $limit;
726 + $select_limit = '';
727 + foreach ($limit_options as $l_o) {
728 + $select_limit .= '<option value="'.$l_o.'"'.selected($limit, $l_o, false).'>'.$l_o.'</option>'.PHP_EOL;
729 + }
730 + $thumbs_number = count($options['thumbs']);
731 + $lastsheet = ceil($thumbs_number/$limit);
732 + $sheet = isset($_REQUEST['sheet']) ? intval($_REQUEST['sheet']) : 1;
733 + if ($sheet <= 0 || $sheet > $lastsheet) {
734 + $sheet = 1;
735 + }
736 +
737 + $offset = ($sheet - 1) * $limit;
738 +
739 + $att_ids = array_slice($att_ids, $offset, $limit);
740 + $atts = get_posts(
741 + array(
742 + 'post_type' => 'attachment',
743 + 'post_status' => 'inherit',
744 + 'numberposts' => -1,
745 + 'post__in' => $att_ids,
746 + 'orderby' => 'post__in'
747 + ));
748 + $titles = array();
749 + foreach ($atts as $att) {
750 + $path_parts = pathinfo($att->guid);
751 + $titles[$att->ID] = $att->post_title.'.'.$path_parts['extension'];
752 + }
753 + unset($atts);
754 +
755 + $thead = '<tr>'.
756 + '<th scope="col" class="manage-column column-cb check-column">'.
757 + '<label class="screen-reader-text" for="cb-select-all-%1$d">'.__('Select All', 'document-gallery').'</label>'.
758 + '<input id="cb-select-all-%1$d" type="checkbox">'.
759 + '</th>'.
760 + '<th scope="col" class="manage-column column-icon">'.__('Thumbnail', 'document-gallery').'</th>'.
761 + '<th scope="col" class="manage-column column-title '.(($orderby != 'title')?'sortable desc':'sorted '.$order).'"><a href="?'.http_build_query(array_merge($URL_params, array('orderby'=>'title','order'=>(($orderby != 'title')?'asc':(($order == 'asc')?'desc':'asc'))))).'"><span>'.__('File name', 'document-gallery').'</span><span class="sorting-indicator"></span></th>'.
762 + '<th scope="col" class="manage-column column-date '.(($orderby != 'date')?'sortable asc':'sorted '.$order).'"><a href="?'.http_build_query(array_merge($URL_params, array('orderby'=>'date','order'=>(($orderby != 'date')?'desc':(($order == 'asc')?'desc':'asc'))))).'"><span>'.__('Date', 'document-gallery').'</span><span class="sorting-indicator"></span></th>'.
763 + '</tr>';
764 +
765 + $pagination = '<div class="alignleft bulkactions"><button class="button action deleteSelected">'.__('Delete Selected', 'document-gallery').'</button></div><div class="tablenav-pages">'.
766 + '<span class="displaying-num">'.
767 + $thumbs_number.' '._n('item', 'items', $thumbs_number).
768 + '</span>'.($lastsheet>1?
769 + '<span class="pagination-links">'.
770 + '<a class="first-page'.( $sheet==1 ? ' disabled' : '').'" title="'.__('Go to the first page', 'document-gallery').'"'.( $sheet==1 ? '' : ' href="?'.http_build_query($URL_params).'"').'>«</a>'.
771 + '<a class="prev-page'.( $sheet==1 ? ' disabled' : '').'" title="'.__('Go to the previous page', 'document-gallery').'"'.( $sheet==1 ? '' : ' href="?'.http_build_query(array_merge($URL_params, array('sheet'=>$sheet-1))).'"').'>‹</a>'.
772 + '<span class="paging-input">'.
773 + '<input class="current-page" title="'.__('Current page', 'document-gallery').'" type="text" name="paged" value="'.$sheet.'" size="'.strlen($sheet).'" maxlength="'.strlen($sheet).'"> '.__('of', 'document-gallery').' <span class="total-pages">'.$lastsheet.'</span></span>'.
774 + '<a class="next-page'.( $sheet==$lastsheet ? ' disabled' : '').'" title="'.__('Go to the next page', 'document-gallery').'"'.( $sheet==$lastsheet ? '' : ' href="?'.http_build_query(array_merge($URL_params, array('sheet'=>$sheet+1))).'"').'>›</a>'.
775 + '<a class="last-page'.( $sheet==$lastsheet ? ' disabled' : '').'" title="'.__('Go to the last page', 'document-gallery').'"'.( $sheet==$lastsheet ? '' : ' href="?'.http_build_query(array_merge($URL_params, array('sheet'=>$lastsheet))).'"').'>»</a>'.
776 + '</span>':' <b>|</b> ').
777 + '<span class="displaying-num"><select dir="rtl" class="limit_per_page">'.$select_limit.'</select> '.__('items per page', 'document-gallery').'</span>'.
778 + '</div>'.
779 + '<br class="clear" />';
780 +
781 + // Avoiding json_encode to avoid compatibility issues on some systems
782 + $json_like = '';
783 + foreach ($URL_params as $k => $v) {
784 + $json_like .= '"'.$k.'":"'.$v.'",';
785 + }
786 + ?>
787 +
788 +<script type="text/javascript">
789 +var URL_params = <?php echo '{'.trim($json_like,', ').'}'; ?>;
790 + </script>
791 +<div class="thumbs-list-wrapper">
792 + <div>
793 + <div class="tablenav top"><?php echo $pagination; ?></div>
794 + <table id="ThumbsTable" class="wp-list-table widefat fixed media"
795 + cellpadding="0" cellspacing="0">
796 + <thead>
797 + <?php printf($thead, 1); ?>
798 + </thead>
799 + <tfoot>
800 + <?php printf($thead, 2); ?>
801 + </tfoot>
802 + <tbody><?php
803 + $i = 0;
804 + foreach ($options['thumbs'] as $v) {
805 + if ($i < $offset) { $i++; continue; }
806 + if (++$i > $offset + $limit) { break; }
807 +
808 + $icon = isset($v['thumb_url']) ? $v['thumb_url'] : DG_URL . 'assets/icons/missing.png';
809 + $title = isset($titles[$v['thumb_id']]) ? $titles[$v['thumb_id']] : '';
810 + $date = DocumentGallery::localDateTimeFromTimestamp($v['timestamp']);
811 +
812 + echo '<tr><td scope="row" class="check-column"><input type="checkbox" class="cb-ids" name="' . DG_OPTION_NAME . '[ids][]" value="' .
813 + $v['thumb_id'].'"></td><td class="column-icon media-icon"><img src="' .
814 + $icon.'" />'.'</td><td class="title column-title">' .
815 + ($title ? '<strong><a href="' . home_url('/?attachment_id='.$v['thumb_id']).'" target="_blank" title="'.__('View', 'document-gallery').' \'' .
816 + $title.'\' '.__('attachment page', 'document-gallery').'">'.$title.'</a></strong>' : __('Attachment not found', 'document-gallery')) .
817 + '</td><td class="date column-date">'.$date.'</td></tr>'.PHP_EOL;
818 + } ?>
819 + </tbody>
820 + </table>
821 + <div class="tablenav bottom"><?php echo $pagination; ?></div>
822 + </div>
823 +</div>
824 +<?php }
825 + /**
826 + * Render the Logging table.
827 + */
828 + public static function renderLoggingSection() {
829 + $log_list = DG_Logger::readLog();
830 + if ($log_list) {
831 + $levels = array_map(array(__CLASS__, 'getLogLabelSpan'), array_keys(DG_LogLevel::getLogLevels()));
832 +
833 + $thead = '<tr>'.
834 + '<th scope="col" class="manage-column column-date"><span>'.__('Date', 'document-gallery').'</span></th>'.
835 + '<th scope="col" class="manage-column column-level"><span>'.__('Level', 'document-gallery').'</span></th>'.
836 + '<th scope="col" class="manage-column column-message"><span>'.__('Message', 'document-gallery').'</span></th>'.
837 + '</tr>';
838 +
839 + ?>
840 +<div class="log-list-wrapper">
841 + <div>
842 + <div class="tablenav top">
843 + <div class="alignleft bulkactions">
844 + <button class="action expandAll">
845 + <?php echo __('Expand All', 'document-gallery'); ?>
846 + </button>
847 + <button class="action collapseAll">
848 + <?php echo __('Collapse All', 'document-gallery'); ?>
849 + </button>
850 + </div>
851 + <div class="levelSelector">
852 + <input type="checkbox" id="allLevels" name="lswitch" value="all" checked />
853 + <label for="allLevels" class="allLevels">ALL</label>
854 + <?php
855 + foreach (array_keys(DG_LogLevel::getLogLevels()) as $k) { ?>
856 + <?php
857 + $lower = strtolower($k);
858 + $upper = strtoupper($k);
859 + ?>
860 + <input type="checkbox" id="<?php echo $lower; ?>Level" name="lswitch" value="<?php echo $lower; ?>" checked />
861 + <label for="<?php echo $lower; ?>Level" class="<?php echo $lower; ?>Level"><?php echo $upper; ?></label>
862 + <?php }
863 + ?>
864 + </div>
865 + </div>
866 + <table id="LogTable" class="wp-list-table widefat fixed media" cellpadding="0" cellspacing="0">
867 + <thead>
868 + <?php echo $thead; ?>
869 + </thead>
870 + <tfoot>
871 + <?php echo $thead; ?>
872 + </tfoot>
873 + <tbody><?php
874 + $i = 0;
875 + foreach ($log_list as $v) {
876 + $date = DocumentGallery::localDateTimeFromTimestamp($v[0]);
877 + $v[2] = preg_replace('/ (attachment #)(\d+) /', ' <a href="' . home_url() . '/?attachment_id=\2" target="_blank">\1<strong>\2</strong></a> ', $v[2]);
878 + $v[2] = preg_replace('/^(\(\w+::\w+\)) /', '<strong>\1</strong> ', $v[2]);
879 + $v[2] = preg_replace('/(\(?\w+::\w+\)?)/m', '<i>\1</i>', $v[2]);
880 +
881 + echo '<tr><td class="date column-date" data-sort-value="'.$v[0].'"><span class="logLabel date">'.$date.'</span></td>' .
882 + '<td class="column-level">'.$levels[$v[1]].'</td>' .
883 + '<td class="column-entry">'.(empty($v[3]) ? '<pre>'.$v[2].'</pre>' : '<div class="expander" title="Click to Expand"><pre>'.$v[2].'</pre><div><span class="dashicons dashicons-arrow-down-alt2"></span></div></div><div class="spoiler-body"><pre>'.$v[3].'</pre></div>').'</td>' .
884 + '</tr>'.PHP_EOL;
885 + } ?>
886 + </tbody>
887 + </table>
888 + <div class="tablenav bottom">
889 + <div class="alignright bulkactions">
890 + <button class="button action clearLog" name = '<?php echo DG_OPTION_NAME; ?>[clearLog]' value = 'true'>
891 + <?php echo __('Clear Log', 'document-gallery'); ?>
892 + </button>
893 + </div>
894 + </div>
895 + </div>
896 +</div>
897 +<?php } else {
898 + echo '<div class="noLog">'.__('There are no log entries at this time.', 'document-gallery').'<br />'.__('For Your information:', 'document-gallery').' <strong><i>'.__('Logging', 'document-gallery').'</i></strong> '.(DG_Logger::logEnabled()?'<span class="loggingON">'.__('is turned ON', 'document-gallery').'!</span>':'<span class="loggingOFF">'.__('is turned OFF', 'document-gallery').'!</span>').'</div>';
899 + }
900 + }
901 +
902 + /**
903 + * Takes label name and returns SPAN tag.
904 + * @param string $e label name.
905 + * @return string SPAN tag
906 + */
907 + private static function getLogLabelSpan($e) {
908 + return '<span class="logLabel ' . strtolower($e) . '">' . strtoupper($e) . '</span>';
909 + }
910 +
911 + /**
295 912 * Render a checkbox field.
296 913 * @param array $args
297 914 */
298 915 public static function renderCheckboxField($args) {
299 916 $args['disabled'] = isset($args['disabled']) ? $args['disabled'] : false;
300 - printf('<input type="checkbox" value="1" name="%1$s[%2$s]" id="%3$s" %4$s %5$s/> %6$s',
917 + printf('<label><input type="checkbox" value="1" name="%1$s[%2$s]" id="%3$s" %4$s %5$s/> %6$s</label>',
301 918 $args['option_name'],
302 919 $args['name'],
303 920 $args['label_for'],
304 921 checked($args['value'], 1, false),
@@ -310,15 +927,26 @@
310 927 * Render a text field.
311 928 * @param array $args
312 929 */
313 930 public static function renderTextField($args) {
314 - printf('<input type="text" value="%1$s" name="%2$s[%3$s]" id="%4$s" /> %5$s',
315 - $args['value'],
316 - $args['option_name'],
317 - $args['name'],
318 - $args['label_for'],
319 - $args['description']);
931 + printf('<input type="%1$s" value="%2$s" name="%3$s[%4$s]" id="%5$s" /> %6$s',
932 + isset($args['type']) ? $args['type'] : 'text',
933 + $args['value'],
934 + $args['option_name'],
935 + $args['name'],
936 + $args['label_for'],
937 + $args['description']);
320 938 }
939 +
940 + /**
941 + * Accepts a two-dimensional array where each inner array consists of valid arguments for renderTextField.
942 + * @param array $args
943 + */
944 + public static function renderMultiTextField($args) {
945 + foreach ($args as $arg) {
946 + self::renderTextField($arg);
947 + }
948 + }
321 949
322 950 /**
323 951 * Render a select field.
324 952 * @param array $args
@@ -338,77 +966,14 @@
338 966 }
339 967
340 968 print '</select> ' . $args['description'];
341 969 }
342 -
970 +
343 971 /**
344 - * Validates submitted options, sanitizing any invalid options.
345 - * @param array $values User-submitted new options.
346 - * @return array Sanitized new options.
972 + * Wraps the PHP exit language construct.
347 973 */
348 - public static function validateSettings($values) {
349 - include_once DG_PATH . 'inc/class-gallery.php';
350 -
351 - global $dg_options;
352 - $ret = $dg_options;
353 -
354 - // handle gallery shortcode defaults
355 - $errs = array();
356 - $ret['gallery']['defaults'] =
357 - DG_Gallery::sanitizeDefaults($values['gallery_defaults'], $errs);
358 -
359 - foreach ($errs as $k => $v) {
360 - add_settings_error(DG_OPTION_NAME, str_replace('_', '-', $k), $v);
361 - }
362 -
363 - // handle setting the active thumbers
364 - foreach ($ret['thumber']['active'] as $k => $v) {
365 - $ret['thumber']['active'][$k] = isset($values['thumber_active'][$k]);
366 - }
367 -
368 - // if new thumbers available, clear failed thumbnails for retry
369 - foreach ($dg_options['thumber']['active'] as $k => $v) {
370 - if (!$v && $ret['thumber']['active'][$k]) {
371 - foreach ($dg_options['thumber']['thumbs'] as $k => $v) {
372 - if (false === $v) {
373 - unset($ret['thumber']['thumbs'][$k]);
374 - }
375 - }
376 - break;
377 - }
378 - }
379 -
380 - // handle changed CSS
381 - if (trim($values['css']) != trim($ret['css']['text'])) {
382 - if (DocumentGallery::updateUserGalleryStyle($values['css'])) {
383 - $ret['css']['text'] = $values['css'];
384 - $ret['css']['version']++;
385 - } else {
386 - add_settings_error(DG_OPTION_NAME, 'css',
387 - __('Failed to update CSS file.', 'document-gallery'));
388 - }
389 - }
390 -
391 - // handle setting the Ghostscript path
392 - if (isset($values['thumber_advanced']['gs']) &&
393 - 0 != strcmp($values['thumber_advanced']['gs'], $ret['thumber']['gs'])) {
394 - if (false === strpos($values['thumber_advanced']['gs'], ';')) {
395 - $ret['thumber']['gs'] = $values['thumber_advanced']['gs'];
396 - } else {
397 - add_settings_error(DG_OPTION_NAME, 'thumber-gs',
398 - __('Invalid Ghostscript path given: ', 'document-gallery')
399 - . $values['thumber_advanced']['gs']);
400 - }
401 - }
402 -
403 - return $ret;
404 - }
405 -
406 - /**
407 - * Enqueues stylesheet for admin options page.
408 - */
409 - public static function enqueueAdminStyle() {
410 - wp_enqueue_style('dg-admin');
974 + public static function _exit() {
975 + exit;
411 976 }
412 977
413 978 /**
414 979 * Blocks instantiation. All functions are static.