Support Forums | Demo Gallery [1.x] [2.x] | Downloads | News | Site Map ]
Nuked Gallery
  Create a FREE account or Login   As a guest, you don't have access to our FULL navigation system.
 Forum FAQForum FAQ   StatisticsStatistics   SearchSearch   UsergroupsUsergroups   FavoritesFavorites  

[TESTING] Selectable Album Random Block
Goto page Previous  1, 2, 3, 4, 5, 6, 7
 
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Integration » Blocks View previous topicPrinter friendly versionView next topic
Author Message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Feb 24, 2006 8:17 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

sorry, kinda got sidetracked w/ the 2.1 release. i should have some time this weekend to take a look at this.
Back to top
Offline View user's profile Send private message Visit poster's website
AdBot
   Post subject: Re: [TESTING] Selectable Album Random Block  

Back to top
slackbladder

Moderator
Moderator


Joined: Mar 29, 2003
Posts: 1038
Location: Cambs,UK

PostPosted: Fri Feb 24, 2006 8:19 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

Appreciate it Smile
Back to top
Offline View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
slackbladder

Moderator
Moderator


Joined: Mar 29, 2003
Posts: 1038
Location: Cambs,UK

PostPosted: Fri Mar 03, 2006 2:20 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

Dari if you don't have the time or are unable to help can you please let me know so I can sort it another way - many thanks
Back to top
Offline View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
menelaos61

Beginner
Beginner


Joined: Mar 23, 2005
Posts: 3

PostPosted: Fri Mar 03, 2006 3:30 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

Hi guys,
To indicate in the block-file from which album the block must derive it's pictures, just add:

Code: › 'itemId'=>1234


to the block-code (1234 would have to correspond with the album code of choice)

so find the piece of code like:
Code: › list($ret,$html, $head) = GalleryEmbed::getImageBlock(array('blocks'=>$blockType,'show'=>$display,'itemFrame'=>'solid','albumFrame'=>'solid','maxSize' => $maxSize));


and replace it with something like:
Code: › list($ret,$html, $head) = GalleryEmbed::getImageBlock(array('blocks'=>$blockType,'show'=>$display,'itemId'=>1234,'itemFrame'=>'solid','albumFrame'=>'solid','maxSize' => $maxSize));


Remember to find out the itemId number of the album of your choice...

This method works fabulously Smile

Cheers,
Richard (menelaos61)
Back to top
Offline View user's profile Send private message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Mar 03, 2006 7:32 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

slackbladder wrote: › Dari if you don't have the time or are unable to help can you please let me know so I can sort it another way - many thanks


actually, after hacking away at the selectable block file, i realized that since you want to hardcode in the values of albums, that the normal random block file is what you should use.

try:
PHP: › <?php

/* 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Developed by Dariush Molavi at NukedGallery.net
 * Version 2.0
 * 13 December 2003
 */

 
if (eregi("block-NG-RandomPhoto_functions.php",$_SERVER['PHP_SELF'])) {
    
Header("Location: index.php");
    die();
}

global 
$gallery$GALLERY_EMBEDDED_INSIDE$GALLERY_EMBEDDED_INSIDE_TYPE$GALLERY_MODULENAME$Version_Num;

/*******************************************************************/
/* Full path to your Gallery, don't forget the trailing /          */
/*******************************************************************/
$GALLERY_BASEDIR "/home/httpd/phpnuke.nukedgallery.net/htdocs/modules/gallery/";

/*******************************************************************/
/* The module name of your Gallery, default is "gallery"           */
/*******************************************************************/
$GALLERY_MODULENAME "gallery";

/*******************************************************************/
/* Time, in seconds, to refresh random photo cache. Default is     */
/* 86400 (check it daily)                                          */
/*******************************************************************/
define(CACHE_EXPIRED10);

/*******************************************************************/
/* Full path to your albums directory, don't forget the trailing / */
/*******************************************************************/
define(ALBUM_DIRECTORY,"/home/httpd/phpnuke.nukedgallery.net/htdocs/albums/");



