Well... the random-block doesn't have anything to do with pnphpbb2, so there shouldn't be any influence there. How are you using the random block? Just as a normal postnuke module?
edfel
Joined: 2004-02-08
Posts: 7
Posted: Sun, 2004-08-01 09:37
if (pnModAvailable('your-gallery-name'))
include("http://your.server/modules.php?op=modload&name=your-gallery-name&file=index&include=block-random.php");
else
echo ' ';
I replace with my info, the block _was_ working. Thats the strage and odd part...
The block is blank only displays block title.
signe
Joined: 2003-07-27
Posts: 2322
Posted: Sun, 2004-08-01 18:53
Make sure that Gallery is initialized and activated in postnuke, or remove the 'if' and 'else' statements.
skyttegaard
Joined: 2003-07-21
Posts: 14
Posted: Wed, 2004-09-08 11:42
edfel wrote:
... the block _was_ working. Thats the strage and odd part...
The block is blank only displays block title.
I've just experienced exactly the same problem - block has been working for some time - suddenly stops showing images.
Block is still displayed with no errors - it just doesn't show a picture.
Link to my site is: http://www.skyttegaard.com/postnuke/index.php
I'll let you know if I get it sorted out.
- Peter -
skyttegaard
Joined: 2003-07-21
Posts: 14
Posted: Wed, 2004-09-08 12:42
Well - I managed to get it working again but I'm not sure what the problem really was.
I moved the following files from the postnuke_home/modules/gallery/album/ directory:
block-random.cache
block-random.dat
block-random.dat.bak
block-random.dat.lock
and them I copied them back into the same directory as the user running my Apache server (in my case, it's nobody) - then everything worked again.
skyttegaard
Joined: 2003-07-21
Posts: 14
Posted: Thu, 2004-09-09 18:20
Problem returned after 24 hours. It seems that the problem is in the rebuild part of block-random.php
When the random block is called, it checks the age of the cache file:
if ($rebuild) {
scanAlbums();
saveCache();
} else {
readCache();
}
If the cache file does not exist or is older than the max cache time, the scanAlbum and saveCache functions are called.
These functions are supposed to scan all albums and update the cache file. Problem is, that this apparently doesn't work under Postnuke. In my case, if calls the functions correctly but doesn't update the cache file - which in turn means that the cache file stays outdated, and the random block keeps calling the rebuild part without showing pictures.
You can check the time stamp on your cache file - probably:
Postnuke_home/modules/gallery/album/block-random.dat
If it's older than your max cache time, it will attempt the rebuild which then fails.
When I call the random block directly, it correctly discovers the old cache file and performs the rebuild - including update of the cache file - and then everything works fine until the next cache expiry time.
That should update the file and show a random picture - it will then also work in Postnuke for some time.
I don't know why the rebuil doesn't work under Postnuke.
- Peter -
signe
Joined: 2003-07-27
Posts: 2322
Posted: Thu, 2004-09-09 20:59
skyttegaard, which version of Gallery are you running? That code is not what's in the 1.4.4 version of block-random.php.
Particularly, the 'CACHE_EXPIRED' should be a Gallery variable, not a defined value like it is in what you pasted. There was lots of other work done, too.
skyttegaard
Joined: 2003-07-21
Posts: 14
Posted: Fri, 2004-09-10 06:45
Gallery version is 1.4.4-pl1
The CACHE_EXPIRED is a gallery variable defined in gallery\config.php
It may well be, however, that my gallery\block-random.php is a leftover from an older version, which could explain the problem - the full code of the file I have is:
<?
/*
* 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.
*
* $Id: block-random.php,v 1.3.4.3 2004/07/28 03:46:11 cryptographite Exp $
*/
/*
* 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.
*
* If your Gallery is embedded and you call it via an URL,
* make sure you are giving the needed paramters.
*
* *Nuke:
* http://<URL to your Nuke>/modules.php?op=modload&name=gallery&file=index&include=block-random.php
*
* Mambo:
* http://<URL to Mambo>/index.php?option=com_gallery&Itemid=XXX
*/
require(dirname(__FILE__) . "/init.php");
/* Initializing the seed */
srand ((double) microtime() * 1000000);
/*
* 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;
}
That is definitely not the version of block-random that comes with 1.4.4
skyttegaard
Joined: 2003-07-21
Posts: 14
Posted: Fri, 2004-09-10 15:31
I admit that it looks different because the Gallery Forum deletes all leading spaces so you can't see the code hierachy.
But apart from that, it looks to me as the code included in 1.4.4
signe
Joined: 2003-07-27
Posts: 2322
Posted: Fri, 2004-09-10 17:10
I must have been really tired when I responded last night, because I completely missed this part...
as well as the header and file revision from CVS. Yes.. it is from 1.4.4
I can't say why you're running into the issue you are, since many, many people run the random-block from inside nuke with no issues. Unless your postnuke and gallery installations run as different users on the webhost, I can't see any reason why this would fail.
How do you include the random block in your nuke block? Do you use the web include, or a file include. (http://..., or /home/...)
skyttegaard
Joined: 2003-07-21
Posts: 14
Posted: Sat, 2004-09-11 20:09
I use the random block as a web include in a Core/PHP block:
if (pnModAvailable('gallery'))
include("http://skyttegaard.com/postnuke/modules.php?op=modload&name=gallery&file=index&include=block-random.php");
else
echo ' ';
I just did a complete reinstall of Gallery and that solved the problem. Guess I must have messed up the previous installation somehow.
Posts: 2322
Well... the random-block doesn't have anything to do with pnphpbb2, so there shouldn't be any influence there. How are you using the random block? Just as a normal postnuke module?
Posts: 7
if (pnModAvailable('your-gallery-name'))
include("http://your.server/modules.php?op=modload&name=your-gallery-name&file=index&include=block-random.php");
else
echo ' ';
I replace with my info, the block _was_ working. Thats the strage and odd part...
The block is blank only displays block title.
Posts: 2322
Make sure that Gallery is initialized and activated in postnuke, or remove the 'if' and 'else' statements.
Posts: 14
I've just experienced exactly the same problem - block has been working for some time - suddenly stops showing images.
Block is still displayed with no errors - it just doesn't show a picture.
Link to my site is: http://www.skyttegaard.com/postnuke/index.php
I'll let you know if I get it sorted out.
- Peter -
Posts: 14
Well - I managed to get it working again but I'm not sure what the problem really was.
I moved the following files from the postnuke_home/modules/gallery/album/ directory:
block-random.cache
block-random.dat
block-random.dat.bak
block-random.dat.lock
and them I copied them back into the same directory as the user running my Apache server (in my case, it's nobody) - then everything worked again.
Posts: 14
Problem returned after 24 hours. It seems that the problem is in the rebuild part of block-random.php
When the random block is called, it checks the age of the cache file:
// 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();
}
If the cache file does not exist or is older than the max cache time, the scanAlbum and saveCache functions are called.
These functions are supposed to scan all albums and update the cache file. Problem is, that this apparently doesn't work under Postnuke. In my case, if calls the functions correctly but doesn't update the cache file - which in turn means that the cache file stays outdated, and the random block keeps calling the rebuild part without showing pictures.
You can check the time stamp on your cache file - probably:
Postnuke_home/modules/gallery/album/block-random.dat
If it's older than your max cache time, it will attempt the rebuild which then fails.
When I call the random block directly, it correctly discovers the old cache file and performs the rebuild - including update of the cache file - and then everything works fine until the next cache expiry time.
You can try the same by entering the URL:
http://your_postnuke_home/modules/gallery/block-random.php
That should update the file and show a random picture - it will then also work in Postnuke for some time.
I don't know why the rebuil doesn't work under Postnuke.
- Peter -
Posts: 2322
skyttegaard, which version of Gallery are you running? That code is not what's in the 1.4.4 version of block-random.php.
Particularly, the 'CACHE_EXPIRED' should be a Gallery variable, not a defined value like it is in what you pasted. There was lots of other work done, too.
Posts: 14
Gallery version is 1.4.4-pl1
The CACHE_EXPIRED is a gallery variable defined in gallery\config.php
It may well be, however, that my gallery\block-random.php is a leftover from an older version, which could explain the problem - the full code of the file I have is:
<?
/*
* 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.
*
* $Id: block-random.php,v 1.3.4.3 2004/07/28 03:46:11 cryptographite Exp $
*/
/*
* 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.
*
* If your Gallery is embedded and you call it via an URL,
* make sure you are giving the needed paramters.
*
* *Nuke:
* http://<URL to your Nuke>/modules.php?op=modload&name=gallery&file=index&include=block-random.php
*
* Mambo:
* http://<URL to Mambo>/index.php?option=com_gallery&Itemid=XXX
*/
require(dirname(__FILE__) . "/init.php");
/* 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 (!empty($album)) {
$index = choosePhoto($album);
}
if (!empty($index)) {
$id = $album->getPhotoId($index);
echo ""
. "<center><a href=" . makeAlbumUrl($album->fields["name"], $id) . ">"
. $album->getThumbnailTag($index)
. "</a></center>";
$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 "<center>No photo chosen.</center>";
}
/*
* --------------------------------------------------
* 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;
} elseif ($count == 1) {
$choose = 1;
if ($album->isAlbum($choose)) {
return null;
}
} else {
$choose = rand(1, $count);
$wrap = 0;
while ($album->isHiddenRecurse($choose) || $album->isAlbum($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;
}
}
}
}
?>
Posts: 2322
That is definitely not the version of block-random that comes with 1.4.4
Posts: 14
I admit that it looks different because the Gallery Forum deletes all leading spaces so you can't see the code hierachy.
But apart from that, it looks to me as the code included in 1.4.4
Posts: 2322
I must have been really tired when I responded last night, because I completely missed this part...
as well as the header and file revision from CVS. Yes.. it is from 1.4.4
I can't say why you're running into the issue you are, since many, many people run the random-block from inside nuke with no issues. Unless your postnuke and gallery installations run as different users on the webhost, I can't see any reason why this would fail.
How do you include the random block in your nuke block? Do you use the web include, or a file include. (http://..., or /home/...)
Posts: 14
I use the random block as a web include in a Core/PHP block:
if (pnModAvailable('gallery'))
include("http://skyttegaard.com/postnuke/modules.php?op=modload&name=gallery&file=index&include=block-random.php");
else
echo ' ';
I just did a complete reinstall of Gallery and that solved the problem. Guess I must have messed up the previous installation somehow.
Thanks.
- Peter -