Skip to content

Commit 008be06

Browse files
Click to copy Log (#804)
* Add Click to copy logs * Filter for logs max line * Replace esc_html_* functions
1 parent c6573c9 commit 008be06

File tree

5 files changed

+53
-24
lines changed

5 files changed

+53
-24
lines changed

assets/js/litespeed-cache-admin.js

+9
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,12 @@ function litespeed_add_zero(i) {
581581
}
582582
return i;
583583
}
584+
585+
function litespeed_copy_to_clipboard(elementId) {
586+
var range = document.createRange();
587+
range.selectNode(document.getElementById(elementId));
588+
window.getSelection().removeAllRanges();
589+
window.getSelection().addRange(range);
590+
document.execCommand('copy');
591+
window.getSelection().removeAllRanges();
592+
}

src/doc.cls.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public static function queue_issues($return = false)
174174
{
175175
$str =
176176
'<div class="litespeed-desc">' .
177-
esc_html__('The queue is processed asynchronously. It may take time.', 'litespeed-cache') .
177+
__('The queue is processed asynchronously. It may take time.', 'litespeed-cache') .
178178
self::learn_more('https://docs.litespeedtech.com/lscache/lscwp/troubleshoot/#quiccloud-queue-issues', false, false, false, true) .
179179
'</div>';
180180
if ($return) {

thirdparty/litespeed-check.cls.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function detect()
7171
'<div ' .
7272
self::$_msg_id .
7373
'>' .
74-
esc_html__('Please consider disabling the following detected plugins, as they may conflict with LiteSpeed Cache:', 'litespeed-cache') .
74+
__('Please consider disabling the following detected plugins, as they may conflict with LiteSpeed Cache:', 'litespeed-cache') .
7575
'<p style="color: red; font-weight: 700;">' .
7676
'PageSpeed Ninja' .
7777
'</p>' .
@@ -122,7 +122,7 @@ public static function incompatible_plugin_notice($plugin, $_network_wide, $acti
122122
'<div ' .
123123
self::$_msg_id .
124124
'>' .
125-
esc_html__('Please consider disabling the following detected plugins, as they may conflict with LiteSpeed Cache:', 'litespeed-cache') .
125+
__('Please consider disabling the following detected plugins, as they may conflict with LiteSpeed Cache:', 'litespeed-cache') .
126126
'<p style="color: red; font-weight: 700;">' .
127127
implode(', ', $active_incompatible_plugins) .
128128
'</p>' .

tpl/presets/standard.tpl.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@
8484
?>
8585

8686
<h3 class="litespeed-title-short">
87-
<?php esc_html_e( 'LiteSpeed Cache Standard Presets', 'litespeed-cache' ); ?>
87+
<?php _e( 'LiteSpeed Cache Standard Presets', 'litespeed-cache' ); ?>
8888
<?php Doc::learn_more( 'https://docs.litespeedtech.com/lscache/lscwp/presets/#standard-tab' ); ?>
8989
</h3>
9090

91-
<p><?php esc_html_e( 'Use an official LiteSpeed-designed Preset to configure your site in one click. Try no-risk caching essentials, extreme optimization, or something in between.', 'litespeed-cache' ); ?></p>
91+
<p><?php _e( 'Use an official LiteSpeed-designed Preset to configure your site in one click. Try no-risk caching essentials, extreme optimization, or something in between.', 'litespeed-cache' ); ?></p>
9292

9393
<div class="litespeed-comparison-cards">
9494
<?php
@@ -113,7 +113,7 @@
113113
</ul>
114114
</div>
115115
<div class="litespeed-card-footer">
116-
<h4><?php esc_html_e( 'Who should use this preset?', 'litespeed-cache' ); ?></h4>
116+
<h4><?php _e( 'Who should use this preset?', 'litespeed-cache' ); ?></h4>
117117
<?php foreach ( $presets[ $name ]['footer'] as $line ) : ?>
118118
<p><?php echo esc_html( $line ); ?></p>
119119
<?php endforeach; ?>
@@ -123,9 +123,9 @@
123123
<a
124124
href="<?php echo Utility::build_url( Router::ACTION_PRESET, Preset::TYPE_APPLY, false, null, array( 'preset' => $name ) ); ?>"
125125
class="button <?php echo $button_class; ?>"
126-
data-litespeed-cfm="<?php printf( esc_html__( 'This will back up your current settings and replace them with the %1$s preset settings. Do you want to continue?', 'litespeed-cache' ), $title ); ?>"
126+
data-litespeed-cfm="<?php printf( __( 'This will back up your current settings and replace them with the %1$s preset settings. Do you want to continue?', 'litespeed-cache' ), $title ); ?>"
127127
>
128-
<?php esc_html_e( 'Apply Preset', 'litespeed-cache' ); ?>
128+
<?php _e( 'Apply Preset', 'litespeed-cache' ); ?>
129129
</a>
130130
</div>
131131
</div>
@@ -155,7 +155,7 @@ class="button <?php echo $button_class; ?>"
155155
if ( ! empty( $summary['preset'] ) || ! empty( $backups ) ) :
156156
?>
157157
<h3 class="litespeed-title-short">
158-
<?php esc_html_e( 'History', 'litespeed-cache' ); ?>
158+
<?php _e( 'History', 'litespeed-cache' ); ?>
159159
</h3>
160160
<?php endif; ?>
161161

@@ -165,12 +165,12 @@ class="button <?php echo $button_class; ?>"
165165
$name = strtolower( $summary['preset'] );
166166
$time = trim( Utility::readable_time( $summary['preset_timestamp'] ) );
167167
if ( 'error' === $name ) {
168-
printf( esc_html__( 'Error: Failed to apply the settings %1$s', 'litespeed-cache' ), $time );
168+
printf( __( 'Error: Failed to apply the settings %1$s', 'litespeed-cache' ), $time );
169169
} elseif ( 'backup' === $name ) {
170-
printf( esc_html__( 'Restored backup settings %1$s', 'litespeed-cache' ), $time );
170+
printf( __( 'Restored backup settings %1$s', 'litespeed-cache' ), $time );
171171
} else {
172172
printf(
173-
esc_html__( 'Applied the %1$s preset %2$s', 'litespeed-cache' ),
173+
__( 'Applied the %1$s preset %2$s', 'litespeed-cache' ),
174174
'<strong>' . esc_html( $presets[ $name ]['title'] ) . '</strong>',
175175
$time
176176
);
@@ -181,13 +181,13 @@ class="button <?php echo $button_class; ?>"
181181

182182
<?php foreach ( $backups as $backup ) : ?>
183183
<p>
184-
<?php printf( esc_html__( 'Backup created %1$s before applying the %2$s preset', 'litespeed-cache' ), $backup['time'], $backup['title'] ); ?>
184+
<?php printf( __( 'Backup created %1$s before applying the %2$s preset', 'litespeed-cache' ), $backup['time'], $backup['title'] ); ?>
185185
<a
186186
href="<?php echo Utility::build_url( Router::ACTION_PRESET, Preset::TYPE_RESTORE, false, null, array( 'timestamp' => $backup['timestamp'] ) ); ?>"
187187
class="litespeed-left10"
188-
data-litespeed-cfm="<?php printf( esc_html__( 'This will restore the backup settings created %1$s before applying the %2$s preset. Any changes made since then will be lost. Do you want to continue?', 'litespeed-cache' ), $backup['time'], $backup['title'] ); ?>"
188+
data-litespeed-cfm="<?php printf( __( 'This will restore the backup settings created %1$s before applying the %2$s preset. Any changes made since then will be lost. Do you want to continue?', 'litespeed-cache' ), $backup['time'], $backup['title'] ); ?>"
189189
>
190-
<?php esc_html_e( 'Restore Settings', 'litespeed-cache' ); ?>
190+
<?php _e( 'Restore Settings', 'litespeed-cache' ); ?>
191191
</a>
192192
</p>
193193
<?php

tpl/toolbox/log_viewer.tpl.php

+29-9
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
array(
99
array(
1010
'name' => 'debug',
11-
'label' => esc_html__('Debug Log', 'litespeed-cache'),
11+
'label' => __('Debug Log', 'litespeed-cache'),
1212
'accesskey' => 'A',
1313
),
1414
array(
1515
'name' => 'purge',
16-
'label' => esc_html__('Purge Log', 'litespeed-cache'),
16+
'label' => __('Purge Log', 'litespeed-cache'),
1717
'accesskey' => 'B',
1818
),
1919
array(
2020
'name' => 'crawler',
21-
'label' => esc_html__('Crawler Log', 'litespeed-cache'),
21+
'label' => __('Crawler Log', 'litespeed-cache'),
2222
'accesskey' => 'C',
2323
),
2424
);
@@ -48,7 +48,9 @@ function subnav_link($item)
4848
: '';
4949
$label = isset($item['label']) ? $item['label'] : $item['name'];
5050

51-
return "<a href='{$url}' class='{$class}' {$subtab} {$accesskey}>{$label}</a>";
51+
$on_click = isset($item['onClick']) ? ' onClick="' . $item['onClick'].'"' : '';
52+
53+
return "<a href='{$url}' class='{$class}' {$subtab} {$accesskey} {$on_click}>{$label}</a>";
5254
}
5355

5456
/**
@@ -59,7 +61,7 @@ function clear_logs_link($accesskey = null)
5961
{
6062
$item =
6163
array(
62-
'label' => esc_html__('Clear Logs', 'litespeed-cache'),
64+
'label' => __('Clear Logs', 'litespeed-cache'),
6365
'url' => Utility::build_url(Router::ACTION_DEBUG2, Debug2::TYPE_CLEAR_LOG),
6466
);
6567
if (null !== $accesskey) {
@@ -68,6 +70,21 @@ function clear_logs_link($accesskey = null)
6870
echo subnav_link($item);
6971
}
7072

73+
/**
74+
* Print a button to copy current log
75+
* @since 7.0
76+
*/
77+
function copy_logs_link($id_to_copy)
78+
{
79+
$item = array(
80+
'name' => 'copy_links',
81+
'label' => __('Copy Log', 'litespeed-cache'),
82+
'cssClass' => 'litespeed-info-button',
83+
'onClick' => "litespeed_copy_to_clipboard('".$id_to_copy."')"
84+
);
85+
return subnav_link($item);
86+
}
87+
7188
$subnav_links = array();
7289
$log_views = array();
7390

@@ -76,22 +93,25 @@ function clear_logs_link($accesskey = null)
7693

7794
$file = $this->cls('Debug2')->path($log['name']);
7895
$lines = File::count_lines($file);
79-
$start = $lines > 1000 ? $lines - 1000 : 0;
96+
$max_lines = apply_filters('litespeed_debug_show_max_lines', 1000);
97+
$start = $lines > $max_lines ? $lines - $max_lines : 0;
8098
$lines = File::read($file, $start);
8199
$lines = $lines ? trim(implode("\n", $lines)) : '';
100+
101+
$log_body_id = 'litespeed-log-' . $log['name'];
82102

83103
$log_views[] =
84104
"<div class='litespeed-log-view-wrapper' data-litespeed-sublayout='{$log['name']}_log'>"
85-
. "<h3 class='litespeed-title'>{$log['label']}</h3>"
86-
. '<div class="litespeed-log-body">'
105+
. "<h3 class='litespeed-title'>{$log['label']}" . copy_logs_link($log_body_id) ."</h3>"
106+
. '<div class="litespeed-log-body" id="' . $log_body_id . '">'
87107
. nl2br(htmlspecialchars($lines))
88108
. '</div>'
89109
. '</div>';
90110
}
91111
?>
92112

93113
<h3 class="litespeed-title">
94-
<?php esc_html_e('LiteSpeed Logs', 'litespeed-cache'); ?>
114+
<?php _e('LiteSpeed Logs', 'litespeed-cache'); ?>
95115
<?php Doc::learn_more('https://docs.litespeedtech.com/lscache/lscwp/toolbox/#log-view-tab'); ?>
96116
</h3>
97117

0 commit comments

Comments
 (0)