X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Random Youtube Video Player (https://forum.x-cart.com/showthread.php?t=55589)

minfinger 09-17-2010 01:13 PM

Random Youtube Video Player
 
My client has several Youtube Videos that we'd like to display in the left menu bar and have to randomly chosen on each refresh or load of any page.

I tried the AJAX Banner Script, but that just displays one every so many seconds. It's switching before the videos stop.

Is this possible?

cflsystems 09-17-2010 03:17 PM

Re: Random Youtube Video Player
 
Can't advise on that but I would suggest not to start the video on page load. Have the plugin there but let the customer to decide if they want to play it or not. If I get to a site which automatically plays video or music or some sort of animation that moves over the screen it makes me leave that site immediately and not come back.

minfinger 09-17-2010 03:20 PM

Re: Random Youtube Video Player
 
Steve,

Thanks for the comment. I had no intention of starting the video on load.

www.littlepuppiesonline.com

The videos show on the right hand side. Like I said using the AJAX just swaps out the Embedded code from YouTube. It's not randomizing the videos.

I did read a small tutorial about making an SQL Database to accomplish the randomization of the videos, but I think there should be an easier way.

cflsystems 09-17-2010 03:23 PM

Re: Random Youtube Video Player
 
Quote:

Originally Posted by minfinger
Steve,

Thanks for the comment. I had no intention of starting the video on load.

I see it. Yes, like this is acceptable :)
Sorry can't help you with the random load

Regs 09-18-2010 05:11 PM

Re: Random Youtube Video Player
 
Not sure how to use smarty plugins but perhaps with some further googling, you'll be able to find out and use the following:\

http://roblogic.net/tech/articles/4

Cheers,

Regs.

minfinger 09-21-2010 12:17 PM

Re: Random Youtube Video Player
 
I did find this, but it appears to be ASP based using an SQL DB. Any thoughts?

http://www.codeproject.com/KB/aspnet/PlayYouTubeVideo.aspx

minfinger 09-21-2010 12:18 PM

Re: Random Youtube Video Player
 
Quote:

Originally Posted by Regs
Not sure how to use smarty plugins but perhaps with some further googling, you'll be able to find out and use the following:\

http://roblogic.net/tech/articles/4

Cheers,

Regs.


Regs I had a php one before, I'm not so sure it works. Does PHP run inside x-cart as a TPL?

minfinger 09-22-2010 06:53 AM

Re: Random Youtube Video Player
 
Regs, I found this one as well.

http://www.jakeludington.com/youtube/20070615_how_to_randomize_youtube_videos_with_php. html

I got the flash portion to show on the site, but the PHP isn't pulling in the tag on the Video to make it display.

Regs 09-22-2010 07:37 AM

Re: Random Youtube Video Player
 
Can you post the relevant portion of the template you are putting the php code in?

As long as your path to the text file is correct and you wrap the php code in {php}{/php} tags in your template, it should work (as my limited understanding allows me to say :))

Once you get that working though, looking into using native smarty language code would be ideal - there should be code to set an array and to pull a random line from it.

Cheers,

Regs.

minfinger 09-22-2010 11:48 AM

Re: Random Youtube Video Player
 
Regs,

This guy in another thread talking about PHP in X-Cart figured it out along the lines of what you were saying.

Quote:

Originally Posted by geckoday
Two ways. The easiest is to just do this in the template like this:
Code:

{assign var=video_array value='/home/minfinge/public_html/littlepuppiesonline.com/skin1/customer/main/YourVideoList.txt'|file}
{assign var=video_rand value=$video_array|@array_rand}
<object width="200" height="137"><param name="movie"  value="http://www.youtube.com/v/{$video_array.$video_rand|trim}"></param><param  name="wmode" value="transparent"></param><embed  src="http://www.youtube.com/v/{$video_array.$video_rand|trim}"  type="application/x-shockwave-flash" wmode="transparent" width="200"  height="137"></embed></object>


That still puts code into the template and you'd end up duplicating it everywhere if you use it in multiple places. I prefer to use Smarty plugins for this kind of stuff like this:

PHP Code:

<?php
if (!defined('XCART_START')) { header("Location: ../../../"); die("Access denied"); }
## -----------------------------------------------------------------------------
## Smarty plugin "random_video"
## Purpose: Retrieve random vidoe name for display
##
##
## -----------------------------------------------------------------------------
##
## Changelog:
##
## 2010-09-22 Created
##
##
## -----------------------------------------------------------------------------
##
## Preparations
## ------------
## Uses the following file:
##   skin1/customer/main/YourVideoList.txt - list of videos, one per line
## 
##
## Sample usage
## ------------
## {random_video result="video_rand"}
## <object width="200" height="137"><param name="movie"  value="http://www.youtube.com/v/{$video_rand}"></param><param  name="wmode" value="transparent"></param><embed  src="http://www.youtube.com/v/{$video_rand}"  type="application/x-shockwave-flash" wmode="transparent" width="200"  height="137"></embed></object>
## 
##
## Parameters
## ----------
##
## result [string] (required)
##      Smarty variable to return result string in.  Result is a random line form the video file
##      trimmed and ready for substitution into HTML.
## 
## 
## -----------------------------------------------------------------------------

function smarty_function_random_video($params, &$smarty) {

  
$required_params = array('result');

  foreach(
$required_params as $_key => $reqd_param) {
    if (!isset(
$params[$reqd_param]))
      
$smarty->trigger_error("random_video: required attribute '$reqd_param' not passed"E_USER_ERROR);
  }

  
$result    '';
  foreach(
$params as $_key => $_val) {
    switch(
$_key) {
      case 
'result':
          if (!
is_array($_val)) {
              if (
$_val <> '')
                $
$_key $_val;
              else
                
$smarty->trigger_error("random_video: '$_key' cannot be an empty string"E_USER_ERROR);
          } else
              
$smarty->trigger_error("random_video: '$_key' cannot be an array"E_USER_ERROR);
          break;

      default:
          
$smarty->trigger_error("random_video: attribute '$_key' not recognized"E_USER_NOTICE);
          break;
    }
  }

  
$video_file $smarty->template_dir.DIRECTORY_SEPARATOR."customer/main/YourVideoList.txt";
  
  if (!
is_file($video_file))
      
$smarty->trigger_error("random_video: video list file '$video_file' is missing"E_USER_NOTICE);
      
  
$video_array file($video_file);
  if (
count($video_array) < 1)
      
$smarty->trigger_error("random_video: video list file '$video_file' is empty"E_USER_NOTICE);
      
  
$smarty->assign($resulttrim($video_array[array_rand($video_array)]));

}

Save this in include/templater/plugins/function.random_video.php and use it like the code comments show. I would probably add a parameter to select the video file to it so it can be used in multiple places for different lists of videos but I'll leave that as an exercise for the reader.



All times are GMT -8. The time now is 10:27 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.