Login
Schnipsel
Während es in Joomla 1.0x noch einige statistische Auswertungen im Backend gab (u.a. Seitenaufrufe), ist dieses Feature bei Joomla 1.5 weitgehend verschwunden.
JT SlideShow - PHP
Im Joomla Extensions Directory (JED) fanden wir ein hübsches Slideshow-Modul, das wir auch auf dieser Seite benutzen (z.B.) bei Hauptmenü/Partner auf der linken Seite.
Leider gab's ein kleines Problem ..
Wir stellten fest, dass das Modul bei der automatischen Anzeige von Bilddateien eines Ordners immer ein oder zwei "Phantombilder" anzeigen will, die nicht existieren.
Nachforschungen im Quellcode der Datei helper.php zeigten, daß die PHP-Funktion count() auf Werte des Typs boolean angewendet wurde:
Bsp.:
Zeile 208: $jpgimages = glob("".$this->folder."/*.jpg");
$jpgimages wird zu einem Arrray mit Bildern - oder, wenn es keine Bilder gibt zu FALSE !
Später wird mehrfach die Funktion count() auf $jpgimages angewendet.
Das Problem: count(false) liefert als Ergebnis 1 !!!
Hier der Original-Code:
// Show all images
if ($this->showallimages) {
// Directory SlideShow
// if subdirectory parameter is yes
$jpgimages = glob("".$this->folder."/*.jpg");
$pngimages = glob("".$this->folder."/*.png");
$gifimages = glob("".$this->folder."/*.gif");
// Generating image array
// Adding jpeg files to (directory) slideshow
$this->image = $jpgimages;
// Adding png files to (directory) slideshow
$j=0;
for ($i = count($jpgimages); $i < count($jpgimages)+count($pngimages); $i++) {
$this->image[$i]=$pngimages[$j];
$j=$j+1;
}
// Adding gif files to (directory) slideshow
$j=0;
for ($i = count($this->image); $i < count($jpgimages)+count($pngimages)+count($gifimages); $i++) {
$this->image[$i]=$gifimages[$j];
$j=$j+1;
}
}
.. und hier unsere "quick and dirty"-Lösung:
// Show all images
if ($this->showallimages) {
// Directory SlideShow
// if subdirectory parameter is yes
$jpgimages = glob("".$this->folder."/*.jpg");
$pngimages = glob("".$this->folder."/*.png");
$gifimages = glob("".$this->folder."/*.gif");
/*
barg-it: strikteres Zählen -- PHP - count(false)-Problem --
.. die Arrayelemente werden korrekt gezählt und in Variablen der Form $count_xxx abgelegt
.. alle nachfolgenden Aufrufe der Funktion werden durch die entsprechende Variable ersetzt.
*/
$count_jpg = $jpgimages ? count($jpgimages): 0 ;
$count_png = $pngimages ? count($pngimages): 0 ;
$count_gif = $gifimages ? count($gifimages): 0 ;
// Generating image array
// Adding jpeg files to (directory) slideshow
$this->image = $jpgimages;
// Adding png files to (directory) slideshow
$j=0;
for ($i = $count_jpg; $i < $count_jpg+$count_png; $i++) {
$this->image[$i]=$pngimages[$j];
$j=$j+1;
}
// Adding gif files to (directory) slideshow
$j=0;
for ($i = count($this->image); $i < $count_jpg+$count_png+$count_gif; $i++) {
$this->image[$i]=$gifimages[$j];
$j=$j+1;
}
}
Eleganter wäre wohl eine Lösung, die dafür sorgt, daß $jpgimages immer zu einem Arrray wird.
Statt false sollte dann ein leeres Array von glob() zurückgegeben werden.
Aber das ist eine andere Geschichte ..



