C:\xampp\htdocs\landing\wp-content\plugins\mailchimp-for-wp\includes\class-debug-log.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php

/**
 * Class MC4WP_Debug_Log
 *
 * Simple logging class which writes to a file, loosely based on PSR-3.
 */
class MC4WP_Debug_Log {


    
/**
     * Detailed debug information
     */
    
const DEBUG 100;

    
/**
     * Interesting events
     *
     * Examples: Visitor subscribed
     */
    
const INFO 200;

    
/**
     * Exceptional occurrences that are not errors
     *
     * Examples: User already subscribed
     */
    
const WARNING 300;

    
/**
     * Runtime errors
     */
    
const ERROR 400;

    
/**
     * Logging levels from syslog protocol defined in RFC 5424
     *
     * @var array $levels Logging levels
     */
    
protected static $levels = array(
        
self::DEBUG   => 'DEBUG',
        
self::INFO    => 'INFO',
        
self::WARNING => 'WARNING',
        
self::ERROR   => 'ERROR',
    );

    
/**
     * @var string The file to which messages should be written.
     */
    
public $file;

    
/**
     * @var int Only write messages with this level or higher
     */
    
public $level;

    
/**
     * @var resource
     */
    
protected $stream;

    
/**
     * MC4WP_Debug_Log constructor.
     *
     * @param string $file
     * @param mixed $level;
     */
    
public function __construct$file$level self::DEBUG ) {
        
$this->file  $file;
        
$this->level self::to_level$level );
    }

    
/**
     * @param mixed $level
     * @param string $message
     * @return boolean
     */
    
public function log$level$message ) {
        
$level self::to_level$level );

        
// only log if message level is higher than log level
        
if ( $level $this->level ) {
            return 
false;
        }

        
// obfuscate email addresses in log message since log might be public.
        
$message mc4wp_obfuscate_email_addresses( (string) $message );

        
// first, get rid of everything between "invisible" tags
        
$message preg_replace'/<(?:style|script|head)>.+?<\/(?:style|script|head)>/is'''$message );

        
// then, strip tags (while retaining content of these tags)
        
$message strip_tags$message );
        
$message trim$message );

        
// generate line
        
$level_name self::get_level_name$level );
        
$datetime   gmdate'Y-m-d H:i:s'time() + ( get_option'gmt_offset') * HOUR_IN_SECONDS ) );
        
$message    sprintf'[%s] %s: %s'$datetime$level_name$message ) . PHP_EOL;

        
// did we open stream yet?
        
if ( ! is_resource$this->stream ) ) {
            
// attempt to open stream
            
$this->stream = @fopen$this->file'c+' );
            if ( ! 
is_resource$this->stream ) ) {
                return 
false;
            }

            
// make sure first line of log file is a PHP tag + exit statement (to prevent direct file access)
            
$line            fgets$this->stream );
            
$php_exit_string '<?php exit; ?>';
            if ( 
strpos$line$php_exit_string ) !== ) {
                
rewind$this->stream );
                
fwrite$this->stream$php_exit_string PHP_EOL $line );
            }

            
// place pointer at end of file
            
fseek$this->stream0SEEK_END );
        }

        
// lock file while we write, ignore errors (not much we can do)
        
flock$this->streamLOCK_EX );

        
// write the message to the file
        
fwrite$this->stream$message );

        
// unlock file again, but don't close it for remainder of this request
        
flock$this->streamLOCK_UN );

        return 
true;
    }

    
/**
     * @param string $message
     * @return boolean
     */
    
public function warning$message ) {
        return 
$this->logself::WARNING$message );
    }

    
/**
     * @param string $message
     * @return boolean
     */
    
public function info$message ) {
        return 
$this->logself::INFO$message );
    }

    
/**
     * @param string $message
     * @return boolean
     */
    
public function error$message ) {
        return 
$this->logself::ERROR$message );
    }

    
/**
     * @param string $message
     * @return boolean
     */
    
public function debug$message ) {
        return 
$this->logself::DEBUG$message );
    }

    
/**
     * Converts PSR-3 levels to local ones if necessary
     *
     * @param string|int Level number or name (PSR-3)
     * @return int
     */
    
public static function to_level$level ) {
        if ( 
is_string$level ) ) {
            
$level strtoupper$level );
            if ( 
defined__CLASS__ '::' $level ) ) {
                return 
constant__CLASS__ '::' $level );
            }

            throw new 
InvalidArgumentException'Level "' $level '" is not defined, use one of: ' implode', 'array_keysself::$levels ) ) );
        }

        return 
$level;
    }

    
/**
     * Gets the name of the logging level.
     *
     * @param  int    $level
     * @return string
     */
    
public static function get_level_name$level ) {
        if ( ! isset( 
self::$levels$level ] ) ) {
            throw new 
InvalidArgumentException'Level "' $level '" is not defined, use one of: ' implode', 'array_keysself::$levels ) ) );
        }

        return 
self::$levels$level ];
    }

    
/**
     * Tests if the log file is writable
     *
     * @return bool
     */
    
public function test() {
        
$handle   = @fopen$this->file'a' );
        
$writable false;

        if ( 
is_resource$handle ) ) {
            
$writable true;
            
fclose$handle );
        }

        return 
$writable;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586