| 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 |
return array( |
| 17 |
'thumber' => array( |
| 18 |
'thumbs' => array(), |
| 19 |
'gs' => DG_Thumber::getGhostscriptExecutable(), |
| 20 |
'active' => DG_Thumber::getDefaultThumbers(), |
| 21 |
'width' => 200, |
| 22 |
'height' => 200 |
| 23 |
), |
| 24 |
'gallery' => array( |
| 25 |
'defaults' => array( |
| 26 |
// default: link directly to file (true to link to attachment pg) |
| 27 |
'attachment_pg' => false, |
| 28 |
'descriptions' => false, |
| 29 |
// include thumbnail of actual document in gallery display |
| 30 |
'fancy' => true, |
| 31 |
// comma-separated list of attachment ids |
| 32 |
'ids' => false, |
| 33 |
// if true, all images attached to current page will be included also |
| 34 |
'images' => false, |
| 35 |
'localpost' => true, |
| 36 |
'order' => 'ASC', |
| 37 |
'orderby' => 'menu_order', |
| 38 |
// only relevant if tax_query used (WP >= 3.1) |
| 39 |
'relation' => 'AND' |
| 40 |
) |
| 41 |
), |
| 42 |
'css' => array('version' => 0, 'text' => ''), |
| 43 |
'version' => DG_VERSION |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Runs every page load, updates when needed. |
| 49 |
*/ |
| 50 |
public static function maybeUpdate() { |
| 51 |
global $dg_options; |
| 52 |
|
| 53 |
// first installation |
| 54 |
if (is_null($dg_options)) { |
| 55 |
$options = self::getDefaultOptions(); |
| 56 |
add_option(DG_OPTION_NAME, $options); |
| 57 |
} |
| 58 |
|
| 59 |
// do update |
| 60 |
elseif (DG_VERSION !== $dg_options['version']) { |
| 61 |
$dg_options['version'] = DG_VERSION; |
| 62 |
update_option(DG_OPTION_NAME, $dg_options); |
| 63 |
|
| 64 |
if ('' !== $dg_options['css']['text']) { |
| 65 |
DocumentGallery::updateUserGalleryStyle($dg_options['css']['text']); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Runs when DG is uninstalled. |
| 72 |
*/ |
| 73 |
public static function uninstall() { |
| 74 |
if (!current_user_can('activate_plugins')) return; |
| 75 |
check_admin_referer('bulk-plugins'); |
| 76 |
|
| 77 |
$options = DG_Thumber::getOptions(); |
| 78 |
|
| 79 |
foreach ($options['thumbs'] as $val) { |
| 80 |
if (false !== $val) { |
| 81 |
@unlink($val['thumb_path']); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
delete_option(DG_OPTION_NAME); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Blocks instantiation. All functions are static. |
| 90 |
*/ |
| 91 |
private function __construct() { |
| 92 |
|
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
?> |
| 97 |
|