Files
redline.com.pl/modules/steasyvideo/classes/StEasyVideoClass.php
Jacek Pyziak eacf500d18 feat: Add YouTube video support and update admin templates
- 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.
2025-05-23 19:27:41 +02:00

168 lines
7.2 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 StEasyVideoClass extends ObjectModel
{
public $id;
public $id_st_easy_video;
public $position;
public $active;
public $url;
public $thumbnail;
public $online_thumbnail;
public $name;
public $loop;
public $muted;
public $autoplay;
public $sub_category;
public $id_product;
public $id_category;
public $id_manufacturer;
public $ratio;
public $location;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'st_easy_video',
'primary' => 'id_st_easy_video',
'multilang' => false,
'fields' => array(
'position' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'url' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'size' => 255, 'required'=>true),
'thumbnail' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'size' => 255),
'online_thumbnail' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
'loop' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'muted' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'autoplay' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'sub_category' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'id_product' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
'id_category' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'location' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'ratio' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'size' => 255),
),
);
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
Shop::addTableAssociation(self::$definition['table'], array('type' => 'shop'));
parent::__construct($id, $id_lang, $id_shop);
}
public function delete()
{
$image = _PS_IMG_DIR_ . 'steasyvideo/' . $this->id . '.jpg';
if (file_exists($image))
@unlink($image);
return parent::delete();
}
public static function getOneVideo($id_product, $location=0)
{
Shop::addTableAssociation('st_easy_video', array('type' => 'shop'));
$sql = 'SELECT *
FROM `'._DB_PREFIX_.'st_easy_video` spv
'.Shop::addSqlAssociation('st_easy_video', 'spv').'
WHERE spv.`active`=1 AND ('.self::getProductWhereConds($id_product).') '.($location ? ' AND spv.`location` IN (0, 2, 3) ' : ' AND spv.`location` IN (0, 3) ').'
ORDER BY spv.`position` desc';
return Db::getInstance()->getRow($sql);
}
public static function getVideos($id_product, $locations=[], $lang=0, $limit=0)
{
Shop::addTableAssociation('st_easy_video', array('type' => 'shop'));
$sql = 'SELECT *
FROM `'._DB_PREFIX_.'st_easy_video` spv
INNER JOIN `'._DB_PREFIX_.'st_easy_video_yuyan` yy ON yy.id_st_easy_video = spv.id_st_easy_video
'.Shop::addSqlAssociation('st_easy_video', 'spv').'
WHERE spv.`active`=1 AND ('.self::getProductWhereConds($id_product).') '.(count($locations) ? ' AND spv.`location` IN ('.implode(',', $locations).') ' : '').($lang ? ' AND ( yy.`id_lang` = 0 OR yy.`id_lang` = '.(int)$lang.')' : '').'
ORDER BY spv.`position` desc'.($limit ? ' LIMIT '.(int)$limit : '');
return Db::getInstance()->executeS($sql);
}
public static function get_lang_obj_data($id)
{
$data=Db::getInstance()->executeS((new DbQuery())->from(self::$definition['table'].'_yuyan')->where('id_st_easy_video='.(int)$id));
$new_data=[];
if($data && !empty($data)){
$new_data=array_column($data,'id_lang');
}
return $new_data;
}
public static function getProductWhereConds($id)
{
$where = '0';
$product = new Product($id);
if ($product->id_manufacturer) {
$where .= ' OR (spv.`id_manufacturer` > 0 AND spv.`id_manufacturer`='.(int)$product->id_manufacturer.')';
}
$id_category = $product->id_category_default;
if ($cates = $product->getCategories()) {
$categories = array();
$parents = array();
foreach ($cates as $id_cate) {
$category = new Category($id_cate);
if (!$category->active || !$category->id) {
continue;
}
if ($category->id) {
// For all product categories instead of deafult category.
$categories[] = (int)$category->id;
$id_array = array();
$category_parents = $category->getParentsCategories();
if (is_array($category_parents) && count($category_parents)) {
foreach ($category_parents as $v) {
$id_array[] = $v['id_category'];
}
}
if (in_array($id_category, $id_array)) {
$parents = array_merge($parents, $id_array);
}
}
}
$where .= ' OR (spv.`id_category` > 0 AND spv.`id_category` IN('.implode(',', array_unique(array_merge($categories, $parents))).') AND spv.`sub_category`=1) OR (spv.`id_category` > 0 AND spv.`id_category` IN('.implode(',', $categories).') AND spv.`sub_category`=0)';
}
if ($product->id) {
$where .= ' OR ( find_in_set(\''.(int)$product->id.'\', spv.`id_product`))';
}
return $where;
}
}