- Introduced a new YouTube tech integration in `youtube.min.js` for enhanced video playback. - Created new admin template files for managing video settings, including `index.php` and `steasyvideo-pro.tpl`. - Updated hook templates (`device_mode.tpl`, `forquickview.tpl`, `header.tpl`, `miniature.tpl`, `miniature_tb.tpl`, and predefined templates) to include video functionality. - Implemented caching headers in several PHP files to improve performance. - Ensured all new templates include proper licensing information and copyright notices.
358 lines
18 KiB
PHP
358 lines
18 KiB
PHP
<?php
|
|
/**
|
|
* Copyright since 2007 PrestaShop SA and Contributors
|
|
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Open Software License (OSL 3.0)
|
|
* that is bundled with this package in the file LICENSE.md.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* https://opensource.org/licenses/OSL-3.0
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
|
*
|
|
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
|
* @copyright Since 2007 PrestaShop SA and Contributors
|
|
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
class EasyVideoBase
|
|
{
|
|
public static $device = ['desktop' => 'DESKTOP', 'mobile' => 'MOBILE', 'quickview' => 'QUICKVIEW'];
|
|
|
|
public static $selectors = array(
|
|
'miniature_video_selector_desktop' => array(
|
|
'classic' => '.product-thumbnail',
|
|
'st' => '.pro_first_box',
|
|
'warehouse' => '.thumbnail-container',
|
|
),
|
|
'miniature_button_selector_desktop' => array(
|
|
'classic' => '.thumbnail-top',
|
|
'st' => '.pro_first_box',
|
|
'warehouse' => '.thumbnail-container',
|
|
),
|
|
'miniature_video_selector_mobile' => array(
|
|
'classic' => '.product-thumbnail',
|
|
'st' => '.pro_first_box',
|
|
'warehouse' => '.thumbnail-container',
|
|
),
|
|
'miniature_button_selector_mobile' => array(
|
|
'classic' => '.thumbnail-top',
|
|
'st' => '.pro_first_box',
|
|
'warehouse' => '.thumbnail-container',
|
|
),
|
|
'gallery_video_selector_desktop' => array(
|
|
'classic' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_top_inner',
|
|
'warehouse' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
),
|
|
'gallery_button_selector_desktop' => array(
|
|
'classic' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_top_inner',
|
|
'warehouse' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
),
|
|
'gallery_type_desktop' => array(
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_thumbnail_type_desktop' => array(
|
|
'classic' => 5,
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_slider_selector_desktop' => array(
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_top',
|
|
'warehouse' => '.page-product:not(.modal-open) #product-images-large',
|
|
),
|
|
'gallery_thumbnail_selector_desktop' => array(
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_thumbs',
|
|
'warehouse' => '.page-product:not(.modal-open) #product-images-thumbs',
|
|
),
|
|
'gallery_thumbnail_item_selector_desktop' => array(
|
|
'classic' => '.images-container .thumb-container',
|
|
'st' => '.pro_gallery_thumbs_container .swiper-slide',
|
|
'warehouse' => '#product-images-thumbs .slick-slide',
|
|
),
|
|
'gallery_video_template_desktop' => array(
|
|
'st' => 2,
|
|
'warehouse' => 3,
|
|
),
|
|
'gallery_video_image_type_desktop' => array(
|
|
'classic' => 'large_default',
|
|
'st' => 'medium_default',
|
|
'warehouse' => 'large_default',
|
|
),
|
|
'gallery_button_template_desktop' => array(
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_button_image_type_desktop' => array(
|
|
'classic' => 'small_default',
|
|
'st' => 'cart_default',
|
|
'warehouse' => 'medium_default',
|
|
),
|
|
|
|
|
|
'gallery_video_selector_mobile' => array(
|
|
'classic' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_top_inner',
|
|
'warehouse' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
),
|
|
'gallery_button_selector_mobile' => array(
|
|
'classic' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_top_inner',
|
|
'warehouse' => '.page-product:not(.modal-open) .images-container .product-cover',
|
|
),
|
|
'gallery_type_mobile' => array(
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_thumbnail_type_mobile' => array(
|
|
'classic' => 5,
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_slider_selector_mobile' => array(
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_top',
|
|
'warehouse' => '.page-product:not(.modal-open) #product-images-large',
|
|
),
|
|
'gallery_thumbnail_selector_mobile' => array(
|
|
'st' => '.page-product:not(.modal-open) .pro_gallery_thumbs',
|
|
'warehouse' => '.page-product:not(.modal-open) #product-images-thumbs',
|
|
),
|
|
'gallery_thumbnail_item_selector_mobile' => array(
|
|
'classic' => '.images-container .thumb-container',
|
|
'st' => '.pro_gallery_thumbs_container .swiper-slide',
|
|
'warehouse' => '#product-images-thumbs .slick-slide',
|
|
),
|
|
'gallery_video_template_mobile' => array(
|
|
'st' => 2,
|
|
'warehouse' => 3,
|
|
),
|
|
'gallery_video_image_type_mobile' => array(
|
|
'classic' => 'large_default',
|
|
'st' => 'medium_default',
|
|
'warehouse' => 'large_default',
|
|
),
|
|
'gallery_button_template_mobile' => array(
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_button_image_type_mobile' => array(
|
|
'classic' => 'small_default',
|
|
'st' => 'cart_default',
|
|
'warehouse' => 'medium_default',
|
|
),
|
|
|
|
|
|
'gallery_video_selector_quickview' => array(
|
|
'classic' => '.modal.quickview .images-container .product-cover',
|
|
'st' => '.modal.quickview .pro_gallery_top_inner',
|
|
'warehouse' => '.modal.quickview .images-container .product-cover',
|
|
),
|
|
'gallery_button_selector_quickview' => array(
|
|
'classic' => '.modal.quickview .images-container .product-cover',
|
|
'st' => '.modal.quickview .pro_gallery_top_inner',
|
|
'warehouse' => '.modal.quickview .images-container .product-cover',
|
|
),
|
|
'gallery_type_quickview' => array(
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_thumbnail_type_quickview' => array(
|
|
'classic' => 5,
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_slider_selector_quickview' => array(
|
|
'st' => '.modal.quickview .pro_gallery_top',
|
|
'warehouse' => '.modal.quickview #product-images-large',
|
|
),
|
|
'gallery_thumbnail_selector_quickview' => array(
|
|
'st' => '.modal.quickview .pro_gallery_thumbs',
|
|
'warehouse' => '.modal.quickview #product-images-thumbs',
|
|
),
|
|
'gallery_thumbnail_item_selector_quickview' => array(
|
|
'classic' => '.images-container .thumb-container',
|
|
'st' => '.pro_gallery_thumbs_container .swiper-slide',
|
|
'warehouse' => '#product-images-thumbs .slick-slide',
|
|
),
|
|
'gallery_video_template_quickview' => array(
|
|
'st' => 2,
|
|
'warehouse' => 3,
|
|
),
|
|
'gallery_video_image_type_quickview' => array(
|
|
'classic' => 'large_default',
|
|
'st' => 'medium_default',
|
|
'warehouse' => 'large_default',
|
|
),
|
|
'gallery_button_template_quickview' => array(
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
'gallery_button_image_type_quickview' => array(
|
|
'classic' => 'small_default',
|
|
'st' => 'cart_default',
|
|
'warehouse' => 'medium_default',
|
|
),
|
|
|
|
'gallery_video_zindex' => array(
|
|
'classic' => 9,
|
|
'st' => 9,
|
|
'warehouse' => 23,
|
|
),
|
|
'miniature_video_zindex' => array(
|
|
'classic' => 1,
|
|
'st' => 1,
|
|
'warehouse' => 1,
|
|
),
|
|
);
|
|
|
|
public static $_theme_name;
|
|
|
|
public static function getThemeName(){
|
|
if(!self::$_theme_name){
|
|
self::$_theme_name = Configuration::get('ST_EASY_VIDEO_THEME_NAME');
|
|
if (!self::$_theme_name) {
|
|
self::$_theme_name = Tools::strtolower(Context::getContext()->shop->theme->getName());
|
|
$parent_theme_name = Tools::strtolower(Context::getContext()->shop->theme->get("parent", ""));
|
|
if ($parent_theme_name == 'panda') {
|
|
self::$_theme_name = 'panda';
|
|
} elseif ($parent_theme_name == 'transformer') {
|
|
self::$_theme_name = 'transformer';
|
|
} elseif ($parent_theme_name == 'warehouse') {
|
|
self::$_theme_name = 'warehouse';
|
|
}
|
|
}
|
|
}
|
|
return self::$_theme_name;
|
|
}
|
|
public static function getSelector($key, $device = '', $default = '')
|
|
{
|
|
$theme_name = self::getThemeName();
|
|
$theme_name = $theme_name == 'panda' || $theme_name == 'transformer' ? 'st' : $theme_name;
|
|
$key = $device ? $key.'_'.$device : $key;
|
|
return isset(self::$selectors[$key]) && array_key_exists($theme_name, self::$selectors[$key]) ? self::$selectors[$key][$theme_name] : (isset(self::$selectors[$key]['classic']) ? self::$selectors[$key]['classic'] : $default);
|
|
}
|
|
|
|
|
|
public static function fetchMediaServer(&$video)
|
|
{
|
|
if($video){
|
|
$image = _PS_IMG_DIR_ . 'steasyvideo/' . $video['id_st_easy_video'] . '.jpg';
|
|
if (file_exists($image)) {
|
|
$image_url = _PS_IMG_ . 'steasyvideo/' . $video['id_st_easy_video'] . '.jpg';
|
|
$video['thumbnail'] = Context::getContext()->link->protocol_content.Tools::getMediaServer($image_url).$image_url;
|
|
}
|
|
}
|
|
}
|
|
public static function getVideosByProduct($id_product, $locations=[], $limit=0, $link_rewrite='', $video_templates=[], $button_templates=[])
|
|
{
|
|
if(!$id_product)
|
|
return false;
|
|
$cover = Product::getCover($id_product);
|
|
$gallery_video_template = $gallery_button_template = $miniature_video_template = $miniature_button_template = $gallery_video_image_type = $gallery_button_image_type = $gallery_video_placeholder_url = $gallery_button_placeholder_url = $miniature_video_image_type = $miniature_button_image_type = $miniature_video_placeholder_url = $miniature_button_placeholder_url = [];
|
|
foreach (self::$device as $kl => $ku) {
|
|
$gallery_video_template[$kl] = Configuration::get('ST_EASY_VIDEO_GALLERY_VIDEO_TEMPLATE_'.$ku);
|
|
if(!$gallery_video_template[$kl] && ($id = self::getSelector('gallery_video_template', $kl)) && !empty($video_templates[$id]))
|
|
$gallery_video_template[$kl] = $video_templates[$id];
|
|
$gallery_button_template[$kl] = Configuration::get('ST_EASY_VIDEO_GALLERY_BUTTON_TEMPLATE_'.$ku);
|
|
if(!$gallery_button_template[$kl] && ($id = self::getSelector('gallery_button_template', $kl)) && !empty($button_templates[$id]))
|
|
$gallery_button_template[$kl] = $button_templates[$id];
|
|
$miniature_video_template[$kl] = Configuration::get('ST_EASY_VIDEO_MINIATURE_VIDEO_TEMPLATE_'.$ku);
|
|
$miniature_button_template[$kl] = Configuration::get('ST_EASY_VIDEO_MINIATURE_BUTTON_TEMPLATE_'.$ku);
|
|
|
|
$gallery_video_image_type[$kl] = Configuration::get('ST_EASY_VIDEO_GALLERY_VIDEO_IMAGE_TYPE_'.$ku);
|
|
$gallery_video_image_type[$kl] = $gallery_video_image_type[$kl] ?: self::getSelector('gallery_video_image_type', $kl);
|
|
$gallery_button_image_type[$kl] = Configuration::get('ST_EASY_VIDEO_GALLERY_BUTTON_IMAGE_TYPE_'.$ku);
|
|
$gallery_button_image_type[$kl] = $gallery_button_image_type[$kl] ?: self::getSelector('gallery_button_image_type', $kl);
|
|
$miniature_video_image_type[$kl] = Configuration::get('ST_EASY_VIDEO_MINIATURE_VIDEO_IMAGE_TYPE_'.$ku);
|
|
$miniature_video_image_type[$kl] = $miniature_video_image_type[$kl] ?: self::getSelector('miniature_video_image_type', $kl);
|
|
$miniature_button_image_type[$kl] = Configuration::get('ST_EASY_VIDEO_MINIATURE_BUTTON_IMAGE_TYPE_'.$ku);
|
|
$miniature_button_image_type[$kl] = $miniature_button_image_type[$kl] ?: self::getSelector('miniature_button_image_type', $kl);
|
|
|
|
if ($cover) {
|
|
$gallery_video_placeholder_url[$kl] = Context::getContext()->link->getImageLink($link_rewrite, $cover['id_image'], $gallery_video_image_type[$kl]);
|
|
$gallery_button_placeholder_url[$kl] = Context::getContext()->link->getImageLink($link_rewrite, $cover['id_image'], $gallery_button_image_type[$kl]);
|
|
$miniature_video_placeholder_url[$kl] = Context::getContext()->link->getImageLink($link_rewrite, $cover['id_image'], $miniature_video_image_type[$kl]);
|
|
$miniature_button_placeholder_url[$kl] = Context::getContext()->link->getImageLink($link_rewrite, $cover['id_image'], $miniature_button_image_type[$kl]);
|
|
} else {
|
|
$gallery_video_placeholder_url[$kl] = Tools::getCurrentUrlProtocolPrefix().Tools::getMediaServer(_THEME_PROD_DIR_)._THEME_PROD_DIR_.Context::getContext()->language->iso_code.'-default-'.$gallery_video_image_type[$kl].'.jpg';
|
|
$gallery_button_placeholder_url[$kl] = Tools::getCurrentUrlProtocolPrefix().Tools::getMediaServer(_THEME_PROD_DIR_)._THEME_PROD_DIR_.Context::getContext()->language->iso_code.'-default-'.$gallery_button_image_type[$kl].'.jpg';
|
|
$miniature_video_placeholder_url[$kl] = Tools::getCurrentUrlProtocolPrefix().Tools::getMediaServer(_THEME_PROD_DIR_)._THEME_PROD_DIR_.Context::getContext()->language->iso_code.'-default-'.$miniature_video_image_type[$kl].'.jpg';
|
|
$miniature_button_placeholder_url[$kl] = Tools::getCurrentUrlProtocolPrefix().Tools::getMediaServer(_THEME_PROD_DIR_)._THEME_PROD_DIR_.Context::getContext()->language->iso_code.'-default-'.$miniature_button_image_type[$kl].'.jpg';
|
|
}
|
|
}
|
|
|
|
|
|
$videos_for_template = [];
|
|
if ($videos = StEasyVideoClass::getVideos($id_product, $locations, Context::getContext()->language->id, $limit)) {
|
|
foreach ($videos as $index => $video) {
|
|
self::fetchMediaServer($video);
|
|
if (preg_match("/youtu(\.be|be\.com)/", $video['url'])) {
|
|
$video['url'] = preg_replace("(^https?)", "", $video['url']);
|
|
if (!$video['thumbnail'] && $video['online_thumbnail'] && ($youtube_id = self::getYoutubeId($video['url']))) {
|
|
$video['thumbnail'] = "//img.youtube.com/vi/".$youtube_id."/default.jpg";
|
|
}
|
|
}
|
|
foreach (self::$device as $kl => $ku) {
|
|
if (!empty($gallery_video_template[$kl])) {
|
|
$video['gallery_video_template_'.$kl] = self::prepareTemplate($gallery_video_template[$kl], $video, $gallery_video_placeholder_url[$kl], $gallery_video_image_type[$kl]);
|
|
}
|
|
if (!empty($gallery_button_template[$kl])) {
|
|
$video['gallery_button_template_'.$kl] = self::prepareTemplate($gallery_button_template[$kl], $video, $gallery_button_placeholder_url[$kl], $gallery_button_image_type[$kl]);
|
|
}
|
|
if (!empty($miniature_video_template[$kl])) {
|
|
$video['miniature_video_template_'.$kl] = self::prepareTemplate($miniature_video_template[$kl], $video, $miniature_video_placeholder_url[$kl], $miniature_video_image_type[$kl]);
|
|
}
|
|
if (!empty($miniature_button_template[$kl])) {
|
|
$video['miniature_button_template_'.$kl] = self::prepareTemplate($miniature_button_template[$kl], $video, $miniature_button_placeholder_url[$kl], $miniature_button_image_type[$kl]);
|
|
}
|
|
}
|
|
|
|
$video['autoplay'] = (int)$video['autoplay'];
|
|
$video['loop'] = (int)$video['loop'];
|
|
$video['muted'] = (int)$video['muted'];
|
|
$video['desktop_ran'] = false;
|
|
$video['mobile_ran'] = false;
|
|
$video['quickview_ran'] = false;
|
|
$videos_for_template['product_'.$id_product.'_'.$index] = $video;
|
|
}
|
|
}
|
|
return $videos_for_template;
|
|
}
|
|
public static function prepareTemplate($template, $video, $placehoder_url, $image_type)
|
|
{
|
|
$image_size = Image::getSize($image_type);
|
|
$template = str_replace('@thumbnail_url@', ($video['thumbnail'] ?: $placehoder_url), $template);
|
|
$template = str_replace('@placeholder_url@', $placehoder_url, $template);
|
|
if ($image_size) {
|
|
$template = str_replace('@placeholder_width@', $image_size['width'], $template);
|
|
$template = str_replace('@placeholder_height@', $image_size['height'], $template);
|
|
} else {
|
|
$template = str_replace('@placeholder_width@', '', $template);
|
|
$template = str_replace('@placeholder_height@', '', $template);
|
|
}
|
|
return $template;
|
|
}
|
|
|
|
public static function getYoutubeId($url)
|
|
{
|
|
preg_match("/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|shorts\/)([^#\&\?]*).*/", $url, $match);
|
|
return ($match && Tools::strlen($match[1]) == 11) ? $match[1] : false;
|
|
}
|
|
|
|
}
|