-
This commit is contained in:
1995
content/php/Parsedown.php
Normal file
1995
content/php/Parsedown.php
Normal file
File diff suppressed because it is too large
Load Diff
52
content/php/markDown.php
Normal file
52
content/php/markDown.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
require_once "Parsedown.php";
|
||||
|
||||
/**
|
||||
* Converte Markdown in HTML da sorgente locale o remota.
|
||||
*
|
||||
* @param string $localPath Percorso del file sul server
|
||||
* @param string $remoteUrl URL del file .md
|
||||
* @return string HTML generato
|
||||
*/
|
||||
function getMarkdownContent($localPath, $remoteUrl)
|
||||
{
|
||||
clearstatcache();
|
||||
|
||||
$markdown = false;
|
||||
// Definiamo il percorso assoluto completo
|
||||
$fullLocalPath = $localPath;
|
||||
|
||||
// 1. Tentativo Locale (Corretto)
|
||||
if (file_exists($fullLocalPath)) {
|
||||
$markdown = file_get_contents($fullLocalPath);
|
||||
}
|
||||
|
||||
// 2. Fallback Remoto
|
||||
if ($markdown === false) {
|
||||
$ch = curl_init($remoteUrl);
|
||||
// Sostituisci la parte del cURL con questa logica di "cache busting"
|
||||
$timestamp = time();
|
||||
$separator = (strpos($remoteUrl, '?') !== false) ? '&' : '?';
|
||||
$urlWithNoCache = $remoteUrl . $separator . "t=" . $timestamp;
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $urlWithNoCache);
|
||||
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
$markdown = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($markdown === false || $httpCode !== 200) {
|
||||
return "<p>Errore: Impossibile recuperare il contenuto ($httpCode).</p>";
|
||||
}
|
||||
}
|
||||
|
||||
$Parsedown = new Parsedown();
|
||||
// Importante: Rimuove eventuali spazi bianchi superflui all'inizio/fine
|
||||
return '<div class="markdown-body">' . $Parsedown->text(trim($markdown)) . '</div>';
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user