Jun9 updates

This commit is contained in:
2025-06-09 16:27:54 -06:00
parent a2b77b5a93
commit 2ffa1b2267
6 changed files with 142 additions and 2 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
defined('DEBUG') || define('DEBUG', $debug ?? $config['DEBUG'] ?? false);
if (ob_get_level() === 0) {
ob_start();
}
function debug($msg) {
error_log($msg);
if (DEBUG > 1) print($msg . "\n");
}
register_shutdown_function(function () {
$error = error_get_last();
if ($error !== null) {
// Log fatal error details
$type = $error['type'];
$message = $error['message'];
$file = $error['file'];
$line = $error['line'];
echo "[SHUTDOWN] Fatal error: {$message} in {$file} on line {$line}\n";
// Optional: log to file
// file_put_contents('/path/to/shutdown.log', "[SHUTDOWN] ...\n", FILE_APPEND);
} else {
if (DEBUG > 1) {
DEBUG && header('Content-Type: text/plain');
# define('X','Well');
DEBUG && print("Constants\n".print_r((get_defined_constants(true))['user']??'No Constants', true) . "\n");
DEBUG && print("Functions\n".print_r((get_defined_functions(true))['user']??'No Functions', true) . "\n");
DEBUG && print("Variables\n".print_r(array_diff_key(get_defined_vars(), array_flip(['_SERVER','_GET','_POST','_COOKIE', '_FILES'])), true) . "\n");
DEBUG && print("Includes\n".print_r(get_included_files(), true) . "\n");
}
echo "[SHUTDOWN] Script completed normally.\n";
}
});
+100
View File
@@ -0,0 +1,100 @@
<?php
# Request Content-Type
stripos($_SERVER['CONTENT_TYPE'], 'application/json') === 0; // ✅ true
$data = json_decode(file_get_contents('php://input'), true);
function generateCard($title, $url, $image, $description = '') {
return <<<HTML
<div class="card mb-4" style="width: 18rem;">
<a href="{$url}" class="text-decoration-none text-reset">
<img src="{$image}" class="card-img-top" alt="{$title}">
<div class="card-body">
<h5 class="card-title">{$title}</h5>
<p class="card-text">{$description}</p>
</div>
</a>
</div>
HTML;
}
$meta['title'] = $meta['title'] !== '' ? $meta['title'] : 'Home';
$meta['title'] ??= ucfirst(str_replace('/', '', $path)) ?: 'Home';
function extractMeta($directory) {
$metaData = [];
if (!is_dir($directory)) {
throw new Exception("Directory not found: $directory");
}
foreach (new DirectoryIterator($directory) as $file) {
if ($file->isFile() && $file->getExtension() === 'md') {
$contents = file_get_contents($file->getPathname());
// Extract title and image from the front matter
if (preg_match('/^-{3,}\s*(.*?)\s*-{3,}/s', $contents, $matches)) {
$frontMatter = $matches[1];
// Extract title
preg_match('/title:\s*(.*?)\s*$/m', $frontMatter, $titleMatch);
$title = trim($titleMatch[1] ?? '');
// Extract image
preg_match('/image:\s*(.*?)\s*$/m', $frontMatter, $imageMatch);
$image = trim($imageMatch[1] ?? '');
$metaData[$file->getFilename()] = [
'title' => $title,
'image' => $image,
];
}
}
}
return $metaData;
}
$file = '/path/to/your/file.txt';
if (file_exists($file)) {
$modTime = filemtime($file);
echo "Last modified: " . date(DATE_RFC2822, $modTime);
} else {
echo "File not found.";
}
echo realpath($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']);
function render_meta($config, $core = [], $options = []) {
// Default options
$defaults = [
'ogm' => false,
'twitter' => false,
'schema' => true,
];
// Merge provided options with defaults
$options = array_merge($defaults, $options);
// Example usage
var_dump($options);
}
function compareDates($date1, $date2) {
try {
// Normalize both dates to the same format (ISO 8601)
$normalized1 = (new DateTime($date1))->format('Y-m-d');
$normalized2 = (new DateTime($date2))->format('Y-m-d');
// Return comparison result
return strcmp($normalized1, $normalized2);
} catch (Exception $e) {
// Handle invalid date formats
trigger_error("Invalid date format: " . $e->getMessage(), E_USER_WARNING);
return null;
}
}
+3
View File
@@ -0,0 +1,3 @@
<?php
# sigh