source: extensions/rv_gmaps/trunk/kml.php @ 17513

Last change on this file since 17513 was 17513, checked in by rvelices, 12 years ago

rv_gmaps use derivative func calls

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
RevLine 
[3447]1<?php
2define('PHPWG_ROOT_PATH','../../');
3
4include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
5
6if (!isset($rvm_dir))
7  access_denied( 'Plugin not installed' );
8
9include_once( dirname(__FILE__) .'/include/functions_map.php');
10include_once( dirname(__FILE__) .'/include/functions.php');
11
12rvm_load_language();
13set_make_full_url();
14
15$section = '';
16if ( $conf['question_mark_in_urls']==false and
17     isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) )
18{
19  $section = $_SERVER["PATH_INFO"];
20  $section = str_replace('//', '/', $section);
21}
22else
23{
24  foreach ($_GET as $key=>$value)
25  {
26    if (!strlen($value)) $section=$key;
27    break;
28  }
29}
30// deleting first "/" if displayed
31$tokens = explode(
32  '/',
33  preg_replace('#^/#', '', $section)
34  );
35$next_token = 0;
36$result = rvm_parse_kml_url($tokens, $next_token);
37$page = array_merge( $page, $result );
38
39$order_by=null;
40if ( isset($page['ll']) )
41  $where_sql = rvm_ll_to_sql($page['ll'], $order_by);
42else
43  $where_sql = rvm_bounds_to_sql( $page['box'] );
44
45
[13092]46$img_fields = ' i.id,i.representative_ext,i.name,i.comment,i.file,i.path,i.lat,i.lon,i.date_creation';
[3447]47
48rvm_build_section_items($img_fields, $where_sql, RVM_BUILD_ARRAY, $order_by);
49
50
51$dataTpl = new Template( PHPWG_ROOT_PATH );
52$dataTpl->set_filename('main', dirname(__FILE__).'/template/earth_kml.tpl' );
53
54$dataTpl->assign(
55  array(
56    'PAGE_TITLE' => strip_tags(@$page['title']),
57    'CONTENT_ENCODING' => get_pwg_charset(),
58    'PAGE_COMMENT' => strip_tags( @$page['comment'], '<a><br><p><b><i><small><strong><font>'),
59    'U_INDEX' => duplicate_index_url( array('start'=>0) ),
60  )
61);
62
63if ( !empty($page['items']) )
[8666]64  $dataTpl->assign( 'NB_ITEMS_DESC', sprintf( l10n('%d photos'), count($page['items']) ).'<br/>' );
[3447]65
66
67// +-----------------------------------------------------------------------+
68// |              sub categories network links                             |
69// +-----------------------------------------------------------------------+
70if ( 'categories'==$page['section'] and !isset($page['flat']) )
71{
72  $query = '
73SELECT id, name, permalink, comment, uppercats, representative_picture_id
74  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
75  ON id = cat_id and user_id = '.$user['id'].'
76  WHERE id_uppercat '.
77  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).'
78  ORDER BY rank
79;';
80//  echo "<pre>" . var_export($query,true);
81  $result = pwg_query($query);
82  $categories = array();
83  $thumbnail_ids=array();
84  while ($row = mysql_fetch_assoc($result))
85  {
86    array_push($categories, $row);
87    if (isset($row['representative_picture_id']) and is_numeric($row['representative_picture_id']))
88      array_push($thumbnail_ids, $row['representative_picture_id'] );
89  }
90  $thumbnail_src_of = array();
91  if ( count($thumbnail_ids) )
92  {
93    $query = '
[13092]94SELECT id, path, representative_ext
[3447]95  FROM '.IMAGES_TABLE.'
96  WHERE id IN ('.implode(',', $thumbnail_ids).')';
97    $result = pwg_query($query);
98    while ($row = mysql_fetch_assoc($result))
[13092]99      $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
[3447]100    unset($thumbnail_ids);
101  }
102
103  $cat_bounds = rvm_get_cat_bounds();
104
105  foreach ($categories as $category)
106  {
107    if ( !isset( $cat_bounds[ $category['id'] ] ) )
108      continue; // without geo tagged images
109
110    $bounds = $cat_bounds[ $category['id'] ];
111
112    if ( isset($bounds['self']) )
113    {
[8666]114      $count_desc = l10n_dec('%d photo', '%d photos', $bounds['self']['count']);
[3447]115      if ( $bounds['self']['count'] == $bounds['count'] )
116        $count_desc .= ' '.l10n('images_available_cpl');
117      else
[8666]118        $count_desc .= '/'.l10n_dec('%d photo', '%d photos', $bounds['count']).' '.l10n_dec('images_available_cat','images_available_cats', $bounds['nb_cats'] );
[3447]119    }
120    else
[8666]121      $count_desc = l10n_dec('%d photo', '%d photos', $bounds['count'])
[3447]122        .' '.l10n_dec('images_available_cat','images_available_cats', $bounds['nb_cats'] );
123
124                $tpl_var = array(
125                                'NAME'    => $category['name'],
126                                'COMMENT' => trigger_event('render_category_literal_description', trigger_event('render_category_description', @$category['comment']) ),
127                                'U_CATEGORY' => make_index_url( array('category'=>$category) ),
128                                'U_KML'   => rvm_make_kml_index_url( array('section'=>'categories', 'category'=>$category) ),
129                                'U_MAP'   => rvm_make_map_index_url( array('section'=>'categories', 'category'=>$category) ),
130                                'COUNT_DESC' => $count_desc,
131                                'region'  => $bounds,
132      );
133    if ( isset( $thumbnail_src_of[$category['representative_picture_id']] ) )
134      $tpl_var['TN_SRC'] = $thumbnail_src_of[$category['representative_picture_id']];
135
136    $dataTpl->append( 'categories', $tpl_var );
137  }
138}
139
140
141
142// +-----------------------------------------------------------------------+
143// | generate content for items                                            |
144// +-----------------------------------------------------------------------+
145$bounds = array();
146foreach( $page['items'] as $img )
147{
148        $bounds = bounds_add($bounds, $img['lat'], $img['lon']);
149        $page_url = duplicate_picture_url(array('image_id' => $img['id'],'image_file' => $img['file']),  array('start') );
150
151  $tpl_var = array(
152      'U_PAGE'=> $page_url,
[17513]153      'TN_SRC'  => DerivativeImage::url(IMG_THUMB, $img),
[13092]154      'TITLE'  => render_element_name($img),
155      'DESCRIPTION'  => render_element_description($img),
[3447]156      'LAT'   => $img['lat'],
157      'LON'   => $img['lon'],
158      'DATE_CREATION' => $img['date_creation'],
159    );
160        $dataTpl->append('images', $tpl_var);
161}
162
163if ( !empty($bounds) )
164  $dataTpl->assign( 'region', $bounds );
165
166/*header('Cache-Control: public' );
167header('Expires: '.gmdate('D, d M Y H:i:s', time()+600).' GMT');
168header('Pragma:');*/
169header('Content-Disposition: inline; filename="'.str2url($page['title']).'.kml";' );
170header('Content-Type: application/vnd.google-earth.kml+xml; charset='.get_pwg_charset());
171if (isset($_GET['debug']))
172  header('Content-Type: text/xml; charset='.get_pwg_charset());
173
174
175$dataTpl->pparse('main');
176
[6639]177?>
Note: See TracBrowser for help on using the repository browser.