Random Block does not show up

msteinhoff

Joined: 2004-07-15
Posts: 6
Posted: Thu, 2004-07-15 21:05

I have installed Gallery as a module, that works great ! I followed the directions in gallery/contrib and made the approriate changes to module.php, problem is that whne I add the Random block..nothing shows up.

Not sure that Info you need..ask and you shall receive.

Thanks

 
signe
signe's picture

Joined: 2003-07-27
Posts: 2322
Posted: Thu, 2004-07-15 21:10

What CMS are you using?
Which version of Gallery?
Which Random Block?
How are you trying to run the Random Block?

 
msteinhoff

Joined: 2004-07-15
Posts: 6
Posted: Thu, 2004-07-15 23:19

CMS? Not sure what you mean.

I'm running:

php-nuke 7.2
gallery v.1.4.4-RC1
the random block that comes with gallery...it's in the gallery dir
I am adding it though pnp-nuke admin...blocks

 
signe
signe's picture

Joined: 2003-07-27
Posts: 2322
Posted: Thu, 2004-07-15 23:25
Quote:
I am adding it though pnp-nuke admin...blocks

Ok.. but how are you adding it? What text/code are you using?

 
msteinhoff

Joined: 2004-07-15
Posts: 6
Posted: Fri, 2004-07-16 00:03

well...I copied the block-random.php from the gallery dir to the block dir, then went to the admin section, clicked on blocks, scrolled down and the selected Random from the drop down list, then hit add. I'm kind of new to php-nuke(hard to believe I know). This is the code:

<?
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2004 Bharat Mediratta
*
* 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.
*/

/*
* This block selects a random photo for display. It will only display photos
* from albums that are visible to the public. It will not display hidden
* photos.
*
* Once a day (or whatever you set CACHE_EXPIRED to) we scan all albums and
* create a cache file listing each public album and the number of photos it
* contains. For all subsequent attempts we use that cache file. This means
* that if you change your albums around it may take a day before this block
* starts (or stops) displaying them.
*/

require(dirname(__FILE__) . "/init.php");

if (!empty($profile)) {
$timer = time();
}

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

define('CACHE_FILE', $gallery->app->albumDir . "/block-random.dat");
define('CACHE_EXPIRED', $gallery->app->blockRandomCache);

// Check the cache file to see if it's up to date
$rebuild = 1;
if (fs_file_exists(CACHE_FILE)) {
$stat = fs_stat(CACHE_FILE);
$mtime = $stat[9];
if ((time() - $mtime) < CACHE_EXPIRED) {
$rebuild = 0;
}
}

if ($rebuild) {
scanAlbums();
saveCache();
} else {
readCache();
}

$album = chooseAlbum();

if ($album) {
$index = choosePhoto($album);
}

if (isset($index)) {
$id = $album->getPhotoId($index);
echo ""
."<a href=" .makeAlbumUrl($album->fields["name"], $id) .">"
.$album->getThumbnailTag($index)
."</a>";

$caption = $album->getCaption($index);
if ($caption) {
echo "<br><center>$caption</center>";
}

echo "<br><center>From: "
."<a href=" .makeAlbumUrl($album->fields["name"]) .">"
.$album->fields["title"]
."</a></center>";
} else {
print "No photo chosen.";
}

if (!empty($profile)) {
$elapsed = time() - $timer;
print "<br>Elapsed: $elapsed secs";
}

/*
* --------------------------------------------------
* Support functions
* --------------------------------------------------
*/

function saveCache() {
global $cache;
safe_serialize($cache, CACHE_FILE);
}

function readCache() {
global $cache;

$sCache = getFile(CACHE_FILE);
$cache = unserialize($sCache);
}

