Topics

User Functions

Events

There are no upcoming events

What's New

Stories

1 new Stories in the last 2 weeks

Comments last 2 weeks


Trackbacks last 2 weeks

No new trackback comments

Links last 2 weeks

No recent new links

NEW FILES last 14 days

No new files

Welcome to Geeklog Saturday, May 25 2013 @ 10:54 AM EDT


 Forum Index > Extensions > Cool Hacks New Topic Post Reply
 Here's the code for showing a Random Image (4images)
   
Anonymous: Lacy
 12/30/04 04:47PM (Read 3233 times)  



Add the following code to lib-custom.php (at the bottom - right before the ?>

PHP Formatted Code
// RANDOM IMAGE FUNCTION
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!

 
 Quote
Anonymous: Lacy
 01/02/05 04:44PM  



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!

 
 Quote
samstone
 01/02/05 05:17PM  
+++++
Full Member

Status: offline


Registered: 09/29/02
Posts: 820
Are you talking about 4image with GL1.3.11?

 
Profile Email
 Quote
Anonymous: Lacy
 01/02/05 06:36PM  



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.)

 
 Quote
deesh123
 03/06/05 08:56PM  
++---
Junior

Status: offline


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?

 
Profile Email
 Quote
deesh123
 03/09/05 11:27AM  
++---
Junior

Status: offline


Registered: 01/04/05
Posts: 22
I figured it out:

here

 
Profile Email
 Quote
Content generated in: 0.41 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to post 
Filtered HTML Allowed 
Censored Content