1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Read Metadata plugin for piwigo by TEMMII | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2016-2021 ddtddt http://temmii.com/piwigo/ | |
---|
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')) die('Hacking attempt!'); |
---|
23 | global $template; |
---|
24 | include_once(PHPWG_ROOT_PATH .'admin/include/tabsheet.class.php'); |
---|
25 | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | // | Check Access and exit when user status is not ok | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | check_status(ACCESS_ADMINISTRATOR); |
---|
30 | |
---|
31 | //-------------------------------------------------------- sections definitions |
---|
32 | if (!is_webmaster()){ |
---|
33 | array_push($page['errors'], l10n('This section is reserved for the webmaster')); |
---|
34 | } else{ |
---|
35 | |
---|
36 | if (!isset($_GET['tab'])) |
---|
37 | $page['tab'] = 'read'; |
---|
38 | else |
---|
39 | $page['tab'] = $_GET['tab']; |
---|
40 | |
---|
41 | $tabsheet = new tabsheet(); |
---|
42 | $tabsheet->add('read', l10n('Metadata'), READ_METADATA_ADMIN . '-read'); |
---|
43 | $tabsheet->select($page['tab']); |
---|
44 | $tabsheet->assign(); |
---|
45 | |
---|
46 | switch ($page['tab']) |
---|
47 | { |
---|
48 | case 'read': |
---|
49 | $admin_base_url = READ_METADATA_ADMIN.'-read'; |
---|
50 | if (isset($_GET['showmetadata']) and !isset($_POST['submitreadmetadata'])) { |
---|
51 | check_input_parameter('showmetadata', $_GET, false, PATTERN_ID); |
---|
52 | $_POST['idreadmetadata']=$_GET['showmetadata']; |
---|
53 | $_POST['submitreadmetadata']=1; |
---|
54 | } |
---|
55 | if(isset($_POST['idreadmetadata2']) and $_POST['idreadmetadata2']!=-1){ |
---|
56 | $_POST['idreadmetadata']=$_POST['idreadmetadata2']; |
---|
57 | } |
---|
58 | |
---|
59 | if(isset($_POST['idreadmetadata'])){ |
---|
60 | $template->assign( |
---|
61 | 'read', |
---|
62 | array('RM_ID' => $_POST['idreadmetadata'])); |
---|
63 | }else{ |
---|
64 | $template->assign( |
---|
65 | 'read', |
---|
66 | array('RM_ID' => '')); |
---|
67 | } |
---|
68 | |
---|
69 | $tab_picture = pwg_query('SELECT id,file,name FROM ' . IMAGES_TABLE . ' order by id;'); |
---|
70 | if (pwg_db_num_rows($tab_picture)) { |
---|
71 | while ($info_photos = pwg_db_fetch_assoc($tab_picture)) { |
---|
72 | if(empty($info_photos['name'])){$legend=$info_photos['file'];}else{$legend=$info_photos['name'];} |
---|
73 | $items = array( |
---|
74 | 'PHOTOID' => $info_photos['id'], |
---|
75 | 'PHOTOINFO' => $info_photos['id'].' - '.$legend, |
---|
76 | ); |
---|
77 | $template->append('info_photos', $items); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | if (isset($_POST['submitreadmetadata'])){ |
---|
82 | if (isset($_POST['idreadmetadata']) and is_numeric($_POST['idreadmetadata'])){ |
---|
83 | $query = 'select id,name,file,path FROM ' . IMAGES_TABLE . ' WHERE id = \''.$_POST['idreadmetadata'].'\';'; |
---|
84 | $result = pwg_query($query); |
---|
85 | $row = pwg_db_fetch_assoc($result); |
---|
86 | $filename=$row['path']; |
---|
87 | if(empty($filename)){ |
---|
88 | $_SESSION['page_infos'] = array(l10n('This ID isn\'t used in your gallery')); |
---|
89 | redirect($admin_base_url); |
---|
90 | } |
---|
91 | if(exif_imagetype($filename) != IMAGETYPE_JPEG and exif_imagetype($filename) != IMAGETYPE_TIFF_II and exif_imagetype($filename) != IMAGETYPE_TIFF_MM){ |
---|
92 | $_SESSION['page_infos'] = array(l10n('This file type doesn\'t use metadata')); |
---|
93 | redirect($admin_base_url); |
---|
94 | } |
---|
95 | $rd_image = new SrcImage($row); |
---|
96 | $name=$row['name']; |
---|
97 | $file=$row['file']; |
---|
98 | $template->assign( |
---|
99 | 'readmetadata', |
---|
100 | array( |
---|
101 | 'RM_NAME' => $name, |
---|
102 | 'RM_FILE' => $file, |
---|
103 | 'RM_SCR' => DerivativeImage::url(IMG_THUMB, $rd_image), |
---|
104 | 'U_SHOWPHOTOADMIN' => 'admin.php?page=photo-'.$_POST['idreadmetadata'], |
---|
105 | )); |
---|
106 | /*IPTC*/ |
---|
107 | $iptc_result = array(); |
---|
108 | $imginfo = array(); |
---|
109 | getimagesize($filename, $imginfo); |
---|
110 | if (isset($imginfo['APP13'])){ |
---|
111 | $iptc = iptcparse($imginfo['APP13']); |
---|
112 | if (is_array($iptc)){ |
---|
113 | foreach (array_keys($iptc) as $iptc_key){ |
---|
114 | if (isset($iptc[$iptc_key][0])){ |
---|
115 | if ($iptc_key == '2#025'){ |
---|
116 | $value = implode(',', |
---|
117 | array_map( |
---|
118 | 'clean_iptc_value', |
---|
119 | $iptc[$iptc_key] |
---|
120 | ) |
---|
121 | ); |
---|
122 | }else{ |
---|
123 | $value = clean_iptc_value($iptc[$iptc_key][0]); |
---|
124 | } |
---|
125 | $iptc_result[$iptc_key] = $value; |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | $template->assign( |
---|
130 | 'readmetadata2', |
---|
131 | array( |
---|
132 | 'RM_IPTCWORDING' => 'IPTC Fields in ', |
---|
133 | )); |
---|
134 | $keys = array_keys($iptc_result); |
---|
135 | sort($keys); |
---|
136 | foreach ($keys as $key){ |
---|
137 | $items['RM_KEY'] = $key; |
---|
138 | $items['RM_VALUE'] = $iptc_result[$key]; |
---|
139 | $template->append('rm_iptc', $items); |
---|
140 | } |
---|
141 | }else{ |
---|
142 | $template->assign( |
---|
143 | 'readmetadata2', |
---|
144 | array( |
---|
145 | 'RM_IPTCWORDING' => 'no IPTC information ', |
---|
146 | )); |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | /*Exif*/ |
---|
151 | $exif = exif_read_data($filename); |
---|
152 | foreach ($exif as $key => $section){ |
---|
153 | if(is_array($section)){ |
---|
154 | $i=0; |
---|
155 | foreach ($section as $name => $value){ |
---|
156 | if($i==0){ |
---|
157 | $items['RM_SECTION'] = $key.'<br>'; |
---|
158 | }else{ |
---|
159 | $items['RM_SECTION'] = ''; |
---|
160 | } |
---|
161 | $items['RM_KEY'] = $name; |
---|
162 | $items['RM_VALUE'] = $value; |
---|
163 | $template->append('rm_exif', $items); |
---|
164 | $i++; |
---|
165 | } |
---|
166 | }else{ |
---|
167 | $items['RM_SECTION'] = '1'; |
---|
168 | $items['RM_KEY'] = $key; |
---|
169 | $items['RM_VALUE'] = $section; |
---|
170 | $template->append('rm_exif', $items); |
---|
171 | } |
---|
172 | } |
---|
173 | $template->assign( |
---|
174 | 'readmetadata3', |
---|
175 | array( |
---|
176 | 'RM_EXIFWORDING' => 'EXIF Fields in ', |
---|
177 | )); |
---|
178 | |
---|
179 | # |
---|
180 | # Read and parse XMP metadata |
---|
181 | # (ImageMagick PHP extension required) |
---|
182 | # |
---|
183 | |
---|
184 | // Check ImageMagick is installed |
---|
185 | if ( extension_loaded( 'imagick' ) && |
---|
186 | class_exists( 'imagick' )) { |
---|
187 | |
---|
188 | //create new Imagick object from image & get the XMP data |
---|
189 | $RM_IM = new imagick($filename) ; |
---|
190 | $RM_XMP = $RM_IM -> getImageProperties( "xmp:*" ) ; |
---|
191 | |
---|
192 | // Setup readout |
---|
193 | $headerTxt = 'XMP Properties:' ; |
---|
194 | $template -> assign('XMPdata', $RM_XMP) ; |
---|
195 | } |
---|
196 | else { |
---|
197 | $headerTxt = l10n('Unable to read XMP data. ImageMagick not loaded.') ; |
---|
198 | } |
---|
199 | |
---|
200 | $template -> assign('XMPheader', $headerTxt ) ; |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | }else{ |
---|
205 | $_SESSION['page_infos'] = array(l10n('You must choose a photo ID')); |
---|
206 | redirect($admin_base_url); |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | break; |
---|
214 | } |
---|
215 | |
---|
216 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
217 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
218 | } |
---|
219 | ?> |
---|