/*******************************************************************/
/*          STOP!! DO NOT EDIT ANYTHING BELOW THIS POINT           */
/*******************************************************************/
define(CACHE_FILEALBUM_DIRECTORY."block-random.cache");

$GALLERY_EMBEDDED_INSIDE "nuke";
$GALLERY_EMBEDDED_INSIDE_TYPE "phpnuke";

require_once(
$GALLERY_BASEDIR "init.php");

function 
createBlockContent($album,$index,$scale,$auto=0) {
    global 
$gallery$GALLERY_EMBEDDED_INSIDE$GALLERY_EMBEDDED_INSIDE_TYPE$GALLERY_MODULENAME;

    
$id $album->getPhotoId($index);
    
$caption $album->getCaption($index);
    
$photo $album->getPhoto($index);
    
$dir $album->getAlbumDirURL("full");
    
$image $photo->image;
    
$PHOTO_URL makeAlbumUrl($album->fields['name'], $id);
    
$ALBUM_URL makeAlbumUrl($album->fields['name']);
    if(
$scale == 0) {
                        if(
$auto == 0) {
                                
$IMG "<center><a href=\"$PHOTO_URL\">".$album->getThumbnailTag($index)."</a><br>";
                        }
                        else {
                                
$IMG "<center><a href=\"$PHOTO_URL\" target=\"_top\">".$album->getThumbnailTag($index)."</a><br>";
                        }
    } else {
                        if(
$auto == 0) {
                                
$IMG "<center><a href=\"$PHOTO_URL\">".$album->getThumbnailTag($index,$scale)."</a><br>";
                        }
                        else {
                                
$IMG "<center><a href=\"$PHOTO_URL\" target=\"_top\">".$album->getThumbnailTag($index,$scale)."</a><br>";
                        }
    }
    
$FROM "From: <a href=\"$ALBUM_URL\">" $album->fields['title'] . '</a>';
    
$blockContent .=  "\t$IMG\n";
    
$blockContent .= "\t$caption<br />\n";
    
$blockContent .= "\t$FROM\n</center>";
    return 
$blockContent;
}

function 
get_photo($interval$scale,$auto=0) {
    global 
$gallery$GALLERY_EMBEDDED_INSIDE$GALLERY_EMBEDDED_INSIDE_TYPE$GALLERY_MODULENAME;

    switch (
$interval) {
        case 
0:
            list(
$album,$index) = get_random_photo_id();
            while(
$album->getAlbumName($index)) {
                list(
$album,$index) = get_random_photo_id();
            }
            
$blockContent createBlockContent($album,$index,$scale,$auto);
            return 
$blockContent;
            break;
        case 
1:
            if (
file_exists($gallery->app->albumDir."/hourly.txt")) {
                
$stat=stat($gallery->app->albumDir."/hourly.txt");
                
$modtime $stat['mtime'];
                if(
date("G"$modtime) != date("G"time())) {                
                    list(
$album,$index) = get_random_photo_id();
                                while(
$album->getAlbumName($index)) {
                                        list(
$album,$index) = get_random_photo_id();
                                }
                    
$blockContent createBlockContent($album,$index,$scale);
                    
$fp fopen($gallery->app->albumDir."/hourly.txt","w");
                    
fwrite($fp,$album->fields['name']."/".$index);
                    
fclose($fp);
                    return 
$blockContent;
                }
                else {
                    
$fp fopen($gallery->app->albumDir."/hourly.txt","r");
                    
$line explode("/",fgets($fp));
                    
$albumName $line[0];
                    
$album = new Album();
                    
$album->load($albumName);
                    
$index $line[1];
                    
$blockContent createBlockContent($album,$index,$scale);
                    return 
$blockContent;
                }
            }
            else {
                list(
$album,$index) = get_random_photo_id();
                            while(
$album->getAlbumName($index)) {
                                    list(
$album,$index) = get_random_photo_id();
                            }
                
$blockContent createBlockContent($album,$index,$scale);
                
$fp fopen($gallery->app->albumDir."/hourly.txt","w");
                
fwrite($fp,$album->fields['name']."/".$index);
                
fclose($fp);
                return 
$blockContent;
            }
            break;
        case 
24:
            if (
file_exists($gallery->app->albumDir."/daily.txt")) {
                
$stat=stat($gallery->app->albumDir."/daily.txt");
                
$modtime $stat['mtime'];
                if(
date("d"$modtime) != date("d"time())) {                
                    list(
$album,$index) = get_random_photo_id();
                                while(
$album->getAlbumName($index)) {
                                        list(
$album,$index) = get_random_photo_id();
                                }
                    
$blockContent createBlockContent($album,$index,$scale);
                    
$fp fopen($gallery->app->albumDir."/daily.txt","w");
                    
fwrite($fp,$album->fields['name']."/".$index);
                    
fclose($fp);
                    return 
$blockContent;
                }
                else {
                    
$fp fopen($gallery->app->albumDir."/daily.txt","r");
                    
$line explode("/",fgets($fp));
                    
$albumName $line[0];
                    
$album = new Album();
                    
$album->load($albumName);
                    
$index $line[1];
                    
$blockContent createBlockContent($album,$index,$scale);
                    return 
$blockContent;
                }
            }
            else {
                list(
$album,$index) = get_random_photo_id();
                            while(
$album->getAlbumName($index)) {
                                    list(
$album,$index) = get_random_photo_id();
                            }
                
$blockContent createBlockContent($album,$index,$scale);
                
$fp fopen($gallery->app->albumDir."/daily.txt","w");
                
fwrite($fp,$album->fields['name']."/".$index);
                
fclose($fp);
                return 
$blockContent;
            }
            break;
    }
}

