-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcredits.php
75 lines (63 loc) · 2.67 KB
/
credits.php
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
<?php
$relPath="./pinc/";
include_once($relPath.'base.inc');
include_once($relPath.'theme.inc');
$title = _("Credits");
output_header($title);
echo "<h1>$title</h1>";
echo "<p>" . sprintf(_("This site is powered by the <a href='%s'>dproofreaders</a> source code and licensed under the GPL v2."), "https://github.com/DistributedProofreaders/dproofreaders") . "</p>";
echo "<h2>" . _("Developers") . "</h2>";
echo "<p>" . sprintf(_("This software brought to you by many volunteer developers across the world over many years. Recent developer contributions after the move to git can be seen on the project's <a href='%s'>Github Contributors page</a>."), "https://github.com/DistributedProofreaders/dproofreaders/graphs/contributors"). "</p>";
echo "<h2>" . _("Bundled Software"). "</h2>";
echo "<p>" . _("The following open source code is bundled and used with the dproofreaders code.") . "</p>";
$credit_details = load_credit_details($code_dir);
asort($credit_details);
echo "<ul>";
foreach($credit_details as $detail)
{
echo "<li>";
echo "<b>" . $detail["name"] . "</b><br>";
echo "<a href='" . $detail["url"] . "'>" . $detail["url"] . "</a><br>";
echo "<a href='" . $detail["license_url"] . "'>" . $detail["license"] . "</a>";
echo "</li>";
}
echo "</ul>";
#----------------------------------------------------------------------------
function load_credit_details($code_dir)
{
$credit_details = [];
$dir_iter = new PermissiveRecursiveDirectoryIterator($code_dir);
$files = new RecursiveIteratorIterator($dir_iter);
foreach($files as $file_info)
{
$file = $file_info->getPathname();
if(basename($file) != "details.json")
continue;
$details = json_decode(file_get_contents($file), TRUE);
if(isAssoc($details))
$details = [ $details ];
foreach($details as $detail)
{
$credit_details[$detail["name"]] = $detail;
}
}
return $credit_details;
}
# Ignore exceptions when iterating over the directory, such as permission
# errors from SETUP/
# from antennen at https://www.php.net/manual/en/class.recursivedirectoryiterator.php
class PermissiveRecursiveDirectoryIterator extends RecursiveDirectoryIterator {
function getChildren() {
try {
return new PermissiveRecursiveDirectoryIterator($this->getPathname());
} catch(UnexpectedValueException $e) {
return new RecursiveArrayIterator(array());
}
}
}
# https://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
function isAssoc(array $arr)
{
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
}