1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : admin_sync.php |
---|
4 | * Project : piwigo-openstreetmap |
---|
5 | * Descr : Generate the admin panel |
---|
6 | * Base on : RV Maps & Earth plugin |
---|
7 | * |
---|
8 | * Created : 12.06.2013 |
---|
9 | * |
---|
10 | * Copyright 2013 <xbgmsharp@gmail.com> |
---|
11 | * |
---|
12 | * |
---|
13 | * This program is free software: you can redistribute it and/or modify |
---|
14 | * it under the terms of the GNU General Public License as published by |
---|
15 | * the Free Software Foundation, either version 3 of the License, or |
---|
16 | * (at your option) any later version. |
---|
17 | * |
---|
18 | * This program is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
25 | * |
---|
26 | ************************************************/ |
---|
27 | |
---|
28 | // Check whether we are indeed included by Piwigo. |
---|
29 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
30 | |
---|
31 | // Geneate default value |
---|
32 | $sync_options = array( |
---|
33 | 'simulate' => true, |
---|
34 | 'cat_id' => 0, |
---|
35 | 'subcats_included' => true, |
---|
36 | ); |
---|
37 | |
---|
38 | if ( isset($_POST['submit']) ) |
---|
39 | { |
---|
40 | // Override default value from the form |
---|
41 | $sync_options = array( |
---|
42 | 'simulate' => isset($_POST['simulate']), |
---|
43 | 'cat_id' => isset($_POST['cat_id']) ? (int)$_POST['cat_id'] : 0, |
---|
44 | 'subcats_included' => isset($_POST['subcats_included']), |
---|
45 | ); |
---|
46 | |
---|
47 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
48 | include_once( dirname(__FILE__).'/../include/functions_metadata.php' ); |
---|
49 | $where_clauses = array(); |
---|
50 | if ( $sync_options['cat_id']!=0 ) |
---|
51 | { |
---|
52 | $query=' SELECT id FROM '.CATEGORIES_TABLE.' WHERE '; |
---|
53 | |
---|
54 | if ( $sync_options['subcats_included']) |
---|
55 | $query .= 'uppercats REGEXP \'(^|,)'.$sync_options['cat_id'].'(,|$)\''; |
---|
56 | else |
---|
57 | $query .= 'id='.$sync_options['cat_id']; |
---|
58 | $cat_ids = array_from_query($query, 'id'); |
---|
59 | |
---|
60 | $query='SELECT `id`, `path` ,`lat` ,`lon` FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id |
---|
61 | WHERE category_id IN ('.implode(',', $cat_ids).') |
---|
62 | GROUP BY id'; |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | $query='SELECT `id`, `path` ,`lat` ,`lon` FROM '.IMAGES_TABLE; |
---|
67 | } |
---|
68 | |
---|
69 | $images = hash_from_query( $query, 'id'); |
---|
70 | $datas = array(); |
---|
71 | $errors = array(); |
---|
72 | foreach ($images as $image) |
---|
73 | { |
---|
74 | $filename = $image['path']; |
---|
75 | $exif = @read_exif_data( $filename ); |
---|
76 | if ( empty($exif) ) |
---|
77 | continue; |
---|
78 | |
---|
79 | $ll = osm_exif_to_lat_lon($exif); |
---|
80 | if (!is_array($ll)) |
---|
81 | { |
---|
82 | if (!empty($ll)) |
---|
83 | $errors[] = $filename. ': '.$ll; |
---|
84 | continue; |
---|
85 | } |
---|
86 | |
---|
87 | $infos[] = $filename. " has exif_data"; |
---|
88 | $datas[] = array ( |
---|
89 | 'id' => $image['id'], |
---|
90 | 'lat' => $ll[0], |
---|
91 | 'lon' => $ll[1], |
---|
92 | ); |
---|
93 | } |
---|
94 | |
---|
95 | if ( count($datas)>0 and !$sync_options['simulate'] ) |
---|
96 | { |
---|
97 | mass_updates( |
---|
98 | IMAGES_TABLE, |
---|
99 | array( |
---|
100 | 'primary' => array('id'), |
---|
101 | 'update' => array('lat', 'lon') |
---|
102 | ), |
---|
103 | $datas |
---|
104 | ); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | // Send sync result to template |
---|
109 | $template->assign('sync_errors', $errors ); |
---|
110 | $template->assign('sync_infos', $infos ); |
---|
111 | |
---|
112 | // Send result to templates |
---|
113 | $template->assign( |
---|
114 | 'metadata_result', |
---|
115 | array( |
---|
116 | 'NB_ELEMENTS_DONE' => count($datas), |
---|
117 | 'NB_ELEMENTS_CANDIDATES' => count($images), |
---|
118 | 'NB_ERRORS' => count($errors), |
---|
119 | ) |
---|
120 | ); |
---|
121 | } |
---|
122 | |
---|
123 | $query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.' WHERE `lat` IS NOT NULL and `lon` IS NOT NULL '; |
---|
124 | list($nb_geotagged) = pwg_db_fetch_array( pwg_query($query) ); |
---|
125 | |
---|
126 | $query = 'SELECT id, CONCAT(name, IF(dir IS NULL, " (V)", "") ) AS name, uppercats, global_rank FROM '.CATEGORIES_TABLE; |
---|
127 | display_select_cat_wrapper($query, |
---|
128 | array( $sync_options['cat_id'] ), |
---|
129 | 'categories', |
---|
130 | false); |
---|
131 | |
---|
132 | // Send value to templates |
---|
133 | $template->assign( |
---|
134 | array( |
---|
135 | 'SUBCATS_INCLUDED_CHECKED' => $sync_options['subcats_included'] ? 'checked="checked"' : '', |
---|
136 | 'NB_GEOTAGGED' => $nb_geotagged, |
---|
137 | ) |
---|
138 | ); |
---|
139 | |
---|
140 | ?> |
---|