source: extensions/rv_gmaps/trunk/mapl.php @ 13092

Last change on this file since 13092 was 13092, checked in by rvelices, 12 years ago

rv_gmaps compatible with core version 2.4

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1<?php
2if ( !defined('PHPWG_ROOT_PATH') )
3  define('PHPWG_ROOT_PATH','../../');
4
5include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
6include_once( dirname(__FILE__) .'/include/functions.php');
7include_once( dirname(__FILE__) .'/include/functions_map.php');
8
9check_status(ACCESS_GUEST);
10if (!isset($rvm_dir))
11  access_denied( 'Plugin not installed' );
12
13rvm_load_language();
14
15$section = '';
16if ( $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  if ( !isset($page['root_path']) )
22  {
23    $path_count = count( explode('/', $section) );
24    $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1);
25  }
26}
27else
28{
29  foreach ($_GET as $key=>$value)
30  {
31    if (!strlen($value)) $section=$key;
32    break;
33  }
34}
35
36// deleting first "/" if displayed
37$tokens = explode(
38  '/',
39  preg_replace('#^/#', '', $section)
40  );
41$next_token = 0;
42$result = rvm_parse_blowup_url($tokens, $next_token);
43$page = array_merge( $page, $result );
44
45$order_by=null;
46if ( isset($page['ll']) )
47  $where_sql = rvm_ll_to_sql($page['ll'], $order_by);
48else
49  $where_sql = rvm_bounds_to_sql( $page['box'] );
50
51$img_fields = ' i.id';
52
53$was_flat = @$page['flat'];
54$page['flat']=true;
55rvm_build_section_items($img_fields, $where_sql, RVM_BUILD_HASH, $order_by);
56$page['items']=array_keys($page['items']);
57if (!$was_flat) unset($page['flat']);
58
59$template->set_filename( 'map', dirname(__FILE__).'/template/mapl.tpl');
60
61if (!empty($page['items']))
62{
63/* GENERATE THE CATEGORY LIST *************************************************/
64$where_sql = 'i.id IN ('.implode(',', $page['items'] ).')';
65$where_sql .= get_sql_condition_FandF(
66        array( 'forbidden_categories' => 'category_id' ),
67        ' AND'
68      );
69$query = '
70SELECT DISTINCT c.id, c.name, c.permalink, COUNT(DISTINCT i.id) counter
71  FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id=image_id
72    INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id
73  WHERE '.$where_sql.'
74  GROUP BY category_id
75  ORDER BY counter DESC
76  LIMIT 0,5
77;';
78$result = pwg_query($query);
79$categories=array();
80while ($row=mysql_fetch_assoc($result))
81  array_push($categories, $row);
82$categories = add_level_to_tags($categories);
83
84foreach( $categories as $category)
85{
86  $template->append(
87    'related_categories', array(
88      'U_MAP' => rvm_make_map_index_url( array( 'category' => $category ) ),
89      'URL' => make_index_url( array( 'category' => $category ) ),
90      'NAME' => trigger_event('render_element_description', $category['name']),
91      'TITLE' => l10n_dec( '%d photo', '%d photos', $category['counter'] ),
92      'CLASS' => 'tagLevel'.$category['level']
93    )
94    );
95}
96
97/* GENERATE THE TAG LIST ******************************************************/
98$tags = get_common_tags( $page['items'], $conf['content_tag_cloud_items_number'], null);
99$tags = add_level_to_tags($tags);
100function counter_compare($a, $b)
101{
102  $d = $a['counter'] - $b['counter'];
103  if ($d==0)
104    return strcmp($a['name'], $b['name']);
105  return -$d;
106}
107usort($tags, 'counter_compare');
108foreach ($tags as $tag)
109{
110  $template->append(
111    'related_tags',
112    array_merge( $tag,
113      array(
114        'U_MAP' => rvm_make_map_index_url( array( 'tags' => array($tag) ) ),
115        'URL' => make_index_url( array( 'tags' => array($tag) ) ),
116        'TITLE' => l10n_dec( '%d photo', '%d photos', $tag['counter'] ),
117      )
118    )
119  );
120}
121} // end !empty items
122
123
124$title = '<a target="_top" title="'.sprintf( l10n('go to %s'),$page['title']).'" href="'.duplicate_index_url( array('start'=>0) ).'">'.$page['title'].'</a>';
125if ( count($page['items']) > 0)
126  $title.=' ['.count($page['items']).']';
127
128$template->assign(
129  array(
130    'PLUGIN_ROOT_URL' => get_absolute_root_url().'plugins/'.$rvm_dir,
131    'TITLE'   => $title,
132    'U_HOME'  => make_index_url(),
133    'U_KML'   => rvm_duplicate_kml_index_url( array('flat'=>1), array('start') ),
134    'KML_LINK_TITLE' => sprintf( l10n('opens %s in Google Earth'), strip_tags($page['title']) ),
135  )
136  );
137
138$url = rvm_duplicate_blowup_url(array('start'=>0));
139$navbar = create_navigation_bar($url, count( $page['items'] ), $page['start'], 48);
140$template->assign('navbar', $navbar);
141
142$page['items'] = array_slice(
143  $page['items'],
144  $page['start'],
145  48
146  );
147
148$pictures = array();
149if (count($page['items']) > 0)
150{
151  $rank_of = array_flip($page['items']);
152
153  $query = '
154SELECT *
155  FROM '.IMAGES_TABLE.'
156  WHERE id IN ('.implode(',', $page['items']).')
157;';
158  $result = pwg_query($query);
159  while ($row = pwg_db_fetch_assoc($result))
160  {
161    $row['rank'] = $rank_of[ $row['id'] ];
162    $pictures[] = $row;
163  }
164  usort($pictures, 'rank_compare');
165  unset($rank_of);
166}
167
168foreach ($pictures as $img)
169{
170  $page_url = duplicate_picture_url(
171        array(
172          'image_id' => $img['id'],
173          'image_file' => $img['file'],
174          'flat' => 1,
175        ),
176        array('start')
177      );
178  $name = render_element_name($img);
179  $desc = render_element_description($img);
180
181  $tpl_thumbnails_var[] = array_merge( $img, array(
182                'NAME' => $name,
183    'TN_ALT' => htmlspecialchars(strip_tags($name)),
184    'TN_TITLE' => get_thumbnail_title($img, $name, $desc),
185    'URL' => $page_url,
186    'DESCRIPTION' => $desc,
187    'src_image' => new SrcImage($img),
188    ) );
189}
190$template->assign( array(
191  'derivative_params' => ImageStdParams::get_by_type(IMG_THUMB),
192  'SHOW_THUMBNAIL_CAPTION' => false,
193        'thumbnails' => $tpl_thumbnails_var,
194    ) );
195$template->set_filename('index_thumbnails', 'thumbnails.tpl');
196$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
197
198$title = $page['title'];
199$page['body_id'] = 'theMapListPage';
200
201include(PHPWG_ROOT_PATH.'include/page_header.php');
202$template->parse('map');
203include(PHPWG_ROOT_PATH.'include/page_tail.php');
204
205?>
Note: See TracBrowser for help on using the repository browser.