source: extensions/BatchDownloader/maintain.inc.php @ 16392

Last change on this file since 16392 was 16379, checked in by mistic100, 12 years ago

first commit, not complete
TODO : use multisize, download history, localization, compatibility with User Selection (and create User Selection !!)

File size: 2.7 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4define(
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
19function plugin_install() 
20{
21  global $conf, $prefixeTable;
22 
23  $query = '
24CREATE 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,
30  `nb_zip` smallint(2) NOT NULL DEFAULT 0,
31  `last_zip` smallint(2) NOT NULL DEFAULT 0,
32  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
33  `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
34  PRIMARY KEY (`id`)
35) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
36;';
37  pwg_query($query);
38 
39  $query = '
40CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` (
41  `set_id` mediumint(8) NOT NULL,
42  `image_id` mediumint(8) NOT NULL,
43  `zip` smallint(5) NOT NULL DEFAULT 0,
44  UNIQUE KEY `UNIQUE` (`set_id`,`image_id`)
45) DEFAULT CHARSET=utf8
46;';
47  pwg_query($query);
48
49  conf_update_param('batch_download', batch_download_default_config);
50 
51  mkdir($conf['data_location'] . 'download_archives/', 0755);
52}
53
54function plugin_activate()
55{
56  global $conf;
57
58  if (empty($conf['batch_download']))
59  {
60    conf_update_param('batch_download', batch_download_default_config);
61  }
62 
63  if (!file_exists($conf['data_location'] . 'download_archives/'))
64  {
65    mkdir($conf['data_location'] . 'download_archives/', 0755);
66  }
67}
68
69function plugin_uninstall() 
70{
71  global $prefixeTable, $conf;
72 
73  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "batch_download" LIMIT 1;');
74  pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;');
75  pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;');
76 
77  rrmdir($conf['data_location'].'download_archives/');
78}
79
80function rrmdir($dir)
81{
82  if (!is_dir($dir))
83  {
84    return false;
85  }
86  $dir = rtrim($dir, '/');
87  $objects = scandir($dir);
88  $return = true;
89 
90  foreach ($objects as $object)
91  {
92    if ($object !== '.' && $object !== '..')
93    {
94      $path = $dir.'/'.$object;
95      if (filetype($path) == 'dir') 
96      {
97        $return = $return && rrmdir($path); 
98      }
99      else 
100      {
101        $return = $return && @unlink($path);
102      }
103    }
104  }
105 
106  return $return && @rmdir($dir);
107} 
108
109?>
Note: See TracBrowser for help on using the repository browser.