source: extensions/rv_gmaps/trunk/map_data.php @ 6639

Last change on this file since 6639 was 6639, checked in by plg, 14 years ago

makes rv_gmaps compatible with ExtendedDescriptions at photo comment level

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1<?php
2if ( !defined('PHPWG_ROOT_PATH') )
3  define('PHPWG_ROOT_PATH','../../');
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
12
13//set_make_full_url();
14$page['root_path']=get_absolute_root_url(false);
15
16$rewritten = '';
17foreach (array_keys($_GET) as $key)
18{
19  $rewritten = $key;
20  break;
21}
22// deleting first "/" if displayed
23$tokens = explode(
24  '/',
25  preg_replace('#^/#', '', $rewritten)
26  );
27$next_token = 0;
28$result = rvm_parse_map_data_url($tokens, $next_token);
29$page = array_merge( $page, $result );
30
31$where_sql = rvm_bounds_to_sql( $page['box'] );
32
33$img_fields = ' i.id,i.tn_ext,i.name,i.comment,i.path,i.lat,i.lon';
34
35$was_flat = @$page['flat'];
36$page['flat']=true;
37rvm_build_section_items($img_fields, $where_sql, RVM_BUILD_HASH);
38if (!$was_flat) unset($page['flat']);
39
40/*header('Cache-Control: public' );
41header('Expires: '.gmdate('D, d M Y H:i:s', time()+600).' GMT');
42header('Pragma:');*/
43header('Content-Type: text/plain; charset='.get_pwg_charset());
44
45if ( extension_loaded('zlib') && !ini_get('zlib.output_compression') )
46  ob_start('ob_gzhandler');
47
48$clusters = array();
49$cluster_debug = '';
50if ( !empty($page['items']) )
51{
52  include_once( dirname(__FILE__) .'/include/cluster_maker.php');
53  $cm = new ClusterMaker();
54  $clusters = $cm->make_clusters(
55      $page['items'],
56      isset($_GET['lap']) ? $_GET['lap'] : 0.01,
57      isset($_GET['lop']) ? $_GET['lop'] : 0.01,
58      isset($_GET['n']) ? $_GET['n'] : rvm_get_config_var('nb_markers',40)
59    );
60  $cluster_debug .= ' cluster: '. $cm->debug_str. ';';
61}
62
63function jsgm_position( $position )
64{
65  return 'new GLatLng(' . $position['lat'] . ',' . $position['lon'] . ')';
66}
67
68function jsgm_bounds( $bounds )
69{
70  return 'new GLatLngBounds(' . jsgm_position(bounds_sw($bounds)) . ',' . jsgm_position(bounds_ne($bounds)) . ')';
71}
72
73function jsgm_str( $str )
74{
75  return '"'. str_replace(array("\\",'"',"\n","\r","\t"), array("\\\\",'\"',"\\n","\\r","\\t"), $str) .'"';
76}
77
78$out='';
79function rvo($s) {
80  global $out; $out.=$s;
81}
82
83function rvf() {
84  global $out; echo $out; $out='';
85  ob_flush();
86}
87
88$start_output = get_moment();
89
90rvo( '{' );
91
92rvo( "\ntitle: ".jsgm_str( strip_tags($page['title']) ) );
93rvo( ",\n" );
94
95rvo( "page_url: ".jsgm_str( duplicate_index_url( array('start'=>0) ) ) );
96rvo( ",\n" );
97
98rvo( "blowup_url: ".jsgm_str( rvm_duplicate_blowup_url( array('start'=>0) ) ) );
99rvo( ",\n" );
100
101rvo( "kml_url: ".jsgm_str( rvm_duplicate_kml_index_url( array('start'=>0, 'flat'=>1) ) ) );
102rvo( ",\n" );
103
104rvo( "nb_items: ".count($page['items']) );
105rvo( ",\n" );
106
107rvo( "bounds: " );
108if ( isset($cm) )
109  rvo( jsgm_bounds( $cm->bounds ) );
110else
111  rvo( "null" );
112rvo( ",\n" );
113
114
115rvo( "\nnb_clusters: ".count($clusters) );
116rvo( "," );
117
118rvo( "\nimage_clusters: [\n" );
119$i=0;
120foreach( $clusters as $c )
121{
122  if ($i) rvo( ",\n\n" );
123  rvo( "{" );
124  rvo( 'position: '. jsgm_position( bounds_center($c['bounds']) ) );
125  rvo( ",\n" );
126  rvo( 'bounds: '. jsgm_bounds( $c['bounds'] ) );
127  rvo( ",\n" );
128  rvo( 'nb_items: '.count($c['items']) );
129  rvo( ",\n" );
130
131  rvo( 'blowup_url: "'.rvm_duplicate_blowup_url(array('box'=>$c['bounds']), array('start') ). '"' );
132  rvo( ",\n" );
133
134  rvo( 'kml_url: "'.rvm_duplicate_kml_index_url(array('box'=>$c['bounds'], 'flat'=>1), array('start') ). '"' );
135  rvo( ",\n" );
136
137  $max_per_cluster = rvm_get_config_var('nb_images_per_marker',20);
138  if ( count($c['items']) >  $max_per_cluster )
139  {
140    $c['items'] = array_slice($c['items'], 0, $max_per_cluster);
141  }
142  rvo( 'items: [' );
143  for ($j=0; $j<count($c['items']); $j++)
144  {
145    $img = $page['items'] [ $c['items'][$j] ];
146    $img['file'] = basename( $img['path'] );
147    if (!empty( $img['name'] ) )
148      $title = $img['name'];
149    else
150      $title = str_replace('_', ' ', get_filename_wo_extension($img['file']));
151
152    $params = array(
153        'image_id' => $img['id'],
154        'image_file' => $img['file'],
155        'flat' => 1,
156      );
157    $page_url = duplicate_picture_url($params, array('start') );
158
159    if ($j) rvo( "," );
160    rvo( "{" );
161    rvo( "tn: ".jsgm_str( get_thumbnail_url( $img ) ) );
162    rvo( "," );
163    rvo( "name: ".jsgm_str( $title ) );
164    rvo( "," );
165    rvo( "comment: ".jsgm_str( trigger_event('render_element_description', $img['comment']) ) );
166    rvo( "," );
167    rvo( "page_url: ".jsgm_str( $page_url ) );
168    rvo( "}" );
169  }
170  rvo( ']' );
171  rvo( "\n" );
172  rvo( "}" );
173  rvf();
174  $i++;
175}
176rvo( "] /*clusters*/\n" );
177
178$time = get_elapsed_time($t2, get_moment());
179$page['queries_time'] = number_format($page['queries_time'],3,'.',' ');
180rvo( "\n,debug:'$time; out:".get_elapsed_time($start_output,get_moment()).";$cluster_debug queries:".$page['count_queries']." in ".$page['queries_time']."s'\n" );
181
182rvo( '}' );
183rvf();
184?>
Note: See TracBrowser for help on using the repository browser.