Random box click to main gallery

doogie

Joined: 2004-01-11
Posts: 14
Posted: Wed, 2006-02-08 19:55

Now if you click random box it opens the picture that it was on. Is there away to make it open main gallery instead of just that picture?

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Wed, 2006-02-08 22:03

Edit the random block module and replace the url part with the url to your gallery.

 
Jonathan Pikey

Joined: 2006-02-08
Posts: 8
Posted: Wed, 2006-02-08 23:41
ckdake wrote:
Edit the random block module and replace the url part with the url to your gallery.

Thanks alot ckdake! Had this problem too, gonna try it out tonight.

 
doogie

Joined: 2004-01-11
Posts: 14
Posted: Thu, 2006-02-09 00:44

I don't see where to do that.

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Thu, 2006-02-09 05:41

doogie: I think you'll need to edit the code in gallery2/modules/imageblock/classes/ImageBlockHelper.class

 
doogie

Joined: 2004-01-11
Posts: 14
Posted: Thu, 2006-02-09 10:22

Im useing gallery 1.5

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Fri, 2006-02-10 05:15

ah, my apologies! Didn't notice what forum this was in.. take a look at gallery/block-random.php. changing $gallery->html_wrap['imageHref'] = $photoUrl; to $gallery->html_wrap['imageHref'] = $albumUrl; should do the trick.

 
doogie

Joined: 2004-01-11
Posts: 14
Posted: Sat, 2006-02-11 06:39

I dont see anything like that.

global $GALLERY_NO_SESSIONS;
global $GALLERY_BASEDIR;
global $GALLERY_EMBEDDED_INSIDE;
global $GALLERY_EMBEDDED_INSIDE_TYPE;
global $GALLERY_MODULENAME;
global $gallery;

$GALLERY_MODULENAME = "gallery"; //Change this to your module Name
$GALLERY_BASEDIR = "modules/$GALLERY_MODULENAME/";
$GALLERY_EMBEDDED_INSIDE = "postnuke";
$GALLERY_EMBEDDED_INSIDE_TYPE = $GALLERY_EMBEDDED_INSIDE;
$GALLERY_NO_SESSIONS = true;

require_once($GALLERY_BASEDIR . "init.php");
if (!$gallery->app->albumDir) {
include($GALLERY_BASEDIR . "config.php");
}

define(CACHE_FILE, $gallery->app->albumDir . "/block-random.cache");
define(CACHE_EXPIRED, 86400);

$blocks_modules['gallery_random'] = array(
'func_display' => 'blocks_gallery_random_block',
'func_edit' => 'blocks_gallery_random_edit',
'func_update' => 'blocks_gallery_random_update',
'func_add' => 'blocks_gallery_random_add',
'text_type' => 'gallery_random',
'text_type_long' => 'gallery Random Picture',
'allow_multiple' => true,
'form_content' => false,
'form_refresh' => false,
'show_preview' => true
);

// Mainfunction
function blocks_gallery_random_block($row)
{
global $GALLERY_NO_SESSIONS;
global $GALLERY_BASEDIR;
global $GALLERY_EMBEDDED_INSIDE;
global $GALLERY_MODULENAME;
global $gallery;
global $op;
global $mop;
global $include;
global $name;
global $borderColor;
global $borderWidth;

// Uncomment next line to show the run-time of the block
// at the end of execution (for performance tests)
//$profile = 1;

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

// Rogue Permission
pnSecAddSchema('gallery_random_block::', 'Block title::');

// Hack prevention.
if (!empty($HTTP_GET_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_POST_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_COOKIE_VARS["GALLERY_BASEDIR"])) {
print "Security violation\n";
exit;
}

//check for Rogue Permission
if (!pnSecAuthAction(0, 'gallery_random_block::', "$row[title]::", ACCESS_READ)) { return; }

$vars = getVarsFrom_gallery_random_Content($row);
$row['content'] = "";

// Thumbwitdh
$tmbwidth = $vars['tmbwidth'];
// Thumbheight
$tmbheight = $vars['tmbheight'];
// Save aspect ratio
$svaspect = $vars['svaspect'];
// Don't do any resize
$uresize = $vars['uresize'];
$uphoto = $vars['uphoto'];
$borderWidth = $vars['borderwidth'];
$borderColor = $vars['bordercolor'];
$albumname = $vars['albumname'];
$showcaption = $vars['showcaption'];
$showaname = $vars['showaname'];

$row['content'] = "";

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

// 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) OR pnUserLoggedIn()){
$rebuild = 0;
}
}

