Geeklog France

MediaGallery fonction Random Full Image

Create static page with this code:

$rutaImagen = phpblock_mg_randommediaFull();
$pathalbum = phpblock_mg_randFull();

echo "<center><img src='$rutaImagen'></img></center>";
echo "<center><a href='$pathalbum'><b>Votar</b></a></center>";

And we need to add this code to lib-custom.php

* albums.  It uses the full (orginally uploaded image) for the display.
 *
 * This function can be called from a static page or a block
 *
 * Staticpage Instructions:
 *
 *   To use this function in a static page, the static page must allow PHP
 *   to execute.
 *
 *   Place the following code in the static page:
 *
 *   echo phpblock_mg_randommediaFull();
 *
 * Block Instructions:
 *
 *   Create a Geeklog block, type PHP Block and enter phpblock_mg_randommediaFull
 *   as the Block Function.
 *
 *
 */

function phpblock_mg_randommediaFull(){
    global $_CONF, $_MG_CONF, $_TABLES, $_USER, $LANG_MG03;

    $retval = '';
    $gotit = 0;

    $sql = "SELECT * FROM {$_TABLES['mg_albums']} as a LEFT JOIN {$_TABLES['mg_media_albums']} as ma
            on a.album_id=ma.album_id LEFT JOIN {$_TABLES['mg_media']} as m on ma.media_id=m.media_id WHERE
            m.media_type=0 AND a.enable_random=1 AND a.hidden=0 " . COM_getPermSQL('and') . " ORDER BY RAND(NOW()) LIMIT 1";

    $result = DB_query( $sql,1 );
    $nRows  = DB_numRows( $result );
    if ( $nRows > 0 ) {
        $row    = DB_fetchArray( $result );
        $gotit = true;
    } else {
        $gotit = false;
    }

    if ( $gotit ) {
        $T = new Template($_CONF['path'] . 'plugins/mediagallery/templates');
        $T->set_file (array ('rblock' => 'random_block.thtml'));
        $T->set_var('site_url', $_CONF['site_url']);
        $T->set_var('site_admin_url', $_CONF['site_admin_url']);
        $url_media      = $_MG_CONF['site_url'] . '/media.php?s=' . $row['media_id'];
        $url_album      = $_MG_CONF['site_url'] . '/album.php?aid=' . $row['album_id'];
        $media      = $_MG_CONF['site_url'] . '/mediaobjects/orig/' . $row['media_filename'][0] .'/' . $row['media_filename'] . '.' . $row['media_mime_ext'];

        $msize = @getimagesize($_MG_CONF['path_html'] . '/mediaobjects/orig/' . $row['media_filename'][0] .'/' . $row['media_filename'] . '.' . $row['media_mime_ext']);
        if ($msize == false ) {
            return '';
        }
        $imgwidth = $msize[0];
        $imgheight = $msize[1];

        $T->set_var(array(
            'url_media'         =>  $url_media,
            'url_album'         =>  $url_album,
            'media_thumbnail'   =>  $media,
            'media_height'      =>  $imgheight,
            'media_width'       =>  $imgwidth,
            'border_width'      =>  $imgwidth + 14,
            'media_title'       =>  COM_stripslashes(strip_tags($row['media_title'])),
            'lang_browse_album' =>  $LANG_MG03['browse_album']
        ));

        $T->parse('output', 'rblock');
        $retval .= $_MG_CONF['site_url'] . '/mediaobjects/orig/' . $row['media_filename'][0] .'/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
    }

    return $retval;
}

/*
 * This function will display a random image from the Media Gallery
 * albums.  It uses the full (orginally uploaded image) for the display.
 *
 * This function can be called from a static page or a block
 *
 * Staticpage Instructions:
 *
 *   To use this function in a static page, the static page must allow PHP
 *   to execute.
 *
 *   Place the following code in the static page:
 *
 *   echo phpblock_mg_randommediaFull();
 *
 * Block Instructions:
 *
 *   Create a Geeklog block, type PHP Block and enter phpblock_mg_randommediaFull
 *   as the Block Function.
 *
 *
 */

function phpblock_mg_randFull(){
    global $_CONF, $_MG_CONF, $_TABLES, $_USER, $LANG_MG03;

    $retval = '';
    $gotit = 0;

    $sql = "SELECT * FROM {$_TABLES['mg_albums']} as a LEFT JOIN {$_TABLES['mg_media_albums']} as ma
            on a.album_id=ma.album_id LEFT JOIN {$_TABLES['mg_media']} as m on ma.media_id=m.media_id WHERE
            m.media_type=0 AND a.enable_random=1 AND a.hidden=0 " . COM_getPermSQL('and') . " ORDER BY RAND(NOW()) LIMIT 1";

    $result = DB_query( $sql,1 );
    $nRows  = DB_numRows( $result );
    if ( $nRows > 0 ) {
        $row    = DB_fetchArray( $result );
        $gotit = true;
    } else {
        $gotit = false;
    }

    if ( $gotit ) {
        $T = new Template($_CONF['path'] . 'plugins/mediagallery/templates');
        $T->set_file (array ('rblock' => 'random_block.thtml'));
        $T->set_var('site_url', $_CONF['site_url']);
        $T->set_var('site_admin_url', $_CONF['site_admin_url']);
        $url_media      = $_MG_CONF['site_url'] . '/media.php?s=' . $row['media_id'];
        $url_album      = $_MG_CONF['site_url'] . '/album.php?aid=' . $row['album_id'];
        $media      = $_MG_CONF['site_url'] . '/mediaobjects/orig/' . $row['media_filename'][0] .'/' . $row['media_filename'] . '.' . $row['media_mime_ext'];

        $retval .= $_MG_CONF['site_url'] . '/mediaobjects/orig/' . $row['media_filename'][0] .'/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
    }

    return $url_media;
}
Connecté en tant que : Guest (Guest)
plugins/mediagallery/random-full-image.txt · Dernière modification: 2010/05/12 13:57 par ::Ben
 

Download geeklog

Last version 1.8.1

Espace Membre





Devenir membre
Enregistrez-vous

Mot de passe oublié ?

Change language

Categories

  • Geeklog (38)
  • Plugins (53)
  • Thèmes (17)
  • My cart

    Votre panier (0 article)

    Votre panier est vide!

    0.00 EUR

    Visual Theme Switcher

    Test out available themes by selecting from one of the 6 available themes or give the Visual Switcher a try:

    Follow us on twitter

    En ligne

    Visiteurs: 8