HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: /home4/cca63905/www/nueva/modules/artsnowstorm/artsnowstorm.php
<?php
/**
*  2009-2016 Arte e Informatica
*
*  For support feel free to contact us on our website at http://www.arteinformatica.eu
*
*  @author    Arte e Informatica <admin@arteinformatica.eu>
*  @copyright 2009-2016 Arte e Informatica
*  @version   1.0
*  @license   One Paid Licence By WebSite Using This Module. No Rent. No Sell. No Share.
*/

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

class Artsnowstorm extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'artsnowstorm';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Arte e Infomatica';
        $this->need_instance = 0;

        /**
         * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
         */
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Art Free Snow Storm');
        $this->description = $this->l('The module inserts a javascript effect for a perfect storm of snow');
    }

    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        //Configuration::updateValue('ARTSNOWSTORM_TWINKLE_EFFECT', false);

        return parent::install() &&
			Configuration::updateValue('ARTSNOWSTORM_TWINKLE_EFFECT', '1') &&
			Configuration::updateValue('ARTSNOWSTORM_FOLLOW_MOUSE', '1') &&
			Configuration::updateValue('ARTSNOWSTORM_MAX_ACTIVE', '96') &&
			Configuration::updateValue('ARTSNOWSTORM_MAX', '128') &&
			Configuration::updateValue('ARTSNOWSTORM_SNOW_COLOR', '#99ccff') &&
			Configuration::updateValue('ARTSNOWSTORM_ON_BLUR', '1') &&
			Configuration::updateValue('ARTSNOWSTORM_SNOW_STICK', '1') &&
            $this->registerHook('header') &&
            $this->registerHook('backOfficeHeader') &&
		    $this->registerHook('displayHeader');
    }

    public function uninstall()
    {
        Configuration::deleteByName('ARTSNOWSTORM_TWINKLE_EFFECT');
		Configuration::deleteByName('ARTSNOWSTORM_FOLLOW_MOUSE');
        Configuration::deleteByName('ARTSNOWSTORM_MAX_ACTIVE');
		Configuration::deleteByName('ARTSNOWSTORM_MAX');
		Configuration::deleteByName('ARTSNOWSTORM_SNOW_COLOR');
		Configuration::deleteByName('ARTSNOWSTORM_ON_BLUR');
		Configuration::deleteByName('ARTSNOWSTORM_SNOW_STICK');
        return parent::uninstall();
    }

    /**
     * Load the configuration form
     */
    public function getContent() 
    {
        $output = null;
		
			$artsnowstorm_twinkle_effect = (int)Configuration::get('ARTSNOWSTORM_TWINKLE_EFFECT');
			$artsnowstorm_follow_mouse = (int)Configuration::get('ARTSNOWSTORM_FOLLOW_MOUSE');
			$artsnowstorm_on_blur = (int)Configuration::get('ARTSNOWSTORM_ON_BLUR');
			$artsnowstorm_snow_stick = (int)Configuration::get('ARTSNOWSTORM_SNOW_STICK');
			$artsnowstorm_snow_color = pSQL(Configuration::get('ARTSNOWSTORM_SNOW_COLOR'));
			$artsnowstorm_max_active = (int)Configuration::get('ARTSNOWSTORM_MAX_ACTIVE');
			$artsnowstorm_max = (int)Configuration::get('ARTSNOWSTORM_MAX');
		
		/**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitArtsnowstormModule')) == true) {
			
			$artsnowstorm_twinkle_effect = Tools::getValue('ARTSNOWSTORM_TWINKLE_EFFECT');
			$artsnowstorm_follow_mouse = Tools::getValue('ARTSNOWSTORM_FOLLOW_MOUSE');
			$artsnowstorm_on_blur = Tools::getValue('ARTSNOWSTORM_ON_BLUR');
			$artsnowstorm_snow_stick = Tools::getValue('ARTSNOWSTORM_SNOW_STICK');
			$artsnowstorm_snow_color = Tools::getValue('ARTSNOWSTORM_SNOW_COLOR');
			$artsnowstorm_max_active = Tools::getValue('ARTSNOWSTORM_MAX_ACTIVE');
			$artsnowstorm_max = Tools::getValue('ARTSNOWSTORM_MAX');
			
			if(Configuration::updateValue('ARTSNOWSTORM_TWINKLE_EFFECT', (int)$artsnowstorm_twinkle_effect)) {
				Configuration::updateValue('ARTSNOWSTORM_FOLLOW_MOUSE', (int)$artsnowstorm_follow_mouse);
				Configuration::updateValue('ARTSNOWSTORM_ON_BLUR', (int)$artsnowstorm_on_blur);
				Configuration::updateValue('ARTSNOWSTORM_SNOW_STICK', (int)$artsnowstorm_snow_stick);
				Configuration::updateValue('ARTSNOWSTORM_SNOW_COLOR', pSQL($artsnowstorm_snow_color));
				Configuration::updateValue('ARTSNOWSTORM_MAX_ACTIVE', (int)$artsnowstorm_max_active);
				Configuration::updateValue('ARTSNOWSTORM_MAX', (int)$artsnowstorm_max);
				$output .= $this->displayConfirmation($this->l('Settings updated'));
			} else {
				$output .= $this->displayError($this->l('Settings failed.'));
			}
			
            //$this->postProcess();
        }

        $this->context->smarty->assign('module_dir', $this->_path);

        $output .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

        return $output.$this->renderForm();
    }

    /**
     * Create the form that will be displayed in the configuration of your module.
     */
    protected function renderForm()
    {
        $helper = new HelperForm();

        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $helper->module = $this;
        $helper->default_form_language = $this->context->language->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitArtsnowstormModule';
        $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(
            'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        );

        return $helper->generateForm(array($this->getConfigForm()));
    }

    /**
     * Create the structure of your form.
     */
    protected function getConfigForm()
    {
        return array(
            'form' => array(
                'legend' => array(
                'title' => $this->l('Settings'),
                'icon' => 'icon-cogs',
                ),
                'input' => array(
                    array(
                        'type' => 'switch',
                        'label' => $this->l('Use Twinkle Effect'),
                        'name' => 'ARTSNOWSTORM_TWINKLE_EFFECT',
                        'is_bool' => true,
                        'desc' => $this->l('Allow snow to randomly "flicker" in and out of view while falling'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => true,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => false,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),
					array(
                        'type' => 'switch',
                        'label' => $this->l('Follow Mouse'),
                        'name' => 'ARTSNOWSTORM_FOLLOW_MOUSE',
                        'is_bool' => true,
                        'desc' => $this->l('Allows snow to move dynamically with the "wind", relative to the mouse\'s X (left/right) coordinates.'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => true,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => false,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),
						array(
                        'type' => 'switch',
                        'label' => $this->l('Freeze On Blur'),
                        'name' => 'ARTSNOWSTORM_ON_BLUR',
                        'is_bool' => true,
                        'desc' => $this->l('Stops the snow effect when the browser window goes out of focus, eg., user is in another tab. Saves CPU, nicer to user.'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => true,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => false,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),
							array(
                        'type' => 'switch',
                        'label' => $this->l('Snow Stick'),
                        'name' => 'ARTSNOWSTORM_SNOW_STICK',
                        'is_bool' => true,
                        'desc' => $this->l('Allows the snow to "stick" to the bottom of the window. When off, snow will never sit at the bottom.'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => true,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => false,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),
                    array(
                        'col' => 3,
                        'type' => 'text',
                        'desc' => $this->l('Enter the color in html format (es. #FFFFFF)'),
                        'name' => 'ARTSNOWSTORM_SNOW_COLOR',
                        'label' => $this->l('Snow Color'),
                    ),
					array(
					    'col' => 3,
                        'type' => 'text',
                        'name' => 'ARTSNOWSTORM_MAX',
                        'label' => $this->l('Flakes Max'),
						'desc' => $this->l('Sets the maximum number of snowflakes that can exist on the screen at any given time.'),
                    ),
                    array(
					    'col' => 3,
                        'type' => 'text',
                        'name' => 'ARTSNOWSTORM_MAX_ACTIVE',
                        'label' => $this->l('Flakes Max Active'),
						'desc' => $this->l('Sets the limit of "falling" snowflakes (ie. moving on the screen, thus considered to be active.)'),
                    ),
					
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
		    'ARTSNOWSTORM_TWINKLE_EFFECT' => Tools::getValue('ARTSNOWSTORM_TWINKLE_EFFECT', Configuration::get('ARTSNOWSTORM_TWINKLE_EFFECT')),
			'ARTSNOWSTORM_MAX_ACTIVE' => Tools::getValue('ARTSNOWSTORM_MAX_ACTIVE', Configuration::get('ARTSNOWSTORM_MAX_ACTIVE')),
			'ARTSNOWSTORM_ON_BLUR' => Tools::getValue('ARTSNOWSTORM_ON_BLUR', Configuration::get('ARTSNOWSTORM_ON_BLUR')),
			'ARTSNOWSTORM_SNOW_STICK' => Tools::getValue('ARTSNOWSTORM_SNOW_STICK', Configuration::get('ARTSNOWSTORM_SNOW_STICK')),
			'ARTSNOWSTORM_MAX' => Tools::getValue('ARTSNOWSTORM_MAX', Configuration::get('ARTSNOWSTORM_MAX')),
			'ARTSNOWSTORM_FOLLOW_MOUSE' => Tools::getValue('ARTSNOWSTORM_FOLLOW_MOUSE', Configuration::get('ARTSNOWSTORM_FOLLOW_MOUSE')),
			'ARTSNOWSTORM_SNOW_COLOR' => Tools::getValue('ARTSNOWSTORM_SNOW_COLOR', Configuration::get('ARTSNOWSTORM_SNOW_COLOR'))
     
        );
    }

    /**
     * Save form data.
     */
    protected function postProcess()
    {
        $form_values = $this->getConfigFormValues();

        foreach (array_keys($form_values) as $key) {
            Configuration::updateValue($key, Tools::getValue($key));
        }
    }

    /**
    * Add the CSS & JavaScript files you want to be loaded in the BO.
    */
    public function hookBackOfficeHeader()
    {
        if (Tools::getValue('module_name') == $this->name) {
            //$this->context->controller->addJS($this->_path.'views/js/back.js');
            //$this->context->controller->addCSS($this->_path.'views/css/back.css');
        }
    }

    /**
     * Add the CSS & JavaScript files you want to be added on the FO.
     */
    public function hookHeader($params)
    {
        //$this->context->controller->addJS($this->_path.'/views/js/front.js');
       // $this->context->controller->addCSS($this->_path.'/views/css/front.css');
		
    }

    public function hookDisplayHeader()
    {
		
		$artcolor_code = "";
		$artsnowstorm_snow_color = '#99ccff';
		$artsnowstorm_twinkle_effect = 0;
		$artsnowstorm_follow_mouse = 1;
		$artsnowstorm_on_blur = 1;
		$artsnowstorm_snow_stick = 1;
		$artsnowstorm_twinkle_effect = (int)Configuration::get('ARTSNOWSTORM_TWINKLE_EFFECT');
		$artsnowstorm_follow_mouse = (int)Configuration::get('ARTSNOWSTORM_FOLLOW_MOUSE');
		$artsnowstorm_on_blur = (int)Configuration::get('ARTSNOWSTORM_ON_BLUR');
	    $artsnowstorm_snow_color = pSQL(Configuration::get('ARTSNOWSTORM_SNOW_COLOR'));
		$artsnowstorm_max_active = (int)Configuration::get('ARTSNOWSTORM_MAX_ACTIVE');
		$artsnowstorm_max = (int)Configuration::get('ARTSNOWSTORM_MAX');
		$artsnowstorm_snow_stick = (int)Configuration::get('ARTSNOWSTORM_SNOW_STICK');
		
			if ($artsnowstorm_twinkle_effect == 1) {
				$artsnowstorm_twinkle_effect = 'true';
				} else {
					$artsnowstorm_twinkle_effect = 'false';
			}
			
			if ($artsnowstorm_follow_mouse == 1) {
				$artsnowstorm_follow_mouse = 'true';
				} else {
					$artsnowstorm_follow_mouse = 'false';
			}
			
			if ($artsnowstorm_on_blur == 1) {
				$artsnowstorm_on_blur = 'true';
				} else {
					$artsnowstorm_on_blur = 'false';
			}
			
			if ($artsnowstorm_snow_stick == 1) {
				$artsnowstorm_snow_stick = 'true';
				} else {
					$artsnowstorm_snow_stick = 'false';
			}
			
			$artcolor_code =  ltrim($artsnowstorm_snow_color, '#');
			if (ctype_xdigit($artcolor_code) && (Tools::strlen($artcolor_code) == 6 || Tools::strlen($artcolor_code) == 3)) {
				
				} else {
				$artsnowstorm_snow_color = '#99ccff';
			}
 
            if ($artsnowstorm_max_active < 1) {
				$artsnowstorm_max_active = 96;
			}
			 if ($artsnowstorm_max_active < 1) {
				$artsnowstorm_max_active = 128;
			}

		  
		$this->smarty->assign(array(
				'artsnowstorm_twinkle_effect' => $artsnowstorm_twinkle_effect,
				'arturi' => $this->getPathUri(),
				'artsnowstorm_follow_mouse' => $artsnowstorm_follow_mouse,
				'artsnowstorm_snow_color' => $artsnowstorm_snow_color,
				'artsnowstorm_max_active' => $artsnowstorm_max_active,
				'artsnowstorm_on_blur' => $artsnowstorm_on_blur,
				'artsnowstorm_snow_stick' => $artsnowstorm_snow_stick,
				'artsnowstorm_max' => $artsnowstorm_max				
			));	
		
        return $this->display(__FILE__, 'artsnowstorm.tpl');
    }
}