-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout_locations.php
111 lines (89 loc) · 2.87 KB
/
layout_locations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* layout locations
*
* This is the default layout for locations.
*
* @see locations/index.php
* @see locations/locations.php
*
* @author Bernard Paques
* @author GnapZ
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
Class Layout_locations extends Layout_interface {
/**
* list locations
*
* Recognize following variants:
* - 'no_anchor' to list items attached to one particular anchor
* - 'no_author' to list items attached to one user prolocation
*
* @param resource the SQL result
* @return string the rendered text
*
* @see layouts/layout.php
**/
function layout($result) {
global $context;
// empty list
if(!SQL::count($result)) {
$output = array();
return $output;
}
// we return an array of ($url => $attributes)
$items = array();
// process all items in the list
while($item = SQL::fetch($result)) {
// initialize variables
$prefix = $suffix = $icon = '';
// the url to view this item
$url = Locations::get_url($item['id']);
// build a valid label
if($item['geo_place_name'])
$label = Skin::strip($item['geo_place_name'], 10);
else
$label = $item['latitude'].', '.$item['longitude'];
// description
if($item['description'])
$suffix .= ' '.ucfirst(trim($item['description']));
// the menu bar for associates and poster
if(Surfer::is_empowered() || Surfer::is($item['edit_id'])) {
$menu = array( Locations::get_url($item['id'], 'edit') => i18n::s('Edit'),
Locations::get_url($item['id'], 'delete') => i18n::s('Delete') );
$suffix .= ' '.Skin::build_list($menu, 'menu');
}
// add a separator
if($suffix)
$suffix = ' - '.$suffix;
// append details to the suffix
$suffix .= BR.'<span '.tag::_class('details').'>';
// details
$details = array();
// item poster
if(isset($this->layout_variant) && ($this->layout_variant != 'no_author')) {
if($item['edit_name'])
$details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date']));
} else
$details[] = Anchors::get_action_label($item['edit_action']);
// show an anchor location
if(isset($this->layout_variant) && ($this->layout_variant != 'no_anchor') && $item['anchor'] && ($anchor = Anchors::get($item['anchor']))) {
$anchor_url = $anchor->get_url();
$anchor_label = ucfirst($anchor->get_title());
$details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor_url, $anchor_label, 'article'));
}
// all details
if(count($details))
$suffix .= ucfirst(implode(', ', $details))."\n";
// end of details
$suffix .= '</span>';
// list all components for this item
$items[$url] = array($prefix, $label, $suffix, 'location', $icon);
}
// end of processing
SQL::free($result);
return $items;
}
}
?>