1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // | EDIT_CL | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | Copyright(C) 2010 cljosse | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | This program is free software; you can redistribute it and/or modify | |
---|
9 | // | it under the terms of the GNU General Public License as published by | |
---|
10 | // | the Free Software Foundation | |
---|
11 | // | | |
---|
12 | // | This program is distributed in the hope that it will be useful, but | |
---|
13 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
14 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
15 | // | General Public License for more details. | |
---|
16 | // | | |
---|
17 | // | You should have received a copy of the GNU General Public License | |
---|
18 | // | along with this program; if not, write to the Free Software | |
---|
19 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
20 | // | USA. | |
---|
21 | // +-----------------------------------------------------------------------+ |
---|
22 | if (!defined('EDIT_CL_PATH')) |
---|
23 | define( |
---|
24 | 'EDIT_CL_PATH', |
---|
25 | PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' |
---|
26 | ); |
---|
27 | if (!defined('ROOT_URL')) |
---|
28 | define( 'ROOT_URL', get_root_url().'/' ); |
---|
29 | |
---|
30 | $EDIT_CL_PATH_ABS=str_replace('\\','/',dirname(__FILE__) ); |
---|
31 | if (!defined('EDIT_CL_PATH_ABS')) |
---|
32 | define( |
---|
33 | 'EDIT_CL_PATH_ABS', $EDIT_CL_PATH_ABS."/" |
---|
34 | ); |
---|
35 | |
---|
36 | class cl_edit_functions { |
---|
37 | |
---|
38 | /************************************** |
---|
39 | * list all columns of each given table |
---|
40 | *************************************** |
---|
41 | * @return array of array |
---|
42 | */ |
---|
43 | static public function Get_columns_of($table){ |
---|
44 | $columns_of = array(); |
---|
45 | $query = 'DESC '.$table.';'; |
---|
46 | $result = mysql_query($query); |
---|
47 | $columns_of[$table] = array(); |
---|
48 | |
---|
49 | if ($result) |
---|
50 | while ($row = mysql_fetch_row($result)) |
---|
51 | array_push($columns_of[$table], $row[0]); |
---|
52 | |
---|
53 | return $columns_of; |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | class cl_edit_controler { |
---|
58 | |
---|
59 | static public function add_meta_gps($new_ps_file_info_array,$image){ |
---|
60 | global $nom_fichier,$erreur_message, $info_message; |
---|
61 | |
---|
62 | |
---|
63 | // $exif = @read_exif_data( $exif ); |
---|
64 | // $exif = @array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) ); |
---|
65 | |
---|
66 | foreach( $new_ps_file_info_array['selection'] as $filename ) { |
---|
67 | //====================================================== |
---|
68 | if($new_ps_file_info_array['lat']=='') { |
---|
69 | |
---|
70 | $new_ps_file_info_array['lat']=$image['lat']; |
---|
71 | $new_ps_file_info_array['lon']=$image['lon']; |
---|
72 | $new_ps_file_info_array['alt']=$image['alt']; |
---|
73 | } |
---|
74 | if($new_ps_file_info_array['lat']=='') { |
---|
75 | $erreur_message .= "Error - lon or lat = null : $filename <br>\n"; |
---|
76 | }else{ |
---|
77 | if($filename!="") { |
---|
78 | //= $new_ps_file_info_array[ 'filename' ]; |
---|
79 | // Protect against hackers editing other files |
---|
80 | // copy( $filename, $filename.".bak" ); |
---|
81 | $path_parts = pathinfo( $filename ); |
---|
82 | |
---|
83 | if ( strcasecmp( $path_parts["extension"], "jpg" ) != 0 ) { |
---|
84 | $erreur_message .= $filename ; |
---|
85 | $erreur_message .="Incorrect File Type - JPEG Only\n"; |
---|
86 | $filename=""; |
---|
87 | return; |
---|
88 | } |
---|
89 | // Change: removed limitation on file being in current directory - as of version 1.11 |
---|
90 | // Retrieve the header information |
---|
91 | |
---|
92 | $nom_fichier=$filename; |
---|
93 | $jpeg_header_data = get_jpeg_header_data( $filename ); |
---|
94 | // Retreive the EXIF, XMP and Photoshop IRB information from |
---|
95 | // the existing file, so that it can be updated |
---|
96 | $Exif_array = get_EXIF_JPEG( $filename ); |
---|
97 | $XMP_array = read_XMP_array_from_text( get_XMP_text( $jpeg_header_data ) ); |
---|
98 | $IRB_array = get_Photoshop_IRB( $jpeg_header_data ); |
---|
99 | // Update the JPEG header information with the new Photoshop File Info |
---|
100 | |
---|
101 | $jpeg_header_data = put_GPS_file_info( $jpeg_header_data, $new_ps_file_info_array, $Exif_array, $XMP_array, $IRB_array ); |
---|
102 | // Check if the Update worked |
---|
103 | if ( $jpeg_header_data == FALSE ) { |
---|
104 | // Update of file info didn''t work - output error message |
---|
105 | $erreur_message .= "jpeg_header_data |
---|
106 | Error - Failure update Photoshop File Info : $filename <br>\n"; |
---|
107 | return false; |
---|
108 | // Output HTML with the form and data which was |
---|
109 | // sent, to allow the user to fix it |
---|
110 | }else if ( FALSE == put_jpeg_header_data( $filename, $filename, $jpeg_header_data ) ) { |
---|
111 | // Attempt to write the new JPEG file |
---|
112 | // Writing of the new file didn''t work - output error message |
---|
113 | $erreur_message .= "Error - Failure to write new JPEG : $filename <br>\n"; |
---|
114 | return false; |
---|
115 | // Output HTML with the form and data which was |
---|
116 | // sent, to allow the user to fix it |
---|
117 | }else{ |
---|
118 | return true; |
---|
119 | } |
---|
120 | }// test filename} |
---|
121 | } //for each |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | } |
---|
127 | //========================================================== |
---|
128 | static public function Get_exif_gps($firt_image,$image,$hight_gps,$lecture_exif) { |
---|
129 | global $errors;global $template ; |
---|
130 | global $info_message ; |
---|
131 | error_reporting ( 1 ); |
---|
132 | $filename=$firt_image; |
---|
133 | |
---|
134 | $datas = array(); |
---|
135 | $errors = array(); |
---|
136 | $exif = @read_exif_data( $filename ); |
---|
137 | if ( empty($exif) ) return; |
---|
138 | |
---|
139 | $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) ); |
---|
140 | if(count($exif)==0 || $hight_gps ){ |
---|
141 | $path_parts = pathinfo( $filename ); |
---|
142 | $exif = @read_exif_data( $path_parts['dirname']."/pwg_high/".$path_parts['basename']); |
---|
143 | $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) ); |
---|
144 | } |
---|
145 | if(count($exif)==0) return ; |
---|
146 | //==================================================================== |
---|
147 | if(!$lecture_exif){ |
---|
148 | $lat = $image['lat'] ; |
---|
149 | $lon = $image['lon'] ; |
---|
150 | $alt = $image['alt']; |
---|
151 | } |
---|
152 | $p1=base_to_meta($image); |
---|
153 | |
---|
154 | if($exif['GPSLatitude'][0]=="1/1" && $lat!=""){ |
---|
155 | $exif['GPSLatitudeRef'] = $p1['GPSLatitudeRef'] ; |
---|
156 | $exif['GPSLatitude']=$p1['GPSLatitude']; |
---|
157 | $exif['GPSLongitudeRef'] = $p1['GPSLongitudeRef']; |
---|
158 | $exif['GPSLongitude']=$p1['GPSLongitude']; |
---|
159 | $exif['GPSAltitudeRef'] =$p1['GPSAltitudeRef']; |
---|
160 | $exif['GPSAltitude']= $p1['GPSAltitude']; |
---|
161 | |
---|
162 | } |
---|
163 | |
---|
164 | $is_exif = is_array($exif['GPSLatitude']) && $exif['GPSLatitude']!='' ; |
---|
165 | $is_exif = is_array($exif['GPSLongitude']) && $exif['GPSLongitude']!='' & $is_exif ; |
---|
166 | |
---|
167 | if ($is_exif) { |
---|
168 | $lat_exif = Parse_Lat_Lon( $exif['GPSLatitude'] ); |
---|
169 | $lon_exif = Parse_Lat_Lon( $exif['GPSLongitude'] ); |
---|
170 | $alt_exif = Parse_Fract( $exif['GPSAltitude'] ); |
---|
171 | } |
---|
172 | |
---|
173 | $is_exif = $lat_exif!=0; |
---|
174 | //============================== |
---|
175 | if ($lat =="" || $hight_gps){ |
---|
176 | $lat = Parse_Lat_Lon( $exif['GPSLatitude'] ); |
---|
177 | if ( $exif['GPSLatitudeRef']=='S' ) $lat = -$lat; |
---|
178 | }else{ |
---|
179 | if($lat<0) $exif['GPSLatitudeRef']='S' ; |
---|
180 | else $exif['GPSLatitudeRef']='N' ; |
---|
181 | } |
---|
182 | //============================== |
---|
183 | if ($lon =="" || $hight_gps) { |
---|
184 | $lon = Parse_Lat_Lon( $exif['GPSLongitude'] ); |
---|
185 | if ( $exif['GPSLongitudeRef']=='W' ) $lon = -$lon; |
---|
186 | }else{ |
---|
187 | if ($lon<0) $exif['GPSLongitudeRef'] ='W' ; |
---|
188 | else $exif['GPSLongitudeRef'] ='E' ; |
---|
189 | } |
---|
190 | //======================================================================= |
---|
191 | $altref = 0; |
---|
192 | if (!is_array($exif['GPSAltitude']) or !is_array($exif['GPSAltitudeRef']) ){ |
---|
193 | $exif['GPSAltitude']=$alt; |
---|
194 | $exif['GPSAltitudeRef']=0; |
---|
195 | } else { |
---|
196 | $alt = $exif['GPSAltitude']; |
---|
197 | $altref = $exif['GPSAltitudeRef']; |
---|
198 | } |
---|
199 | //======================================================================== |
---|
200 | $datas[] = array ( |
---|
201 | 'is_exif' => $is_exif , |
---|
202 | ' filename=' => $filename , |
---|
203 | 'id' => $image['id'] , |
---|
204 | 'lat' => $lat , |
---|
205 | 'lon' => $lon , |
---|
206 | 'latDMS' => $exif['GPSLatitude'][0]." ". |
---|
207 | $exif['GPSLatitude'][1]." ". |
---|
208 | $exif['GPSLatitude'][2]." ". |
---|
209 | $exif['GPSLatitudeRef'], |
---|
210 | 'lonDMS' => $exif['GPSLongitude'][0]." ". |
---|
211 | $exif['GPSLongitude'][1]." ". |
---|
212 | $exif['GPSLongitude'][2]." ". |
---|
213 | $exif['GPSLongitudeRef'], |
---|
214 | 'altref' => $exif['GPSAltitudeRef'], |
---|
215 | 'alt' => $exif['GPSAltitude'] |
---|
216 | ); |
---|
217 | |
---|
218 | return $datas[0] ; |
---|
219 | } |
---|
220 | |
---|
221 | /************************************************ |
---|
222 | * add_data_base |
---|
223 | ************************************************/ |
---|
224 | static public function add_data_base($sel,$lat,$lon,$alt){ |
---|
225 | global $page,$info_message,$erreur_message ; |
---|
226 | |
---|
227 | if ( strlen($lat)>0 and strlen($lon)>0 ) { |
---|
228 | if ( (double)$lat<=90 and (double)$lat>=-90 |
---|
229 | and (double)$lon<=180 and (double)$lat>=-180 ) |
---|
230 | $update_query = 'lat='.$lat.', lon='.$lon; |
---|
231 | else |
---|
232 | $erreur_message .= 'Invalid lat or lon value'; |
---|
233 | } |
---|
234 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
---|
235 | $update_query = 'lat=NULL, lon=NULL'; |
---|
236 | else |
---|
237 | $erreur_message .= 'Both lat/lon must be empty or not empty'; |
---|
238 | if ( strlen($alt)==0) |
---|
239 | $update_query .= ', alt=NULL'; |
---|
240 | else |
---|
241 | $update_query .= ', alt=' .$alt ; |
---|
242 | |
---|
243 | if (isset($update_query)){ |
---|
244 | $update_query = ' |
---|
245 | UPDATE '.IMAGES_TABLE.' SET '.$update_query.' |
---|
246 | WHERE id IN ('.implode(',',$sel).')'; |
---|
247 | pwg_query($update_query) ; |
---|
248 | cl_meta_invalidate_cache(); |
---|
249 | $info_message .= l10n('update') . "[DB] " . implode(',',$sel) . " ". IMAGES_TABLE . " : " . l10n('OK') ."<br />"; |
---|
250 | } |
---|
251 | } |
---|
252 | //====================================================== |
---|
253 | static public function cl_edit_admin_menu($menu) |
---|
254 | { |
---|
255 | include_once( dirname(__FILE__) .'/include/functions.php'); |
---|
256 | add_event_handler('invalidate_user_cache', 'cl_meta_invalidate_cache' ); |
---|
257 | array_push($menu, |
---|
258 | array( |
---|
259 | 'NAME' => 'EDIT Maps & Earth', |
---|
260 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/admin.php') ) |
---|
261 | ); |
---|
262 | return $menu; |
---|
263 | } |
---|
264 | /**************************** |
---|
265 | * |
---|
266 | *****************************/ |
---|
267 | static public function cl_edit_Get_Options(){ |
---|
268 | global $conf,$EDIT_CL_parametres,$infos_message ; |
---|
269 | if (!isset($conf['edit_gmaps'])){ |
---|
270 | $q = ' |
---|
271 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
272 | VALUES ("edit_gmaps","","Parametres du plugin edit_gmaps") |
---|
273 | ;'; |
---|
274 | pwg_query($q); |
---|
275 | |
---|
276 | } |
---|
277 | $EDIT_CL_parametres = unserialize($conf['edit_gmaps']); |
---|
278 | if (!isset($EDIT_CL_parametres->lat )){ |
---|
279 | $EDIT_CL_parametres= cl_edit_controler::cl_edit_Set_Options(); |
---|
280 | } |
---|
281 | |
---|
282 | return $EDIT_CL_parametres; |
---|
283 | } |
---|
284 | /* |
---|
285 | * |
---|
286 | */ |
---|
287 | static public function cl_edit_Set_Options(){ |
---|
288 | global $EDIT_CL_parametres; |
---|
289 | //============================================================================= |
---|
290 | $my_para=$EDIT_CL_parametres; |
---|
291 | $lon= isset($my_para->lon)? $my_para->lon:'' ; |
---|
292 | $lat= isset($my_para->lat)? $my_para->lat:'' ; |
---|
293 | $alt= isset($my_para->alt)? $my_para->alt:'0' ; |
---|
294 | $my_para->lon = (isset($_POST['lon']))? $_POST['lon']: $lon ; |
---|
295 | $my_para->lat = (isset($_POST['lat']))? $_POST['lat']: $lat ; |
---|
296 | $my_para->alt = (isset($_POST['alt']))? $_POST['alt']: $alt ; |
---|
297 | $my_para->adress = (isset($_POST['match']))? $_POST['match']: '' ; |
---|
298 | //=============================================================================== |
---|
299 | if ( isset($_POST['selectAction'] ) && $_POST['selectAction'] == l10n('cl_edit_save') ) { |
---|
300 | $my_para->check_exif = isset($_POST['check_exif']) ? $_POST['check_exif'] : "off" ; |
---|
301 | |
---|
302 | }else{ |
---|
303 | $my_para->check_exif = isset($_POST['check_exif']) ? $_POST['check_exif'] : ( ( isset($my_para->check_exif) ) ? $my_para->check_exif : 'off') ; |
---|
304 | } |
---|
305 | $EDIT_CL_parametres=$my_para; |
---|
306 | return $my_para; |
---|
307 | |
---|
308 | } |
---|
309 | /********************** |
---|
310 | * |
---|
311 | **********************/ |
---|
312 | static public function cl_edit_sauve_options_inf() { |
---|
313 | global $options,$infos_message,$conf,$EDIT_CL_parametres ; |
---|
314 | // $infos_message .=l10n("cl_edit_save_config")."<br>". cl_print_var($EDIT_CL_parametres); |
---|
315 | // cl_aff_infos_plus(); |
---|
316 | if ( isset($EDIT_CL_parametres) ){ |
---|
317 | $query = ' |
---|
318 | UPDATE '.CONFIG_TABLE.' |
---|
319 | SET value="'.addslashes(serialize($EDIT_CL_parametres)).'" |
---|
320 | WHERE param = "edit_gmaps" |
---|
321 | LIMIT 1'; |
---|
322 | pwg_query($query); |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | |
---|
327 | } // class |
---|
328 | |
---|
329 | /************************* |
---|
330 | * |
---|
331 | *************************/ |
---|
332 | if(!function_exists("cl_print_var")){ |
---|
333 | function cl_print_var($variables){ |
---|
334 | ob_start(); |
---|
335 | echo '<pre>'; |
---|
336 | print_r($variables); |
---|
337 | echo '</pre>'; |
---|
338 | $m= ob_get_contents(); |
---|
339 | ob_end_clean(); |
---|
340 | return $m; |
---|
341 | } |
---|
342 | } |
---|
343 | /****************** |
---|
344 | * |
---|
345 | ******************/ |
---|
346 | if(!function_exists("cl_aff_infos_plus")){ |
---|
347 | function cl_aff_infos_plus() |
---|
348 | { |
---|
349 | global $template,$infos_message,$error_message,$warnings_message, $user ; |
---|
350 | global $conf,$lang,$page ; |
---|
351 | //============================================================== |
---|
352 | if (isset($error_message)) { |
---|
353 | if ($error_message <> ""){ |
---|
354 | $error_message=str_replace("\n",'<br />',$error_message) ; |
---|
355 | $template->assign('errors',$error_message); |
---|
356 | $error_message=""; |
---|
357 | } |
---|
358 | } |
---|
359 | //============================================================== |
---|
360 | if (isset($warnings_message)) { |
---|
361 | if ($warnings_message <> ""){ |
---|
362 | $warnings_message=str_replace("\n",'<br />',$warnings_message) ; |
---|
363 | $template->assign('warnings',$warnings_message); |
---|
364 | $warnings_message=""; |
---|
365 | } |
---|
366 | } |
---|
367 | //============================================= |
---|
368 | if (isset($infos_message)){ |
---|
369 | if ($infos_message <> ""){ |
---|
370 | $infos_message=str_replace("\n",'<br />',$infos_message) ; |
---|
371 | $template->assign('infos',$infos_message); |
---|
372 | $infos_message=""; |
---|
373 | } |
---|
374 | } |
---|
375 | //============================================================= |
---|
376 | return; |
---|
377 | |
---|
378 | } // function cl_autosize_aff_infos_plus |
---|
379 | //=============================================================== |
---|
380 | } |
---|
381 | ?> |
---|