Skip to content

Commit 61a878c

Browse files
authored
Add a copy function for the SHA256 checksum (#1957)
1 parent a57c1f9 commit 61a878c

6 files changed

Lines changed: 64 additions & 19 deletions

File tree

include/layout.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ function site_footer(array $config = []): void
504504
require __DIR__ . "/footer.inc";
505505
}
506506

507+
function sha256_html(string $checksum): string
508+
{
509+
$checksum = htmlspecialchars($checksum, ENT_QUOTES, 'UTF-8');
510+
511+
return '<span class="sha256-row"><span class="sha256">' . $checksum . '</span><button type="button" class="sha256-copy" data-copy-text="' . $checksum . '" aria-label="Copy sha256 checksum">Copy</button></span>';
512+
}
513+
507514
function get_nav_items(): array {
508515
return [
509516
new NavItem(

include/version.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ function show_source_releases()
139139
<?php download_link($rel['filename'], $rel['filename']); ?>
140140
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
141141
<?php
142-
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
143-
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
142+
if (isset($rel['sha256'])) {
143+
echo sha256_html($rel['sha256']);
144+
}
144145
?>
145146
<?php if (isset($rel['note']) && $rel['note']): ?>
146147
<p>

js/common.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,18 @@ function applyTheme(theme) {
879879
}
880880

881881
applyTheme(savedTheme)
882+
883+
const downloads = document.querySelector('.downloads');
884+
downloads?.addEventListener('click', function (event) {
885+
var button = event.target.closest('.sha256-copy');
886+
if (!button || !navigator.clipboard) {
887+
return;
888+
}
889+
890+
navigator.clipboard.writeText(button.dataset.copyText).then(function () {
891+
button.textContent = 'Copied';
892+
setTimeout(function () {
893+
button.textContent = 'Copy';
894+
}, 1500);
895+
});
896+
});

pre-release-builds.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@
9797
<a href="<?php echo $file_info['path'] ?>"><?php echo "php-{$info['version']}.tar.{$file_type}"; ?></a>
9898
<span class="releasedate"><?php echo date('d M Y', strtotime($info['date'])); ?></span>
9999
<?php foreach ($QA_CHECKSUM_TYPES as $algo): ?>
100-
<span class="<?php echo $algo; ?>">
101100
<?php if (isset($file_info[$algo]) && strlen($file_info[$algo])) : ?>
102-
<?php echo $file_info[$algo]; ?>
101+
<?php echo sha256_html($file_info[$algo]); ?>
103102
<?php else: ?>
104103
<em><small>No checksum value available</small></em>)&nbsp;
105104
<?php endif; ?>
@@ -189,7 +188,7 @@
189188
}
190189

191190
if ($includeSha && $sha !== '') {
192-
$parts[] = '<span class="sha256">' . htmlspecialchars($sha, ENT_QUOTES, 'UTF-8') . '</span>';
191+
$parts[] = sha256_html($sha);
193192
}
194193

195194
return '<li>' . implode(' ', $parts) . '</li>';
@@ -311,4 +310,3 @@
311310

312311
<?php
313312
site_footer(['sidebar' => $SIDEBAR_DATA]);
314-

releases/index.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,8 @@ function mk_rel(int $major,
219219
echo " <li>\n";
220220
if (isset($src['filename'])) {
221221
download_link($src["filename"], $src["name"]); echo "<br>\n";
222-
$linebreak = '';
223-
foreach (['md5', 'sha256'] as $cs) {
224-
if (isset($src[$cs])) {
225-
echo $linebreak;
226-
echo "<span class=\"{$cs}sum\">{$cs}: {$src[$cs]}</span>\n";
227-
$linebreak = "<br/>";
228-
}
222+
if (isset($src['sha256'])) {
223+
echo sha256_html($src['sha256']), "\n";
229224
}
230225
} else {
231226
echo "<a href=\"{$src['link']}\">{$src['name']}</a>";

styles/theme-base.css

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,20 +783,49 @@ fieldset {
783783
.content-header .changelog {
784784
color:#369;
785785
}
786-
.content-box .md5sum, .content-box .sha256 {
786+
.content-box .sha256,
787+
.downloads .sha256 {
787788
display: block;
788789
font: normal 0.875rem/1.5rem "Fira Mono", "Source Code Pro", monospace;
789790
overflow: hidden;
790791
text-overflow: ellipsis;
791792
}
792-
.content-box .md5sum:before {
793-
content: "md5: ";
794-
font-family: var(--font-family-sans-serif);
795-
}
796-
.content-box .sha256:before {
793+
.content-box .sha256:before,
794+
.downloads .sha256:before {
797795
content: "sha256: ";
798796
font-family: var(--font-family-sans-serif);
799797
}
798+
.content-box .sha256-row,
799+
.downloads .sha256-row {
800+
display: flex;
801+
align-items: center;
802+
gap: 0.5rem;
803+
}
804+
.content-box .sha256-row .sha256,
805+
.downloads .sha256-row .sha256 {
806+
min-width: 0;
807+
}
808+
.content-box .sha256-copy,
809+
.downloads .sha256-copy {
810+
border: 1px solid var(--dark-blue-color);
811+
border-radius: 30px;
812+
background-color: var(--dark-blue-color);
813+
color: #fff;
814+
padding: 0.2rem 0.65rem;
815+
font-size: 0.75rem;
816+
line-height: 1rem;
817+
cursor: pointer;
818+
min-width: 4.25rem;
819+
text-align: center;
820+
white-space: nowrap;
821+
}
822+
.content-box .sha256-copy:hover,
823+
.content-box .sha256-copy:focus,
824+
.downloads .sha256-copy:hover,
825+
.downloads .sha256-copy:focus {
826+
border-color: var(--dark-magenta-color);
827+
background-color: var(--dark-magenta-color);
828+
}
800829
.content-box .releasedate {
801830
float: right;
802831
font-size: 0.9rem;

0 commit comments

Comments
 (0)