This commit is contained in:
Aliberk Sandıkçı 2024-01-07 15:35:18 +03:00
parent 3651e381fb
commit 3d819798dd
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
5 changed files with 126 additions and 44 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ build/*
*.tar.gz
*.zip
/vendor/
config.php
config.php
data.toml

View File

@ -27,8 +27,6 @@
}
}
.guess-tr {}
.guess-th {
border: aliceblue 3px solid;
}
@ -69,4 +67,48 @@
.type12::after {
content: "👆"
}
/* */
/* AUTOCOMPLETE */
/* */
.autocomplete {
/*the container must be positioned relative:*/
position: relative;
display: inline-block;
box-sizing: border-box;
}
.autocomplete-items {
box-sizing: border-box;
position: absolute;
border: 2px solid #10161d;
border-bottom: none;
border-top: none;
z-index: 99;
/*position the autocomplete items to be the same width as the container:*/
top: 100%;
left: 0;
right: 0;
}
.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #96939B;
border-bottom: 1px solid #10161d;
}
.autocomplete-items div:hover {
/*when hovering an item:*/
background-color: #00ADB5;
color: #e8e8e8;
}
.autocomplete-active {
/*when navigating through the items using the arrow keys:*/
background-color: #00ADB5 !important;
color: #e8e8e8;
}

View File

@ -25,9 +25,9 @@
min-height: 100vh;">
<form class="centered" style="margin-top: 10vh;" action="index.php" method="post">
<label style="margin-bottom:1vh;" for="mainInput">Yurtlu Öğrencinin İsmini Giriniz</label>
<div><input style="width:80%;" class="input" type="text" id="mainInput" name="mainInput" placeholder="İsim Soyisim" /><input style="width:20%;" class="input" type="submit" value="Dene" /></div>
<div class="autocomplete"><input style="width:80%;" class="input" type="text" id="mainInput" name="mainInput" placeholder="İsim Soyisim" /><input style="width:20%;" class="input" type="submit" value="Dene" /></div>
</form>
<div id="tebriks">
<div id="tebriks" style="display: none;">
</div>
<div id="tahminler">
@ -38,6 +38,8 @@
<div id="notices">
</div>
<div id="tsparticles"></div>
<hr style="width: 100%; box-sizing: border-box;">
<div id="sorumli" style="margin-top:auto;text-align:center;">Veri Sorumlusu: <b>Ömer Arda Muratoğlu</b><br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div>
<hr style="width: 100%; box-sizing: border-box;">
@ -54,6 +56,52 @@
</body>
<script>
function callConfetti() {
const duration = 10 * 1000,
animationEnd = Date.now() + duration,
defaults = {
startVelocity: 30,
spread: 360,
ticks: 60,
zIndex: 0
};
function randomInRange(min, max) {
return Math.random() * (max - min) + min;
}
const interval = setInterval(function() {
const timeLeft = animationEnd - Date.now();
if (timeLeft <= 0) {
return clearInterval(interval);
}
const particleCount = 50 * (timeLeft / duration);
// since particles fall down, start a bit higher than random
confetti(
Object.assign({}, defaults, {
particleCount,
origin: {
x: randomInRange(0.1, 0.3),
y: Math.random() - 0.2
},
})
);
confetti(
Object.assign({}, defaults, {
particleCount,
origin: {
x: randomInRange(0.7, 0.9),
y: Math.random() - 0.2
},
})
);
}, 250);
}
</script>
<script>
function isSameDay(a, b) {
return a.toDateString() == b.toDateString();
@ -62,10 +110,12 @@
if (localStorage.getItem("win") == null) {
localStorage.setItem("win", "none");
}
flagConf = 1;
document.getElementById("tebriks").style.display = "none";
if (localStorage.getItem("win") != null && localStorage.getItem("win") === "winned") {
document.getElementById("tebriks").style.display = "block";
document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
flagConf = 0;
}
// LOCAL STORAGE AND GUESS HANDLING
@ -193,6 +243,9 @@
document.getElementById("tebriks").style.display = "block";
document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
localStorage.setItem("win", "winned");
if (flagConf) {
callConfetti();
}
}
@ -335,5 +388,6 @@
autocomplete(document.getElementById("mainInput"), persons2);
</script>
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/confetti@3.0.3/tsparticles.confetti.bundle.min.js"></script>
</html>

