source: extensions/virtualize/admin.php @ 30249

Last change on this file since 30249 was 29761, checked in by plg, 10 years ago

manage pwg_representative and keep original file extension (useful for videos, pdf, etc.)

File size: 4.6 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    representative_ext,
49    id
50  FROM '.IMAGES_TABLE.'
51  WHERE path NOT LIKE \'./upload/%\'
52;';
53  $result = pwg_query($query);
54  while ($row = pwg_db_fetch_assoc($result))
55  {
56    $file_for_md5sum  = $row['oldpath'];
57    $md5sum = md5_file($file_for_md5sum);
58
59    list($year, $month, $day, $hour, $minute, $second) = preg_split('/[^\d]+/', $row['date_available']);
60
61    $upload_dir = './upload/'.$year.'/'.$month.'/'.$day;
62    mkgetdir($upload_dir);
63
64    $newfilename_wo_ext = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8);
65   
66    $extension = get_extension($row['oldpath']);
67    $newfilename = $newfilename_wo_ext.'.'.$extension;
68
69    $newpath = $upload_dir.'/'.$newfilename;
70
71    if (rename($row['oldpath'], $newpath))
72    {
73      if (!empty($row['representative_ext']))
74      {
75        $rep_dir = $upload_dir.'/pwg_representative';
76        mkgetdir($rep_dir);
77       
78        $rep_oldpath = original_to_representative($row['oldpath'], $row['representative_ext']);
79        rename($rep_oldpath, $rep_dir.'/'.$newfilename_wo_ext.'.'.$row['representative_ext']);
80      }
81
82      $query = '
83UPDATE '.IMAGES_TABLE.'
84  SET path = \''.$newpath.'\',
85      storage_category_id = NULL
86  WHERE id = '.$row['id'].'
87;';
88      pwg_query($query);
89
90      delete_element_derivatives(
91        array(
92          'path' => $row['oldpath'],
93          'representative_ext' => $row['representative_ext'],
94          )
95        );
96    }
97  }
98
99  $query = '
100UPDATE '.CATEGORIES_TABLE.'
101  SET dir = NULL
102;';
103  pwg_query($query);
104
105  array_push($page['infos'], l10n('Information data registered in database'));
106}
107
108
109// +-----------------------------------------------------------------------+
110// |                             template init                             |
111// +-----------------------------------------------------------------------+
112
113$template->set_filenames(
114  array(
115    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
116    )
117  );
118
119$template->assign(
120    array(
121      'F_ADD_ACTION'=> $admin_base_url,
122    )
123  );
124
125// +-----------------------------------------------------------------------+
126// |                           sending html code                           |
127// +-----------------------------------------------------------------------+
128
129$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
130?>
Note: See TracBrowser for help on using the repository browser.