source: extensions/virtualize/admin.php @ 21275

Last change on this file since 21275 was 17679, checked in by plg, 12 years ago

compatible with Piwigo 2.4

File size: 4.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2011      Pierrick LE GALL             http://piwigo.org |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22if( !defined("PHPWG_ROOT_PATH") )
23{
24  die ("Hacking attempt!");
25}
26
27include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
28
29$admin_base_url = get_root_url().'admin.php?page=plugin&section=virtualize%2Fadmin.php';
30load_language('plugin.lang', dirname(__FILE__).'/');
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35
36check_status(ACCESS_ADMINISTRATOR);
37
38// +-----------------------------------------------------------------------+
39// |                            add permissions                            |
40// +-----------------------------------------------------------------------+
41
42if (isset($_POST['submit']))
43{
44  $query = '
45SELECT
46    path AS oldpath,
47    date_available,
48    id
49  FROM '.IMAGES_TABLE.'
50  WHERE path NOT LIKE \'./upload/%\'
51;';
52  $result = pwg_query($query);
53  while ($row = pwg_db_fetch_assoc($result))
54  {
55    $file_for_md5sum  = $row['oldpath'];
56    $md5sum = md5_file($file_for_md5sum);
57
58    list($year, $month, $day, $hour, $minute, $second) = preg_split('/[^\d]+/', $row['date_available']);
59
60    $upload_dir = './upload/'.$year.'/'.$month.'/'.$day;
61    if (!is_dir($upload_dir))
62    {
63      umask(0000);
64      $recursive = true;
65      if (!@mkdir($upload_dir, 0777, $recursive))
66      {
67        echo 'error during "'.$upload_dir.'" directory creation';
68        exit();
69      }
70    }
71    secure_directory($upload_dir);
72
73    $extension = get_extension($row['oldpath']);
74    $newfilename = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8).'.jpg';
75
76    $newpath = $upload_dir.'/'.$newfilename;
77
78    $query = '
79UPDATE '.IMAGES_TABLE.'
80  SET path = \''.$newpath.'\',
81      storage_category_id = NULL
82  WHERE id = '.$row['id'].'
83;';
84    pwg_query($query);
85
86    rename($row['oldpath'], $newpath);
87    delete_element_derivatives(array('path' => $row['oldpath']));
88  }
89
90  $query = '
91UPDATE '.CATEGORIES_TABLE.'
92  SET dir = NULL
93;';
94  pwg_query($query);
95
96  array_push($page['infos'], l10n('Information data registered in database'));
97}
98
99
100// +-----------------------------------------------------------------------+
101// |                             template init                             |
102// +-----------------------------------------------------------------------+
103
104$template->set_filenames(
105  array(
106    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
107    )
108  );
109
110$template->assign(
111    array(
112      'F_ADD_ACTION'=> $admin_base_url,
113    )
114  );
115
116// +-----------------------------------------------------------------------+
117// |                           sending html code                           |
118// +-----------------------------------------------------------------------+
119
120$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
121?>
Note: See TracBrowser for help on using the repository browser.