Skip to content

Commit

Permalink
Add short listing for my Now page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirthe Valentijn committed Feb 13, 2024
1 parent 44021ac commit b151133
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirthe/kirby_mylastfm",
"version": "1.0",
"version": "1.1.0",
"description": "Show recently played tracks and albums for a LastFM account",
"homepage": "https://github.com/mirthe/kirby_mylastfm",
"keywords": ["kirby-plugin", "lastfm", "music", "history", "log"],
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'snippets' => [
'lastfm-albums-played' => __DIR__ . '/snippets/albums.php',
'lastfm-recenttracks' => __DIR__ . '/snippets/tracks.php',
'lastfm-recenttracks-short' => __DIR__ . '/snippets/tracks-list.php',
'lastfm-topartists' => __DIR__ . '/snippets/artists.php'

// getTopArtists toevoegen?
Expand Down
19 changes: 19 additions & 0 deletions snippets/ago.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
date_default_timezone_set('Europe/Amsterdam');
function timeago($time, $tense = "ago"){
if(empty($time)) return "n/a";
$time=strtotime($time);
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] $tense ";
}
?>
19 changes: 19 additions & 0 deletions snippets/tracks-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php include('gettracks.php');
include('ago.php'); ?>

<dl class="tracks-list">
<?php $counter = 0;
foreach($rss->recenttracks->track as $item):
if ($counter == $limit) {break;} ?>
<dt>
<a href="<?= $item->url ?>"><?= $item->name ?></a>
<small class="subtiel">
<?= timeago(date("d-m-Y H:i", intval($item->date['uts']))) ?>
</small>
</dt>
<dd>
<?= $item->artist ?> - <?= $item->album ?>
</dd>
<?php $counter++;
endforeach ?>
</dl>
22 changes: 2 additions & 20 deletions snippets/tracks.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
<?php include('gettracks.php');
date_default_timezone_set('Europe/Amsterdam');

function timeago($time, $tense = "ago"){
if(empty($time)) return "n/a";
$time=strtotime($time);
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] $tense ";
}
?>
<?php include('gettracks.php');
include('ago.php'); ?>

<div class="masonry masonry--small">
<?php foreach($rss->recenttracks->track as $item): ?>
Expand Down

0 comments on commit b151133

Please sign in to comment.