[16379] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | define( |
---|
| 5 | 'batch_download_default_config', |
---|
| 6 | serialize(array( |
---|
| 7 | 'groups' => array(), |
---|
| 8 | 'level' => 0, |
---|
| 9 | 'photo_size' => 'original', |
---|
| 10 | 'archive_prefix' => 'piwigo', |
---|
| 11 | 'archive_comment' => null, |
---|
| 12 | 'archive_timeout' => 48, /* hours */ |
---|
| 13 | 'max_elements' => 500, |
---|
| 14 | 'max_size' => 100, /* MB */ |
---|
| 15 | 'last_clean' => time(), |
---|
| 16 | )) |
---|
| 17 | ); |
---|
| 18 | |
---|
| 19 | function plugin_install() |
---|
| 20 | { |
---|
| 21 | global $conf, $prefixeTable; |
---|
| 22 | |
---|
| 23 | $query = ' |
---|
| 24 | CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` ( |
---|
| 25 | `id` mediumint(8) NOT NULL AUTO_INCREMENT, |
---|
| 26 | `user_id` smallint(5) NOT NULL, |
---|
| 27 | `date_creation` datetime NOT NULL, |
---|
| 28 | `type` varchar(16) CHARACTER SET utf8 NOT NULL, |
---|
| 29 | `type_id` varchar(64) CHARACTER SET utf8 NOT NULL, |
---|
[16400] | 30 | `nb_zip` smallint(3) NOT NULL DEFAULT 0, |
---|
| 31 | `last_zip` smallint(3) NOT NULL DEFAULT 0, |
---|
[16379] | 32 | `nb_images` mediumint(8) NOT NULL DEFAULT 0, |
---|
[16400] | 33 | `total_size` int(10) NOT NULL DEFAULT 0, |
---|
[16379] | 34 | `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new", |
---|
| 35 | PRIMARY KEY (`id`) |
---|
| 36 | ) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 |
---|
| 37 | ;'; |
---|
| 38 | pwg_query($query); |
---|
| 39 | |
---|
| 40 | $query = ' |
---|
| 41 | CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` ( |
---|
| 42 | `set_id` mediumint(8) NOT NULL, |
---|
| 43 | `image_id` mediumint(8) NOT NULL, |
---|
| 44 | `zip` smallint(5) NOT NULL DEFAULT 0, |
---|
| 45 | UNIQUE KEY `UNIQUE` (`set_id`,`image_id`) |
---|
| 46 | ) DEFAULT CHARSET=utf8 |
---|
| 47 | ;'; |
---|
| 48 | pwg_query($query); |
---|
| 49 | |
---|
| 50 | conf_update_param('batch_download', batch_download_default_config); |
---|
| 51 | |
---|
| 52 | mkdir($conf['data_location'] . 'download_archives/', 0755); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function plugin_activate() |
---|
| 56 | { |
---|
| 57 | global $conf; |
---|
| 58 | |
---|
| 59 | if (empty($conf['batch_download'])) |
---|
| 60 | { |
---|
| 61 | conf_update_param('batch_download', batch_download_default_config); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | if (!file_exists($conf['data_location'] . 'download_archives/')) |
---|
| 65 | { |
---|
| 66 | mkdir($conf['data_location'] . 'download_archives/', 0755); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | function plugin_uninstall() |
---|
| 71 | { |
---|
| 72 | global $prefixeTable, $conf; |
---|
| 73 | |
---|
| 74 | pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "batch_download" LIMIT 1;'); |
---|
| 75 | pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;'); |
---|
| 76 | pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;'); |
---|
| 77 | |
---|
| 78 | rrmdir($conf['data_location'].'download_archives/'); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | function rrmdir($dir) |
---|
| 82 | { |
---|
| 83 | if (!is_dir($dir)) |
---|
| 84 | { |
---|
| 85 | return false; |
---|
| 86 | } |
---|
| 87 | $dir = rtrim($dir, '/'); |
---|
| 88 | $objects = scandir($dir); |
---|
| 89 | $return = true; |
---|
| 90 | |
---|
| 91 | foreach ($objects as $object) |
---|
| 92 | { |
---|
| 93 | if ($object !== '.' && $object !== '..') |
---|
| 94 | { |
---|
| 95 | $path = $dir.'/'.$object; |
---|
| 96 | if (filetype($path) == 'dir') |
---|
| 97 | { |
---|
| 98 | $return = $return && rrmdir($path); |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
| 102 | $return = $return && @unlink($path); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return $return && @rmdir($dir); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | ?> |
---|