Changeset 17780 for extensions/rv_gmaps


Ignore:
Timestamp:
Sep 6, 2012, 10:24:41 PM (12 years ago)
Author:
rvelices
Message:

rv_gmaps fixes when compile_template_cache_language=true (prefilter fails and lat/lon data destroyed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_gmaps/trunk/admin/admin_boot.php

    r17705 r17780  
    5353        $template->append('element_set_global_plugins_actions',
    5454                array('ID' => 'geotag', 'NAME'=>l10n('Geotag'), 'CONTENT' => '
    55   <label>{\'Latitude\'|@translate} (-90=S to 90=N)
     55  <label>'.l10n('Latitude').' (-90=S to 90=N)
    5656    <input type="text" size="8" name="lat">
    5757  </label>
    58   <label>{\'Longitude\'|@translate} (-180=E to 180=W)
     58  <label>'.l10n('Longitude').' (-180=E to 180=W)
    5959    <input type="text" size="9" name="lon">
    6060  </label> (Empty values will erase coordinates)
     
    9797{
    9898  global $page;
    99  
    100   if (isset($_POST['submit']))
    101   {
    102     $collection = explode(',', $_POST['element_ids']);
    103    
    104     $datas = array();
    105     $errors = array();
    106    
    107     $query = '
     99
     100  if (!isset($_POST['submit']))
     101    return;
     102
     103  $collection = explode(',', $_POST['element_ids']);
     104
     105  $datas = array();
     106  $errors = array();
     107  $form_errors = 0;
     108
     109  $query = '
    108110SELECT id, name
    109111  FROM '.IMAGES_TABLE.'
    110112  WHERE id IN ('.implode(',', $collection).')
    111113;';
    112     $result = pwg_query($query);
    113    
    114     while ($row = pwg_db_fetch_assoc($result))
    115     {
    116       $data = array();
    117       $error = false;
    118       $data['id'] = $row['id'];
    119       $data['lat'] = trim($_POST['lat-'.$row['id']]);
    120       $data['lon'] = trim($_POST['lon-'.$row['id']]);
    121      
    122       if ( strlen($data['lat'])>0 and strlen($data['lon'])>0 )
    123       {
    124         if ( (double)$data['lat']>90 or (double)$data['lat']<-90
    125             or (double)$data['lon']>180 or (double)$data['lon']<-180 )
    126           $error = true;
    127       }
    128       elseif ( strlen($data['lat'])==0 and strlen($data['lon'])==0 )
    129       {
    130         // nothing
    131       }
    132       else
    133       {
     114  $result = pwg_query($query);
     115
     116  while ($row = pwg_db_fetch_assoc($result))
     117  {
     118    if (!isset($_POST['lat-'.$row['id']]))
     119    {
     120      $form_errors++;
     121      continue;
     122    }
     123    $error = false;
     124    $data = array(
     125      'id' => $row['id'],
     126      'lat' => trim($_POST['lat-'.$row['id']]),
     127      'lon' => trim($_POST['lon-'.$row['id']])
     128    );
     129
     130    if ( strlen($data['lat'])>0 and strlen($data['lon'])>0 )
     131    {
     132      if ( (double)$data['lat']>90 or (double)$data['lat']<-90
     133          or (double)$data['lon']>180 or (double)$data['lon']<-180 )
    134134        $error = true;
    135       }
    136      
    137       if ($error)
    138         array_push($errors, $row['name']);
    139       else
    140         array_push($datas, $data);
    141     }
    142    
    143     mass_updates(
    144       IMAGES_TABLE,
    145       array(
    146         'primary' => array('id'),
    147         'update' => array('lat', 'lon')
    148         ),
    149       $datas
    150       );
    151    
    152     if (count($errors)>0)
    153     {
    154       array_push($page['errors'], 'Invalid lat or lon value for files: '.implode(', ', $errors));
    155     }
    156   }
     135    }
     136    elseif ( strlen($data['lat'])==0 and strlen($data['lon'])==0 )
     137    {
     138      // nothing
     139    }
     140    else
     141    {
     142      $error = true;
     143    }
     144
     145    if ($error)
     146      $errors[] = $row['name'];
     147    else
     148      $datas[] = $data;
     149  }
     150
     151  mass_updates(
     152    IMAGES_TABLE,
     153    array(
     154      'primary' => array('id'),
     155      'update' => array('lat', 'lon')
     156      ),
     157    $datas
     158    );
     159
     160  if (count($errors)>0)
     161  {
     162    $page['errors'][] = 'Invalid lat or lon value for files: '.implode(', ', $errors);
     163  }
     164  if ($form_errors)
     165    $page['errors'][] = 'Maps & Earth: Invalid form submission for '.$form_errors.' photos';
    157166}
    158167
     
    161170{
    162171  global $template, $conf, $page, $is_category, $category_info;
    163  
     172
     173  $template->set_prefilter('batch_manager_unit', 'rvm_prefilter_batch_manager_unit');
     174
    164175  $query = '
    165176SELECT id,lat,lon
    166177  FROM '.IMAGES_TABLE;
    167  
     178
    168179  if ($is_category)
    169180  {
    170181    $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']);
    171    
     182
    172183    $conf['order_by'] = $conf['order_by_inside_category'];
    173184    if (!empty($category_info['image_order']))
     
    201212    $row['lat'] = preg_replace('#\.([0-9]*?)([0]+)$#', '.$1', $row['lat']);
    202213    $row['lon'] = preg_replace('#\.([0-9]*?)([0]+)$#', '.$1', $row['lon']);
    203    
     214
    204215    $tpl_vars[ $row['id'] ] = array(
    205216      'LAT' => rtrim($row['lat'], '.'),
     
    207218      );
    208219  }
    209  
     220
    210221  $template->assign('GEOTAG', $tpl_vars);
    211  
    212   $template->set_prefilter('batch_manager_unit', 'rvm_prefilter_batch_manager_unit');
    213 }
    214 
    215 function rvm_prefilter_batch_manager_unit($content, &$smarty)
    216 {
    217   $search = '<td><strong>{\'Who can see this photo?\'|@translate}</strong></td>';
    218   $add = '<td><strong>{\'Geotag\'|@translate}</strong></td>
     222}
     223
     224function rvm_prefilter_batch_manager_unit($content)
     225{
     226  $needle = '</table>';
     227  $pos = strpos($content, $needle);
     228  if ($pos!==false)
     229  {
     230    $add = '<tr><td><strong>{\'Geotag\'|@translate}</strong></td>
    219231      <td>
    220232        <label>{\'Latitude\'|@translate}
     
    225237        </label>
    226238      </td>
    227     </tr>
    228 
    229     <tr>
    230       ';
    231   return str_replace($search, $add.$search, $content);
     239    </tr>';
     240    $content = substr_replace($content, $add, $pos, 0);
     241  }
     242  return $content;
    232243}
    233244?>
Note: See TracChangeset for help on using the changeset viewer.