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 | static public function Memo_vars($variables) { |
---|
38 | ob_start(); |
---|
39 | echo '<pre>'; |
---|
40 | print_r($variables); |
---|
41 | echo '</pre>'; |
---|
42 | $m= ob_get_contents(); |
---|
43 | ob_end_clean(); |
---|
44 | return $m; |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * list all columns of each given table |
---|
49 | * |
---|
50 | * @return array of array |
---|
51 | */ |
---|
52 | static public function Get_columns_of($table){ |
---|
53 | $columns_of = array(); |
---|
54 | $query = 'DESC '.$table.';'; |
---|
55 | $result = mysql_query($query); |
---|
56 | $columns_of[$table] = array(); |
---|
57 | |
---|
58 | if ($result) |
---|
59 | while ($row = mysql_fetch_row($result)) |
---|
60 | array_push($columns_of[$table], $row[0]); |
---|
61 | |
---|
62 | return $columns_of; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | class cl_edit_controler { |
---|
67 | |
---|
68 | static public function add_meta_gps($new_ps_file_info_array,$image){ |
---|
69 | global $nom_fichier,$erreur_message, $info_message; |
---|
70 | |
---|
71 | |
---|
72 | // $exif = @read_exif_data( $exif ); |
---|
73 | // $exif = @array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) ); |
---|
74 | |
---|
75 | foreach( $new_ps_file_info_array['selection'] as $filename ) { |
---|
76 | //====================================================== |
---|
77 | if($new_ps_file_info_array['lat']=='') { |
---|
78 | |
---|
79 | $new_ps_file_info_array['lat']=$image['lat']; |
---|
80 | $new_ps_file_info_array['lon']=$image['lon']; |
---|
81 | $new_ps_file_info_array['alt']=$image['alt']; |
---|
82 | } |
---|
83 | if($new_ps_file_info_array['lat']=='') { |
---|
84 | $erreur_message .= "Error - lon or lat = null : $filename <br>\n"; |
---|
85 | }else{ |
---|
86 | if($filename!="") { |
---|
87 | //= $new_ps_file_info_array[ 'filename' ]; |
---|
88 | // Protect against hackers editing other files |
---|
89 | // copy( $filename, $filename.".bak" ); |
---|
90 | $path_parts = pathinfo( $filename ); |
---|
91 | |
---|
92 | if ( strcasecmp( $path_parts["extension"], "jpg" ) != 0 ) { |
---|
93 | $erreur_message .= $filename ; |
---|
94 | $erreur_message .="Incorrect File Type - JPEG Only\n"; |
---|
95 | $filename=""; |
---|
96 | return; |
---|
97 | } |
---|
98 | // Change: removed limitation on file being in current directory - as of version 1.11 |
---|
99 | // Retrieve the header information |
---|
100 | |
---|
101 | $nom_fichier=$filename; |
---|
102 | $jpeg_header_data = get_jpeg_header_data( $filename ); |
---|
103 | // Retreive the EXIF, XMP and Photoshop IRB information from |
---|
104 | // the existing file, so that it can be updated |
---|
105 | $Exif_array = get_EXIF_JPEG( $filename ); |
---|
106 | $XMP_array = read_XMP_array_from_text( get_XMP_text( $jpeg_header_data ) ); |
---|
107 | $IRB_array = get_Photoshop_IRB( $jpeg_header_data ); |
---|
108 | // Update the JPEG header information with the new Photoshop File Info |
---|
109 | |
---|
110 | $jpeg_header_data = put_GPS_file_info( $jpeg_header_data, $new_ps_file_info_array, $Exif_array, $XMP_array, $IRB_array ); |
---|
111 | // Check if the Update worked |
---|
112 | if ( $jpeg_header_data == FALSE ) { |
---|
113 | // Update of file info didn''t work - output error message |
---|
114 | $erreur_message .= "jpeg_header_data |
---|
115 | Error - Failure update Photoshop File Info : $filename <br>\n"; |
---|
116 | return false; |
---|
117 | // Output HTML with the form and data which was |
---|
118 | // sent, to allow the user to fix it |
---|
119 | }else if ( FALSE == put_jpeg_header_data( $filename, $filename, $jpeg_header_data ) ) { |
---|
120 | // Attempt to write the new JPEG file |
---|
121 | // Writing of the new file didn''t work - output error message |
---|
122 | $erreur_message .= "Error - Failure to write new JPEG : $filename <br>\n"; |
---|
123 | return false; |
---|
124 | // Output HTML with the form and data which was |
---|
125 | // sent, to allow the user to fix it |
---|
126 | }else{ |
---|
127 | return true; |
---|
128 | } |
---|
129 | }// test filename} |
---|
130 | } //for each |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | } |
---|
136 | //========================================================== |
---|
137 | static public function Get_exif_gps($firt_image,$image,$hight_gps,$lecture_exif) { |
---|
138 | global $errors;global $template ; |
---|
139 | global $info_message ; |
---|
140 | error_reporting ( 1 ); |
---|
141 | $filename=$firt_image; |
---|
142 | |
---|
143 | $datas = array(); |
---|
144 | $errors = array(); |
---|
145 | $exif = @read_exif_data( $filename ); |
---|
146 | if ( empty($exif) ) return; |
---|
147 | |
---|
148 | $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) ); |
---|
149 | if(count($exif)==0 || $hight_gps ){ |
---|
150 | $path_parts = pathinfo( $filename ); |
---|
151 | $exif = @read_exif_data( $path_parts['dirname']."/pwg_high/".$path_parts['basename']); |
---|
152 | $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) ); |
---|
153 | } |
---|
154 | if(count($exif)==0) return ; |
---|
155 | //==================================================================== |
---|
156 | if(!$lecture_exif){ |
---|
157 | $lat = $image['lat'] ; |
---|
158 | $lon = $image['lon'] ; |
---|
159 | $alt = $image['alt']; |
---|
160 | } |
---|
161 | $p1=base_to_meta($image); |
---|
162 | |
---|
163 | if($exif['GPSLatitude'][0]=="1/1" && $lat!=""){ |
---|
164 | $exif['GPSLatitudeRef'] = $p1['GPSLatitudeRef'] ; |
---|
165 | $exif['GPSLatitude']=$p1['GPSLatitude']; |
---|
166 | $exif['GPSLongitudeRef'] = $p1['GPSLongitudeRef']; |
---|
167 | $exif['GPSLongitude']=$p1['GPSLongitude']; |
---|
168 | $exif['GPSAltitudeRef'] =$p1['GPSAltitudeRef']; |
---|
169 | $exif['GPSAltitude']= $p1['GPSAltitude']; |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | $is_exif = is_array($exif['GPSLatitude']) && $exif['GPSLatitude']!='' ; |
---|
174 | $is_exif = is_array($exif['GPSLongitude']) && $exif['GPSLongitude']!='' & $is_exif ; |
---|
175 | |
---|
176 | if ($is_exif) { |
---|
177 | $lat_exif = Parse_Lat_Lon( $exif['GPSLatitude'] ); |
---|
178 | $lon_exif = Parse_Lat_Lon( $exif['GPSLongitude'] ); |
---|
179 | $alt_exif = Parse_Fract( $exif['GPSAltitude'] ); |
---|
180 | } |
---|
181 | |
---|
182 | $is_exif = $lat_exif!=0; |
---|
183 | //============================== |
---|
184 | if ($lat =="" || $hight_gps){ |
---|
185 | $lat = Parse_Lat_Lon( $exif['GPSLatitude'] ); |
---|
186 | if ( $exif['GPSLatitudeRef']=='S' ) $lat = -$lat; |
---|
187 | }else{ |
---|
188 | if($lat<0) $exif['GPSLatitudeRef']='S' ; |
---|
189 | else $exif['GPSLatitudeRef']='N' ; |
---|
190 | } |
---|
191 | //============================== |
---|
192 | if ($lon =="" || $hight_gps) { |
---|
193 | $lon = Parse_Lat_Lon( $exif['GPSLongitude'] ); |
---|
194 | if ( $exif['GPSLongitudeRef']=='W' ) $lon = -$lon; |
---|
195 | }else{ |
---|
196 | if ($lon<0) $exif['GPSLongitudeRef'] ='W' ; |
---|
197 | else $exif['GPSLongitudeRef'] ='E' ; |
---|
198 | } |
---|
199 | //======================================================================= |
---|
200 | $altref = 0; |
---|
201 | if (!is_array($exif['GPSAltitude']) or !is_array($exif['GPSAltitudeRef']) ){ |
---|
202 | $exif['GPSAltitude']=$alt; |
---|
203 | $exif['GPSAltitudeRef']=0; |
---|
204 | } else { |
---|
205 | $alt = $exif['GPSAltitude']; |
---|
206 | $altref = $exif['GPSAltitudeRef']; |
---|
207 | } |
---|
208 | //======================================================================== |
---|
209 | $datas[] = array ( |
---|
210 | 'is_exif' => $is_exif , |
---|
211 | ' filename=' => $filename , |
---|
212 | 'id' => $image['id'] , |
---|
213 | 'lat' => $lat , |
---|
214 | 'lon' => $lon , |
---|
215 | 'latDMS' => $exif['GPSLatitude'][0]." ". |
---|
216 | $exif['GPSLatitude'][1]." ". |
---|
217 | $exif['GPSLatitude'][2]." ". |
---|
218 | $exif['GPSLatitudeRef'], |
---|
219 | 'lonDMS' => $exif['GPSLongitude'][0]." ". |
---|
220 | $exif['GPSLongitude'][1]." ". |
---|
221 | $exif['GPSLongitude'][2]." ". |
---|
222 | $exif['GPSLongitudeRef'], |
---|
223 | 'altref' => $exif['GPSAltitudeRef'], |
---|
224 | 'alt' => $exif['GPSAltitude'] |
---|
225 | ); |
---|
226 | |
---|
227 | return $datas[0] ; |
---|
228 | } |
---|
229 | |
---|
230 | /************************************************ |
---|
231 | * add_data_base |
---|
232 | ************************************************/ |
---|
233 | static public function add_data_base($sel,$lat,$lon,$alt){ |
---|
234 | global $page,$info_message,$erreur_message ; |
---|
235 | |
---|
236 | if ( strlen($lat)>0 and strlen($lon)>0 ) { |
---|
237 | if ( (double)$lat<=90 and (double)$lat>=-90 |
---|
238 | and (double)$lon<=180 and (double)$lat>=-180 ) |
---|
239 | $update_query = 'lat='.$lat.', lon='.$lon; |
---|
240 | else |
---|
241 | $erreur_message .= 'Invalid lat or lon value'; |
---|
242 | } |
---|
243 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
---|
244 | $update_query = 'lat=NULL, lon=NULL'; |
---|
245 | else |
---|
246 | $erreur_message .= 'Both lat/lon must be empty or not empty'; |
---|
247 | if ( strlen($alt)==0) |
---|
248 | $update_query .= ', alt=NULL'; |
---|
249 | else |
---|
250 | $update_query .= ', alt=' .$alt ; |
---|
251 | |
---|
252 | if (isset($update_query)){ |
---|
253 | $update_query = ' |
---|
254 | UPDATE '.IMAGES_TABLE.' SET '.$update_query.' |
---|
255 | WHERE id IN ('.implode(',',$sel).')'; |
---|
256 | pwg_query($update_query) ; |
---|
257 | cl_meta_invalidate_cache(); |
---|
258 | $info_message .= l10n('update') . "[DB] " . implode(',',$sel) . " ". IMAGES_TABLE . " : " . l10n('OK') ."<br />"; |
---|
259 | } |
---|
260 | } |
---|
261 | //====================================================== |
---|
262 | static public function cl_edit_admin_menu($menu) |
---|
263 | { |
---|
264 | include_once( dirname(__FILE__) .'/include/functions.php'); |
---|
265 | add_event_handler('invalidate_user_cache', 'cl_meta_invalidate_cache' ); |
---|
266 | array_push($menu, |
---|
267 | array( |
---|
268 | 'NAME' => 'EDIT Maps & Earth', |
---|
269 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/admin.php') ) |
---|
270 | ); |
---|
271 | return $menu; |
---|
272 | } |
---|
273 | /* |
---|
274 | * |
---|
275 | */ |
---|
276 | function cl_edit_Get_Options() |
---|
277 | { |
---|
278 | global $conf,$EDIT_CL_parametres; |
---|
279 | $EDIT_CL_parametres = unserialize($conf['cl_edit']); |
---|
280 | $EDIT_CL_parametres = cl_edit_Set_Options(); |
---|
281 | return $EDIT_CL_parametres; |
---|
282 | } |
---|
283 | /* |
---|
284 | * |
---|
285 | */ |
---|
286 | function cl_edit_Set_Options() |
---|
287 | { |
---|
288 | |
---|
289 | global $EDIT_CL_parametres; |
---|
290 | //============================================================================= |
---|
291 | $my_para=$EDIT_CL_parametres; |
---|
292 | $my_para->type=(isset($_POST['type']))? $_POST['type']: ((isset($my_para->type)) ? $my_para->type: 'Ty') ; |
---|
293 | |
---|
294 | //=============================================================================== |
---|
295 | |
---|
296 | if ( isset($_POST['selectAction'] ) && $_POST['selectAction'] == l10n('cl_edit_save') ) { |
---|
297 | $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : "off" ; |
---|
298 | |
---|
299 | }else{ |
---|
300 | $my_para->check_desc_v = isset($_POST['check_desc_v']) ? $_POST['check_desc_v'] : ( ( isset($my_para->check_desc_v) ) ? $my_para->check_desc_v : 'off') ; |
---|
301 | |
---|
302 | |
---|
303 | } |
---|
304 | |
---|
305 | return $my_para; |
---|
306 | } |
---|
307 | /* |
---|
308 | * |
---|
309 | */ |
---|
310 | function cl_edit_sauve_options_inf() |
---|
311 | { |
---|
312 | global $options,$infos_message,$conf,$EDIT_CL_parametres ; |
---|
313 | $infos_message .=l10n("cl_edit_save_config")."<br>"; |
---|
314 | $EDIT_CL_parametres=cl_edit_Set_Options(); |
---|
315 | |
---|
316 | if ( isset($EDIT_CL_parametres) ) |
---|
317 | { |
---|
318 | |
---|
319 | $query = ' |
---|
320 | UPDATE '.CONFIG_TABLE.' |
---|
321 | SET value="'.addslashes(serialize($EDIT_CL_parametres)).'" |
---|
322 | WHERE param = "cl_EDIT_CL" |
---|
323 | LIMIT 1'; |
---|
324 | pwg_query($query); |
---|
325 | } |
---|
326 | |
---|
327 | } |
---|
328 | |
---|
329 | |
---|
330 | |
---|
331 | } // class |
---|
332 | |
---|
333 | |
---|
334 | ?> |
---|