function choosePhoto($album) {
global $cache;

$count = $cache[$album->fields["name"]];
if ($count == 0) {
// Shouldn't happen
return null;
} else if ($count == 1) {
$choose = 1;
} else {
$choose = rand(1, $count);
$wrap = 0;
if ($album->isHiddenRecurse($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 (empty($choose)) {
$choose = $name;
}

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

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

function scanAlbums() {
global $cache;
global $gallery;

$cache = array();
$everybody = $gallery->userDB->getEverybody();
$albumDB = new AlbumDB();
foreach ($albumDB->albumList as $tmpAlbum) {
if ($tmpAlbum->canReadRecurse($everybody->getUid()) && !$tmpAlbum->isHiddenRecurse()) {
$seeHidden = $everybody->canWriteToAlbum($tmpAlbum);
$numPhotos = $tmpAlbum->numPhotos($seeHidden);
$name = $tmpAlbum->fields["name"];
if ($numPhotos > 0) {
$cache[$name] = $numPhotos;
}
}
}
}
?>

 
signe
signe's picture

Joined: 2003-07-27
Posts: 2322
Posted: Fri, 2004-07-16 01:18
 
msteinhoff

Joined: 2004-07-15
Posts: 6
Posted: Fri, 2004-07-16 01:46

ok but it has no instructions for php-nuke 7.2.....? and....

This is the current themesidebox function:

function themesidebox($title, $content) {
echo "<table border=\"0\" align=\"center\" width=\"138\" cellpadding=\"0\" cellspacing=\"0\">"
."<tr><td background=\"themes/DeepBlue/images/table-title.gif\" width=\"138\" height=\"20\">"
."&amp;&amp;&amp;&amp;&amp;<font color=\"#FFFFFF\"><b>$title</b></font>"
."</td></tr><tr><td><img src=\"themes/DeepBlue/images/pixel.gif\" width=\"100%\" height=\"3\"></td></tr></table>\n"
."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"138\">\n"
."<tr><td width=\"138\" bgcolor=\"#000000\">\n"
."<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"138\">\n"
."<tr><td width=\"138\" bgcolor=\"#ffffff\">\n"
."$content"
."</td></tr></table></td></tr></table><br>";
}

do i change it to:

function themesidebox($title, $content)
if (@file_exists($content)) {
$fp = fopen ($content, "r");
$content = fread($fp, filesize($content));
fclose ($fp);
$content = "?>$content<?";
$content = eval($content);
} else if (eregi("^http", $content)) {
$fp = fopen ($content, "r");
$content = fread($fp, 65535);
fclose ($fp);
}

{
echo "<table border=\"0\" align=\"center\" width=\"138\" cellpadding=\"0\" cellspacing=\"0\">"
."<tr><td background=\"themes/DeepBlue/images/table-title.gif\" width=\"138\" height=\"20\">"
."&amp;&amp;&amp;&amp;&amp;<font color=\"#FFFFFF\"><b>$title</b></font>"
."</td></tr><tr><td><img src=\"themes/DeepBlue/images/pixel.gif\" width=\"100%\" height=\"3\"></td></tr></table>\n"
."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"138\">\n"
."<tr><td width=\"138\" bgcolor=\"#000000\">\n"
."<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"138\">\n"
."<tr><td width=\"138\" bgcolor=\"#ffffff\">\n"
."$content"
."</td></tr></table></td></tr></table><br>";
}

Lastly I have no idea how to do thi slast part:

Then create an HTML block containing the following url (change the text in red to be appropriate for your server:
http://your.server/modules.php?op=modload&name=your-gallery-name&file=index&include=block-random.php

 
msteinhoff

Joined: 2004-07-15
Posts: 6
Posted: Fri, 2004-07-16 02:41

ok i figured out most if it...got the box created...put the code in..but still no photo...the box shows up now...but somethings still not right.

www.thesteinhoffs.com

if you want to take a look

 
signe
signe's picture

Joined: 2003-07-27
Posts: 2322
Posted: Fri, 2004-07-16 03:07

The instructions for postnuke .7 are what you need to look at. Postnuke is not 7.2, it's .72.

You don't need to change ANY code to use the random block. You just insert the one line into a Core-PHP block.

 
msteinhoff

Joined: 2004-07-15
Posts: 6
Posted: Fri, 2004-07-16 03:32

ok..but im running php-nuke..

i'll take a look..
(edit)

I made the .7 changes like you suggested..the code show up in the box.

 
rudolfpietersma

Joined: 2003-01-09
Posts: 45
Posted: Tue, 2004-08-17 13:27

Where can I change this:

themesidebox() function ??

Rudolff.