forked from Kliqqi-CMS/Kliqqi-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
live2.php
198 lines (179 loc) · 7.35 KB
/
live2.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
include_once('internal/Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'link.php');
if(!Enable_Live) {
header("Location: $my_pligg_base/error_404.php");
die();
}
// number of items to show on the page
$max_items = items_to_show;
if(!($time=check_integer('time'))) {
$time = 0;
}
header('Content-Type: text/plain; charset=UTF-8');
$last_timestamp = 0;
// always check groups (to hide private groups)
$from = " LEFT JOIN ".table_groups." ON ".table_links.".link_group_id = ".table_groups.".group_id ";
$groups = $db->get_results("SELECT * FROM " . table_group_member . " WHERE member_user_id = {$current_user->user_id} and member_status = 'active'");
if($groups)
{
$group_ids = array();
foreach($groups as $group)
$group_ids[] = $group->member_group_id;
$group_list = join(",",$group_ids);
$where = " AND (".table_groups.".group_privacy!='private' OR ISNULL(".table_groups.".group_privacy) OR ".table_groups.".group_id IN($group_list)) ";
}
else
{
$group_list = '';
$where = " AND (".table_groups.".group_privacy!='private' OR ISNULL(".table_groups.".group_privacy))";
}
get_votes($time);
get_new_stories($time);
get_new_published($time);
get_comments($time);
if($last_timestamp == 0) $last_timestamp = time();
echo "timestamp=$last_timestamp;\n";
if(count($events) < 1) exit;
ksort($events);
$keys = array_reverse(array_keys($events));
$lines = min(count($keys), $max_items);
$counter=0;
echo "new_items=$lines;\n";
echo "new_data = ([";
foreach ($keys as $key) {
echo "{" . $events[$key] . "}, ";
$counter++;
if($counter>=$max_items) {
echo "]);";
exit();
}
}
echo "]);";
// get latest votes
function get_votes($time) {
global $db, $events, $last_timestamp;
$res = $db->get_results("SELECT *, unix_timestamp(vote_date) as timestamp
FROM " . table_votes . ", " . table_links . "
WHERE vote_date > FROM_UNIXTIME($time) AND link_id = vote_link_id AND vote_user_id != link_author AND (link_status='published' OR link_status='new') AND vote_type = 'links'
ORDER BY vote_date DESC
LIMIT 20");
if (!$res) return;
foreach ($res as $event) {
if(substr($event->vote_ip, 0, 3) != '0.0'){
$id=$event->vote_id;
$uid = $event->vote_user_id;
if($uid > 0) {
$user = $db->get_var("select user_login from " . table_users . " where user_id = $uid");
} else {
$user= preg_replace('/\.[0-9]+$/', '', $event->vote_ip);
}
if ($event->vote_value < 0) {
$type = 'Down Vote';
$who = $user;
} elseif ($event->vote_value >= 0) {
$type = 'Up Vote';
$who = $user;
} else {
$type = 'Problem';
$who = $event->vote_value;
}
$status = get_status($event->link_status);
$key = $event->timestamp . ':votes:'.$id;
if (Voting_Method == 2) {
$votes = $event->link_votes/2;
} else {
$votes = $event->link_votes;
}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp > $last_timestamp) $last_timestamp = $event->timestamp;
}
}
}
// get latest stories
function get_new_stories($time) {
global $db, $events, $last_timestamp, $from, $where;
$res = $db->get_results("select unix_timestamp(link_date) as timestamp, user_login, link_author, link_id, link_title, link_url, link_status, link_date, link_votes
from " . table_links . "
LEFT JOIN " . table_users . " ON user_id=link_author
$from
where link_status='new' and link_date > from_unixtime($time)
$where
order by link_date desc limit 20");
if (!$res) return;
foreach ($res as $event) {
$id=$event->link_id;
$uid = $event->link_author;
$type = 'Submission';
$who = $event->user_login;
$status = get_status($event->link_status);
$key = $event->timestamp . ':new:'.$id;
if(Voting_Method == 2){$votes = $event->link_votes/2;}
else {$votes = $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp > $last_timestamp) $last_timestamp = $event->timestamp;
}
}
// get latest published stories
function get_new_published($time) {
global $db, $events, $last_timestamp,$from, $where;;
$res = $db->get_results("select unix_timestamp(link_published_date) as timestamp, user_login, link_author, link_id, link_title, link_url, link_status, link_date, link_votes
from " . table_links . "
LEFT JOIN " . table_users . " ON user_id=link_author
$from
where link_status='published' and link_published_date > from_unixtime($time)
$where
order by link_published_date desc, link_date DESC limit 20");
if (!$res) return;
foreach ($res as $event) {
$id=$event->link_id;
$uid = $event->link_author;
$type = 'Published';
$who = $event->user_login;
$status = get_status($event->link_status);
$key = $event->timestamp . ':published:'.$id;
if(Voting_Method == 2){$votes = $event->link_votes/2;}
else {$votes = $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp > $last_timestamp) $last_timestamp = $event->timestamp;
}
}
// get latest comments
function get_comments($time) {
global $db, $events, $last_timestamp;
$res = $db->get_results("select comment_id, unix_timestamp(comment_date) as timestamp, user_login, comment_user_id, link_author, link_id, link_title, link_url, link_status, link_date, link_published_date, link_votes from " . table_comments . ", " . table_links . ", " . table_users . " where comment_status='published' AND comment_date > from_unixtime($time) and link_id = comment_link_id and (link_status='published' OR link_status='new') and user_id=comment_user_id order by comment_date desc limit 20");
if (!$res) return;
foreach ($res as $event) {
$id=$event->comment_id;
$uid=$event->comment_user_id;
$type = 'Comment';
$who = $event->user_login;
$status = get_status($event->link_status);
$key = $event->timestamp . ':comment:'.$id;
if(Voting_Method == 2){$votes = $event->link_votes/2;}
else {$votes = $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp > $last_timestamp) $last_timestamp = $event->timestamp;
}
}
function get_status($status) {
switch ($status) {
case 'published':
$status = _('Published');
break;
case 'new':
$status = _('New');
break;
case 'discard':
$status = _('Discarded');
break;
}
return $status;
}
?>