public function hookDisplayHome($params) { if (!$this->isCached('editorial.tpl', $this->getCacheId())) { $id_shop = (int) $this->context->shop->id; $editorial = EditorialClass::getByIdShop($id_shop); if (!$editorial) { return; } $editorial = new EditorialClass((int) $editorial->id, $this->context->language->id); if (!$editorial) { return; } $this->smarty->assign(array('editorial' => $editorial, 'default_lang' => (int) $this->context->language->id, 'image_width' => Configuration::get('EDITORIAL_IMAGE_WIDTH'), 'image_height' => Configuration::get('EDITORIAL_IMAGE_HEIGHT'), 'id_lang' => $this->context->language->id, 'homepage_logo' => !Configuration::get('EDITORIAL_IMAGE_DISABLE') && file_exists('modules/editorial/homepage_logo_' . (int) $id_shop . '.jpg'), 'image_path' => $this->_path . 'homepage_logo_' . (int) $id_shop . '.jpg')); } return $this->display(__FILE__, 'editorial.tpl', $this->getCacheId()); }
public function getContent() { global $cookie; /* display the module name */ $this->_html = '<h2>' . $this->displayName . '</h2>'; $errors = ''; // Delete logo image if (Tools::isSubmit('deleteImage')) { if (!file_exists(dirname(__FILE__) . '/homepage_logo.jpg')) { $errors .= $this->displayError($this->l('This action cannot be taken.')); } else { unlink(dirname(__FILE__) . '/homepage_logo.jpg'); Configuration::updateValue('EDITORIAL_IMAGE_DISABLE', 1); Tools::redirectAdmin('index.php?tab=AdminModules&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $cookie->id_employee)); } $this->_html .= $errors; } /* update the editorial xml */ if (Tools::isSubmit('submitUpdate')) { // Forbidden key $forbidden = array('submitUpdate'); $editorial = new EditorialClass(1); $editorial->copyFromPost(); $editorial->update(); /* upload the image */ if (isset($_FILES['body_homepage_logo']) and isset($_FILES['body_homepage_logo']['tmp_name']) and !empty($_FILES['body_homepage_logo']['tmp_name'])) { Configuration::set('PS_IMAGE_GENERATION_METHOD', 1); if (file_exists(dirname(__FILE__) . '/homepage_logo.jpg')) { unlink(dirname(__FILE__) . '/homepage_logo.jpg'); } if ($error = checkImage($_FILES['body_homepage_logo'], $this->maxImageSize)) { $errors .= $error; } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES['body_homepage_logo']['tmp_name'], $tmpName)) { return false; } elseif (!imageResize($tmpName, dirname(__FILE__) . '/homepage_logo.jpg')) { $errors .= $this->displayError($this->l('An error occurred during the image upload.')); } if (isset($tmpName)) { unlink($tmpName); } } $this->_html .= $errors == '' ? $this->displayConfirmation($this->l('Settings updated successfully')) : $errors; if (file_exists(dirname(__FILE__) . '/homepage_logo.jpg')) { list($width, $height, $type, $attr) = getimagesize(dirname(__FILE__) . '/homepage_logo.jpg'); Configuration::updateValue('EDITORIAL_IMAGE_WIDTH', (int) round($width)); Configuration::updateValue('EDITORIAL_IMAGE_HEIGHT', (int) round($height)); Configuration::updateValue('EDITORIAL_IMAGE_DISABLE', 0); } } /* display the editorial's form */ $this->_displayForm(); return $this->_html; }