Jump to content

Blockbanner security removal


Crezzur.com

Recommended Posts

hey all,

 

I want to add my own "header" into prestashop, and to do this i want to use the presta shop "Blockbanner" module wich comes with the free module.

 

The problem i encounter is that it keeps saying i have no right to modify this module when i try to install it. Because for some reason it still checks the 'blockbanner' module for updates.

 

i have changed the module name to "headerblock instead of blockbanner. anyone sees what i have to remove in orde to not check prestashop modules for an update

<?php

if (!defined('_PS_VERSION_'))
	exit;

class HeaderBlock extends Module {
	
	public function __construct()
	{
		$this->name = 'HeaderBlock';
		$this->tab = 'front_office_features';
		$this->version = '1.0';
		$this->author = 'Crezzur';
		$this->need_instance = 0;

		$this->bootstrap = true;
		parent::__construct();

		$this->displayName = $this->l('Header block');
		$this->description = $this->l('Displays a header at the top of the shop.');
		$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
	}

	public function install()
	{
		return
			parent::install() &&
			$this->registerHook('displayHeader') &&
			$this->registerHook('actionObjectLanguageAddAfter') &&
			$this->installFixtures() &&
			$this->disableDevice(Context::DEVICE_MOBILE);
	}

	public function hookActionObjectLanguageAddAfter($params)
	{
		return $this->installFixture((int)$params['object']->id, Configuration::get('HEADERBLOCK_IMG', (int)Configuration::get('PS_LANG_DEFAULT')));
	}

	protected function installFixtures()
	{
		$languages = Language::getLanguages(false);
		foreach ($languages as $lang)
			$this->installFixture((int)$lang['id_lang'], 'sale70.png');

		return true;
	}

	protected function installFixture($id_lang, $image = null)
	{
		$values['HEADERBLOCK_IMG'][(int)$id_lang] = $image;
		$values['HEADERBLOCK_LINK'][(int)$id_lang] = '';
		$values['HEADERBLOCK_DESC'][(int)$id_lang] = '';
		Configuration::updateValue('HEADERBLOCK_IMG', $values['HEADERBLOCK_IMG']);
		Configuration::updateValue('HEADERBLOCK_LINK', $values['HEADERBLOCK_LINK']);
		Configuration::updateValue('HEADERBLOCK_DESC', $values['HEADERBLOCK_DESC']);
	}

	public function uninstall()
	{
		Configuration::deleteByName('HEADERBLOCK_IMG');
		Configuration::deleteByName('HEADERBLOCK_LINK');
		Configuration::deleteByName('HEADERBLOCK_DESC');
		return parent::uninstall();
	}

	public function hookDisplayTop($params)
	{
		if (!$this->isCached('headerblock.tpl', $this->getCacheId()))
		{
			$imgname = Configuration::get('HEADERBLOCK_IMG', $this->context->language->id);

			if ($imgname && file_exists(_PS_MODULE_DIR_.$this->name.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.$imgname))
				$this->smarty->assign('header_img', $this->context->link->protocol_content.Tools::getMediaServer($imgname).$this->_path.'img/'.$imgname);

			$this->smarty->assign(array(
				'header_link' => Configuration::get('HEADERBLOCK_LINK', $this->context->language->id),
				'header_desc' => Configuration::get('HEADERBLOCK_DESC', $this->context->language->id)
			));
		}

		return $this->display(__FILE__, 'headerblock.tpl', $this->getCacheId());
	}

	public function hookDisplayHeader($params)
	{
		return $this->hookDisplayTop($params);
	}

	public function hookDisplayFooter($params)
	{
		return $this->hookDisplayTop($params);
	}

