/
functions.php
executable file
·57 lines (41 loc) · 1.28 KB
/
functions.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
<?php
//===============================================
function auto_version( $file ) //$file = RELATIVE: /css/myfile.css
{
//dump( SITEPATH.$file, 1 );
if( strpos( $file, '/' ) !== 0 or ! file_exists( SITEPATH.$file ) )
return $file;
$mtime = filemtime( SITEPATH.$file );
return preg_replace( '{\\.([^./]+)$}', ".$mtime.\$1", $file );
}
//===============================================
function serve_file( $filename )
{
$src_file = __DIR__.$filename;
if ( strpos( $filename, '.css' ) !== false )
{
$mime_type = 'text/css';
}
else if ( strpos( $filename, '.js' ) !== false )
{
$mime_type = 'application/javascript';
}
//dump( $src_file, 1 );
$size = filesize( $src_file );
header( "Expires: 0");
header( "Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0");
header( "Cache-Control: private", false );
header( "Content-transfer-encoding: binary" );
header( 'Content-Type: '.$mime_type );
header( 'Content-Length: '.$size );
exit( readfile( $src_file ) );
}
//===============================================
function dump( $val, $halt = false )
{
echo '<pre>';
echo htmlspecialchars( print_r( $val, true ) );
echo "</pre>\n";
if ( $halt ) exit;
}
//===============================================