|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @property CI_DB_active_record $db |
|
5
|
|
|
* @property DX_Auth $dx_auth |
|
6
|
|
|
*/ |
|
7
|
|
|
class Seoexpert_model extends CI_Model |
|
8
|
|
|
{ |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Seoexpert_model constructor. |
|
12
|
|
|
*/ |
|
13
|
|
|
public function __construct() { |
|
14
|
|
|
|
|
15
|
|
|
parent::__construct(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Deinstall |
|
20
|
|
|
* @return boolean|null |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
public function deinstall() { |
|
23
|
|
|
|
|
24
|
|
|
$this->load->dbforge(); |
|
25
|
|
|
$this->dbforge->drop_table('mod_seo'); |
|
26
|
|
|
$this->dbforge->drop_table('mod_seo_products'); |
|
27
|
|
|
$this->dbforge->drop_table('mod_seo_inflect'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get base settings |
|
32
|
|
|
* @param bool|int $langId |
|
33
|
|
|
* @return array|bool |
|
|
|
|
|
|
34
|
|
|
*/ |
|
35
|
|
|
public function getBaseSettings($langId = false) { |
|
36
|
|
|
|
|
37
|
|
|
if (!$langId || is_numeric($langId) === false) { |
|
38
|
|
|
return false; |
|
39
|
|
|
} |
|
40
|
|
|
$settings = $this->db->select('add_site_name, add_site_name_to_cat, delimiter, create_keywords, create_description')->where('s_name', 'main')->get('settings')->row_array(); |
|
41
|
|
|
$settingsIn = $this->db->where('lang_ident', $langId)->get('settings_i18n')->row_array(); |
|
42
|
|
|
|
|
43
|
|
|
$res = array_merge($settings, $settingsIn); |
|
44
|
|
|
|
|
45
|
|
|
if ($res) { |
|
46
|
|
|
return $res; |
|
47
|
|
|
} |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get categories by ID, NAME |
|
53
|
|
|
* @param string $term id,name |
|
|
|
|
|
|
54
|
|
|
* @param integer $limit limit for results |
|
55
|
|
|
* @return boolean|array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getCategoriesByIdName($term, $limit = 7) { |
|
58
|
|
|
|
|
59
|
|
|
$locale = MY_Controller::defaultLocale(); |
|
60
|
|
|
|
|
61
|
|
|
$sql = "SELECT * |
|
62
|
|
|
FROM `shop_category_i18n` |
|
63
|
|
|
WHERE (`locale` = '$locale' |
|
64
|
|
|
AND `name` LIKE '%$term%') |
|
65
|
|
|
OR (`id` LIKE '%$term%' AND `locale` = '$locale') |
|
66
|
|
|
LIMIT 0 , $limit"; |
|
67
|
|
|
$query = $this->db->query($sql); |
|
68
|
|
|
|
|
69
|
|
|
if ($query) { |
|
70
|
|
|
return $query->result_array(); |
|
71
|
|
|
} else { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get language id |
|
|
|
|
|
|
78
|
|
|
* @param bool|string $locale |
|
|
|
|
|
|
79
|
|
|
* @return bool|int |
|
|
|
|
|
|
80
|
|
|
*/ |
|
|
|
|
|
|
81
|
|
View Code Duplication |
public function getLangIdByLocale($locale = false) { |
|
82
|
|
|
|
|
83
|
|
|
if (!$locale) { |
|
84
|
|
|
$locale = \MY_Controller::getCurrentLocale(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$res = $this->db->select('id')->where('identif', $locale)->get('languages')->row_array(); |
|
88
|
|
|
if ($res) { |
|
89
|
|
|
return $res['id']; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return false; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get module settings |
|
97
|
|
|
* @param string $locale |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
View Code Duplication |
public function getSettings($locale = 'ru') { |
|
101
|
|
|
|
|
102
|
|
|
$settings = $this->db->select('settings') |
|
103
|
|
|
->where('locale', $locale) |
|
104
|
|
|
->get('mod_seo') |
|
105
|
|
|
->row_array(); |
|
106
|
|
|
|
|
107
|
|
|
$settings = unserialize($settings['settings']); |
|
108
|
|
|
return $settings ?: false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Install |
|
113
|
|
|
* @return boolean |
|
114
|
|
|
*/ |
|
115
|
|
|
public function install() { |
|
116
|
|
|
|
|
117
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `mod_seo` ( |
|
118
|
|
|
`id` int(11) NOT NULL AUTO_INCREMENT, |
|
119
|
|
|
`locale` varchar(5) DEFAULT NULL, |
|
120
|
|
|
`settings` text DEFAULT NULL, |
|
121
|
|
|
PRIMARY KEY (`id`) |
|
122
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'; |
|
123
|
|
|
|
|
124
|
|
|
$this->db->query($sql); |
|
125
|
|
|
|
|
126
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `mod_seo_products` ( |
|
127
|
|
|
`id` int(11) NOT NULL AUTO_INCREMENT, |
|
128
|
|
|
`cat_id` int(11) NOT NULL, |
|
129
|
|
|
`locale` varchar(5) DEFAULT NULL, |
|
130
|
|
|
`settings` text DEFAULT NULL, |
|
131
|
|
|
`active` tinyint(4) DEFAULT NULL, |
|
132
|
|
|
`empty_meta` int(11) DEFAULT NULL, |
|
133
|
|
|
PRIMARY KEY (`id`) |
|
134
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'; |
|
135
|
|
|
|
|
136
|
|
|
$this->db->query($sql); |
|
137
|
|
|
|
|
138
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `mod_seo_inflect` ( |
|
139
|
|
|
`id` int(11) NOT NULL AUTO_INCREMENT, |
|
140
|
|
|
`original` varchar(250) NOT NULL, |
|
141
|
|
|
`inflection_id` int(11) NOT NULL, |
|
142
|
|
|
`inflected` varchar(250) NOT NULL, |
|
143
|
|
|
PRIMARY KEY (`id`) |
|
144
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'; |
|
145
|
|
|
$this->db->query($sql); |
|
146
|
|
|
|
|
147
|
|
|
$this->db->where('name', 'mod_seo')->update('components', ['autoload' => 1, 'in_menu' => 1]); |
|
148
|
|
|
return true; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Set Base settings |
|
153
|
|
|
* @param bool|int $langId |
|
154
|
|
|
* @param array $settings |
|
|
|
|
|
|
155
|
|
|
* @return bool |
|
156
|
|
|
*/ |
|
157
|
|
|
public function setBaseSettings($langId = false, $settings) { |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
if (!$langId) { |
|
160
|
|
|
return false; |
|
161
|
|
|
} |
|
162
|
|
|
// Update shop settings table |
|
163
|
|
|
$mainSettings = [ |
|
164
|
|
|
'add_site_name' => $settings['add_site_name'], |
|
165
|
|
|
'add_site_name_to_cat' => $settings['add_site_name_to_cat'], |
|
166
|
|
|
'delimiter' => $settings['delimiter'], |
|
167
|
|
|
'create_keywords' => $settings['create_keywords'], |
|
168
|
|
|
'create_description' => $settings['create_description'] |
|
169
|
|
|
]; |
|
170
|
|
|
$this->db->where('s_name', 'main')->update('settings', $mainSettings); |
|
171
|
|
|
|
|
172
|
|
|
//Check exists settings with current langId |
|
173
|
|
|
$checkLangSettings = $this->db->where('lang_ident', $langId)->get('settings_i18n')->row_array(); |
|
174
|
|
|
|
|
175
|
|
|
$mainSettingsIn = [ |
|
176
|
|
|
'name' => $settings['name'], |
|
177
|
|
|
'short_name' => $settings['short_name'], |
|
178
|
|
|
'description' => $settings['description'], |
|
179
|
|
|
'keywords' => $settings['keywords'] |
|
180
|
|
|
]; |
|
181
|
|
|
|
|
182
|
|
|
// Update or insert shop settings I18n table |
|
183
|
|
|
if ($checkLangSettings) { |
|
184
|
|
|
return $this->db->where('lang_ident', $langId)->update('settings_i18n', $mainSettingsIn); |
|
185
|
|
|
} else { |
|
186
|
|
|
$mainSettingsIn['lang_ident'] = $langId; |
|
187
|
|
|
return $this->db->insert('settings_i18n', $mainSettingsIn); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Save settings |
|
193
|
|
|
* @param array $settings |
|
194
|
|
|
* @param string $locale |
|
195
|
|
|
* @return bool |
|
196
|
|
|
*/ |
|
197
|
|
View Code Duplication |
public function setSettings($settings, $locale = 'ru') { |
|
198
|
|
|
|
|
199
|
|
|
$data = $this->db->select('locale') |
|
200
|
|
|
->where('locale', $locale) |
|
201
|
|
|
->get('mod_seo') |
|
202
|
|
|
->row_array(); |
|
203
|
|
|
if (empty($data)) { |
|
204
|
|
|
return $this->db->insert('mod_seo', ['locale' => $locale, 'settings' => serialize($settings)]); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
return $this->db->where('locale', $locale) |
|
208
|
|
|
->update( |
|
209
|
|
|
'mod_seo', |
|
210
|
|
|
['settings' => serialize($settings) |
|
211
|
|
|
] |
|
212
|
|
|
); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
} |