-
Notifications
You must be signed in to change notification settings - Fork 38
/
post_best_comment.php
executable file
·87 lines (65 loc) · 2.24 KB
/
post_best_comment.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
#! /usr/bin/env php
<?php
// Check which hostname server we run for, for example: mnm, emnm, etc.
$site_name = $argv[2];
include(__DIR__.'/../www/config.php');
include(mnminclude.'external_post.php');
$my_id = SitesMgr::get_id($site_name);
if (! $my_id > 0) {
syslog(LOG_INFO, "Meneame, ".basename(__FILE__)." site not found $site_name");
echo "No site id found\n";
die;
}
SitesMgr::__init($my_id);
syslog(LOG_INFO, "Meneame, running ".basename(__FILE__)." for $site_name");
$info = SitesMgr::get_info();
$properties = SitesMgr::get_extended_properties();
if (intval($argv[1]) > 0) {
$hours = intval($argv[1]);
} else {
$hours = 1;
}
$key = "post_best_comment_$my_id";
$previous = Annotation::get_text($key);
if ($previous) {
$extra = "AND comment_id not in ($previous)";
}
$now = intval(time()/60) * 60;
$coef = 0.8;
$min_karma = $globals['comment_highlight_karma'] * 2;
$min_value = $globals['comment_highlight_karma'];
$min_length = 400;
$sql_value = "comment_karma*(1-($now-unix_timestamp(comment_date))*$coef/($hours*3600)) as value";
$where_value = "comment_karma*(1-($now-unix_timestamp(comment_date))*$coef/($hours*3600)) > $min_value";
$sql = "select comment_id, karma, $sql_value from comments, sub_statuses where id = $my_id AND status in ('published') AND comment_date > date_sub(now(), interval $hours hour) and LENGTH(comment_content) > $min_length and comment_karma > $min_karma AND $where_value AND comment_link_id = link $extra order by value desc limit 1";
$res = $db->get_row($sql);
if (! $res) {
exit(0);
}
$comment = Comment::from_db($res->comment_id);
if (! $comment) {
exit(2);
}
$image = false;
if ($comment->media_size > 0) {
$media = new Upload('comment', $comment->id);
if ($media->read()) {
$image = $media->pathname();
$maxlen -= 24;
}
}
$url = $globals[scheme].'//'.get_server_name().$comment->get_relative_individual_permalink();
syslog(LOG_INFO, "Meneame, posting comment $url");
// Store in cache
if ($previous) {
$ids = explode(',',$previous);
if (count($ids) > 10) {
array_shift($ids);
}
} else {
$ids = array();
}
$ids[] = $comment->id;
$previous = implode(',', $ids);
Annotation::store_text($key, $previous, time() + 86400);
twitter_post($properties, '💬 '.$comment->content, $url, $image);