forked from DistributedProofreaders/dproofreaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharsuites.php
209 lines (189 loc) · 7.39 KB
/
charsuites.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
$relPath = '../pinc/';
include_once($relPath."base.inc");
include_once($relPath."theme.inc");
include_once($relPath."unicode.inc");
include_once($relPath."CharSuites.inc");
include_once($relPath."prefs_options.inc");
include_once($relPath."Project.inc"); // get_projectID_param()
require_login();
$charsuite_name = $_GET["charsuite"] ?? null;
$projectid = get_projectID_param($_REQUEST, "projectid", true);
$charsuite = null;
if ($charsuite_name && !$projectid) {
try {
$charsuite = CharSuites::get($charsuite_name);
} catch (UnexpectedValueException $e) {
// try loading the suite as though it were a project id
// for a custom project suite
try {
$project = new Project($charsuite_name);
$charsuite = $project->get_custom_charsuite();
} catch (NonexistentProjectException $e) {
// continue
}
// continue
}
}
[, , $font_family, ] = get_user_proofreading_font();
$extra_args['css_data'] = ".gs-char { font-family: $font_family; }";
if ($charsuite) {
$title = _("Character Suite");
output_header($title, NO_STATSBAR, $extra_args);
echo "<h1>" . html_safe($title) . "</h1>";
echo "<p><a href='?'>" . _("View all character suites") . "</a></p>";
echo "<p>";
echo _("Below are all the characters with their Unicode codepoints that are available within this character suite.");
echo " ";
echo _("Hovering over a character will show its Unicode name in a tooltip.");
echo "</p>";
output_charsuite($charsuite, true);
output_pickerset($charsuite->pickerset, $charsuite->codepoints);
} elseif ($projectid) {
$project = new Project($projectid);
$title = _("Project Character Suites");
output_header($title, NO_STATSBAR, $extra_args);
echo "<h1>" . html_safe($title) . "</h1>";
echo "<p>" . sprintf(
_("Character Suites for <a href='%s'>%s</a>."),
"$code_url/project.php?id=$projectid",
html_safe($project->nameofwork)
) . "</p>";
$charsuites = $project->get_charsuites();
foreach ($charsuites as $charsuite) {
output_charsuite($charsuite);
}
} else {
$title = _("All Character Suites");
output_header($title, NO_STATSBAR, $extra_args);
echo "<h1>" . html_safe($title) . "</h1>";
echo "<p>";
echo _("Below are all enabled character suites in the system.");
echo " ";
echo _("Hovering over a character will show its Unicode name in a tooltip.");
echo "</p>";
$enabled_charsuites = CharSuites::get_enabled();
foreach ($enabled_charsuites as $charsuite) {
output_charsuite($charsuite);
}
$all_charsuites = CharSuites::get_all();
if (count($all_charsuites) > count($enabled_charsuites)) {
echo "<h1>" . _("Disabled Character Suites") . "</h1>";
echo "<p>" . _("The following character suites are installed but not enabled and cannot be used for new projects. They may not be finalized.") . "</p>";
foreach ($all_charsuites as $charsuite) {
if (!$charsuite->is_enabled()) {
output_charsuite($charsuite);
}
}
}
}
//----------------------------------------------------------------------------
function output_charsuite(CharSuite $charsuite, bool $show_detail = false): void
{
$slug = utf8_url_slug($charsuite->title);
echo "<h2 id='$slug'>" . html_safe($charsuite->title) . "</h2>";
if ($charsuite->description) {
echo "<p>" . html_safe($charsuite->description) . "</p>";
}
if (!$show_detail) {
$encoded_name = urlencode($charsuite->name);
echo "<p><a href='?charsuite=$encoded_name'>" . _("View character suite details") . "</a></p>";
} elseif (!$charsuite->is_enabled()) {
echo "<p class='warning'>". _("This character suite is installed but not enabled and cannot be used for new projects.") . "</p>";
}
$characters = convert_codepoint_ranges_to_characters($charsuite->codepoints);
output_characters_table($characters);
if ($show_detail && $charsuite->reference_urls) {
echo "<p>" . _("Reference URLs") . ":";
echo "<ul>";
foreach ($charsuite->reference_urls as $url) {
echo "<li><a href='$url'>$url</a></li>";
}
echo "</ul>";
echo "</p>";
}
}
/** @param string[] $all_codepoints */
function output_pickerset(?PickerSet $pickerset, array $all_codepoints): void
{
echo "<h2>" . _("Character Picker Sets") . "</h2>";
if (!$pickerset) {
echo "<p>" . _("No picker set is defined for this character suite.") . "</p>";
return;
}
echo "<p>" . _("The following groupings represent sets of characters available in the character picker within the proofreading interface for projects using this character suite. Each grouping is labeled by a one- to four-character string that is used for the grouping's menu within the character picker.") . "</p>";
$set = $pickerset->get_subsets();
$picker_characters = [];
foreach ($set as $menu => $coderows) {
$header = $menu;
$title = $pickerset->get_title($menu);
if ($menu != $title) {
$header .= " - $title";
}
// first the menu item
echo "<h3>" . html_safe($header) . "</h3>";
// now the picker rows
echo "<table class='basic'>";
foreach ($coderows as $row) {
echo "<tr>";
$characters = convert_codepoint_ranges_to_characters($row);
$picker_characters = array_merge($picker_characters, $characters);
output_characters_slice($characters);
echo "</tr>";
}
echo "</table>";
}
$all_characters = convert_codepoint_ranges_to_characters($all_codepoints);
$remainder = array_diff($all_characters, array_unique($picker_characters));
if (count($all_characters) != count(array_unique($picker_characters)) && $remainder) {
echo "<h3>" . _("Characters not in a picker set") . "</h3>";
echo "<table class='basic'>";
echo "<tr>";
output_characters_table($remainder);
echo "</tr>";
echo "</table>";
}
}
/** @param string[] $characters */
function output_characters_table(array $characters, int $table_width = 16): void
{
// maximum number of codepoints to output
$MAX_CODEPOINTS = 2048;
echo "<table class='basic'>";
$offset = 0;
while (($slice = array_slice($characters, $offset, $table_width)) &&
$offset < $MAX_CODEPOINTS) {
echo "<tr>";
output_characters_slice($slice);
echo "</tr>";
$offset += $table_width;
}
echo "</table>";
if ($offset >= $MAX_CODEPOINTS) {
echo "<p class='warning'>";
echo sprintf(
_("Only %1\$s of %2\$s codepoints printed."),
$offset,
count($characters)
);
echo "</p>";
}
}
/** @param (string|null)[] $slice */
function output_characters_slice(array $slice): void
{
foreach ($slice as $char) {
if ($char !== null) {
$title = attr_safe(utf8_character_name($char));
$codepoint = string_to_codepoints_string($char, "<br>");
$char = html_safe($char);
echo "<td class='center-align' title='$title'>";
echo "<span class='gs-char'>$char</span><br>";
echo "<span class='gs-codepoint'>$codepoint</span>";
echo "</td>";
} else {
// this is just a placeholder
echo "<td></td>";
}
}
}