-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.default.php
More file actions
278 lines (254 loc) · 7.9 KB
/
Copy pathaction.default.php
File metadata and controls
278 lines (254 loc) · 7.9 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
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
<?php
#----------------------------------------------------------------------
# Module: MBVFaq - a simple FAQ module
# Action: default
# Default frontend action for the module
#----------------------------------------------------------------------
# See file MBVFaq.module.php for full details of copyright, licence, etc.
#----------------------------------------------------------------------
$funcs = new MBVFshared();
//convert deprecated formats
if (isset($params['faq_id'])) {
$params['faq'] = $params['faq_id'];
}
if (isset($params['category'])) {
$params['cat'] = $params['category'];
}
// are we displaying a single item ?
if (!isset($params['cat']) && isset($params['faq']) && $params['faq'] != '') {
// get data for the matching faq
$item = $funcs->GetItem($this, $params['faq']);
if ($this->GetPreference('short_question', TRUE)) {
if ($item->question == '') {
$item->question = $item->long_question;
}
} elseif ($item->long_question != '') {
$item->question = $item->long_question;
}
if ($this->GetPreference('short_answer', TRUE)) {
if ($item->short_answer != '') {
$item->answer = $item->short_answer;
} else {
$item->answer = $item->long_answer;
}
} elseif ($item->long_answer != '') {
$item->answer = $item->long_answer;
} else {
$item->answer = $item->short_answer;
}
$tplvars = array(
'item' => $item,
'styles_root' => $this->GetModuleURLPath().'/css',
'label_question' => $this->Lang('item'),
'label_answer' => $this->Lang('answer')
);
$funcs->ProcessTemplate($this, 'detail.tpl', $tplvars);
} else {
if (isset($config['default_encoding']) && $config['default_encoding'] != '') {
$enc = strtoupper($config['default_encoding']);
} else {
$enc = FALSE;
}
$categories = array();
$thiscat = '';
if (isset($params['cat']) && $params['cat'] != '') { // is cat= parameter present?
$thiscat = $params['cat'];
}
if ($thiscat == '') { // [re]list all categories
$categories = $funcs->GetCategories($this, $id, $returnid, TRUE, TRUE);
} else {
$thiscat = ($enc) ?
html_entity_decode($thiscat, ENT_QUOTES, $enc):
html_entity_decode($thiscat, ENT_QUOTES);
/* Convert string (having a name or id, or possibly ;-separated names
and/or ids) into an array of category data, each member an array
of some of the tabled data for the corresponding category */
$wanted = explode(";", $thiscat);
// now we have an array of categories to display
foreach ($wanted as $choice) {
if (choice != '') {
$sql = "SELECT * FROM $this->CatTable WHERE ";
// find out if we have an id or a name
if ((intval($choice)==0) && ($choice<>"0")) { // it's a string, so assume it's a name
$sql .= "name=?";
} else { // not a string so assume it's an id
$sql .= "category_id=?";
}
$queryvars = array(trim($choice));
$rst = $db->Execute($sql, $queryvars);
if ($rst) {
while ($row = $rst->FetchRow()) {
$one = new stdClass();
$one->category_id = $row['category_id'];
$one->name = $row['name'];
$one->order= $row['vieworder'];
$one->category_link = $funcs->GetLink($this, $id, $returnid, $one->name, $one->name);
$categories[$one->category_id] = $one; //lose any previous category with the same index
}
$rst->Close();
}
}
}
}
if (isset($params['pattern'])) {
$pattern = ($enc) ?
html_entity_decode($params['pattern'], ENT_QUOTES, $enc):
html_entity_decode($params['pattern'], ENT_QUOTES);
if (substr($pattern, 0, 1)=='!') {
$neg = TRUE;
$pattern = substr($pattern, 1);
} else {
$neg = FALSE;
}
if (!function_exists('fnmatch')) {
function fnmatch($pattern, $string, $flags)
{
return @preg_match(
'/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'),
array('*' => '.*', '?' => '.?')) . '$/i', $string);
}
}
} else {
$pattern = FALSE;
}
if (isset($params['regex'])) {
$regex = ($enc) ?
html_entity_decode($params['regex'], ENT_QUOTES, $enc):
html_entity_decode($params['regex'], ENT_QUOTES);
if (substr($regex, 0, 1)=='!') {
$negr = TRUE;
$regex = substr($regex, 1);
} else {
$negr = FALSE;
}
} else {
$regex= FALSE;
}
$tplvars = array();
$sq = $this->GetPreference('short_question', TRUE);
$sa = $this->GetPreference('short_answer', TRUE);
$multi = (count($categories) > 1);
$cc = 1; //div id counter
// populate questions for the categories
foreach ($categories as $indx => $category) {
/* Construct an array of objects, one member for each of the active
questions in the specified category, and set the array as the
->items parameter of $category object. Each non-empty category
will then have the following parameters:
category_id // the internal id used to identify the category
name // the name of the category
order // the sort-order number of the category
category_link // link that will display the category on a page by itself
items // an array of objects for all published questions in the category
Each member of the items array is an object with the
following parameters:
item_id
category_id
category
question
answer
itemlink
divid //id for answer div, N or C.N
*/
$sql = "SELECT * FROM $this->ItemTable WHERE category_id=? AND active=1 ORDER BY vieworder ASC";
$rst = $db->Execute($sql, array($category->category_id));
if ($rst) {
if (!$rst->EOF) {
$qc = 1; //div id counter
$items = array();
while ($row = $rst->FetchRow()) {
if ($sq) {
$s = $row['short_question'];
if ($s == '') {
$s = $row['long_question'];
}
} else {
$s = $row['long_question'];
if ($s == '') {
$s = $row['short_question'];
}
}
if ($pattern) {
if (fnmatch($pattern, $s, FNM_NOESCAPE | FNM_PATHNAME | FNM_PERIOD) != FALSE) {
if ($neg) {
continue;
}
} elseif (!$neg) {
continue;
}
}
if ($regex) {
if (preg_match('/'.$regex.'/', $s) !== FALSE) {
if ($negr) {
continue;
}
} elseif (!$negr) {
continue;
}
}
$one = new stdClass();
$one->divid = ($multi) ? $cc.'-'.$qc : $qc; //jQuery can't cope with period in id name
++$qc;
$one->item_id = $row['item_id'];
$one->category_id = $row['category_id'];
$one->category = $category->name;
$one->question = $s;
if ($sa) {
$s = $row['short_answer'];
if ($s == '') {
$s = $row['long_answer'];
}
} else {
$s = $row['long_answer'];
if ($s == '') {
$s = $row['short_answer'];
}
}
$one->answer = $funcs->ProcessTemplateFromData($this, $s, $tplvars);
$one->itemlink = $funcs->GetLink($this, $id, $returnid, strip_tags($row['short_question']), '', $row['item_id']);
$items[] = $one;
}
if (count($items) > 0) {
$category->items = $items;
++$cc;
} else { //if category is empty, ignore it
unset($categories[$indx]);
}
} else {
unset($categories[$indx]);
}
$rst->Close();
} else {
unset($categories[$indx]);
}
}
$tplvars['cats'] = array_values($categories);
$numcat = count($categories);
$tplvars['catcount'] = $numcat;
if ($numcat > 0 && $this->GetPreference('use_jquery', TRUE)) {
if ($numcat == 1) {
//don't want 1-X for a single category
$first = reset($categories);
$qc = 1; //div id counter
foreach ($first->items as &$one) {
$one->divid = $qc;
++$qc;
}
unset($one);
}
$fn = cms_join_path(dirname(__FILE__), 'lib', 'js', 'jquery-faq.js');
$jq = ''.@file_get_contents($fn);
//generalise jquery lib from the default "jquery.min.js"
$wpat = cms_join_path('lib', 'jquery', 'js', 'jquery*.min.js');
$pat = cms_join_path('lib', 'jquery', 'js', 'jquery.min.js');
foreach (glob($wpat) as $filepath) {
$jq = str_replace($pat, $filepath, $jq);
break;
}
$tplvars['jquery'] = $jq;
} else {
$tplvars['noitems'] = $this->Lang('noitems');
}
// Display the populated template
$funcs->ProcessTemplate($this, 'overview.tpl', $tplvars);
}