GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Begin replacing MD5 and decouple admin-themes from checksums · forkdone/TextPatternCMS@7a38261

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • txp-checksums.php
  • README.md
  • textpattern
    • admin-themes
      • classic
        • checksums.txt
      • hiveneutral
        • checksums.txt
      • hive
        • checksums.txt
    • checksums.txt
    • include
      • txp_diag.php
    • lib
      • constants.php
      • txplib_admin.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/txp-checksums.php‎

Copy file name to clipboardExpand all lines: .github/txp-checksums.php
+79-29Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,96 @@
2626
}
2727

2828
if (empty($argv[1])) {
29-
die("usage: {$argv[0]} <txpath> [update|rebuild]\n");
29+
die("usage: {$argv[0]} <txpath> [all|core|admin-themes]\n");
3030
}
3131

32-
$action = empty($argv[2]) ? 'update' : $argv[2];
32+
$locs = empty($argv[2]) ? 'all' : $argv[2];
3333

3434
define('txpath', rtrim(realpath($argv[1]), '/'));
3535

3636
$event = '';
3737
$prefs['enable_xmlrpc_server'] = true;
38-
require_once(txpath . '/lib/constants.php');
39-
require_once(txpath . '/lib/txplib_misc.php');
40-
require_once(txpath . '/lib/txplib_admin.php');
38+
require_once(txpath.'/lib/constants.php');
39+
require_once(txpath.'/lib/txplib_misc.php');
40+
require_once(txpath.'/lib/txplib_admin.php');
41+
4142
$files = array();
42-
$destination = txpath . DS . 'checksums.txt';
43+
$fpattern = '/.*\.(?:php|js)$/';
44+
45+
if ($locs === 'all' || $locs === 'core') {
46+
$destination = txpath;
47+
48+
$files = files_to_checksum($destination, $fpattern);
49+
50+
// Append root and rpc files.
51+
$files = array_merge($files, glob(txpath.DS.'..'.DS.'*.php'));
52+
$files = array_merge($files, glob(txpath.DS.'..'.DS.'rpc'.DS.'*.php'));
53+
54+
// Remove setup and config-dist.php.
55+
$files = array_filter($files, function($e) { return (strpos($e, '/setup') === false); });
56+
$files = array_filter($files, function($e) { return (strpos($e, '/config-dist') === false); });
57+
58+
// Remove admin-themes because they're checksummed independently.
59+
$files = array_filter($files, function($e) { return (strpos($e, '/admin-themes') === false); });
4360

44-
switch ($action) {
45-
case 'update':
46-
$files = calculate_checksums();
47-
break;
48-
case 'rebuild':
49-
$files = files_to_checksum(txpath, '/.*\.(?:php|js)$/');
61+
// Output list.
62+
if ($files) {
63+
$files = prep_checksums($files);
64+
write_checksums($destination, $files);
65+
$files = calculate_checksums($files);
66+
write_checksums($destination, $files);
67+
echo "Checksums updated in ".$destination."\n";
68+
}
69+
}
70+
71+
if ($locs === 'all' || $locs === 'admin-themes') {
72+
$destination = txpath.DS.'admin-themes';
5073

51-
// Append root and rpc files.
52-
$files = array_merge($files, glob(txpath . DS . '..' . DS . '*.php'));
53-
$files = array_merge($files, glob(txpath . DS . '..' . DS . 'rpc' . DS . '*.php'));
74+
$iterator = new DirectoryIterator($destination);
75+
$themesInstalled = array();
76+
77+
foreach ($iterator as $fileinfo) {
78+
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
79+
$themesInstalled[] = $fileinfo->getFilename();
80+
}
81+
}
5482

55-
// Remove setup and config-dist.php.
56-
$files = array_filter($files, function($e) { return (strpos($e, '/setup') === false); });
57-
$files = array_filter($files, function($e) { return (strpos($e, '/config-dist') === false); });
83+
foreach ($themesInstalled as $themeName) {
84+
$endpoint = $destination.DS.$themeName;
85+
$files = files_to_checksum($endpoint, $fpattern);
5886

5987
// Output list.
6088
if ($files) {
61-
$files = array_map(function ($str) { return str_replace(txpath, '', $str . ": " . str_repeat('a', 32)); }, $files);
62-
file_put_contents($destination, implode(n, $files));
63-
$files = calculate_checksums();
89+
$files = prep_checksums($files);
90+
write_checksums($endpoint, $files);
91+
$files = calculate_checksums($files);
92+
write_checksums($endpoint, $files);
93+
echo "Checksums updated in ".$endpoint."\n";
6494
}
65-
break;
95+
}
96+
}
97+
98+
/**
99+
* Create a file list, including new matching files added to the repo
100+
*
101+
* @param [type] $dir [description]
102+
* @param [type] $files [description]
103+
* @return [type] [description]
104+
*/
105+
function prep_checksums($files)
106+
{
107+
return array_map(function ($str) { return str_replace(txpath, '', $str.": ".str_repeat('a', CHECKSUM_BYTES)); }, $files);
66108
}
67109

