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.tn_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 | |
---|
45 | if ( extension_loaded('zlib') && !ini_get('zlib.output_compression') ) |
---|
46 | ob_start('ob_gzhandler'); |
---|
47 | |
---|
48 | $clusters = array(); |
---|
49 | $cluster_debug = ''; |
---|
50 | if ( !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 | |
---|
63 | function jsgm_position( $position ) |
---|
64 | { |
---|
65 | return 'new google.maps.LatLng(' . $position['lat'] . ',' . $position['lon'] . ')'; |
---|
66 | } |
---|
67 | |
---|
68 | function jsgm_bounds( $bounds ) |
---|
69 | { |
---|
70 | return 'new google.maps.LatLngBounds(' . jsgm_position(bounds_sw($bounds)) . ',' . jsgm_position(bounds_ne($bounds)) . ')'; |
---|
71 | } |
---|
72 | |
---|
73 | function jsgm_str( $str ) |
---|
74 | { |
---|
75 | return '"'. str_replace(array("\\",'"',"\n","\r","\t"), array("\\\\",'\"',"\\n","\\r","\\t"), $str) .'"'; |
---|
76 | } |
---|
77 | |
---|
78 | $out=''; |
---|
79 | function rvo($s) { |
---|
80 | global $out; $out.=$s; |
---|
81 | } |
---|
82 | |
---|
83 | function rvf() { |
---|
84 | global $out; echo $out; $out=''; |
---|
85 | ob_flush(); |
---|
86 | } |
---|
87 | |
---|
88 | $start_output = get_moment(); |
---|
89 | |
---|
90 | rvo( '{' ); |
---|
91 | |
---|
92 | rvo( "\ntitle: ".jsgm_str( strip_tags(trigger_event('render_element_description', $page['title']) ) ) ); |
---|
93 | rvo( ",\n" ); |
---|
94 | |
---|
95 | rvo( "page_url: ".jsgm_str( duplicate_index_url( array('start'=>0) ) ) ); |
---|
96 | rvo( ",\n" ); |
---|
97 | |
---|
98 | rvo( "blowup_url: ".jsgm_str( rvm_duplicate_blowup_url( array('start'=>0) ) ) ); |
---|
99 | rvo( ",\n" ); |
---|
100 | |
---|
101 | rvo( "kml_url: ".jsgm_str( rvm_duplicate_kml_index_url( array('start'=>0, 'flat'=>1) ) ) ); |
---|
102 | rvo( ",\n" ); |
---|
103 | |
---|
104 | rvo( "nb_items: ".count($page['items']) ); |
---|
105 | rvo( ",\n" ); |
---|
106 | |
---|
107 | rvo( "bounds: " ); |
---|
108 | if ( isset($cm) ) |
---|
109 | rvo( jsgm_bounds( $cm->bounds ) ); |
---|
110 | else |
---|
111 | rvo( "null" ); |
---|
112 | rvo( ",\n" ); |
---|
113 | |
---|
114 | |
---|
115 | rvo( "\nnb_clusters: ".count($clusters) ); |
---|
116 | rvo( "," ); |
---|
117 | |
---|
118 | rvo( "\nimage_clusters: [\n" ); |
---|
119 | $i=0; |
---|
120 | foreach( $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 | $max_per_cluster = rvm_get_config_var('nb_images_per_marker',20); |
---|
135 | if ( count($c->items) > $max_per_cluster ) |
---|
136 | { |
---|
137 | $c->items = array_slice($c->items, 0, $max_per_cluster); |
---|
138 | } |
---|
139 | rvo( 'items: [' ); |
---|
140 | for ($j=0; $j<count($c->items); $j++) |
---|
141 | { |
---|
142 | $img = $page['items'] [ $c->items[$j] ]; |
---|
143 | $img['file'] = basename( $img['path'] ); |
---|
144 | if (!empty( $img['name'] ) ) |
---|
145 | $title = $img['name']; |
---|
146 | else |
---|
147 | $title = str_replace('_', ' ', get_filename_wo_extension($img['file'])); |
---|
148 | |
---|
149 | $params = array( |
---|
150 | 'image_id' => $img['id'], |
---|
151 | 'image_file' => $img['file'], |
---|
152 | 'flat' => 1, |
---|
153 | ); |
---|
154 | $page_url = duplicate_picture_url($params, array('start') ); |
---|
155 | |
---|
156 | if ($j) rvo( "," ); |
---|
157 | rvo( "{" ); |
---|
158 | rvo( "tn: ".jsgm_str( get_thumbnail_url( $img ) ) ); |
---|
159 | rvo( ",name: ".jsgm_str( trigger_event('render_element_description', $title) ) ); |
---|
160 | rvo( ",comment: ".jsgm_str( trigger_event('render_element_description', $img['comment']) ) ); |
---|
161 | rvo( ",page_url: ".jsgm_str( $page_url ) ); |
---|
162 | rvo( "}" ); |
---|
163 | } |
---|
164 | rvo( ']' ); |
---|
165 | rvo( "\n" ); |
---|
166 | rvo( "}" ); |
---|
167 | rvf(); |
---|
168 | $i++; |
---|
169 | } |
---|
170 | rvo( "] /*clusters*/\n" ); |
---|
171 | |
---|
172 | $time = get_elapsed_time($t2, get_moment()); |
---|
173 | $page['queries_time'] = number_format($page['queries_time'],3,'.',' '); |
---|
174 | rvo( "\n,debug:'$time; out:".get_elapsed_time($start_output,get_moment()).";$cluster_debug queries:".$page['count_queries']." in ".$page['queries_time']."s'\n" ); |
---|
175 | |
---|
176 | rvo( '}' ); |
---|
177 | rvf(); |
---|
178 | ?> |
---|