Galerie.php
OOP galerie obrázků
php
<?php
class Galerie {
private $sloupcu;
private $soubory = array();
public function __construct($sloupcu) {
$this->sloupcu = $sloupcu;
}
public function nacti($slozka) {
$adresar = dir($slozka);
while ($polozka = $adresar->read()) {
if (strpos($polozka, '_nahled.') !== false) {
$this->soubory[] = "$slozka/$polozka";
}
}
$adresar->close();
}
public function __toString() {
$radek=0;
$radky=array();
while (sizeOf($slice=array_slice($this->soubory, $radek*$this->sloupcu, $this->sloupcu)) > 0) {
$polozky=array();
foreach ($slice as $soubor) {
$nahled = htmlspecialchars($soubor);
$obrazek = htmlspecialchars(str_replace('_nahled.', '.', $soubor));
$polozky[] = "<a href=\"$obrazek\"><img src=\"$nahled\" alt=\"\"></a>";
}
$radky[]="<td>".implode("</td>\n<td>", $polozky)."</td>\n";
$radek++;
}
$tabulka= "<tr>\n".implode("</tr>\n<tr>\n", $radky)."</tr>";
return <<<EOT
<!DOCTYPE html>
<html lang="cs-cz">
<head>
<meta charset="utf-8" />
<title>Galerie obrázků</title>
</head>
<body>
<h1>Galerie obrázků</h1>
<table id="galerie">
$tabulka
</table>
</body>
</html>
EOT;
}
}
$galerie = new Galerie(5);
$galerie->nacti('obrazky');
echo $galerie;
Neformátovaný
Přidáno: 23.8.2013
Expirace: Neuvedeno