if (($rebuild) AND ($albumname == "none")){
scanAlbums();
saveCache();
}else{
readCache();
}

if ($albumname == "none") {
$album = chooseAlbum();
}else{
$album = New Album();
$album->load($albumname);
}

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

if (isset($index)) {
$id = $album->getPhotoId($index);

// Resize thumb when resizing is selected
if ($uresize != 0) {
$tmbTag = tmbresizeTag($album, $index, $tmbwidth, $tmbheight, $svaspect, $uphoto);
} else {
if ($uphoto == 0) {
$tmbTag = $album->getThumbnailTag($index);
}else{
$tmbTag = $album->getPhotoTag($index, $full=0);
}
}

if ($showcaption <> 0) {
$caption = $album->getCaption($index);
} else {
$caption ="";
}

$row['content'] = ""
."<center>"
.tmbdrawBorder($album, $id, $tmbTag, strtr($caption, '"', '`'))
."</center>";

//Print caption
if (($caption) AND ($showcaption == 1)) {
$row['content'] .= "<br><center>$caption</center>";
}

//Print album name and link
switch ($showaname) {
case 1: //Classic Style
$row['content'] .= "<br><center>Album: "
."<a href=" .makeAlbumUrl($album->fields["name"]) .">"
.$album->fields["title"]
."</a></center>";
break;
case 2: //Petkov Style
$row['content'] .= "<center>"
."<a href=" .makeAlbumUrl($album->fields["name"]) ." title=\"Visit the album\">"
.$album->fields["title"]
."</a></center>";
break;
}

} else {
$row['content'] .= "No photo chosen.";
}

if ($profile) {
$elapsed = time() - $timer;
$row['content'] .= "<br>Elapsed: $elapsed secs";
}

themesideblock($row);
}

function blocks_gallery_random_add($row)
{
$row['content']="tmbwidth=150\ntmbheight=113\nsvaspect=0\nuresize=0\nuphoto=0\nborderwidth=off\nbordercolor=black"
."\nshowcaption=1\nshowaname=1\nalbumname=none\n";
return $row;
}

function blocks_gallery_random_update($row)
{
global $HTTP_POST_VARS;
$row['content']= "tmbwidth=".$HTTP_POST_VARS['tmbwidth']."\ntmbheight=".$HTTP_POST_VARS['tmbheight']."\nsvaspect=".$HTTP_POST_VARS['svaspect']
."\nuresize=".$HTTP_POST_VARS['uresize']."\nuphoto=".$HTTP_POST_VARS['uphoto']."\nborderwidth=".$HTTP_POST_VARS['borderwidth']
."\nbordercolor=".$HTTP_POST_VARS['bordercolor']."\nalbumname=".$HTTP_POST_VARS['albumname']
."\nshowcaption=".$HTTP_POST_VARS['showcaption']."\nshowaname=".$HTTP_POST_VARS['showaname']."\n";
return($row);
}

