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.file,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 | $start_output = get_moment(); |
---|
80 | |
---|
81 | |
---|
82 | echo "{\ntitle:", jsgm_str( strip_tags(trigger_event('render_element_description', $page['title']) ) ) |
---|
83 | , ",\npage_url:", jsgm_str( duplicate_index_url( array('start'=>0) ) ) |
---|
84 | , ",\nblowup_url:", jsgm_str( rvm_duplicate_blowup_url( array('start'=>0) ) ) |
---|
85 | , ",\nkml_url:", jsgm_str( rvm_duplicate_kml_index_url( array('start'=>0, 'flat'=>1) ) ) |
---|
86 | , ",\nnb_items:", count($page['items']); |
---|
87 | |
---|
88 | echo ",\nbounds:"; |
---|
89 | if ( isset($cm) ) |
---|
90 | echo jsgm_bounds( $cm->bounds ); |
---|
91 | else |
---|
92 | echo "null"; |
---|
93 | |
---|
94 | echo ",\n\nnb_clusters:", count($clusters); |
---|
95 | |
---|
96 | echo ",\nimage_clusters:[\n"; |
---|
97 | $i=0; |
---|
98 | $thumb_params = ImageStdParams::get_by_type(IMG_THUMB); |
---|
99 | $page_url_model = duplicate_picture_url( |
---|
100 | array( |
---|
101 | 'image_id' => 123456789, |
---|
102 | 'image_file' => 'dummy_file.txt', |
---|
103 | 'flat' => 1, |
---|
104 | ), |
---|
105 | array('start') |
---|
106 | ); |
---|
107 | |
---|
108 | foreach( $clusters as $c ) |
---|
109 | { |
---|
110 | if ($i) echo ",\n\n" ; |
---|
111 | echo '{position:', jsgm_position( bounds_center($c->bounds) ); |
---|
112 | echo ",\nbounds:", jsgm_bounds( $c->bounds ); |
---|
113 | echo ",\nnb_items:", count($c->items); |
---|
114 | echo ",\n"; |
---|
115 | |
---|
116 | echo 'blowup_url:"', rvm_duplicate_blowup_url(array('box'=>$c->bounds), array('start') ), '"'; |
---|
117 | |
---|
118 | $max_per_cluster = rvm_get_config_var('nb_images_per_marker',20); |
---|
119 | if ( count($c->items) > $max_per_cluster ) |
---|
120 | $c->items = array_slice($c->items, 0, $max_per_cluster); |
---|
121 | |
---|
122 | echo ",\nitems:["; |
---|
123 | for ($j=0; $j<count($c->items); $j++) |
---|
124 | { |
---|
125 | $img = $page['items'] [ $c->items[$j] ]; |
---|
126 | |
---|
127 | $page_url = str_replace(array('123456789','dummy_file'), array($img['id'], get_filename_wo_extension($img['file'])), $page_url_model); |
---|
128 | |
---|
129 | if ($j) echo( "," ); |
---|
130 | echo "{tn:", jsgm_str( DerivativeImage::url( $thumb_params,$img ) ); |
---|
131 | echo ",name:", jsgm_str( render_element_name($img) ); |
---|
132 | echo ",comment:", jsgm_str( render_element_description($img) ); |
---|
133 | echo ",page_url:", jsgm_str( $page_url ); |
---|
134 | echo "}"; |
---|
135 | } |
---|
136 | echo "]\n}"; |
---|
137 | $i++; |
---|
138 | } |
---|
139 | echo "] /*clusters*/\n"; |
---|
140 | |
---|
141 | $time = get_elapsed_time($t2, get_moment()); |
---|
142 | $page['queries_time'] = number_format($page['queries_time'],3,'.',' '); |
---|
143 | echo "\n,debug:'$time; out:", get_elapsed_time($start_output,get_moment()), ";$cluster_debug queries:", $page['count_queries'], " in ", $page['queries_time'], "s'\n" ; |
---|
144 | |
---|
145 | echo '}'; |
---|
146 | ?> |
---|