I know this is low on the priority list, but I thought it wouldn't hurt to ask in case someone figured the problem out and just has never posted the answer here. I've been playing with the random block as a standalone. I'd like to incorporate it into my online journal. While it works pretty well, it does throw an error message pretty regularly, that seems directly connected to the fact that it is trying to call upon the image that is used as the highlight photo for a sub-album. For some reason the code chokes on that. That is the only problem I've encountered, and I don't know enough to know how to fix it.
The error message is:
Fatal error: Call to a member function on a non-object in /home/virtual/***/fst/var/www/html/gallery/view_photo.php on line 70
This is the line being referred to in the view_photo.php:
list($imageWidth, $imageHeight) = $image->getRawDimensions();
Does anyone have this worked out?
Thanks!
Gaile
Posts: 54
Hi
I have this error too :
Fatal error: Call to a member function on a non-object in c:easyphp2wwwgalleryview_photo.php on line 70
it only happen when clicking on an image that is used as the highlight of a sub-album, but I also realized that this image should not be picked up by random block because it suppose to be hidden.
So I think the problem is more coming from the fact that random block is actually picking from pictures that are hidden than because these pictures are hightlight of a sub album.
But I don't have the answer.
phil
Posts: 54
HelOOooo !
I'm not kidding, random block is picking up hidden pictures !
anybody interested in this ?
phil
Posts: 77
Hi,
which block are you using?
Joerg
Posts: 54
Hi,
I'm using this code :
// Hack prevention.
if (!empty($HTTP_GET_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_POST_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_COOKIE_VARS["GALLERY_BASEDIR"])) {
print "Security violationn";
exit;
}
require($GALLERY_BASEDIR . "init.php");
if ($profile) {
$timer = time();
}
/* Initializing the seed */
srand ((double) microtime() * 1000000);
define(CACHE_FILE, $gallery->app->albumDir . "/block-random.cache");
define(CACHE_EXPIRED, 86400);
// 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 "<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><left><b>&middot;&nbsp;</b>"
."<a href=" .makeAlbumUrl($album->fields["name"]) .">View the Album"
// .$album->fields["title"] ceci est la ligne pour afficher le nom de lalbum
."</a></left>";
} else {
print "No photo chosen.";
}
if ($profile) {
$elapsed = time() - $timer;
print "<br>Elapsed: $elapsed secs";
}
/*
* --------------------------------------------------
* Support functions
* --------------------------------------------------
*/
function saveCache() {
global $cache;
if ($fd = fs_fopen(CACHE_FILE, "w")) {
foreach ($cache as $key => $val) {
fwrite($fd, "$key/$valn");
}
fclose($fd);
}
}
function readCache()
{
global $cache;
if ($fd = fs_fopen(CACHE_FILE, "r"))
{
while ($line = fgets($fd, 4096))
{
list($key, $val) = explode("/", trim($line));
$cache[$key] = $val;
}
fclose($fd);
}
}
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->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 != 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 ($everybody->canReadAlbum($tmpAlbum)) {
$seeHidden = $everybody->canWriteToAlbum($tmpAlbum);
$numPhotos = $tmpAlbum->numPhotos($seeHidden);
$name = $tmpAlbum->fields["name"];
if ($numPhotos > 0) {
$cache[$name] = $numPhotos;
}
}
}
}
?>