View File

@ -9,14 +9,11 @@ require __DIR__ . '/../vendor/autoload.php';
$parser = new Toml();
$dock_local_test = 1;
# Fetch remote data each 1 hour
# Fetch Remote data and update data.toml (running each 10 min with cronjob)
function updateRemoteData()
{
# PREREQUIRITIES Create a cronjob or a systemd service for update it regularly !
# GET FROM GIT WITH ACCESS TOKEN AND SAVE TO data.toml
global $DATAACCESS_TOKEN;
global $APP_NAME;
$string = file_get_contents("https://git.aliberksandikci.com.tr/api/v1/repos/ifl/YurdleBackend/raw/data.toml?access_token=" . $DATAACCESS_TOKEN);
if ($string === FALSE) {
echo "Could not read the file.";
@ -24,47 +21,40 @@ function updateRemoteData()
$file = __DIR__ . "/../data.toml";
file_put_contents($file, $string, LOCK_EX);
}
chmod("$file", 0700);
chown("$file", $APP_NAME);
# REVIEW MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!!
parseTOML(); # parse again after update
parseTOML(); // not necessary
}
# Choose the todays person, everyday TSI 03:00
# Choose the todays person (running each day with cronjob)
function chooseTodayPerson()
{
# PREREQUIRIITES with cronjob or systemd, run this function everyday TSI 03.00
global $APP_NAME;
$data = parseTOML()["data"];
# parse toml
$personArr = array();
foreach ($data as $key => $value) {
array_push($personArr, $key);
}
print_r($personArr);
srand();
$random_number = random_int(0, count($personArr) - 1);
$choosen = $personArr[$random_number];
# get users array length
// TODO control each person if already choosed recently? (make all persons avaliable AFTER all of them choosed )
# get a random number
# make this person todays person, change $TODAYS_PERSON variable in today.php
$string = "<?php \$TODAYS_PERSON = \"$choosen\";";
$file = __DIR__ . "/todays.php";
file_put_contents($file, $string, LOCK_EX);
chmod("$file", 0700);
chown("$file", $APP_NAME);
}
# Send all person names to frontend
function getAllPersonNames()
{
# Parse Toml
# get `users` array
# get isim_soyisim of each user in `users` array and add to newArr
# NewArr
# send these as arry to frontend
# aliberk_sandikci24 -> "Aliberk Sandıı
// APPROACH 1: (needs public-> users array)
// $users = parseTOML()["public"]["users"];
// $arr = array();
// foreach ($users as $user) {
// array_push($arr, parseTOML()["data"][$user]["isim_soyisim"]);
// }
// return $arr;
// APPROACH 2:
$data = parseTOML()["data"];
$arr = array();
foreach ($data as $d) {
@ -102,7 +92,6 @@ function sendDataDate()
$arr[1] = date("d/m/Y H:i:s", filemtime(__DIR__ . "/" . $filename));
}
return $arr;
}
@ -178,7 +167,7 @@ function compareARR($guess, $todays, $krit)
if ($equalNum == 0) {
return 0;
} else if ($equalNum == count($todays)) {
} else if ($equalNum == count($todays) && $equalNum == count($guess)) {
return 2;
} else if ($equalNum >= 1) {
return 1;
@ -200,6 +189,3 @@ function parseTOML()
$array = $parser::ParseFile(__DIR__ . "/../data.toml");
return $array;
}
updateRemoteData();
comparePerson('aliberk_sandikci24');

View File

@ -1,2 +1 @@
<?php
$TODAYS_PERSON = "burak_sina_akbudak24";
<?php $TODAYS_PERSON = "aliberk_sandikci24";