aboutsummaryrefslogtreecommitdiff
path: root/views/default/infinite_scroll/list.php
blob: 6a6ab9ec7d20637a78ebc32ef3684dc672ec3d1b (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
<?php

$path = explode('/', $vars['path']);
array_shift($path);

$list_type = get_input('list_type', 'list');
set_input('list_type', 'list');

ob_start();
elgg_set_viewtype('json');

// Check this when #4723 closed.
if (!$path[0]) {
	include(elgg_get_root_path().'index.php');
} else {
	page_handler(array_shift($path), implode('/', $path));
}

$json = json_decode(ob_get_clean());

switch(get_input('items_type')){
	case 'entity':
		foreach ($json as $child) foreach ($child as $grandchild) $json = $grandchild;
		
		/* Removing duplicates
		   This is unnecessary when #4504 is fixed. */
		if (version_compare(get_version(true), '1.8.7', '<')) {
			$buggy = $json;
			$json = array();
			$guids = array();
			foreach ($buggy as $item) {
				$guids[] = $item->guid;
			}
			$guids = array_unique($guids);
			foreach (array_keys($guids) as $i) {
				$json[$i] = $buggy[$i];
			}
		}
		break;
	case 'annotation': 
		foreach ($json as $child) {
			$json = $child;
		}
		$json = elgg_get_annotations(array(
			'items' => $json->guid,
			'offset' => get_input('offset'),
			'limit' => 25,
		));
		break;
	case 'river':
		$json = $json->activity;
		break;
}

if (!is_array($json)) {
	exit();
}

$items = array();
foreach($json as $item) {
	switch(get_input('items_type')) {
		case 'entity':
			$type_class = array(
				'site' => 'ElggSite',
				'user' => 'ElggUser',
				'group' => 'ElggGroup',
				'object' => 'ElggObject'
			);
			$items[] = new $type_class[$item->type]($item);
			break;
		case 'annotation': 
			$items = $json;
			break;
		case 'river':
			$items[] = new ElggRiverItem($item);
			break;
	}
}

header('Content-type: text/plain');

elgg_set_viewtype('default');
echo elgg_view("page/components/$list_type", array("items" => $items));