source: extensions/edit_gmaps/admin/admin_edit.php @ 10060

Last change on this file since 10060 was 10060, checked in by cljosse, 13 years ago

[extensions] edit_gmaps compatibility with piwigo 2.2

File size: 18.7 KB
Line 
1<?php 
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3global $lang;
4load_language('lang', dirname(__FILE__).'/../');
5$admin_url = PHPWG_ROOT_PATH.'admin.php';
6
7if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
8 
9/***********************************************************************************/
10if (!defined('TOOL_KIT_PATH')) define(  'TOOL_KIT_PATH',   EDIT_CL_PATH."admin/");
11if (!defined('INCLUDE_PATH')) define(  'INCLUDE_PATH',   TOOL_KIT_PATH.'include/' );                     
12$Toolkit_Dir =INCLUDE_PATH           ;   
13 
14include $Toolkit_Dir . 'fonctions.php';
15/***********************************************************************************/
16$info_message="" ;
17$error_message="";
18 
19/************* Mise à jour des meta données ***************/
20if ( isset($_POST['update']) && $_POST['update']==l10n('update_exif')){
21  $exif = @read_exif_data( $exif );     
22  $exif = @array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) );
23
24  // error_reporting ( 0 );
25  // Hide any unknown EXIF tags       
26  $GLOBALS['HIDE_UNKNOWN_TAGS'] = FALSE;
27  include $Toolkit_Dir.'Toolkit_Version.php';   // Change: added as of version 1.11
28    // Include the required files for reading and writing Photoshop File Info
29  include  $Toolkit_Dir.'JPEG.php';
30  include  $Toolkit_Dir.'XMP.php';
31  include  $Toolkit_Dir.'Photoshop_IRB.php';
32  include  $Toolkit_Dir.'EXIF.php';
33  include  $Toolkit_Dir.'GPS_File_Info.php';
34  $GLOBALS['HTTP_POST_VARS']=$_POST ;
35  // Copy all of the HTML Posted variables into an array
36  $new_ps_file_info_array = $GLOBALS['HTTP_POST_VARS'];
37  // Some characters are escaped with backslashes in HTML Posted variable
38  // Cycle through each of the HTML Posted variables, and strip out the slashes '
39  foreach( $new_ps_file_info_array as $var_key => $var_val ){ 
40    if ($var_key !="selection")
41        $new_ps_file_info_array[ $var_key ] = stripslashes( $var_val );                           
42  }         
43  $new_ps_file_info_array['selection'] = explode(";",$new_ps_file_info_array['filename']);
44  foreach( $new_ps_file_info_array['selection']  as $filename )   {
45    //======================================================
46    //= $new_ps_file_info_array[ 'filename' ];
47    if($filename!="") {   // Protect against hackers editing other files                               
48      // copy( $filename,  $filename.".bak" ); 
49      $path_parts = pathinfo( $filename );   
50      if(1) {
51        if ( strcasecmp( $path_parts["extension"], "jpg" ) != 0 ) {
52          $error_message .= $filename ;                                 
53          $error_message .="Incorrect File Type - JPEG Only\n";
54          $filename="";
55          //  exit( );
56         }
57        // Change: removed limitation on file being in current directory - as of version 1.11
58        // Retrieve the header information
59        $jpeg_header_data = get_jpeg_header_data( $filename );
60        // Retreive the EXIF, XMP and Photoshop IRB information from
61        // the existing file, so that it can be updated
62        $Exif_array = get_EXIF_JPEG( $filename );
63        $XMP_array = read_XMP_array_from_text( get_XMP_text( $jpeg_header_data ) );
64        $IRB_array = get_Photoshop_IRB( $jpeg_header_data );
65
66        // Update the JPEG header information with the new Photoshop File Info
67        $jpeg_header_data = put_GPS_file_info( $jpeg_header_data, $new_ps_file_info_array, $Exif_array, $XMP_array, $IRB_array );
68        // Check if the Update worked
69        if ( $jpeg_header_data == FALSE ) {
70            // Update of file info didn''t work - output error message
71            $error_message .= "jpeg_header_data
72            Error - Failure update Photoshop File Info : $filename <br>\n";
73            // Output HTML with the form and data which was
74            // sent, to allow the user to fix it
75          }else if ( FALSE == put_jpeg_header_data(  $filename, $filename, $jpeg_header_data ) ) {
76            // Attempt to write the new JPEG file
77            // Writing of the new file didn''t work - output error message
78            $error_message .= "Error - Failure to write new JPEG : $filename <br>\n";
79            // Output HTML with the form and data which was
80            // sent, to allow the user to fix it
81          }else{
82            $info_message .= l10n('update') . " Exif: " . $filename . " " .  l10n('OK') ."<br />" ;
83          }   
84          $_POST['submit']= l10n('update_database') ;
85        }
86      }
87    }
88    $_POST['update'] ="ok";
89  } 
90/****************************************************************/
91if ( !isset($_GET['cat']) )   $_GET['cat'] = 'caddie';
92$_GET['mode'] = 'map';
93if (PHPWG_VERSION < 2.2 ) {
94 include (PHPWG_ROOT_PATH.'admin/element_set.php');                             
95 } else {
96if (!isset($page['title'])) $page['title']="";
97    include (PHPWG_ROOT_PATH.'admin/batch_manager.php');                 
98    $template->concat('TABSHEET_TITLE', ' '.l10n_dec('%d image', '%d images', count($page['cat_elements_id'])).' - '.$page['title']);
99   }   
100
101if ( isset($_POST['submit'])  ) { 
102        $collection = array();
103                if( !isset ($_POST['target'])) {
104                    $_POST['submit'] = l10n('Submit') ;
105                    $_POST['target']='selection';
106                    $collection = $_POST['selection'];
107               }
108
109  switch ($_POST['target'])
110  {
111    case 'all' :
112      $collection = $page['cat_elements_id'];
113      break;
114    case 'selection' :
115      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
116        array_push($page['errors'], l10n('Select at least one photo'));
117      else
118        $collection = $_POST['selection'];
119      break;
120  } 
121
122  /******** Mise à jour base de données *****/
123   if (   $_POST['submit'] == l10n('update_database') ){
124        if ( count($collection)>0 ){
125    $lat = trim($_POST['lat']);
126    $lon = trim($_POST['lon']);
127        $alt = trim($_POST['alt']);
128
129    if ( strlen($lat)>0 and strlen($lon)>0 ) {
130      if ( (double)$lat<=90 and (double)$lat>=-90
131          and (double)$lon<=180 and (double)$lat>=-180 )
132        $update_query = 'lat='.$lat.', lon='.$lon;
133      else
134        $page['errors'][] = 'Invalid lat or lon value';
135    }
136    elseif ( strlen($lat)==0 and strlen($lon)==0 )
137      $update_query = 'lat=NULL, lon=NULL';
138    else
139      $page['errors'][] = 'Both lat/lon must be empty or not empty';
140
141              if ( strlen($alt)==0) 
142                     $update_query .= ', alt=NULL';
143                  else
144                     $update_query .= ', alt=' .$alt ;
145
146        if (isset($update_query)){
147      $update_query = '
148                UPDATE '.IMAGES_TABLE.' SET '.$update_query.'
149                WHERE id IN ('.implode(',',$collection).')';
150        pwg_query($update_query);
151                cl_meta_invalidate_cache();
152                $info_message .= l10n('update') . " " . IMAGES_TABLE . " : " .  l10n('OK') ;
153                $_POST['submit'] = l10n('Submit') ;
154     }
155    }
156  }
157 }
158/**************************************/
159$specials_selected = null;
160foreach( array('caddie'=>'Caddie', 'recent'=>'Recent photos') as $k => $v)
161{
162        $link = $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat='.$k;
163        $template->append(
164                'specials',
165                array(
166                        $link => l10n($v),
167                        ),
168                true
169                );
170        if ($k == $_GET['cat']) $specials_selected = $link;
171}
172$template->assign('specials_selected', $specials_selected);
173/****************************************/
174$query = '
175SELECT id,name,uppercats,global_rank
176  FROM '.CATEGORIES_TABLE.'
177;';
178$result = pwg_query($query);
179$categories = array();
180$selecteds = array();
181if (!empty($result))
182{
183  while ($row = mysql_fetch_assoc($result))
184  {
185    $url = $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat='.$row['id'];
186    if ( $row['id']==$_GET['cat'] ) $selecteds[] = $url;
187    $row['id']=$url;
188    array_push($categories, $row);
189  }
190}
191usort($categories, 'global_rank_compare');
192display_select_categories($categories, $selecteds, 'categories', false);
193
194if (!empty($_GET['display']))
195{
196  if ('all' == $_GET['display'])
197    $page['nb_images'] = count($page['cat_elements_id']);
198  else
199    $page['nb_images'] = intval($_GET['display']);
200}
201else
202  $page['nb_images'] = 20;
203
204if ( !empty($page['cat_elements_id']) )
205{
206  $nav_bar = create_navigation_bar(
207    $admin_url.get_query_string_diff(array('start')),
208    count($page['cat_elements_id']),
209    $page['start'],
210    $page['nb_images']
211    );
212  $template->assign('navbar', $nav_bar);
213}
214
215$images=array();
216if ( !empty($page['cat_elements_id']) )
217{
218  $query='
219SELECT id,tn_ext,name,path,file,lat,lon,alt FROM '.IMAGES_TABLE.'
220  WHERE id IN ('.implode(',',$page['cat_elements_id']).')
221  '.$conf['order_by'].'
222  LIMIT '.$page['start'].', '.$page['nb_images'].'
223;';
224  $result = pwg_query($query);
225  while ( $row=mysql_fetch_assoc($result) )
226    $images[] = $row;
227}
228
229foreach ($images as $image)
230{
231        $tpl_var = array_merge( $image,
232      array(
233        'U_TN' => get_thumbnail_url($image),
234        'TITLE' => get_thumbnail_title($image)
235      )
236    );
237  if ( isset($image['lat']) )
238    $tpl_var['U_MAP'] = cl_make_map_picture_url( array('image_id'=>$image['id'], 'image_file'=>$image['file']) );
239        $template->append('thumbnails', $tpl_var);
240}
241
242$template->assign(
243    array(
244      'U_DISPLAY'=> $admin_url.get_query_string_diff(array('display'))
245    ) 
246  );
247
248//==========================================================
249        if (!defined('EDIT_CL_PATH')) define(  'EDIT_CL_PATH',  EDIT_CL_PATH .'admin/' ); 
250        $path = EDIT_CL_PATH;
251    $plg_data = implode( '', file($path.'main.inc.php') );
252         if (preg_match("|Version: (.*)|", $plg_data, $val))
253          { $EDIT_CL_PATH_plugin['version'] = trim($val[1]);  } 
254            $EDIT_CL_PATH_plugin = array_map('htmlspecialchars', $EDIT_CL_PATH_plugin); 
255            $version= $EDIT_CL_PATH_plugin['version'] ;
256            $icon_path = 'themes/default/icon/help.png';
257            $path_js=  'themes/default/js/' ; 
258
259//==================================================================================
260$match=""; 
261     
262if ( isset($_POST['submit'])   )
263{       
264  if ($_POST['submit']==l10n('Submit') )
265   {
266      $_POST['selection']=array(); 
267      $collection =array(); 
268          unset($collection); 
269  }
270 
271
272 if ($_POST['submit']==l10n('reset' ) )
273                {
274                        $_POST['selection']=array();
275                        unset($collection);
276                }
277 
278 }
279//=================================================================================
280$src="";
281
282$template->assign(
283    array(      'EDIT_CL_PATH' => EDIT_CL_PATH,
284                'path_js' => $path_js,
285            'VERSION'=> $version,
286            'EDIT_CL_PATH_ABS' => dirname(__FILE__).'/',
287              ) 
288  );
289  global $lang_info;
290    if (date_default_timezone_get()) { 
291            $adresse =  date_default_timezone_get()   ;
292        }else{
293
294        }
295    $adresse =  $lang_info['country'];   ;
296    $adresse=str_replace("/",", ",$adresse);
297    $template->assign( 'coordinates',
298                                        array(  'FILE' => '',
299                                'LAT' => '100',
300                                                                'LON' => '100',
301                                                                'ADRESSE' => $adresse,
302                                                                'ZOOM' => 18,
303                                'ALT' => 0
304                                                        )
305                                                );   
306
307if (isset($_POST['submit']) and $_POST['submit']==l10n('selection' ))
308{
309  if (isset($collection)) { 
310    $lat =1000;$first_image="";                           
311    foreach ($collection as $id_0)  {
312                foreach ($images as $image) {
313                        if (array_search($id_0,$image)) { 
314            $_POST['selection'] = $collection ;   
315            $infos_gps=  Get_exif_gps( $image['path'],$image) ;   
316            $image['lat']=$infos_gps['lat'];
317            $image['lon']=$infos_gps['lon'];
318            $image['alt']=$infos_gps['alt']; 
319            if ($lat==1000) {
320                                $lat= ($image['lat'] <> '') ? $image['lat'] : '100'  ;
321                                      $lon= ($image['lon']  <> '') ? $image['lon'] : '3.0'  ;
322              $alt= ($image['alt']  <> '') ? $image['alt'] : '0'  ;
323                                      if($lat != '100') $lat=$image['lat'];
324                                      //=====================================================
325                                      $template->assign( 'coordinates',
326                                             array('FILE' => $image['path'],
327                     'LAT' =>   $lat  ,
328                                                                                 'LON' =>   $lon  ,
329                                                                                 'ADRESSE' =>  $adresse ,
330                                                                                 'ZOOM' => 4,
331                     'ALT' =>   $alt ,
332                                                                                )
333                                                                        );
334                                }
335                                               
336                    $lon=$image['lon'];
337                    $lat=$image['lat'];   
338                    if($infos_gps['is_exif'])   $info_message .='EXIF';   
339
340                $lonDMS= dec2dms($lon) ;
341                $latDMS= dec2dms($lat) ;
342
343
344                            $tpl_var = array_merge( 
345                                    $image,
346                                        array(
347                  'filename' =>  $image['path'],
348                  'exif' => $infos_gps['is_exif'] ,
349                  'lat'  =>    $image['lat']    ,
350                  'lon' =>     $image['lon']    ,
351                  'alt' =>     $image['alt']    , 
352                  'latDMS' =>    $latDMS[3]     ,
353                  'lonDMS' =>   "-->".$lonDMS[3]     ,
354                  'adresse' =>  $adresse   ,
355                  'U_TN' => get_thumbnail_url($image),
356                  'TITLE' => get_thumbnail_title($image),
357                                                            'U_MAP' => cl_make_map_picture_url(
358                                                                                            array(
359                                                                                                 'image_id'=>$image['id'],
360                                                                                                 'image_file'=>$image['file'],
361                                                                                                 ) 
362                                                                                    ),
363                                                                  )                                                             
364                                                );       
365                                $template->append('Selectthumbnails', $tpl_var);                       
366                        }
367                }       
368        }
369  }
370
371} 
372
373
374 if ( !empty($first_image))
375 { $error_message .= cl_edit_controler::Memo_Vars($first_image);
376 if (isset($_POST['update'])) {
377// document.Envoie.latDMS.value
378        $image= first_image ;
379        $filename=$image['path'] ;
380        $Val_exif="";
381        $Val_XMP="";           
382   /*  */   
383     if (!empty($infos_gps)) 
384     $Position = $infos_gps ;
385     else  $Position =  Get_exif_gps($filename,$image) ;
386
387  $jpeg_header_data = get_jpeg_header_data($filename ); 
388     $template->assign( array(
389      'filename_abs' =>   $filename , 
390      'filename' => $filename, 
391     'datas'    =>    array(
392/*       'Val_JPEG_APP'=> Generate_JPEG_APP_Segment_HTML( $jpeg_header_data ),
393        'Val_intrinsic'=> Interpret_intrinsic_values_to_HTML( get_jpeg_intrinsic_values( $jpeg_header_data ) ),
394        'Val_Comment'=> Interpret_Comment_to_HTML( $jpeg_header_data ),
395        'Val_JFIF'=> Interpret_JFIF_to_HTML( get_JFIF( $jpeg_header_data ), $filename ),
396        'Val_JFXX'=>Interpret_JFXX_to_HTML( get_JFXX( $jpeg_header_data ), $filename ),
397        'Val_App12' => Interpret_App12_Pic_Info_to_HTML( $jpeg_header_data ),         
398        'Val_IRB' => Interpret_IRB_to_HTML( get_Photoshop_IRB( $jpeg_header_data ), $filename ),
399
400        'Val_exif'=>  Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename),
401        'Val_XMP' =>  Interpret_XMP_to_HTML( read_XMP_array_from_text( get_XMP_text( $jpeg_header_data) ) ),
402          */
403     //
404         ),
405 'Datadase' =>  ($Position) ,
406          ) );
407       
408
409          }
410}
411
412
413  //=======================================================================
414function cl_make_map_picture_url($params)
415{
416        global $conf;
417        /*if ( empty($conf['gmaps_api_key']) and $_SERVER['SERVER_ADDR']!='127.0.0.1' )
418                return "";*/
419        $map_url = make_picture_url($params);
420        return add_url_params($map_url, array('map'=>null) );
421}
422$v1=0;
423
424
425
426function Get_exif_gps($firt_image,$image)
427{
428
429 error_reporting ( 1 );
430 $filename=$firt_image;
431 
432  $datas = array();
433  $errors = array();
434 
435
436  $exif = @read_exif_data( $filename ); 
437global $errors;global $template ;
438
439      if ( empty($exif) ) return;
440         $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) );
441
442//====================================================================
443    $lat = $image['lat'] ;         
444    $lon = $image['lon'] ; 
445    $alt = $image['alt'];
446    global $info_message ;
447
448$is_exif = "'".(is_array($exif['GPSLatitude']) and is_array($exif['GPSLongitude']) )."'" ;
449 if ($is_exif) {
450     $lat_exif = parse_lat_lon( $exif['GPSLatitude'] );         
451     $lon_exif = parse_lat_lon( $exif['GPSLongitude'] );
452     $alt_exif = Parse_Fract( $exif['GPSAltitude'] ); 
453 }
454
455if ($lat =="") 
456{   
457  $lat = Parse_Lat_Lon( $exif['GPSLatitude'] ); 
458  if ( $exif['GPSLatitudeRef']=='S' ) $lat = -$lat;
459 
460}else{
461    $is_exif="false" ;
462    if($lat<0)      $exif['GPSLatitudeRef']='S' ;
463        else        $exif['GPSLatitudeRef']='N' ;
464       
465     
466}   
467if ($lon =="") {
468       
469                $lon = parse_lat_lon( $exif['GPSLongitude'] );
470                if ( $exif['GPSLongitudeRef']=='W' ) $lon = -$lon;
471           }else{
472             if ($lon<0) $exif['GPSLongitudeRef'] ='W' ;
473             else $exif['GPSLongitudeRef'] ='E' ;
474                 
475           }
476
477   
478 
479//=======================================================================         
480           $altref = 0;
481
482if (!is_array($exif['GPSAltitude']) or !is_array($exif['GPSAltitudeRef']) )
483                {
484                         $exif['GPSAltitude']=$alt;
485             $exif['GPSAltitudeRef']=0;
486                }       else {
487                $alt =           $exif['GPSAltitude'];
488            $altref = $exif['GPSAltitudeRef'];
489        }
490 //========================================================================     
491                $datas[] = array (
492            'is_exif' => $is_exif, 
493            ' filename=' => $filename ,
494                        'id' =>    $image['id'] ,
495                        'lat' =>   $lat ,
496                        'lon' =>   $lon ,
497                        'latDMS' =>     $exif['GPSLatitude'][0]['Numerator']  . "/" .
498                            $exif['GPSLatitude'][0]['Denominator'] . " " .   
499                            $exif['GPSLatitude'][1]['Numerator'] . "/" .
500                            $exif['GPSLatitude'][1]['Denominator']. " " .   
501                            $exif['GPSLatitude'][2]['Numerator'] . "/" .
502                            $exif['GPSLatitude'][2]['Denominator'],
503                        'lonDMS' =>     $exif['GPSLongitude'][0]['Numerator']  . "/" .
504                            $exif['GPSLongitude'][0]['Denominator'] . " " .   
505                            $exif['GPSLongitude'][1]['Numerator'] . "/" .
506                            $exif['GPSLongitude'][1]['Denominator']. " " .   
507                            $exif['GPSLongitude'][2]['Numerator'] . "/" .
508                            $exif['GPSLongitude'][2]['Denominator'],
509            'altref' => $exif['GPSAltitudeRef'],
510            'alt' =>   $exif['GPSAltitude'] ,
511
512                        ); 
513
514return $datas[0] ;
515}
516if ($info_message!="")
517$template->assign('infos',$info_message);
518if ($error_message!="")
519$template->assign('errors',$error_message);
520?>
Note: See TracBrowser for help on using the repository browser.