Files
Varaverk/Plugin/usr/local/emhttp/plugins/varaverk/include/docs.php
T
Gmer4Lfe 7b7a3a9e9e Fix plugin routing, missing includes, and make SCRIPTS_DIR configurable
- Rename varaverk.page → Varaverk.page: unRAID nginx only routes URLs
  starting with a capital letter (~^/[A-Z].*), lowercase caused 404
- Add require_once config.php to include/scheduler.php and include/docs.php:
  both used SCRIPTS_DIR constant without including the file that defines it
- Replace hardcoded SCRIPTS_DIR with cfg-file-backed setting: reads from
  /boot/config/plugins/varaverk/varaverk.cfg, falls back to default on first run
- Add Plugin Settings card to Config tab with scripts path field
- Add api/settings.php to write the cfg file (validates directory exists)
2026-05-23 16:48:52 -04:00

51 lines
1.6 KiB
PHP

<?php
// Docs — markdown file discovery, $VAR substitution, and rendering.
// Requires parsedown or similar. Falls back to <pre> if not available.
require_once __DIR__ . '/config.php';
define('PARSEDOWN_PATH', '/usr/local/emhttp/plugins/varaverk/lib/Parsedown.php');
function vv_docs_tree(): array {
$base = SCRIPTS_DIR;
$tree = [];
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($base, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($files as $f) {
if ($f->isFile() && strtolower($f->getExtension()) === 'md') {
$rel = ltrim(str_replace($base, '', $f->getPathname()), '/');
$tree[] = $rel;
}
}
sort($tree);
return $tree;
}
function vv_docs_render(string $rel, array $vars): string {
$path = SCRIPTS_DIR . '/' . $rel;
if (!file_exists($path)) return '<p>File not found.</p>';
$md = file_get_contents($path);
// Substitute `$VAR_NAME` markers with live conf values
$md = preg_replace_callback('/`\$([A-Z0-9_]+)`/', function($m) use ($vars) {
$key = $m[1];
return isset($vars[$key])
? '<code class="vv-live-var">' . htmlspecialchars($vars[$key]) . '</code>'
: '<code class="vv-unknown-var">$' . htmlspecialchars($key) . '</code>';
}, $md);
// Render markdown
if (file_exists(PARSEDOWN_PATH)) {
require_once PARSEDOWN_PATH;
$pd = new Parsedown();
$pd->setSafeMode(true);
return $pd->text($md);
}
// Fallback: plain preformatted text
return '<pre>' . htmlspecialchars($md) . '</pre>';
}