summaryrefslogtreecommitdiff
path: root/pages/prefix.inc
diff options
context:
space:
mode:
Diffstat (limited to 'pages/prefix.inc')
-rw-r--r--pages/prefix.inc451
1 files changed, 451 insertions, 0 deletions
diff --git a/pages/prefix.inc b/pages/prefix.inc
new file mode 100644
index 0000000..d7d8a40
--- /dev/null
+++ b/pages/prefix.inc
@@ -0,0 +1,451 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
+
+?>
+
+<br>
+<div class="container">
+ <div id="page-content">
+ <h2>Prefix generator</h2>
+ <p>This prefix generator will take into account the prefixes from the existing members to try to generate new original prefixes for a potential new member.</p>
+
+ <div style="display:grid;grid-template-columns:1fr 1fr 1fr;grid-gap:10px;">
+ <select id="system" title="Existing prefixes from..." class="tooltip-nohelp form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns=&apos;http://www.w3.org/2000/svg&apos; viewBox=&apos;0 0 16 16&apos;%3e%3cpath fill=&apos;none&apos; stroke=&apos;%23ffffff&apos; stroke-linecap=&apos;round&apos; stroke-linejoin=&apos;round&apos; stroke-width=&apos;2&apos; d=&apos;M2 5l6 6 6-6&apos;/%3e%3c/svg%3e");' onchange="update();">
+ <optgroup label="General Options">
+ <option value="all">All systems</option>
+ <option value="none">Ignore existing prefixes</option>
+ </optgroup>
+ <optgroup label="Individual Systems">
+ <option value="cloudburst">Cloudburst System</option>
+ <option value="raindrops">Raindrops System</option>
+ </optgroup>
+ </select>
+ <input title="First Name" type="text" class="tooltip-nohelp form-control" id="first-name" placeholder="First Name" style="color:white;background:#111;border-color:#222;" onchange="update();" onkeydown="update();" onkeyup="update();">
+ <input title="Last Name" type="text" class="tooltip-nohelp form-control" id="last-name" placeholder="Last Name (optional)" style="color:white;background:#111;border-color:#222;" onchange="update();" onkeydown="update();" onkeyup="update();">
+ </div>
+
+ <br>
+ <div id="already" class="alert alert-primary" style="display:none;">
+ There is already a member named <b id="already-name">Name</b> in one of the systems, their primary prefix is currently <code id="already-prefix">???</code>
+ </div>
+ <div id="results-singular" style="display:none;">
+ <h4>Generated Prefix</h4>
+ <p>Below is a generated prefix for a member who goes by the entered name. We managed to generate only a single prefix for this name.</p>
+ </div>
+ <div id="results-none">
+ <h4>Generated Prefix</h4>
+ <p>We couldn't generate a prefix for a member who goes by this name, try tuning your settings.</p>
+ </div>
+ <div id="results-plural" style="display:none;">
+ <h4>Generated Prefixes</h4>
+ <p>Below is a list of generated prefixes for a member who goes by the entered name. The prefixes are ordered by relevance, the first prefix being the most relevant one. Hover over a prefix to see what makes it revelent or not</p>
+ </div>
+ <ol id="generated">
+ <li><code>{...}</code></li>
+ </ol>
+ <p id="hidden-message" style="display:none;"><span id="hidden-count">0</span> <span id="hidden-plural">entries have been hidden because they are existing prefixes </span><span id="hidden-singular">entry has been hidden because it is an existing prefix </span>in the selected system<span id="hidden-sys-plural">s</span>.</p>
+ </div>
+
+ <script>
+ let existing = <?php
+
+ $existing1 = [];
+ foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true) as $member) {
+ if ($member["name"] !== "unknown") {
+ foreach ($member['proxy_tags'] as $tag) {
+ if (!$tag["prefix"]) {
+ $existing1[] = "..." . $tag["suffix"];
+ } else if (!$tag["suffix"]) {
+ $existing1[] = $tag["prefix"];
+ } else {
+ $existing1[] = $tag["prefix"] . "..." . $tag["suffix"];
+ }
+ }
+ }
+ }
+
+
+ $existing2 = [];
+ foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true) as $member) {
+ if ($member["name"] !== "unknown") {
+ foreach ($member['proxy_tags'] as $tag) {
+ if (!$tag["prefix"]) {
+ $existing2[] = "..." . $tag["suffix"];
+ } else if (!$tag["suffix"]) {
+ $existing2[] = $tag["prefix"];
+ } else {
+ $existing2[] = $tag["prefix"] . "..." . $tag["suffix"];
+ }
+ }
+ }
+ }
+
+ echo(json_encode([
+ "cloudburst" => $existing1,
+ "raindrops" => $existing2
+ ]));
+
+ ?>;
+
+ let prefixesUsedBy = <?php
+
+ $existing1 = [];
+ foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true) as $member) {
+ if ($member["name"] !== "unknown") {
+ foreach ($member['proxy_tags'] as $tag) {
+ if (!$tag["prefix"]) {
+ $existing1["..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
+ } else if (!$tag["suffix"]) {
+ $existing1[$tag["prefix"]] = $member["display_name"] ?? $member["name"];
+ } else {
+ $existing1[$tag["prefix"] . "..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
+ }
+ }
+ }
+ }
+
+
+ $existing2 = [];
+ foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true) as $member) {
+ if ($member["name"] !== "unknown") {
+ foreach ($member['proxy_tags'] as $tag) {
+ if (!$tag["prefix"]) {
+ $existing2["..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
+ } else if (!$tag["suffix"]) {
+ $existing2[$tag["prefix"]] = $member["display_name"] ?? $member["name"];
+ } else {
+ $existing2[$tag["prefix"] . "..." . $tag["suffix"]] = $member["display_name"] ?? $member["name"];
+ }
+ }
+ }
+ }
+
+ echo(json_encode([
+ "cloudburst" => $existing1,
+ "raindrops" => $existing2
+ ]));
+
+ ?>;
+
+ let o;
+ let membersByPrefixCloudburst = {};
+ let membersByPrefixRaindrops = {};
+
+ o = prefixesUsedBy["cloudburst"];
+ Object.keys(o).map((i) => { if (!membersByPrefixCloudburst[o[i]]) membersByPrefixCloudburst[o[i]] = []; membersByPrefixCloudburst[o[i]].push(i); });
+
+ o = prefixesUsedBy["raindrops"];
+ Object.keys(o).map((i) => { if (!membersByPrefixRaindrops[o[i]]) membersByPrefixRaindrops[o[i]] = []; membersByPrefixRaindrops[o[i]].push(i); });
+
+ function update() {
+ let generated = [];
+ let toIgnore = [];
+
+ let system = document.getElementById("system").value;
+ let firstName = document.getElementById("first-name").value.toLowerCase().trim().replace(/[^a-z]/gm, "");
+ let lastName = document.getElementById("last-name").value.toLowerCase().trim().replace(/[^a-z]/gm, "");
+
+ document.getElementById("already").style.display = "none";
+ if (Object.keys(membersByPrefixRaindrops).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).includes((firstName + " " + lastName).trim())) {
+ let data = {
+ name: Object.keys(membersByPrefixRaindrops)[Object.keys(membersByPrefixRaindrops).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())],
+ prefix: membersByPrefixRaindrops[Object.keys(membersByPrefixRaindrops)[Object.keys(membersByPrefixRaindrops).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())]][0]
+ };
+ console.log(data);
+
+ document.getElementById("already-name").innerText = data.name;
+ document.getElementById("already-prefix").innerText = data.prefix;
+ document.getElementById("already").style.display = "";
+ }
+ if (Object.keys(membersByPrefixCloudburst).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).includes((firstName + " " + lastName).trim())) {
+ let data = {
+ name: Object.keys(membersByPrefixCloudburst)[Object.keys(membersByPrefixCloudburst).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())],
+ prefix: membersByPrefixCloudburst[Object.keys(membersByPrefixCloudburst)[Object.keys(membersByPrefixCloudburst).map(i => i.toLowerCase().trim().replace(/[^a-z ]/gm, "")).indexOf((firstName + " " + lastName).trim())]][0]
+ };
+ console.log(data);
+
+ document.getElementById("already-name").innerText = data.name;
+ document.getElementById("already-prefix").innerText = data.prefix;
+ document.getElementById("already").style.display = "";
+ }
+
+ switch (system) {
+ case "all":
+ toIgnore = [...existing["cloudburst"], ...existing["raindrops"]];
+ document.getElementById("hidden-sys-plural").style.display = "";
+ break;
+
+ case "raindrops":
+ toIgnore = existing["raindrops"];
+ document.getElementById("hidden-sys-plural").style.display = "none";
+ break;
+
+ case "cloudburst":
+ toIgnore = existing["cloudburst"];
+ document.getElementById("hidden-sys-plural").style.display = "none";
+ break;
+
+ case "none":
+ toIgnore = [];
+ document.getElementById("hidden-sys-plural").style.display = "";
+ break;
+ }
+
+ if (firstName.length > 0) {
+ generated.push({
+ prefix: firstName.substring(0, 1) + ".",
+ rules: ["<span class='text-warning'>firstNameFirstLetter</span>"]
+ });
+ }
+
+ if (lastName.length > 0) {
+ generated.push({
+ prefix: lastName.substring(0, 1) + ".",
+ rules: ["<span class='text-warning'>lastNameFirstLetter</span>"]
+ });
+ }
+
+ if (firstName.length > 1) {
+ generated.push({
+ prefix: firstName.substring(0, 2) + ".",
+ rules: ["<span class='text-warning'>firstNameFirstTwoLetters</span>"]
+ });
+ }
+
+ if (firstName.length > 0 && lastName.length > 0) {
+ generated.push({
+ prefix: firstName.substring(0, 1) + lastName.substring(0, 1) + ".",
+ rules: ["<span class='text-warning'>lastNameFirstTwoLetters</span>"]
+ });
+ }
+
+ if (firstName.length > 1) {
+ for (let i = 2; i < firstName.length + 1; i++) {
+ if (!(
+ firstName.substring(i - 1, i) === "a" ||
+ firstName.substring(i - 1, i) === "e" ||
+ firstName.substring(i - 1, i) === "i" ||
+ firstName.substring(i - 1, i) === "o" ||
+ firstName.substring(i - 1, i) === "u" ||
+ firstName.substring(i - 1, i) === "y"
+ )) {
+ generated.push({
+ prefix: firstName.substring(i - 1, i) + ".",
+ rules: ["<span class='text-warning'>firstNameLetterConsonant</span>"]
+ });
+ }
+ }
+ }
+
+ if (lastName.length > 1) {
+ for (let i = 2; i < lastName.length + 1; i++) {
+ if (!(
+ lastName.substring(i - 1, i) === "a" ||
+ lastName.substring(i - 1, i) === "e" ||
+ lastName.substring(i - 1, i) === "i" ||
+ lastName.substring(i - 1, i) === "o" ||
+ lastName.substring(i - 1, i) === "u" ||
+ lastName.substring(i - 1, i) === "y"
+ )) {
+ generated.push({
+ prefix: lastName.substring(i - 1, i) + ".",
+ rules: ["<span class='text-warning'>lastNameLetterConsonant</span>"]
+ });
+ }
+ }
+ }
+
+ if (firstName.length > 1) {
+ for (let i = 2; i < firstName.length + 1; i++) {
+ if (
+ firstName.substring(i - 1, i) === "a" ||
+ firstName.substring(i - 1, i) === "e" ||
+ firstName.substring(i - 1, i) === "i" ||
+ firstName.substring(i - 1, i) === "o" ||
+ firstName.substring(i - 1, i) === "u" ||
+ firstName.substring(i - 1, i) === "y"
+ ) {
+ generated.push({
+ prefix: firstName.substring(i - 1, i) + ".",
+ rules: ["<span class='text-warning'>firstNameLetterVowel</span>"]
+ });
+ }
+ }
+ }
+
+ if (lastName.length > 1) {
+ for (let i = 2; i < lastName.length; i++) {
+ if (
+ lastName.substring(i - 1, i) === "a" ||
+ lastName.substring(i - 1, i) === "e" ||
+ lastName.substring(i - 1, i) === "i" ||
+ lastName.substring(i - 1, i) === "o" ||
+ lastName.substring(i - 1, i) === "u" ||
+ lastName.substring(i - 1, i) === "y"
+ ) {
+ generated.push({
+ prefix: lastName.substring(i - 1, i + 1) + ".",
+ rules: ["<span class='text-warning'>lastNameTwoLettersVowel</span>"]
+ });
+ }
+ }
+ }
+
+ if (firstName.length > 2) {
+ for (let i = 2; i < firstName.length; i++) {
+ if (!(
+ firstName.substring(i - 1, i) === "a" ||
+ firstName.substring(i - 1, i) === "e" ||
+ firstName.substring(i - 1, i) === "i" ||
+ firstName.substring(i - 1, i) === "o" ||
+ firstName.substring(i - 1, i) === "u" ||
+ firstName.substring(i - 1, i) === "y"
+ )) {
+ generated.push({
+ prefix: firstName.substring(i - 1, i + 1) + ".",
+ rules: ["<span class='text-warning'>firstNameTwoLettersConsonant</span>"]
+ });
+ }
+ }
+ }
+
+ if (lastName.length > 2) {
+ for (let i = 2; i < lastName.length; i++) {
+ if (!(
+ lastName.substring(i - 1, i) === "a" ||
+ lastName.substring(i - 1, i) === "e" ||
+ lastName.substring(i - 1, i) === "i" ||
+ lastName.substring(i - 1, i) === "o" ||
+ lastName.substring(i - 1, i) === "u" ||
+ lastName.substring(i - 1, i) === "y"
+ )) {
+ generated.push({
+ prefix: lastName.substring(i - 1, i + 1) + ".",
+ rules: ["<span class='text-warning'>lastNameTwoLettersConsonant</span>"]
+ });
+ }
+ }
+ }
+
+ if (firstName.length > 2) {
+ for (let i = 2; i < firstName.length; i++) {
+ if (
+ firstName.substring(i - 1, i) === "a" ||
+ firstName.substring(i - 1, i) === "e" ||
+ firstName.substring(i - 1, i) === "i" ||
+ firstName.substring(i - 1, i) === "o" ||
+ firstName.substring(i - 1, i) === "u" ||
+ firstName.substring(i - 1, i) === "y"
+ ) {
+ generated.push({
+ prefix: firstName.substring(i - 1, i + 1) + ".",
+ rules: ["<span class='text-warning'>firstNameTwoLettersVowel</span>"]
+ });
+ }
+ }
+ }
+
+ if (lastName.length > 2) {
+ for (let i = 2; i < lastName.length; i++) {
+ if (
+ lastName.substring(i - 1, i) === "a" ||
+ lastName.substring(i - 1, i) === "e" ||
+ lastName.substring(i - 1, i) === "i" ||
+ lastName.substring(i - 1, i) === "o" ||
+ lastName.substring(i - 1, i) === "u" ||
+ lastName.substring(i - 1, i) === "y"
+ ) {
+ generated.push({
+ prefix: lastName.substring(i - 1, i + 1) + ".",
+ rules: ["<span class='text-warning'>lastNameTwoLettersVowel</span>"]
+ });
+ }
+ }
+ }
+
+ generated = generated.filter((c, index) => {
+ return generated.map((i) => { return i.prefix; }).indexOf(c.prefix) === index;
+ });
+
+ let generatedVowels = generated.filter((i) => {
+ return i.prefix.match(/[aeiouy]/);
+ }).map((i) => {
+ i.rules.push("<span class='text-danger'>containsVowels</span>");
+ return i;
+ });
+
+ let generatedNotVowels = generated.filter((i) => {
+ return !i.prefix.match(/[aeiouy]/);
+ }).map((i) => {
+ i.rules.push("<span class='text-success'>notContainsVowels</span>");
+ return i;
+ });
+
+ generated = [...generatedNotVowels, ... generatedVowels];
+
+ generated.sort((a, b) => {
+ return a.prefix.length - b.prefix.length;
+ });
+
+ let totalLength = generated.length;
+ generated = generated.filter((i) => {
+ return !toIgnore.includes(i.prefix);
+ });
+ let lengthAfterIgnore = generated.length;
+ let ignoredCount = totalLength - lengthAfterIgnore;
+
+ document.getElementById("hidden-count").innerText = ignoredCount.toString();
+ document.getElementById("hidden-plural").style.display = ignoredCount === 1 ? "none" : "inline";
+ document.getElementById("hidden-singular").style.display = ignoredCount === 1 ? "inline" : "none";
+ document.getElementById("hidden-message").style.display = ignoredCount === 0 ? "none" : "";
+
+ document.getElementById("results-none").style.display = "none";
+ document.getElementById("results-singular").style.display = "none";
+ document.getElementById("results-plural").style.display = "none";
+
+ if (generated.length === 0) {
+ document.getElementById("generated").innerHTML = "<li><code>{...}</code></li>";
+ document.getElementById("results-none").style.display = "";
+ } else {
+ let html = [];
+ let index = 1;
+
+ for (let prefix of generated) {
+ if (prefix.prefix === "n." || prefix.prefix === "g.") continue;
+
+ html.push(`<li><code data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="right" title="<b>Prefix:</b> <code>${prefix.prefix}</code><br><b>Score:</b> ${((1 - (index/generated.length))*100).toFixed(2)}%<hr><div class='text-peh-nowrap'>- ${prefix.rules.join("</div><div class='text-peh-nowrap'>- ")}</div><hr><div class='text-peh-nowrap'>- <span class='text-${existing["cloudburst"].includes(prefix.prefix) ? "danger" : "success"}'>Cloudburst</span> ${existing["cloudburst"].includes(prefix.prefix) ? ` (${prefixesUsedBy["cloudburst"][prefix.prefix]})` : ""}</div><div class='text-peh-nowrap'>- <span class='text-${existing["raindrops"].includes(prefix.prefix) ? "danger" : "success"}'>Raindrops</span> ${existing["raindrops"].includes(prefix.prefix) ? ` (${prefixesUsedBy["raindrops"][prefix.prefix]})` : ""}">${prefix.prefix}</code></li>`);
+
+ index++;
+ }
+
+ document.getElementById("generated").innerHTML = html.join("");
+
+ document.getElementById(generated.length > 1 ? "results-plural" : "results-singular").style.display = "";
+ }
+
+ let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
+ let tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
+ return new bootstrap.Tooltip(tooltipTriggerEl)
+ });
+
+ Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach((item) => {
+ item.style.cursor = "help";
+ })
+ }
+ </script>
+ <style>
+ .tooltip-inner {
+ text-align: left !important;
+ }
+
+ .text-peh-nowrap {
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ overflow: hidden;
+ }
+ </style>
+</div>
+
+<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc'; ?>