Hallo !
Ich hab ein Droplet aus dem Randomimage recursive abgeleitet, das in der Foldergallery den Text zum Bild sucht
und das stylish mit css umwickelt.
//:[[Random-FG?dir=<Verzeichnis>&height=<Pixel>&width=<Pixel>]]
//:Basically, this works exactly like the [[RandomImage]] droplet, but unlike that one, it recurses into subdirectories, too.
//: You can also show the LATEST image of all images in all subfolders by adding the "latest"-attribute: [[RandomOrLatest?dir=<Verzeichnis>&height=<Pixel>&width=<Pixel>&latest=1]]
// Am besten width= leer lassen, sonst werden die Bilder verzerrt!
global $suffixes, $thumbs, $thumbdir, $f_time, $f_latest, $database;
// config
$thumbdir = 'fg-thumbs'; // sub directory for thumbnail images
$suffixes = 'jpg|jpeg|gif|png'; // recognized file suffixes for images
$random = 1;
// end config
$thumbs = isset( $thumb ) ? 1 : 0;
$random = isset( $latest ) ? 0 : 1;
$folder = WB_PATH.MEDIA_DIRECTORY.'/'.$dir;
$names = array();
$dir_handle = @opendir($folder);
$names = recurse_dir( $dir_handle, $folder );
if ( $random ) {
shuffle($names);
$image=$names[0];
// text dazu in foldergallery suchen
$bn=basename($image) ;
// Gibt es Bilder in dieser Kategorie
$sql = 'SELECT * FROM ' . TABLE_PREFIX . 'mod_foldergallery_files WHERE file_name="' . $bn . '" ORDER BY position ASC;';
$query = $database->query($sql);
while ($bild = $query->fetchRow()) {
if ($bild['file_name'] == 'folderpreview.jpg')
continue;
$ca = $bild['caption'];
$caption =preg_replace("/\r\n|\n|\r/i","<br>",$ca);
}
}
else {
$image = $f_latest;
$caption = '' ;
}
$name = $image;
if ( preg_match( "#/(\w+)\.\w+$#", $image, $match ) )
{
$name = $match[1];
}
return '<div class="rol-outer"><div class="rol-img"><img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$image.'" alt="'.$name.'" width="'.$width.'" height="'.$height.'" /></div><div="rol-caption">'.$caption.'</div></div>';
// return '<img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$image.'" alt="'.$name.'" width="'.$width.'" height="'.$height.'" />'.$caption;
function recurse_dir( $dir_handle, $path )
{
global $suffixes, $thumbs, $thumbdir, $f_time, $f_latest;
$files = array();
//running the while loop
while ( false !== ( $file = readdir($dir_handle) ) )
{
$dir = $path.'/'.$file;
// recurse
if( is_dir($dir) && $file != '.' && $file != '..' )
{
$handle = @opendir($dir);
$files = array_merge(
recurse_dir( $handle, $dir ),
$files
);
} elseif( $file != '.' && $file != '..' && preg_match( "/\.$suffixes$/i", $file ) )
{
if ( $thumbs && ! preg_match( "#/$thumbdir$#i", $path ) )
{
continue;
}
if ( ! $thumbs && preg_match( "#/$thumbdir$#i", $path ) )
{
continue;
}
$timedat = filemtime($path.'/'.$file);
if ( $timedat > $f_time ) {
$f_time = $timedat;
$f_latest = str_ireplace(
WB_PATH.MEDIA_DIRECTORY,
"",
$path.'/'.$file
);
}
$files[] = str_ireplace(
WB_PATH.MEDIA_DIRECTORY,
"",
$path.'/'.$file
);
}
}
//closing the directory
closedir( $dir_handle );
return $files;
}
[code]
Personal Message (Online)
Re: ich brauch einen Tip - zu Datenbankzugriffen in droplets
« Reply #5 on: November 17, 2011, 08:22:23 PM »
Reply with quote Modify message Remove message
Yes !
droplet Random-FG (Code unten) holt sich die Texte aus der Foldergallery zum Randombild (eines Astes evtl. mehrerer Foldergallerien)
Code:
//:[[Random-FG?dir=<Verzeichnis>&height=<Pixel>&width=<Pixel>]]
//:Basically, this works exactly like the [[RandomImage]] droplet, but unlike that one, it recurses into subdirectories, too.
//: You can also show the LATEST image of all images in all subfolders by adding the "latest"-attribute: [[RandomOrLatest?dir=<Verzeichnis>&height=<Pixel>&width=<Pixel>&latest=1]]
// Am besten width= leer lassen, sonst werden die Bilder verzerrt!
global $suffixes, $thumbs, $thumbdir, $f_time, $f_latest, $database;
// config
$thumbdir = 'fg-thumbs'; // sub directory for thumbnail images
$suffixes = 'jpg|jpeg|gif|png'; // recognized file suffixes for images
$random = 1;
// end config
$thumbs = isset( $thumb ) ? 1 : 0;
$random = isset( $latest ) ? 0 : 1;
$folder = WB_PATH.MEDIA_DIRECTORY.'/'.$dir;
$names = array();
$dir_handle = @opendir($folder);
$names = recurse_dir( $dir_handle, $folder );
if ( $random ) {
shuffle($names);
$image=$names[0];
// text dazu in foldergallery suchen
$bn=basename($image) ;
// Gibt es Bilder in dieser Kategorie
$sql = 'SELECT * FROM ' . TABLE_PREFIX . 'mod_foldergallery_files WHERE file_name="' . $bn . '" ORDER BY position ASC;';
$query = $database->query($sql);
while ($bild = $query->fetchRow()) {
if ($bild['file_name'] == 'folderpreview.jpg')
continue;
$ca = $bild['caption'];
$caption =preg_replace("/\r\n|\n|\r/i","<br>",$ca);
}
}
else {
$image = $f_latest;
$caption = '' ;
}
$name = $image;
if ( preg_match( "#/(\w+)\.\w+$#", $image, $match ) )
{
$name = $match[1];
}
return '<div class="rol-outer"><div class="rol-img"><img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$image.'" alt="'.$name.'" width="'.$width.'" height="'.$height.'" /></div><div="rol-caption">'.$caption.'</div></div>';
// return '<img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$image.'" alt="'.$name.'" width="'.$width.'" height="'.$height.'" />'.$caption;
function recurse_dir( $dir_handle, $path )
{
global $suffixes, $thumbs, $thumbdir, $f_time, $f_latest;
$files = array();
//running the while loop
while ( false !== ( $file = readdir($dir_handle) ) )
{
$dir = $path.'/'.$file;
// recurse
if( is_dir($dir) && $file != '.' && $file != '..' )
{
$handle = @opendir($dir);
$files = array_merge(
recurse_dir( $handle, $dir ),
$files
);
} elseif( $file != '.' && $file != '..' && preg_match( "/\.$suffixes$/i", $file ) )
{
if ( $thumbs && ! preg_match( "#/$thumbdir$#i", $path ) )
{
continue;
}
if ( ! $thumbs && preg_match( "#/$thumbdir$#i", $path ) )
{
continue;
}
$timedat = filemtime($path.'/'.$file);
if ( $timedat > $f_time ) {
$f_time = $timedat;
$f_latest = str_ireplace(
WB_PATH.MEDIA_DIRECTORY,
"",
$path.'/'.$file
);
}
$files[] = str_ireplace(
WB_PATH.MEDIA_DIRECTORY,
"",
$path.'/'.$file
);
}
}
//closing the directory
closedir( $dir_handle );
return $files;
}
bringt ein Ergebniss wie momentan (mitte nov 2011) auf der TESTSEITE
http://ezimo2.kunst-und-design-schule.de/pages/bilder.phpeine passende Änderung im css des z.b templates wäre
.rol-outer {
width: 100% ;
text-align: center ;
}
.rol-caption{
display: table-cell ;
vertical-align: middle ;
text-align: center ;
}
.rol-img {
height: 220px ;
}
.rol-img img{
-moz-box-shadow: 6px 6px 6px grey;
-webkit-box-shadow: 6px 6px 6px grey;
box-shadow: 6px 6px 6px grey;
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=6, Direction=135, Color='grey');
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=6, Direction=135, Color='grey')";
}
[/code]