PluginProbe
Document Gallery / 2.0.3
Document Gallery v2.0.3
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
document-gallery / inc / class-setup.php

class-setup.php in Document Gallery 2.0.3, at inc/class-setup.php

115 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('WPINC') OR exit;
3
4 /**
5 * Holds functions that handle DG setup / uninstallation.
6 *
7 * @author drossiter
8 */
9 class DG_Setup {
10
11 /**
12 * @return array Contains default options for DG.
13 */
14 public static function getDefaultOptions() {
15 include_once DG_PATH . 'inc/class-thumber.php';
16 $date = gmdate('D, d M Y H:i:s');
17 $etag = md5($date);
18 return array(
19 'thumber' => array(
20 'thumbs' => array(),
21 'gs' => DG_Thumber::getGhostscriptExecutable(),
22 'active' => DG_Thumber::getDefaultThumbers(),
23 'width' => 200,
24 'height' => 200
25 ),
26 'gallery' => array(
27 'defaults' => array(
28 // default: link directly to file (true to link to attachment pg)
29 'attachment_pg' => false,
30 'descriptions' => false,
31 // include thumbnail of actual document in gallery display
32 'fancy' => true,
33 // comma-separated list of attachment ids
34 'ids' => false,
35 // if true, all images attached to current page will be included also
36 'images' => false,
37 'localpost' => true,
38 'order' => 'ASC',
39 'orderby' => 'menu_order',
40 // only relevant if tax_query used (WP >= 3.1)
41 'relation' => 'AND'
42 )
43 ),
44 'css' => array(
45 'text' => '',
46 'last-modified' => $date,
47 'etag' => $etag,
48 'version' => 0
49 ),
50 'version' => DG_VERSION
51 );
52 }
53
54 /**
55 * Runs every page load, updates when needed.
56 */
57 public static function maybeUpdate() {
58 global $dg_options;
59
60 // first installation
61 if (empty($dg_options)) {
62 $dg_options = self::getDefaultOptions();
63 add_option(DG_OPTION_NAME, $dg_options);
64 }
65
66 // do update
67 elseif (DG_VERSION !== $dg_options['version']) {
68 // update plugin version
69 $dg_options['version'] = DG_VERSION;
70
71 // used in dynamic CSS HTTP headers
72 $dg_options['css']['last-modified'] = gmdate('D, d M Y H:i:s');
73 $dg_options['css']['etag'] = md5($dg_options['css']['last-modified']);
74
75 // remove previously-failed thumbs
76 $thumbs = $dg_options['thumber']['thumbs'];
77 foreach ($thumbs as $k => $v) {
78 if (false === $v) {
79 unset($dg_options['thumber']['thumbs'][$k]);
80 }
81 }
82
83 // commit DB changes
84 update_option(DG_OPTION_NAME, $dg_options);
85 }
86 }
87
88 /**
89 * Runs when DG is uninstalled.
90 */
91 public static function uninstall() {
92 if (!current_user_can('activate_plugins')) return;
93 check_admin_referer('bulk-plugins');
94
95 $options = DG_Thumber::getOptions();
96
97 foreach ($options['thumbs'] as $val) {
98 if (false !== $val) {
99 @unlink($val['thumb_path']);
100 }
101 }
102
103 delete_option(DG_OPTION_NAME);
104 }
105
106 /**
107 * Blocks instantiation. All functions are static.
108 */
109 private function __construct() {
110
111 }
112 }
113
114 ?>
115