diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/config.example.inc.php | 5 | ||||
-rw-r--r-- | inc/footer.inc.php | 5 | ||||
-rw-r--r-- | inc/header.inc.php (renamed from inc/head.html) | 2 | ||||
-rw-r--r-- | inc/lastfm.inc.php | 65 | ||||
-rw-r--r-- | inc/nav.inc.php (renamed from inc/nav.php) | 9 |
5 files changed, 79 insertions, 7 deletions
diff --git a/inc/config.example.inc.php b/inc/config.example.inc.php new file mode 100644 index 0000000..433a60d --- /dev/null +++ b/inc/config.example.inc.php @@ -0,0 +1,5 @@ +<?php +// Create a constant array with config variables +const CONF = array( + "lastfm_key" => "key" +); diff --git a/inc/footer.inc.php b/inc/footer.inc.php new file mode 100644 index 0000000..59babfc --- /dev/null +++ b/inc/footer.inc.php @@ -0,0 +1,5 @@ +<hr> + <div style="text-align: center;"> + <img src="/res/img/buttons/browser.gif" alt="Any Damn Browser"> <a href="https://www.linux.org/"><img src="/res/img/buttons/linuxnow.gif" alt="Linux NOW!"></a> <a href="https://www.vim.org/"><img src="/res/img/buttons/vim.gif" alt="vim"></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img style="border:0;width:88px;height:31px" src="/res/img/buttons/vcss-blue.gif" alt="Valid CSS!"></a> <a href=""><img style="border:0;width:88px;height:31px" src="/res/img/buttons/valid-html401-blue.png" alt="Valid HTML 4.01!"></a><br> + Last Modified <span class="date"><?=date('Y-m-d H:i:s', filemtime($file) + 3600);?> GMT</span> + </div> diff --git a/inc/head.html b/inc/header.inc.php index 93953e9..f891dca 100644 --- a/inc/head.html +++ b/inc/header.inc.php @@ -1,4 +1,6 @@ <meta charset="utf-8"> <meta property="og:type" content="website"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta name="theme-color" content="#333333"> <link rel="stylesheet" id="theme" href="/res/css/dark.css" type="text/css"> + <script defer data-domain="diskfloppy.me" src="https://analytics.nickandfloppy.com/js/plausible.js"></script> diff --git a/inc/lastfm.inc.php b/inc/lastfm.inc.php new file mode 100644 index 0000000..b7bbde4 --- /dev/null +++ b/inc/lastfm.inc.php @@ -0,0 +1,65 @@ +<h1>Last.fm <small><a href="https://www.last.fm/user/floppydisk_">Profile</a></small></h1> +<?php +require('inc/config.inc.php'); + +$curl_current = curl_init(); + +curl_setopt_array($curl_current, [ + CURLOPT_URL => "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=".CONF['lastfm_user']."&nowplaying=true&format=json&api_key=".CONF['lastfm_key'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "GET", +]); + +$current_response = curl_exec($curl_current); +$err = curl_error($curl_current); + +curl_close($curl_current); + +if ($err) { + die("cURL Error #:" . $err); +} +$current_response = json_decode($current_response, true); +$nowplaying = $current_response['recenttracks']['track'][0]; + +echo ' <b>Last/Current Track:</b> <a href="'.$nowplaying['url'].'">'.$nowplaying['name'].' • '.$nowplaying['artist']['#text'].'</a>'.PHP_EOL; + +$tracks_to_show = 10; + +$curl = curl_init(); + +curl_setopt_array($curl, [ + CURLOPT_URL => "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=".CONF['lastfm_user']."&format=json&period=7day&api_key=".CONF['lastfm_key'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "GET", +]); + +$toptracks_response = curl_exec($curl); +$err = curl_error($curl); + +curl_close($curl); + +if ($err) { + die("cURL Error #:" . $err); +} +echo ' <h2>Top '.$tracks_to_show.' Tracks (Last 7 days)</h2>'.PHP_EOL; +echo ' <ol>'.PHP_EOL; +$toptracks_response = json_decode($toptracks_response, true); +$tracks = $toptracks_response['toptracks']['track']; +$count = 0; +foreach ($tracks as $track) { + echo ' <li>'.PHP_EOL; + echo ' <a href="'.$track['url'].'">'.$track['name'].' • '.$track['artist']['name'].'</a>'.PHP_EOL; + echo ' <small>('.$track['playcount'].' plays)</small>'.PHP_EOL; + echo ' </li>'.PHP_EOL; + if ($count >= $tracks_to_show - 1) break; + $count++; +} +echo ' </ol>';
\ No newline at end of file diff --git a/inc/nav.php b/inc/nav.inc.php index 3f14fff..e75445c 100644 --- a/inc/nav.php +++ b/inc/nav.inc.php @@ -1,16 +1,12 @@ -<script lang="javascript" src="/res/js/themeswap.js"></script> <div class="header"> <nav> <div> - <!--<a href="/me/">about</a> | <a href="/projects/">projects</a> | - <a href="/pics/">pics</a> |--> - <a href="/dog/">dog</a> | <a href="https://github.com/floppydisk05?tab=repositories">repos</a> | <a href="/calculators/">calculators</a> | <a href="/computers/">computers</a> | <a href="/bookmarks/">bookmarks</a> | - <a href="https://blog.diskfloppy.me/">blog</a> + <a href="/guestbook/">guestbook</a> </div> </nav> <div class="pagetree"> @@ -39,6 +35,5 @@ ?> </span> - <div style="float: right;"><a onclick="javascript:toggleTheme()">dark / light mode</a></div> - </div> + </div> <!-- pagetree --> </div> <!-- header -->
\ No newline at end of file |