Projet

Général

Profil

Paste
Télécharger (1,58 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / simplepie-1.3.1 / build / compile.php @ 4b706e38

1 41cc1b08 Assos Assos
<?php
2
// Set up our constants
3
define('SP_PATH', dirname(dirname(__FILE__)));
4
define('COMPILED', SP_PATH . DIRECTORY_SEPARATOR . 'SimplePie.compiled.php');
5
6
function remove_header($contents)
7
{
8
        $tokens = token_get_all($contents);
9
        $stripped_source = '';
10
        $stripped_doc = false;
11
        $stripped_open = false;
12
        foreach ($tokens as $value)
13
        {
14
                if (is_string($value))
15
                {
16
                        $stripped_source .= "{$value}";
17
                        continue;
18
                }
19
                switch ($value[0])
20
                {
21
                        case T_DOC_COMMENT:
22
                                if (!$stripped_doc)
23
                                {
24
                                        $stripped_doc = true;
25
                                        continue 2;
26
                                }
27
                                break;
28
                        case T_OPEN_TAG:
29
                                if (!$stripped_open)
30
                                {
31
                                        $stripped_open = true;
32
                                        continue 2;
33
                                }
34
                                break;
35
                }
36
                $stripped_source .= "{$value[1]}";
37
        }
38
39
        return $stripped_source;
40
}
41
42
// Start with the header
43
$compiled = file_get_contents(SP_PATH . '/build/header.txt');
44
$compiled .= "\n";
45
46
// Add the base class
47
$contents = file_get_contents(SP_PATH . '/library/SimplePie.php');
48
$compiled .= remove_header($contents) . "\n";
49
50
// Add all the files in the SimplePie directory
51
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(SP_PATH . '/library/SimplePie'));
52
foreach($files as $file_path => $info)
53
{
54
        $contents = file_get_contents($file_path);
55
        $compiled .= remove_header($contents) . "\n";
56
}
57
58
// Strip excess whitespace
59
$compiled = preg_replace("#\n\n\n+#", "\n\n", $compiled);
60
61
// Hardcode the build
62
$compiled = str_replace(
63
        "define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()))",
64
        "define('SIMPLEPIE_BUILD', '" . gmdate('YmdHis', time()) . "')",
65
        $compiled
66
);
67
68
// Finally, save
69
file_put_contents(COMPILED, $compiled);