diff --git a/classes/ImageType.php b/classes/ImageType.php index df48d21da..46c1348ea 100644 --- a/classes/ImageType.php +++ b/classes/ImageType.php @@ -43,6 +43,9 @@ class ImageTypeCore extends ObjectModel /** @var int Apply to categories */ public $categories; + /** @var int Apply to hotels */ + public $hotels; + /** @var int Apply to manufacturers */ public $manufacturers; @@ -67,6 +70,7 @@ class ImageTypeCore extends ObjectModel 'height' => array('type' => self::TYPE_INT, 'validate' => 'isImageSize', 'required' => true), 'categories' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'products' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + 'hotels' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'manufacturers' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'suppliers' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'scenes' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), @@ -110,6 +114,17 @@ class ImageTypeCore extends ObjectModel return self::$images_types_cache[$type]; } + /** + * Get image type properties from type name + * + * @param string $type_name Name + * @return array Image type definition + */ + public static function getTypeByName($name) + { + return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'image_type` WHERE `name` like "'.pSQL($name).'"'); + } + /** * Check if type already is already registered in database * diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index dff3e5ceb..97e5c30e4 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -1692,8 +1692,8 @@ abstract class ObjectModelCore implements Core_Foundation_Database_EntityInterfa $types = ImageType::getImagesTypes(); foreach ($types as $image_type) { if ($this->image_name) { // by webkul - if (file_exists($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format) - && !unlink($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format)) { + if (file_exists($this->image_dir.$this->image_name.'-'.stripslashes($image_type['name']).'.'.$this->image_format) + && !unlink($this->image_dir.$this->image_name.'-'.stripslashes($image_type['name']).'.'.$this->image_format)) { return false; } } else { diff --git a/config/defines.inc.php b/config/defines.inc.php index 829cee0b8..4a86b1930 100644 --- a/config/defines.inc.php +++ b/config/defines.inc.php @@ -128,6 +128,7 @@ define('_PS_LANG_IMG_DIR_', _PS_IMG_DIR_.'l/'); define('_PS_MANU_IMG_DIR_', _PS_IMG_DIR_.'m/'); define('_PS_ORDER_STATE_IMG_DIR_', _PS_IMG_DIR_.'os/'); define('_PS_PROD_IMG_DIR_', _PS_IMG_DIR_.'p/'); +define('_PS_HOTEL_IMG_DIR_', _PS_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'); define('_PS_SCENE_IMG_DIR_', _PS_IMG_DIR_.'scenes/'); define('_PS_SCENE_THUMB_IMG_DIR_', _PS_IMG_DIR_.'scenes/thumbs/'); define('_PS_SHIP_IMG_DIR_', _PS_IMG_DIR_.'s/'); diff --git a/config/defines_uri.inc.php b/config/defines_uri.inc.php index 19b2fd530..a7e882daa 100644 --- a/config/defines_uri.inc.php +++ b/config/defines_uri.inc.php @@ -71,6 +71,7 @@ define('_THEME_COL_DIR_', _PS_IMG_.'co/'); define('_THEME_GENDERS_DIR_', _PS_IMG_.'genders/'); define('_SUPP_DIR_', _PS_IMG_.'su/'); define('_PS_PROD_IMG_', _PS_IMG_.'p/'); +define('_PS_HOTEL_IMG_', __PS_BASE_URI__.'modules/hotelreservationsystem/views/img/hotel_img/'); /* Other URLs */ define('_PS_JS_DIR_', __PS_BASE_URI__.'js/'); diff --git a/controllers/admin/AdminImagesController.php b/controllers/admin/AdminImagesController.php index 11ce68c13..131f871ca 100644 --- a/controllers/admin/AdminImagesController.php +++ b/controllers/admin/AdminImagesController.php @@ -52,20 +52,53 @@ class AdminImagesControllerCore extends AdminController ); $this->fields_list = array( - 'id_image_type' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), - 'name' => array('title' => $this->l('Name')), - 'width' => array('title' => $this->l('Width'), 'suffix' => ' px'), - 'height' => array('title' => $this->l('Height'), 'suffix' => ' px'), - 'products' => array('title' => $this->l('Products'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printEntityActiveIcon', 'orderby' => false), - 'categories' => array('title' => $this->l('Categories'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printEntityActiveIcon', 'orderby' => false), - // 'manufacturers' => array('title' => $this->l('Manufacturers'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printEntityActiveIcon', 'orderby' => false), - // 'suppliers' => array('title' => $this->l('Suppliers'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printEntityActiveIcon', 'orderby' => false), - // 'stores' => array('title' => $this->l('Stores'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printEntityActiveIcon', 'orderby' => false) + 'id_image_type' => array( + 'title' => $this->l('ID'), + 'align' => 'center', + 'class' => 'fixed-width-xs' + ), + 'name' => array( + 'title' => $this->l('Name'), + 'align' => 'left' + ), + 'width' => array( + 'title' => $this->l('Width'), + 'suffix' => ' px' + ), + 'height' => array( + 'title' => $this->l('Height'), + 'suffix' => ' px' + ), + 'products' => array( + 'title' => $this->l('Products'), + 'align' => 'center', + 'type' => 'bool', + 'active' => 'products', + 'ajax' => true, + 'orderby' => false + ), + 'categories' => array( + 'title' => $this->l('Categories'), + 'align' => 'center', + 'type' => 'bool', + 'active' => 'categories', + 'ajax' => true, + 'orderby' => false + ), + 'hotels' => array( + 'title' => $this->l('Hotels'), + 'align' => 'center', + 'type' => 'bool', + 'active' => 'hotels', + 'ajax' => true, + 'callback' => 'printEntityActiveIcon', + 'orderby' => false + ), ); // Scenes tab has been removed by default from the installation, but may still exists in updates if (Tab::getIdFromClassName('AdminScenes')) { - $this->fields_list['scenes'] = array('title' => $this->l('Scenes'), 'align' => 'center', 'type' => 'bool', 'callback' => 'printEntityActiveIcon', 'orderby' => false); + $this->fields_list['scenes'] = array('title' => $this->l('Scenes'), 'align' => 'center', 'type' => 'bool', 'orderby' => false); } // No need to display the old image system migration tool except if product images are in _PS_PROD_IMG_DIR_ @@ -267,87 +300,26 @@ class AdminImagesControllerCore extends AdminController ), ) ), - // array( - // 'type' => 'switch', - // 'label' => $this->l('Manufacturers'), - // 'name' => 'manufacturers', - // 'required' => false, - // 'is_bool' => true, - // 'hint' => $this->l('This type will be used for Manufacturer images.'), - // 'values' => array( - // array( - // 'id' => 'manufacturers_on', - // 'value' => 1, - // 'label' => $this->l('Enabled') - // ), - // array( - // 'id' => 'manufacturers_off', - // 'value' => 0, - // 'label' => $this->l('Disabled') - // ), - // ) - // ), - // array( - // 'type' => 'switch', - // 'label' => $this->l('Suppliers'), - // 'name' => 'suppliers', - // 'required' => false, - // 'is_bool' => true, - // 'hint' => $this->l('This type will be used for Supplier images.'), - // 'values' => array( - // array( - // 'id' => 'suppliers_on', - // 'value' => 1, - // 'label' => $this->l('Enabled') - // ), - // array( - // 'id' => 'suppliers_off', - // 'value' => 0, - // 'label' => $this->l('Disabled') - // ), - // ) - // ), array( 'type' => 'switch', - 'label' => $this->l('Scenes'), - 'name' => 'scenes', + 'label' => $this->l('Hotels'), + 'name' => 'hotels', 'required' => false, - 'class' => 't', 'is_bool' => true, - 'hint' => $this->l('This type will be used for Scene images.'), + 'hint' => $this->l('This type will be used for Hotel images.'), 'values' => array( array( - 'id' => 'scenes_on', + 'id' => 'hotels_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( - 'id' => 'scenes_off', + 'id' => 'hotels_off', 'value' => 0, 'label' => $this->l('Disabled') ), ) ), - // array( - // 'type' => 'switch', - // 'label' => $this->l('Stores'), - // 'name' => 'stores', - // 'required' => false, - // 'is_bool' => true, - // 'hint' => $this->l('This type will be used for Store images.'), - // 'values' => array( - // array( - // 'id' => 'stores_on', - // 'value' => 1, - // 'label' => $this->l('Enabled') - // ), - // array( - // 'id' => 'stores_off', - // 'value' => 0, - // 'label' => $this->l('Disabled') - // ), - // ) - // ), ), 'submit' => array( 'title' => $this->l('Save') @@ -357,6 +329,29 @@ class AdminImagesControllerCore extends AdminController parent::__construct(); } + public function ajaxProcess() + { + $response = array('success' => false); + if ($action = Tools::getValue('action')) { + $action = str_replace('image_type', '', $action); + $fields = ObjectModel::getDefinition($this->className)['fields']; + if (array_key_exists($action, $fields)) { + $idImageType = Tools::getValue('id_image_type'); + if (Validate::isLoadedObject($objImageType = new ImageType($idImageType))) { + $objImageType->$action = !$objImageType->$action; + if ($objImageType->save()) { + $response['success'] = true; + $response['text'] = $this->l('The status has been updated successfully.'); + } else { + $response['text'] = $this->l('An error occurred while updating this status.'); + } + } + } + } + + $this->ajaxDie(json_encode($response)); + } + public function postProcess() { // When moving images, if duplicate images were found they are moved to a folder named duplicates/ @@ -404,11 +399,6 @@ class AdminImagesControllerCore extends AdminController } } - public static function printEntityActiveIcon($value, $object) - { - return ($value ? '' : ''); - } - protected function _childValidation() { if (!Tools::getValue('id_image_type') && Validate::isImageTypeName($typeName = Tools::getValue('name')) && ImageType::typeAlreadyExists($typeName)) { @@ -423,11 +413,8 @@ class AdminImagesControllerCore extends AdminController { $types = array( 'categories' => $this->l('Categories'), - 'manufacturers' => $this->l('Manufacturers'), - 'suppliers' => $this->l('Suppliers'), - 'scenes' => $this->l('Scenes'), - 'products' => $this->l('Products'), - 'stores' => $this->l('Stores') + 'products' => $this->l('Room Types'), + 'hotels' => $this->l('Hotels'), ); $formats = array(); @@ -455,19 +442,6 @@ class AdminImagesControllerCore extends AdminController if (!is_dir($dir)) { return false; } - $toDel = scandir($dir); - - foreach ($toDel as $d) { - foreach ($type as $imageType) { - if (preg_match('/^[0-9]+\-'.($product ? '[0-9]+\-' : '').$imageType['name'].'\.jpg$/', $d) - || (count($type) > 1 && preg_match('/^[0-9]+\-[_a-zA-Z0-9-]*\.jpg$/', $d)) - || preg_match('/^([[:lower:]]{2})\-default\-'.$imageType['name'].'\.jpg$/', $d)) { - if (file_exists($dir.$d)) { - unlink($dir.$d); - } - } - } - } // delete product images using new filesystem. if ($product) { @@ -488,6 +462,25 @@ class AdminImagesControllerCore extends AdminController } } } + } else { + $toDel = scandir($dir); + foreach ($toDel as $d) { + if ($d === '.' || $d === '..') { + continue; + } + if (is_dir($dir.$d)) { + $this->_deleteOldImages($dir.$d.'/', $type, $product); + } + foreach ($type as $imageType) { + if (preg_match('/^[0-9]+\-'.($product ? '[0-9]+\-' : '').$imageType['name'].'\.jpg$/', $d) + || (count($type) > 1 && preg_match('/^[0-9]+\-[_a-zA-Z0-9-]*\.jpg$/', $d)) + || preg_match('/^([[:lower:]]{2})\-default\-'.$imageType['name'].'\.jpg$/', $d)) { + if (file_exists($dir.$d)) { + unlink($dir.$d); + } + } + } + } } } @@ -499,7 +492,7 @@ class AdminImagesControllerCore extends AdminController * @param bool $productsImages * @return bool|string */ - protected function _regenerateNewImages($dir, $type, $productsImages = false) + protected function _regenerateNewImages($dir, $type, $imageElement = false) { if (!is_dir($dir)) { return false; @@ -507,45 +500,48 @@ class AdminImagesControllerCore extends AdminController $generate_hight_dpi_images = (bool)Configuration::get('PS_HIGHT_DPI'); - if (!$productsImages) { + if ($imageElement != 'products') { $formated_thumb_scene = ImageType::getFormatedName('thumb_scene'); $formated_medium = ImageType::getFormatedName('medium'); - foreach (scandir($dir) as $image) { - if (preg_match('/^[0-9]*\.jpg$/', $image)) { - foreach ($type as $k => $imageType) { - // Customizable writing dir - $newDir = $dir; - if ($imageType['name'] == $formated_thumb_scene) { - $newDir .= 'thumbs/'; - } - if (!file_exists($newDir)) { - continue; - } + $this->regenerateImageInDir($dir, $type); + // foreach (scandir($dir) as $image) { + // if (preg_match('/^[0-9]*\.jpg$/', $image)) { + // foreach ($type as $k => $imageType) { + // // Customizable writing dir + // $newDir = $dir; + // if ($imageType['name'] == $formated_thumb_scene) { + // $newDir .= 'thumbs/'; + // } + // if (!file_exists($newDir)) { + // continue; + // } - if (($dir == _PS_CAT_IMG_DIR_) && ($imageType['name'] == $formated_medium) && is_file(_PS_CAT_IMG_DIR_.str_replace('.', '_thumb.', $image))) { - $image = str_replace('.', '_thumb.', $image); - } + // if (($dir == _PS_CAT_IMG_DIR_) && ($imageType['name'] == $formated_medium) && is_file(_PS_CAT_IMG_DIR_.str_replace('.', '_thumb.', $image))) { + // $image = str_replace('.', '_thumb.', $image); + // } + + // if (!file_exists($newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg')) { + // if (!file_exists($dir.$image) || !filesize($dir.$image)) { + // $this->errors[] = sprintf(Tools::displayError('Source file does not exist or is empty (%s)'), $dir.$image); + // } elseif (!ImageManager::resize($dir.$image, $newDir.substr(str_replace('_thumb.', '.', $image), 0, -4).'-'.stripslashes($imageType['name']).'.jpg', (int)$imageType['width'], (int)$imageType['height'])) { + // $this->errors[] = sprintf(Tools::displayError('Failed to resize image file (%s)'), $dir.$image); + // } + + // if ($generate_hight_dpi_images) { + // if (!ImageManager::resize($dir.$image, $newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'2x.jpg', (int)$imageType['width']*2, (int)$imageType['height']*2)) { + // $this->errors[] = sprintf(Tools::displayError('Failed to resize image file to high resolution (%s)'), $dir.$image); + // } + // } + // } + // // stop 4 seconds before the timeout, just enough time to process the end of the page on a slow server + // if (time() - $this->start_time > $this->max_execution_time - 4) { + // return 'timeout'; + // } + // } + // } + // } - if (!file_exists($newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg')) { - if (!file_exists($dir.$image) || !filesize($dir.$image)) { - $this->errors[] = sprintf(Tools::displayError('Source file does not exist or is empty (%s)'), $dir.$image); - } elseif (!ImageManager::resize($dir.$image, $newDir.substr(str_replace('_thumb.', '.', $image), 0, -4).'-'.stripslashes($imageType['name']).'.jpg', (int)$imageType['width'], (int)$imageType['height'])) { - $this->errors[] = sprintf(Tools::displayError('Failed to resize image file (%s)'), $dir.$image); - } - if ($generate_hight_dpi_images) { - if (!ImageManager::resize($dir.$image, $newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'2x.jpg', (int)$imageType['width']*2, (int)$imageType['height']*2)) { - $this->errors[] = sprintf(Tools::displayError('Failed to resize image file to high resolution (%s)'), $dir.$image); - } - } - } - // stop 4 seconds before the timeout, just enough time to process the end of the page on a slow server - if (time() - $this->start_time > $this->max_execution_time - 4) { - return 'timeout'; - } - } - } - } } else { foreach (Image::getAllImages() as $image) { $imageObj = new Image($image['id_image']); @@ -576,6 +572,53 @@ class AdminImagesControllerCore extends AdminController return (bool)count($this->errors); } + public function regenerateImageInDir($dir, $type) + { + foreach (scandir($dir) as $image) { + if ($image === '.' || $image === '..') { + continue; + } + if (is_dir($dir.$image)) { + $this->regenerateImageInDir($dir.$image.'/', $type); + } + if (preg_match('/^[0-9]*\.jpg$/', $image)) { + foreach ($type as $k => $imageType) { + // Customizable writing dir + $newDir = $dir; + if ($imageType['name'] == $formated_thumb_scene) { + $newDir .= 'thumbs/'; + } + + if (!file_exists($newDir)) { + continue; + } + + if (($dir == _PS_CAT_IMG_DIR_) && ($imageType['name'] == $formated_medium) && is_file(_PS_CAT_IMG_DIR_.str_replace('.', '_thumb.', $image))) { + $image = str_replace('.', '_thumb.', $image); + } + if (!file_exists($newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg')) { + if (!file_exists($dir.$image) || !filesize($dir.$image)) { + $this->errors[] = sprintf(Tools::displayError('Source file does not exist or is empty (%s)'), $dir.$image); + } elseif (!ImageManager::resize($dir.$image, $newDir.substr(str_replace('_thumb.', '.', $image), 0, -4).'-'.stripslashes($imageType['name']).'.jpg', (int)$imageType['width'], (int)$imageType['height'])) { + $this->errors[] = sprintf(Tools::displayError('Failed to resize image file (%s)'), $dir.$image); + } + + if ($generate_hight_dpi_images) { + if (!ImageManager::resize($dir.$image, $newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'2x.jpg', (int)$imageType['width']*2, (int)$imageType['height']*2)) { + $this->errors[] = sprintf(Tools::displayError('Failed to resize image file to high resolution (%s)'), $dir.$image); + } + } + } + + // stop 4 seconds before the timeout, just enough time to process the end of the page on a slow server + if (time() - $this->start_time > $this->max_execution_time - 4) { + return 'timeout'; + } + } + } + } + } + /** * Regenerate no-pictures images * @@ -649,11 +692,8 @@ class AdminImagesControllerCore extends AdminController $process = array( array('type' => 'categories', 'dir' => _PS_CAT_IMG_DIR_), - array('type' => 'manufacturers', 'dir' => _PS_MANU_IMG_DIR_), - array('type' => 'suppliers', 'dir' => _PS_SUPP_IMG_DIR_), - array('type' => 'scenes', 'dir' => _PS_SCENE_IMG_DIR_), array('type' => 'products', 'dir' => _PS_PROD_IMG_DIR_), - array('type' => 'stores', 'dir' => _PS_STORE_IMG_DIR_) + array('type' => 'hotels', 'dir' => _PS_HOTEL_IMG_DIR_), ); // Launching generation process @@ -678,7 +718,7 @@ class AdminImagesControllerCore extends AdminController if ($deleteOldImages) { $this->_deleteOldImages($proc['dir'], $formats, ($proc['type'] == 'products' ? true : false)); } - if (($return = $this->_regenerateNewImages($proc['dir'], $formats, ($proc['type'] == 'products' ? true : false))) === true) { + if (($return = $this->_regenerateNewImages($proc['dir'], $formats, $proc['type'])) === true) { if (!count($this->errors)) { $this->errors[] = sprintf(Tools::displayError('Cannot write images for this type: %s. Please check the %s folder\'s writing permissions.'), $proc['type'], $proc['dir']); } diff --git a/controllers/admin/AdminThemesController.php b/controllers/admin/AdminThemesController.php index ca48faac1..b5058de9b 100644 --- a/controllers/admin/AdminThemesController.php +++ b/controllers/admin/AdminThemesController.php @@ -144,7 +144,7 @@ class AdminThemesControllerCore extends AdminController 'fields' => array( 'PS_LOGO' => array( 'title' => $this->l('Header logo'), - 'hint' => $this->l('Will appear on main page. Recommended height: 52px. Maximum height on default theme: 65px.'), + 'hint' => $this->l('Will appear on main page. Maximum height on default theme: 60px.'), 'type' => 'file', 'name' => 'PS_LOGO', 'tab' => 'logo', diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 54c5dbe17..aaa0bfa06 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -271,11 +271,11 @@ class ContactControllerCore extends FrontController if (isset($hotel['id_cover_img']) && $hotel['id_cover_img'] && Validate::isLoadedObject( - $objHtlImg = new HotelImage($hotel['id_cover_img']) + $objHotelImage = new HotelImage($hotel['id_cover_img']) ) ) { // by webkul to get media link. - $htlImgLink = $this->context->link->getMediaLink(_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'.$objHtlImg->hotel_image_id.'.jpg'); + $htlImgLink = $this->context->link->getMediaLink($objHotelImage->getImageLink($hotel['id_cover_img'], ImageType::getFormatedName('medium'))); if ((bool)Tools::file_get_contents($htlImgLink)) { $hotel['image_url'] = $htlImgLink; diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index a3aa8160d..6db22437d 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -959,6 +959,7 @@ CREATE TABLE `PREFIX_image_type` ( `height` int(10) unsigned NOT NULL, `products` tinyint(1) NOT NULL DEFAULT '1', `categories` tinyint(1) NOT NULL DEFAULT '1', + `hotels` tinyint(1) NOT NULL DEFAULT '1', `manufacturers` tinyint(1) NOT NULL DEFAULT '1', `suppliers` tinyint(1) NOT NULL DEFAULT '1', `scenes` tinyint(1) NOT NULL DEFAULT '1', diff --git a/install/data/xml/image_type.xml b/install/data/xml/image_type.xml index 532136538..238f474ea 100644 --- a/install/data/xml/image_type.xml +++ b/install/data/xml/image_type.xml @@ -5,6 +5,7 @@ + @@ -12,14 +13,12 @@ - - - - - - - - - + + + + + + + diff --git a/modules/dashproducts/dashproducts.php b/modules/dashproducts/dashproducts.php index f40a124ef..0a6155cbe 100644 --- a/modules/dashproducts/dashproducts.php +++ b/modules/dashproducts/dashproducts.php @@ -348,7 +348,7 @@ class DashProducts extends Module } $objHRT = new HotelRoomType($product_obj->id); - $objHBI = new HotelBranchInformation($objHRT->id_hotel, $this->context->language->id); + $objHotelBranch = new HotelBranchInformation($objHRT->id_hotel, $this->context->language->id); $tr = array(); $tr[] = array( @@ -367,8 +367,8 @@ class DashProducts extends Module $tr[] = array( 'id' => 'hotel', 'value' => ''. - Tools::htmlentitiesUTF8($objHBI->hotel_name).'', + '&id='.$objHotelBranch->id.'&updatehtl_branch_info" target="_blank">'. + Tools::htmlentitiesUTF8($objHotelBranch->hotel_name).'', 'class' => 'text-center', ); $tr[] = array( @@ -443,7 +443,7 @@ class DashProducts extends Module $body = array(); if (is_array($hotels) && count($hotels)) foreach ($hotels as $hotel) { - $objHBI = new HotelBranchInformation($hotel['id_hotel'], $this->context->language->id); + $objHotelBranch = new HotelBranchInformation($hotel['id_hotel'], $this->context->language->id); $tr = array(); $tr[] = array( 'id' => 'reference', @@ -454,12 +454,12 @@ class DashProducts extends Module ); $tr[] = array( 'id' => 'image', - 'value' => $this->getHotelImage($objHBI->id), + 'value' => $this->getHotelImage($objHotelBranch->id), 'class' => 'text-center', ); $tr[] = array( 'id' => 'location', - 'value' => $objHBI->address, + 'value' => $objHotelBranch->address, 'class' => 'text-center', ); $tr[] = array( @@ -479,15 +479,13 @@ class DashProducts extends Module public function getHotelImage($idHotel) { - $imageDir = _MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; - $noPictureImagePath = _PS_IMG_.'p/en.jpg'; + $noPictureImagePath = _PS_IMG_.'p/en.jpg'; $hotelImage = HotelImage::getCover($idHotel); - $imgLink = ''; if (is_array($hotelImage) && count($hotelImage)) { - $imagePath = $imageDir.$hotelImage['hotel_image_id'].'.jpg'; - $imgLink = $imagePath; + $objHotelImage = new HotelImage(); + $imgLink = $this->context->link->getMediaLink($objHotelImage->getImageLink($hotelImage['id'], ImageType::getFormatedName('small'))); } else { - $imgLink = $noPictureImagePath; + $imgLink = $this->context->link->getMediaLink($noPictureImagePath); } return ''; diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 44b43a517..bd0193d22 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -543,25 +543,19 @@ class HotelHelper public function saveDummyHotelImages($idHotel) { if ($idHotel) { - $hotelImgPath = _PS_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; - if (is_dir($hotelImgPath)) { - if ($dir = opendir($hotelImgPath)) { - while (($file = readdir($dir)) !== false) { - $explodeFile = explode('.', $file); - if ($explodeFile[1] == 'jpg') { - $coverImgExist = HotelImage::getCover($idHotel); - $objHtlImage = new HotelImage(); - $objHtlImage->id_hotel = $idHotel; - $objHtlImage->hotel_image_id = $explodeFile[0]; - if (!$coverImgExist) { - $objHtlImage->cover = 1; - } else { - $objHtlImage->cover = 0; - } - $objHtlImage->add(); - } + $objHotelImage = new HotelImage(); + if (is_dir(_PS_HOTEL_IMG_DIR_)) { + foreach(scandir(_PS_HOTEL_IMG_DIR_) as $file) { + if ($file === '.' || $file === '..') { + continue; + } + if (preg_match('/[^\\s]+\.jpg$/', $file)) { + $imageDetail = $objHotelImage->uploadHotelImages( + array('tmp_name' => _PS_HOTEL_IMG_DIR_.$file), + $idHotel + ); + unlink(_PS_HOTEL_IMG_DIR_.$file); } - closedir($dir); } } } diff --git a/modules/hotelreservationsystem/classes/HotelImage.php b/modules/hotelreservationsystem/classes/HotelImage.php index 219128609..62edfc7cb 100644 --- a/modules/hotelreservationsystem/classes/HotelImage.php +++ b/modules/hotelreservationsystem/classes/HotelImage.php @@ -22,15 +22,17 @@ class HotelImage extends ObjectModel { public $id; public $id_hotel; - public $hotel_image_id; public $cover; + public $image_format = 'jpg'; + + protected static $access_rights = 0775; + public static $definition = array( 'table' => 'htl_image', 'primary' => 'id', 'fields' => array( 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), - 'hotel_image_id' => array('type' => self::TYPE_STRING), 'cover' => array('type' => self::TYPE_BOOL,'validate' => 'isBool') ), ); @@ -40,12 +42,13 @@ class HotelImage extends ObjectModel { parent::__construct($id, $id_lang, $id_shop); - $this->image_dir = _PS_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; - $this->image_name = $this->hotel_image_id; + $this->source_index = _PS_HOTEL_IMG_DIR_.'index.php'; + + $this->image_dir = $this->getImagePathDir(); } /** - * Deletes current interior image block from the database + * Deletes current hotel image from the database * @return bool `true` if delete was successful */ public function delete() @@ -105,31 +108,56 @@ class HotelImage extends ObjectModel ); } - public function uploadHotelImages($images, $idHotel, $destPath) + public function getImageLink($id, $type = null) { - if (isset($images) && $idHotel && $destPath) { + return _PS_HOTEL_IMG_.self::getImageHotelId($id).'/'.$id.($type ? '-'.$type : '' ).'.'.$this->image_format; + } + + public function getImagePath() + { + if ($hotelDir = $this->getImgFolder()) { + return _PS_HOTEL_IMG_.$hotelDir; + } + + return false; + } + + public function getImagePathDir() + { + if ($hotelDir = $this->getImgFolder()) { + return _PS_HOTEL_IMG_DIR_.$hotelDir; + } + + return false; + } + + public function getImgFolder() + { + if ($this->id) { + if ($idHotel = self::getImageHotelId($this->id)) { + return $idHotel.'/'; + } + } + + return false; + } + + public static function getImageHotelId($id) + { + return Db::getInstance()->getValue(' + SELECT `id_hotel` + FROM `'._DB_PREFIX_.'htl_image` + WHERE `id` = '. (int)$id + ); + } + + public function uploadHotelImages($images, $idHotel) + { + if (isset($images) && $idHotel) { $objHotelHelper = new HotelHelper(); $hotelImages = $images['tmp_name']; if (is_array($images['tmp_name'])) { foreach ($hotelImages as $image) { - $randName = $objHotelHelper->generateRandomCode(8); - $imageName = $randName.'.jpg'; - if (ImageManager::resize($image, $destPath.$imageName)) { - $objHtlImage = new HotelImage(); - $objHtlImage->id_hotel = $idHotel; - if ($coverImgExist = HotelImage::getCover($idHotel)) { - $objHtlImage->cover = 0; - } else { - $objHtlImage->cover = 1; - } - $objHtlImage->hotel_image_id = $randName; - $objHtlImage->save(); - } - } - } else { - $randName = $objHotelHelper->generateRandomCode(8); - $imageName = $randName.'.jpg'; - if (ImageManager::resize($hotelImages, $destPath.$imageName)) { $objHtlImage = new HotelImage(); $objHtlImage->id_hotel = $idHotel; if ($coverImgExist = HotelImage::getCover($idHotel)) { @@ -137,14 +165,87 @@ class HotelImage extends ObjectModel } else { $objHtlImage->cover = 1; } - $objHtlImage->hotel_image_id = $randName; if ($objHtlImage->save()) { - $addedImage = array( - 'id_image' => $objHtlImage->id, - 'cover' => $objHtlImage->cover, - 'image_url' => Context::getContext()->link->getMediaLink(_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'.$randName.'.jpg'), - ); - return $addedImage; + if ($path = $objHtlImage->getPathForCreation()) { + if (ImageManager::resize( + $image, + $path.$objHtlImage->id.'.'.$objHtlImage->image_format + )) { + // add hotel images in all required sizes + $imagesTypes = ImageType::getImagesTypes('hotels'); + $generate_hight_dpi_images = (bool)Configuration::get('PS_HIGHT_DPI'); + + foreach ($imagesTypes as $imageType) { + if (!ImageManager::resize( + $image, + $path.$objHtlImage->id.'-'.stripslashes($imageType['name']).'.'.$objHtlImage->image_format, + $imageType['width'], + $imageType['height'] + )) { + continue; + } + + if ($generate_hight_dpi_images) { + if (!ImageManager::resize( + $image, + $path.$objHtlImage->id.'-'.stripslashes($imageType['name']).'.'.$objHtlImage->image_format, + (int)$imageType['width']*2, + (int)$imageType['height']*2 + )) { + continue; + } + } + } + + + } + } + } + } + } else { + $objHtlImage = new HotelImage(); + $objHtlImage->id_hotel = $idHotel; + if ($coverImgExist = HotelImage::getCover($idHotel)) { + $objHtlImage->cover = 0; + } else { + $objHtlImage->cover = 1; + } + if ($objHtlImage->save()) { + if ($path = $objHtlImage->getPathForCreation()) { + if (ImageManager::resize( + $hotelImages, + $path.$objHtlImage->id.'.'.$objHtlImage->image_format + )) { + $imagesTypes = ImageType::getImagesTypes('hotels'); + $generate_hight_dpi_images = (bool)Configuration::get('PS_HIGHT_DPI'); + foreach ($imagesTypes as $imageType) { + if (!ImageManager::resize( + $hotelImages, + $path.$objHtlImage->id.'-'.stripslashes($imageType['name']).'.'.$objHtlImage->image_format, + $imageType['width'], + $imageType['height'] + )) { + continue; + } + + if ($generate_hight_dpi_images) { + if (!ImageManager::resize( + $hotelImages, + $path.$objHtlImage->id.'-'.stripslashes($imageType['name']).'.'.$objHtlImage->image_format, + (int)$imageType['width']*2, + (int)$imageType['height']*2 + )) { + continue; + } + } + } + $addedImage = array( + 'id_image' => $objHtlImage->id, + 'cover' => $objHtlImage->cover, + 'image_url' => Context::getContext()->link->getMediaLink($objHtlImage->getImageLink($objHtlImage->id)), + ); + return $addedImage; + } } } } @@ -153,6 +254,37 @@ class HotelImage extends ObjectModel return false; } + public function getPathForCreation() + { + if (!$this->id) { + return false; + } + $path = $this->getImgFolder(); + $this->createImgFolder(); + return _PS_HOTEL_IMG_DIR_.$path; + } + + public function createImgFolder() + { + if (!$this->id) { + return false; + } + + if (!file_exists(_PS_HOTEL_IMG_DIR_.$this->getImgFolder())) { + // Apparently sometimes mkdir cannot set the rights, and sometimes chmod can't. Trying both. + $success = @mkdir(_PS_HOTEL_IMG_DIR_.$this->getImgFolder(), self::$access_rights, true); + $chmod = @chmod(_PS_HOTEL_IMG_DIR_.$this->getImgFolder(), self::$access_rights); + + // Create an index.php file in the new folder + if (($success || $chmod) + && !file_exists(_PS_HOTEL_IMG_DIR_.$this->getImgFolder().'index.php') + && file_exists($this->source_index)) { + return @copy($this->source_index, _PS_HOTEL_IMG_DIR_.$this->getImgFolder().'index.php'); + } + } + return true; + } + public function getAllImages() { return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_image`'); diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index c88ff1324..d8bc8a5df 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -80,7 +80,6 @@ class HotelReservationSystemDb "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, - `hotel_image_id` varchar(32) NOT NULL, `cover` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", diff --git a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelImages.php b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelImages.php index 4e13597eb..83a8705db 100644 --- a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelImages.php +++ b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementHotelImages.php @@ -171,8 +171,8 @@ class WebserviceSpecificManagementHotelImages implements WebserviceSpecificManag // Get available image ids $available_image_ids = array(); - $objHotelImg = new HotelImage(); - $images = $objHotelImg->getImagesByHotelId($object_id); + $objHotelImage = new HotelImage(); + $images = $objHotelImage->getImagesByHotelId($object_id); foreach ($images as $image) { $available_image_ids[] = $image['id']; @@ -185,9 +185,9 @@ class WebserviceSpecificManagementHotelImages implements WebserviceSpecificManag } else { // Check for new image system $image_id = $this->wsObject->urlSegment[2]; - if (Validate::isLoadedObject($objHotelImg = new HotelImage($image_id))) { - if (file_exists($directory.$objHotelImg->hotel_image_id.'.jpg')) { - $filename = $directory.'/'.$objHotelImg->hotel_image_id.'.jpg'; + if (Validate::isLoadedObject($objHotelImage = new HotelImage($image_id))) { + if (file_exists($objHotelImage->getImagePathDir().$objHotelImage->id.'.'.$objHotelImage->image_format)) { + $filename = $objHotelImage->getImagePathDir().$objHotelImage->id.'.'.$objHotelImage->image_format; } } } @@ -223,8 +223,8 @@ class WebserviceSpecificManagementHotelImages implements WebserviceSpecificManag } $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('images', array()); - $objHotelImg = new HotelImage(); - $images = $objHotelImg->getAllImages(); + $objHotelImage = new HotelImage(); + $images = $objHotelImage->getAllImages(); $ids = array(); foreach ($images as $image) { @@ -372,7 +372,7 @@ class WebserviceSpecificManagementHotelImages implements WebserviceSpecificManag @unlink($tmp_name); - $this->imgToDisplay = _PS_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'.$objHotelImage->hotel_image_id.'.jpg'; + $this->imgToDisplay = $objHotelImage->getImagePathDir().$objHotelImage->id.'.'.$objHotelImage->image_format; $this->objOutput->setFieldsToDisplay('full'); $this->output = $this->objOutput->renderEntity($objHotelImage, 1); diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index db62b4f9f..ae51c2d99 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -146,7 +146,8 @@ class AdminAddHotelController extends ModuleAdminController $objHotelImage = new HotelImage(); if ($hotelAllImages = $objHotelImage->getImagesByHotelId($idHotel)) { foreach ($hotelAllImages as &$image) { - $image['image_link'] = $this->context->link->getMediaLink(_MODULE_DIR_.$this->module->name.'/views/img/hotel_img/'.$image['hotel_image_id'].'.jpg'); + $image['image_link'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($image['id'],ImageType::getFormatedName('large'))); + $image['image_link_small'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($image['id'], ImageType::getFormatedName('small'))); } $smartyVars['hotelImages'] = $hotelAllImages; } @@ -530,8 +531,7 @@ class AdminAddHotelController extends ModuleAdminController 'hotel_image' => $_FILES['hotel_image'], ]; $objHotelImage = new HotelImage(); - $hotelImgPath = _PS_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; - $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'], $idHotel, $hotelImgPath); + $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'], $idHotel); if ($imageDetail) { die(json_encode($imageDetail)); } else { diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 8f6214c8a..1edcb4e1d 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -315,7 +315,7 @@ {$image.id|escape:'html':'UTF-8'} - + diff --git a/modules/wkabouthotelblock/controllers/admin/AdminAboutHotelBlockSettingController.php b/modules/wkabouthotelblock/controllers/admin/AdminAboutHotelBlockSettingController.php index d89e7711a..e32bb1cc5 100644 --- a/modules/wkabouthotelblock/controllers/admin/AdminAboutHotelBlockSettingController.php +++ b/modules/wkabouthotelblock/controllers/admin/AdminAboutHotelBlockSettingController.php @@ -280,9 +280,12 @@ class AdminAboutHotelBlockSettingController extends ModuleAdminController } while ((bool)Tools::file_get_contents( $this->context->link->getMediaLink(_MODULE_DIR_.$this->module->name.'/views/img/hotel_interior/'.$tmp_name.'.jpg') )); + $imageSize = ImageType::getTypeByName(ImageType::getFormatedName('large')); ImageManager::resize( $file['tmp_name'], - _PS_MODULE_DIR_.$this->module->name.'/views/img/hotel_interior/'.$tmp_name.'.jpg' + _PS_MODULE_DIR_.$this->module->name.'/views/img/hotel_interior/'.$tmp_name.'.jpg', + $imageSize['width'], + $imageSize['height'] ); $objHtlInteriorImg->name = $tmp_name; diff --git a/modules/wkhotelfeaturesblock/controllers/admin/AdminFeaturesModuleSettingController.php b/modules/wkhotelfeaturesblock/controllers/admin/AdminFeaturesModuleSettingController.php index 2859145dd..fef3dc7b3 100644 --- a/modules/wkhotelfeaturesblock/controllers/admin/AdminFeaturesModuleSettingController.php +++ b/modules/wkhotelfeaturesblock/controllers/admin/AdminFeaturesModuleSettingController.php @@ -317,7 +317,13 @@ class AdminFeaturesModuleSettingController extends ModuleAdminController if (file_exists($imgPath)) { unlink($imgPath); } - ImageManager::resize($file['tmp_name'], $imgPath); + $imageSize = ImageType::getTypeByName(ImageType::getFormatedName('large')); + ImageManager::resize( + $file['tmp_name'], + $imgPath, + $imageSize['width'], + $imageSize['height'] + ); } if ($hotelAmenityId) { diff --git a/modules/wktestimonialblock/controllers/admin/AdminTestimonialsModuleSettingController.php b/modules/wktestimonialblock/controllers/admin/AdminTestimonialsModuleSettingController.php index 1e47c1397..c7942747c 100644 --- a/modules/wktestimonialblock/controllers/admin/AdminTestimonialsModuleSettingController.php +++ b/modules/wktestimonialblock/controllers/admin/AdminTestimonialsModuleSettingController.php @@ -295,7 +295,13 @@ class AdminTestimonialsModuleSettingController extends ModuleAdminController if ($_FILES['testimonial_image']['size']) { $testimonial_img_path = _PS_MODULE_DIR_.$this->module->name.'/views/img/hotels_testimonials_img/'. $objTestimonialData->id.'.jpg'; - ImageManager::resize($_FILES['testimonial_image']['tmp_name'], $testimonial_img_path); + $imageSize = ImageType::getTypeByName(ImageType::getFormatedName('small')); + ImageManager::resize( + $_FILES['testimonial_image']['tmp_name'], + $testimonial_img_path, + $imageSize['width'], + $imageSize['height'] + ); } } if (Tools::getValue("id")) { diff --git a/themes/hotel-reservation-theme/css/global.css b/themes/hotel-reservation-theme/css/global.css index f0a7e72f5..845560a7e 100644 --- a/themes/hotel-reservation-theme/css/global.css +++ b/themes/hotel-reservation-theme/css/global.css @@ -5818,12 +5818,12 @@ header { header .row #header_logo { padding: 10px 0; } header .row #header_logo img { - max-width: 120px; - max-height: 120px; } + max-height: 60px; } header .header-top > div > div > div .header-top-menu { display: flex; flex-direction: row-reverse; align-items: center; + padding: 10px 0; justify-content: end; } header .header-top > div > div > div .header-top-item { position: relative; diff --git a/themes/hotel-reservation-theme/header.tpl b/themes/hotel-reservation-theme/header.tpl index b19aa1f10..04608afdc 100644 --- a/themes/hotel-reservation-theme/header.tpl +++ b/themes/hotel-reservation-theme/header.tpl @@ -105,7 +105,7 @@