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 +53 -17 2.5.0trunk 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;
@@ -123,9 +126,8 @@
123 126 }
124 127
125 128 self::hook_footer();
126 129 }
127 -
128 130 function echo_on() {
129 131 $this->on();
130 132
131 133 $this->_echo = true;
@@ -319,8 +321,13 @@
319 321 global $wpdb;
320 322
321 323 $table = "{$wpdb->prefix}fs_logger";
322 324
325 + /**
326 + * Drop logging table in any case.
327 + */
328 + $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
329 +
323 330 if ( $is_on ) {
324 331 /**
325 332 * Create logging table.
326 333 *
@@ -328,9 +335,9 @@
328 335 * dbDelta must use KEY and not INDEX for indexes.
329 336 *
330 337 * @link https://core.trac.wordpress.org/ticket/2695
331 338 */
332 - $result = $wpdb->query( "CREATE TABLE {$table} (
339 + $result = $wpdb->query( "CREATE TABLE IF NOT EXISTS {$table} (
333 340 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
334 341 `process_id` INT UNSIGNED NOT NULL,
335 342 `user_name` VARCHAR(64) NOT NULL,
336 343 `logger` VARCHAR(128) NOT NULL,
@@ -347,17 +354,13 @@
347 354 KEY `process_id` (`process_id` ASC),
348 355 KEY `process_logger` (`process_id` ASC, `logger` ASC),
349 356 KEY `function` (`function` ASC),
350 357 KEY `type` (`type` ASC))" );
351 - } else {
352 - /**
353 - * Drop logging table.
354 - */
355 - $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
356 358 }
357 359
358 360 if ( false !== $result ) {
359 361 update_option( 'fs_storage_logger', ( $is_on ? 1 : 0 ) );
362 + self::$_isStorageLoggingOn = $is_on;
360 363 }
361 364
362 365 return ( false !== $result );
363 366 }
@@ -632,10 +635,20 @@
632 635 $limit = 10000,
633 636 $offset = 0,
634 637 $order = false
635 638 ) {
636 - global $wpdb;
639 + if ( empty( $filename ) ) {
640 + $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
641 + }
637 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 +
638 651 $query = self::build_db_logs_query(
639 652 $filters,
640 653 $limit,
641 654 $offset,
@@ -642,16 +655,8 @@
642 655 $order,
643 656 true
644 657 );
645 658
646 - $upload_dir = wp_upload_dir();
647 - if ( empty( $filename ) ) {
648 - $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
649 - }
650 - $filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";
651 -
652 - $query .= " INTO OUTFILE '{$filepath}' FIELDS TERMINATED BY '\t' ESCAPED BY '\\\\' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n'";
653 -
654 659 $columns = '';
655 660 for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
656 661 if ( $i > 0 ) {
657 662 $columns .= ', ';
@@ -661,14 +666,18 @@
661 666 }
662 667
663 668 $query = "SELECT {$columns} UNION ALL " . $query;
664 669
665 - $result = $wpdb->query( $query );
670 + $result = $GLOBALS['wpdb']->get_results( $query );
666 671
667 672 if ( false === $result ) {
668 673 return false;
669 674 }
670 675
676 + if ( ! self::write_csv_to_filesystem( $filepath, $result ) ) {
677 + return false;
678 + }
679 +
671 680 return rtrim( $upload_dir['url'], '/' ) . '/' . $filename;
672 681 }
673 682
674 683 /**
@@ -685,8 +694,35 @@
685 694 $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
686 695 }
687 696
688 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;
689 725 }
690 726
691 727 #endregion
692 728 }