1010define ('QWP_TP_JSON ' , 'application/json ' );
1111define ('QWP_TP_VOICE ' , 'audio/x-wav ' );
1212define ('QWP_TP_XML ' , 'text/xml ' );
13+ define ('QWP_TP_HTML ' , 'text/html ' );
1314
1415// request related functions
1516function TO ($ url ) {
@@ -248,6 +249,7 @@ function get_mime_types() {
248249}
249250function no_cache () {
250251 // no cache
252+ header ('Expires: 0 ' );
251253 header ("Cache-Control: no-store, no-cache, must-revalidate " );
252254 header ("Cache-Control: post-check=0, pre-check=0 " , false );
253255}
@@ -261,31 +263,33 @@ function set_content_type($content_type = 'text/plain', $is_image = false) {
261263 header ("Content-type: $ content_type;charset= " . CONTENT_CHARSET );
262264 }
263265}
264- function download_file ($ file_path , $ file_name , $ content_type = "application/force -download " , $ attachment = true ) {
266+ function download_file ($ file_path , $ file_name , $ content_type = "application/x -download " , $ attachment = true ) {
265267 if (file_exists ($ file_path )) {
266268 $ file_size = filesize ($ file_path );
269+ header ('Content-Description: File Transfer ' );
270+ header ("Content-type: " . $ content_type );
271+ header ("Content-Transfer-Encoding: Binary " );
272+ no_cache ();
267273 header ('Pragma: public ' );
268- header ('Last-Modified: ' . gmdate ('D, d M Y H:i:s ' ) . ' GMT ' );
269- header ('Content-Transfer-Encoding: binary ' );
270- header ('Content-Encoding: none ' );
271- header ('Content-type: ' . $ content_type );
272274 if ($ attachment ) {
273- header ('Content-Disposition: attachment; filename=" ' . $ file_name . ' " ' );
275+ header ('Content-Disposition: attachment; filename= ' . $ file_name );
274276 }
275277 header ('Content-length: ' . $ file_size );
276278 readfile ($ file_path );
277279 } else {
278280 req_not_found ();
279281 }
280282}
281- function set_output_file ($ file_name , $ content_type = "application/force-download " , $ attachment = true ) {
282- header ('Last-Modified: ' . gmdate ('D, d M Y H:i:s ' ) . ' GMT ' );
283- header ('Content-Transfer-Encoding: binary ' );
284- header ('Content-Encoding: none ' );
285- header ('Content-type: ' . $ content_type );
283+ function set_output_file ($ file_name , $ content_type = "application/x-download " , $ attachment = true , $ file_size = 0 ) {
284+ header ('Content-Description: File Transfer ' );
285+ header ("Content-type: " . $ content_type );
286+ header ("Content-Transfer-Encoding: Binary " );
287+ no_cache ();
288+ header ('Pragma: public ' );
286289 if ($ attachment ) {
287- header ('Content-Disposition: attachment; filename=" ' . $ file_name . ' " ' );
290+ header ('Content-Disposition: attachment; filename= ' . $ file_name );
288291 }
292+ if ($ file_size ) header ('Content-length: ' . $ file_size );
289293}
290294// db related functions
291295function encode_slash ($ data ) {
@@ -307,7 +311,7 @@ function encode_array_slash(&$arr) {
307311 }
308312}
309313function safe_html ($ string , $ length = null ) {
310- $ string = trim ($ string );
314+ $ string = trim_ex ($ string );
311315 $ string = utf8_decode ($ string );
312316 $ string = htmlentities ($ string , ENT_NOQUOTES );
313317 $ string = str_replace ("# " , "# " , $ string );
@@ -568,6 +572,9 @@ function date_to_int($timestamp, $format = 'Y-m-d') {
568572 }
569573 return @mktime (0 , 0 , 0 , $ ret ['month ' ], $ ret ['day ' ], $ ret ['year ' ]);
570574}
575+ function xls_time_to_int ($ t ) {
576+ return @mktime (0 , 0 , 0 , 1 , intval ($ t ) - 1 , 1900 );
577+ }
571578function get_date ($ t = 0 , $ offset = 0 , $ sep = '/ ' ) {
572579 $ format = 'Y ' . $ sep . 'm ' . $ sep . 'd ' ;
573580 if ($ offset === 0 ) {
@@ -721,6 +728,11 @@ function copy_from(&$target, $from) {
721728 $ target [$ k ] = $ v ;
722729 }
723730}
731+ function copy_from_ex (&$ target , &$ from ) {
732+ foreach ($ from as $ k => $ v ) {
733+ $ target [$ k ] = $ v ;
734+ }
735+ }
724736// string related functions
725737// string format function like c# string.format
726738function format ($ f ) {
@@ -765,6 +777,10 @@ function trim_all_spaces($str) {
765777 $ str = remove_4bytes_utf8 ($ str );
766778 return preg_replace (array ('/\s/ ' , '/\xC2\xA0/ ' ), '' , $ str );
767779}
780+ function trim_ex (&$ str ) {
781+ $ str = trim ($ str );
782+ $ str = trim ($ str , "\xC2\xA0" );
783+ }
768784function trim_array (&$ arr , $ trims = null )
769785{
770786 if ($ trims )
@@ -1052,6 +1068,7 @@ function get_input_rules($k = null) {
10521068 'digits ' => "^ \\d+$ " ,
10531069 'letters ' => "^([a-z]|[A-Z])+$ " ,
10541070 'alphanumeric ' => "^[ \\w|-]+$ " ,
1071+ 'alphanumeric_ex ' => "^[ \\w|-| \\.]+$ " ,
10551072 // Copyright (c) 2010-2013 Diego Perini, MIT licensed
10561073 // https://gist.github.com/dperini/729294
10571074 // see also https://mathiasbynens.be/demo/url-regex
@@ -1122,6 +1139,13 @@ function is_alphanumeric($v) {
11221139 }
11231140 return preg_match ("/ " . $ statement . "/ " , $ v );
11241141}
1142+ function is_alphanumeric_ex ($ v ) {
1143+ static $ statement ;
1144+ if (!isset ($ statement )) {
1145+ $ statement = get_input_rules ('alphanumeric_ex ' );
1146+ }
1147+ return preg_match ("/ " . $ statement . "/ " , $ v );
1148+ }
11251149function is_url ($ v ) {
11261150 static $ statement ;
11271151 if (!isset ($ statement )) {
0 commit comments