This repository was archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathblocklanguages.php
More file actions
115 lines (102 loc) · 3.92 KB
/
blocklanguages.php
File metadata and controls
115 lines (102 loc) · 3.92 KB
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
113
114
115
<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
class BlockLanguages extends Module
{
public function __construct()
{
$this->name = 'blocklanguages';
$this->tab = 'front_office_features';
$this->version = '1.5.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Language selector block');
$this->description = $this->l('Adds a block allowing customers to select a language for your store\'s content.');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
}
public function install()
{
return (parent::install() && $this->registerHook('displayNav') && $this->registerHook('displayHeader'));
}
protected function _prepareHook($params)
{
$languages = Language::getLanguages(true, $this->context->shop->id);
if (!count($languages))
return false;
$link = new Link();
if ((int)Configuration::get('PS_REWRITING_SETTINGS'))
{
$default_rewrite = array();
if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int)Tools::getValue('id_product')))
{
$rewrite_infos = Product::getUrlRewriteInformations((int)$id_product);
foreach ($rewrite_infos as $infos)
$default_rewrite[$infos['id_lang']] = $link->getProductLink((int)$id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int)$infos['id_lang']);
}
if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int)Tools::getValue('id_category')))
{
$rewrite_infos = Category::getUrlRewriteInformations((int)$id_category);
foreach ($rewrite_infos as $infos)
$default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int)$id_category, $infos['link_rewrite'], $infos['id_lang']);
}
if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int)Tools::getValue('id_cms')) || ($id_cms_category = (int)Tools::getValue('id_cms_category'))))
{
$rewrite_infos = (isset($id_cms) && !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
foreach ($rewrite_infos as $infos)
{
$arr_link = (isset($id_cms) && !isset($id_cms_category)) ?
$link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) :
$link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
$default_rewrite[$infos['id_lang']] = $arr_link;
}
}
$this->smarty->assign('lang_rewrite_urls', $default_rewrite);
}
return true;
}
/**
* Returns module content for header
*
* @param array $params Parameters
* @return string Content
*/
public function hookDisplayTop($params)
{
if (!$this->_prepareHook($params))
return;
return $this->display(__FILE__, 'blocklanguages.tpl');
}
public function hookDisplayNav($params)
{
return $this->hookDisplayTop($params);
}
public function hookDisplayHeader($params)
{
$this->context->controller->addCSS($this->_path.'blocklanguages.css', 'all');
}
}