source: extensions/virtualize/admin.php @ 16319

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

better management on GVideo videos

File size: 5.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    has_high,
49    tn_ext,
50    id
51  FROM '.IMAGES_TABLE.'
52  WHERE path NOT LIKE \'./upload/%\'
53;';
54  $result = pwg_query($query);
55  while ($row = pwg_db_fetch_assoc($result))
56  {
57    $file_for_md5sum  = $row['oldpath'];
58    if ('true' == $row['has_high'])
59    {
60      $file_for_md5sum = dirname($row['oldpath']).'/pwg_high/'.basename($row['oldpath']);
61    }
62    $md5sum = md5_file($file_for_md5sum);
63
64    list($year, $month, $day, $hour, $minute, $second) = preg_split('/[^\d]+/', $row['date_available']);
65
66    $upload_dir = './upload/'.$year.'/'.$month.'/'.$day;
67    if (!is_dir($upload_dir))
68    {
69      umask(0000);
70      $recursive = true;
71      if (!@mkdir($upload_dir, 0777, $recursive))
72      {
73        echo 'error during "'.$upload_dir.'" directory creation';
74        exit();
75      }
76    }
77    secure_directory($upload_dir);
78
79    $extension = get_extension($row['oldpath']);
80    if (in_array($extension, array('vimeo', 'ytube', 'dm')))
81    {
82      $newfilename = basename($row['oldpath']);
83    }
84    else
85    {
86      $newfilename = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8).'.jpg';
87    }
88
89    $newpath = $upload_dir.'/'.$newfilename;
90
91    $query = '
92UPDATE '.IMAGES_TABLE.'
93  SET path = \''.$newpath.'\',
94      storage_category_id = NULL
95  WHERE id = '.$row['id'].'
96;';
97    pwg_query($query);
98
99    rename($row['oldpath'], $newpath);
100
101    # high definition
102    if ('true' == $row['has_high'])
103    {
104      $high_dir = $upload_dir.'/pwg_high';
105     
106      if (!is_dir($high_dir))
107      {
108        umask(0000);
109        $recursive = true;
110        if (!@mkdir($high_dir, 0777, $recursive))
111        {
112          echo 'error during "'.$high_dir.'" directory creation';
113          exit();
114        }
115      }
116     
117      rename(
118        dirname($row['oldpath']).'/pwg_high/'.basename($row['oldpath']),
119        $high_dir.'/'.$newfilename
120        );
121    }
122
123    # thumbnail
124    if (!empty($row['tn_ext']))
125    {
126      $tn_dir = $upload_dir.'/thumbnail';
127     
128      if (!is_dir($tn_dir))
129      {
130        umask(0000);
131        $recursive = true;
132        if (!@mkdir($tn_dir, 0777, $recursive))
133        {
134          echo 'error during "'.$tn_dir.'" directory creation';
135          exit();
136        }
137      }
138     
139      $tn_oldname = $conf['prefix_thumbnail'];
140      $tn_oldname.= get_filename_wo_extension(basename($row['oldpath']));
141      $tn_oldname.= '.'.$row['tn_ext'];
142     
143      rename(
144        dirname($row['oldpath']).'/thumbnail/'.$tn_oldname,
145        $tn_dir.'/'.$conf['prefix_thumbnail'].get_filename_wo_extension(basename($newfilename)).'.jpg'
146        );
147    }
148    // break;
149  }
150
151  $query = '
152UPDATE '.CATEGORIES_TABLE.'
153  SET dir = NULL
154;';
155  pwg_query($query);
156}
157
158
159// +-----------------------------------------------------------------------+
160// |                             template init                             |
161// +-----------------------------------------------------------------------+
162
163$template->set_filenames(
164  array(
165    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
166    )
167  );
168
169$template->assign(
170    array(
171      'F_ADD_ACTION'=> $admin_base_url,
172    )
173  );
174
175// +-----------------------------------------------------------------------+
176// |                           sending html code                           |
177// +-----------------------------------------------------------------------+
178
179$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
180?>
Note: See TracBrowser for help on using the repository browser.