1 | <?php |
---|
2 | define('PHPWG_ROOT_PATH','../../'); |
---|
3 | |
---|
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 | rvm_load_language(); |
---|
13 | set_make_full_url(); |
---|
14 | |
---|
15 | $section = ''; |
---|
16 | if ( $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 | } |
---|
22 | else |
---|
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; |
---|
40 | if ( isset($page['ll']) ) |
---|
41 | $where_sql = rvm_ll_to_sql($page['ll'], $order_by); |
---|
42 | else |
---|
43 | $where_sql = rvm_bounds_to_sql( $page['box'] ); |
---|
44 | |
---|
45 | |
---|
46 | $img_fields = ' i.id,i.tn_ext,i.name,i.comment,i.file,i.path,i.lat,i.lon,i.date_creation'; |
---|
47 | |
---|
48 | rvm_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 | |
---|
63 | if ( !empty($page['items']) ) |
---|
64 | $dataTpl->assign( 'NB_ITEMS_DESC', sprintf( l10n('%d elements'), count($page['items']) ).'<br/>' ); |
---|
65 | |
---|
66 | |
---|
67 | // +-----------------------------------------------------------------------+ |
---|
68 | // | sub categories network links | |
---|
69 | // +-----------------------------------------------------------------------+ |
---|
70 | if ( 'categories'==$page['section'] and !isset($page['flat']) ) |
---|
71 | { |
---|
72 | $query = ' |
---|
73 | SELECT 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 = ' |
---|
94 | SELECT id, path, tn_ext |
---|
95 | FROM '.IMAGES_TABLE.' |
---|
96 | WHERE id IN ('.implode(',', $thumbnail_ids).')'; |
---|
97 | $result = pwg_query($query); |
---|
98 | while ($row = mysql_fetch_assoc($result)) |
---|
99 | $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); |
---|
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 | { |
---|
114 | $count_desc = l10n_dec('%d element', '%d elements', $bounds['self']['count']); |
---|
115 | if ( $bounds['self']['count'] == $bounds['count'] ) |
---|
116 | $count_desc .= ' '.l10n('images_available_cpl'); |
---|
117 | else |
---|
118 | $count_desc .= '/'.l10n_dec('%d element', '%d elements', $bounds['count']).' '.l10n_dec('images_available_cat','images_available_cats', $bounds['nb_cats'] ); |
---|
119 | } |
---|
120 | else |
---|
121 | $count_desc = l10n_dec('%d element', '%d elements', $bounds['count']) |
---|
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(); |
---|
146 | foreach( $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 | if (!empty( $img['name'] ) ) |
---|
152 | $title = $img['name']; |
---|
153 | else |
---|
154 | $title = str_replace('_', ' ', get_filename_wo_extension($img['file'])); |
---|
155 | |
---|
156 | $tpl_var = array( |
---|
157 | 'U_PAGE'=> $page_url, |
---|
158 | 'TN_SRC' => get_thumbnail_url($img), |
---|
159 | 'TITLE' => $title, |
---|
160 | 'DESCRIPTION' => $img['comment'], |
---|
161 | 'LAT' => $img['lat'], |
---|
162 | 'LON' => $img['lon'], |
---|
163 | 'DATE_CREATION' => $img['date_creation'], |
---|
164 | ); |
---|
165 | $dataTpl->append('images', $tpl_var); |
---|
166 | } |
---|
167 | |
---|
168 | if ( !empty($bounds) ) |
---|
169 | $dataTpl->assign( 'region', $bounds ); |
---|
170 | |
---|
171 | /*header('Cache-Control: public' ); |
---|
172 | header('Expires: '.gmdate('D, d M Y H:i:s', time()+600).' GMT'); |
---|
173 | header('Pragma:');*/ |
---|
174 | header('Content-Disposition: inline; filename="'.str2url($page['title']).'.kml";' ); |
---|
175 | header('Content-Type: application/vnd.google-earth.kml+xml; charset='.get_pwg_charset()); |
---|
176 | if (isset($_GET['debug'])) |
---|
177 | header('Content-Type: text/xml; charset='.get_pwg_charset()); |
---|
178 | |
---|
179 | |
---|
180 | $dataTpl->pparse('main'); |
---|
181 | |
---|
182 | ?> |
---|