Question

I am using a video script and I want to randomize the url thumbs : there's a common.php that defines global vars for the thumbs dir and url :

define('THUMB_FILES_DIR',' ');
define('THUMB_FILES_URL','');
define('THUMBS_DIR',THUMB_FILES_DIR.'/thumbs');
define('THUMBS_URL',THUMB_FILES_URL.'/thumbs');

and the functions to get the thumbs are :

   /**
     * FUNCTION USED TO GET THUMBNAIL
     * @param ARRAY video_details, or videoid will also work
     */

function get_thumb($vdetails,$num='default',$multi=false,$count=false,$return_full_path=true,$return_big=true,$size=false){
        global $db,$Cbucket,$myquery;
        $num = $num ? $num : 'default';
        #checking what kind of input we have
        if(is_array($vdetails))
        {
            if(empty($vdetails['title']))
            {
                #check for videoid
                if(empty($vdetails['videoid']) && empty($vdetails['vid']) && empty($vdetails['videokey']))
                {
                    if($multi)
                        return $dthumb[0] = default_thumb();
                    return default_thumb();
                }else{
                    if(!empty($vdetails['videoid']))
                        $vid = $vdetails['videoid'];
                    elseif(!empty($vdetails['vid']))
                        $vid = $vdetails['vid'];
                    elseif(!empty($vdetails['videokey']))
                        $vid = $vdetails['videokey'];
                    else
                    {
                        if($multi)
                            return $dthumb[0] = default_thumb();
                        return default_thumb();
                    }
                }
            }
        }else{
            if(is_numeric($vdetails))
                $vid = $vdetails;
            else
            {
                if($multi)
                    return $dthumb[0] = default_thumb();
                return default_thumb();
            }
        }


        #checking if we have vid , so fetch the details
        if(!empty($vid))
            $vdetails = $myquery->get_video_details($vid);

        if(empty($vdetails['title']))
        {
            if($multi)
                    return default_thumb();
            return default_thumb();
        }

        #Checking if there is any custom function for
        if(count($Cbucket->custom_get_thumb_funcs) > 0)
        {

            foreach($Cbucket->custom_get_thumb_funcs as $funcs)
            {

                //Merging inputs
                $in_array = array(
                'num' => $num,
                'multi' => $multi,
                'count' => $count,
                'return_full_path' => $return_full_path,
                'return_big' => $return_big
                );
                if(function_exists($funcs))
                {
                    $func_returned = $funcs($vdetails,$in_array);
                    if($func_returned)
                    return $func_returned;
                }
            }
        }

        #get all possible thumbs of video
        if($vdetails['file_name'])
        $vid_thumbs = glob(THUMBS_DIR."/".$vdetails['file_name']."*");
        #replace Dir with URL
        if(is_array($vid_thumbs))
        foreach($vid_thumbs as $thumb)
        {
            if(file_exists($thumb) && filesize($thumb)>0)
            {
                $thumb_parts = explode('/',$thumb);
                $thumb_file = $thumb_parts[count($thumb_parts)-1];

                if(!is_big($thumb_file) || $return_big)
                {
                    if($return_full_path)
                        $thumbs[] = THUMBS_URL.'/'.$thumb_file;
                    else
                        $thumbs[] = $thumb_file;
                }
            }elseif(file_exists($thumb))
                unlink($thumb);
        }

        if(count($thumbs)==0)
        {
            if($count)
                return count($thumbs);
            if($multi)
                    return $dthumb[0] = default_thumb();
            return default_thumb();
        }
        else
        {
            if($multi)
                return $thumbs;
            if($count)
                return count($thumbs);

            //Now checking for thumb
            if($num=='default')
            {
                $num = $vdetails['default_thumb'];
            }
            if($num=='big' || $size=='big')
            {

                $num = 'big-'.$vdetails['default_thumb'];
                if(!file_exists(THUMBS_DIR.'/'.$vdetails['file_name'].'-'.$num.'.jpg'))
                $num = 'big';               
            }

            $default_thumb = array_find($vdetails['file_name'].'-'.$num,$thumbs);

            if(!empty($default_thumb))
                return $default_thumb;
            return $thumbs[0];
        }

    }

    /**
     * Function used to check weaether given thumb is big or not
     */
    function is_big($thumb_file)
    {
        if(strstr($thumb_file,'big'))
            return true;
        else
            return false;
    }
    function GetThumb($vdetails,$num='default',$multi=false,$count=false)
    {

        return get_thumb($vdetails,$num,$multi,$count);
    }

    /**
     * function used to get detaulf thumb of ClipBucket 
     */
    function default_thumb()
    {
        if(file_exists(TEMPLATEDIR.'/images/thumbs/processing.png'))
        {
            return TEMPLATEURL.'/images/thumbs/processing.png';
        }elseif(file_exists(TEMPLATEDIR.'/images/thumbs/processing.jpg'))
        {
            return TEMPLATEURL.'/images/thumbs/processing.jpg';
        }else
        return BASEURL.'/files/thumbs/processing.jpg';
    }

I want to randomize the thumbs url from which is serverd the images this way http://img[random number].domainname

if I create an array with the values of the thumbs url and then shuffle the result to the

define('THUMB_FILES_DIR',' ');
define('THUMB_FILES_URL','');

all the thumbs will have the same url value how to do to have different values passed to html pages ?

No correct solution

OTHER TIPS

Instead of using global variables for the thumbs url, you need to use a function. Then it can pick a URL at random when it's called.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top