189 lines
5.4 KiB
PHP
189 lines
5.4 KiB
PHP
<?php
|
|
|
|
if (!defined('_PS_VERSION_')){
|
|
exit;
|
|
}
|
|
|
|
class Cyb_Facebook extends Module {
|
|
|
|
|
|
public function __construct(){
|
|
$this->name = 'cyb_facebook';
|
|
$this->tab = 'cyb_facebook';
|
|
$this->version = '1';
|
|
$this->author = 'Cyberscope Bastien';
|
|
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
|
|
$this->bootstrap = true;
|
|
$this->display = 'view';
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Cyberscope Facebook');
|
|
$this->description = $this->l('');
|
|
$this->confirmUninstall = $this->l('Êtes-vous sûr de vouloir désinstaller ce module ?');
|
|
|
|
$this->templateFile = 'module:cyb_facebook/cyb_facebook.tpl';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function install(){
|
|
if(!parent::install()
|
|
|| !Configuration::updateValue('facebook_image', '')
|
|
|| !Configuration::updateValue('facebook_lien', '')
|
|
|| !$this->registerHook('displayHomeAfter')
|
|
|| !$this->registerHook('header')){
|
|
return false;
|
|
}
|
|
else{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function uninstall(){
|
|
if(!parent::uninstall()
|
|
|| !Configuration::deleteByName('facebook_image')
|
|
|| !Configuration::deleteByName('facebook_lien')){
|
|
return false;
|
|
}
|
|
else{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getContent(){
|
|
return $this->postProcess().$this->renderForm();
|
|
}
|
|
|
|
private function postProcess(){
|
|
if(Tools::isSubmit('submitConfFacebook')) {
|
|
|
|
$filename = '';
|
|
if (isset($_FILES['facebook_image'], $_FILES['facebook_image']['name']) && $_FILES['facebook_image']['name']) {
|
|
if ($error = ImageManager::validateUpload($_FILES['facebook_image'], 4000000)) {
|
|
$errors[] = $error;
|
|
} else {
|
|
$filename = $_FILES['facebook_image']['name'];
|
|
|
|
if (! move_uploaded_file($_FILES['facebook_image']['tmp_name'],
|
|
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $filename)
|
|
) {
|
|
return $this->displayError($this->trans('An error occurred while attempting to upload the file.',
|
|
array(), 'Admin.Notifications.Error'));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(Configuration::updateValue('facebook_image', $filename) && Configuration::updateValue('facebook_lien', $_POST['facebook_lien'])){
|
|
return $this->displayConfirmation('Le champ a été enregistré');
|
|
}
|
|
else{
|
|
return $this->displayError('Une erreur a été rencontré');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function renderForm(){
|
|
$helper = new HelperForm();
|
|
$helper->submit_action = 'submitConfFacebook';
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->module = $this;
|
|
|
|
$fields_form = array(
|
|
// 'tinymce' => true,
|
|
'form' => array(
|
|
'legend' => array(
|
|
'title' => $this->trans('Settings', array(), 'Admin.Global'),
|
|
'icon' => 'icon-cogs'
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'file',
|
|
'label' => 'Image',
|
|
'name' => 'facebook_image',
|
|
'required' => true,
|
|
'display_image' => true,
|
|
'desc' => $this->l('Dimensions : 480*170px'),
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => 'Lien :',
|
|
'name' => 'facebook_lien',
|
|
'class' => '',
|
|
'required' => true,
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'title' => 'Sauvegarder'
|
|
)
|
|
),
|
|
);
|
|
|
|
$fields_form['form']['facebook_image'] = Configuration::get('facebook_image');
|
|
|
|
$helper->tpl_vars = array(
|
|
'fields_value' => $this->getAddFieldsValues(),
|
|
'image_baseurl' => $this->_path.'img/',
|
|
'base_url' => $this->context->shop->getBaseURL(),
|
|
);
|
|
|
|
return $helper->generateForm(array($fields_form));
|
|
}
|
|
|
|
|
|
public function getAddFieldsValues()
|
|
{
|
|
return array(
|
|
'facebook_image' => Configuration::get('facebook_image'),
|
|
'facebook_lien' => Configuration::get('facebook_lien'),
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hookHeader(){
|
|
$this->context->controller->registerStylesheet('css-cyb-facebook', 'modules/' . $this->name. '/css/style.css',
|
|
[
|
|
'media' => 'all',
|
|
'priority' => 0,
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hookdisplayHomeAfter(){
|
|
global $smarty;
|
|
|
|
$smarty->assign('facebook', array(
|
|
'lien' => Configuration::get('facebook_lien'),
|
|
'image' => $this->context->link->getMediaLink(_MODULE_DIR_.$this->name.'/img/'.Configuration::get('facebook_image'))));
|
|
|
|
return $this->display(__FILE__,'cyb_facebook.tpl');
|
|
}
|
|
|
|
|
|
|
|
|
|
} |