-
Notifications
You must be signed in to change notification settings - Fork 0
/
Json.php
52 lines (37 loc) · 1.37 KB
/
Json.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
<?php namespace components\message_board; if(!defined('TX')) die('No direct access.');
use \components\message_board\classes\FeedReader;
class Json extends \dependencies\BaseComponent
{
protected $permissions = array(
'get_feed_messages' => 0,
'get_feed_sources' => 0
);
public function get_feed_sources($options, $sub_routes)
{
//No reason we can't do this in parallel.
mk('Session')->close();
return mk('Sql')->table('message_board', 'FeedSources')
->where('feed_id', $sub_routes->{0})
->execute();
}
public function get_feed_messages($options, $sub_routes)
{
/*
Note:
The session is preserved here.
Because if an update is required, one user can perform many parallel requests that each trigger the update.
This would potentially be a DOS attack as it fires many CURL requests.
*/
#TODO: To mitigate a DDOS-attack against feeds that need to update, mark a feeds' state as 'IDLE' or 'UPDATING' in the database.
$reader = new FeedReader($sub_routes->{0});
$messages = $reader->fetch(true, $options);
//Include custom getter stuff.
foreach($messages as $message){
$message->webpages;
$message->images->each(function($image){
$image->url->set((string)$image->generate_url());
});
}
return $messages;
}
}