Outils pour utilisateurs

Outils du site


dotclear:randomimages:public.php

_public.php

Version 0.4alpha2 (consultez les révisions de cette page pour les autres versions)

class RandomImages
{
    public static function myWidget(&$w)
    {
    global $core;
 
    function exploration($parentdir,$extbig,$racinedir) {
        $dhdir = opendir($racinedir.$parentdir);
        if (!isset($files))
            $files = array();
        if ($dhdir!=False) {
            while (false !== ($subdir = readdir($dhdir)))  {
                $dir = $parentdir.'/'.$subdir;
                if (is_dir($racinedir.$dir) & $subdir != '.' & $subdir != '..')    {
                    //C'est un dossier, rappel de la fonction
                    $files += exploration($parentdir.'/'.$subdir,$extbig,$racinedir);
                } elseif ($subdir{0} != "." & in_array(strrchr($subdir,'.'),$extbig)) {
                    //pour les images qui se trouve directement dans le dossier principal
                    $files[] = $parentdir.'/'.$subdir;
                }
            }
        }
        return $files;
    }
 
    if (isset($_SERVER['DOCUMENT_ROOT_HASH']))
        $racinedir = $_SERVER['DOCUMENT_ROOT_HASH'];
    else
        $racinedir = $_SERVER['DOCUMENT_ROOT'];
    $files = array();
 
    $format = $w->format;
    $openWith = $w->openWith;
 
    switch($format) {
        case 1:
            //$ext = array("_sq.jpg", "_sq.png", "_sq.jpg", "_sq.gif");
            $ext = array("_sq.jpg", "_sq.jpg", "_sq.jpg", "_sq.jpg");
            break;
        case 2:
            //$ext = array("_t.jpg", "_t.png", "_t.jpg", "_t.gif");
            $ext = array("_t.jpg", "_t.jpg", "_t.jpg", "_t.jpg");
            break;
        case 3:
            //$ext = array("_s.jpg", "_s.png", "_s.jpg", "_s.gif");
            $ext = array("_s.jpg", "_s.jpg", "_s.jpg", "_s.jpg");
            break;
        case 4:
            //$ext = array("_m.jpg", "_m.png", "_m.jpg", "_m.gif");
            $ext = array("_m.jpg", "_m.jpg", "_m.jpg", "_m.jpg");
            break;
        case 5:
            $ext = array("", "", "", "");
            $openWith = False;
        }
    $extbig = array(".jpg", ".png", ".jpeg", ".gif");
 
 
    switch($openWith) {
        case 1: //normal
            $link = '<a href="%orig%" title="%titre%"><img src="%min%" alt="'.__('image').'" /></a>';
            break;
        case 2: //popup
            $link = '<a href="%orig%" onclick="window.open(this.href, \'%titre%\', \'resizable=yes, width=%X% ,height=%Y, location=no, menubar=no, status=no\'); return false;" title="%titre%" ><img src="%min%" alt="'.__('image').'" /></a>';
            break;
/*
        case 3: //lightbox
            $link = '<a href="%orig%" rel="lightbox[randomimages]" title="%titre%"><img src="%min%" alt="'.__('image').'" /></a>';
            break;
*/
        default :
            $link = '<img src="%orig%" alt="'.__('image').'" />';
            break;
        }
 
 
    $files = exploration($w->imagedir,$extbig,$racinedir);
 
 
    //sort($files);
    $titre = html::escapeHTML($w->title);
 
    $chaine = '
        <div class="imghasard">
        <h2>'.$titre.'</h2><p>';
 
    //Boucle pour afficher plusieurs images
    $nofindimg = 0;
 
    shuffle($files);
    $nb = 0;
    foreach ($files as $imgbig) {
        if ($nb == $w->nbre)
            break;
 
        if ($format == 5) {
            $img = $imgbig;
        } else {
            $img = str_replace($extbig,$ext,$imgbig);   //création du chemin de la miniature
            $p = strrpos($img,"/")+1;
            $img = substr($img,0,$p).'.'.substr($img,$p);
        }
 
        $reso = getimagesize($racinedir.$imgbig);
        //Si la miniature existe
        if (is_file($racinedir.$img)) {
            //Création du lien
            $chaine .= str_replace(array('%min%','%orig%','%titre%','%X%','%Y'),array('/'.$img,'/'.$imgbig,$titre,($reso[0]+20),($reso[1])+20),$link);
            $nb ++;
        } else {
            //désincrémentation de nombre, incrémentation des imges non trouvées
            $nofindimg++;
            //$chaine .= "<pre>$img</pre>";
        }
    }
 
    if ($nb == 0)
        $chaine .= '<p>'.__('Error! No picture was found.').'</p>
                        <ul>
                            <li>'.__('Make sure you set the correct directory (plugin seeks').'
                            <a href="/'.$w->imagedir.'">'.__('here').'</a>).</li>
                            <li>'.__('Have you explored this directory with the media manager of dotclear for to create miniatures ?').'</li>
                            <li>'.__('Have you ever a problem? Ask me').'
                            <a href="http://forum.jonas.tuxfamily.org/">'.__('here').'</a>.</li>
                        <ul>';
 
    //$chaine .= '['.(microtime(True)-$time).']';
    $chaine .= '</p></div>';
 
    if ($w->homepage && $core->url->type != 'default') {
                        return;
                }
    else {
        return $chaine;
            }
    }
}
?>
dotclear/randomimages/public.php.txt · Dernière modification: 15/01/2010 12:34 (modification externe)