	public function postProcess()
	{
		if (Tools::isSubmit('submitStoreConf'))
		{
			$languages = Language::getLanguages(false);
			$values = array();
			$update_images_values = false;

			foreach ($languages as $lang)
			{
				if (isset($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']])
					&& isset($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']]['tmp_name'])
					&& !empty($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']]['tmp_name']))
				{
					if ($error = ImageManager::validateUpload($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']], 4000000))
						return $error;
					else
					{
						$ext = substr($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']]['name'], strrpos($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']]['name'], '.') + 1);
						$file_name = md5($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']]['name']).'.'.$ext;

						if (!move_uploaded_file($_FILES['HEADERBLOCK_IMG_'.$lang['id_lang']]['tmp_name'], dirname(__FILE__).DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.$file_name))
							return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
						else
						{
							if (Configuration::hasContext('HEADERBLOCK_IMG', $lang['id_lang'], Shop::getContext())
								&& Configuration::get('HEADERBLOCK_IMG', $lang['id_lang']) != $file_name)
								@unlink(dirname(__FILE__).DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.Configuration::get('HEADERBLOCK_IMG', $lang['id_lang']));

							$values['HEADERBLOCK_IMG'][$lang['id_lang']] = $file_name;
						}
					}

					$update_images_values = true;
				}

				$values['HEADERBLOCK_LINK'][$lang['id_lang']] = Tools::getValue('HEADERBLOCK_LINK_'.$lang['id_lang']);
				$values['HEADERBLOCK_DESC'][$lang['id_lang']] = Tools::getValue('HEADERBLOCK_DESC_'.$lang['id_lang']);
			}

			if ($update_images_values)
				Configuration::updateValue('HEADERBLOCK_IMG', $values['HEADERBLOCK_IMG']);

			Configuration::updateValue('HEADERBLOCK_LINK', $values['HEADERBLOCK_LINK']);
			Configuration::updateValue('HEADERBLOCK_DESC', $values['HEADERBLOCK_DESC']);

			$this->_clearCache('headerblock.tpl');
			return $this->displayConfirmation($this->l('The settings have been updated.'));
		}
		return '';
	}

	public function getContent()
	{
		return $this->postProcess().$this->renderForm();
	}

	public function renderForm()
	{
		$fields_form = array(
			'form' => array(
				'legend' => array(
					'title' => $this->l('Settings'),
					'icon' => 'icon-cogs'
				),
				'input' => array(
					array(
						'type' => 'file_lang',
						'label' => $this->l('Top header image'),
						'name' => 'HEADERBLOCK_IMG',
						'desc' => $this->l('Upload an image for your top header. The recommended dimensions are 1170 x 65px if you are using the default theme.'),
						'lang' => true,
					),
					array(
						'type' => 'text',
						'lang' => true,
						'label' => $this->l('Header Link'),
						'name' => 'HEADERBLOCK_LINK',
						'desc' => $this->l('Enter the link associated to your header. When clicking on the header, the link opens in the same window. If no link is entered, it redirects to the homepage.')
					),
					array(
						'type' => 'text',
						'lang' => true,
						'label' => $this->l('Header description'),
						'name' => 'HEADERBLOCK_DESC',
						'desc' => $this->l('Please enter a short but meaningful description for the header.')
					)
				),
				'submit' => array(
					'title' => $this->l('Save')
				)
			),
		);

		$helper = new HelperForm();
		$helper->show_toolbar = false;
		$helper->table =  $this->table;
		$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
		$helper->default_form_language = $lang->id;
		$helper->module = $this;
		$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
		$helper->identifier = $this->identifier;
		$helper->submit_action = 'submitStoreConf';
		$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->tpl_vars = array(
			'uri' => $this->getPathUri(),
			'fields_value' => $this->getConfigFieldsValues(),
			'languages' => $this->context->controller->getLanguages(),
			'id_language' => $this->context->language->id
		);

		return $helper->generateForm(array($fields_form));
	}

	public function getConfigFieldsValues()
	{
		$languages = Language::getLanguages(false);
		$fields = array();

		foreach ($languages as $lang)
		{
			$fields['HEADERBLOCK_IMG'][$lang['id_lang']] = Tools::getValue('HEADERBLOCK_IMG_'.$lang['id_lang'], Configuration::get('HEADERBLOCK_IMG', $lang['id_lang']));
			$fields['HEADERBLOCK_LINK'][$lang['id_lang']] = Tools::getValue('HEADERBLOCK_LINK_'.$lang['id_lang'], Configuration::get('HEADERBLOCK_LINK', $lang['id_lang']));
			$fields['HEADERBLOCK_DESC'][$lang['id_lang']] = Tools::getValue('HEADERBLOCK_DESC_'.$lang['id_lang'], Configuration::get('HEADERBLOCK_DESC', $lang['id_lang']));
		}

		return $fields;
	}
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...