Datumsabhängiger Inhalt

Erstellt: 08.03.2022 Lesedauer ≤ 1 Min.

Dieses Skript ermöglicht die zeitgesteuerte Anzeige von Seiteninhalten auf anderen Seiten.

Voraussetzungen

Das Layout der aufgerufenen Seite muss …

  1. … einen Bereich <main>…</main> enthalten, der als „gesamter Seiteninhalt“ extrahiert werden kann.
  2. … den Meta-Variable description oder (ranghöher) summary für die Ausgabe eines Teasers enthalten.
Querverweis

Modul Timed

Das Skript

Stand: 26.11.2022

Ladefehler: $$$ file a $$$

<?php
function GetTimed($Datei,$stopp,$start,$otype) {
    
$DerInhalt '<p><mark>Termindatei fehlt.</mark></p>';
    
$ok file_exists($_SERVER["DOCUMENT_ROOT"] . $Datei);
    
$show true;
    
date_default_timezone_set("Europe/Berlin");
    
$heute date('Y-m-d',time());
    if (
DateTime::createFromFormat('Y-m-d'$stopp) == false) {
        
$stopp date('Y-m-d',time());
    }
    if (
DateTime::createFromFormat('Y-m-d'$start) == false) {
        
$start date('Y-m-d',time());
    }
    if (
$heute $stopp){   
       
$show false/* „drüber“ */
    
}
    if (
$heute $start){
       
$show false;  /* „drunter“ */
    
}
    if (
$ok) { $DerInhalt ''; }
    if (
$ok and $show) {
        if (isset(
$otype) AND ($otype == '0')){    
            
$tags get_meta_tags($_SERVER["DOCUMENT_ROOT"] . $Datei);    
            
$DerInhalt '<article class="temp">';
            if (isset (
$tags['title'])){
                
$DerInhalt .= '<h2><a href="'.$Datei.'">'$tags['title'] . '</a></h2>';
            }
            if (isset (
$tags['summary'])){
                
$DerInhalt .= '<p>'.$tags['summary'].'</p>';
            }
            else {
                if (isset (
$tags['description'])){
                    
$DerInhalt .= '<p>'.$tags['description'].'</p>';
                }
                else {
                    
$DerInhalt .= '<p>Keine weiteren Angaben.</p>';
                }
            }
            
$DerInhalt .= '<p class="more"><a href="'.$Datei'">Weiterlesen…</a></p></article>';
        }
        else {
            
ob_start();  // Daten GERENDERT holen
            
include($_SERVER["DOCUMENT_ROOT"] . $Datei);
            
$alles=ob_get_contents(); 
            
ob_end_clean();
            
            
preg_match('/<main>(.*?)<\/main>/si',$alles,$matches);
            if (
$matches) {
                
$DerInhalt '<article class="temp">'.$matches[1].'</article>';
            }
            else {
                
$DerInhalt '<article class="temp">Keine Detailansicht möglich.</article>';
            }        
        }
    }
    return 
$DerInhalt;
}
?>