PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / trunk
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites vtrunk
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
← All changes | freemius/includes/class-fs-logger.php +55 -18 2.1.2trunk View file →
@@ -31,8 +31,11 @@
31 31 * @var int ABSPATH length.
32 32 */
33 33 private static $_abspathLength;
34 34
35 + /**
36 + * @var FS_Logger[] $LOGGERS
37 + */
35 38 private static $LOGGERS = array();
36 39 private static $LOG = array();
37 40 private static $CNT = 0;
38 41 private static $_HOOKED_FOOTER = false;
@@ -37,11 +40,12 @@
37 40 private static $CNT = 0;
38 41 private static $_HOOKED_FOOTER = false;
39 42
40 43 private function __construct( $id, $on = false, $echo = false ) {
44 + $bt = debug_backtrace();
45 +
41 46 $this->_id = $id;
42 47
43 - $bt = debug_backtrace();
44 48 $caller = $bt[2];
45 49
46 50 if ( false !== strpos( $caller['file'], 'plugins' ) ) {
47 51 $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
@@ -122,9 +126,8 @@
122 126 }
123 127
124 128 self::hook_footer();
125 129 }
126 -
127 130 function echo_on() {
128 131 $this->on();
129 132
130 133 $this->_echo = true;
@@ -318,8 +321,13 @@
318 321 global $wpdb;
319 322
320 323 $table = "{$wpdb->prefix}fs_logger";
321 324
325 + /**
326 + * Drop logging table in any case.
327 + */
328 + $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
329 +
322 330 if ( $is_on ) {
323 331 /**
324 332 * Create logging table.
325 333 *
@@ -327,9 +335,9 @@
327 335 * dbDelta must use KEY and not INDEX for indexes.
328 336 *
329 337 * @link https://core.trac.wordpress.org/ticket/2695
330 338 */
331 - $result = $wpdb->query( "CREATE TABLE {$table} (
339 + $result = $wpdb->query( "CREATE TABLE IF NOT EXISTS {$table} (
332 340 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
333 341 `process_id` INT UNSIGNED NOT NULL,
334 342 `user_name` VARCHAR(64) NOT NULL,
335 343 `logger` VARCHAR(128) NOT NULL,
@@ -346,17 +354,13 @@
346 354 KEY `process_id` (`process_id` ASC),
347 355 KEY `process_logger` (`process_id` ASC, `logger` ASC),
348 356 KEY `function` (`function` ASC),
349 357 KEY `type` (`type` ASC))" );
350 - } else {
351 - /**
352 - * Drop logging table.
353 - */
354 - $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
355 358 }
356 359
357 360 if ( false !== $result ) {
358 361 update_option( 'fs_storage_logger', ( $is_on ? 1 : 0 ) );
362 + self::$_isStorageLoggingOn = $is_on;
359 363 }
360 364
361 365 return ( false !== $result );
362 366 }
@@ -631,10 +635,20 @@
631 635 $limit = 10000,
632 636 $offset = 0,
633 637 $order = false
634 638 ) {
635 - global $wpdb;
639 + if ( empty( $filename ) ) {
640 + $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
641 + }
636 642
643 + $upload_dir = wp_upload_dir();
644 + $filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";
645 +
646 + WP_Filesystem();
647 + if ( ! $GLOBALS['wp_filesystem']->is_writable( dirname( $filepath ) ) ) {
648 + return false;
649 + }
650 +
637 651 $query = self::build_db_logs_query(
638 652 $filters,
639 653 $limit,
640 654 $offset,
@@ -641,16 +655,8 @@
641 655 $order,
642 656 true
643 657 );
644 658
645 - $upload_dir = wp_upload_dir();
646 - if ( empty( $filename ) ) {
647 - $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
648 - }
649 - $filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";
650 -
651 - $query .= " INTO OUTFILE '{$filepath}' FIELDS TERMINATED BY '\t' ESCAPED BY '\\\\' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n'";
652 -
653 659 $columns = '';
654 660 for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
655 661 if ( $i > 0 ) {
656 662 $columns .= ', ';
@@ -660,14 +666,18 @@
660 666 }
661 667
662 668 $query = "SELECT {$columns} UNION ALL " . $query;
663 669
664 - $result = $wpdb->query( $query );
670 + $result = $GLOBALS['wpdb']->get_results( $query );
665 671
666 672 if ( false === $result ) {
667 673 return false;
668 674 }
669 675
676 + if ( ! self::write_csv_to_filesystem( $filepath, $result ) ) {
677 + return false;
678 + }
679 +
670 680 return rtrim( $upload_dir['url'], '/' ) . '/' . $filename;
671 681 }
672 682
673 683 /**
@@ -684,8 +694,35 @@
684 694 $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
685 695 }
686 696
687 697 return rtrim( $upload_dir['url'], '/' ) . $filename;
698 + }
699 +
700 + /**
701 + * @param string $file_path
702 + * @param array $query_results
703 + *
704 + * @return bool
705 + */
706 + private static function write_csv_to_filesystem( $file_path, $query_results ) {
707 + if ( empty( $query_results ) ) {
708 + return false;
709 + }
710 +
711 + $content = '';
712 +
713 + foreach ( $query_results as $row ) {
714 + $row_data = array_map( function ( $value ) {
715 + return str_replace( "\n", ' ', $value );
716 + }, (array) $row );
717 + $content .= implode( "\t", $row_data ) . "\n";
718 + }
719 +
720 + if ( ! $GLOBALS['wp_filesystem']->put_contents( $file_path, $content, FS_CHMOD_FILE ) ) {
721 + return false;
722 + }
723 +
724 + return true;
688 725 }
689 726
690 727 #endregion
691 728 }