function 
get_random_photo_id(){
        
/* Initializing the seed */
        
srand ((double) microtime() * 1000000);

        
readcache();
        
$album choosealbum();

        if (
$album) {
            
$index choosephoto($album);
        }
        return array(
$album,$index);
}


function 
readcache() {
    global 
$cache;

    
$cache = array('album_name'=>'num_photos''album_2'=>'num_photos');

}

function 
choosephoto($album) {
    global 
$cache$gallery;

    
$count $cache[$album->fields["name"]];

    if (
$count == 0) {
        
// Shouldn't happen
        
return null;
    } else if (
$count == 1) {
        
$choose 1;
    } else {
        
$count floatval($count);
        
$choose rand(1$count);
        
$wrap 0;
        if (
$album->isHidden($choose)) {
            
$choose++;
            if (
$choose $album->numPhotos(1)) {
                
$choose 1;
                
$wrap++;
                if (
$wrap 2) {
                    return 
null;
                }
            }
        }
    }
    return 
$choose;
}

function 
choosealbum() {
    global 
$cache;

    
/*
     * The odds that an album will be selected is proportional
     * to the number of (visible) items in the album.
     */

    
$total 0;
    foreach (
$cache as $name => $count) {
        if (!
$choose) {
            
$choose $name;
        }

        
$total += $count;
        if (
$total != && ($total == || rand(1$total) <= $count)) {
            
$choose $name;
        }
    }

    if (
$choose) {
        
$album = new Album();
        
$album->load($choose);
        return 
$album;
    } else {
        return 
null;
    }
}

?>


note that in the readcache function, you'll need the album name and the number of photos in the album (the randomizer uses the number of photos to determine how often to pull from that album).
Back to top
Offline View user's profile Send private message Visit poster's website
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Mar 03, 2006 7:33 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

menelaos61 wrote: › Hi guys,
To indicate in the block-file from which album the block must derive it's pictures, just add:

Code: › 'itemId'=>1234


to the block-code (1234 would have to correspond with the album code of choice)

so find the piece of code like:
Code: › list($ret,$html, $head) = GalleryEmbed::getImageBlock(array('blocks'=>$blockType,'show'=>$display,'itemFrame'=>'solid','albumFrame'=>'solid','maxSize' => $maxSize));


and replace it with something like:
Code: › list($ret,$html, $head) = GalleryEmbed::getImageBlock(array('blocks'=>$blockType,'show'=>$display,'itemId'=>1234,'itemFrame'=>'solid','albumFrame'=>'solid','maxSize' => $maxSize));


