@@ -148,109 +148,109 @@ function getThumbnailSpecs($tableName, $fieldName, $view) {
148
148
}
149
149
########################################################################
150
150
function createThumbnail ($ img , $ specs ) {
151
- $ w= $ specs ['width ' ];
152
- $ h= $ specs ['height ' ];
153
- $ id= $ specs ['identifier ' ];
154
- $ path= dirname ($ img );
151
+ $ w = $ specs ['width ' ];
152
+ $ h = $ specs ['height ' ];
153
+ $ id = $ specs ['identifier ' ];
154
+ $ path = dirname ($ img );
155
155
156
156
// image doesn't exist or inaccessible?
157
- if (!$ size= @getimagesize ($ img )) return FALSE ;
157
+ if (!$ size = @getimagesize ($ img )) return false ;
158
158
159
159
// calculate thumbnail size to maintain aspect ratio
160
- $ ow= $ size [0 ]; // original image width
161
- $ oh= $ size [1 ]; // original image height
162
- $ twbh= $ h / $ oh* $ ow ; // calculated thumbnail width based on given height
163
- $ thbw= $ w / $ ow* $ oh ; // calculated thumbnail height based on given width
160
+ $ ow = $ size [0 ]; // original image width
161
+ $ oh = $ size [1 ]; // original image height
162
+ $ twbh = $ h / $ oh * $ ow ; // calculated thumbnail width based on given height
163
+ $ thbw = $ w / $ ow * $ oh ; // calculated thumbnail height based on given width
164
164
if ($ w && $ h ) {
165
- if ($ twbh> $ w ) $ h= $ thbw ;
166
- if ($ thbw> $ h ) $ w= $ twbh ;
165
+ if ($ twbh > $ w ) $ h = $ thbw ;
166
+ if ($ thbw > $ h ) $ w = $ twbh ;
167
167
} elseif ($ w ) {
168
- $ h= $ thbw ;
168
+ $ h = $ thbw ;
169
169
} elseif ($ h ) {
170
- $ w= $ twbh ;
170
+ $ w = $ twbh ;
171
171
} else {
172
- return FALSE ;
172
+ return false ;
173
173
}
174
174
175
175
// dir not writeable?
176
- if (!is_writable ($ path )) return FALSE ;
176
+ if (!is_writable ($ path )) return false ;
177
177
178
178
// GD lib not loaded?
179
- if (!function_exists ('gd_info ' )) return FALSE ;
180
- $ gd= gd_info ();
179
+ if (!function_exists ('gd_info ' )) return false ;
180
+ $ gd = gd_info ();
181
181
182
182
// GD lib older than 2.0?
183
183
preg_match ('/\d/ ' , $ gd ['GD Version ' ], $ gdm );
184
- if ($ gdm [0 ]< 2 ) return FALSE ;
184
+ if ($ gdm [0 ] < 2 ) return false ;
185
185
186
186
// get file extension
187
187
preg_match ('/\.[a-zA-Z]{3,4}$/U ' , $ img , $ matches );
188
- $ ext= strtolower ($ matches [0 ]);
188
+ $ ext = strtolower ($ matches [0 ]);
189
189
190
190
// check if supplied image is supported and specify actions based on file type
191
- if ($ ext== '.gif ' ) {
192
- if (!$ gd ['GIF Create Support ' ]) return FALSE ;
193
- $ thumbFunc= 'imagegif ' ;
194
- } elseif ($ ext== '.png ' ) {
195
- if (!$ gd ['PNG Support ' ]) return FALSE ;
196
- $ thumbFunc= 'imagepng ' ;
197
- } elseif ($ ext== '.jpg ' || $ ext== '.jpe ' || $ ext== '.jpeg ' ) {
198
- if (!$ gd ['JPG Support ' ] && !$ gd ['JPEG Support ' ]) return FALSE ;
199
- $ thumbFunc= 'imagejpeg ' ;
191
+ if ($ ext == '.gif ' ) {
192
+ if (!$ gd ['GIF Create Support ' ]) return false ;
193
+ $ thumbFunc = 'imagegif ' ;
194
+ } elseif ($ ext == '.png ' ) {
195
+ if (!$ gd ['PNG Support ' ]) return false ;
196
+ $ thumbFunc = 'imagepng ' ;
197
+ } elseif ($ ext == '.jpg ' || $ ext == '.jpe ' || $ ext == '.jpeg ' ) {
198
+ if (!$ gd ['JPG Support ' ] && !$ gd ['JPEG Support ' ]) return false ;
199
+ $ thumbFunc = 'imagejpeg ' ;
200
200
} else {
201
- return FALSE ;
201
+ return false ;
202
202
}
203
203
204
204
// determine thumbnail file name
205
- $ ext= $ matches [0 ];
206
- $ thumb= substr ($ img , 0 , -5 ). str_replace ($ ext , $ id. $ ext , substr ($ img , -5 ));
205
+ $ ext = $ matches [0 ];
206
+ $ thumb = substr ($ img , 0 , -5 ) . str_replace ($ ext , $ id . $ ext , substr ($ img , -5 ));
207
207
208
208
// if the original image smaller than thumb, then just copy it to thumb
209
- if ($ h> $ oh && $ w> $ ow ) {
210
- return (@copy ($ img , $ thumb ) ? TRUE : FALSE );
209
+ if ($ h > $ oh && $ w > $ ow ) {
210
+ return (@copy ($ img , $ thumb ) ? true : false );
211
211
}
212
212
213
213
// get image data
214
- if (!$ imgData= imagecreatefromstring (implode ('' , file ($ img )))) return FALSE ;
214
+ if (!$ imgData = imagecreatefromstring (implode ('' , file ($ img )))) return false ;
215
215
216
216
// finally, create thumbnail
217
- $ thumbData= imagecreatetruecolor ($ w , $ h );
217
+ $ thumbData = imagecreatetruecolor ($ w , $ h );
218
218
219
219
//preserve transparency of png and gif images
220
- if ($ thumbFunc== 'imagepng ' ) {
221
- if (($ clr= @imagecolorallocate ($ thumbData , 0 , 0 , 0 ))!= -1 ) {
220
+ if ($ thumbFunc == 'imagepng ' ) {
221
+ if (($ clr = @imagecolorallocate ($ thumbData , 0 , 0 , 0 )) != -1 ) {
222
222
@imagecolortransparent ($ thumbData , $ clr );
223
223
@imagealphablending ($ thumbData , false );
224
224
@imagesavealpha ($ thumbData , true );
225
225
}
226
- } elseif ($ thumbFunc== 'imagegif ' ) {
226
+ } elseif ($ thumbFunc == 'imagegif ' ) {
227
227
@imagealphablending ($ thumbData , false );
228
- $ transIndex= imagecolortransparent ($ imgData );
229
- if ($ transIndex>= 0 ) {
230
- $ transClr= imagecolorsforindex ($ imgData , $ transIndex );
231
- $ transIndex= imagecolorallocatealpha ($ thumbData , $ transClr ['red ' ], $ transClr ['green ' ], $ transClr ['blue ' ], 127 );
228
+ $ transIndex = imagecolortransparent ($ imgData );
229
+ if ($ transIndex >= 0 ) {
230
+ $ transClr = imagecolorsforindex ($ imgData , $ transIndex );
231
+ $ transIndex = imagecolorallocatealpha ($ thumbData , $ transClr ['red ' ], $ transClr ['green ' ], $ transClr ['blue ' ], 127 );
232
232
imagefill ($ thumbData , 0 , 0 , $ transIndex );
233
233
}
234
234
}
235
235
236
236
// resize original image into thumbnail
237
- if (!imagecopyresampled ($ thumbData , $ imgData , 0 , 0 , 0 , 0 , $ w , $ h , $ ow , $ oh )) return FALSE ;
237
+ if (!imagecopyresampled ($ thumbData , $ imgData , 0 , 0 , 0 , 0 , $ w , $ h , $ ow , $ oh )) return false ;
238
238
unset($ imgData );
239
239
240
240
// gif transparency
241
- if ($ thumbFunc== 'imagegif ' && $ transIndex>= 0 ) {
241
+ if ($ thumbFunc == 'imagegif ' && $ transIndex >= 0 ) {
242
242
imagecolortransparent ($ thumbData , $ transIndex );
243
- for ($ y= 0 ; $ y< $ h ; ++$ y )
244
- for ($ x= 0 ; $ x< $ w ; ++$ x )
245
- if (((imagecolorat ($ thumbData , $ x , $ y )>> 24 ) & 0x7F ) >= 100 ) imagesetpixel ($ thumbData , $ x , $ y , $ transIndex );
243
+ for ($ y = 0 ; $ y < $ h ; ++$ y )
244
+ for ($ x = 0 ; $ x < $ w ; ++$ x )
245
+ if (((imagecolorat ($ thumbData , $ x , $ y ) >> 24 ) & 0x7F ) >= 100 ) imagesetpixel ($ thumbData , $ x , $ y , $ transIndex );
246
246
imagetruecolortopalette ($ thumbData , true , 255 );
247
247
imagesavealpha ($ thumbData , false );
248
248
}
249
249
250
- if (!$ thumbFunc ($ thumbData , $ thumb )) return FALSE ;
250
+ if (!$ thumbFunc ($ thumbData , $ thumb )) return false ;
251
251
unset($ thumbData );
252
252
253
- return TRUE ;
253
+ return true ;
254
254
}
255
255
########################################################################
256
256
function makeSafe ($ string , $ is_gpc = true ) {
@@ -304,7 +304,7 @@ function sql($statment, &$o) {
304
304
if (!$ connected ) {
305
305
/****** Connect to MySQL ******/
306
306
if (!extension_loaded ('mysql ' ) && !extension_loaded ('mysqli ' )) {
307
- $ o ['error ' ] = 'PHP is not configured to connect to MySQL on this machine. Please see <a href="http ://www.php.net/manual/en/ref.mysql.php">this page</a> for help on how to configure MySQL. ' ;
307
+ $ o ['error ' ] = 'PHP is not configured to connect to MySQL on this machine. Please see <a href="https ://www.php.net/manual/en/ref.mysql.php">this page</a> for help on how to configure MySQL. ' ;
308
308
if ($ o ['silentErrors ' ]) return false ;
309
309
310
310
@include_once ($ header );
@@ -730,11 +730,7 @@ function bootstrapSQLSelect($name, $sql, $selectedValue, $class = '', $selectedC
730
730
}
731
731
########################################################################
732
732
function isEmail ($ email ) {
733
- if (preg_match ('/^([*+!.&#$¦ \'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,45})$/i ' , $ email )) {
734
- return $ email ;
735
- }
736
-
737
- return false ;
733
+ return filter_var (trim ($ email ), FILTER_VALIDATE_EMAIL );
738
734
}
739
735
########################################################################
740
736
function notifyMemberApproval ($ memberID ) {
@@ -1112,7 +1108,7 @@ function getUploadedFile($FieldName, $MaxSize=0, $FileTypes='csv|txt', $NoRename
1112
1108
########################################################################
1113
1109
function toBytes ($ val ) {
1114
1110
$ val = trim ($ val );
1115
- $ last = strtolower ($ val{ strlen ($ val )-1 } );
1111
+ $ last = strtolower ($ val[ strlen ($ val )-1 ] );
1116
1112
switch ($ last ) {
1117
1113
// The 'G' modifier is available since PHP 5.1.0
1118
1114
case 'g ' :
@@ -1129,7 +1125,7 @@ function toBytes($val) {
1129
1125
function convertLegacyOptions ($ CSVList ) {
1130
1126
$ CSVList =str_replace (';;; ' , ';|| ' , $ CSVList );
1131
1127
$ CSVList =str_replace (';; ' , '|| ' , $ CSVList );
1132
- return $ CSVList ;
1128
+ return trim ( $ CSVList, ' | ' ) ;
1133
1129
}
1134
1130
########################################################################
1135
1131
function getValueGivenCaption ($ query , $ caption ) {
@@ -1394,7 +1390,7 @@ public static function placeholder() {
1394
1390
1395
1391
/* dismiss after x seconds if requested */
1396
1392
if(options.dismiss_seconds > 0) {
1397
- setTimeout(function() { /* */ this_notif.addClass('invisible'); }, options.dismiss_seconds * 1000);
1393
+ setTimeout(function() { this_notif.addClass('invisible'); }, options.dismiss_seconds * 1000);
1398
1394
}
1399
1395
1400
1396
/* dismiss for x days if requested and user dismisses it */
@@ -1510,8 +1506,7 @@ function safe_html($str) {
1510
1506
/* if $str has no HTML tags, apply nl2br */
1511
1507
if ($ str == strip_tags ($ str )) return nl2br ($ str );
1512
1508
1513
- $ hc = new CI_Input ();
1514
- $ hc ->charset = datalist_db_encoding;
1509
+ $ hc = new CI_Input (datalist_db_encoding);
1515
1510
1516
1511
return $ hc ->xss_clean ($ str );
1517
1512
}
@@ -2091,7 +2086,6 @@ function guessMySQLDateTime($dt) {
2091
2086
2092
2087
return trim ("$ date $ time " );
2093
2088
}
2094
-
2095
2089
#########################################################
2096
2090
function lookupQuery ($ tn , $ lookupField ) {
2097
2091
/*
@@ -2179,3 +2173,22 @@ function userCanImport() {
2179
2173
return false ;
2180
2174
}
2181
2175
#########################################################
2176
+ function parseTemplate ($ template ) {
2177
+ if (trim ($ template ) == '' ) return $ template ;
2178
+
2179
+ global $ Translation ;
2180
+ foreach ($ Translation as $ symbol => $ trans )
2181
+ $ template = str_replace ("<%%TRANSLATION( $ symbol)%%> " , $ trans , $ template );
2182
+
2183
+ // Correct <MaxSize> and <FileTypes> to prevent invalid HTML
2184
+ $ template = str_replace (['<MaxSize> ' , '<FileTypes> ' ], ['{MaxSize} ' , '{FileTypes} ' ], $ template );
2185
+ $ template = str_replace ('<%%BASE_UPLOAD_PATH%%> ' , getUploadDir ('' ), $ template );
2186
+
2187
+ return $ template ;
2188
+ }
2189
+ #########################################################
2190
+ function getUploadDir ($ dir ) {
2191
+ if ($ dir == '' ) $ dir = config ('adminConfig ' )['baseUploadPath ' ];
2192
+
2193
+ return rtrim ($ dir , '\\/ ' ) . '/ ' ;
2194
+ }
0 commit comments