php version <?php $url = "https://alcea-wisteria.de/artbackup/"; $html = file_get_contents($url); //$pattern = '/<tr>(.*?)<\/tr>/s'; //timestamp based $pattern = '/<td data-sort="([^"]*)"/'; //filename based preg_match_all($pattern, $html, $matches); $dates = array(); $urls = array(); foreach ($matches[0] as $match) { preg_match('/\d{4}-\d{2}-\d{2}/', $match, $date); if (!empty($date)) { $dates[] = $date[0]; $urls[] = $date[0]; // Append the date to the URL } } $newestIndex = array_search(max($dates), $dates); $newestUrl = $urls[$newestIndex]; // Weekly counts $weekCounts = array(); foreach ($dates as $date) { $weekYear = date('o-\WW', strtotime($date)); // Extract the year and week number if (isset($weekCounts[$weekYear])) { $weekCounts[$weekYear]++; } else { $weekCounts[$weekYear] = 1; } } $startDate = min(array_keys($weekCounts)); $endDate = date('o-\WW'); // Get the current year-week $currentDate = $startDate; while ($currentDate <= $endDate) { if (!isset($weekCounts[$currentDate])) { $weekCounts[$currentDate] = 0; } $currentDate = date('o-\WW', strtotime($currentDate . ' +1 week')); } ksort($weekCounts); $weekLabels = array_keys($weekCounts); $weekData = array_values($weekCounts); // Monthly counts $monthCounts = array(); foreach ($dates as $date) { $monthYear = date('Y-m', strtotime($date)); // Extract the year and month if (isset($monthCounts[$monthYear])) { $monthCounts[$monthYear]++; } else { $monthCounts[$monthYear] = 1; } } $startDate = min(array_keys($monthCounts)); $endDate = date('Y-m'); // Get the current year-month $currentDate = $startDate; while ($currentDate <= $endDate) { if (!isset($monthCounts[$currentDate])) { $monthCounts[$currentDate] = 0; } $currentDate = date('Y-m', strtotime($currentDate . ' +1 month')); } ksort($monthCounts); $monthLabels = array_keys($monthCounts); $monthData = array_values($monthCounts); ?> <!DOCTYPE html> <html> <head> <title>Date Chart</title> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> </head> <body> <button onclick="switchView('week')">Weekly View</button> <button onclick="switchView('month')">Monthly View</button> <canvas id="myChart"></canvas> <script> var weekLabels = <?php echo json_encode($weekLabels); ?>; var weekData = <?php echo json_encode($weekData); ?>; var monthLabels = <?php echo json_encode($monthLabels); ?>; var monthData = <?php echo json_encode($monthData); ?>; var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'line', data: { labels: weekLabels, datasets: [{ label: 'Counts Per Week (Latest: <?php echo $newestUrl; ?>)', data: weekData, backgroundColor: 'rgba(75, 192, 192, 0.2)', borderColor: 'rgba(75, 192, 192, 1)', borderWidth: 1 }] }, options: { scales: { y: { beginAtZero: true, stepSize: 1 } }, plugins: { tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || ''; var value = context.parsed.y; var tooltipLabel = 'Value: ' + value; // Customize the tooltip label here return tooltipLabel; } } } } } }); function switchView(view) { if (view === 'week') { myChart.data.labels = weekLabels; myChart.data.datasets[0].data = weekData; myChart.data.datasets[0].label = 'Counts Per Week (Latest: <?php echo $newestUrl; ?>)'; } else if (view === 'month') { myChart.data.labels = monthLabels; myChart.data.datasets[0].data = monthData; myChart.data.datasets[0].label = 'Counts Per Month (Latest: <?php echo $newestUrl; ?>)'; } myChart.update(); } </script> </body> </html>