1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Read Metadata | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2016 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'])) { |
---|
51 | check_input_parameter('showmetadata', $_GET, false, PATTERN_ID); |
---|
52 | $_POST['idreadmetadata']=$_GET['showmetadata']; |
---|
53 | $_POST['submitreadmetadata']=1; |
---|
54 | } |
---|
55 | |
---|
56 | if(isset($_POST['idreadmetadata'])){ |
---|
57 | $template->assign( |
---|
58 | 'read', |
---|
59 | array('RM_ID' => $_POST['idreadmetadata'])); |
---|
60 | }else{ |
---|
61 | $template->assign( |
---|
62 | 'read', |
---|
63 | array('RM_ID' => '')); |
---|
64 | } |
---|
65 | if (isset($_POST['submitreadmetadata'])){ |
---|
66 | if (isset($_POST['idreadmetadata']) and is_numeric($_POST['idreadmetadata'])){ |
---|
67 | $query = 'select id,name,file,path FROM ' . IMAGES_TABLE . ' WHERE id = \''.$_POST['idreadmetadata'].'\';'; |
---|
68 | $result = pwg_query($query); |
---|
69 | $row = pwg_db_fetch_assoc($result); |
---|
70 | $filename=$row['path']; |
---|
71 | if(empty($filename)){ |
---|
72 | $_SESSION['page_infos'] = array(l10n('This ID isn\'t used in your gallery')); |
---|
73 | redirect($admin_base_url); |
---|
74 | } |
---|
75 | if(exif_imagetype($filename) != IMAGETYPE_JPEG and exif_imagetype($filename) != IMAGETYPE_TIFF_II and exif_imagetype($filename) != IMAGETYPE_TIFF_MM){ |
---|
76 | $_SESSION['page_infos'] = array(l10n('This file type isn\'t use metadata')); |
---|
77 | redirect($admin_base_url); |
---|
78 | } |
---|
79 | $rd_image = new SrcImage($row); |
---|
80 | $name=$row['name']; |
---|
81 | $file=$row['file']; |
---|
82 | $template->assign( |
---|
83 | 'readmetadata', |
---|
84 | array( |
---|
85 | 'RM_NAME' => $name, |
---|
86 | 'RM_FILE' => $file, |
---|
87 | 'RM_SCR' => DerivativeImage::url(IMG_THUMB, $rd_image), |
---|
88 | 'U_SHOWPHOTOADMIN' => 'admin.php?page=photo-'.$_POST['idreadmetadata'].'&rmphotoid='.$_POST['idreadmetadata'], |
---|
89 | )); |
---|
90 | /*IPTC*/ |
---|
91 | $iptc_result = array(); |
---|
92 | $imginfo = array(); |
---|
93 | getimagesize($filename, $imginfo); |
---|
94 | if (isset($imginfo['APP13'])){ |
---|
95 | $iptc = iptcparse($imginfo['APP13']); |
---|
96 | if (is_array($iptc)){ |
---|
97 | foreach (array_keys($iptc) as $iptc_key){ |
---|
98 | if (isset($iptc[$iptc_key][0])){ |
---|
99 | if ($iptc_key == '2#025'){ |
---|
100 | $value = implode(',', |
---|
101 | array_map( |
---|
102 | 'clean_iptc_value', |
---|
103 | $iptc[$iptc_key] |
---|
104 | ) |
---|
105 | ); |
---|
106 | }else{ |
---|
107 | $value = clean_iptc_value($iptc[$iptc_key][0]); |
---|
108 | } |
---|
109 | $iptc_result[$iptc_key] = $value; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | $template->assign( |
---|
114 | 'readmetadata2', |
---|
115 | array( |
---|
116 | 'RM_IPTCWORDING' => 'IPTC Fields in ', |
---|
117 | )); |
---|
118 | $keys = array_keys($iptc_result); |
---|
119 | sort($keys); |
---|
120 | foreach ($keys as $key){ |
---|
121 | $items['RM_KEY'] = $key; |
---|
122 | $items['RM_VALUE'] = $iptc_result[$key]; |
---|
123 | $template->append('rm_iptc', $items); |
---|
124 | } |
---|
125 | }else{ |
---|
126 | $template->assign( |
---|
127 | 'readmetadata2', |
---|
128 | array( |
---|
129 | 'RM_IPTCWORDING' => 'no IPTC information ', |
---|
130 | )); |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | /*Exif*/ |
---|
135 | $exif = read_exif_data($filename); |
---|
136 | foreach ($exif as $key => $section){ |
---|
137 | if(is_array($section)){ |
---|
138 | $i=0; |
---|
139 | foreach ($section as $name => $value){ |
---|
140 | if($i==0){ |
---|
141 | $items['RM_SECTION'] = $key.'<br>'; |
---|
142 | }else{ |
---|
143 | $items['RM_SECTION'] = ''; |
---|
144 | } |
---|
145 | $items['RM_KEY'] = $name; |
---|
146 | $items['RM_VALUE'] = $value; |
---|
147 | $template->append('rm_exif', $items); |
---|
148 | $i++; |
---|
149 | } |
---|
150 | }else{ |
---|
151 | $items['RM_SECTION'] = '1'; |
---|
152 | $items['RM_KEY'] = $key; |
---|
153 | $items['RM_VALUE'] = $section; |
---|
154 | $template->append('rm_exif', $items); |
---|
155 | } |
---|
156 | } |
---|
157 | $template->assign( |
---|
158 | 'readmetadata3', |
---|
159 | array( |
---|
160 | 'RM_EXIFWORDING' => 'EXIF Fields in ', |
---|
161 | )); |
---|
162 | |
---|
163 | |
---|
164 | }else{ |
---|
165 | $_SESSION['page_infos'] = array(l10n('You must chose ID photo')); |
---|
166 | redirect($admin_base_url); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | |
---|
172 | |
---|
173 | break; |
---|
174 | } |
---|
175 | |
---|
176 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
177 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
178 | } |
---|
179 | ?> |
---|