flash.moe/pages/index.php

294 lines
11 KiB
PHP
Raw Normal View History

2020-07-30 00:55:37 +00:00
<?php
2022-02-04 20:30:52 +00:00
namespace Makai;
2022-02-05 03:35:42 +00:00
$router->get('/about', mkiRedirect('/'));
$router->get('/about.html', mkiRedirect('/'));
$router->get('/about.php', mkiRedirect('/'));
$router->get('/index.php', mkiRedirect('/'));
$router->get('/index.html', mkiRedirect('/'));
2022-09-25 03:22:21 +00:00
$router->get('/related.php', mkiRedirect('/'));
$router->get('/related.html', mkiRedirect('/'));
$router->get('/friends', mkiRedirect('/'));
$router->get('/friends.php', mkiRedirect('/'));
$router->get('/friends.html', mkiRedirect('/'));
$router->get('/related', mkiRedirect('/'));
$router->get('/etc.php', mkiRedirect('/'));
$router->get('/etc.html', mkiRedirect('/'));
$router->get('/etcetera', mkiRedirect('/'));
$router->get('/etcetera.html', mkiRedirect('/'));
$router->get('/etcetera.php', mkiRedirect('/'));
$router->get('/misc', mkiRedirect('/'));
$router->get('/misc.html', mkiRedirect('/'));
$router->get('/misc.php', mkiRedirect('/'));
$router->get('/etc', mkiRedirect('/'));
2022-09-25 22:17:54 +00:00
$router->get('/365', mkiRedirect('/'));
2022-09-25 03:22:21 +00:00
$router->get('/donate', mkiRedirect('/'));
2022-09-25 22:17:54 +00:00
$router->get('/blog.php', mkiRedirect('/'));
$router->get('/blog-post.php', mkiRedirect('/'));
$router->get('/blog/:id', mkiRedirect('/'));
$router->get('/old-blog', mkiRedirect('/'));
$router->get('/old-blog/:id', mkiRedirect('/'));
2022-02-05 03:35:42 +00:00
$router->get('/header-bgs.json', function() {
return json_encode(FM_BGS);
});
$router->get('/now-listening', function() {
2020-07-30 00:55:37 +00:00
$offset = (int)filter_input(INPUT_GET, 'offset', FILTER_SANITIZE_NUMBER_INT);
2022-02-05 03:35:42 +00:00
$body = fm_component('header', [
2020-07-30 00:55:37 +00:00
'title' => 'flash.moe / now listening',
'do_fullscreen_header' => true,
'is_now_playing' => true,
2020-07-30 00:55:37 +00:00
'offset' => $offset,
]);
2022-02-05 03:35:42 +00:00
$body .= fm_component('footer', [
2020-07-30 00:55:37 +00:00
'hide' => true,
'onload' => [
['fm.initIndex', 10],
],
2020-07-30 00:55:37 +00:00
]);
2022-02-05 03:35:42 +00:00
return $body;
});
2020-07-30 00:55:37 +00:00
2022-02-05 03:35:42 +00:00
$router->get('/now-listening.json', function() {
$lfmInfo = cache_output('lastfm', 10, function() {
return json_decode(file_get_contents('https://now.flash.moe/get.php?u=flashwave_'));
});
2020-08-21 00:33:19 +00:00
2022-02-05 03:35:42 +00:00
if(empty($lfmInfo[0]->name))
return [];
$lfmInfo = $lfmInfo[0];
return [
'name' => strval($lfmInfo->name),
'now_playing' => !empty($lfmInfo->nowplaying),
'url' => strval($lfmInfo->url),
'cover' => !empty($lfmInfo->images->large) ? strval($lfmInfo->images->large) : '',
'artist' => [
'name' => !empty($lfmInfo->artist->name) ? strval($lfmInfo->artist->name) : '',
'url' => explode('/_/', strval($lfmInfo->url))[0],
],
];
});
2022-02-06 01:36:05 +00:00
$router->get('/np.php', function() {
header('Content-Type: text/xml');
return cache_output('lastfm-xml', 10, function() {
return file_get_contents('https://now.flash.moe/get.php?u=flashwave_&f=xml');
});
});
2022-02-05 03:35:42 +00:00
$router->get('/home', function() {
$body = fm_component('header', [
2020-08-21 00:33:19 +00:00
'title' => 'flash.moe / homepage',
'do_fullscreen_header' => true,
]);
2022-02-05 03:35:42 +00:00
$body .= <<<HTML
2020-08-21 00:33:19 +00:00
<div class="php">
<div class="php-time">
<div class="php-time-analog">
<div class="clock">
<div class="clock-background"></div>
<div class="clock-center"></div>
<div class="clock-hand clock-hand-hours"><div class="clock-hand-display"></div></div>
<div class="clock-hand clock-hand-minutes"><div class="clock-hand-display"></div></div>
<div class="clock-hand clock-hand-seconds"><div class="clock-hand-display"></div></div>
<div class="clock-number clock-number-3"><div class="clock-number-display"></div></div>
<div class="clock-number clock-number-6"><div class="clock-number-display"></div></div>
<div class="clock-number clock-number-9"><div class="clock-number-display"></div></div>
<div class="clock-number clock-number-12"><div class="clock-number-display"></div></div>
</div>
</div>
2020-09-08 21:09:02 +00:00
<div class="php-time-alter">
<div class="php-time-digital">
<div class="php-time-digital-hours">--</div>
<div class="php-time-digital-separator">:</div>
<div class="php-time-digital-minutes">--</div>
</div>
<div class="php-time-date">
<span class="php-date-label">Week</span>
<span class="php-date-week">--</span>
<span class="php-date-label">&nbsp;&mdash;&nbsp;</span>
<span class="php-date-year">----</span><span class="php-date-label">-</span><span class="php-date-month">---</span><span class="php-date-label">-</span><span class="php-date-day">--</span>
</div>
2020-08-21 00:33:19 +00:00
</div>
</div>
<form class="php-search" method="get" action="https://duckduckgo.com/">
<div class="php-search-input">
<input type="search" name="q" placeholder="Search using DuckDuckGo..."/>
</div>
</form>
</div>
2022-02-05 03:35:42 +00:00
HTML;
$body .= fm_component('footer', [
2020-08-21 00:33:19 +00:00
'hide' => true,
2020-10-25 22:11:05 +00:00
'skip_analytics' => true,
'onload' => [
['fm.initClock'],
['fm.initIndex', 10],
],
2020-08-21 00:33:19 +00:00
]);
2022-02-05 03:35:42 +00:00
return $body;
});
2022-02-04 04:25:57 +00:00
2022-02-05 03:35:42 +00:00
$router->get('/', function() use ($db) {
2022-02-04 20:30:52 +00:00
$legacyPage = (string)filter_input(INPUT_GET, 'p');
2020-07-30 00:55:37 +00:00
if(!empty($legacyPage)) {
$legacyPages = [
'projects' => '/projects',
'contact' => '/contact',
'about' => '/',
'etc' => '/etc',
'hosted' => '/etc',
'friends' => '/related',
];
2022-02-05 03:35:42 +00:00
2020-07-30 00:55:37 +00:00
if(isset($legacyPages[$legacyPage])) {
header('Location: ' . $legacyPages[$legacyPage]);
2022-02-05 03:35:42 +00:00
return 302;
2020-07-30 00:55:37 +00:00
}
}
2022-02-05 03:35:42 +00:00
$projects = (new Projects($db))->getFeatured();
$languages = new Languages($db);
2020-07-30 00:55:37 +00:00
$contact = [
[
'id' => 'email',
'name' => 'E-mail',
2020-08-19 01:20:25 +00:00
'icon' => 'fmi fmi-email',
2020-10-25 22:11:05 +00:00
'display' => 'contact@flash.moe',
'link' => 'mailto:contact@flash.moe',
2020-07-30 00:55:37 +00:00
],
[
'id' => 'flashii',
'name' => 'Flashii',
2020-08-19 01:20:25 +00:00
'icon' => 'fmi fmi-flashii',
2020-07-30 00:55:37 +00:00
'display' => 'flash',
'link' => '//flashii.net/profile.php?u=1',
],
[
'id' => 'twitter',
'name' => 'Twitter',
2020-08-19 01:20:25 +00:00
'icon' => 'fmi fmi-twitter',
2020-07-30 00:55:37 +00:00
'display' => '@smugwave',
'link' => '//twitter.com/smugwave',
],
];
2022-02-05 03:35:42 +00:00
$body = fm_component('header', [
2020-07-30 00:55:37 +00:00
'title' => 'flash.moe',
'is_index' => true,
]);
2022-02-05 03:35:42 +00:00
$body .= '<div class="index-menu">';
for($i = 1; $i < count(FM_NAV); ++$i) {
$link = FM_NAV[$i];
$body .= "<a href=\"{$link['link']}\"";
if($link['link'][0] === '/' && substr($link['link'], 0, 2) !== '//')
2022-09-25 23:04:03 +00:00
$body .= '';
2022-02-05 03:35:42 +00:00
$body .= ">{$link['title']}</a>";
}
$body .= <<<HTML
</div>
<div class="index-featured">
HTML;
$body .= <<<HTML
<div class="index-feature">
<div class="index-feature-header">
2022-09-25 23:04:03 +00:00
<a href="/projects" class="index-feature-header-link"></a>
2022-02-05 03:35:42 +00:00
<div class="index-feature-header-title">Projects</div>
<div class="index-feature-header-more">More</div>
</div>
HTML;
foreach($projects as $project) {
$links = [];
if($project->hasHomePageUrl())
$links[] = ['class' => 'homepage', 'text' => 'Homepage', 'url' => $project->getHomePageUrl()];
if($project->hasSourceUrl())
$links[] = ['class' => 'repository', 'text' => 'Source', 'url' => $project->getSourceUrl()];
if($project->hasDiscussionUrl())
$links[] = ['class' => 'forum', 'text' => 'Discussion', 'url' => $project->getDiscussionUrl()];
$colour = $project->hasColour() ? $project->getColour() : $languages->getProjectColour($project);
$colour = str_pad(dechex($colour), 6, '0', STR_PAD_LEFT);
$body .= <<<HTML
<div class="index-project" style="background-color: #{$colour};">
2022-09-25 23:04:03 +00:00
<a href="/projects#{$project->getCleanName()}" class="index-project-anchor"></a>
2022-02-05 03:35:42 +00:00
<div class="index-project-content">
<div class="index-project-name">{$project->getName()}</div>
HTML;
if($project->hasSummary())
$body .= "<div class=\"index-project-summary\">{$project->getSummary()}</div>";
$body .= '</div>';
if(!empty($links)) {
$body .= '<div class="index-project-links">';
foreach($links as $link)
$body .= "<a class=\"index-project-link index-project-link-{$link['class']}\" href=\"{$link['url']}\" rel=\"noopener\" target=\"_blank\">{$link['text']}</a>";
$body .= '</div>';
}
$body .= '</div>';
}
$body .= <<<HTML
</div>
<div class="index-feature">
<div class="index-feature-header">
2022-09-25 23:04:03 +00:00
<a href="/contact" class="index-feature-header-link"></a>
2022-02-05 03:35:42 +00:00
<div class="index-feature-header-title">Contact</div>
<div class="index-feature-header-more">More</div>
</div>
<div class="index-contact">
HTML;
foreach($contact as $social) {
$body .= "<div class=\"social social-{$social['id']}\">";
if(isset($social['link'])) {
$body .= "<a href=\"{$social['link']}\" class=\"social-background\" target=\"_blank\" rel=\"noopener\"></a>";
} else {
$body .= "<div class=\"social-background\" onclick=\"fm.selectTextInElement(this.parentNode.querySelector('.social-handle')); fm.copySelectedText();\"></div>";
}
$body .= <<<HTML
<div class="social-icon {$social['icon']}"></div>
<div class="social-content">
<div class="social-name">{$social['name']}</div>
<div class="social-handle">{$social['display']}</div>
</div>
</div>
HTML;
}
$body .= '</div></div></div>';
$body .= fm_component('footer', [
2020-07-30 00:55:37 +00:00
'is_index' => true,
'onload' => [
['fm.initIndex'],
],
2020-07-30 00:55:37 +00:00
]);
2022-02-05 03:35:42 +00:00
return $body;
});