-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblocksape.php
More file actions
173 lines (141 loc) · 5.03 KB
/
blocksape.php
File metadata and controls
173 lines (141 loc) · 5.03 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Sape block: module for PrestaShop 1.2-1.6
*
* @author zapalm <zapalm@ya.ru>
* @copyright 2013-2016 zapalm
* @link http://prestashop.modulez.ru/en/free-products/36-sapient-solution-sape.html The module's homepage
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_'))
exit;
class BlockSape extends Module
{
private $conf_default = array(
'BLOCKSAPE_USER' => '',
'BLOCKSAPE_FORCE_SHOW' => 1,
'BLOCKSAPE_FORCE_URI' => 0,
);
public function __construct()
{
$this->name = 'blocksape';
$this->tab = version_compare(_PS_VERSION_, '1.4', '>=') ? 'advertising_marketing' : 'Advertisement';
$this->version = '1.2.2';
$this->author = 'zapalm';
$this->need_instance = 0;
$this->bootstrap = false;
parent::__construct();
$this->displayName = $this->l('Sape block');
$this->description = $this->l('Adds a block to display Sape advertisement links.');
}
public function install()
{
foreach ($this->conf_default as $c => $v)
Configuration::updateValue($c, $v);
return parent::install()
&& $this->registerHook('header')
&& $this->registerHook('footer')
&& $this->registerHook('leftColumn')
&& $this->registerHook('rightColumn');
}
public function uninstall()
{
foreach ($this->conf_default as $c => $v)
Configuration::deleteByName($c);
return parent::uninstall();
}
public function getContent()
{
$output = '<h2>'.$this->displayName.'</h2>';
if (Tools::isSubmit('submit_save'))
{
$res = 1;
foreach ($this->conf_default as $k => $v)
{
if ($k == 'BLOCKSAPE_USER')
$res &= Configuration::updateValue($k, Tools::getValue($k));
else
$res &= Configuration::updateValue($k, (int)Tools::getValue($k));
}
$output .= $res ? $this->displayConfirmation($this->l('Settings updated')) : $this->displayError($this->l('Some setting not updated'));
}
$conf = Configuration::getMultiple(array_keys($this->conf_default));
$output .= '
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
<fieldset>
<legend><img src="'._PS_ADMIN_IMG_.'help.png" />'.$this->l('Info').'</legend>
<label>'.$this->l('SAPE homepage').'</label>
<div class="margin-form">
<a class="link" target="_blank" href="http://www.sape.ru/r.rTYnEaMVRz.php">sape.ru</a>
</div>
</fieldset>
<br/>
<fieldset>
<legend><img src="'._PS_ADMIN_IMG_.'cog.gif" />'.$this->l('Settings').'</legend>
<label>'.$this->l('Your user ID').'</label>
<div class="margin-form">
<input type="text" size="40" name="BLOCKSAPE_USER" value="'.$conf['BLOCKSAPE_USER'].'" />
<p class="clear">'.$this->l('Something like this: sadfsdfsdf7d76gf5ds5g6df7gdfg8dd.').'</p>
</div>
<label>'.$this->l('Force show a code').'</label>
<div class="margin-form">
<input type="checkbox" name="BLOCKSAPE_FORCE_SHOW" value="1" '.($conf['BLOCKSAPE_FORCE_SHOW'] ? 'checked="checked"' : '').'" />
<p class="clear">'.$this->l('For the testing.').'</p>
</div>
<label>'.$this->l('Force page URI applying').'</label>
<div class="margin-form">
<input type="checkbox" name="BLOCKSAPE_FORCE_URI" value="1" '.($conf['BLOCKSAPE_FORCE_URI'] ? 'checked="checked"' : '').'" />
<p class="clear">'.$this->l('When there is a problem of detecting pages URLs.').'</p>
</div>
<center><input type="submit" name="submit_save" value="'.$this->l('Save').'" class="button" /></center>
</fieldset>
</form>
<br class="clear">
';
return $output;
}
public function hookHeader($params)
{
if (version_compare(_PS_VERSION_, '1.4', '<'))
return '<link href="'._MODULE_DIR_.$this->name.'/blocksape.css" rel="stylesheet" type="text/css" media="all" />';
Tools::addCSS($this->_path.'blocksape.css', 'all');
}
public function hookLeftColumn($params)
{
global $smarty, $link, $product, $category;
$conf = Configuration::getMultiple(array_keys($this->conf_default));
if (!$conf['BLOCKSAPE_USER'])
return null;
if (!defined('_SAPE_USER'))
define('_SAPE_USER', $conf['BLOCKSAPE_USER']);
$sape_handler = $_SERVER['DOCUMENT_ROOT'].'/'._SAPE_USER.'/sape.php';
if (!file_exists($sape_handler))
return null;
require_once $sape_handler;
$options = array();
$options['charset'] = 'UTF-8';
$options['force_show_code'] = (bool)$conf['BLOCKSAPE_FORCE_SHOW'];
if ($conf['BLOCKSAPE_FORCE_URI'])
{
// we are in a category or in a product page?
if (!empty($product))
$options['request_uri'] = $link->getProductLink($product->id, $product->link_rewrite);
elseif (!empty($category))
$options['request_uri'] = $link->getCategoryLink($category->id, $category->link_rewrite);
}
$sape = new SAPE_client($options);
$ad_link = $sape->return_links();
$smarty->assign('ad_link', $ad_link);
return $this->display(__FILE__, 'blocksape.tpl');
}
public function hookRightColumn($params)
{
return $this->hookLeftColumn($params);
}
public function hookFooter($params)
{
global $smarty;
$smarty->assign('footer', true);
return $this->hookLeftColumn($params);
}
}