function blocks_gallery_random_edit($row)
{
global $cache;
global $gallery;

$album = New Album();

if (fs_file_exists(CACHE_FILE)) {
readCache();
}

// Break out options from our content field
$vars = getVarsFrom_gallery_random_Content($row);

// Parameters for block parts. Part will not be shown if zero
// $output = "<tr><td class=\"pn-normal\">". "Galleryname " ."</td><td><input type=\"text\" name=\"galleryname\" size=\"15\" value=\"$vars[galleryname]\"></td></tr>";
$output = "<tr><td class=\"pn-normal\">". "Albumname " ."</td><td><select name=\"albumname\" size=\"1\" tabindex=\"3\">";

if ($vars['albumname'] == "none") {
$output .= "<option value=\"none\" selected>No special album</option>";
}else{
$output .= "<option value=\"none\">No special album</option>";
}

if (is_array($cache)) {
foreach ($cache as $name => $count) {
$album->load($name);
$longname = $album->fields['title'];
if ($vars['albumname'] == $name) {
$output .= "<option value=\"$name\" selected>$longname</option>";
}else{
$output .= "<option value=\"$name\">$longname</option>";
}
}
}

$output .= "</select></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Width of thumb (px) " ."</td><td><input type=\"text\" name=\"tmbwidth\" size=\"4\" value=\"$vars[tmbwidth]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Height of thumb (px) " ."</td><td><input type=\"text\" name=\"tmbheight\" size=\"4\" value=\"$vars[tmbheight]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Borderwidth (pixel/off='off') " ."</td><td><input type=\"text\" name=\"borderwidth\" size=\"3\" value=\"$vars[borderwidth]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Bordercolor: " ."</td><td><input type=\"text\" name=\"bordercolor\" size=\"20\" value=\"$vars[bordercolor]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Save aspect ratio (0=no/1=yes) " ."</td><td><input type=\"text\" name=\"svaspect\" size=\"1\" value=\"$vars[svaspect]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Use resize (0=no/1=yes) " ."</td><td><input type=\"text\" name=\"uresize\" size=\"1\" value=\"$vars[uresize]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Use photo not thumb (0=no/1=yes) " ."</td><td><input type=\"text\" name=\"uphoto\" size=\"1\" value=\"$vars[uphoto]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Show caption (0=no/1=Classic and Petkov/2=Petkov-Style only) " ."</td><td><input type=\"text\" name=\"showcaption\" size=\"1\" value=\"$vars[showcaption]\"></td></tr>";
$output .= "<tr><td class=\"pn-normal\">". "Show album name (0=no/1=Classic/2=Petkov-Style ) " ."</td><td><input type=\"text\" name=\"showaname\" size=\"1\" value=\"$vars[showaname]\"></td></tr>";
return $output;
}

////
// Get variables from content
// Format of variables:
// name=val
// name=val
////

function getVarsFrom_gallery_random_Content($row){
$links = explode("\n", $row['content']);
$vars = array();
foreach ($links as $link) {
$link = trim($link);
if ($link)
{
$var = explode("=", $link);
$vars = array_merge($vars, array($var[0] => $var[1]));
}
}
// Defaults
if (!isset($vars['tmbwidth']))
{
$vars['tmbwidth'] = 150;
}
if (!isset($vars['tmbheight']))
{
$vars['tmbheight'] = 113;
}
if (!isset($vars['svaspect']) OR (empty($vars['svaspect'])))
{
$vars['svaspect'] = 0;
}
if (!isset($vars['uresize']) OR (empty($vars['uresize'])))
{
$vars['uresize'] = 0;
}
if (!isset($vars['uphoto']) OR (empty($vars['uphoto'])))
{
$vars['uphoto'] = 0;
}
if (!isset($vars['borderwidth']) OR (empty($vars['borderwidth'])))
{
$vars['borderwidth'] = "off";
}
if (!isset($vars['bordercolor']) OR (empty($vars['bordercolor'])))
{
$vars['bordercolor'] = "black";
}

if (!isset($vars['albumname']) OR (empty($vars['albumname'])))
{
$vars['albumname'] = "none";
}

if (!isset($vars['showcaption']))
{
$vars['showcaption'] = 1;
}

if (!isset($vars['showaname']))
{
$vars['showaname'] = 1;
}
return($vars);
}

/*
* --------------------------------------------------
* Support functions (gallery)
* --------------------------------------------------
*/
function tmbdrawBorder($album, $id, $tmbTag, $caption="") {
global $GALLERY_BASEDIR;
global $borderColor;
global $borderWidth;

$imageDir = $GALLERY_BASEDIR . "images";
if (!strcmp($borderWidth, "off")) {
$borderColor = $album->fields["bgcolor"];
$borderWidth = 1;
}
$pixelImage = $imageDir . "/pixel_trans.gif";
$tag = $tmbTag;

//
//is it a highlight?
//
if ($id != "unknown") {
$href = makeAlbumUrl($album->fields["name"], $id);
}else{
$href = makeAlbumUrl($album->fields["name"]);
}

$output = "<table width=\"1%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$output .= "<tr bgcolor=\"$borderColor\">";
$output .= "<td colspan=\"3\" height=\"$borderWidth\"><img src=\"$pixelImage\" width=\"$borderWidth\" height=\"1\"></td>";
$output .= "</tr>";
$output .= "<tr>";
$output .= "<td bgcolor=\"$borderColor\" width=\"$borderWidth\"><img src=\"$pixelImage\" width=\"$borderWidth\" height=\"1\"></td>";
$output .= "<td><a href=\"$href\" title=\"$caption\">$tag</a></td>";
$output .= "<td bgcolor=\"$borderColor\" width=\"$borderWidth\"><img src=\"$pixelImage\" width=\"$borderWidth\" height=\"1\"></td></tr>";
$output .= "<tr bgcolor=\"$borderColor\">";
$output .= "<td colspan=\"3\" height=\"$borderWidth\"><img src=\"$pixelImage\" width=\"$borderWidth\" height=\"1\"></td>";
$output .= "</tr>";
$output .= "</table>";

return $output;
}