Remember to find out the itemId number of the album of your choice...

This method works fabulously Smile

Cheers,
Richard (menelaos61)


this works for G2, but slackbladder is enquiring about G1 Smile
Back to top
Offline View user's profile Send private message Visit poster's website
slackbladder

Moderator
Moderator


Joined: Mar 29, 2003
Posts: 1038
Location: Cambs,UK

PostPosted: Fri Mar 03, 2006 7:35 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

Hi Dari,

Does the 'hacked' block create / re-build the cache file (so new photo's when added to the album are also added to the cache i.e. the cache number increases)?
Back to top
Offline View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Mar 03, 2006 7:39 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

no, this is a quick and dirty hack. it doesn't use a cache file at all, just an array that you populate with your albums by hand (i thought that's what you wanted)...however, updating the array with the proper values shouldn't be too hard...
Back to top
Offline View user's profile Send private message Visit poster's website
slackbladder

Moderator
Moderator


Joined: Mar 29, 2003
Posts: 1038
Location: Cambs,UK

PostPosted: Fri Mar 03, 2006 7:46 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

What I am after (and have it working just about using the selectable block) is:

From the block code I can select (hard code) an album from which the random block pulls an image from.

I currently use a different 'cache' file for each album (e.g. album1-random.cache, album2-random.cache)

I need for the code to rebuild each seperate cache, using it's hardcoded album images.

The reason all this is that I have built a site (music) that has sections dedicated to different artists, each artist has a section the gallery for his photos.

Please review:

http://www.classicalx.com

then an artist page:

http://www.classicalx.com/Andrea_Bocelli.html

Random block is on the left.

Many thanks for the help Smile
Back to top
Offline View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
LuckyMcGee

Beginner
Beginner


Joined: Jan 17, 2006
Posts: 17

PostPosted: Sat Jun 17, 2006 2:17 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

I'm getting MySQL errors when attempting to use it with Gallery2. Confused

[edit] If this is only for Gallery1, is there a way to eliminate certain albums from displaying in the random photo block in G2?? [/edit]

Thanks!

Errors received:

Code: › Warning: main(/home/.alonso/xxxx/the152.com/modules/gallery2/init.php): failed to open stream: No such file or directory in /home/.alonso/xxxx/the152.com/NG-RandomPhotoSelectTest_functions.php on line 61

Fatal error: main(): Failed opening required '/home/.alonso/xxxx/the152.com/modules/gallery2/init.php' (include_path='.:/usr/local/lib/php') in /home/.alonso/xxxx/the152.com/NG-RandomPhotoSelectTest_functions.php on line 61
Back to top
Offline View user's profile Send private message Visit poster's website
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Sat Jun 17, 2006 7:44 am    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

that block is only for g1. you can via album properties in g2, "hide" the album from imageblock.
Back to top
Offline View user's profile Send private message Visit poster's website
LuckyMcGee

Beginner
Beginner


Joined: Jan 17, 2006
Posts: 17

PostPosted: Tue Jun 20, 2006 6:29 pm    Post subject: Re: [TESTING] Selectable Album Random Block Reply with quote

I hate when I post, and then find the answer 2 seconds later. Embarassed Laughing
Back to top
Offline View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Integration » Blocks View previous topicPrinter friendly versionView next topic
Goto page Previous  1, 2, 3, 4, 5, 6, 7

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours

Powered by phpBB © phpBB Group



Sponsors: Dedicated ServersDomain NamesWeb HostingDomain Name RegistrationDedicated Web HostingWeb Design New YorkCompare VoIPseo packagesSEO CompanyNew York Yellow PagesFind LocationsVOIP Phone ServiceNeckermannOnline internetSEORestaurant Locator • Get great HP coupons from CouponSnapshot • Search for great dell coupons at CouponSnapshot.com.au • Graduation DressesAndroid TabletSEO IndiaBuy Phen375fuel filter

8th year online! 2003-2011
Legal • Use of this site consitutes agreement to the Acceptable Use Policy
Hosted by Implosion WorksSourceForge.net Logo • Theme by TonicMedia