* @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; class BlockStore extends Module { public function __construct() { $this->name = 'blockstore'; $this->tab = 'front_office_features'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Store locator block'); $this->description = $this->l('Displays a store locator link directly on your webiste.'); } public function install() { Configuration::updateValue('BLOCKSTORE_IMG', 'store.jpg'); return parent::install() && $this->registerHook('rightColumn') && $this->registerHook('header'); } public function uninstall() { Configuration::deleteByName('BLOCKSTORE_IMG'); return parent::uninstall(); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookRightColumn($params) { if (!$this->isCached('blockstore.tpl', $this->getCacheId())) { $this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG')); $sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'store s' .Shop::addSqlAssociation('store', 's'); $total = Db::getInstance()->getValue($sql); if ($total <= 0) return; } return $this->display(__FILE__, 'blockstore.tpl', $this->getCacheId()); } public function hookHeader($params) { $this->context->controller->addCSS($this->_path.'blockstore.css', 'all'); } public function postProcess() { if (Tools::isSubmit('submitStoreConf')) { if (isset($_FILES['store_img']) && isset($_FILES['store_img']['tmp_name']) && !empty($_FILES['store_img']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['store_img'], 4000000)) return $this->displayError($this->l('Invalid image')); else { $ext = substr($_FILES['store_img']['name'], strrpos($_FILES['store_img']['name'], '.') + 1); $file_name = md5($_FILES['store_img']['name']).'.'.$ext; if (!move_uploaded_file($_FILES['store_img']['tmp_name'], dirname(__FILE__).'/'.$file_name)) return $this->displayError($this->l('An error occurred while attempting to upload the file.')); else { if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $file_name) @unlink(dirname(__FILE__).'/'.Configuration::get('BLOCKSTORE_IMG')); Configuration::updateValue('BLOCKSTORE_IMG', $file_name); $this->_clearCache('blockstore.tpl'); return $this->displayConfirmation($this->l('The settings have been updated.')); } } } } return ''; } public function getContent() { $output = $this->postProcess().'
'.$this->l('Store locator block configuration').''; if (Configuration::get('BLOCKSTORE_IMG')) $output .= '
'.$this->l('Store image').'
'; $output .= '
( '.$this->l('The selected image will be displayed as 174x115').' )

'; return $output; } }