-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.php
154 lines (137 loc) · 5.05 KB
/
start.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
elgg_register_event_handler('init', 'system', 'smartfeed_init');
function smartfeed_init()
{
/* register page handlers */
elgg_register_page_handler('dashboard', function () {
require_once dirname(__FILE__) . '/pages/dashboard.php';
return true;
});
/* register java script */
$url = elgg_get_simplecache_url('js', 'vendors/angular');
elgg_register_simplecache_view('js/vendors/angular');
elgg_register_js('angular', $url);
// load angualr at the header for all the site (can be extracted to the core \ other plugin)
elgg_load_js('angular');
$url = elgg_get_simplecache_url('js', 'vendors/underscore');
elgg_register_simplecache_view('js/vendors/underscore');
elgg_register_js('underscore', $url);
elgg_load_js('underscore');
$url = elgg_get_simplecache_url('js', 'vendors/ng_infinite_scroll');
elgg_register_simplecache_view('js/vendors/ng_infinite_scroll');
elgg_register_js('ng_infinite_scroll', $url);
elgg_load_js('ng_infinite_scroll');
$url = elgg_get_simplecache_url('js', 'ng_feed/app');
elgg_register_simplecache_view('js/ng_feed/app');
elgg_register_js('ng_feed_app', $url);
$url = elgg_get_simplecache_url('js', 'ng_feed/feed_ctrl');
elgg_register_simplecache_view('js/ng_feed/feed_ctrl');
elgg_register_js('feed_ctrl', $url);
$url = elgg_get_simplecache_url('js', 'ng_feed/activities_loader_service');
elgg_register_simplecache_view('js/ng_feed/activities_loader_service');
elgg_register_js('activities_loader_service', $url);
$url = elgg_get_simplecache_url('js', 'ng_feed/pubsub_broker_service');
elgg_register_simplecache_view('js/ng_feed/pubsub_broker_service');
elgg_register_js('pubsub_broker_service', $url);
$url = elgg_get_simplecache_url('js', 'ng_feed/pretty_date');
elgg_register_simplecache_view('js/ng_feed/pretty_date');
elgg_register_js('pretty_date', $url);
$url = elgg_get_simplecache_url('js', 'ng_feed/activity_log');
elgg_register_simplecache_view('js/ng_feed/activity_log');
elgg_register_js('activity_log', $url);
$url = elgg_get_simplecache_url('js', 'ng_feed/auto_refresh');
elgg_register_simplecache_view('js/ng_feed/auto_refresh');
elgg_register_js('auto_refresh', $url);
$url = elgg_get_simplecache_url('css', 'feed');
elgg_register_simplecache_view('css/feed');
elgg_register_css('feed', $url);
/* register REST API for the feed */
elgg_ws_expose_function(
"get_feed",
"get_feed",
array(
'user_guid' => array('type' => 'string'),
'last_item_guid' => array('type' => 'string', 'required' => false),
),
'This function returns a feed items for the given user where the last item guid as recived',
'GET',
false,
false
);
elgg_ws_expose_function(
"fetch_new_items",
"fetch_new_items",
array(
'user_guid' => array('type' => 'string'),
'last_item_guid' => array('type' => 'string', 'required' => false),
),
'This function returns only new items if exists',
'GET',
false,
false
);
}
function get_feed($user_guid, $last_item_guid)
{
// This is just a mock :)
// There is no sense to the data only the structre
$result = array();
for ($i = $last_item_guid; $i < $last_item_guid + 5; $i++) {
$result[] = new Activity($i,
time() - 100 * $i,
'create',
'Tomer created comment on a post',
new ActivityItem($user_guid,
time() - 80 * $i,
'ElggUser',
'Tomer Kruvi',
'very cool guy! :)'
),
new ActivityItem('2222',
time() - 120 * $i,
'ElggUser',
'Someo nee lse',
'im someone else!'
),
new ActivityItem('3333',
time() - 60 * $i,
'ElggPost',
'the post title',
'this is super interesting post...'
)
);
}
return json_encode($result);
}
function fetch_new_items($user_guid, $last_item_guid)
{
// This is just a mock :)
// There is no sense to the data only the structre
$result = array();
for ($i = $last_item_guid; $i < $last_item_guid + 2; $i++) {
$result[] = new Activity($i,
time(),
'create',
'Tomer created comment on a post in a page',
new ActivityItem($user_guid,
time() - 100,
'ElggUser',
'Tomer Kruvi',
'very cool guy! :)'
),
new ActivityItem('4444',
time() - 50 * $i,
'ElggPage',
'SecertPageName',
'sheker sheker'
),
new ActivityItem('5555',
time() - 40 * $i,
'ElggPost',
'funny story!! thx!',
'this is super interesting post...'
)
);
}
return json_encode($result);
}