aboutsummaryrefslogtreecommitdiff
path: root/mod/search/views/default/search/listing.php
blob: f947bd8085d508c3360fff33100f1356bf1d5fba (plain)
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
<?php
/**
 * Elgg search listing
 *
 * @package Elgg
 * @subpackage Core
 * @author Curverider Ltd
 * @link http://elgg.org/
 */


$entities = $vars['entities'];
$count = $vars['count'] - count($vars['entities']);

if (!is_array($vars['entities']) || !count($vars['entities'])) {
	return FALSE;
}

// figure out what we're deal with.
if (array_key_exists('type', $vars['params']) && array_key_exists('subtype', $vars['params'])) {
	$type_str = elgg_echo("item:{$vars['params']['type']}:{$vars['params']['subtype']}");
} elseif (array_key_exists('type', $vars['params'])) {
	$type_str = elgg_echo("item:{$vars['params']['type']}");
} else {
	$type_str = elgg_echo('search:unknown_entity');
}

$query = htmlspecialchars(http_build_query(
	array(
		'q' => $vars['params']['query'],
		'entity_type' => $vars['params']['type'],
		'entity_subtype' => $vars['params']['subtype'],
		'search_type' => 'entities',
	)
));

$url = "{$vars['url']}pg/search?$query";

// get pagination
if (array_key_exists('pagination', $vars['params']) && $vars['params']['pagination']) {
	$nav .= elgg_view('navigation/pagination',array(
		'baseurl' => $url,
		'offset' => $vars['params']['offset'],
		'count' => $vars['count'],
		'limit' => $vars['params']['limit'],
	));
} else {
	$nav = '';
}

// get any more links.
$more_check = $vars['count'] - ($vars['params']['offset'] + $vars['params']['limit']);
$more = ($more_check > 0) ? $more_check : 0;

if ($more) {
	$title_key = ($more == 1) ? 'comment' : 'comments';
	$more_str = sprintf(elgg_echo('search:more'), $count, $type_str);
	$more_link = "<a href=\"$url\">$more_str</a>";
} else {
	$more_link = '';
}

echo $nav;
$body = elgg_view_title($title_str);

foreach ($entities as $entity) {
	if ($owner = $entity->getOwnerEntity()) {
		$owner_icon = $owner->getIcon('tiny');
		$icon = "<img src=\"$owner_icon\" />";
	} else {
		$icon = '';
	}
	$title = $entity->getVolatileData('search_matched_title');
	$description = $entity->getVolatileData('search_matched_description');
	$url = $entity->getURL();
	$title = "<a href=\"$url\">$title</a>";
	$tc = $entity->time_created;
	$tu = $entity->time_updated;
	$time = friendly_time(($tu > $tc) ? $tu : $tc);

	$body .= <<<___END
<span class="searchListing">
	<h3 class="searchTitle">$title</h3>
	<span class="searchDescription">$description</span><br />
	<span class="searchInfo">$icon $time - $more_link</span>
</span>
___END;
}

echo elgg_view('page_elements/contentwrapper', array('body' => $body));
echo $nav;