first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,471 @@
<?php
if (!class_exists('UrlRedirect'))
require_once(dirname(dirname(__FILE__)).'/../classes/UrlRedirect.php');
class AdminUrlRedirectController extends ModuleAdminController
{
public $tab = null;
public function __construct()
{
$this->bootstrap = true;
$this->table = 'x13linkrewrite';
$this->className = 'UrlRedirect';
$this->lang = false;
$this->context = Context::getContext();
$this->_defaultOrderBy = 'id_x13linkrewrite';
$this->_defaultOrderWay = 'DESC';
$this->addRowAction('edit');
$this->addRowAction('delete');
parent::__construct();
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?')
)
);
$this->fields_list = array(
'id_x13linkrewrite' => array(
'title' => $this->l('ID'),
'type' => 'text',
),
'old_url' => array(
'title' => $this->l('Old URL'),
'type' => 'text',
),
'new_url' => array(
'title' => $this->l('New URL'),
'type' => 'text',
),
'redirect_type' => array(
'title' => $this->l('Type redirect'),
'type' => 'text',
),
'redirect_count' => array(
'title' => $this->l('Quantity redirect'),
'type' => 'text',
),
'active' => array(
'title' => $this->l('Active'),
'active' => 'status',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
),
'date_add' => array(
'title' => $this->l('Date added'),
'type' => 'date',
)
);
}
public function postProcess()
{
if (Tools::isSubmit('submitUploadFile')) {
if (isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name']))
{
if ($_FILES['csv_file']['size'] > Tools::getMaxUploadSize())
{
$this->errors[] = sprintf(
$this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you are trying to upload is %2$d kB.'),
(Tools::getMaxUploadSize() / 1024),
number_format(($_FILES['csv_file']['size'] / 1024), 2, '.', '')
);
}
else
{
$file = _PS_MODULE_DIR_.$this->module->name.'/csv/tmp.csv';
if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file))
$this->errors[] = $this->l('Failed to copy the file.');
else
{
if (($handle = fopen ($file,"r")) !== FALSE)
{
while (($data = fgetcsv($handle, 0, Tools::getValue('separate', ";"))) !== FALSE)
{
if (!empty($data[0])) {
$id = (int)UrlRedirect::existURL($data[0], 'old_url', false);
$object = new UrlRedirect($id);
$object->old_url = $data[0];
$object->new_url = $data[1];
$object->redirect_type = (int)$data[2];
$object->active = $data[3] ? 1 : 0;
if (($message = $object->validateFields(false, true)) !== true) {
$this->_errors[] = '<div class="danger alert alert-danger">'.$message.'</div>';
//$this->_warnings[] = '<div class="warning alert alert-warning"><b>'.$object->old_url.'</b> Przekierowanie z podanego adresu już istnieje!</div>';
} else {
if ($object->id) {
$object->update();
} else {
$object->add();
}
}
}
}
fclose ($handle);
}
Tools::redirectAdmin('index.php?controller=AdminUrlRedirect&token='.Tools::getAdminTokenLite('AdminUrlRedirect').'&conf=18');
//$this->_html .= $this->displayConfirmation('Przekierowania zaimportowane');
}
}
} elseif (array_key_exists('csv_file', $_FILES) && (int)$_FILES['csv_file']['error'] === 1) {
$max_upload = (int)ini_get('upload_max_filesize');
$max_post = (int)ini_get('post_max_size');
$upload_mb = min($max_upload, $max_post);
$this->errors[] = sprintf(
$this->l('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'),
'<b>'.$_FILES['csv_file']['name'].'</b> ',
'<b>'.$upload_mb.'</b>'
);
}
} else if (Tools::isSubmit('submitReplace')) {
$search_text = Tools::getValue('search_text');
$replace_to = Tools::getValue('replace_to');
$list = UrlRedirect::getRedirects();
if ($list)
foreach ($list as $redirect) {
if (strpos($redirect['old_url'], $search_text) != -1 || strpos($redirect['new_url'], $search_text) != -1) {
$redirect['old_url'] = str_replace($search_text, $replace_to, $redirect['old_url']);
$redirect['new_url'] = str_replace($search_text, $replace_to, $redirect['new_url']);
Db::getInstance()->update('x13linkrewrite', array('old_url' => $redirect['old_url'], 'new_url' => $redirect['new_url']), 'id_x13linkrewrite = '.$redirect['id_x13linkrewrite']);
}
}
} else if (Tools::isSubmit('submitSettings')) {
Configuration::updateValue('X13LINKREWRITE_PRODUCT_R', (bool)Tools::getValue('X13LINKREWRITE_PRODUCT_R'));
}
parent::postProcess();
}
public function renderList()
{
return parent::renderList().$this->renderImportForm().$this->renderReplalceForm().$this->renderSettingsForm();
}
public function renderImportForm()
{
$fields_form_1 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Import file'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'file',
'label' => $this->l('File'),
'name' => 'csv_file',
'desc' => $this->l('Column 1: old url, Column 2: new url, Column 3: type of rewrite, Column 3: active/inactive{1:0}'),
),
array(
'type' => 'text',
'label' => $this->l('Column separator'),
'name' => 'separate',
'default' => ',',
),
),
'buttons' => array(
'submitUploadFile' => array(
'title' => $this->l('Save'),
'type' => 'submit',
'icon' => 'process-icon-save',
'class' => 'btn btn-default pull-right',
'name' => 'submitUploadFile',
)
)
),
);
if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
$fields_form_1['form']['buttons'] = array(
'submitUploadFile' => array(
'title' => $this->l('Save'),
'type' => 'submit',
'icon' => 'process-icon-save',
'class' => 'btn btn-default pull-right',
'name' => 'submitUploadFile',
)
);
} else {
$fields_form_1['form']['submit'] = array(
'title' => $this->l('Save'),
'name' => 'submitUploadFile',
'class' => 'button'
);
}
$field_values = array(
'separate' => ','
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->module->name;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this->module;
$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 = 'submitUploadFile';
$helper->currentIndex = $this->context->link->getAdminLink('AdminUrlRedirect', false);
$helper->token = Tools::getAdminTokenLite('AdminUrlRedirect');
$helper->tpl_vars = array(
'fields_value' => $field_values,
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form_1));
}
public function renderReplalceForm()
{
$fields_form_1 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Mass change'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Search term'),
'name' => 'search_text',
),
array(
'type' => 'text',
'label' => $this->l('Change to'),
'name' => 'replace_to',
),
),
)
);
if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
$fields_form_1['form']['buttons'] = array(
'submitReplace' => array(
'title' => $this->l('Change'),
'type' => 'submit',
'icon' => 'process-icon-save',
'class' => 'btn btn-default pull-right',
'name' => 'submitReplace',
)
);
} else {
$fields_form_1['form']['submit'] = array(
'title' => $this->l('Save'),
'name' => 'submitReplace',
'class' => 'button'
);
}
$field_values = array(
'search_text' => '',
'replace_to' => '',
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->module->name;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this->module;
$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 = 'submitReplace';
$helper->currentIndex = $this->context->link->getAdminLink('AdminUrlRedirect', false);
$helper->token = Tools::getAdminTokenLite('AdminUrlRedirect');
$helper->tpl_vars = array(
'fields_value' => $field_values,
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form_1));
}
public function renderSettingsForm()
{
$fields_form_1 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Ustawienia'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => (version_compare(_PS_VERSION_, '1.6.0', '<') === true ? 'radio' : 'switch'),
'label' => $this->l('Przekierowanie produktu jeśli nieaktywny do kategorii'),
'name' => 'X13LINKREWRITE_PRODUCT_R',
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => '_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => '_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
),
)
);
if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
$fields_form_1['form']['buttons'] = array(
'submitSettings' => array(
'title' => $this->l('Save'),
'type' => 'submit',
'icon' => 'process-icon-save',
'class' => 'btn btn-default pull-right',
'name' => 'submitSettings',
)
);
} else {
$fields_form_1['form']['submit'] = array(
'title' => $this->l('Save'),
'name' => 'submitSettings',
'class' => 'button'
);
}
$field_values = array(
'X13LINKREWRITE_PRODUCT_R' => Configuration::get('X13LINKREWRITE_PRODUCT_R')
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->module->name;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this->module;
$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 = 'submitSettings';
$helper->currentIndex = $this->context->link->getAdminLink('AdminUrlRedirect', false);
$helper->token = Tools::getAdminTokenLite('AdminUrlRedirect');
$helper->tpl_vars = array(
'fields_value' => $field_values,
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form_1));
}
public function renderForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Add rewrite'),
'icon' => 'icon-cogs'
));
$this->fields_form['input'] = array();
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Old URL'),
'name' => 'old_url',
);
$this->fields_form['input'][]= array(
'type' => 'text',
'label' => $this->l('New URL'),
'name' => 'new_url',
);
$this->fields_form['input'][]= array(
'type' => 'select',
'label' => $this->l('Type redirect'),
'name' => 'redirect_type',
'options' => array(
'query' => array(
array(
'id' => '301',
'name' => '301'
),
array(
'id' => '302',
'name' => '302'
),
array(
'id' => '303',
'name' => '303'
)
),
'id' => 'id',
'name' => 'name'
),
);
if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
$this->fields_form['input'][]= array(
'type' => 'switch',
'label' => $this->l('Active'),
'name' => 'active',
'default' => 0,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
);
} else {
$this->fields_form['input'][]= array(
'type' => 'radio',
'label' => $this->l('Active'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
);
}
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitx13linkrewrite',
);
return parent::renderForm();
}
}