Subversion Repositories vgwhois

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
#
4
#  generic Whois - Maintenance Framework Common Functions
5
#
6
#  (c) 2013-2015 Daniel Marschall, ViaThinkSoft [www.viathinksoft.de]
7
#
8
#  Distribution, usage etc. pp. regulated by the current version of GPL.
9
#
10
#
11
#  Version 2015-05-06
12
#
13
 
14
function getpatternfiles() {
15
        $out = array();
16
 
17
        # NEW FILES
18
        $files = glob(__DIR__ . '/../../main/pattern/'.'*');
19
        foreach ($files as &$file) {
20
                # see /usr/bin/gwhois
21
                if (preg_match('@\.dpkg-@', $file)) continue;
22
                if (preg_match('@\.orig$@', $file)) continue;
23
                if (preg_match('@\.bak$@',  $file)) continue;
24
                if (preg_match('@\.save$@', $file)) continue;
25
                if (preg_match('@^\.@',     $file)) continue;
26
 
27
                $out[] = $file;
28
        }
29
 
30
        return $out;
31
}
32
 
33
function get_united_pattern() {
34
        $cont = '';
35
 
36
        $files = getpatternfiles();
37
        foreach ($files as &$file) {
38
                $cont .= file_get_contents($file)."\n\n";
39
        }
40
 
41
        return $cont;
42
}
43
 
44
function cached_file($url, $cache_dir, $max_age = /* 24*60*60 */ 86400) {
45
        $cachefile = $cache_dir . '/' . sha1($url) . '.cache';
46
        if (file_age($cachefile) > $max_age) {
47
                $cont = file_get_contents($url);
48
                file_put_contents($cachefile, $cont);
49
        } else {
50
                $cont = file_get_contents($cachefile);
51
        }
52
        return $cont;
53
}