summaryrefslogtreecommitdiff
path: root/includes/util/profiles.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/util/profiles.inc')
-rw-r--r--includes/util/profiles.inc97
1 files changed, 97 insertions, 0 deletions
diff --git a/includes/util/profiles.inc b/includes/util/profiles.inc
new file mode 100644
index 0000000..66274c7
--- /dev/null
+++ b/includes/util/profiles.inc
@@ -0,0 +1,97 @@
+<?php
+
+function calculateProfileScore($member) {
+ $values = [
+ ((isset($member["_metadata"]["birth"]["age"]) && $member["_metadata"]["birth"]["age"] > 0) || isset($member["_metadata"]["birth"]["year"]) && $member["_metadata"]["birth"]["year"] > 1900) || ((isset($member["_metadata"]["birth"]["age"]) && $member["_metadata"]["birth"]["age"] === -1) && in_array("alicorn", $member["_metadata"]["species"])),
+ isset($member["_metadata"]["birth"]["date"]) && trim($member["_metadata"]["birth"]["date"]) !== "" && $member["_metadata"]["birth"]["date"] !== "01-01",
+ file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html") && strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html"))) > 200,
+ file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html") && strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html"))) > 200,
+ isset($member["banner"]),
+ file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png"),
+ isset($member["color"])
+ ];
+
+ $result = [
+ "values" => $values,
+ "pages" => [],
+ "characters" => [],
+ "score" => (float)array_reduce($values, function ($a, $b) {
+ return $a + $b;
+ }),
+ "score2" => (float)array_reduce($values, function ($a, $b) {
+ return $a + $b;
+ }),
+ "actions" => []
+ ];
+
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html") && strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html"))) <= 200) {
+ $result["pages"][] = true;
+ $result["score"] += strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html"))) / 201;
+ } else {
+ $result["pages"][] = false;
+ }
+
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html") && strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html"))) <= 200) {
+ $result["pages"][] = true;
+ $result["score"] += strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html"))) / 201;
+ } else {
+ $result["pages"][] = false;
+ }
+
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html")) {
+ $result["characters"][] = strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . ".html")));
+ } else {
+ $result["characters"][] = -1;
+ }
+
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html")) {
+ $result["characters"][] = strlen(preg_replace("/[^a-zA-Z0-9]/m", "", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/content/" . $member["id"] . "-private.html")));
+ } else {
+ $result["characters"][] = -1;
+ }
+
+ if (!((isset($member["_metadata"]["birth"]["age"]) && $member["_metadata"]["birth"]["age"] > 0) || isset($member["_metadata"]["birth"]["year"]) && $member["_metadata"]["birth"]["year"] > 1900) && !(isset($member["_metadata"]["birth"]["age"]) && $member["_metadata"]["birth"]["age"] === -1) && in_array("alicorn", $member["_metadata"]["species"])) {
+ $result["score"] += 0.5;
+ }
+
+ $result["progress"] = $result["score"] / 7;
+ $result["sortable"] = (int)($result["progress"] * 100000000000000);
+
+ if (!$result["values"][5]) {
+ $result["actions"][] = "a Pony Town character";
+ }
+
+ if (!$result["values"][6]) {
+ $result["actions"][] = "a color";
+ }
+
+ if (!$result["values"][2]) {
+ if ($result["characters"][0] === -1) {
+ $result["actions"][] = "a public page";
+ } else {
+ $result["actions"][] = (200 - $result["characters"][0]) . " characters to the public page";
+ }
+ }
+
+ if (!$result["values"][3]) {
+ if ($result["characters"][1] === -1) {
+ $result["actions"][] = "a private page";
+ } else {
+ $result["actions"][] = (200 - $result["characters"][1]) . " characters to the private page";
+ }
+ }
+
+ if (!$result["values"][4]) {
+ $result["actions"][] = "a banner";
+ }
+
+ if (!$result["values"][0]) {
+ $result["actions"][] = "an age";
+ }
+
+ if (!$result["values"][1]) {
+ $result["actions"][] = "a birthdate";
+ }
+
+ return $result;
+} \ No newline at end of file