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