[9562] | 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 | |
---|
| 22 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 23 | { |
---|
| 24 | die ("Hacking attempt!"); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 28 | |
---|
| 29 | $admin_base_url = get_root_url().'admin.php?page=plugin§ion=virtualize%2Fadmin.php'; |
---|
| 30 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 31 | |
---|
| 32 | // +-----------------------------------------------------------------------+ |
---|
| 33 | // | Check Access and exit when user status is not ok | |
---|
| 34 | // +-----------------------------------------------------------------------+ |
---|
| 35 | |
---|
| 36 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 37 | |
---|
| 38 | // +-----------------------------------------------------------------------+ |
---|
| 39 | // | add permissions | |
---|
| 40 | // +-----------------------------------------------------------------------+ |
---|
| 41 | |
---|
| 42 | if (isset($_POST['submit'])) |
---|
| 43 | { |
---|
| 44 | $query = ' |
---|
| 45 | SELECT |
---|
| 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 | $newfilename = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8).'.jpg'; |
---|
| 80 | |
---|
| 81 | $newpath = $upload_dir.'/'.$newfilename; |
---|
| 82 | |
---|
| 83 | $query = ' |
---|
| 84 | UPDATE '.IMAGES_TABLE.' |
---|
| 85 | SET path = \''.$newpath.'\', |
---|
| 86 | storage_category_id = NULL |
---|
| 87 | WHERE id = '.$row['id'].' |
---|
| 88 | ;'; |
---|
| 89 | pwg_query($query); |
---|
| 90 | |
---|
| 91 | rename($row['oldpath'], $newpath); |
---|
| 92 | |
---|
| 93 | # high definition |
---|
| 94 | if ('true' == $row['has_high']) |
---|
| 95 | { |
---|
| 96 | $high_dir = $upload_dir.'/pwg_high'; |
---|
| 97 | |
---|
| 98 | if (!is_dir($high_dir)) |
---|
| 99 | { |
---|
| 100 | umask(0000); |
---|
| 101 | $recursive = true; |
---|
| 102 | if (!@mkdir($high_dir, 0777, $recursive)) |
---|
| 103 | { |
---|
| 104 | echo 'error during "'.$high_dir.'" directory creation'; |
---|
| 105 | exit(); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | rename( |
---|
| 110 | dirname($row['oldpath']).'/pwg_high/'.basename($row['oldpath']), |
---|
| 111 | $high_dir.'/'.$newfilename |
---|
| 112 | ); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | # thumbnail |
---|
| 116 | $tn_dir = $upload_dir.'/thumbnail'; |
---|
| 117 | |
---|
| 118 | if (!is_dir($tn_dir)) |
---|
| 119 | { |
---|
| 120 | umask(0000); |
---|
| 121 | $recursive = true; |
---|
| 122 | if (!@mkdir($tn_dir, 0777, $recursive)) |
---|
| 123 | { |
---|
| 124 | echo 'error during "'.$tn_dir.'" directory creation'; |
---|
| 125 | exit(); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | $tn_oldname = $conf['prefix_thumbnail']; |
---|
| 130 | $tn_oldname.= get_filename_wo_extension(basename($row['oldpath'])); |
---|
| 131 | $tn_oldname.= '.'.$row['tn_ext']; |
---|
| 132 | |
---|
| 133 | rename( |
---|
| 134 | dirname($row['oldpath']).'/thumbnail/'.$tn_oldname, |
---|
| 135 | $tn_dir.'/'.$conf['prefix_thumbnail'].$newfilename |
---|
| 136 | ); |
---|
| 137 | |
---|
| 138 | // break; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | $query = ' |
---|
| 142 | UPDATE '.CATEGORIES_TABLE.' |
---|
| 143 | SET dir = NULL |
---|
| 144 | ;'; |
---|
| 145 | pwg_query($query); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | // +-----------------------------------------------------------------------+ |
---|
| 150 | // | template init | |
---|
| 151 | // +-----------------------------------------------------------------------+ |
---|
| 152 | |
---|
| 153 | $template->set_filenames( |
---|
| 154 | array( |
---|
| 155 | 'plugin_admin_content' => dirname(__FILE__).'/admin.tpl' |
---|
| 156 | ) |
---|
| 157 | ); |
---|
| 158 | |
---|
| 159 | $template->assign( |
---|
| 160 | array( |
---|
| 161 | 'F_ADD_ACTION'=> $admin_base_url, |
---|
| 162 | ) |
---|
| 163 | ); |
---|
| 164 | |
---|
| 165 | // +-----------------------------------------------------------------------+ |
---|
| 166 | // | sending html code | |
---|
| 167 | // +-----------------------------------------------------------------------+ |
---|
| 168 | |
---|
| 169 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 170 | ?> |
---|