source: extensions/read_metadata/admin.php @ 31936

Last change on this file since 31936 was 31748, checked in by ddtddt, 7 years ago

[extensions] - read_metadata

File size: 6.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Read Metadata                                                         |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2016-2017 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,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                        $items = array(
73                                        'PHOTOID' => $info_photos['id'],
74                                        'PHOTOINFO' => $info_photos['id'].' - '.$info_photos['name'],
75                                );
76                        $template->append('info_photos', $items);
77        }
78    }
79
80if (isset($_POST['submitreadmetadata'])){
81  if (isset($_POST['idreadmetadata']) and is_numeric($_POST['idreadmetadata'])){
82        $query = 'select id,name,file,path FROM ' . IMAGES_TABLE . ' WHERE id = \''.$_POST['idreadmetadata'].'\';';
83        $result = pwg_query($query);
84        $row = pwg_db_fetch_assoc($result);
85        $filename=$row['path'];
86        if(empty($filename)){
87          $_SESSION['page_infos'] = array(l10n('This ID isn\'t used in your gallery'));
88          redirect($admin_base_url);
89        }
90        if(exif_imagetype($filename) != IMAGETYPE_JPEG and exif_imagetype($filename) != IMAGETYPE_TIFF_II and exif_imagetype($filename) != IMAGETYPE_TIFF_MM){
91          $_SESSION['page_infos'] = array(l10n('This file type doesn\'t use metadata'));
92          redirect($admin_base_url);           
93        }
94        $rd_image = new SrcImage($row);
95        $name=$row['name'];
96        $file=$row['file'];
97        $template->assign(
98          'readmetadata',
99                array(
100                  'RM_NAME' => $name,
101                  'RM_FILE' => $file,
102                  'RM_SCR' => DerivativeImage::url(IMG_THUMB, $rd_image),
103                  'U_SHOWPHOTOADMIN' => 'admin.php?page=photo-'.$_POST['idreadmetadata'],
104        ));
105        /*IPTC*/
106        $iptc_result = array();
107        $imginfo = array();
108        getimagesize($filename, $imginfo);
109        if (isset($imginfo['APP13'])){
110          $iptc = iptcparse($imginfo['APP13']);
111          if (is_array($iptc)){
112                foreach (array_keys($iptc) as $iptc_key){
113          if (isset($iptc[$iptc_key][0])){
114           if ($iptc_key == '2#025'){
115             $value = implode(',',
116               array_map(
117                 'clean_iptc_value',
118                 $iptc[$iptc_key]
119               )
120             );
121           }else{
122             $value = clean_iptc_value($iptc[$iptc_key][0]);
123           }
124           $iptc_result[$iptc_key] = $value;
125          }
126        }
127      }
128          $template->assign(
129          'readmetadata2',
130                array(
131                  'RM_IPTCWORDING' => 'IPTC Fields in ',
132          ));
133      $keys = array_keys($iptc_result);
134      sort($keys);
135          foreach ($keys as $key){
136                $items['RM_KEY'] = $key;
137                $items['RM_VALUE'] = $iptc_result[$key];
138                $template->append('rm_iptc', $items);
139          }
140        }else{
141          $template->assign(
142            'readmetadata2',
143                  array(
144                    'RM_IPTCWORDING' => 'no IPTC information ',
145          ));
146
147    }
148       
149        /*Exif*/
150        $exif = read_exif_data($filename);
151        foreach ($exif as $key => $section){
152                if(is_array($section)){
153                        $i=0;
154                  foreach ($section as $name => $value){
155                        if($i==0){
156                          $items['RM_SECTION'] = $key.'<br>';
157                        }else{
158                          $items['RM_SECTION'] = '';
159                        }
160                        $items['RM_KEY'] = $name;
161                        $items['RM_VALUE'] = $value;
162                        $template->append('rm_exif', $items);
163                        $i++;
164                  }
165                }else{
166                        $items['RM_SECTION'] = '1';
167                        $items['RM_KEY'] = $key;
168                        $items['RM_VALUE'] = $section;
169                        $template->append('rm_exif', $items);
170                }
171        }
172        $template->assign(
173          'readmetadata3',
174                array(
175                  'RM_EXIFWORDING' => 'EXIF Fields in ',
176          ));
177
178       
179  }else{
180        $_SESSION['page_infos'] = array(l10n('You must choose a photo ID'));
181        redirect($admin_base_url);
182  }
183}
184               
185               
186               
187               
188  break;
189} 
190
191$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); 
192$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
193}
194?>
Note: See TracBrowser for help on using the repository browser.