Welcome to Geeklog, Anonymous Tuesday, December 10 2024 @ 07:08 pm EST
Geeklog Forums
Here's the code for showing a Random Image (4images)
Lacy
Anonymous
Add the following code to lib-custom.php (at the bottom - right before the ?>
function phpblock_rand4image() {
global $_CONF, $_USER, $_TABLES;
$imgdir = "photos";
$title_limit = 30;
$dscp_limit = 50;
// DATABASE
$rand_sql = DB_query("SELECT image_id,cat_id,image_name,image_description,image_thumb_file FROM 4images_images WHERE (image_thumb_file!='')ORDER BY RAND(NOW()) LIMIT 1");
$num = DB_numRows($rand_sql);
if ($num == 0) {
$rand .= '<br/><center>No images exist yet!</center><br/>';
} else {
$A = DB_fetchArray($rand_sql);
$album = DB_getItem("4images_categories",cat_name,"cat_id=$A[cat_id]");
if(strlen ($A['image_name']) > $title_limit){
$A['image_name'] = substr($A['image_name'], 0, $title_limit);
$A['image_name'] .= "..";
}
$rand .='<table width="98%"><td width="100%">';
$rand .='<center><a href="' .$_CONF['site_url']. '/' .$imgdir. '/details.php?image_id=' .$A['image_id']. '">';
$rand .='<img src="' .$_CONF['site_url']. '/' .$imgdir. '/data/thumbnails/' .$A['cat_id']. '/' .$A['image_thumb_file']. '" alt="' .$A['image_name']. '" style="border: 1 solid #000000;"><br>';
$rand .=$A['image_name'];
$rand .='</a></center>';
$rand .='<br>Album: <a href="' .$_CONF['site_url']. '/' .$imgdir. '/categories.php?cat_id=' .$A['cat_id']. '">' .$album. '</a>';
$rand .='</td></table>';
return $rand;
}
}
Now - create a new block.
Type - PHP Block.
Block Function - phpblock_rand4image
You're all set!
Text Formatted Code
// RANDOM IMAGE FUNCTIONfunction phpblock_rand4image() {
global $_CONF, $_USER, $_TABLES;
$imgdir = "photos";
$title_limit = 30;
$dscp_limit = 50;
// DATABASE
$rand_sql = DB_query("SELECT image_id,cat_id,image_name,image_description,image_thumb_file FROM 4images_images WHERE (image_thumb_file!='')ORDER BY RAND(NOW()) LIMIT 1");
$num = DB_numRows($rand_sql);
if ($num == 0) {
$rand .= '<br/><center>No images exist yet!</center><br/>';
} else {
$A = DB_fetchArray($rand_sql);
$album = DB_getItem("4images_categories",cat_name,"cat_id=$A[cat_id]");
if(strlen ($A['image_name']) > $title_limit){
$A['image_name'] = substr($A['image_name'], 0, $title_limit);
$A['image_name'] .= "..";
}
$rand .='<table width="98%"><td width="100%">';
$rand .='<center><a href="' .$_CONF['site_url']. '/' .$imgdir. '/details.php?image_id=' .$A['image_id']. '">';
$rand .='<img src="' .$_CONF['site_url']. '/' .$imgdir. '/data/thumbnails/' .$A['cat_id']. '/' .$A['image_thumb_file']. '" alt="' .$A['image_name']. '" style="border: 1 solid #000000;"><br>';
$rand .=$A['image_name'];
$rand .='</a></center>';
$rand .='<br>Album: <a href="' .$_CONF['site_url']. '/' .$imgdir. '/categories.php?cat_id=' .$A['cat_id']. '">' .$album. '</a>';
$rand .='</td></table>';
return $rand;
}
}
Now - create a new block.
Type - PHP Block.
Block Function - phpblock_rand4image
You're all set!
12
13
Quote
Lacy
Anonymous
Oh and change
$imgdir = "photos";
to whatever directory you have 4images installed in. I have mine installed in the photos folder .. therefore I put PHOTOS there.
Later!
$imgdir = "photos";
to whatever directory you have 4images installed in. I have mine installed in the photos folder .. therefore I put PHOTOS there.
Later!
13
14
Quote
Lacy
Anonymous
I have it working with two versions - 1.3.10 and 1.3.9sr1. I haven't tested it out in other versions.
(I'm still working on getting 1.3.10 to fully integrate with 4images. The coe has changed and the integration hack doesn't work completely. But you don't have to have it integrated for this to work.)
(I'm still working on getting 1.3.10 to fully integrate with 4images. The coe has changed and the integration hack doesn't work completely. But you don't have to have it integrated for this to work.)
17
11
Quote
Status: offline
deesh123
Forum User
Junior
Registered: 01/04/05
Posts: 22
For some dumb reason when I integrated 4images with GL, I put my 4images directory inside of another directory.
So my address to my photo album iis www.mysite.com/mypics/4images/index.php.
Everything worked fine up until when I tried to apply the code for showing a random image. Since I have an extra folder, the random image code sends the user to
http://www.mysite.com/public_html/gallery/details.php?image_id=8
instead of
http://www.mysite.com/mypics/4images/details.php?image_id=8
What is the best way to alter the code to work with my extra directory?
So my address to my photo album iis www.mysite.com/mypics/4images/index.php.
Everything worked fine up until when I tried to apply the code for showing a random image. Since I have an extra folder, the random image code sends the user to
http://www.mysite.com/public_html/gallery/details.php?image_id=8
instead of
http://www.mysite.com/mypics/4images/details.php?image_id=8
What is the best way to alter the code to work with my extra directory?
18
15
Quote
All times are EST. The time is now 07:08 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content