Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 11:26:37 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155556 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Droplet Random Image mit Text für die Foldergallery  (Read 583 times)
gottfried

Offline Offline

Posts: 981


« on: November 19, 2011, 06:34:37 PM »

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.

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;
}

[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.php

eine passende Änderung im css des z.b templates wäre

Code:

.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]
« Last Edit: November 19, 2011, 06:41:27 PM by gottfried » Logged
jrast

Offline Offline

Posts: 315



« Reply #1 on: November 21, 2011, 03:14:52 PM »

Ich hatte da auch mal was, vieleicht einfach so als Ergänzung. Ist als Code-Section umgesetzt und lädt 3 Bilder aus der Foldergallery mit dem dazugehörigen Kategorietitel.

Code:
// Bilder
$section_id =38; // Section ID der Foldergallery Seite
$page_id = 32; // Page ID der Foldergallery Seite
$count = 3;  // Anzahl Bilder
global $database;

$sql = "SELECT cat.cat_name AS alt_text, CONCAT(sett.root_dir,cat.parent,'/',cat.categorie,'/fg-thumbs/',files.file_name) AS path, "
        ."CONCAT(wbpages.link,'.php?cat=',cat.parent,'/',cat.categorie) AS link "
        ."FROM wbmod_foldergallery_files files, wbmod_foldergallery_categories cat, wbmod_foldergallery_settings sett, wbpages "
        ."WHERE cat.id=files.parent_id AND cat.section_id = ".$section_id." AND wbpages.page_id = ".$page_id." AND sett.section_id= ".$section_id." "
        ."ORDER BY RAND() LIMIT ".$count.";";


$query = $database->query($sql);
echo '<div class="front_img"><ul class="photostyle">';
while($row = $query->fetchRow()) {
  echo '<li><a href="'.WB_URL.'/pages'.$row['link'].'" alt="'.$row['alt_text'].'">'
       .'<img src="'.WB_URL.$row['path'].'" alt="'.$row['alt_text'].'"><br>'.$row['alt_text'].'</a></li>';
}
echo '</ul></div><br>';

Das Ergebniss ist auf www.jotoedi.ch auf der Startseite zu sehen. Verwendet noch Foldergallery 1.20 und WB 2.8.1, weiss also nicht ob da für neuere Versionen kleine Anpassungen nötig sind.

Interessant daran ist vor allem dass alle Links und Verknüpfungen direkt Datenbankseitig erstellt werden und somit eigentlich recht schnell sein sollte.
« Last Edit: November 21, 2011, 03:18:32 PM by jrast » Logged

- If life turns bad, just hang on! -
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!