source: extensions/read_metadata/admin.php @ 31551

Last change on this file since 31551 was 31551, checked in by ddtddt, 8 years ago

[extensions] - read_metadata - Beta 1

File size: 4.9 KB
Line 
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
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($_POST['idreadmetadata'])){
51$template->assign(
52  'read',
53    array('RM_ID' => $_POST['idreadmetadata']));
54}else{
55$template->assign(
56  'read',
57    array('RM_ID' => ''));     
58}
59if (isset($_POST['submitreadmetadata'])){
60  if (isset($_POST['idreadmetadata']) and is_numeric($_POST['idreadmetadata'])){
61        $query = 'select name,file,path FROM ' . IMAGES_TABLE . ' WHERE id = \''.$_POST['idreadmetadata'].'\';';
62        $result = pwg_query($query);
63        $row = pwg_db_fetch_assoc($result);
64        $filename=$row['path'];
65        if(empty($filename)){
66          $_SESSION['page_infos'] = array(l10n('This ID isn\'t used in your gallery'));
67          redirect($admin_base_url);
68        }
69        $name=$row['name'];
70        $file=$row['file'];
71        $template->assign(
72          'readmetadata',
73                array(
74                  'RM_NAME' => $name,
75                  'RM_FILE' => $file,
76        ));
77        /*IPTC*/
78        $iptc_result = array();
79        $imginfo = array();
80        getimagesize($filename, $imginfo);
81        if (isset($imginfo['APP13'])){
82          $iptc = iptcparse($imginfo['APP13']);
83          if (is_array($iptc)){
84                foreach (array_keys($iptc) as $iptc_key){
85          if (isset($iptc[$iptc_key][0])){
86           if ($iptc_key == '2#025'){
87             $value = implode(',',
88               array_map(
89                 'clean_iptc_value',
90                 $iptc[$iptc_key]
91               )
92             );
93           }else{
94             $value = clean_iptc_value($iptc[$iptc_key][0]);
95           }
96           $iptc_result[$iptc_key] = $value;
97          }
98        }
99      }
100          $template->assign(
101          'readmetadata2',
102                array(
103                  'RM_IPTCWORDING' => 'IPTC Fields in ',
104          ));
105      $keys = array_keys($iptc_result);
106      sort($keys);
107          foreach ($keys as $key){
108                $items['RM_KEY'] = $key;
109                $items['RM_VALUE'] = $iptc_result[$key];
110                $template->append('rm_iptc', $items);
111          }
112        }else{
113          $template->assign(
114            'readmetadata2',
115                  array(
116                    'RM_IPTCWORDING' => 'no IPTC information ',
117          ));
118
119    }
120       
121        /*Exif*/
122        $exif = read_exif_data($filename);
123        foreach ($exif as $key => $section){
124                if(is_array($section)){
125                  foreach ($section as $name => $value){
126                        $items['RM_KEY'] = $key.' -> '.$name;
127                        $items['RM_VALUE'] = $value;
128                  }
129                }else{
130                        $items['RM_KEY'] = $key;
131                        $items['RM_VALUE'] = $section;
132                }
133                $template->append('rm_exif', $items);
134        }
135        $template->assign(
136          'readmetadata3',
137                array(
138                  'RM_EXIFWORDING' => 'EXIF Fields in ',
139          ));
140
141       
142  }else{
143        $_SESSION['page_infos'] = array(l10n('You must chose ID photo'));
144        redirect($admin_base_url);
145  }
146}
147               
148               
149               
150               
151  break;
152} 
153
154$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); 
155$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
156}
157?>
Note: See TracBrowser for help on using the repository browser.