|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (!defined('BASEPATH')) { |
|
4
|
|
|
exit('No direct script access allowed'); |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class for Banners module |
|
9
|
|
|
* @uses MY_Controller |
|
10
|
|
|
* @author L.Andriy <[email protected]> |
|
11
|
|
|
* @copyright (c) 2013, ImageCMS |
|
12
|
|
|
* @package ImageCMSModule |
|
13
|
|
|
* @property Banner_model $banner_model |
|
14
|
|
|
*/ |
|
15
|
|
|
class Banners extends MY_Controller |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
public $no_install = true; |
|
19
|
|
|
|
|
20
|
|
View Code Duplication |
public function __construct() { |
|
21
|
|
|
parent::__construct(); |
|
22
|
|
|
if (count($this->db->where('name', 'banners')->get('components')->result_array()) == 0) { |
|
23
|
|
|
$this->no_install = false; |
|
24
|
|
|
} |
|
25
|
|
|
$this->load->module('core'); |
|
26
|
|
|
$this->load->model('banner_model'); |
|
27
|
|
|
$lang = new MY_Lang(); |
|
28
|
|
|
$lang->load('banners'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function index() { |
|
32
|
|
|
if ($this->no_install === false) { |
|
33
|
|
|
return false; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Render banner into template |
|
39
|
|
|
* @access public |
|
40
|
|
|
* @param integer $id is id entity (brand, category, product, page) .... for main id = 0 |
|
|
|
|
|
|
41
|
|
|
* @param integer $group |
|
42
|
|
|
* @return false|null |
|
43
|
|
|
* @author L.Andriy <[email protected]> |
|
44
|
|
|
* @copyright (c) 2013, ImageCMS |
|
45
|
|
|
*/ |
|
46
|
|
|
public function render($id = 0, $group = 0) { |
|
47
|
|
|
if ($this->no_install === false) { |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
$type = $this->core->core_data['data_type']; |
|
51
|
|
|
$lang = $this->get_main_lang('identif'); |
|
52
|
|
|
$painting = $type . '_' . (int) $id; |
|
53
|
|
|
|
|
54
|
|
|
$hash = 'baners' . $type . $id . \CI_Controller::get_instance()->config->item('template'); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$banners = $this->banner_model->get_all_banner($lang, $group); |
|
57
|
|
|
foreach ($banners as $banner) { |
|
58
|
|
|
$data = unserialize($banner['where_show']); |
|
59
|
|
|
|
|
60
|
|
|
if ((in_array($painting, $data) || in_array($type . '_0', $data)) && $banner['active'] && (time() < $banner['active_to'] or $banner['active_to'] == '-1')) { |
|
61
|
|
|
$ban[] = $banner; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
if (count($ban) > 0) { |
|
65
|
|
|
|
|
66
|
|
|
$tpl = $this->banner_model->get_settings_tpl() ? $type . '_slider' : 'slider'; |
|
67
|
|
|
|
|
68
|
|
|
ob_start(); |
|
69
|
|
|
\CMSFactory\assetManager::create() |
|
70
|
|
|
->registerStyle('style') |
|
71
|
|
|
->registerScript('jquery.cycle.all.min') |
|
72
|
|
|
->setData(['banners' => $ban]) |
|
73
|
|
|
->render($tpl, TRUE); |
|
74
|
|
|
|
|
75
|
|
|
$baners_view = ob_get_clean(); |
|
76
|
|
|
|
|
77
|
|
|
echo $baners_view; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getByGroup($group) { |
|
82
|
|
|
$banners = $this->banner_model->get_all_banner(MY_Controller::getCurrentLocale(), $group); |
|
83
|
|
|
return $banners; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* install module and create table |
|
88
|
|
|
* @access public |
|
89
|
|
|
* @author L.Andriy <[email protected]> |
|
90
|
|
|
* @copyright (c) 2013, ImageCMS |
|
91
|
|
|
*/ |
|
92
|
|
|
public function _install() { |
|
93
|
|
|
|
|
94
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `mod_banner` ( |
|
95
|
|
|
`id` int(11) NOT NULL AUTO_INCREMENT, |
|
96
|
|
|
`active` tinyint(4) NOT NULL, |
|
97
|
|
|
`active_to` int(11) DEFAULT NULL, |
|
98
|
|
|
`where_show` text CHARACTER SET utf8, |
|
99
|
|
|
`position` int(11) DEFAULT NULL, |
|
100
|
|
|
PRIMARY KEY (`id`) |
|
101
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'; |
|
102
|
|
|
|
|
103
|
|
|
$this->db->query($sql); |
|
104
|
|
|
|
|
105
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `mod_banner_i18n` ( |
|
106
|
|
|
`id` int(11) NOT NULL, |
|
107
|
|
|
`url` text CHARACTER SET utf8, |
|
108
|
|
|
`locale` varchar(5) CHARACTER SET utf8 NOT NULL, |
|
109
|
|
|
`name` varchar(25) CHARACTER SET utf8 DEFAULT NULL, |
|
110
|
|
|
`description` text CHARACTER SET utf8, |
|
111
|
|
|
`photo` varchar(255) CHARACTER SET utf8 DEFAULT NULL, |
|
112
|
|
|
KEY `id` (`id`,`locale`) |
|
113
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;'; |
|
114
|
|
|
|
|
115
|
|
|
$this->db->query($sql); |
|
116
|
|
|
|
|
117
|
|
|
$this->db->where('name', 'banners'); |
|
118
|
|
|
$this->db->update('components', ['enabled' => 1]); |
|
119
|
|
|
$this->banner_model->createGroupsTable(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* deinstall module and drop tables |
|
124
|
|
|
* @access public |
|
125
|
|
|
* @author L.Andriy <[email protected]> |
|
126
|
|
|
* @copyright (c) 2013, ImageCMS |
|
127
|
|
|
*/ |
|
128
|
|
|
public function _deinstall() { |
|
129
|
|
|
|
|
130
|
|
|
if ($this->dx_auth->is_admin() == FALSE) { |
|
131
|
|
|
exit; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
$this->load->dbforge(); |
|
135
|
|
|
$this->dbforge->drop_table('mod_banner'); |
|
136
|
|
|
$this->dbforge->drop_table('mod_banner_i18n'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* check current language |
|
141
|
|
|
* @access public |
|
142
|
|
|
* @author L.Andriy <[email protected]> |
|
143
|
|
|
* @copyright (c) 2013, ImageCMS |
|
144
|
|
|
* @param string $flag |
|
|
|
|
|
|
145
|
|
|
*/ |
|
146
|
|
|
public function get_main_lang($flag = null) { |
|
147
|
|
|
|
|
148
|
|
|
$lang = $this->db->get('languages')->result_array(); |
|
149
|
|
|
$lan_array = []; |
|
150
|
|
|
foreach ($lang as $l) { |
|
151
|
|
|
$lan_array[$l['identif']] = $l['id']; |
|
152
|
|
|
$lan_array_rev[$l['id']] = $l['identif']; |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
$lang_uri = $this->uri->segment(1); |
|
156
|
|
|
if (in_array($lang_uri, $lan_array_rev)) { |
|
157
|
|
|
$lang_id = $lan_array[$lang_uri]; |
|
158
|
|
|
$lang_ident = $lang_uri; |
|
159
|
|
|
} else { |
|
160
|
|
|
$lang = $this->db->where('default', 1)->get('languages')->result_array(); |
|
161
|
|
|
$lang_id = $lang[0]['id']; |
|
162
|
|
|
$lang_ident = $lang[0]['identif']; |
|
163
|
|
|
} |
|
164
|
|
|
if ($flag == 'id') { |
|
165
|
|
|
return $lang_id; |
|
166
|
|
|
} |
|
167
|
|
|
if ($flag == 'identif') { |
|
168
|
|
|
return $lang_ident; |
|
169
|
|
|
} |
|
170
|
|
|
if ($flag == null) { |
|
171
|
|
|
return [ |
|
172
|
|
|
'id' => $lang_id, |
|
173
|
|
|
'identif' => $lang_ident, |
|
174
|
|
|
]; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public static function addMenu() { |
|
179
|
|
|
// return array( |
|
180
|
|
|
// 1 => |
|
181
|
|
|
// array( |
|
182
|
|
|
// 'identifier' => 'banners', |
|
183
|
|
|
// 'text' => lang("Banners management", "banners"), |
|
184
|
|
|
// 'link' => '/admin/components/cp/banners', |
|
185
|
|
|
// 'subMenu' => |
|
186
|
|
|
// array( |
|
187
|
|
|
// array( |
|
188
|
|
|
// 'identifier' => 'banners_man', |
|
189
|
|
|
// 'text' => lang("Banners management", "banners"), |
|
190
|
|
|
// 'link' => '/admin/components/cp/banners', |
|
191
|
|
|
// 'class' => '', |
|
192
|
|
|
// 'id' => '', |
|
193
|
|
|
// 'pjax' => '', |
|
194
|
|
|
// 'icon' => '', |
|
195
|
|
|
// 'divider' => false, |
|
196
|
|
|
// ), |
|
197
|
|
|
// array( |
|
198
|
|
|
// 'identifier' => 'create_banner', |
|
199
|
|
|
// 'text' => lang("Create a banner", "banners"), |
|
200
|
|
|
// 'link' => '/admin/components/init_window/banners/create', |
|
201
|
|
|
// 'class' => '', |
|
202
|
|
|
// 'id' => '', |
|
203
|
|
|
// 'pjax' => '', |
|
204
|
|
|
// 'icon' => '', |
|
205
|
|
|
// 'divider' => false, |
|
206
|
|
|
// ), |
|
207
|
|
|
// ), |
|
208
|
|
|
// ) |
|
209
|
|
|
// ); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/* End of file banners.php */ |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.