- 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.
577 lines
23 KiB
PHP
577 lines
23 KiB
PHP
<?php
|
|
/**
|
|
* @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 AdminStEasyVideoListController extends ModuleAdminController
|
|
{
|
|
protected $spacer_size = '5';
|
|
protected $contr = '';
|
|
public function __construct()
|
|
{
|
|
$this->bootstrap = true;
|
|
$this->table = 'st_easy_video';
|
|
$this->className = 'StEasyVideoClass';
|
|
$this->lang = false;
|
|
$this->addRowAction('edit');
|
|
$this->addRowAction('delete');
|
|
|
|
if (Shop::isFeatureActive()) {
|
|
Shop::addTableAssociation($this->table, array('type' => 'shop'));
|
|
}
|
|
|
|
parent::__construct();
|
|
|
|
$this->bulk_actions = array(
|
|
'delete' => array(
|
|
'text' => $this->trans('Delete selected', array(), 'Modules.StEasyVideo.Admin'),
|
|
'icon' => 'icon-trash',
|
|
'confirm' => $this->trans('Delete selected items?', array(), 'Modules.StEasyVideo.Admin'),
|
|
)
|
|
);
|
|
|
|
if (!file_exists(_PS_IMG_DIR_.'/steasyvideo')) {
|
|
@mkdir(_PS_IMG_DIR_.'/steasyvideo', 0775, true)
|
|
|| @chmod(_PS_IMG_DIR_.'/steasyvideo', 0775);
|
|
}
|
|
|
|
$this->fieldImageSettings = [
|
|
'name' => 'thumbnail',
|
|
'dir' => 'steasyvideo',
|
|
];
|
|
|
|
$this->fields_list = array(
|
|
'id_st_easy_video' => array(
|
|
'title' => $this->trans('ID', array(), 'Modules.StEasyVideo.Admin'),
|
|
'class' => 'fixed-width-xs'
|
|
),
|
|
'url' => array(
|
|
'title' => $this->l('Url'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-xl',
|
|
),
|
|
'name' => array(
|
|
'title' => $this->l('Name'),
|
|
'width' => 140,
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
'id_product' => array(
|
|
'title' => $this->l('Add to'),
|
|
'width' => 140,
|
|
'type' => 'text',
|
|
'callback' => 'displayAddTo',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-xl',
|
|
),
|
|
'id_category' => array(
|
|
'title' => $this->l('Language'),
|
|
'width' => 140,
|
|
'type' => 'text',
|
|
'callback' => 'displayYuyan',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-xs',
|
|
),
|
|
'autoplay' => array(
|
|
'title' => $this->trans('Autoplay', array(), 'Modules.StEasyVideo.Admin'),
|
|
'type' => 'text',
|
|
'callback' => 'displayState',
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-md',
|
|
),
|
|
'muted' => array(
|
|
'title' => $this->trans('Muted', array(), 'Modules.StEasyVideo.Admin'),
|
|
'type' => 'text',
|
|
'callback' => 'displayState',
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-md',
|
|
),
|
|
'loop' => array(
|
|
'title' => $this->trans('Loop', array(), 'Modules.StEasyVideo.Admin'),
|
|
'type' => 'text',
|
|
'callback' => 'displayState',
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-md',
|
|
),
|
|
'active' => array(
|
|
'title' => $this->trans('Status', array(), 'Modules.StEasyVideo.Admin'),
|
|
'active' => 'status',
|
|
'type' => 'bool',
|
|
'orderby' => false,
|
|
'class' => 'fixed-width-md',
|
|
),
|
|
);
|
|
|
|
$this->_where = $this->addWhere();
|
|
$this->_orderBy = 'id_st_easy_video';
|
|
$this->_orderWay = 'DESC';
|
|
|
|
|
|
if (Tools::isSubmit('ajax_product_list')) {
|
|
$this->getAjaxProductsList();
|
|
}
|
|
|
|
Media::addJsDefL('stsb_comfirmation_msg', $this->trans('Are you sure?', array(), 'Modules.StEasyVideo.Admin'));
|
|
}
|
|
|
|
public function postProcess()
|
|
{
|
|
if (Tools::getValue('deletethumbnail')) {
|
|
if (file_exists(_PS_IMG_DIR_.'/steasyvideo/'.(int)Tools::getValue('id_st_easy_video').'.jpg')
|
|
&& !unlink(_PS_IMG_DIR_.'/steasyvideo/'.(int)Tools::getValue('id_st_easy_video').'.jpg')) {
|
|
$this->context->controller->errors[] = $this->trans('Error while delete', array(), 'Admin.Notifications.Error');
|
|
}
|
|
Tools::redirectAdmin(self::$currentIndex.'&conf=7&' . $this->identifier . '='.(int)Tools::getValue('id_st_easy_video').'&update' . $this->table . '&token=' . $this->token);
|
|
}
|
|
return parent::postProcess();
|
|
}
|
|
public function setMedia($isNewTheme = false)
|
|
{
|
|
parent::setMedia($isNewTheme);
|
|
$this->addJqueryPlugin(array('autocomplete'));
|
|
$this->addJs(_MODULE_DIR_.$this->module->name.'/views/js/admin.js?108');
|
|
}
|
|
public function displayState($value, $tr)
|
|
{
|
|
$arr = array(
|
|
'0' => $this->l('No'),
|
|
'1' => $this->l('Yes'),
|
|
'2' => $this->l('Default'),
|
|
);
|
|
return array_key_exists($value, $arr) ? $arr[$value] : '';
|
|
}
|
|
public function displayYuyan($value, $tr)
|
|
{
|
|
$res = '';
|
|
$yuyuan = StEasyVideoYuyanClass::getByVideo($tr['id_st_easy_video']);
|
|
if ($yuyuan && is_array($yuyuan)) {
|
|
$all_languages = Language::getLanguages(false);
|
|
foreach ($yuyuan as $y) {
|
|
foreach ($all_languages as $language) {
|
|
if ($y['id_lang'] == $language['id_lang']) {
|
|
$res .= $language['name'];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$res = $this->l('All');
|
|
}
|
|
return $res;
|
|
}
|
|
public function displayAddTo($value, $tr)
|
|
{
|
|
$name = '';
|
|
if ($tr['id_category'] > 0) {
|
|
$category = new Category($tr['id_category'], Context::getContext()->language->id);
|
|
if (Validate::isLoadedObject($category)) {
|
|
$name .= $category->name;
|
|
}
|
|
} elseif ($tr['id_product'] != '') {
|
|
$products = Db::getInstance()->executeS('SELECT id_product,name from `'._DB_PREFIX_.'product_lang` WHERE id_product IN ('.trim($tr['id_product'], ',').') AND id_lang='.Context::getContext()->language->id.' AND id_shop='.Context::getContext()->shop->id);
|
|
if ($products && is_array($products)) {
|
|
foreach ($products as $key => $val) {
|
|
if ($key == 0) {
|
|
$name .= ''.$val['name'];
|
|
} else {
|
|
$name .= '<br>'.$val['name'];
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
} elseif ($tr['id_manufacturer'] > 0) {
|
|
$manufacturer = new Manufacturer($tr['id_manufacturer'], Context::getContext()->language->id);
|
|
if (Validate::isLoadedObject($manufacturer)) {
|
|
$name .= $manufacturer->name;
|
|
}
|
|
}
|
|
return $name;
|
|
}
|
|
public function renderForm()
|
|
{
|
|
if (!($obj = $this->loadObject(true))) {
|
|
return;
|
|
}
|
|
|
|
$image = _PS_IMG_DIR_ . $this->fieldImageSettings['dir'] . '/' . $obj->id . '.jpg';
|
|
$image_size = false;
|
|
$image_tag = '';
|
|
if (file_exists($image)) {
|
|
$image_size = filesize($image) / 1000;
|
|
$image_url = _PS_IMG_ . $this->fieldImageSettings['dir'] . '/' . $obj->id . '.jpg';
|
|
$image_tag = '<img src="' . Context::getContext()->link->protocol_content.Tools::getMediaServer($image_url).$image_url . '" alt="" class="imgm img-thumbnail" />';
|
|
}
|
|
|
|
Media::addJsDef(array(
|
|
'_currentIndex' => $this->context->link->getAdminLink('AdminModules'),
|
|
'_token' => Tools::getAdminTokenLite('AdminModules')
|
|
));
|
|
|
|
$this->fields_form = array(
|
|
'tinymce' => true,
|
|
'legend' => array(
|
|
'title' => $this->l('Add a video'),
|
|
'icon' => 'icon-tags',
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Video url:'),
|
|
'name' => 'url',
|
|
'default_value' => '',
|
|
'class' => 'fixed-width-xxl',
|
|
'required' => true,
|
|
'desc' => array(
|
|
$this->l('Url of a .mp4 file or a youtube url or a vimeo url.'),
|
|
$this->l('You can upload mp4 files to your site via FTP, another way is using the text editor at the bottom of this page to upload videos to your site to get urls.'),
|
|
'<div id="youtube_thumbnail"></div>'
|
|
),
|
|
),
|
|
array(
|
|
'type' => 'textarea',
|
|
'label' => $this->l('For uploading videos:'),
|
|
'name' => 'for_uploading_videos',
|
|
'desc' => $this->l('You can use the video button in the text editor to upload videos to your site to get their urls.'),
|
|
'autoload_rte' => 'rte',
|
|
),
|
|
array(
|
|
'type' => 'radio',
|
|
'label' => $this->l('Display on:'),
|
|
'name' => 'location',
|
|
'is_bool' => false,
|
|
'default_value' => 0,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'location_0',
|
|
'value' => 0,
|
|
'label' => $this->l('All'),
|
|
),
|
|
array(
|
|
'id' => 'location_1',
|
|
'value' => 1,
|
|
'label' => $this->l('Main gallery on the product page'),
|
|
),
|
|
array(
|
|
'id' => 'location_2',
|
|
'value' => 2,
|
|
'label' => $this->l('Product miniature on the product listing pages'),
|
|
),
|
|
array(
|
|
'id' => 'location_3',
|
|
'value' => 3,
|
|
'label' => $this->l('Product miniatures'),
|
|
),
|
|
),
|
|
'validation' => 'isUnsignedInt',
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Name:'),
|
|
'name' => 'name',
|
|
'size' => 64,
|
|
'desc' => $this->l('As a reminder, show on backoffice only.'),
|
|
),
|
|
array(
|
|
'type' => 'switch',
|
|
'label' => $this->l('Use youtube thumbnail if it is a youtube video.'),
|
|
'name' => 'online_thumbnail',
|
|
'is_bool' => true,
|
|
'default_value' => 1,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'online_thumbnail_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Enabled')
|
|
),
|
|
array(
|
|
'id' => 'online_thumbnail_off',
|
|
'value' => 0,
|
|
'label' => $this->l('Disabled')
|
|
)
|
|
),
|
|
),
|
|
'thumbnail' => array(
|
|
'type' => 'file',
|
|
'label' => $this->l('Custom thumbnail:'),
|
|
'name' => 'thumbnail',
|
|
'display_image' => true,
|
|
'image' => $image_tag ? $image_tag : false,
|
|
'size' => $image_size,
|
|
'delete_url' => self::$currentIndex.'&deletethumbnail=1&' . $this->identifier . '='.(int)$obj->id.'&update' . $this->table . '&token=' . $this->token,
|
|
),
|
|
|
|
array(
|
|
'type' => 'radio',
|
|
'label' => $this->l('Autoplay:'),
|
|
'name' => 'autoplay',
|
|
'is_bool' => false,
|
|
'default_value' => 2,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'autoplay_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Yes'),
|
|
),
|
|
array(
|
|
'id' => 'autoplay_off',
|
|
'value' => 0,
|
|
'label' => $this->l('No'),
|
|
),
|
|
array(
|
|
'id' => 'autoplay_default',
|
|
'value' => 2,
|
|
'label' => $this->l('Use default'),
|
|
),
|
|
),
|
|
'validation' => 'isUnsignedInt',
|
|
'desc' => array(
|
|
$this->l('This option is NOT a guarantee that your video will autoplay.'),
|
|
$this->l('This option would not take effect if videos are put to the end of thumbnail gallery.'),
|
|
$this->l('Check the description of this module on sunnytoo.com for more info.'),
|
|
),
|
|
),
|
|
array(
|
|
'type' => 'radio',
|
|
'label' => $this->l('Loop:'),
|
|
'name' => 'loop',
|
|
'default_value' => 2,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'loop_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Yes'),
|
|
),
|
|
array(
|
|
'id' => 'loop_off',
|
|
'value' => 0,
|
|
'label' => $this->l('No'),
|
|
),
|
|
/*array(
|
|
'id' => 'loop_no',
|
|
'value' => 3,
|
|
'label' => $this->l('No, close player after a video ends'),
|
|
),*/
|
|
array(
|
|
'id' => 'loop_default',
|
|
'value' => 2,
|
|
'label' => $this->l('Use default'),
|
|
),
|
|
),
|
|
'validation' => 'isUnsignedInt',
|
|
),
|
|
array(
|
|
'type' => 'radio',
|
|
'label' => $this->l('Muted:'),
|
|
'name' => 'muted',
|
|
'is_bool' => true,
|
|
'default_value' => 2,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'muted_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Yes'),
|
|
),
|
|
array(
|
|
'id' => 'muted_off',
|
|
'value' => 0,
|
|
'label' => $this->l('No'),
|
|
),
|
|
array(
|
|
'id' => 'muted_default',
|
|
'value' => 2,
|
|
'label' => $this->l('Use default'),
|
|
),
|
|
),
|
|
'validation' => 'isUnsignedInt',
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Aspect ratio:'),
|
|
'name' => 'ratio',
|
|
'size' => 64,
|
|
'desc' => $this->l('Generally, the video ratio should be the same as the product images. But if the vidoe ratio is different, then you can force the video to display at a specific ratio, use one of the values 16:9, 4:3, 9:16, 1:1.'),
|
|
),
|
|
array(
|
|
'type' => 'switch',
|
|
'label' => $this->l('Status:'),
|
|
'name' => 'active',
|
|
'is_bool' => true,
|
|
'default_value' => 1,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'active_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Enabled')
|
|
),
|
|
array(
|
|
'id' => 'active_off',
|
|
'value' => 0,
|
|
'label' => $this->l('Disabled')
|
|
)
|
|
),
|
|
),
|
|
array(
|
|
'type' => 'checkbox',
|
|
'label' => $this->l('Language:'),
|
|
'name' => 'id_lang',
|
|
'values' => array(
|
|
'query' => $this->getAllLanguages(),
|
|
'id' => 'id',
|
|
'name' => 'name',
|
|
),
|
|
'desc' => $this->l('It will show out on all languages if you don\'t select any.'),
|
|
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Position:'),
|
|
'name' => 'position',
|
|
'default_value' => 0,
|
|
'class' => 'fixed-width-sm'
|
|
),
|
|
),
|
|
'buttons' => array(
|
|
array(
|
|
'title' => $this->l('Save all'),
|
|
'class' => 'btn btn-default pull-right',
|
|
'icon' => 'process-icon-save',
|
|
'type' => 'submit'
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Save and stay'),
|
|
'stay' => true
|
|
),
|
|
);
|
|
|
|
|
|
if (Shop::isFeatureActive()) {
|
|
$this->fields_form['input'][] = array(
|
|
'type' => 'shop',
|
|
'label' => $this->l('Shop association:'),
|
|
'name' => 'checkBoxShopAsso',
|
|
);
|
|
}
|
|
|
|
if (method_exists($this, 'filterFormFields')) {
|
|
$this->filterFormFields($this->fields_form, $obj);
|
|
}
|
|
|
|
return parent::renderForm();
|
|
}
|
|
public function getFieldsValue($obj)
|
|
{
|
|
foreach ($this->fields_form as $fieldset) {
|
|
if (isset($fieldset['form']['input'])) {
|
|
foreach ($fieldset['form']['input'] as $input) {
|
|
if (!isset($this->fields_value[$input['name']])) {
|
|
if (isset($input['type']) && $input['type'] == 'shop') {
|
|
if ($obj->id) {
|
|
$result = Shop::getShopById((int) $obj->id, $this->identifier, $this->table);
|
|
foreach ($result as $row) {
|
|
$this->fields_value['shop'][$row['id_' . $input['type']]][] = $row['id_shop'];
|
|
}
|
|
}
|
|
} elseif (isset($input['name']) && $input['name']=='id_lang') {
|
|
$lang_obj_data= StEasyVideoClass::get_lang_obj_data($obj->id);
|
|
foreach ($this->getAllLanguages() as $language) {
|
|
if(in_array($language['id'],$lang_obj_data)){
|
|
$this->fields_value['id_lang_'.$language['id']]=$language['id'];
|
|
} elseif (count($lang_obj_data) == 1 && $lang_obj_data[0] == 0) {
|
|
$this->fields_value['id_lang_'.$language['id']]=$language['id'];
|
|
}
|
|
}
|
|
|
|
} else {
|
|
$field_value = $this->getFieldValue($obj, $input['name']);
|
|
if ($field_value === false && isset($input['default_value'])) {
|
|
$field_value = $input['default_value'];
|
|
}
|
|
$this->fields_value[$input['name']] = $field_value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $this->fields_value;
|
|
}
|
|
protected function copyFromPost(&$object, $table)
|
|
{
|
|
parent::copyFromPost($object, $table);
|
|
if ($this->contr == 'product') {
|
|
if ($ids = Tools::getValue('st_id_product')) {
|
|
$object->id_product = ','.implode(',', $ids).',';
|
|
} else {
|
|
$this->errors[] = $this->l('Please select products.');
|
|
}
|
|
$object->id_category = 0;
|
|
$object->id_manufacturer = 0;
|
|
} elseif ($this->contr == 'category') {
|
|
$object->id_product = '';
|
|
$object->id_manufacturer = 0;
|
|
if (!$object->id_category) {
|
|
$this->errors[] = $this->l('Please select a category.');
|
|
}
|
|
} elseif ($this->contr == 'manufacturer') {
|
|
$object->id_category = 0;
|
|
$object->id_product = '';
|
|
if (!$object->id_manufacturer) {
|
|
$this->errors[] = $this->l('Please select a manufacturer.');
|
|
}
|
|
} else {
|
|
$this->errors[] = $this->l('Where do you want to add the video.');
|
|
}
|
|
}
|
|
|
|
public function afterAdd($object)
|
|
{
|
|
return $this->updateAssoLang($object->id);
|
|
}
|
|
public function afterUpdate($object)
|
|
{
|
|
return $this->updateAssoLang($object->id);
|
|
}
|
|
public function updateAssoLang($id, $lang = [])
|
|
{
|
|
StEasyVideoYuyanClass::deleteByVideo($id);
|
|
$lang_arr = array();
|
|
$all_languages = Language::getLanguages(false);
|
|
foreach ($all_languages as $lang) {
|
|
if (Tools::getValue('id_lang_'.$lang['id_lang'])) {
|
|
$lang_arr[] = $lang['id_lang'];
|
|
}
|
|
}
|
|
$res = true;
|
|
if (count($lang_arr) && count($lang_arr) < count($all_languages)) {
|
|
$res = StEasyVideoYuyanClass::changeVideoYuyan($id, $lang_arr);
|
|
}else{
|
|
$res = StEasyVideoYuyanClass::changeVideoYuyan($id, [0]);
|
|
}
|
|
return $res;
|
|
}
|
|
public function getAllLanguages()
|
|
{
|
|
$lang_list = Language::getLanguages(false);
|
|
$new = [];
|
|
foreach ($lang_list as $val) {
|
|
$new[] = [
|
|
'id' => $val['id_lang'],
|
|
'name' => $val['name']
|
|
];
|
|
}
|
|
return $new;
|
|
}
|
|
}
|