Repair protocol php script and guard against the next php update fail

This commit is contained in:
Nils 2023-12-10 19:42:23 +01:00
parent e4237262de
commit 095136c5df
1 changed files with 24 additions and 12 deletions

View File

@ -6,22 +6,34 @@
<pre> <!-- Keep pure text line breaks -->
<?php
//see https://github.com/vstelmakh/url-highlight
require '/home/meeehgru/vendor/autoload.php'; //relative path with DIR . concat does not work
use VStelmakh\UrlHighlight\UrlHighlight;
$urlHighlight = new UrlHighlight();
$autoloadPath = '/home/meeehgru/vendor/autoload.php';
$files = glob("./protokolle/osamc_*.txt");
foreach(array_reverse($files) as $file){
// Check if autoload.php file exists
if (!file_exists($autoloadPath)) {
echo "<p>PHP Configuration changed. The autoload.php file is missing. Please run <code>composer install</code> or <code>composer require vstelmakh/url-highlight</code>. Please inform the osamc.de staff about this problem.</p>";
} else {
require $autoloadPath;
// Check if UrlHighlight class exists
if (!class_exists(\VStelmakh\UrlHighlight\UrlHighlight::class)) {
echo "<p>PHP Configuration changed. Run <code>composer require vstelmakh/url-highlight</code>. Please inform the osamc.de staff about this problem.</p>";
} else {
// Your existing code goes here
use VStelmakh\UrlHighlight\UrlHighlight;
$urlHighlight = new UrlHighlight();
$files = glob("./protokolle/osamc_*.txt");
foreach(array_reverse($files) as $file){
$path_parts = pathinfo($file);
echo "<h2>" . $path_parts['filename'] . "</h2>";
echo "\n";
echo $urlHighlight->highlightUrls(file_get_contents($file));
echo "\n";
}
// Remove fclose($out); as $out is not defined
}
}
fclose($out);
?>
</pre>
</body>