source: extensions/read_metadata/admin.php

Last change on this file was 33042, checked in by ddtddt, 3 months ago

[read_metadata] SHOW iptc

File size: 7.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Read Metadata plugin for piwigo  by TEMMII                            |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2016-2023 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
22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
23global $template;
24include_once(PHPWG_ROOT_PATH .'admin/include/tabsheet.class.php');
25
26// +-----------------------------------------------------------------------+
27// | Check Access and exit when user status is not ok                      |
28// +-----------------------------------------------------------------------+
29check_status(ACCESS_ADMINISTRATOR);
30
31//-------------------------------------------------------- sections definitions
32if (!is_webmaster()){
33  array_push($page['errors'], l10n('This section is reserved for the webmaster'));
34} else{
35
36if (!isset($_GET['tab']))
37    $page['tab'] = 'read';
38else
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
46switch ($page['tab'])
47{
48  case 'read':
49$admin_base_url = READ_METADATA_ADMIN.'-read';
50if (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}
55if(isset($_POST['idreadmetadata2']) and $_POST['idreadmetadata2']!=-1){
56  $_POST['idreadmetadata']=$_POST['idreadmetadata2'];
57}
58
59if(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
81if (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                  'RM_IPTView' => 'view',
134          ));
135      $keys = array_keys($iptc_result);
136      sort($keys);
137          foreach ($keys as $key){
138                $items['RM_KEY'] = $key;
139                $items['RM_VALUE'] = $iptc_result[$key];
140                $template->append('rm_iptc', $items);
141          }
142        }else{
143          $template->assign(
144            'readmetadata2',
145                  array(
146                    'RM_IPTCWORDING' => 'no IPTC information ',
147          ));
148
149    }
150       
151        /*Exif*/
152        $exif = exif_read_data($filename);
153        foreach ($exif as $key => $section){
154                if(is_array($section)){
155                        $i=0;
156                  foreach ($section as $name => $value){
157                        if($i==0){
158                          $items['RM_SECTION'] = $key.'<br>';
159                        }else{
160                          $items['RM_SECTION'] = '';
161                        }
162                        $items['RM_KEY'] = $name;
163                        $items['RM_VALUE'] = $value;
164                        $template->append('rm_exif', $items);
165                        $i++;
166                  }
167                }else{
168                        $items['RM_SECTION'] = '1';
169                        $items['RM_KEY'] = $key;
170                        $items['RM_VALUE'] = $section;
171                        $template->append('rm_exif', $items);
172                }
173        }
174        $template->assign(
175          'readmetadata3',
176                array(
177                  'RM_EXIFWORDING' => 'EXIF Fields in ',
178          ));
179         
180        #
181        #       Read and parse XMP metadata
182        #       (ImageMagick PHP extension required)
183        #
184
185        //      Check ImageMagick is installed
186        if      (       extension_loaded(       'imagick' ) &&
187                        class_exists(           'imagick' )) { 
188
189                //create new Imagick object from image & get the XMP data
190                $RM_IM =                        new imagick($filename) ;               
191                $RM_XMP =                       $RM_IM -> getImageProperties( "xmp:*" ) ;
192
193                // Setup readout
194                $headerTxt = 'XMP Properties:' ;
195                $template -> assign('XMPdata', $RM_XMP) ;
196        }
197        else {
198                $headerTxt = l10n('Unable to read XMP data. ImageMagick not loaded.') ;
199        }
200
201        $template ->    assign('XMPheader', $headerTxt ) ;
202
203
204       
205  }else{
206        $_SESSION['page_infos'] = array(l10n('You must choose a photo ID'));
207        redirect($admin_base_url);
208  }
209}
210               
211               
212               
213               
214  break;
215} 
216
217$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); 
218$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
219}
220?>
Note: See TracBrowser for help on using the repository browser.