1

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 ?

4
  • 1
    You will need to look into URL rewriting via .htaccess. Aug 24, 2012 at 11:19
  • do you think so because it is more simple or impossible in php code Aug 24, 2012 at 11:29
  • What could be the reason for that? Not allowing caching for the clients?
    – feeela
    Aug 24, 2012 at 11:52
  • no I want to lower the TTFB of my website which is very high nearly 3 seconds Aug 24, 2012 at 12:12

1 Answer 1

-2

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.

2
  • can't I add a parameter to the existing function that chage the url ? Aug 24, 2012 at 12:13
  • Maybe allow $num='random', and then shuffle the result of glob.
    – Barmar
    Aug 24, 2012 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.