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

Revision 20461, 5.9 KB checked in by rvelices, 7 years ago (diff)

rv* plugins use pwg_db_* instead of mysql_* functions

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