function tmbresizeTag($album, $index, $tmbwidth, $tmbheight, $svaspect, $uphoto) {
if ($uphoto == 0) {
$tmbTagDetails = explode(" ", $album->getThumbnailTag($index));
$tmbDimensions = $album->getThumbDimensions($index);
}else{
$tmbTagDetails = explode(" ", $album->getPhotoTag($index, $full=0));;
$tmbDimensions = array (substr($tmbTagDetails[2], strrpos($tmbTagDetails[2], "=")+1),substr($tmbTagDetails[3], strrpos($tmbTagDetails[3], "=")+1));
}
$tmbURL = trim($tmbTagDetails[1]);
$tmbBorder = trim($tmbTagDetails[5]);
if ($svaspect != 0) {

//Original aspect
$tmbratio = $tmbDimensions[0] / $tmbDimensions[1];

// Height is set
if ( ($tmbwidth == 0) AND ($tmbheight != 0) ) {
$tmbwidth = round($tmbheight * $tmbratio);
//prevent undesired upsizing of the image
if ($tmbwidth > $tmbDimensions[0]) {
$tmbwidth = $tmbDimensions[0];
$tmbheight = round($tmbwidth / $tmbratio);
}
}

// Width is set
if ( ($tmbwidth != 0) AND ($tmbheight == 0) ) {
$tmbheight = round($tmbwidth / $tmbratio);
//prevent undesired upsizing of the image
if ($tmbheight > $tmbDimensions[1]) {
$tmbheight = $tmbDimensions[1];
$tmbwidth = round($tmbheight * $tmbratio);
}
}

$tmboutput = "<img $tmbURL width=$tmbwidth height=$tmbheight $tmbBorder";
} else {
$tmboutput = "<img $tmbURL width=$tmbwidth height=$tmbheight $tmbBorder";
}
return $tmboutput;
}

function saveCache() {
global $cache;
if ($fd = fs_fopen(CACHE_FILE, "w")) {
foreach ($cache as $key => $val) {
fwrite($fd, "$key/$val\n");
}
fclose($fd);
}
}

function readCache() {
global $cache;
if ($fd = fs_fopen(CACHE_FILE, "r")) {
while ($line = fgets($fd, 4096)) {
list($key, $val) = explode("/", trim($line)); //trim-Fix from Mailing-List
$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)) {
#echo $tmpAlbum->fields["title"] . "-" . $everybody->getUsername();
$seeHidden = $everybody->canWriteToAlbum($tmpAlbum);
$numPhotos = $tmpAlbum->numPhotos($seeHidden);
$name = $tmpAlbum->fields["name"];
if ($numPhotos > 0) {
$cache[$name] = $numPhotos;
}
}
}
}

?>

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Sat, 2006-02-11 18:19

What version of Gallery are you using?

 
doogie

Joined: 2004-01-11
Posts: 14
Posted: Sat, 2006-02-11 23:25

1.5
I see now it in this part
//Print album name and link
switch ($showaname) {
case 1: //Classic Style
$row['content'] .= "<br><center>Album: "
."<a href=" .makeAlbumUrl($album->fields["name"]) .">"
.$album->fields["title"]
."</a></center>";
break;
case 2: //Petkov Style
$row['content'] .= "<center>"
."<a href=" .makeAlbumUrl($album->fields["name"]) ." title=\"Visit the album\">"
.$album->fields["title"]
."</a></center>";

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Sun, 2006-02-12 00:03

you should upgrade to the newest version as there have been several security fixes.

 
ckdake
ckdake's picture

Joined: 2004-02-18
Posts: 2258
Posted: Mon, 2006-04-10 02:07

I should get 1.5.3 uploaded tonight or tomorrow.

--
http://ckdake.com/

If you found my help useful, please consider donating to Gallery.

 
jklapp

Joined: 2006-04-26
Posts: 1
Posted: Wed, 2006-04-26 21:05
ckdake wrote:
Edit the random block module and replace the url part with the url to your gallery.

Hi :)

I'm running Gallery2. Could you please elaborate more on this?

Thank you :)