@@ -96,56 +96,56 @@ protected function compile()
96
96
return ;
97
97
}
98
98
99
-
100
- /**
101
- * Add the search menu
102
- */
99
+ // Add the search menu
103
100
$ strWhere = '' ;
104
101
$ varKeyword = '' ;
105
102
$ strOptions = '' ;
103
+ $ strSearch = \Input::get ('search ' );
104
+ $ strFor = \Input::get ('for ' );
105
+ $ arrFields = trimsplit (', ' , $ this ->list_fields );
106
+ $ arrSearchFields = trimsplit (', ' , $ this ->list_search );
106
107
107
108
$ this ->Template ->searchable = false ;
108
- $ arrSearchFields = trimsplit (', ' , $ this ->list_search );
109
109
110
110
if (!empty ($ arrSearchFields ) && is_array ($ arrSearchFields ))
111
111
{
112
112
$ this ->Template ->searchable = true ;
113
113
114
- if (\Input::get ('search ' ) && \Input::get ('for ' ))
114
+ if ($ strSearch && !in_array ($ strSearch , $ arrSearchFields , true ))
115
+ {
116
+ $ strSearch = '' ;
117
+ $ strFor = '' ;
118
+ }
119
+
120
+ if ($ strSearch && $ strFor )
115
121
{
116
- $ varKeyword = '% ' . \Input:: get ( ' for ' ) . '% ' ;
117
- $ strWhere = (!$ this ->list_where ? " WHERE " : " AND " ) . \Input:: get ( ' search ' ) . " LIKE ? " ;
122
+ $ varKeyword = '% ' . $ strFor . '% ' ;
123
+ $ strWhere = (!$ this ->list_where ? " WHERE " : " AND " ) . $ strSearch . " LIKE ? " ;
118
124
}
119
125
120
126
foreach ($ arrSearchFields as $ field )
121
127
{
122
- $ strOptions .= ' <option value=" ' . $ field . '" ' . (($ field == \Input:: get ( ' search ' ) ) ? ' selected="selected" ' : '' ) . '> ' . (strlen ($ label = $ GLOBALS ['TL_DCA ' ][$ this ->list_table ]['fields ' ][$ field ]['label ' ][0 ]) ? $ label : $ field ) . '</option> ' . "\n" ;
128
+ $ strOptions .= ' <option value=" ' . $ field . '" ' . (($ field == $ strSearch ) ? ' selected="selected" ' : '' ) . '> ' . (strlen ($ label = $ GLOBALS ['TL_DCA ' ][$ this ->list_table ]['fields ' ][$ field ]['label ' ][0 ]) ? $ label : $ field ) . '</option> ' . "\n" ;
123
129
}
124
130
}
125
131
126
132
$ this ->Template ->search_fields = $ strOptions ;
127
133
128
-
129
- /**
130
- * Get the total number of records
131
- */
134
+ // Get the total number of records
132
135
$ strQuery = "SELECT COUNT(*) AS count FROM " . $ this ->list_table ;
133
136
134
137
if ($ this ->list_where )
135
138
{
136
139
$ strQuery .= " WHERE ( " . $ this ->list_where . ") " ;
137
140
}
138
141
139
- $ strQuery .= $ strWhere ;
142
+ $ strQuery .= $ strWhere ;
140
143
$ objTotal = $ this ->Database ->prepare ($ strQuery )->execute ($ varKeyword );
141
144
142
-
143
- /**
144
- * Validate the page count
145
- */
145
+ // Validate the page count
146
146
$ id = 'page_l ' . $ this ->id ;
147
- $ page = (\Input::get ($ id ) !== null ) ? \Input::get ($ id ) : 1 ;
148
- $ per_page = \Input::get ('per_page ' ) ?: $ this ->perPage ;
147
+ $ page = (\Input::get ($ id ) !== null ) ? ( int ) \Input::get ($ id ) : 1 ;
148
+ $ per_page = ( int ) \Input::get ('per_page ' ) ?: $ this ->perPage ;
149
149
150
150
// Thanks to Hagen Klemp (see #4485)
151
151
if ($ per_page > 0 && ($ page < 1 || $ page > max (ceil ($ objTotal ->count /$ per_page ), 1 )))
@@ -158,10 +158,7 @@ protected function compile()
158
158
$ objHandler ->generate ($ objPage ->id );
159
159
}
160
160
161
-
162
- /**
163
- * Get the selected records
164
- */
161
+ // Get the selected records
165
162
$ strQuery = "SELECT " . $ this ->strPk . ", " . $ this ->list_fields ;
166
163
167
164
if ($ this ->list_info_where )
@@ -183,16 +180,30 @@ protected function compile()
183
180
return $ GLOBALS ['TL_DCA ' ][$ this ->list_table ]['fields ' ][$ field ]['eval ' ]['rgxp ' ] == 'date ' || $ GLOBALS ['TL_DCA ' ][$ this ->list_table ]['fields ' ][$ field ]['eval ' ]['rgxp ' ] == 'time ' || $ GLOBALS ['TL_DCA ' ][$ this ->list_table ]['fields ' ][$ field ]['eval ' ]['rgxp ' ] == 'datim ' ;
184
181
};
185
182
183
+ $ order_by = \Input::get ('order_by ' );
184
+
185
+ if ($ order_by && !in_array ($ order_by , $ arrFields , true ))
186
+ {
187
+ $ order_by = '' ;
188
+ }
189
+
190
+ $ sort = \Input::get ('sort ' );
191
+
192
+ if ($ sort && !in_array ($ sort , array ('asc ' , 'desc ' )))
193
+ {
194
+ $ sort = '' ;
195
+ }
196
+
186
197
// Order by
187
- if (\Input:: get ( ' order_by ' ) )
198
+ if ($ order_by )
188
199
{
189
- if ($ isInt (\Input:: get ( ' order_by ' ) ))
200
+ if ($ isInt ($ order_by ))
190
201
{
191
- $ strQuery .= " ORDER BY CAST( " . \Input:: get ( ' order_by ' ) . " AS SIGNED) " . \Input:: get ( ' sort ' ) ;
202
+ $ strQuery .= " ORDER BY CAST( " . $ order_by . " AS SIGNED) " . $ sort ;
192
203
}
193
204
else
194
205
{
195
- $ strQuery .= " ORDER BY " . \Input:: get ( ' order_by ' ) . ' ' . \Input:: get ( ' sort ' ) ;
206
+ $ strQuery .= " ORDER BY " . $ order_by . ' ' . $ sort ;
196
207
}
197
208
}
198
209
elseif ($ this ->list_sort )
@@ -210,9 +221,9 @@ protected function compile()
210
221
$ objDataStmt = $ this ->Database ->prepare ($ strQuery );
211
222
212
223
// Limit
213
- if (\Input:: get ( ' per_page ' ) )
224
+ if ($ per_page )
214
225
{
215
- $ objDataStmt ->limit (\Input:: get ( ' per_page ' ) , (($ page - 1 ) * $ per_page ));
226
+ $ objDataStmt ->limit ($ per_page , (($ page - 1 ) * $ per_page ));
216
227
}
217
228
elseif ($ this ->perPage )
218
229
{
@@ -221,10 +232,7 @@ protected function compile()
221
232
222
233
$ objData = $ objDataStmt ->execute ($ varKeyword );
223
234
224
-
225
- /**
226
- * Prepare the URL
227
- */
235
+ // Prepare the URL
228
236
$ strUrl = preg_replace ('/\?.*$/ ' , '' , \Environment::get ('request ' ));
229
237
$ blnQuery = false ;
230
238
@@ -240,13 +248,9 @@ protected function compile()
240
248
$ this ->Template ->url = $ strUrl ;
241
249
$ strVarConnector = ($ blnQuery || \Config::get ('disableAlias ' )) ? '& ' : '? ' ;
242
250
243
-
244
- /**
245
- * Prepare the data arrays
246
- */
251
+ // Prepare the data arrays
247
252
$ arrTh = array ();
248
253
$ arrTd = array ();
249
- $ arrFields = trimsplit (', ' , $ this ->list_fields );
250
254
251
255
// THEAD
252
256
for ($ i =0 , $ c =count ($ arrFields ); $ i <$ c ; $ i ++)
@@ -262,10 +266,10 @@ protected function compile()
262
266
$ strField = strlen ($ label = $ GLOBALS ['TL_DCA ' ][$ this ->list_table ]['fields ' ][$ arrFields [$ i ]]['label ' ][0 ]) ? $ label : $ arrFields [$ i ];
263
267
264
268
// Add a CSS class to the order_by column
265
- if (\Input:: get ( ' order_by ' ) == $ arrFields [$ i ])
269
+ if ($ order_by == $ arrFields [$ i ])
266
270
{
267
- $ sort = (\Input:: get ( ' sort ' ) == 'asc ' ) ? 'desc ' : 'asc ' ;
268
- $ class = ' sorted ' . \Input:: get ( ' sort ' ) ;
271
+ $ sort = ($ sort == 'asc ' ) ? 'desc ' : 'asc ' ;
272
+ $ class = ' sorted ' . $ sort ;
269
273
}
270
274
271
275
$ arrTh [] = array
@@ -310,7 +314,7 @@ protected function compile()
310
314
$ arrTd [$ class ][$ k ] = array
311
315
(
312
316
'raw ' => $ v ,
313
- 'content ' => ( $ value ? $ value : ' ' ) ,
317
+ 'content ' => $ value ?: ' ' ,
314
318
'class ' => 'col_ ' . $ j . (($ j ++ == 0 ) ? ' col_first ' : '' ) . ($ this ->list_info ? '' : (($ j >= (count ($ arrRows [$ i ]) - 1 )) ? ' col_last ' : '' )),
315
319
'id ' => $ arrRows [$ i ][$ this ->strPk ],
316
320
'field ' => $ k ,
@@ -323,29 +327,23 @@ protected function compile()
323
327
$ this ->Template ->thead = $ arrTh ;
324
328
$ this ->Template ->tbody = $ arrTd ;
325
329
326
-
327
- /**
328
- * Pagination
329
- */
330
+ // Pagination
330
331
$ objPagination = new \Pagination ($ objTotal ->count , $ per_page , \Config::get ('maxPaginationLinks ' ), $ id );
331
332
$ this ->Template ->pagination = $ objPagination ->generate ("\n " );
332
333
$ this ->Template ->per_page = $ per_page ;
333
334
$ this ->Template ->total = $ objTotal ->count ;
334
335
335
-
336
- /**
337
- * Template variables
338
- */
336
+ // Template variables
339
337
$ this ->Template ->action = \Environment::get ('indexFreeRequest ' );
340
- $ this ->Template ->details = ($ this ->list_info != '' ) ? true : false ;
338
+ $ this ->Template ->details = (bool ) $ this ->list_info ;
341
339
$ this ->Template ->search_label = specialchars ($ GLOBALS ['TL_LANG ' ]['MSC ' ]['search ' ]);
342
340
$ this ->Template ->per_page_label = specialchars ($ GLOBALS ['TL_LANG ' ]['MSC ' ]['list_perPage ' ]);
343
341
$ this ->Template ->fields_label = $ GLOBALS ['TL_LANG ' ]['MSC ' ]['all_fields ' ][0 ];
344
342
$ this ->Template ->keywords_label = $ GLOBALS ['TL_LANG ' ]['MSC ' ]['keywords ' ];
345
- $ this ->Template ->search = \Input:: get ( ' search ' ) ;
346
- $ this ->Template ->for = \Input:: get ( ' for ' ) ;
347
- $ this ->Template ->order_by = \Input:: get ( ' order_by ' ) ;
348
- $ this ->Template ->sort = \Input:: get ( ' sort ' ) ;
343
+ $ this ->Template ->search = $ strSearch ;
344
+ $ this ->Template ->for = $ strFor ;
345
+ $ this ->Template ->order_by = $ order_by ;
346
+ $ this ->Template ->sort = $ sort ;
349
347
$ this ->Template ->col_last = 'col_ ' . $ j ;
350
348
}
351
349
0 commit comments