# HG changeset patch # User Dan # Date 1185460630 14400 # Node ID c0c324f0eeb55cafeaefbded961ac0bbcf21a4ce # Parent ad3b061a1c76f978eddd8ca7156311f074cb07cc Added the Random Image sidebar block diff -r ad3b061a1c76 -r c0c324f0eeb5 plugins/Gallery.php --- a/plugins/Gallery.php Wed Jul 25 20:25:02 2007 -0400 +++ b/plugins/Gallery.php Thu Jul 26 10:37:10 2007 -0400 @@ -50,5 +50,6 @@ require( ENANO_ROOT . '/plugins/gallery/upload.php' ); require( ENANO_ROOT . '/plugins/gallery/fetcher.php' ); require( ENANO_ROOT . '/plugins/gallery/search.php' ); +require( ENANO_ROOT . '/plugins/gallery/sidebar.php' ); ?> diff -r ad3b061a1c76 -r c0c324f0eeb5 plugins/gallery/sidebar.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/gallery/sidebar.php Thu Jul 26 10:37:10 2007 -0400 @@ -0,0 +1,67 @@ +sql_query('SELECT img_id,img_title FROM '.table_prefix.'gallery WHERE is_folder=0;'); + if ( !$q ) + $db->_die(); + + $images = array(); + while ( $row = $db->fetchrow() ) + { + $id = intval($row['img_id']); + $images[$id] = $row['img_title']; + } + + // Loop through all gallery images until we find one we can read (typically on the first try, but you never know...) + $my_image = false; + while ( count($images) > 0 ) + { + $rand = array_rand($images); + $image = $images[$rand]; + $acl = $session->fetch_page_acl(strval($rand), 'Gallery'); + if ( $acl->get_permissions('read') ) + { + $my_image = $image; + break; + } + unset($images[$rand]); + } + if ( $my_image ) + { + // Generate sidebar HTML + $image_link = '
'; + } + else + { + $image_link = 'No images in the gallery.'; + } + $template->sidebar_widget('Random image', $image_link); +} + +$plugins->attachHook('compile_template', 'gal_sidebar_block();'); + +?>