1 | <?php |
---|
2 | if ( !defined('PHPWG_ROOT_PATH') ) |
---|
3 | define('PHPWG_ROOT_PATH','../../'); |
---|
4 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
5 | |
---|
6 | if (!isset($rvm_dir)) |
---|
7 | access_denied( 'Plugin not installed' ); |
---|
8 | |
---|
9 | include_once( dirname(__FILE__) .'/include/functions_map.php'); |
---|
10 | include_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 = ''; |
---|
17 | foreach (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.representative_ext,i.name,i.comment,i.path,i.lat,i.lon'; |
---|
34 | |
---|
35 | $was_flat = @$page['flat']; |
---|
36 | $page['flat']=true; |
---|
37 | rvm_build_section_items($img_fields, $where_sql, RVM_BUILD_HASH); |
---|
38 | if (!$was_flat) unset($page['flat']); |
---|
39 | |
---|
40 | /*header('Cache-Control: public' ); |
---|
41 | header('Expires: '.gmdate('D, d M Y H:i:s', time()+600).' GMT'); |
---|
42 | header('Pragma:');*/ |
---|
43 | header('Content-Type: text/plain; charset='.get_pwg_charset()); |
---|
44 | header('X-Robots-Tag: noindex'); |
---|
45 | |
---|
46 | if ( extension_loaded('zlib') && !ini_get('zlib.output_compression') ) |
---|
47 | ob_start('ob_gzhandler'); |
---|
48 | |
---|
49 | $clusters = array(); |
---|
50 | $cluster_debug = ''; |
---|
51 | if ( !empty($page['items']) ) |
---|
52 | { |
---|
53 | include_once( dirname(__FILE__) .'/include/cluster_maker.php'); |
---|
54 | $cm = new ClusterMaker(); |
---|
55 | $clusters = $cm->make_clusters( |
---|
56 | $page['items'], |
---|
57 | isset($_GET['lap']) ? $_GET['lap'] : 0.01, |
---|
58 | isset($_GET['lop']) ? $_GET['lop'] : 0.01, |
---|
59 | isset($_GET['n']) ? $_GET['n'] : rvm_get_config_var('nb_markers',40) |
---|
60 | ); |
---|
61 | $cluster_debug .= ' cluster: '. $cm->debug_str. ';'; |
---|
62 | } |
---|
63 | |
---|
64 | function jsgm_position( $position ) |
---|
65 | { |
---|
66 | return 'new google.maps.LatLng(' . $position['lat'] . ',' . $position['lon'] . ')'; |
---|
67 | } |
---|
68 | |
---|
69 | function jsgm_bounds( $bounds ) |
---|
70 | { |
---|
71 | return 'new google.maps.LatLngBounds(' . jsgm_position(bounds_sw($bounds)) . ',' . jsgm_position(bounds_ne($bounds)) . ')'; |
---|
72 | } |
---|
73 | |
---|
74 | function jsgm_str( $str ) |
---|
75 | { |
---|
76 | return '"'. str_replace(array("\\",'"',"\n","\r","\t"), array("\\\\",'\"',"\\n","\\r","\\t"), $str) .'"'; |
---|
77 | } |
---|
78 | |
---|
79 | $out=''; |
---|
80 | function rvo($s) { |
---|
81 | global $out; $out.=$s; |
---|
82 | } |
---|
83 | |
---|
84 | function rvf() { |
---|
85 | global $out; echo $out; $out=''; |
---|
86 | ob_flush(); |
---|
87 | } |
---|
88 | |
---|
89 | $start_output = get_moment(); |
---|
90 | |
---|
91 | rvo( '{' ); |
---|
92 | |
---|
93 | rvo( "\ntitle:".jsgm_str( strip_tags(trigger_event('render_element_description', $page['title']) ) ) ); |
---|
94 | rvo( ",\n" ); |
---|
95 | |
---|
96 | rvo( "page_url:".jsgm_str( duplicate_index_url( array('start'=>0) ) ) ); |
---|
97 | rvo( ",\n" ); |
---|
98 | |
---|
99 | rvo( "blowup_url:".jsgm_str( rvm_duplicate_blowup_url( array('start'=>0) ) ) ); |
---|
100 | rvo( ",\n" ); |
---|
101 | |
---|
102 | rvo( "kml_url:".jsgm_str( rvm_duplicate_kml_index_url( array('start'=>0, 'flat'=>1) ) ) ); |
---|
103 | rvo( ",\n" ); |
---|
104 | |
---|
105 | rvo( "nb_items:".count($page['items']) ); |
---|
106 | rvo( ",\n" ); |
---|
107 | |
---|
108 | rvo( "bounds:" ); |
---|
109 | if ( isset($cm) ) |
---|
110 | rvo( jsgm_bounds( $cm->bounds ) ); |
---|
111 | else |
---|
112 | rvo( "null" ); |
---|
113 | rvo( ",\n" ); |
---|
114 | |
---|
115 | |
---|
116 | rvo( "\nnb_clusters:".count($clusters) ); |
---|
117 | rvo( "," ); |
---|
118 | |
---|
119 | rvo( "\nimage_clusters:[\n" ); |
---|
120 | $i=0; |
---|
121 | foreach( $clusters as $c ) |
---|
122 | { |
---|
123 | if ($i) rvo( ",\n\n" ); |
---|
124 | rvo( "{" ); |
---|
125 | rvo( 'position:'. jsgm_position( bounds_center($c->bounds) ) ); |
---|
126 | rvo( ",\n" ); |
---|
127 | rvo( 'bounds:'. jsgm_bounds( $c->bounds ) ); |
---|
128 | rvo( ",\n" ); |
---|
129 | rvo( 'nb_items:'.count($c->items) ); |
---|
130 | rvo( ",\n" ); |
---|
131 | |
---|
132 | rvo( 'blowup_url:"'.rvm_duplicate_blowup_url(array('box'=>$c->bounds), array('start') ). '"' ); |
---|
133 | rvo( ",\n" ); |
---|
134 | |
---|
135 | $max_per_cluster = rvm_get_config_var('nb_images_per_marker',20); |
---|
136 | if ( count($c->items) > $max_per_cluster ) |
---|
137 | { |
---|
138 | $c->items = array_slice($c->items, 0, $max_per_cluster); |
---|
139 | } |
---|
140 | rvo( 'items:[' ); |
---|
141 | for ($j=0; $j<count($c->items); $j++) |
---|
142 | { |
---|
143 | $img = $page['items'] [ $c->items[$j] ]; |
---|
144 | $img['file'] = basename( $img['path'] ); |
---|
145 | if (!empty( $img['name'] ) ) |
---|
146 | $title = $img['name']; |
---|
147 | else |
---|
148 | $title = str_replace('_', ' ', get_filename_wo_extension($img['file'])); |
---|
149 | |
---|
150 | $params = array( |
---|
151 | 'image_id' => $img['id'], |
---|
152 | 'image_file' => $img['file'], |
---|
153 | 'flat' => 1, |
---|
154 | ); |
---|
155 | $page_url = duplicate_picture_url($params, array('start') ); |
---|
156 | |
---|
157 | if ($j) rvo( "," ); |
---|
158 | rvo( "{" ); |
---|
159 | rvo( "tn:".jsgm_str( get_thumbnail_url( $img ) ) ); |
---|
160 | rvo( ",name:".jsgm_str( trigger_event('render_element_description', $title) ) ); |
---|
161 | rvo( ",comment:".jsgm_str( trigger_event('render_element_description', $img['comment']) ) ); |
---|
162 | rvo( ",page_url:".jsgm_str( $page_url ) ); |
---|
163 | rvo( "}" ); |
---|
164 | } |
---|
165 | rvo( ']' ); |
---|
166 | rvo( "\n" ); |
---|
167 | rvo( "}" ); |
---|
168 | rvf(); |
---|
169 | $i++; |
---|
170 | } |
---|
171 | rvo( "] /*clusters*/\n" ); |
---|
172 | |
---|
173 | $time = get_elapsed_time($t2, get_moment()); |
---|
174 | $page['queries_time'] = number_format($page['queries_time'],3,'.',' '); |
---|
175 | rvo( "\n,debug:'$time; out:".get_elapsed_time($start_output,get_moment()).";$cluster_debug queries:".$page['count_queries']." in ".$page['queries_time']."s'\n" ); |
---|
176 | |
---|
177 | rvo( '}' ); |
---|
178 | rvf(); |
---|
179 | ?> |
---|