ajax aoc panel (main site)
This commit is contained in:
parent
c12b217b37
commit
a6539cf081
16
www/commands/html_panel-aoc-calendar.php
Normal file
16
www/commands/html_panel-aoc-calendar.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once (__DIR__ . '/../internals/base.php');
|
||||||
|
require_once (__DIR__ . '/../internals/adventofcode.php');
|
||||||
|
|
||||||
|
global $PARAM_AOCCALENDAR;
|
||||||
|
$PARAM_AOCCALENDAR =
|
||||||
|
[
|
||||||
|
'year' => intval($_GET['year']),
|
||||||
|
'nav' => boolval($_GET['nav']),
|
||||||
|
'linkheader' => boolval($_GET['linkheader']),
|
||||||
|
'ajax' => boolval($_GET['ajax']),
|
||||||
|
'frame' => false,
|
||||||
|
'frameid' => strval($_GET['frameid']),
|
||||||
|
];
|
||||||
|
require (__DIR__ . '/../fragments/panel_aoc_calendar.php');
|
@ -1180,6 +1180,12 @@ html, body {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.aoc_calendar_header_title a {
|
||||||
|
color: #000000;
|
||||||
|
font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
.aoc_calendar_header_link.aoc_prev {
|
.aoc_calendar_header_link.aoc_prev {
|
||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
padding-left: 0.5em;
|
padding-left: 0.5em;
|
||||||
|
1
www/data/css/styles.min.css
vendored
1
www/data/css/styles.min.css
vendored
@ -227,6 +227,7 @@ html,body{margin:0;padding:0;height:100%}
|
|||||||
.aoc_calendar_header{display:flex;flex-direction:row;justify-content:space-between;margin-bottom:.5em;background:#888}
|
.aoc_calendar_header{display:flex;flex-direction:row;justify-content:space-between;margin-bottom:.5em;background:#888}
|
||||||
.aoc_calendar_header_link{display:flex;color:#000;text-decoration:none}
|
.aoc_calendar_header_link{display:flex;color:#000;text-decoration:none}
|
||||||
.aoc_calendar_header_title{flex-grow:0;display:flex;color:#000;font-family:Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:bold}
|
.aoc_calendar_header_title{flex-grow:0;display:flex;color:#000;font-family:Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:bold}
|
||||||
|
.aoc_calendar_header_title a{color:#000;font-family:Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;text-decoration:none}
|
||||||
.aoc_calendar_header_link.aoc_prev{flex-grow:0;padding-left:.5em}
|
.aoc_calendar_header_link.aoc_prev{flex-grow:0;padding-left:.5em}
|
||||||
.aoc_calendar_header_link.aoc_next{flex-grow:0;padding-right:.5em}
|
.aoc_calendar_header_link.aoc_next{flex-grow:0;padding-right:.5em}
|
||||||
.aoc_calendar_header_link.aoc_link_hidden{visibility:hidden}
|
.aoc_calendar_header_link.aoc_link_hidden{visibility:hidden}
|
||||||
|
@ -36,6 +36,12 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.aoc_calendar_header_title a {
|
||||||
|
color: $LAYER2_HEADER_FG;
|
||||||
|
font-family: $FONT_HEADER;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
.aoc_calendar_header_link.aoc_prev {
|
.aoc_calendar_header_link.aoc_prev {
|
||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
padding-left: 0.5em;
|
padding-left: 0.5em;
|
||||||
|
12
www/data/javascript/aoc_panel_interactive.js
Normal file
12
www/data/javascript/aoc_panel_interactive.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
function changeAOCPanel(year, shownav, linkheader, ajax, frameid)
|
||||||
|
{
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', '/api/html::panel_aoc_calendar?year='+year+'&nav='+shownav+'&linkheader='+linkheader+'&ajax='+ajax+'&frameid='+frameid);
|
||||||
|
xhr.onload = function()
|
||||||
|
{
|
||||||
|
if (xhr.status === 200) document.getElementById(frameid).innerHTML = xhr.responseText;
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
@ -26,7 +26,7 @@ $year = $post['extras']['aoc:year'];
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
global $PARAM_AOCCALENDAR;
|
global $PARAM_AOCCALENDAR;
|
||||||
$PARAM_AOCCALENDAR = ['year' => $year, 'nav'=>true];
|
$PARAM_AOCCALENDAR = ['year' => $year, 'nav'=>true, 'linkheader'=>false, 'ajax'=>false];
|
||||||
require (__DIR__ . '/../fragments/panel_aoc_calendar.php')
|
require (__DIR__ . '/../fragments/panel_aoc_calendar.php')
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once(__DIR__ . '/../internals/adventofcode.php');
|
require_once(__DIR__ . '/../internals/adventofcode.php');
|
||||||
|
|
||||||
global $PARAM_AOCPANEL;
|
$years = AdventOfCode::listYears();
|
||||||
$year = $PARAM_AOCPANEL['year'];
|
$year = end($years);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="index_pnl_base">
|
<div class="index_pnl_base">
|
||||||
|
|
||||||
<div class="index_pnl_header">
|
<div class="index_pnl_header">
|
||||||
<a href="<?php echo AdventOfCode::getURLForYear($year); ?>">Advent of Code <?php echo $year; ?></a>
|
<a href="<?php echo AdventOfCode::getURLForYear($year); ?>">Advent of Code</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="index_pnl_content">
|
<div class="index_pnl_content">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
global $PARAM_AOCCALENDAR;
|
global $PARAM_AOCCALENDAR;
|
||||||
$PARAM_AOCCALENDAR = ['year' => $year, 'nav'=>false];
|
$PARAM_AOCCALENDAR = ['year' => $year, 'nav'=>true, 'linkheader'=>true, 'ajax'=>true];
|
||||||
require (__DIR__ . '/../fragments/panel_aoc_calendar.php')
|
require (__DIR__ . '/../fragments/panel_aoc_calendar.php')
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -4,24 +4,49 @@ global $PARAM_AOCCALENDAR;
|
|||||||
|
|
||||||
$year = $PARAM_AOCCALENDAR['year'];
|
$year = $PARAM_AOCCALENDAR['year'];
|
||||||
$shownav = $PARAM_AOCCALENDAR['nav'];
|
$shownav = $PARAM_AOCCALENDAR['nav'];
|
||||||
|
$linkheader = $PARAM_AOCCALENDAR['linkheader'];
|
||||||
|
$ajax = $PARAM_AOCCALENDAR['ajax'];
|
||||||
|
$frame = isset($PARAM_AOCCALENDAR['frame']) ? $PARAM_AOCCALENDAR['frame'] : true;
|
||||||
|
$frameid = isset($PARAM_AOCCALENDAR['frameid']) ? $PARAM_AOCCALENDAR['frameid'] : ('aoc_frame_' . getRandomToken(16));
|
||||||
|
|
||||||
$assocdays = AdventOfCode::listSingleYearAssociative($year);
|
$assocdays = AdventOfCode::listSingleYearAssociative($year);
|
||||||
$prev_year = $shownav ? AdventOfCode::getPrevYear($year) : null;
|
$prev_year = $shownav ? AdventOfCode::getPrevYear($year) : null;
|
||||||
$next_year = $shownav ? AdventOfCode::getNextYear($year) : null;
|
$next_year = $shownav ? AdventOfCode::getNextYear($year) : null;
|
||||||
|
|
||||||
|
if ($ajax) includeAdditionalScript("/data/javascript/aoc_panel_interactive.js", 'defer', true);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="aoc_calendar_parent">
|
<?php if ($frame) echo '<div class="aoc_calendar_parent" id="' . $frameid . '">'; ?>
|
||||||
<div class="aoc_calendar">
|
<div class="aoc_calendar">
|
||||||
<div class="aoc_calendar_header">
|
<div class="aoc_calendar_header">
|
||||||
<?php
|
<?php
|
||||||
if ($prev_year !== null) echo '<a href="' . AdventOfCode::getURLForYear($prev_year) . '" class="aoc_calendar_header_link aoc_prev" ><</a>';
|
if ($prev_year !== null)
|
||||||
else echo '<a href="#" class="aoc_calendar_header_link aoc_prev aoc_link_hidden" ><</a>';
|
{
|
||||||
|
if ($ajax)
|
||||||
|
echo '<a href="javascript:void();" onclick="javascript:changeAOCPanel(' . $prev_year . ', ' . ($shownav?'true':'false') . ', ' . ($linkheader?'true':'false') . ', ' . ($ajax?'true':'false') . ', \'' . $frameid . '\')" class="aoc_calendar_header_link aoc_prev" ><</a>';
|
||||||
|
else
|
||||||
|
echo '<a href="' . AdventOfCode::getURLForYear($prev_year) . '" class="aoc_calendar_header_link aoc_prev" ><</a>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo '<a href="#" class="aoc_calendar_header_link aoc_prev aoc_link_hidden" ><</a>';
|
||||||
|
}
|
||||||
|
|
||||||
echo '<span class="aoc_calendar_header_title">'.$year.'</span>';
|
if ($linkheader) echo '<span class="aoc_calendar_header_title"><a href="' . AdventOfCode::getURLForYear($year) . '">'.$year.'</a></span>';
|
||||||
|
else echo '<span class="aoc_calendar_header_title">'.$year.'</span>';
|
||||||
|
|
||||||
if ($next_year !== null) echo '<a href="' . AdventOfCode::getURLForYear($next_year) . '" class="aoc_calendar_header_link aoc_next" >></a>';
|
if ($next_year !== null)
|
||||||
else echo '<a href="" class="aoc_calendar_header_link aoc_next aoc_link_hidden" >></a>';
|
{
|
||||||
|
if ($ajax)
|
||||||
|
echo '<a href="javascript:void();" onclick="javascript:changeAOCPanel(' . $next_year . ', ' . ($shownav?'true':'false') . ', ' . ($linkheader?'true':'false') . ', ' . ($ajax?'true':'false') . ', \'' . $frameid . '\')" class="aoc_calendar_header_link aoc_next" >></a>';
|
||||||
|
else
|
||||||
|
echo '<a href="' . AdventOfCode::getURLForYear($next_year) . '" class="aoc_calendar_header_link aoc_next" >></a>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo '<a href="" class="aoc_calendar_header_link aoc_next aoc_link_hidden" >></a>';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -39,4 +64,4 @@ $next_year = $shownav ? AdventOfCode::getNextYear($year) : null;
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<?php if ($frame) echo '</div>'; ?>
|
||||||
|
@ -405,3 +405,18 @@ function get_client_ip() {
|
|||||||
else if(isset($_SERVER['REMOTE_ADDR'])) return $_SERVER['REMOTE_ADDR'];
|
else if(isset($_SERVER['REMOTE_ADDR'])) return $_SERVER['REMOTE_ADDR'];
|
||||||
else return 'UNKNOWN';
|
else return 'UNKNOWN';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRandomToken($length = 32)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(!isset($length) || intval($length) <= 8 ) $length = 32;
|
||||||
|
|
||||||
|
if (function_exists('random_bytes')) return bin2hex(random_bytes($length));
|
||||||
|
if (function_exists('mcrypt_create_iv')) return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
|
||||||
|
if (function_exists('openssl_random_pseudo_bytes')) return bin2hex(openssl_random_pseudo_bytes($length));
|
||||||
|
}
|
||||||
|
catch (Exception $e) { throw new InvalidArgumentException($e); }
|
||||||
|
|
||||||
|
throw new InvalidArgumentException("No random");
|
||||||
|
}
|
@ -25,6 +25,8 @@ $API_COMMANDS =
|
|||||||
'alephnote::show' => [ 'src' => __DIR__.'/../commands/alephnote_show.php', 'auth' => 'ajax_secret' ],
|
'alephnote::show' => [ 'src' => __DIR__.'/../commands/alephnote_show.php', 'auth' => 'ajax_secret' ],
|
||||||
|
|
||||||
'updates::show' => [ 'src' => __DIR__.'/../commands/updates_show.php', 'auth' => 'ajax_secret' ],
|
'updates::show' => [ 'src' => __DIR__.'/../commands/updates_show.php', 'auth' => 'ajax_secret' ],
|
||||||
|
|
||||||
|
'html::panel_aoc_calendar' => [ 'src' => __DIR__.'/../commands/html_panel-aoc-calendar.php', 'auth' => 'none' ],
|
||||||
];
|
];
|
||||||
|
|
||||||
$cmd = strtolower($OPTIONS['cmd']);
|
$cmd = strtolower($OPTIONS['cmd']);
|
||||||
@ -91,7 +93,7 @@ catch (exception $e)
|
|||||||
"IP: " . get_client_ip() . "\r\n\r\n" .
|
"IP: " . get_client_ip() . "\r\n\r\n" .
|
||||||
"ERROR: " . $e . "\r\n\r\n";
|
"ERROR: " . $e . "\r\n\r\n";
|
||||||
|
|
||||||
sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
|
if (isProd()) sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com');
|
||||||
|
|
||||||
httpDie(500, 'Error.');
|
httpDie(500, 'Error.');
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,7 @@
|
|||||||
|
|
||||||
<?php include (__DIR__ . '/../fragments/panel_books.php'); ?>
|
<?php include (__DIR__ . '/../fragments/panel_books.php'); ?>
|
||||||
|
|
||||||
<?php /* global $PARAM_AOCPANEL; $PARAM_AOCPANEL=['year'=>2018]; include (__DIR__ . '/../fragments/panel_aoc.php'); */ ?>
|
<?php include (__DIR__ . '/../fragments/panel_aoc.php'); ?>
|
||||||
<?php global $PARAM_AOCPANEL; $PARAM_AOCPANEL=['year'=>2019]; include (__DIR__ . '/../fragments/panel_aoc.php'); ?>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user