More work on polls and themes

This commit is contained in:
Daisuke
2020-04-21 17:42:31 -05:00
parent d34a7c7ced
commit f59049c3c2
18 changed files with 281 additions and 103 deletions

View File

@ -67,6 +67,7 @@ function emojify($string, $emojis, $size = 40) {
function emoji_list($val){
$emojilist = api_get("/custom_emojis");
$c = 0;
$return = "";
foreach ($emojilist as $emoji){
if (starts_with($emoji['shortcode'],$val) && $c < 50){
$return .= "<img style='margin:1px;' src='".$emoji['static_url']."' class='emoji' title='".$emoji['shortcode']."' height=40>";
@ -283,7 +284,7 @@ function render_reply($item) {
$unlisted = "&#xe816;";
$direct = "&#xf0e0;";
$reply['date'] = "<a style='text-decoration:none;color:darkgray;' target='_blank' href='" . $item['url'] . "'><span class='fontello'>&#xe817;</span></a> - <a class='ldr' style='text-decoration:none;color:darkgray;' target='_blank' href='?thread=" . $item['id'] . "&instance=$srv" . "'>" . date("d/m/y H:i", strtotime($item['created_at'])) . "</a> - <span class='fontello' style='color:darkgray;'>" . $$item['visibility'] . "</span>";
$reply['date'] = "<a class='ldr' style='text-decoration:none;' target='_blank' href='?thread=" . $item['id'] . "&instance=$srv" . "'>" . time_elapsed_string($item['created_at']) . "</a> - <span class='fontello'>" . $$item['visibility'] . "</span>";
$reply['media'] = "";
if (!empty($item['media_attachments'])) {
@ -720,23 +721,23 @@ function timeline($query) {
switch ($query['mode']) {
case "home":
$array = api_get("timelines/home?limit=25{$media}{$next}");
$array = api_get("timelines/home?limit=30{$media}{$next}");
break;
case "federated":
$array = api_get("timelines/public?limit=25{$media}{$next}");
$array = api_get("timelines/public?limit=30{$media}{$next}");
break;
case "tag":
$array = api_get("timelines/tag/" . $query['tag'] . "?limit=25{$media}{$next}");
$array = api_get("timelines/tag/" . $query['tag'] . "?limit=30{$media}{$next}");
break;
case "local":
$array = api_get("timelines/public?limit=25&local=true{$media}{$next}");
$array = api_get("timelines/public?limit=30&local=true{$media}{$next}");
break;
case "user":
$array = api_get("accounts/" . $query['user'] . "/statuses?limit=25{$media}{$next}");
$array = api_get("accounts/" . $query['user'] . "/statuses?limit=30{$media}{$next}");
break;
case "thread":
@ -746,19 +747,19 @@ function timeline($query) {
break;
case "favourites":
$array = api_get("favourites?limit=25{$media}{$next}");
$array = api_get("favourites?limit=30{$media}{$next}");
break;
case "direct":
$array = api_get("timelines/direct?limit=25{$next}");
$array = api_get("timelines/direct?limit=30{$next}");
break;
case "list":
$array = api_get("timelines/list/" . $query['list'] . "?limit=25{$next}");
$array = api_get("timelines/list/" . $query['list'] . "?limit=30{$next}");
break;
case "bookmarks":
$array = api_get("bookmarks?limit=25{$next}");
$array = api_get("bookmarks?limit=30{$next}");
break;
case "search":
@ -767,11 +768,11 @@ function timeline($query) {
case "account":
$info = api_get("accounts/verify_credentials");
$array = api_get("accounts/" . $info['id'] . "/statuses?limit=25{$media}{$next}");
$array = api_get("accounts/" . $info['id'] . "/statuses?limit=30{$media}{$next}");
break;
default:
$array = api_get("timelines/public?limit=25{$media}{$next}");
$array = api_get("timelines/public?limit=30{$media}{$next}");
break;
}
@ -781,7 +782,7 @@ function timeline($query) {
$next = end($array) ['id'];
$thread = array();
/*
foreach ($array as $elem) {
if ($query['replies'] == "on" || $query['mode'] == "thread") {
$thread[] = $elem;
@ -792,12 +793,26 @@ function timeline($query) {
}
}
}*/
foreach ($array as $elem) {
if ($query['replies'] == "on" || $query['mode'] == "thread") {
$thread[] = $elem;
}
else {
if ($elem['in_reply_to_id'] == null) {
$thread[] = $elem;
} else {
$rel = api_get("accounts/relationships?id=" . $elem['in_reply_to_account_id']);
if ($rel[0]['following']){
$thread[] = $elem;
}
}
}
}
return array(
$thread,
$next
);
return $thread;
}
/* this function takes in a whole post entity and spits out the HTMLfied text of the post
@ -896,3 +911,32 @@ function themes($mode,$name = false){
}
}
}
function time_elapsed_string($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}