Blame view

web/admin/exts-src/common.php 1.09 KB
457eed6f   xu   app-api
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
<?php
error_reporting(0);
/*
 * @current_dir 当前目录
 */
function readjs($current_dir = './')
{
    /*
     * 处理例子:
     * [QUERY_STRING] => ?ui/lazyload-1.0.0.js,unit/globalInit-2.0.0.js
     */
    if (!is_dir($current_dir)){
        return ;
    }

    $Q = '?';
    $E = ',';

    $query_string = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';

    if (!$query_string){
        return ;
    }

    $pos = strrpos($query_string, $Q);
    if (false !== $pos) {
        $query_string = substr($query_string, $pos + strlen($Q));
    }

    $files = explode($E, $query_string);

    foreach ($files as $file) {

        $js = substr($file, -3);
        $css = substr($file, -4);

        if ($js !== '.js' &&  $css !== '.css'){
            return ;
        }

//        if ( $js === '.js'){
//            header("Content-type: application/x-javascript; charset=utf-8");
//        } elseif ($css === '.css'){
//            header("Content-type: text/css; charset=utf-8");
//        }

        if (is_file($file = $current_dir . $file)) {
            readfile($file);
        }
    }
}