I am trying to post this php code with a variable or if needed variables on my tpl file but I am having no luck.

  $secret = "user_name";
  $uri_prefix = "/dl/";

  # filename
  # please note file name starts with "/"
  $f = /test/test1.mp4;

  # current timestamp
  $t = time();

  $t_hex = sprintf("%08x", $t);
  $m = md5($secret.$f.$t_hex);

  # generate link

  $vfn = "http://this_is_where_url_goes.com".sprintf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f);

This is my php file that already displays code correctly on my tpl file I just need to add the above code to it correctly.

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {getTrailerAttribs} function plugin
 *
 * Type:     function<br>
 * Name:     getTrailerAttribs<br>
 * Purpose:  <br>
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_getTrailerAttribs($params, &$smarty)
{
	if ( @$trailer = new ffmpeg_movie($params['trailerLocation']) ) {


	$trailerAttribs = array( 'width' => $trailer->getFrameWidth(), 'height' => $trailer->getFrameHeight() );
	$smarty->assign("trailerWidth", $trailerAttribs['width']);
	$smarty->assign("trailerHeight", $trailerAttribs['height']);


}


}

Someone please help 🙂

    Use php, code and html tags as appropriate when posting code.

    It is not at all clear what you are trying to do or what isn't working. There is no apparent connection between the two blocks of php code.

    ezra1973;10966734 wrote:

    This is my php file that already displays code correctly on my tpl file I just need to add the above code to it correctly.

    The php code does not display code in any tpl files. The php code can generate output, and it can assign data to template variables that are used to generate output in the template file.
    You should not add php code to any template file.

    # The function does not return a string, it returns null. The doc block is
    # correct though - your plugin should return a string
    /**
     * @return string
     */
    
    # If the only thing the function deals with are dimensions, why not call it
    # ..._getTrailerDimensions?
    function smarty_function_getTrailerAttribs($params, &$smarty)
    {
    	# Why is the error supression operator needed?
        if ( @$trailer = new ffmpeg_movie($params['trailerLocation']) ) {
    		# Why use an array that is not used for anything but the equivalent of the
    		# two function calls you allready perform: getFrameWidth(), getFrameHeight?
    		/* just remove it
            $trailerAttribs = array( 'width' => $trailer->getFrameWidth(), 'height' => $trailer->getFrameHeight() );
            */
    
    	# This is a bad idea. Once your plugins start assigning to smarty variables
    	# you have a high risk of ending up overwriting variables that are allready
    	# in use, and then you have a really hard time of debugging ahead of you.
    	# Still, this is where your member function calls should have been made
    	/* Just remove this part as well
    	$smarty->assign("trailerWidth", $trailer->getFrameWidth());
    	$smarty->assign("trailerHeight", $trailer->getFrameHeight());
    	*/
    
    	# This is how you should do it
    	return 'width: '.$trailer->getFrameWidth().'; height: '.$trailer->getFrameHeight().';';
    
    	# Or possibly like this
    	return 'width="'.$trailer->getFrameWidth().'" height="'.$trailer->getFrameHeight().'"';
    }
    } 
    

    It's also very likely that this plugin isn't needed, and that you could instead do

    width: {trailer->getWidth()}; height: {$trailer->getHeight()};
    

    The trailer should of course be assigned to a smarty variable first, and that's done in php code before the template is displayed.

      The code I am trying to add talks to my streaming server. The code that is already in place and works plays trailers. I want to move the trailers to my streaming server. I need to add the new code so it provides a token for videos to play so its secure and no one can hotlink to my video clips. Thats the purpose of the extra code that needs to be added.

        If what you assign to $vfn is all you need, then just assign that to a smarty variable

        $smarty->assign('vfn', $vfn);
        

        and then wherever you need it

        {$vfn}
        

        Or, if you need the same things for several different videos

        $smarty->assign('vfn', sprintf('http://this_is_where_url_goes.com%s%s/%s', $uri_prefix, $m, $t_hex));
        

        and then as you loop or plugins/block (e.g. block.videolist.php) through a list of several videos

        {$vnf}{$videoarray[i].filename}
        <!-- or -->
        {videolist}
            {$vnf}{$current_video_item_from_videolist}
        {/videolist}
        
          Write a Reply...