| 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 |
$dg_options['css']['minified'] = |
| 69 |
DocumentGallery::compileCustomCss($dg_options['css']['text']); |
| 70 |
|
| 71 |
// update plugin version |
| 72 |
$dg_options['version'] = DG_VERSION; |
| 73 |
|
| 74 |
// used in dynamic CSS HTTP headers |
| 75 |
$dg_options['css']['last-modified'] = gmdate('D, d M Y H:i:s'); |
| 76 |
$dg_options['css']['etag'] = md5($dg_options['css']['last-modified']); |
| 77 |
|
| 78 |
// remove previously-failed thumbs |
| 79 |
$thumbs = $dg_options['thumber']['thumbs']; |
| 80 |
foreach ($thumbs as $k => $v) { |
| 81 |
if (false === $v) { |
| 82 |
unset($dg_options['thumber']['thumbs'][$k]); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
// commit DB changes |
| 87 |
update_option(DG_OPTION_NAME, $dg_options); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Runs when DG is uninstalled. |
| 93 |
*/ |
| 94 |
public static function uninstall() { |
| 95 |
if (!current_user_can('activate_plugins')) return; |
| 96 |
check_admin_referer('bulk-plugins'); |
| 97 |
|
| 98 |
$options = DG_Thumber::getOptions(); |
| 99 |
|
| 100 |
foreach ($options['thumbs'] as $val) { |
| 101 |
if (false !== $val) { |
| 102 |
@unlink($val['thumb_path']); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
delete_option(DG_OPTION_NAME); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Blocks instantiation. All functions are static. |
| 111 |
*/ |
| 112 |
private function __construct() { |
| 113 |
|
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
?> |
| 118 |
|