[9412] | 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 | |
---|
[9445] | 36 | class cl_edit_functions { |
---|
[20034] | 37 | |
---|
| 38 | /************************************** |
---|
[9445] | 39 | * list all columns of each given table |
---|
[20034] | 40 | *************************************** |
---|
[9445] | 41 | * @return array of array |
---|
| 42 | */ |
---|
| 43 | static public function Get_columns_of($table){ |
---|
| 44 | $columns_of = array(); |
---|
| 45 | $query = 'DESC '.$table.';'; |
---|
[25359] | 46 | |
---|
[9445] | 47 | $columns_of[$table] = array(); |
---|
[25359] | 48 | $result=pwg_query($query); |
---|
[9445] | 49 | if ($result) |
---|
[25359] | 50 | while ($row = pwg_db_fetch_row($result)){ |
---|
[9445] | 51 | array_push($columns_of[$table], $row[0]); |
---|
[25359] | 52 | } |
---|
[9445] | 53 | return $columns_of; |
---|
| 54 | } |
---|
| 55 | } |
---|
[9412] | 56 | |
---|
| 57 | class cl_edit_controler { |
---|
| 58 | |
---|
[12126] | 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 | //====================================================== |
---|
[17779] | 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 | } |
---|
[12126] | 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 | //========================================================== |
---|
[17779] | 128 | static public function Get_exif_gps($firt_image,$image,$hight_gps,$lecture_exif) { |
---|
[12126] | 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 | //==================================================================== |
---|
[17779] | 147 | if(!$lecture_exif){ |
---|
[12126] | 148 | $lat = $image['lat'] ; |
---|
| 149 | $lon = $image['lon'] ; |
---|
| 150 | $alt = $image['alt']; |
---|
[17779] | 151 | } |
---|
[12126] | 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 | } |
---|
[17776] | 220 | |
---|
| 221 | /************************************************ |
---|
| 222 | * add_data_base |
---|
| 223 | ************************************************/ |
---|
[12126] | 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(); |
---|
[17779] | 249 | $info_message .= l10n('update') . "[DB] " . implode(',',$sel) . " ". IMAGES_TABLE . " : " . l10n('OK') ."<br />"; |
---|
[12126] | 250 | } |
---|
| 251 | } |
---|
| 252 | //====================================================== |
---|
[20034] | 253 | static public function cl_edit_admin_menu($menu) |
---|
[9412] | 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 | } |
---|
[20034] | 264 | /**************************** |
---|
[9412] | 265 | * |
---|
[20034] | 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 | |
---|
[9412] | 282 | return $EDIT_CL_parametres; |
---|
| 283 | } |
---|
| 284 | /* |
---|
| 285 | * |
---|
| 286 | */ |
---|
[20034] | 287 | static public function cl_edit_Set_Options(){ |
---|
[9412] | 288 | global $EDIT_CL_parametres; |
---|
| 289 | //============================================================================= |
---|
[25359] | 290 | |
---|
[20034] | 291 | $my_para=$EDIT_CL_parametres; |
---|
[25359] | 292 | if (empty($my_para)) $my_para= (object) ''; |
---|
[20034] | 293 | $lon= isset($my_para->lon)? $my_para->lon:'' ; |
---|
| 294 | $lat= isset($my_para->lat)? $my_para->lat:'' ; |
---|
| 295 | $alt= isset($my_para->alt)? $my_para->alt:'0' ; |
---|
| 296 | $my_para->lon = (isset($_POST['lon']))? $_POST['lon']: $lon ; |
---|
| 297 | $my_para->lat = (isset($_POST['lat']))? $_POST['lat']: $lat ; |
---|
| 298 | $my_para->alt = (isset($_POST['alt']))? $_POST['alt']: $alt ; |
---|
| 299 | $my_para->adress = (isset($_POST['match']))? $_POST['match']: '' ; |
---|
[9412] | 300 | //=============================================================================== |
---|
[17761] | 301 | if ( isset($_POST['selectAction'] ) && $_POST['selectAction'] == l10n('cl_edit_save') ) { |
---|
[20034] | 302 | $my_para->check_exif = isset($_POST['check_exif']) ? $_POST['check_exif'] : "off" ; |
---|
[9412] | 303 | |
---|
| 304 | }else{ |
---|
[20034] | 305 | $my_para->check_exif = isset($_POST['check_exif']) ? $_POST['check_exif'] : ( ( isset($my_para->check_exif) ) ? $my_para->check_exif : 'off') ; |
---|
[9412] | 306 | } |
---|
[20034] | 307 | $EDIT_CL_parametres=$my_para; |
---|
| 308 | return $my_para; |
---|
[9412] | 309 | |
---|
| 310 | } |
---|
[20034] | 311 | /********************** |
---|
[9412] | 312 | * |
---|
[20034] | 313 | **********************/ |
---|
| 314 | static public function cl_edit_sauve_options_inf() { |
---|
| 315 | global $options,$infos_message,$conf,$EDIT_CL_parametres ; |
---|
| 316 | // $infos_message .=l10n("cl_edit_save_config")."<br>". cl_print_var($EDIT_CL_parametres); |
---|
| 317 | // cl_aff_infos_plus(); |
---|
| 318 | if ( isset($EDIT_CL_parametres) ){ |
---|
[9412] | 319 | $query = ' |
---|
| 320 | UPDATE '.CONFIG_TABLE.' |
---|
| 321 | SET value="'.addslashes(serialize($EDIT_CL_parametres)).'" |
---|
[20034] | 322 | WHERE param = "edit_gmaps" |
---|
[9412] | 323 | LIMIT 1'; |
---|
| 324 | pwg_query($query); |
---|
[20034] | 325 | } |
---|
[9412] | 326 | } |
---|
| 327 | |
---|
| 328 | |
---|
[9445] | 329 | } // class |
---|
[9412] | 330 | |
---|
[20034] | 331 | /************************* |
---|
| 332 | * |
---|
| 333 | *************************/ |
---|
| 334 | if(!function_exists("cl_print_var")){ |
---|
| 335 | function cl_print_var($variables){ |
---|
| 336 | ob_start(); |
---|
| 337 | echo '<pre>'; |
---|
| 338 | print_r($variables); |
---|
| 339 | echo '</pre>'; |
---|
| 340 | $m= ob_get_contents(); |
---|
| 341 | ob_end_clean(); |
---|
| 342 | return $m; |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | /****************** |
---|
| 346 | * |
---|
| 347 | ******************/ |
---|
| 348 | if(!function_exists("cl_aff_infos_plus")){ |
---|
| 349 | function cl_aff_infos_plus() |
---|
| 350 | { |
---|
| 351 | global $template,$infos_message,$error_message,$warnings_message, $user ; |
---|
[25488] | 352 | global $conf,$page ; |
---|
[20034] | 353 | //============================================================== |
---|
| 354 | if (isset($error_message)) { |
---|
| 355 | if ($error_message <> ""){ |
---|
| 356 | $error_message=str_replace("\n",'<br />',$error_message) ; |
---|
| 357 | $template->assign('errors',$error_message); |
---|
| 358 | $error_message=""; |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | //============================================================== |
---|
| 362 | if (isset($warnings_message)) { |
---|
| 363 | if ($warnings_message <> ""){ |
---|
| 364 | $warnings_message=str_replace("\n",'<br />',$warnings_message) ; |
---|
| 365 | $template->assign('warnings',$warnings_message); |
---|
| 366 | $warnings_message=""; |
---|
| 367 | } |
---|
| 368 | } |
---|
| 369 | //============================================= |
---|
| 370 | if (isset($infos_message)){ |
---|
| 371 | if ($infos_message <> ""){ |
---|
| 372 | $infos_message=str_replace("\n",'<br />',$infos_message) ; |
---|
| 373 | $template->assign('infos',$infos_message); |
---|
| 374 | $infos_message=""; |
---|
| 375 | } |
---|
| 376 | } |
---|
| 377 | //============================================================= |
---|
| 378 | return; |
---|
| 379 | |
---|
| 380 | } // function cl_autosize_aff_infos_plus |
---|
| 381 | //=============================================================== |
---|
| 382 | } |
---|
[9412] | 383 | ?> |
---|