68-
if ($files) {
69-
file_put_contents($destination, implode(n, $files));
70-
echo "Checksums updated in " . $destination . ".\n";
110+
/**
111+
* Commit the passed list of checksummed $files (prepped or computed) to the $dir
112+
*
113+
* @param string $dir Destination directory for the checksums.txt file
114+
* @param string $files Checksummed files
115+
*/
116+
function write_checksums($dir, $files)
117+
{
118+
file_put_contents($dir.DS.'checksums.txt', implode(n, $files));
71119
}
72120

73121
/**
@@ -94,16 +142,18 @@ function files_to_checksum($folder, $pattern)
94142
}
95143

96144
/**
97-
* Recalculate checksums of all files in the destination file.
145+
* Recalculate checksums of all files in the destination folder.
98146
*
99147
* @return array List of files and their checksums
100148
*/
101-
function calculate_checksums()
149+
function calculate_checksums($filter = array())
102150
{
103151
$fileList = array();
104152

105-
foreach (check_file_integrity(INTEGRITY_MD5) as $file => $md5) {
106-
$fileList[] = "$file: $md5";
153+
foreach (check_file_integrity(INTEGRITY_HASH, true) as $file => $hash) {
154+
if (empty($filter) || preg_grep('/^' . preg_quote($file, '/') . ':/', $filter)) {
155+
$fileList[] = "$file: $hash";
156+
}
107157
}
108158

109159
return $fileList;
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Usage: `npm run txp-gitdist <version> [dest-dir]` (`dest-dir` defaults to a temp
126126

127127
```ShellSession
128128
npm run txp-index
129-
npm run txp-checksums
129+
npm run txp-checksums ./textpattern
130130
npm run txp-gitdist 1.2.3 ../my-dest-dir
131131
```
132132

Collapse file

‎textpattern/admin-themes/classic/checksums.txt‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/admin-themes/classic/classic.php: 51a357ed9cc97379dbec8d47cb429d747964cab2951abc70
Collapse file

‎textpattern/admin-themes/hive/checksums.txt‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/admin-themes/hive/hive.php: 87fa322e30b930e5973522645f732264b94e51e0ac05886f
2+
/admin-themes/hive/assets/js/autosize.js: a443b43bc89d5b153e3b396a7e47be86e31728231a0f2520
3+
/admin-themes/hive/assets/js/main.js: 6d3e72e69025f84d2b6a0abc5dcda677acf341029c3c0548
4+
/admin-themes/hive/assets/js/darkmode.js: 80f48c67e4a78adff48c38700ecf120c43d07d7a6a4900e7
Collapse file

‎textpattern/admin-themes/hiveneutral/checksums.txt‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/admin-themes/hiveneutral/hiveneutral.php: fcfc63550f01c16aae1e8c0c90b061444dc86eb3e251d124
2+
/admin-themes/hiveneutral/assets/js/autosize.js: a443b43bc89d5b153e3b396a7e47be86e31728231a0f2520
3+
/admin-themes/hiveneutral/assets/js/main.js: 6d3e72e69025f84d2b6a0abc5dcda677acf341029c3c0548
4+
/admin-themes/hiveneutral/assets/js/darkmode.js: 80f48c67e4a78adff48c38700ecf120c43d07d7a6a4900e7

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.