-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathorphan_notes.php
More file actions
executable file
·111 lines (85 loc) · 2.87 KB
/
orphan_notes.php
File metadata and controls
executable file
·111 lines (85 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/*
+----------------------------------------------------------------------+
| Copyright (c) 1997-2023 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net, so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Nuno Lopes <nlopess@php.net> |
+----------------------------------------------------------------------+
$Id$
*/
/*
* This script searches for orphan notes.
* You need a phpweb checkout with, at least,
* manual/en and backend/notes folders
*/
/* Configuration Options */
$manual_dir = 'manual/en';
$notes_dir = 'backend/notes';
/******* END of configurations *****/
/* Collect manual IDs */
function recurse_manual($dir) {
global $array;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..') {
$path = $dir.'/'.$file;
if(is_dir($path)) {
recurse_manual($path);
} else {
$array[substr(md5(substr($path, $GLOBALS['len'], -4)), 0, 16)] = 1;
}
}
}
closedir($dh);
}
}
/* Search for bogus notes IDs */
function recurse_notes($dir) {
global $array, $files, $notes;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..' && substr($file, -4) != '.bz2') {
$path = $dir.'/'.$file;
if(is_dir($path)) {
recurse_notes($path);
} else {
if(!isset($array[$file]) && $file != 'last-updated' && $file != 'sections') {
echo "file: $path\n";
$fp = fopen($path, "r");
while (!feof($fp)) {
$line = chop(fgets($fp, 12288));
if ($line == "") { continue; }
list($id, $sect, , , , ) = explode("|", $line);
++$notes;
if (!isset($done)) {
$done = 1;
echo "old ID: $sect\nNotes IDs: $id";
} else {
echo ", $id";
}
}
echo "\n\n";
++$files;
}
unset($done);
}
}
}
closedir($dh);
}
}
$array = array();
$len = strlen("$manual_dir/");
$files = $notes = 0;
recurse_manual($manual_dir);
recurse_notes($notes_dir);
echo "\nTotal files: $files\nTotal notes: $notes";
?>