Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress - Version 1.1.19

Version Description

Download this release

Release Info

Developer sandesh055
Plugin Icon Funnel Builder by CartFlows – Create High Converting Sales Funnels For WordPress
Version 1.1.19
Comparing to
See all releases

Code changes from version 1.1.18 to 1.1.19

classes/logger/class-cartflows-log-handler-file.php ADDED
@@ -0,0 +1,442 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class Cartflows_Log_Handler_File file.
4
+ *
5
+ * @package WooCommerce\Log Handlers
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit; // Exit if accessed directly.
10
+ }
11
+
12
+ /**
13
+ * Handles log entries by writing to a file.
14
+ *
15
+ * @class Cartflows_Log_Handler_File
16
+ * @version 1.0.0
17
+ * @package WooCommerce/Classes/Log_Handlers
18
+ */
19
+ class Cartflows_Log_Handler_File extends Cartflows_Log_Handler {
20
+
21
+ /**
22
+ * Stores open file handles.
23
+ *
24
+ * @var array
25
+ */
26
+ protected $handles = array();
27
+
28
+ /**
29
+ * File size limit for log files in bytes.
30
+ *
31
+ * @var int
32
+ */
33
+ protected $log_size_limit;
34
+
35
+ /**
36
+ * Cache logs that could not be written.
37
+ *
38
+ * If a log is written too early in the request, pluggable functions may be unavailable. These
39
+ * logs will be cached and written on 'plugins_loaded' action.
40
+ *
41
+ * @var array
42
+ */
43
+ protected $cached_logs = array();
44
+
45
+ /**
46
+ * Constructor for the logger.
47
+ *
48
+ * @param int $log_size_limit Optional. Size limit for log files. Default 5mb.
49
+ */
50
+ public function __construct( $log_size_limit = null ) {
51
+ if ( null === $log_size_limit ) {
52
+ $log_size_limit = 5 * 1024 * 1024;
53
+ }
54
+
55
+ $this->log_size_limit = apply_filters( 'cartflows_log_file_size_limit', $log_size_limit );
56
+
57
+ add_action( 'plugins_loaded', array( $this, 'write_cached_logs' ) );
58
+ }
59
+
60
+ /**
61
+ * Destructor.
62
+ *
63
+ * Cleans up open file handles.
64
+ */
65
+ public function __destruct() {
66
+ foreach ( $this->handles as $handle ) {
67
+ if ( is_resource( $handle ) ) {
68
+ fclose( $handle ); // @codingStandardsIgnoreLine.
69
+ }
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Handle a log entry.
75
+ *
76
+ * @param int $timestamp Log timestamp.
77
+ * @param string $level emergency|alert|critical|error|warning|notice|info|debug.
78
+ * @param string $message Log message.
79
+ * @param array $context {
80
+ * Additional information for log handlers.
81
+ *
82
+ * @type string $source Optional. Determines log file to write to. Default 'log'.
83
+ * @type bool $_legacy Optional. Default false. True to use outdated log format
84
+ * originally used in deprecated Cartflows_WC_Logger::add calls.
85
+ * }
86
+ *
87
+ * @return bool False if value was not handled and true if value was handled.
88
+ */
89
+ public function handle( $timestamp, $level, $message, $context ) {
90
+
91
+ if ( isset( $context['source'] ) && $context['source'] ) {
92
+ $handle = $context['source'];
93
+ } else {
94
+ $handle = 'log';
95
+ }
96
+
97
+ $entry = self::format_entry( $timestamp, $level, $message, $context );
98
+
99
+ return $this->add( $entry, $handle );
100
+ }
101
+
102
+ /**
103
+ * Builds a log entry text from timestamp, level and message.
104
+ *
105
+ * @param int $timestamp Log timestamp.
106
+ * @param string $level emergency|alert|critical|error|warning|notice|info|debug.
107
+ * @param string $message Log message.
108
+ * @param array $context Additional information for log handlers.
109
+ *
110
+ * @return string Formatted log entry.
111
+ */
112
+ protected static function format_entry( $timestamp, $level, $message, $context ) {
113
+
114
+ if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) {
115
+ if ( isset( $context['source'] ) && $context['source'] ) {
116
+ $handle = $context['source'];
117
+ } else {
118
+ $handle = 'log';
119
+ }
120
+ $message = apply_filters( 'cartflows_logger_add_message', $message, $handle );
121
+ $time = date_i18n( 'm-d-Y @ H:i:s' );
122
+ $entry = "{$time} - {$message}";
123
+ } else {
124
+ $entry = parent::format_entry( $timestamp, $level, $message, $context );
125
+ }
126
+
127
+ return $entry;
128
+ }
129
+
130
+ /**
131
+ * Open log file for writing.
132
+ *
133
+ * @param string $handle Log handle.
134
+ * @param string $mode Optional. File mode. Default 'a'.
135
+ * @return bool Success.
136
+ */
137
+ protected function open( $handle, $mode = 'a' ) {
138
+ if ( $this->is_open( $handle ) ) {
139
+ return true;
140
+ }
141
+
142
+ $file = self::get_log_file_path( $handle );
143
+
144
+ if ( $file ) {
145
+ if ( ! file_exists( $file ) ) {
146
+ $temphandle = @fopen( $file, 'w+' ); // @codingStandardsIgnoreLine.
147
+ @fclose( $temphandle ); // @codingStandardsIgnoreLine.
148
+
149
+ if ( defined( 'FS_CHMOD_FILE' ) ) {
150
+ @chmod( $file, FS_CHMOD_FILE ); // @codingStandardsIgnoreLine.
151
+ }
152
+ }
153
+
154
+ $resource = @fopen( $file, $mode ); // @codingStandardsIgnoreLine.
155
+
156
+ if ( $resource ) {
157
+ $this->handles[ $handle ] = $resource;
158
+ return true;
159
+ }
160
+ }
161
+
162
+ return false;
163
+ }
164
+
165
+ /**
166
+ * Check if a handle is open.
167
+ *
168
+ * @param string $handle Log handle.
169
+ * @return bool True if $handle is open.
170
+ */
171
+ protected function is_open( $handle ) {
172
+ return array_key_exists( $handle, $this->handles ) && is_resource( $this->handles[ $handle ] );
173
+ }
174
+
175
+ /**
176
+ * Close a handle.
177
+ *
178
+ * @param string $handle Log handle.
179
+ * @return bool success
180
+ */
181
+ protected function close( $handle ) {
182
+ $result = false;
183
+
184
+ if ( $this->is_open( $handle ) ) {
185
+ $result = fclose( $this->handles[ $handle ] ); // @codingStandardsIgnoreLine.
186
+ unset( $this->handles[ $handle ] );
187
+ }
188
+
189
+ return $result;
190
+ }
191
+
192
+ /**
193
+ * Add a log entry to chosen file.
194
+ *
195
+ * @param string $entry Log entry text.
196
+ * @param string $handle Log entry handle.
197
+ *
198
+ * @return bool True if write was successful.
199
+ */
200
+ protected function add( $entry, $handle ) {
201
+ $result = false;
202
+
203
+ if ( $this->should_rotate( $handle ) ) {
204
+ $this->log_rotate( $handle );
205
+ }
206
+
207
+ if ( $this->open( $handle ) && is_resource( $this->handles[ $handle ] ) ) {
208
+ $result = fwrite( $this->handles[ $handle ], $entry . PHP_EOL ); // @codingStandardsIgnoreLine.
209
+ } else {
210
+ $this->cache_log( $entry, $handle );
211
+ }
212
+
213
+ return false !== $result;
214
+ }
215
+
216
+ /**
217
+ * Clear entries from chosen file.
218
+ *
219
+ * @param string $handle Log handle.
220
+ *
221
+ * @return bool
222
+ */
223
+ public function clear( $handle ) {
224
+ $result = false;
225
+
226
+ // Close the file if it's already open.
227
+ $this->close( $handle );
228
+
229
+ /**
230
+ * $this->open( $handle, 'w' ) == Open the file for writing only. Place the file pointer at
231
+ * the beginning of the file, and truncate the file to zero length.
232
+ */
233
+ if ( $this->open( $handle, 'w' ) && is_resource( $this->handles[ $handle ] ) ) {
234
+ $result = true;
235
+ }
236
+
237
+ do_action( 'cartflows_log_clear', $handle );
238
+
239
+ return $result;
240
+ }
241
+
242
+ /**
243
+ * Remove/delete the chosen file.
244
+ *
245
+ * @param string $handle Log handle.
246
+ *
247
+ * @return bool
248
+ */
249
+ public function remove( $handle ) {
250
+ $removed = false;
251
+ $logs = $this->get_log_files();
252
+ $handle = sanitize_title( $handle );
253
+
254
+ if ( isset( $logs[ $handle ] ) && $logs[ $handle ] ) {
255
+ $file = realpath( trailingslashit( CARTFLOWS_LOG_DIR ) . $logs[ $handle ] );
256
+ if ( 0 === stripos( $file, realpath( trailingslashit( CARTFLOWS_LOG_DIR ) ) ) && is_file( $file ) && is_writable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable
257
+ $this->close( $file ); // Close first to be certain no processes keep it alive after it is unlinked.
258
+ $removed = unlink( $file ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_unlink
259
+ }
260
+ do_action( 'cartflows_log_remove', $handle, $removed );
261
+ }
262
+ return $removed;
263
+ }
264
+
265
+ /**
266
+ * Check if log file should be rotated.
267
+ *
268
+ * Compares the size of the log file to determine whether it is over the size limit.
269
+ *
270
+ * @param string $handle Log handle.
271
+ * @return bool True if if should be rotated.
272
+ */
273
+ protected function should_rotate( $handle ) {
274
+ $file = self::get_log_file_path( $handle );
275
+ if ( $file ) {
276
+ if ( $this->is_open( $handle ) ) {
277
+ $file_stat = fstat( $this->handles[ $handle ] );
278
+ return $file_stat['size'] > $this->log_size_limit;
279
+ } elseif ( file_exists( $file ) ) {
280
+ return filesize( $file ) > $this->log_size_limit;
281
+ } else {
282
+ return false;
283
+ }
284
+ } else {
285
+ return false;
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Rotate log files.
291
+ *
292
+ * Logs are rotated by prepending '.x' to the '.log' suffix.
293
+ * The current log plus 10 historical logs are maintained.
294
+ * For example:
295
+ * base.9.log -> [ REMOVED ]
296
+ * base.8.log -> base.9.log
297
+ * ...
298
+ * base.0.log -> base.1.log
299
+ * base.log -> base.0.log
300
+ *
301
+ * @param string $handle Log handle.
302
+ */
303
+ protected function log_rotate( $handle ) {
304
+ for ( $i = 8; $i >= 0; $i-- ) {
305
+ $this->increment_log_infix( $handle, $i );
306
+ }
307
+ $this->increment_log_infix( $handle );
308
+ }
309
+
310
+ /**
311
+ * Increment a log file suffix.
312
+ *
313
+ * @param string $handle Log handle.
314
+ * @param null|int $number Optional. Default null. Log suffix number to be incremented.
315
+ * @return bool True if increment was successful, otherwise false.
316
+ */
317
+ protected function increment_log_infix( $handle, $number = null ) {
318
+ if ( null === $number ) {
319
+ $suffix = '';
320
+ $next_suffix = '.0';
321
+ } else {
322
+ $suffix = '.' . $number;
323
+ $next_suffix = '.' . ( $number + 1 );
324
+ }
325
+
326
+ $rename_from = self::get_log_file_path( "{$handle}{$suffix}" );
327
+ $rename_to = self::get_log_file_path( "{$handle}{$next_suffix}" );
328
+
329
+ if ( $this->is_open( $rename_from ) ) {
330
+ $this->close( $rename_from );
331
+ }
332
+
333
+ if ( is_writable( $rename_from ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable
334
+ return rename( $rename_from, $rename_to ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename
335
+ } else {
336
+ return false;
337
+ }
338
+
339
+ }
340
+
341
+ /**
342
+ * Get a log file path.
343
+ *
344
+ * @param string $handle Log name.
345
+ * @return bool|string The log file path or false if path cannot be determined.
346
+ */
347
+ public static function get_log_file_path( $handle ) {
348
+ if ( function_exists( 'wp_hash' ) ) {
349
+ return trailingslashit( CARTFLOWS_LOG_DIR ) . self::get_log_file_name( $handle );
350
+ } else {
351
+ wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'cartflows' ), '3.0' );
352
+ return false;
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Get a log file name.
358
+ *
359
+ * File names consist of the handle, followed by the date, followed by a hash, .log.
360
+ *
361
+ * @since 3.3
362
+ * @param string $handle Log name.
363
+ * @return bool|string The log file name or false if cannot be determined.
364
+ */
365
+ public static function get_log_file_name( $handle ) {
366
+ if ( function_exists( 'wp_hash' ) ) {
367
+ $date_suffix = date( 'Y-m-d', current_time( 'timestamp', true ) );
368
+ $hash_suffix = wp_hash( $handle );
369
+ return sanitize_file_name( implode( '-', array( $handle, $date_suffix, $hash_suffix ) ) . '.log' );
370
+ } else {
371
+ wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'cartflows' ), '3.3' );
372
+ return false;
373
+ }
374
+ }
375
+
376
+ /**
377
+ * Cache log to write later.
378
+ *
379
+ * @param string $entry Log entry text.
380
+ * @param string $handle Log entry handle.
381
+ */
382
+ protected function cache_log( $entry, $handle ) {
383
+ $this->cached_logs[] = array(
384
+ 'entry' => $entry,
385
+ 'handle' => $handle,
386
+ );
387
+ }
388
+
389
+ /**
390
+ * Write cached logs.
391
+ */
392
+ public function write_cached_logs() {
393
+ foreach ( $this->cached_logs as $log ) {
394
+ $this->add( $log['entry'], $log['handle'] );
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Delete all logs older than a defined timestamp.
400
+ *
401
+ * @since 3.4.0
402
+ * @param integer $timestamp Timestamp to delete logs before.
403
+ */
404
+ public static function delete_logs_before_timestamp( $timestamp = 0 ) {
405
+ if ( ! $timestamp ) {
406
+ return;
407
+ }
408
+
409
+ $log_files = self::get_log_files();
410
+
411
+ foreach ( $log_files as $log_file ) {
412
+ $last_modified = filemtime( trailingslashit( CARTFLOWS_LOG_DIR ) . $log_file );
413
+
414
+ if ( $last_modified < $timestamp ) {
415
+ @unlink( trailingslashit( CARTFLOWS_LOG_DIR ) . $log_file ); // @codingStandardsIgnoreLine.
416
+ }
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Get all log files in the log directory.
422
+ *
423
+ * @since 3.4.0
424
+ * @return array
425
+ */
426
+ public static function get_log_files() {
427
+ $files = @scandir( CARTFLOWS_LOG_DIR ); // @codingStandardsIgnoreLine.
428
+ $result = array();
429
+
430
+ if ( ! empty( $files ) ) {
431
+ foreach ( $files as $key => $value ) {
432
+ if ( ! in_array( $value, array( '.', '..' ), true ) ) {
433
+ if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) {
434
+ $result[ sanitize_title( $value ) ] = $value;
435
+ }
436
+ }
437
+ }
438
+ }
439
+
440
+ return $result;
441
+ }
442
+ }
classes/logger/class-cartflows-log-handler-interface.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Log Handler Interface
4
+ *
5
+ * @version 3.3.0
6
+ * @package WooCommerce/Interface
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ /**
14
+ * WC Log Handler Interface
15
+ *
16
+ * Functions that must be defined to correctly fulfill log handler API.
17
+ *
18
+ * @version 3.3.0
19
+ */
20
+ interface Cartflows_Log_Handler_Interface {
21
+
22
+ /**
23
+ * Handle a log entry.
24
+ *
25
+ * @param int $timestamp Log timestamp.
26
+ * @param string $level emergency|alert|critical|error|warning|notice|info|debug.
27
+ * @param string $message Log message.
28
+ * @param array $context Additional information for log handlers.
29
+ *
30
+ * @return bool False if value was not handled and true if value was handled.
31
+ */
32
+ public function handle( $timestamp, $level, $message, $context );
33
+ }
classes/logger/class-cartflows-log-handler.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Log handling functionality.
4
+ *
5
+ * @class Cartflows_Log_Handler
6
+ * @package WooCommerce/Abstracts
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ /**
14
+ * Abstract WC Log Handler Class
15
+ *
16
+ * @version 1.0.0
17
+ * @package WooCommerce/Abstracts
18
+ */
19
+ abstract class Cartflows_Log_Handler implements Cartflows_Log_Handler_Interface {
20
+
21
+ /**
22
+ * Formats a timestamp for use in log messages.
23
+ *
24
+ * @param int $timestamp Log timestamp.
25
+ * @return string Formatted time for use in log entry.
26
+ */
27
+ protected static function format_time( $timestamp ) {
28
+ return date( 'c', $timestamp );
29
+ }
30
+
31
+ /**
32
+ * Builds a log entry text from level, timestamp and message.
33
+ *
34
+ * @param int $timestamp Log timestamp.
35
+ * @param string $level emergency|alert|critical|error|warning|notice|info|debug.
36
+ * @param string $message Log message.
37
+ * @param array $context Additional information for log handlers.
38
+ *
39
+ * @return string Formatted log entry.
40
+ */
41
+ protected static function format_entry( $timestamp, $level, $message, $context ) {
42
+ $time_string = self::format_time( $timestamp );
43
+ $level_string = strtoupper( $level );
44
+ $entry = "{$time_string} {$level_string} {$message}";
45
+
46
+ return apply_filters(
47
+ 'cartflows_format_log_entry',
48
+ $entry,
49
+ array(
50
+ 'timestamp' => $timestamp,
51
+ 'level' => $level,
52
+ 'message' => $message,
53
+ 'context' => $context,
54
+ )
55
+ );
56
+ }
57
+ }
classes/logger/class-cartflows-log-levels.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Standard log levels
4
+ *
5
+ * @version 3.2.0
6
+ * @package WooCommerce/Classes
7
+ */
8
+
9
+ defined( 'ABSPATH' ) || exit;
10
+
11
+ /**
12
+ * Log levels class.
13
+ */
14
+ abstract class Cartflows_Log_Levels {
15
+
16
+ /**
17
+ * Log Levels
18
+ *
19
+ * Description of levels:
20
+ * 'emergency': System is unusable.
21
+ * 'alert': Action must be taken immediately.
22
+ * 'critical': Critical conditions.
23
+ * 'error': Error conditions.
24
+ * 'warning': Warning conditions.
25
+ * 'notice': Normal but significant condition.
26
+ * 'info': Informational messages.
27
+ * 'debug': Debug-level messages.
28
+ *
29
+ * @see @link {https://tools.ietf.org/html/rfc5424}
30
+ */
31
+ const EMERGENCY = 'emergency';
32
+ const ALERT = 'alert';
33
+ const CRITICAL = 'critical';
34
+ const ERROR = 'error';
35
+ const WARNING = 'warning';
36
+ const NOTICE = 'notice';
37
+ const INFO = 'info';
38
+ const DEBUG = 'debug';
39
+
40
+ /**
41
+ * Level strings mapped to integer severity.
42
+ *
43
+ * @var array
44
+ */
45
+ protected static $level_to_severity = array(
46
+ self::EMERGENCY => 800,
47
+ self::ALERT => 700,
48
+ self::CRITICAL => 600,
49
+ self::ERROR => 500,
50
+ self::WARNING => 400,
51
+ self::NOTICE => 300,
52
+ self::INFO => 200,
53
+ self::DEBUG => 100,
54
+ );
55
+
56
+ /**
57
+ * Severity integers mapped to level strings.
58
+ *
59
+ * This is the inverse of $level_severity.
60
+ *
61
+ * @var array
62
+ */
63
+ protected static $severity_to_level = array(
64
+ 800 => self::EMERGENCY,
65
+ 700 => self::ALERT,
66
+ 600 => self::CRITICAL,
67
+ 500 => self::ERROR,
68
+ 400 => self::WARNING,
69
+ 300 => self::NOTICE,
70
+ 200 => self::INFO,
71
+ 100 => self::DEBUG,
72
+ );
73
+
74
+
75
+ /**
76
+ * Validate a level string.
77
+ *
78
+ * @param string $level Log level.
79
+ * @return bool True if $level is a valid level.
80
+ */
81
+ public static function is_valid_level( $level ) {
82
+ return array_key_exists( strtolower( $level ), self::$level_to_severity );
83
+ }
84
+
85
+ /**
86
+ * Translate level string to integer.
87
+ *
88
+ * @param string $level Log level, options: emergency|alert|critical|error|warning|notice|info|debug.
89
+ * @return int 100 (debug) - 800 (emergency) or 0 if not recognized
90
+ */
91
+ public static function get_level_severity( $level ) {
92
+ return self::is_valid_level( $level ) ? self::$level_to_severity[ strtolower( $level ) ] : 0;
93
+ }
94
+
95
+ /**
96
+ * Translate severity integer to level string.
97
+ *
98
+ * @param int $severity Serevity level.
99
+ * @return bool|string False if not recognized. Otherwise string representation of level.
100
+ */
101
+ public static function get_severity_level( $severity ) {
102
+ if ( ! array_key_exists( $severity, self::$severity_to_level ) ) {
103
+ return false;
104
+ }
105
+ return self::$severity_to_level[ $severity ];
106
+ }
107
+
108
+ }
classes/logger/class-cartflows-logger-interface.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Logger Interface
4
+ *
5
+ * @version 3.0.0
6
+ * @package WooCommerce/Interface
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ /**
14
+ * WC Logger Interface
15
+ *
16
+ * Functions that must be defined to correctly fulfill logger API.
17
+ *
18
+ * @version 3.0.0
19
+ */
20
+ interface Cartflows_WC_Logger_Interface {
21
+
22
+ /**
23
+ * Add a log entry.
24
+ *
25
+ * This is not the preferred method for adding log messages. Please use log() or any one of
26
+ * the level methods (debug(), info(), etc.). This method may be deprecated in the future.
27
+ *
28
+ * @param string $handle File handle.
29
+ * @param string $message Log message.
30
+ * @param string $level Log level.
31
+ *
32
+ * @return bool True if log was added, otherwise false.
33
+ */
34
+ public function add( $handle, $message, $level = Cartflows_Log_Levels::NOTICE );
35
+
36
+ /**
37
+ * Add a log entry.
38
+ *
39
+ * @param string $level One of the following:
40
+ * 'emergency': System is unusable.
41
+ * 'alert': Action must be taken immediately.
42
+ * 'critical': Critical conditions.
43
+ * 'error': Error conditions.
44
+ * 'warning': Warning conditions.
45
+ * 'notice': Normal but significant condition.
46
+ * 'info': Informational messages.
47
+ * 'debug': Debug-level messages.
48
+ * @param string $message Log message.
49
+ * @param array $context Optional. Additional information for log handlers.
50
+ */
51
+ public function log( $level, $message, $context = array() );
52
+
53
+ /**
54
+ * Adds an emergency level message.
55
+ *
56
+ * System is unusable.
57
+ *
58
+ * @param string $message Log message.
59
+ * @param array $context Optional. Additional information for log handlers.
60
+ */
61
+ public function emergency( $message, $context = array() );
62
+
63
+ /**
64
+ * Adds an alert level message.
65
+ *
66
+ * Action must be taken immediately.
67
+ * Example: Entire website down, database unavailable, etc.
68
+ *
69
+ * @param string $message Log message.
70
+ * @param array $context Optional. Additional information for log handlers.
71
+ */
72
+ public function alert( $message, $context = array() );
73
+
74
+ /**
75
+ * Adds a critical level message.
76
+ *
77
+ * Critical conditions.
78
+ * Example: Application component unavailable, unexpected exception.
79
+ *
80
+ * @param string $message Log message.
81
+ * @param array $context Optional. Additional information for log handlers.
82
+ */
83
+ public function critical( $message, $context = array() );
84
+
85
+ /**
86
+ * Adds an error level message.
87
+ *
88
+ * Runtime errors that do not require immediate action but should typically be logged
89
+ * and monitored.
90
+ *
91
+ * @param string $message Log message.
92
+ * @param array $context Optional. Additional information for log handlers.
93
+ */
94
+ public function error( $message, $context = array() );
95
+
96
+ /**
97
+ * Adds a warning level message.
98
+ *
99
+ * Exceptional occurrences that are not errors.
100
+ *
101
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not
102
+ * necessarily wrong.
103
+ *
104
+ * @param string $message Log message.
105
+ * @param array $context Optional. Additional information for log handlers.
106
+ */
107
+ public function warning( $message, $context = array() );
108
+
109
+ /**
110
+ * Adds a notice level message.
111
+ *
112
+ * Normal but significant events.
113
+ *
114
+ * @param string $message Log message.
115
+ * @param array $context Optional. Additional information for log handlers.
116
+ */
117
+ public function notice( $message, $context = array() );
118
+
119
+ /**
120
+ * Adds a info level message.
121
+ *
122
+ * Interesting events.
123
+ * Example: User logs in, SQL logs.
124
+ *
125
+ * @param string $message Log message.
126
+ * @param array $context Optional. Additional information for log handlers.
127
+ */
128
+ public function info( $message, $context = array() );
129
+
130
+ /**
131
+ * Adds a debug level message.
132
+ *
133
+ * Detailed debug information.
134
+ *
135
+ * @param string $message Log message.
136
+ * @param array $context Optional. Additional information for log handlers.
137
+ */
138
+ public function debug( $message, $context = array() );
139
+ }
classes/logger/class-cartflows-wc-logger.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Provides logging capabilities for debugging purposes.
4
+ *
5
+ * @class Cartflows_WC_Logger
6
+ * @version 2.0.0
7
+ * @package WooCommerce/Classes
8
+ */
9
+
10
+ defined( 'ABSPATH' ) || exit;
11
+
12
+ /**
13
+ * Cartflows_WC_Logger class.
14
+ */
15
+ class Cartflows_WC_Logger implements Cartflows_WC_Logger_Interface {
16
+
17
+ /**
18
+ * Stores registered log handlers.
19
+ *
20
+ * @var array
21
+ */
22
+ protected $handlers;
23
+
24
+ /**
25
+ * Minimum log level this handler will process.
26
+ *
27
+ * @var int Integer representation of minimum log level to handle.
28
+ */
29
+ protected $threshold;
30
+
31
+ /**
32
+ * Constructor for the logger.
33
+ *
34
+ * @param array $handlers Optional. Array of log handlers. If $handlers is not provided, the filter 'woocommerce_register_log_handlers' will be used to define the handlers. If $handlers is provided, the filter will not be applied and the handlers will be used directly.
35
+ * @param string $threshold Optional. Define an explicit threshold. May be configured via WC_LOG_THRESHOLD. By default, all logs will be processed.
36
+ */
37
+ public function __construct( $handlers = null, $threshold = null ) {
38
+ if ( null === $handlers ) {
39
+ $handlers = apply_filters( 'cartflows_register_log_handlers', array() );
40
+
41
+ $default_handler = new Cartflows_Log_Handler_File();
42
+
43
+ array_push( $handlers, $default_handler );
44
+ }
45
+
46
+ $register_handlers = array();
47
+
48
+ if ( ! empty( $handlers ) && is_array( $handlers ) ) {
49
+ foreach ( $handlers as $handler ) {
50
+ $implements = class_implements( $handler );
51
+ if ( is_object( $handler ) && is_array( $implements ) && in_array( 'Cartflows_Log_Handler_Interface', $implements, true ) ) {
52
+ $register_handlers[] = $handler;
53
+ } else {
54
+ wc_doing_it_wrong(
55
+ __METHOD__,
56
+ sprintf(
57
+ /* translators: 1: class name 2: Cartflows_Log_Handler_Interface */
58
+ __( 'The provided handler %1$s does not implement %2$s.', 'cartflows' ),
59
+ '<code>' . esc_html( is_object( $handler ) ? get_class( $handler ) : $handler ) . '</code>',
60
+ '<code>Cartflows_Log_Handler_Interface</code>'
61
+ ),
62
+ '3.0'
63
+ );
64
+ }
65
+ }
66
+ }
67
+
68
+ if ( null !== $threshold ) {
69
+ $threshold = Cartflows_Log_Levels::get_level_severity( $threshold );
70
+ } elseif ( defined( 'WC_LOG_THRESHOLD' ) && Cartflows_Log_Levels::is_valid_level( WC_LOG_THRESHOLD ) ) {
71
+ $threshold = Cartflows_Log_Levels::get_level_severity( WC_LOG_THRESHOLD );
72
+ } else {
73
+ $threshold = null;
74
+ }
75
+
76
+ $this->handlers = $register_handlers;
77
+ $this->threshold = $threshold;
78
+ }
79
+
80
+ /**
81
+ * Determine whether to handle or ignore log.
82
+ *
83
+ * @param string $level emergency|alert|critical|error|warning|notice|info|debug.
84
+ * @return bool True if the log should be handled.
85
+ */
86
+ protected function should_handle( $level ) {
87
+ if ( null === $this->threshold ) {
88
+ return true;
89
+ }
90
+ return $this->threshold <= Cartflows_Log_Levels::get_level_severity( $level );
91
+ }
92
+
93
+ /**
94
+ * Add a log entry.
95
+ *
96
+ * This is not the preferred method for adding log messages. Please use log() or any one of
97
+ * the level methods (debug(), info(), etc.). This method may be deprecated in the future.
98
+ *
99
+ * @param string $handle File handle.
100
+ * @param string $message Message to log.
101
+ * @param string $level Logging level.
102
+ * @return bool
103
+ */
104
+ public function add( $handle, $message, $level = Cartflows_Log_Levels::NOTICE ) {
105
+ $message = apply_filters( 'cartflows_logger_add_message', $message, $handle );
106
+ $this->log(
107
+ $level,
108
+ $message,
109
+ array(
110
+ 'source' => $handle,
111
+ '_legacy' => true,
112
+ )
113
+ );
114
+ wc_do_deprecated_action( 'cartflows_log_add', array( $handle, $message ), '3.0', 'This action has been deprecated with no alternative.' );
115
+ return true;
116
+ }
117
+
118
+ /**
119
+ * Add a log entry.
120
+ *
121
+ * @param string $level One of the following:
122
+ * 'emergency': System is unusable.
123
+ * 'alert': Action must be taken immediately.
124
+ * 'critical': Critical conditions.
125
+ * 'error': Error conditions.
126
+ * 'warning': Warning conditions.
127
+ * 'notice': Normal but significant condition.
128
+ * 'info': Informational messages.
129
+ * 'debug': Debug-level messages.
130
+ * @param string $message Log message.
131
+ * @param array $context Optional. Additional information for log handlers.
132
+ */
133
+ public function log( $level, $message, $context = array() ) {
134
+ if ( ! Cartflows_Log_Levels::is_valid_level( $level ) ) {
135
+ /* translators: 1: Cartflows_WC_Logger::log 2: level */
136
+ wc_doing_it_wrong( __METHOD__, sprintf( __( '%1$s was called with an invalid level "%2$s".', 'cartflows' ), '<code>Cartflows_WC_Logger::log</code>', $level ), '3.0' );
137
+ }
138
+
139
+ if ( $this->should_handle( $level ) ) {
140
+ $timestamp = current_time( 'timestamp', 1 );
141
+ $message = apply_filters( 'cartflows_logger_log_message', $message, $level, $context );
142
+
143
+ foreach ( $this->handlers as $handler ) {
144
+ $handler->handle( $timestamp, $level, $message, $context );
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Adds an emergency level message.
151
+ *
152
+ * System is unusable.
153
+ *
154
+ * @see Cartflows_WC_Logger::log
155
+ *
156
+ * @param string $message Message to log.
157
+ * @param array $context Log context.
158
+ */
159
+ public function emergency( $message, $context = array() ) {
160
+ $this->log( Cartflows_Log_Levels::EMERGENCY, $message, $context );
161
+ }
162
+
163
+ /**
164
+ * Adds an alert level message.
165
+ *
166
+ * Action must be taken immediately.
167
+ * Example: Entire website down, database unavailable, etc.
168
+ *
169
+ * @see Cartflows_WC_Logger::log
170
+ *
171
+ * @param string $message Message to log.
172
+ * @param array $context Log context.
173
+ */
174
+ public function alert( $message, $context = array() ) {
175
+ $this->log( Cartflows_Log_Levels::ALERT, $message, $context );
176
+ }
177
+
178
+ /**
179
+ * Adds a critical level message.
180
+ *
181
+ * Critical conditions.
182
+ * Example: Application component unavailable, unexpected exception.
183
+ *
184
+ * @see Cartflows_WC_Logger::log
185
+ *
186
+ * @param string $message Message to log.
187
+ * @param array $context Log context.
188
+ */
189
+ public function critical( $message, $context = array() ) {
190
+ $this->log( Cartflows_Log_Levels::CRITICAL, $message, $context );
191
+ }
192
+
193
+ /**
194
+ * Adds an error level message.
195
+ *
196
+ * Runtime errors that do not require immediate action but should typically be logged
197
+ * and monitored.
198
+ *
199
+ * @see Cartflows_WC_Logger::log
200
+ *
201
+ * @param string $message Message to log.
202
+ * @param array $context Log context.
203
+ */
204
+ public function error( $message, $context = array() ) {
205
+ $this->log( Cartflows_Log_Levels::ERROR, $message, $context );
206
+ }
207
+
208
+ /**
209
+ * Adds a warning level message.
210
+ *
211
+ * Exceptional occurrences that are not errors.
212
+ *
213
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not
214
+ * necessarily wrong.
215
+ *
216
+ * @see Cartflows_WC_Logger::log
217
+ *
218
+ * @param string $message Message to log.
219
+ * @param array $context Log context.
220
+ */
221
+ public function warning( $message, $context = array() ) {
222
+ $this->log( Cartflows_Log_Levels::WARNING, $message, $context );
223
+ }
224
+
225
+ /**
226
+ * Adds a notice level message.
227
+ *
228
+ * Normal but significant events.
229
+ *
230
+ * @see Cartflows_WC_Logger::log
231
+ *
232
+ * @param string $message Message to log.
233
+ * @param array $context Log context.
234
+ */
235
+ public function notice( $message, $context = array() ) {
236
+ $this->log( Cartflows_Log_Levels::NOTICE, $message, $context );
237
+ }
238
+
239
+ /**
240
+ * Adds a info level message.
241
+ *
242
+ * Interesting events.
243
+ * Example: User logs in, SQL logs.
244
+ *
245
+ * @see Cartflows_WC_Logger::log
246
+ *
247
+ * @param string $message Message to log.
248
+ * @param array $context Log context.
249
+ */
250
+ public function info( $message, $context = array() ) {
251
+ $this->log( Cartflows_Log_Levels::INFO, $message, $context );
252
+ }
253
+
254
+ /**
255
+ * Adds a debug level message.
256
+ *
257
+ * Detailed debug information.
258
+ *
259
+ * @see Cartflows_WC_Logger::log
260
+ *
261
+ * @param string $message Message to log.
262
+ * @param array $context Log context.
263
+ */
264
+ public function debug( $message, $context = array() ) {
265
+ $this->log( Cartflows_Log_Levels::DEBUG, $message, $context );
266
+ }
267
+
268
+ /**
269
+ * Clear entries for a chosen file/source.
270
+ *
271
+ * @param string $source Source/handle to clear.
272
+ * @return bool
273
+ */
274
+ public function clear( $source = '' ) {
275
+ if ( ! $source ) {
276
+ return false;
277
+ }
278
+ foreach ( $this->handlers as $handler ) {
279
+ if ( is_callable( array( $handler, 'clear' ) ) ) {
280
+ $handler->clear( $source );
281
+ }
282
+ }
283
+ return true;
284
+ }
285
+
286
+ /**
287
+ * Clear all logs older than a defined number of days. Defaults to 30 days.
288
+ *
289
+ * @since 3.4.0
290
+ */
291
+ public function clear_expired_logs() {
292
+ $days = absint( apply_filters( 'cartflows_logger_days_to_retain_logs', 30 ) );
293
+ $timestamp = strtotime( "-{$days} days" );
294
+
295
+ foreach ( $this->handlers as $handler ) {
296
+ if ( is_callable( array( $handler, 'delete_logs_before_timestamp' ) ) ) {
297
+ $handler->delete_logs_before_timestamp( $timestamp );
298
+ }
299
+ }
300
+ }
301
+ }
includes/admin/cartflows-error-log.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Page - Status Logs
4
+ *
5
+ * @package WooCommerce/Admin/Logs
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+
13
+
14
+ ?>
15
+ <?php if ( $logs ) : ?>
16
+ <div id="log-viewer-select">
17
+ <div class="alignright">
18
+ <form action="
19
+ <?php
20
+ echo esc_url(
21
+ add_query_arg(
22
+ array(
23
+ 'page' => 'cartflows_settings',
24
+ 'cartflows-error-log' => 1,
25
+ 'tab' => 'logs',
26
+ ),
27
+ admin_url( '/admin.php' )
28
+ )
29
+ );
30
+ ?>
31
+ " method="post">
32
+ <select name="log_file">
33
+ <?php foreach ( $logs as $log_key => $log_file ) : ?>
34
+ <?php
35
+ $timestamp = filemtime( CARTFLOWS_LOG_DIR . $log_file );
36
+ $date = sprintf( __( '%1$s at %2$s', 'cartflows' ), date_i18n( 'F j, Y', $timestamp ), date_i18n( 'g:i a', $timestamp ) ); // phpcs:ignore
37
+ ?>
38
+ <option value="<?php echo esc_attr( $log_key ); ?>" <?php selected( sanitize_title( $viewed_log ), $log_key ); ?>><?php echo esc_html( $log_file ); ?> (<?php echo esc_html( $date ); ?>)</option>
39
+ <?php endforeach; ?>
40
+ </select>
41
+ <button type="submit" class="button" value="<?php esc_attr_e( 'View', 'cartflows' ); ?>"><?php esc_html_e( 'View', 'cartflows' ); ?></button>
42
+ </form>
43
+ </div>
44
+ <div class="clear"></div>
45
+ </div>
46
+ <div id="log-viewer">
47
+ <div class="wcf-log-container">
48
+ <pre><?php echo esc_html( file_get_contents( CARTFLOWS_LOG_DIR . $viewed_log ) ); ?></pre>
49
+ </div>
50
+ <?php if ( ! empty( $viewed_log ) ) : ?>
51
+ <a onclick="return confirm('Are you sure to delete this log?');" style="float: right" href="
52
+ <?php
53
+ echo esc_url(
54
+ wp_nonce_url(
55
+ add_query_arg(
56
+ array(
57
+ 'handle' => sanitize_title( $viewed_log ),
58
+ 'tab' => 'logs',
59
+ )
60
+ ),
61
+ 'remove_log'
62
+ )
63
+ );
64
+ ?>
65
+ "><?php esc_html_e( 'Delete log', 'cartflows' ); ?></a>
66
+ <?php endif; ?>
67
+
68
+ </div>
69
+ <?php else : ?>
70
+ <div class="updated woocommerce-message inline"><p><?php esc_html_e( 'There are currently no logs to view.', 'cartflows' ); ?></p></div>
71
+ <?php endif; ?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: woocommerce, funnel builder, sales funnels
5
  Requires at least: 4.4
6
  Tested up to: 5.2
7
- Stable tag: 1.1.18
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -125,6 +125,13 @@ Glad you asked! CartFlows Pro is an optional add-on to CartFlows that adds addit
125
 
126
  == Changelog ==
127
 
 
 
 
 
 
 
 
128
  = Version 1.1.18 - Friday, 10th May 2019 =
129
  * Fix: Sometimes, Next step link was not working.
130
 
4
  Tags: woocommerce, funnel builder, sales funnels
5
  Requires at least: 4.4
6
  Tested up to: 5.2
7
+ Stable tag: 1.1.19
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
125
 
126
  == Changelog ==
127
 
128
+ = Version 1.1.19 - Tuesday, 4th June 2019 =
129
+ * New: WooCommerce dependency removed. Now, you can use CartFlows without WooCommerce.
130
+ * Improvement: Extra theme compatibility added.
131
+ * Improvement: Oxygen builder compatibility added.
132
+ * Fix: Floating Label issue with account fields. CSS updated.
133
+ * Fix: Remove product icon not visible in the admin area for entre theme.
134
+
135
  = Version 1.1.18 - Friday, 10th May 2019 =
136
  * Fix: Sometimes, Next step link was not working.
137