* @copyright HiPresta 2020 * @license Addons PrestaShop license limitation * @version 1.1.2 * @link https://hipresta.com * * NOTICE OF LICENSE * * Don't use this module on several shops. The license provided by PrestaShop Addons * for all its modules is valid only once for a single shop. */ if (!defined('_PS_VERSION_')) { exit; } include_once(dirname(__FILE__).'/classes/gallery_item.php'); include_once(dirname(__FILE__).'/classes/gallery_image.php'); include_once(dirname(__FILE__).'/classes/gallerySocialAccount.php'); include_once(dirname(__FILE__).'/classes/HiPrestaModule.php'); include_once(dirname(__FILE__).'/classes/adminForms.php'); class HiGallery extends Module { public $psv; public $errors = array(); public $success = array(); public $clean_db; public $gallery_page_title; public $gallery_page_description; public $module_hooks; public $gallery_page_url; public function __construct() { $this->name = 'higallery'; $this->tab = 'front_office_features'; $this->version = '1.1.2'; $this->author = 'hipresta'; $this->need_instance = 0; $this->secure_key = Tools::encrypt($this->name); $this->bootstrap = true; $this->module_key = 'a0e600edf11836dbb41165f551c1926d'; parent::__construct(); $this->globalVars(); $this->displayName = $this->l('Gallery'); $this->description = $this->l('Create unlimitted gallery albums for any page location.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); $this->HiPrestaClass = new HiPrestaGalleryModule($this); $this->adminForms = new HiGalleryAdminForms($this); } public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!parent::install() || !$this->installDb() || !$this->registerHook('home') || !$this->registerHook('header') || !$this->registerHook('footer') || !$this->registerHook('leftColumn') || !$this->registerHook('rightColumn') || !$this->registerHook('higallery') || !$this->registerHook('moduleRoutes') || !$this->HiPrestaClass->createTabs('AdminGallery', 'AdminGallery', 'CONTROLLER_TABS_HIGALLERY', 0) ) { return false; } $this->proceedDb(); return true; } public function uninstall() { if (!parent::uninstall()) { return false; } $this->HiPrestaClass->deleteTabs('CONTROLLER_TABS_HIGALLERY'); if (Configuration::get('CLEAN_HI_GALLERY')) { $this->proceedDb(true); } return true; } protected function installDb() { $res = (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'higallery` ( `id_gallery` int(10) unsigned NOT NULL AUTO_INCREMENT, `active` tinyint(1) unsigned NOT NULL DEFAULT \'1\', `position` VARCHAR(100) NOT NULL, `sort` int unsigned NOT NULL, `date_add` DATETIME, `date_upd` DATETIME, PRIMARY KEY (`id_gallery`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8; '); $res &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'higallery_lang` ( `id_gallery` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(255) NOT NULL, `link_rewrite` varchar(255) NOT NULL, `title` varchar(255) NOT NULL, `description` text NOT NULL, `meta_title` varchar(255) NOT NULL, `meta_description` varchar(255) NOT NULL, `meta_keywords` varchar(255) NOT NULL, PRIMARY KEY (`id_gallery`, `id_lang`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8; '); $res &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'higallery_shop` ( `id_gallery` int(10) unsigned NOT NULL, `id_shop` int(10) unsigned NOT NULL, PRIMARY KEY (`id_gallery`,`id_shop`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8; '); $res &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'higallery_image` ( `id_image` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_gallery` int(10) unsigned NOT NULL, `image` varchar(256) NOT NULL, `position` INT(11) NOT NULL, `date_add` DATETIME, `date_upd` DATETIME, PRIMARY KEY (`id_image`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8; '); $res &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'higallery_image_lang` ( `id_image` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `image_caption` text NOT NULL, PRIMARY KEY (`id_image`, `id_lang`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8; '); $res &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'higallerysocialnetwork` ( `id_higallerysocialnetwork` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(256) NOT NULL, `active` tinyint(1) unsigned NOT NULL DEFAULT \'1\', `access_token` varchar(256) NOT NULL, `social_network` varchar(256) NOT NULL, PRIMARY KEY (`id_higallerysocialnetwork`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8; '); return $res; } private function proceedDb($drop = false) { if (!$drop) { Configuration::updateValue('CLEAN_HI_GALLERY', false); $languages = Language::getLanguages(false); foreach ($languages as $lang) { Configuration::updateValue('HI_GALLERY_PAGE_URL', array($lang['id_lang'] => 'gallery')); } } else { Configuration::deleteByName('CLEAN_HI_GALLERY'); Configuration::deleteByName('HI_GALLERY_PAGE_URL'); Configuration::deleteByName('HI_GALLERY_META_TITLE'); Configuration::deleteByName('HI_GALLERY_META_DESCRIPTION'); Configuration::deleteByName('HI_GALLERY_META_KEYWORDS'); $db_drop = array( 'higallery', 'higallery_lang', 'higallery_shop', 'higallery_image', 'higallery_image_lang', 'higallerysocialnetwork' ); if (!empty($db_drop)) { foreach ($db_drop as $value) { DB::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.pSQL($value)); } } $files_original = glob(_PS_MODULE_DIR_.$this->name.'/views/img/upload/original/*'); foreach ($files_original as $file) { if (is_file($file)) { if ($file != _PS_MODULE_DIR_.$this->name.'/views/img/upload/index.php') { unlink($file); } } } $files_smaill = glob(_PS_MODULE_DIR_.$this->name.'/views/img/upload/small/*'); foreach ($files_smaill as $file) { if (is_file($file)) { if ($file != _PS_MODULE_DIR_.$this->name.'/views/img/upload/index.php') { unlink($file); } } } $files_thumbnail = glob(_PS_MODULE_DIR_.$this->name.'/views/img/upload/thumbnail/*'); foreach ($files_thumbnail as $file) { if (is_file($file)) { if ($file != _PS_MODULE_DIR_.$this->name.'/views/img/upload/index.php') { unlink($file); } } } } } private function globalVars() { $this->psv = (float)Tools::substr(_PS_VERSION_, 0, 3); $this->clean_db = (bool)Configuration::get('CLEAN_HI_GALLERY'); foreach (Language::getLanguages(false) as $language) { $this->gallery_page_url[$language['id_lang']] = Configuration::get('HI_GALLERY_PAGE_URL', $language['id_lang']); $this->gallery_meta_title[$language['id_lang']] = Configuration::get('HI_GALLERY_META_TITLE', $language['id_lang']); $this->gallery_meta_description[$language['id_lang']] = Configuration::get('HI_GALLERY_META_DESCRIPTION', $language['id_lang']); $this->gallery_meta_keywords[$language['id_lang']] = Configuration::get('HI_GALLERY_META_KEYWORDS', $language['id_lang']); $this->gallery_page_title[$language['id_lang']] = Configuration::get('HI_GALLERY_PAGE_TITLE', $language['id_lang']); $this->gallery_page_description[$language['id_lang']] = Configuration::get('HI_GALLERY_PAGE_DESCRIPTION', $language['id_lang']); } } public function renderModal() { return $this->display(__FILE__, 'views/templates/admin/modal.tpl'); } public function renderFakeForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Fake'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'fake_description', 'class' => 'fake_desc', 'autoload_rte' => true, 'lang' => true, 'cols' => 100, 'rows' => 10 ), array( 'type' => 'file', 'label' => $this->l('Slideshow fake'), 'name' => 'fake_file', 'ajax' => true, 'multiple' => true ) ), ), ); $helper = new HelperForm(); $languages = Language::getLanguages(false); foreach ($languages as $key => $language) { $languages[$key]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')); } $helper->languages = $languages; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->show_toolbar = false; $this->fields_form = array(); $helper->submit_action = 'submitBlockSettings'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->module = $this; $empty_array = array(); $languages = Language::getLanguages(false); foreach ($languages as $lang) { $empty_array[$lang['id_lang']] = ''; } $helper->tpl_vars = array( 'fields_value' => array( 'fake_description' => $empty_array, ) ); return $helper->generateForm(array($fields_form)); } public function renderMenuTabs() { $tabs = array( 'generel_settings' => array( 'title' => $this->l('General settings'), 'icon' => 'icon-cog' ), 'gallery_list' => array( 'title' => $this->l('Galleries'), 'icon' => 'icon-camera' ), 'social_accounts' => array( 'title' => $this->l('Social Accounts'), 'icon' => 'icon-instagram' ), 'version' => array( 'title' => $this->l('Version'), 'icon' => 'icon-info' ) ); $more_modules = $this->HiPrestaClass->getModuleContent('A_PGL', false, '', true); if ($more_modules) { $tabs['more_modules'] = array( 'title' => $this->l('More Modules'), 'icon' => 'icon-plus-square' ); } $this->context->smarty->assign( array( 'psv' => $this->psv, 'tabs' => $tabs, 'module_version' => $this->version, 'module_url' => $this->HiPrestaClass->getModuleUrl(), 'module_tab_key' => $this->name, 'module_key' => Tools::getValue($this->name), ) ); return $this->display(__FILE__, 'views/templates/admin/menu_tabs.tpl'); } public function renderVersionForm() { $changelog = ''; if (file_exists(dirname(__FILE__) . '/changelog.txt')) { $changelog = Tools::file_get_contents(dirname(__FILE__) . '/changelog.txt'); } $this->context->smarty->assign('changelog', $changelog); return $this->display(__FILE__, 'views/templates/admin/version.tpl'); } public function renderDocumentationForm() { return $this->display(__FILE__, 'views/templates/admin/documentation.tpl'); } public function renderShopGroupError() { $this->context->smarty->assign( array( 'psv' => $this->psv, ) ); return $this->display(__FILE__, 'views/templates/admin/shop_group_error.tpl'); } public function renderModuleAdminVariables() { $this->context->smarty->assign( array( 'psv' => $this->psv, 'id_lang' => $this->context->language->id, 'id_shop' => Shop::getContextShopID(), 'lang_iso' => $this->context->language->iso_code, 'gallery_secure_key' => $this->secure_key, 'module_dir' => Tools::getHttpHost(true)._MODULE_DIR_.$this->name, 'module_image_path' => __PS_BASE_URI__.'modules/'.$this->name.'/views/img/', 'gallery_admin_controller_dir' => $this->context->link->getAdminLink('AdminGallery') ) ); return $this->display(__FILE__, 'views/templates/admin/variables.tpl'); } public function renderDisplayForm($content) { $this->context->smarty->assign( array( 'psv' => $this->psv, 'errors' => $this->errors, 'success' => $this->success, 'content' => $content ) ); return $this->display(__FILE__, 'views/templates/admin/display_form.tpl'); } public function getGalleryFrontUrl($link_rewrite = '') { $url = ''; if (Configuration::get('PS_REWRITING_SETTINGS')) { if ($link_rewrite !== '') { $url .= $this->context->link->getPageLink('galleryimages', null, null, array('link_rewrite' => $link_rewrite)); } else { $url .= $this->context->link->getPageLink('gallerys', null, null); } } else { if ($link_rewrite !== '') { $url .= $this->context->link->getModuleLink('higallery', 'galleryimage').'&link_rewrite='.$link_rewrite; } else { $url .= $this->context->link->getModuleLink('higallery', 'gallery'); } } return $url; } public function saveSocialAccount() { $id_social_account = (int)Tools::getValue('id_social_account'); $social_account = new GallerySocialAccount($id_social_account); $social_account->active = (int)Tools::getValue('social_active'); $social_account->title = trim(Tools::getValue('social_title')); $social_account->access_token = trim(Tools::getValue('social_access_token')); $social_account->social_network = trim(Tools::getValue('social_network')); if (!$social_account->save()) { return false; } if ($id_social_account) { return $id_social_account; } else { return $social_account->id; } } public function saveGallery($action, $id_gallery = null) { $gallery = new GalleryItem($id_gallery); $gallery->active = Tools::getValue('active'); $gallery->position = Tools::getValue('position'); foreach (Language::getLanguages(false) as $lang) { if (Tools::getValue('name_'.$lang['id_lang'])) { $gallery->name[$lang['id_lang']] = Tools::getValue('name_'.$lang['id_lang']); } else { $gallery->name[$lang['id_lang']] = Tools::getValue('name_'.Configuration::get('PS_LANG_DEFAULT')); } if (Tools::getValue('link_rewrite_'.$lang['id_lang'])) { $gallery->link_rewrite[$lang['id_lang']] = Tools::getValue('link_rewrite_'.$lang['id_lang']); } else { $gallery->link_rewrite[$lang['id_lang']] = Tools::getValue('link_rewrite_'.Configuration::get('PS_LANG_DEFAULT')); } $gallery->title[$lang['id_lang']] = Tools::getValue('page_title_'.$lang['id_lang']); $gallery->description[$lang['id_lang']] = Tools::getValue('page_description_'.$lang['id_lang']); $gallery->meta_title[$lang['id_lang']] = Tools::getValue('meta_title_'.$lang['id_lang']); $gallery->meta_description[$lang['id_lang']] = Tools::getValue('meta_description_'.$lang['id_lang']); $gallery->meta_keywords[$lang['id_lang']] = Tools::getValue('meta_keywords_'.$lang['id_lang']); } if ($action == 'add') { $gallery->add(); } else { $gallery->update(); } } public function saveGalleryImage($action_type, $id = null, $id_gallery = null) { $languages = Language::getLanguages(false); $gallery_image = new GalleryImage($id); $gallery_image->id_gallery = $id_gallery; $gallery_image->image = $this->uploadImage('image_file', $id); if(!$gallery_image->image) { return false; } foreach ($languages as $lang) { $gallery_image->image_caption[$lang['id_lang']] = Tools::getValue('image_caption_'.$lang['id_lang']); } if ($action_type == 'add') { $gallery_image->position = GalleryImage::getPositionMaxValue(); } if ($action_type == 'add') { $gallery_image->add(); } else { $gallery_image->update(); } return true; } public function saveMultipleImages($id_gallery = null) { $languages = Language::getLanguages(false); $gallery_image = new GalleryImage(); $gallery_image->id_gallery = $id_gallery; $gallery_image->image = $this->uploadMultipleImages('files'); if(!$gallery_image->image) { return false; } foreach ($languages as $lang) { $gallery_image->image_caption[$lang['id_lang']] = Tools::getValue('image_caption_'.$lang['id_lang']); } $gallery_image->position = GalleryImage::getPositionMaxValue(); $gallery_image->add(); return true; } public function uploadMultipleImages($name) { if (empty($_FILES[$name])) { return false; } else { $file = array(); $file['name'] = $_FILES[$name]['name'][0]; $file['tmp_name'] = $_FILES[$name]['tmp_name'][0]; $file['type'] = $_FILES[$name]['type'][0]; $file['error'] = $_FILES[$name]['error'][0]; $file['size'] = $_FILES[$name]['size'][0]; } if ($_FILES[$name]['name'][0] !== '' && $file['size'] > 0) { $type = Tools::strtolower(Tools::substr(strrchr($file['name'], '.'), 1)); $imagesize = array(); $imagesize = getimagesize($file['tmp_name']); list($file_width, $file_height) = getimagesize($file['tmp_name']); if(!$file_width || !$file_height) { return false; } $file_ratio = $file_width / $file_height; if (isset($_FILES[$name]) && isset($_FILES[$name]['tmp_name'][0]) && !empty($_FILES[$name]['tmp_name'][0]) && !empty($imagesize) && in_array(Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'MF'); // get available file name if(file_exists(dirname(__FILE__).'/views/img/upload/original/'.$file['name'])){ $i = 0; $ext_array = explode('.', $file['name']); $ext = array_pop($ext_array); $name = Tools::substr($file['name'], 0, -1 * Tools::strlen($ext)); while(file_exists(dirname(__FILE__).'/views/img/upload/original/'.$file['name'])) { $i++; $file['name'] = $name . $i . '.' . $ext; } } if($file_width >= 600){ $resize_width = 600; } else { $resize_width = $file_width; } if (ImageManager::validateUpload($file)) { return true; } elseif (!$temp_name || !move_uploaded_file($file['tmp_name'], $temp_name)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/views/img/upload/original/'.$file['name'], null, null, $type)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/views/img/upload/small/'.$file['name'], $resize_width, $resize_width/$file_ratio, $type)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/views/img/upload/thumbnail/'.$file['name'], 160, 160, $type)) { return false; } if (isset($temp_name)) { unlink($temp_name); } $image = $file['name']; } } else { $image = ''; } return $image; } public function uploadImage($name, $id = null) { if (empty($_FILES[$name])) { return false; } if ($_FILES[$name]['name']) { $file = array(); $file['name'] = $_FILES[$name]['name']; $file['tmp_name'] = $_FILES[$name]['tmp_name']; $file['type'] = $_FILES[$name]['type']; $file['error'] = $_FILES[$name]['error']; $file['size'] = $_FILES[$name]['size']; $type = Tools::strtolower(Tools::substr(strrchr($file['name'], '.'), 1)); $imagesize = array(); list($file_width, $file_height) = getimagesize($file['tmp_name']); if(!$file_width || !$file_height) { return false; } $file_ratio = $file_width / $file_height; $imagesize = getimagesize($file['tmp_name']); if (!empty($file['tmp_name']) && !empty($imagesize) && in_array(Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'MF'); // get available file name if(file_exists(dirname(__FILE__).'/views/img/upload/original/'.$file['name'])){ $i = 0; $ext_array = explode('.', $file['name']); $ext = array_pop($ext_array); $name = Tools::substr($file['name'], 0, -1 * Tools::strlen($ext)); while(file_exists(dirname(__FILE__).'/views/img/upload/original/'.$file['name'])) { $i++; $file['name'] = $name . $i . '.' . $ext; } } if($file_width >= 600){ $resize_width = 600; } else { $resize_width = $file_width; } if (ImageManager::validateUpload($file)) { return true; } elseif (!$temp_name || !move_uploaded_file($file['tmp_name'], $temp_name)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/views/img/upload/original/'.$file['name'], null, null, $type)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/views/img/upload/small/'.$file['name'], $resize_width, $resize_width/$file_ratio, $type)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/views/img/upload/thumbnail/'.$file['name'], 160, 160, $type)) { return false; } if (isset($temp_name)) { unlink($temp_name); } $image = $file['name']; $gallery_image = new GalleryImage($id); if ($gallery_image->image) { if (file_exists(_PS_MODULE_DIR_.$this->name.'/views/img/upload/original/'.$gallery_image->image)) { unlink(_PS_MODULE_DIR_.$this->name.'/views/img/upload/original/'.$gallery_image->image); } elseif (file_exists(_PS_MODULE_DIR_.$this->name.'/views/img/upload/small/'.$gallery_image->image)) { unlink(_PS_MODULE_DIR_.$this->name.'/views/img/upload/small/'.$gallery_image->image); } elseif (file_exists(_PS_MODULE_DIR_.$this->name.'/views/img/upload/thumbnail/'.$gallery_image->image)) { unlink(_PS_MODULE_DIR_.$this->name.'/views/img/upload/thumbnail/'.$gallery_image->image); } } } else { return false; } } else { $gallery_image = new GalleryImage($id); $image = $gallery_image->image; } return $image; } public function copyImageFromURL($url) { $salt = sha1(microtime()); $file_name = Tools::encrypt($url.$salt); $file = dirname(__FILE__).'/views/img/upload/original/'.$file_name.'.jpg'; if (file_exists($file)) { $i = 0; while(file_exists(dirname(__FILE__).'/views/img/upload/original/'.$file_name.'.jpg')) { $i++; $file_name = $file_name . $i; } $file = dirname(__FILE__).'/views/img/upload/original/'.$file_name.'.jpg'; } Tools::copy($url, $file); list($file_width, $file_height) = getimagesize($file); $file_ratio = $file_width / $file_height; if($file_width >= 600){ $resize_width = 600; } else { $resize_width = $file_width; } ImageManager::resize($file, dirname(__FILE__).'/views/img/upload/small/'.$file_name.'.jpg', $resize_width, $resize_width / $file_ratio); ImageManager::resize($file, dirname(__FILE__).'/views/img/upload/thumbnail/'.$file_name.'.jpg', 160, 160); return $file_name.'.jpg'; } public function renderSettingsForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Gallery Page URL'), 'name' => 'gallery_rewrite_url', 'lang' => true, 'prefix' => $this->context->shop->getBaseURL(true), 'suffix' => $this->renderLink($this->context->shop->getBaseURL(true) . $this->gallery_page_url[$this->context->language->id], $this->l('Preview'), '_blank'), 'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.') ), array( 'type' => 'text', 'label' => $this->l('Page title'), 'name' => 'gallery_page_title', 'lang' => true ), array( 'type' => 'textarea', 'label' => $this->l('Page description'), 'name' => 'gallery_page_description', 'autoload_rte' => true, 'lang' => true ), array( 'type' => 'text', 'label' => $this->l('Meta title'), 'name' => 'gallery_meta_title', 'maxchar' => 255, 'lang' => true, 'rows' => 5, 'cols' => 100, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'textarea', 'label' => $this->l('Meta description'), 'name' => 'gallery_meta_description', 'maxchar' => 255, 'lang' => true, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'gallery_meta_keywords', 'lang' => true, 'maxchar' => 255, 'string_format' => false, 'hint' => $this->l('To add "tags," click in the field, write something, and then press "Enter."').' '.$this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => $this->psv >= 1.6 ? 'switch':'radio', 'label' => $this->l('Clean Database when module uninstalled'), 'name' => 'clean_db', 'class' => 't', 'is_bool' => true, 'desc' => $this->l('Not recommended, use this only when you’re not going to use the module'), 'values' => array( array( 'id' => 'clean_db_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'clean_db_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'name' => 'submit_settings_form', 'class' => $this->psv >= 1.6 ? 'btn btn-default pull-right':'button', ) ), ); $helper = new HelperForm(); $helper->module = $this; $helper->show_toolbar = false; $languages = Language::getLanguages(false); foreach ($languages as $key => $language) { $languages[$key]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')); } $helper->languages = $languages; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $this->fields_form = array(); $helper->submit_action = 'submitBlockSettings'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = $this->context->link->getAdminLink( 'AdminModules', false ).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&'.$this->name.'=generel_settings'; $helper->tpl_vars = array( 'fields_value' => $this->getSettingsValues() ); return $helper->generateForm(array($fields_form)); } public function getSettingsValues() { return array( 'gallery_rewrite_url' => $this->gallery_page_url, 'gallery_meta_title' => $this->gallery_meta_title, 'gallery_meta_description' => $this->gallery_meta_description, 'gallery_meta_keywords' => $this->gallery_meta_keywords, 'clean_db' => $this->clean_db, 'gallery_page_title' => $this->gallery_page_title, 'gallery_page_description' => $this->gallery_page_description ); } /*Gallery list*/ public function renderGalleriesList() { $fields_list = array( 'sort' => array( 'title' => $this->l('Sort'), 'width' => 60, 'type' => 'text', 'search' => false, ), 'id_gallery' => array( 'title' => $this->l('ID'), 'width' => 60, 'type' => 'text', 'search' => false, ), 'name' => array( 'title' => $this->l('Name'), 'width' => 140, 'type' => 'text', 'search' => false, ), 'position' => array( 'title' => $this->l('Position'), 'width' => 140, 'type' => 'text', 'search' => false, ), 'status' => array( 'title' => $this->l('Status'), 'width' => 140, 'type' => 'text', 'search' => false, ), 'manage_image' => array( 'title' => $this->l('Manage images'), 'width' => 140, 'type' => 'text', 'search' => false, ), 'custom_hook' => array( 'title' => $this->l('Custom Hook'), 'width' => 140, 'search' => false, ), 'custom_html' => array( 'title' => $this->l('HTML element'), 'width' => 140, 'search' => false, ) ); $helper = new HelperList(); $helper->module = $this; $helper->no_link = true; $helper->shopLinkType = ''; $helper->simple_header = false; $helper->actions = array('edit', 'delete'); $helper->identifier = 'id_gallery'; $helper->show_toolbar = false; $helper->title = $this->l('Galleries'); $helper->table = 'higallery'; $helper->toolbar_btn['new'] = array( 'href' => '#', 'desc' => $this->l('new Gallery') ); $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&'.$this->name.'=gallery_list'; $sql_result = GalleryItem::getGalleriesList(); $helper->listTotal = count($sql_result); $page = ($page = Tools::getValue('submitFilter'.$helper->table)) ? $page : 1; $pagination = ($pagination = Tools::getValue($helper->table.'_pagination')) ? $pagination : 50; $sql_result = $this->HiPrestaClass->pagination($sql_result, $page, $pagination); return $helper->generateList($sql_result, $fields_list); } public function renderAddGalleryForm($action_type = 'add', $id_row = null) { $gallery = new GalleryItem($id_row); $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Gallery'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'hidden', 'name' => 'row_id', ), array( 'type' => 'hidden', 'name' => 'action_type', ), array( 'type' => 'switch', 'label' => $this->l('Active'), 'name' => 'active', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ) ), array( 'type' => 'select', 'label' => $this->l('Position to display'), 'name' => 'position', 'required' => true, 'options' => array( 'query' => array( array('id' => '', 'name' => $this->l('None')), array('id' => 'gallery_page','name' => $this->l('Gallery Page')), array('id' => 'single_gallery_page','name' => $this->l('Single Gallery Page')), array('id' => 'displayHome', 'name' => $this->l('Home')), array('id' => 'displayLeftColumn', 'name' => $this->l('Left Column')), array('id' => 'displayRightColumn', 'name' => $this->l('Right Column')), array('id' => 'displayFooter', 'name' => $this->l('Footer')), array('id' => 'custom','name' => $this->l('Custom')) ), 'id' => 'id', 'name' => 'name' ) ), array( 'type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'lang' => true, 'class' => 'copy2friendlyUrl', 'required' => true, ), array( 'type' => 'text', 'label' => $this->l('Gallery title'), 'name' => 'page_title', 'lang' => true, ), array( 'type' => 'textarea', 'label' => $this->l('Gallery description'), 'name' => 'page_description', 'autoload_rte' => true, 'lang' => true, ), array( 'type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'lang' => true, 'required' => true, 'form_group_class' => 'gallery_page_content', 'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.'), 'prefix' => Tools::getHttpHost(true).__PS_BASE_URI__ . $this->gallery_page_url[$this->context->language->id] .'/', 'suffix' => $id_row ? $this->renderLink($this->context->shop->getBaseURL(true) . $this->gallery_page_url[$this->context->language->id] . '/' . $gallery->link_rewrite[$this->context->language->id], $this->l('Preview'), '_blank') : '' ), array( 'type' => 'text', 'label' => $this->l('Meta title'), 'name' => 'meta_title', 'maxchar' => 250, 'lang' => true, 'rows' => 5, 'cols' => 100, 'form_group_class' => 'gallery_page_content', 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'textarea', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'maxchar' => 250, 'lang' => true, 'form_group_class' => 'gallery_page_content', 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'maxchar' => 250, 'form_group_class' => 'gallery_page_content', 'string_format' => false, 'hint' => $this->l('To add "tags," click in the field, write something, and then press "Enter."').' '.$this->l('Forbidden characters:').' <>;=#{}' ), ), 'submit' => array( 'title' => $this->l('Save'), 'name' => 'submit_gallery_list_form' ), 'buttons' => array( array( 'title' => $this->l('Cancel'), 'class' => $this->psv < 1.6 ? 'button':'btn btn-default pull-left', 'name' => 'submit_gallery_cancel', 'icon' => 'process-icon-cancel', ), ) ), ); $helper = new HelperForm(); $languages = Language::getLanguages(false); foreach ($languages as $key => $language) { $languages[$key]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')); } $helper->languages = $languages; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->show_toolbar = false; $helper->submit_action = 'submitBlockSettings'; $helper->currentIndex = $this->context->link->getAdminLink( 'AdminModules', false ).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&'.$this->name.'=gallery_list'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->module = $this; $helper->tpl_vars = array( 'name_controller' => 'gallery_form', 'fields_value' => $this->getAddGalleryFieldsValues($action_type, $id_row) ); return $helper->generateForm(array($fields_form)); } public function getAddGalleryFieldsValues($action_type, $id_row) { if ($action_type == 'update') { $gallery = new GalleryItem($id_row); return array( 'row_id' => $id_row, 'action_type' => 'update', 'position' => $gallery->position, 'active' => $gallery->active, 'name' => $gallery->name, 'link_rewrite' => $gallery->link_rewrite, 'page_title' => $gallery->title, 'page_description' => $gallery->description, 'meta_title' => $gallery->meta_title, 'meta_description' => $gallery->meta_description, 'meta_keywords' => $gallery->meta_keywords, ); } else { $empty_array = array(); $languages = Language::getLanguages(false); foreach ($languages as $lang) { $empty_array[$lang['id_lang']] = ''; } return array( 'row_id' => $id_row, 'action_type' => 'add', 'active' => true, 'position' => '', 'name' => $empty_array, 'link_rewrite' => $empty_array, 'page_title' => $empty_array, 'page_description' => $empty_array, 'meta_title' => $empty_array, 'meta_description' => $empty_array, 'meta_keywords' => $empty_array, ); } } /*Gallery image*/ public function renderAddGalleryImageForm($id_gallery, $action_type = 'add', $id_row = null) { $image = ''; if ($action_type == 'update') { $gallery_image = new GalleryImage($id_row); $image = $gallery_image->image; } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Manage Images'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'hidden', 'name' => 'multiple_image_files_max_files', ), array( 'type' => 'hidden', 'name' => 'action_type', ), array( 'type' => 'hidden', 'name' => 'row_id', ), array( 'type' => 'hidden', 'name' => 'id_gallery', ), array( 'type' => 'button', 'label' => $this->l('Import from Social Account'), 'name' => 'social_import', 'class' => 'social_import', 'title' => $this->l('Select Social Account') ), array( 'type' => 'file_multiple', 'label' => $this->l('Upload Images'), 'name' => 'multiple_image_files', 'class' => 'multiple_image_files', 'ajax' => true ), array( 'type' => 'text', 'label' => $this->l('Image caption'), 'name' => 'image_caption', 'class' => 'image_caption', 'lang' => true, ), ), 'buttons' => array( array( 'title' => $this->l('Cancel'), 'class' => $this->psv < 1.6 ? 'button':'btn btn-default pull-left', 'name' => 'submit_gallery_cancel', 'icon' => 'process-icon-cancel', ), ) ), ); if($image != ''){ $fields_form['form']['input'][4] = array( 'type' => 'file', 'label' => $this->l('Select Image File'), 'name' => 'image_file', 'required' => true, 'desc' => "" ); $fields_form['form']['submit'] = array( 'title' => $this->l('Save'), 'name' => 'submit_gallery_image_form' ); } $helper = new HelperForm(); $languages = Language::getLanguages(false); foreach ($languages as $key => $language) { $languages[$key]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')); } $helper->languages = $languages; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->show_toolbar = false; $helper->submit_action = 'submitBlockSettings'; $helper->currentIndex = $this->context->link->getAdminLink( 'AdminModules', false ).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&'.$this->name.'=gallery_image'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->module = $this; $helper->tpl_vars = array( 'name_controller' => 'gallery_image_form', 'fields_value' => $this->getAddGalleryImageFieldsValues($id_gallery, $action_type, $id_row), 'max_files' => 100, 'gallery_controller_url' => $this->context->link->getAdminLink('AdminGallery').'&ajax=1&secure_key='.$this->secure_key.'&psv='.$this->psv.'&action=upload_multiple_images' ); return $helper->generateForm(array($fields_form)); } public function getAddGalleryImageFieldsValues($id_gallery, $action_type, $id_row) { if ($action_type == 'update') { $gallery = new GalleryImage($id_row); return array( 'id_gallery' => $id_gallery, 'row_id' => $id_row, 'action_type' => 'update', 'image_caption' => $gallery->image_caption, 'multiple_image_files_max_files' => '' ); } else { $empty_array = array(); $languages = Language::getLanguages(false); foreach ($languages as $lang) { $empty_array[$lang['id_lang']] = ''; } return array( 'id_gallery' => $id_gallery, 'row_id' => $id_row, 'action_type' => 'add', 'image_caption' => $empty_array, 'multiple_image_files_max_files' => '' ); } } public function renderGalleryImageList($id_gallery) { $this->context->smarty->assign( array( 'upload_img_path' => __PS_BASE_URI__.'modules/'.$this->name.'/views/img/upload/', 'gallery_all_image' => GalleryImage::getGalleryAllImages($id_gallery), 'id_gallery' => $id_gallery, ) ); return $this->display(__FILE__, 'views/templates/admin/gallery_image.tpl'); } public function renderModuleAdvertisingForm() { $this->HiPrestaClass->getModuleContent('A_PGL'); return $this->display(__FILE__, 'views/templates/admin/moduleadvertising.tpl'); } public function renderLink($link, $title, $target = '_self') { $this->context->smarty->assign(array( 'link' => $link, 'title' => $title, 'target' => $target )); return $this->display(__FILE__, 'views/templates/admin/link.tpl'); } public function renderSelectSocialAccount() { $this->context->smarty->assign(array( 'add_social_accounts_url' => $this->HiPrestaClass->getModuleUrl() . '&' . $this->name . '=social_accounts', 'social_accounts' => GallerySocialAccount::getAccounts(true) )); return $this->display(__FILE__, 'views/templates/admin/select-social-account.tpl'); } public function loadSocialAccountImages($images, $ig_next_page) { $this->context->smarty->assign(array( 'social_account_images' => $images, 'ig_next_page' => $ig_next_page )); return $this->display(__FILE__, 'views/templates/admin/load-social-account-images.tpl'); } public function loadMoreSocialAccountImages($images) { $this->context->smarty->assign(array( 'social_account_images' => $images )); return $this->display(__FILE__, 'views/templates/admin/load-more-social-account-images.tpl'); } public function displayForm() { $html = ''; $content = ''; if (!$this->HiPrestaClass->isSelectedShopGroup()) { $html .= $this->renderMenuTabs(); switch (Tools::getValue($this->name)) { case 'generel_settings': $content .= $this->renderSettingsForm(); break; case 'gallery_list': $content .= $this->renderFakeForm(); $content .= $this->renderModal(); $content .= $this->renderGalleriesList(); break; case 'social_accounts': $content .= $this->renderModal(); $content .= $this->adminForms->renderSocialAccountsList(); break; case 'more_modules': $content .= $this->renderModuleAdvertisingForm(); break; case 'version': $content .= $this->renderVersionForm(); break; case 'documentation': $content .= $this->renderDocumentationForm(); break; default: $content .= $this->renderSettingsForm(); break; } $html .= $this->renderDisplayForm($content); } else { $html .= $this->renderShopGroupError(); } $this->context->controller->addCSS($this->_path.'views/css/admin.css', 'all'); $this->context->controller->addJS(($this->_path).'views/js/admin.js'); $this->context->controller->addJqueryPlugin('tagify'); $this->context->controller->addJqueryUI('ui.sortable'); $html .= $this->renderModuleAdminVariables(); return $html; } public function postProcess() { if (Tools::isSubmit('submit_settings_form')) { $languages = Language::getLanguages(false); if (trim(Tools::getValue('gallery_rewrite_url_'.Configuration::get('PS_LANG_DEFAULT'))) == '') { $this->errors[] = $this->l('Invalid value for friendly URL'); } else { foreach ($languages as $lang) { if (trim(Tools::getValue('gallery_rewrite_url_'.$lang['id_lang'])) != '' && !Validate::isLinkRewrite(trim(Tools::getValue('gallery_rewrite_url_'.$lang['id_lang'])))) { $this->errors[] = $this->l('Invalid value for friendly URL'); } } } if (empty($this->errors)) { $languages = Language::getLanguages(false); foreach ($languages as $lang) { Configuration::updateValue( 'HI_GALLERY_PAGE_URL', array($lang['id_lang'] => Tools::getValue('gallery_rewrite_url_'.$lang['id_lang'])) ); Configuration::updateValue( 'HI_GALLERY_META_TITLE', array($lang['id_lang'] => Tools::getValue('gallery_meta_title_'.$lang['id_lang'])) ); Configuration::updateValue( 'HI_GALLERY_META_DESCRIPTION', array($lang['id_lang'] => Tools::getValue('gallery_meta_description_'.$lang['id_lang'])) ); Configuration::updateValue( 'HI_GALLERY_META_KEYWORDS', array($lang['id_lang'] => Tools::getValue('gallery_meta_keywords_'.$lang['id_lang'])) ); Configuration::updateValue( 'HI_GALLERY_PAGE_TITLE', array($lang['id_lang'] => Tools::getValue('gallery_page_title_'.$lang['id_lang'])) ); Configuration::updateValue( 'HI_GALLERY_PAGE_DESCRIPTION', array($lang['id_lang'] => Tools::getValue('gallery_page_description_'.$lang['id_lang'])), true ); } Configuration::updateValue('CLEAN_HI_GALLERY', (bool)Tools::getValue('clean_db')); $this->success[] = $this->l('Successful Save'); } } } public function getContent() { if (Tools::isSubmit('submit_settings_form')) { $this->postProcess(); } $this->globalVars(); $this->HiPrestaClass->autoRegisterHook($this->id, array()); return $this->displayForm(); } public function hookHeader() { $this->context->controller->addCSS($this->_path.'views/css/front.css', 'all'); $this->context->controller->addJS($this->_path.'views/js/front.js'); /*Masonry*/ $this->context->controller->addJS($this->_path.'views/js/masonry.pkgd.min.js'); /*Image loader*/ $this->context->controller->addJS($this->_path.'views/js/imagesloaded.pkgd.min.js'); $this->context->controller->addCSS($this->_path.'views/css/jquery.magnific-popup.css', 'all'); $this->context->controller->addJS($this->_path.'views/js/jquery.magnific-popup.min.js'); if ($this->psv < 1.7) { if (Dispatcher::getInstance()->getController() === 'galleryimage') { $galleryimage_meta = GalleryItem::getGalleriesContentByFriendlyUrl(Tools::getValue('link_rewrite')); if (!empty($galleryimage_meta)) { $this->context->smarty->assign(array( 'meta_title' => $galleryimage_meta['meta_title'], 'meta_description' => $galleryimage_meta['meta_description'], 'meta_keywords' => $galleryimage_meta['meta_keywords'], )); } } if (Dispatcher::getInstance()->getController() === 'gallery') { $this->context->smarty->assign(array( 'meta_title' => $this->gallery_meta_title[$this->context->language->id], 'meta_description' => $this->gallery_meta_description[$this->context->language->id], 'meta_keywords' => $this->gallery_meta_keywords[$this->context->language->id] )); } } $this->context->smarty->assign( array( 'psv' => $this->psv, 'gl_secure_key' => $this->secure_key, ) ); $jsVars = array(); $jsVars['higallery'] = array( 'psv' => $this->psv, 'secure_key' => $this->secure_key, 'ajax_url' => $this->context->link->getModuleLink($this->name, 'ajax') ); Media::addJsDef($jsVars); return $this->display(__FILE__, 'header.tpl'); } public function renderGallery($id_gallery) { $gallery = GalleryItem::getGalleryByID($id_gallery); $this->context->smarty->assign(array( 'psv' => $this->psv, 'gallery' => $gallery, 'upload_img_path' => __PS_BASE_URI__.'modules/'.$this->name.'/views/img/upload/', )); return $this->display(__FILE__, 'gallery-ajax.tpl'); } public function returnHookValue($position, $id_gallery = null) { if ($position != null) { $gallerys = GalleryItem::getGalleriesContentByPosition($position); } else { $gallerys = GalleryItem::getGalleriesContentById($id_gallery); } if (empty($gallerys)) { return false; } $this->context->smarty->assign( array( 'psv' => $this->psv, 'gallerys' => $gallerys, 'upload_img_path' => __PS_BASE_URI__.'modules/'.$this->name.'/views/img/upload/', ) ); return $this->display(__FILE__, 'gallery.tpl'); } public function hookHome() { return $this->returnHookValue('displayHome'); } public function hookLeftColumn() { return $this->returnHookValue('displayLeftColumn'); } public function hookRightColumn() { return $this->returnHookValue('displayRightColumn'); } public function hookFooter() { return $this->returnHookValue('displayFooter'); } public function hookhigallery($params) { $id = isset($params['id']) ? $params['id'] : null; return $this->returnHookValue(null, $id); } public function hookModuleRoutes($params) { $return = array(); $return_1 = array( 'controller' => 'gallery', 'rule' => $this->gallery_page_url[$this->context->language->id], 'params' => array( 'fc' => 'module', 'module' => 'higallery', 'controller' => 'gallery', ), 'keywords' => array(), ); $return_2 = array( 'controller' => 'galleryimage', 'rule' => $this->gallery_page_url[$this->context->language->id] . '{/:link_rewrite}', 'params' => array( 'fc' => 'module', 'module' => 'higallery', 'controller' => 'galleryimage', ), 'keywords' => array( 'link_rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*', 'param' => 'link_rewrite'), ), ); // Change controller name in hookModuleRoutes add 's' ex. test -> tests... // and get url use getPageLink('tests', null, null) ... $return['gallerys'] = $return_1; $return['galleryimages'] = $return_2; return $return; } }