-
Notifications
You must be signed in to change notification settings - Fork 9
/
ft.reegion_select.php
281 lines (229 loc) · 6.31 KB
/
ft.reegion_select.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
This file is part of REEgion Select add-on for ExpressionEngine.
REEgion Select is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
REEgion Select is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Read the terms of the GNU General Public License
at <http://www.gnu.org/licenses/>.
Copyright 2011 Derek Hogue
*/
class Reegion_select_ft extends EE_Fieldtype {
var $info = array(
'name' => 'REEgion Select',
'version' => '2.0.8'
);
function __construct()
{
EE_Fieldtype::__construct();
$this->EE->lang->loadfile('reegion_select');
}
function accepts_content_type($name)
{
return ($name == 'channel' || $name == 'grid');
}
function display_settings($settings)
{
$types = $this->_get_types();
$this->EE->table->add_row(
$this->EE->lang->line('rs_region_type', 'region_type'),
form_dropdown('region_type', $types, (isset($settings['region_type'])) ? $settings['region_type'] : '', 'id="region_type"')
);
}
// Matrix support
function display_cell_settings($settings)
{
$types = $this->_get_types();
return array(
array($this->EE->lang->line('rs_region_type', 'region_type'),
form_dropdown('region_type', $types, (isset($settings['region_type'])) ? $settings['region_type'] : ''))
);
}
function grid_display_settings($settings)
{
$types = $this->_get_types();
return array(
$this->grid_dropdown_row(
$this->EE->lang->line('rs_region_type'),
'region_type',
$types,
(isset($settings['region_type'])) ? $settings['region_type'] : ''
)
);
}
// Low Variables support
function display_var_settings($settings)
{
return $this->display_cell_settings($settings);
}
function _get_types()
{
return array(
'countries' => $this->EE->lang->line('rs_countries'),
'states' => $this->EE->lang->line('rs_states'),
'provinces' => $this->EE->lang->line('rs_provinces'),
'provinces_states' => $this->EE->lang->line('rs_provinces_states'),
'states_provinces' => $this->EE->lang->line('rs_states_provinces'),
'ukcounties' => $this->EE->lang->line('rs_ukcounties')
);
}
function save_settings($data)
{
return array(
'region_type' => $this->EE->input->post('region_type')
);
}
function grid_save_settings($data)
{
return $data;
}
// Low Variables support
function save_var_settings($data)
{
return $this->save_settings($data);
}
function display_field($data)
{
return $this->_display($data, $this->field_name);
}
// Matrix support
function display_cell($data)
{
return $this->_display($data, $this->cell_name);
}
// Low Variables support
function display_var_field($data)
{
return $this->_display($data, $this->field_name);
}
function _display($data, $name)
{
include PATH_THIRD.'reegion_select/libraries/regions.php';
switch($this->settings['region_type'])
{
case 'countries':
$regions = $countries;
break;
case 'states':
$regions = $states;
break;
case 'provinces':
$regions = $provinces;
break;
case 'provinces_states':
$regions = array();
$regions[$this->EE->lang->line('rs_provinces')] = $provinces;
$regions[$this->EE->lang->line('rs_states')] = $states;
break;
case 'states_provinces':
$regions = array();
$regions[$this->EE->lang->line('rs_states')] = $states;
$regions[$this->EE->lang->line('rs_provinces')] = $provinces;
break;
case 'ukcounties':
// Counties array has no keys,
// so we need to explicitly set them to match the values.
$regions = array();
foreach($ukcounties as $v)
{
$regions[$v] = $v;
}
break;
}
return form_dropdown($name, array_merge(array('' => '--'), $regions), $data);
}
function replace_tag($data, $params = array(), $tagdata = FALSE)
{
return $this->replace_name($data);
}
function replace_name($data, $params = array(), $tagdata = FALSE, $lv_settings = array())
{
include PATH_THIRD.'reegion_select/libraries/regions.php';
switch($this->settings['region_type'])
{
case 'countries':
return $countries[$data];
break;
case 'states':
return $states[$data];
break;
case 'provinces':
return $provinces[$data];
break;
case 'provinces_states': case 'states_provinces':
$regions = array_merge($provinces, $states);
return $regions[$data];
break;
case 'ukcounties' :
return $data;
break;
}
}
function replace_alpha2($data, $params = array(), $tagdata = FALSE)
{
// Alpha-2 is what we store in the database, so spit it out
return $data;
}
function replace_alpha3($data, $params = array(), $tagdata = FALSE, $lv_settings = array())
{
// Applies to Countries only
if($this->settings['region_type'] == 'countries')
{
include PATH_THIRD.'reegion_select/libraries/regions.php';
$data = $countries_alpha3[$data];
}
return $data;
}
// Low Variables support
function display_var_tag($data, $params = array(), $tagdata = FALSE)
{
if(isset($params['type']))
{
switch($params['type'])
{
case 'alpha2' :
return $data;
break;
case 'alpha3':
return $this->replace_alpha3($data, null, null, $params);
break;
default :
return $this->replace_name($data, null, null, $params);
}
}
else
{
return $this->replace_name($data, null, null, $params);
}
}
// Low Search support
function third_party_search_index($data)
{
// Make both codes and names searchable
$r = $data;
include PATH_THIRD.'reegion_select/libraries/regions.php';
switch($this->settings['region_type'])
{
case 'countries':
$r .= ' ' . $countries_alpha3[$data];
$r .= ' ' . $countries[$data];
break;
case 'states':
$r .= ' ' . $states[$data];
break;
case 'provinces':
$r .= ' ' . $provinces[$data];
break;
case 'provinces_states':
$regions = array_merge($provinces, $states);
$r .= ' ' . $regions[$data];
break;
}
return $r;
}
}