This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
faktiva_cleanurls.php
112 lines (94 loc) · 4.11 KB
/
faktiva_cleanurls.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/*
* This file is part of the "Prestashop Clean URLs" module.
*
* (c) Faktiva (http://faktiva.com)
*
* NOTICE OF LICENSE
* This source file is subject to the CC BY-SA 4.0 license that is
* available at the URL https://creativecommons.org/licenses/by-sa/4.0/
*
* DISCLAIMER
* This code is provided as is without any warranty.
* No promise of being safe or secure
*
* @author Emiliano 'AlberT' Gabrielli <albert@faktiva.com>
* @license https://creativecommons.org/licenses/by-sa/4.0/ CC-BY-SA-4.0
* @source https://github.com/faktiva/prestashop-clean-urls
* @source https://github.com/juferlover/prestashop-clean-urls/tree/Prestashop-1.7-Update
*/
if (!defined('_PS_VERSION_')) {
return;
}
// Set true to enable debugging
define('FKV_DEBUG', false);
if (version_compare(phpversion(), '5.3.0', '>=')) { // Namespaces support is required
include_once __DIR__.'/tools/debug.php';
}
class faktiva_CleanUrls extends Module
{
public function __construct()
{
$this->name = 'faktiva_cleanurls';
$this->tab = 'seo';
$this->version = '1.2.3';
$this->author = 'Faktiva';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6.99');
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Faktiva Clean URLs');
$this->description = $this->l('This override-module allows you to remove URL ID\'s.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall "Faktiva Clean URLs" module?');
}
public function getContent()
{
$output = '<p class="info">'
.$this->l('On some versions you could have to disable Cache, save, open your shop home page, than go back and enable it:').'<br><br>'
.sprintf('%s -> %s -> %s', $this->l('Advanced Parameters'), $this->l('Performance'), $this->l('Clear Smarty cache')).'<br>'
.sprintf('%s -> %s -> %s -> %s', $this->l('Preferences'), $this->l('SEO and URLs'), $this->l('Set user-friendly URL off'), $this->l('Save')).'<br>'
.sprintf('%s -> %s -> %s -> %s', $this->l('Preferences'), $this->l('SEO and URLs'), $this->l('Set user-friendly URL on'), $this->l('Save')).'<br>'
.'</p>';
$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_lang`
WHERE `link_rewrite`
IN (SELECT `link_rewrite` FROM `'._DB_PREFIX_.'product_lang`
GROUP BY `link_rewrite`, `id_lang`
HAVING count(`link_rewrite`) > 1)';
if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
$sql .= ' AND `id_shop` = '.(int) Shop::getContextShopID();
}
if ($res = Db::getInstance()->ExecuteS($sql)) {
$err = $this->l('You need to fix duplicate URL entries:').'<br>';
foreach ($res as $row) {
$lang = $this->context->language->getLanguage($row['id_lang']);
$err .= $row['name'].' ('.$row['id_product'].') - '.$row['link_rewrite'].'<br>';
$shop = $this->context->shop->getShop($lang['id_shop']);
$err .= $this->l('Language: ').$lang['name'].'<br>'.$this->l('Shop: ').$shop['name'].'<br><br>';
}
$output .= $this->displayWarning($err);
} else {
$output .= $this->displayConfirmation($this->l('Nice. You have no duplicate URL entry.'));
}
return '<div class="panel">'.$output.'</div>';
}
public function install()
{
// add link_rewrite as index to improve search
foreach (array('category_lang', 'cms_category_lang', 'cms_lang', 'product_lang') as $tab) {
if (!Db::getInstance()->ExecuteS('SHOW INDEX FROM `'._DB_PREFIX_.$tab.'` WHERE Key_name = \'link_rewrite\'')) {
Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.$tab.'` ADD INDEX ( `link_rewrite` )');
}
}
if (!parent::install()) {
return false;
}
return true;
}
public function uninstall()
{
if (!parent::uninstall()) {
return false;
}
return true;
}
}