Zugang E: Passwort « ◉ » Kapitelende

Blog-News

Erstellt: 08.03.2022 Lesedauer ≤ 1 Min.

Dieses Skript generiert eine „Newsübersicht“ aus einer einstellbaren Anzahl Beiträgen eines Verzeichnisses nach Aktualität.

Es handelt sich um ein modifiziertes zListe-Skript, das eine detaillierte Datei-Liste mit dem (nach Datum) aktuellsten Eintrag an erster Stelle mit einer begrenzbaren Anzahl erzeugt.

Es wird vom Modul News verwendet und wird damit ausgelagert, damit es nur einmal geladen wird, falls mehrere News-Listen auf einer Seite eingebettet werden (s. NoSi.de).

Das Skript

Stand: 21.10.2022

<?php
function GetNews($Suchpfad,$Anzahl,$Stil,$Kopfzeile) {

    
$items glob($Suchpfad,GLOB_BRACE);

    for (
$i 0$i count($items); $i++) {
        if (
is_dir($items[$i])) {
            
$add array_filter(glob($items[$i] . '/*.php'),'is_file');
            
$items array_merge($items$add);
        }
    }
    
$i=0;
    foreach (
$items as $item){
      if (
$item == "index.php" or $item == "." or is_dir($item)){   }
        else {
            
preg_match("/<title>(.+)<\/title>/siU"file_get_contents($item), $matches);
            if (
$matches) {
                
$Datei[$i]['titel'] = $matches[1];
                
$Datei[$i]['pfad'] = pathinfo($itemPATHINFO_DIRNAME) .'/'pathinfo($itemPATHINFO_FILENAME);
                
$tags get_meta_tags($item);
                if (isset (
$tags['published'])){
                    
$Datei[$i]['published'] = $tags['published'];
                }
                else {
                  
$Datei[$i]['published'] = date ('Y-m-d'filemtime($item));
                }
                
$Datei[$i]['dated'] = $Datei[$i]['published'];
                
$Datei[$i]['modified'] = '';
                if (isset (
$tags['modified'])){
                    if (
$tags['modified']>''){
                            
$Datei[$i]['modified'] = $tags['modified'];
                            
$Datei[$i]['dated'] = $Datei[$i]['modified'];
                    }
                }
                if (isset (
$tags['summary'])) {
                        
$Datei[$i]['text'] = $tags['summary'];
                    }
                else {
                    if (isset (
$tags['description'])) {
                            
$Datei[$i]['text'] = $tags['description'];
                        }
                    else
                           
$Datei[$i]['text'] = 'Keine weiteren Angaben.';
                    }
                }
                
$i++;
            }
        } 
// foreach
    
array_multisort(array_map(function($element) {return $element['dated'];}, $Datei), SORT_DESC $Datei);

    global 
$lng;
    
$rm 'Weiterlesen…';
    
$cr 'Erstellt';
    
$mr 'Geändert';
    
$df 'd.m.Y';

    if (Isset(
$lng)) {
        switch (
$lng) {
         case 
'ua' :
            
$rm 'Продовжити читання…';
            
$cr 'Створений';
            
$mr 'Змінений';
            break;
         case 
'en' :
            
$rm 'Read more…';
            
$cr 'Created';
            
$mr 'Modified';
            
$df 'm.d.Y';
            break;
        }
    }

    
$i=0;
    
$output = (($Stil) ? '<div class="' $Stil '">':''). PHP_EOL;
    
$output .=(($Kopfzeile) ? '<h2>'.$Kopfzeile.'</h2>':'').PHP_EOL;
    foreach (
$Datei As $Inhalt){
        
$output .= '<div><h2><a href="'$Datei[$i]['pfad'] . '">'$Datei[$i]['titel'] . '</a></h2>'"\n";
        
$datum $cr.': ' date_format(date_create($Datei[$i]['published']),$df).'&nbsp;&nbsp;';
        
$output .= '<p class="meta">'$datum;
        if (
$Datei[$i]['modified']>''){
            
$datum date_format(date_create($Datei[$i]['modified']),$df);
            
$output .= $cr.': '$datum;
        }
        
$output .= '</p>' "\n";
        
$output .= '<p>'.$Datei[$i]['text'].'</p>'."\n";
        
$output .= '<p class="more"><a href="'$Datei[$i]['pfad'] . '">'.$rm.'</a></p></div>'PHP_EOL;
        
$i++;
      if (
$i>=$Anzahl) Break;
    }
   
$output .= (($Stil) ? '</div>':'') . PHP_EOL;
   return 
$output;
}
?>

Ladefehler: $$$ file a $$$

Zugang E: Passwort « ◉ » Kapitelende